admin
2023-01-02 954ead41d9391bca28a3cc4f9592f73f25b3bbc8
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
// codesDataDlog.cpp: 实现文件
//
#include <iostream>  
#include <string>
#include "StringUtils.h"
#include "pch.h"
#include "codesDataDlog.h"
#include "afxdialogex.h"
#include "framework.h"
#include "GUITool.h"
#include "ExcelUtil.h"
#include "app.h"
#include "SocketManager.h"
#include "JsonUtil.h"
#include "tool.h"
 
 
 
 
 
// codesDataDlog 对话框
 
IMPLEMENT_DYNAMIC(codesDataDlog, CDialogEx)
 
std::list<IndustryData> codesDataDlog::codeData;
bool  codesDataDlog::upload;
bool  codesDataDlog::add;
 
codesDataDlog::codesDataDlog(CWnd* pParent /*=nullptr*/)
    : CDialogEx(IDD_CODE_DATA, pParent)
{
 
}
 
codesDataDlog::~codesDataDlog()
{
}
 
void codesDataDlog::DoDataExchange(CDataExchange* pDX)
{
    CDialogEx::DoDataExchange(pDX);
    DDX_Control(pDX, IDC_BUTTON1, uploadBtn);
 
 
    DDX_Control(pDX, IDC_EDIT2, codesEdit);
}
 
BOOL codesDataDlog::OnInitDialog()
{
    CDialogEx::OnInitDialog();
 
    // 将“关于...”菜单项添加到系统菜单中。
 
    // IDM_ABOUTBOX 必须在系统命令范围内。
    ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
    ASSERT(IDM_ABOUTBOX < 0xF000);
 
    CMenu* pSysMenu = GetSystemMenu(FALSE);
    if (pSysMenu != nullptr)
    {
        BOOL bNameValid;
        CString strAboutMenu;
        bNameValid = strAboutMenu.LoadString(IDS_ABOUTBOX);
        ASSERT(bNameValid);
        if (!strAboutMenu.IsEmpty())
        {
            pSysMenu->AppendMenu(MF_SEPARATOR);
            pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
        }
    }
 
    if (upload)
        uploadBtn.ShowWindow(TRUE);
    else
        uploadBtn.ShowWindow(FALSE);
 
    CString st;
    st.Format(_T("总共%d条数据(%s)"), codeData.size(),add? _T("新增"): _T("覆盖"));
    GetDlgItem(IDC_STATIC)->SetWindowTextW(st);
 
 
    CEdit* edit = (CEdit*)GetDlgItem(IDC_EDIT2);
 
    string data = "";
    for (list<IndustryData>::iterator ele = codeData.begin();ele != codeData.end();ele++) {
        data.append((*ele).code).append(" ").append((*ele).zyltMoney).append( (*ele).zyltMoneyUnit== MONEY_UNIT_Y?"亿":"万").append("\r\n");
    }
 
    CString cdata(data.c_str());
 
    edit->SetWindowTextW(cdata);
 
    return TRUE;  // 除非将焦点设置到控件,否则返回 TRUE
}
 
 
 
 
BEGIN_MESSAGE_MAP(codesDataDlog, CDialogEx)
    ON_BN_CLICKED(IDC_BUTTON1, &codesDataDlog::OnBnClickedButton1)
END_MESSAGE_MAP()
 
 
// codesDataDlog 消息处理程序
 
 
std::string trim(const std::string source, const std::string chars) {
    std::string other(source);
    int start = other.find_first_of(chars);
    int end = other.find_first_not_of(chars, start);
    while (start > -1) {
        other.erase(start, end - start);
        start = other.find_first_of(chars);
        end = other.find_first_not_of(chars, start);
    }
    return other;
}
 
 
void codesDataDlog::OnBnClickedButton1()
{
    codeData.clear();
    if (codeData.size() == 0 ) {
        CString text;
        codesEdit.GetWindowTextW(text);
        string datas = Tool::cstring2String( text);
        //分隔
        int p = 0;
        do {
            int start = p;
            p = datas.find("\n", p + 1);
            string temp = datas.substr(start, p - start);
            if (temp.length() > 2) {
 
                int splitIndex = temp.find("\t");
                if (splitIndex < 0) {
                    splitIndex = temp.find(" ");
                }
                string zylt = trim(temp.substr(0, splitIndex),"\t\r\n ");
                string code= trim( temp.substr(splitIndex, temp.length() - splitIndex),"\t\r\n ");
                code = code.substr(2, code.length()-2);
 
                IndustryData data;
                data.code = code;
                
                if (zylt.find("亿",0) > 0) {
                    data.zyltMoneyUnit = MONEY_UNIT_Y;
                    data.zyltMoney = zylt.substr(0, zylt.length() - 2);
                }
                else if (zylt.find("万",0) > 0) {
                    data.zyltMoneyUnit = MONEY_UNIT_W;
                    data.zyltMoney = zylt.substr(0, zylt.length() - 2);
                }
                codeData.push_back(data);
            }
            if (p < 0) {
                break;
            }
        } while (TRUE);
    
    }
    if (codeData.size() == 0) {
        AfxMessageBox(_T("没有可上传的代码"));
        return;
    }
 
    try {
        SocketManager::sendMsg(JsonUtil::loadGPCodeData(codeData,add).c_str());
 
        AfxMessageBox(_T("上传成功"));
 
    }
    catch (...)
    {
 
        AfxMessageBox(_T("上传失败"));
 
    }
 
 
}