// 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("上传失败"));
|
|
}
|
|
|
}
|