admin
8 天以前 6cd92a169cbc0db35042f243a09d976fd3e1445c
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
// CCodeNameDlg.cpp: 实现文件
//
#include "common/pch.h"
#include "FloatTrade.h"
#include "CCodeNameDlg.h"
#include "afxdialogex.h"
#include "../common/NetworkApi.h"
#include "../common/JsonUtil.h"
#include "Constant.h"
#include "ConfigUtil.h"
 
#define CODE_NUM 10
 
 
// CCodeNameDlg 对话框
 
IMPLEMENT_DYNAMIC(CCodeNameDlg, CDialogEx)
 
CCodeNameDlg::CCodeNameDlg(CWnd* pParent /*=nullptr*/)
    : CDialogEx(IDD_DIALOG_CODE_NAME, pParent)
{
 
}
 
CCodeNameDlg::~CCodeNameDlg()
{
}
 
void CCodeNameDlg::DoDataExchange(CDataExchange* pDX)
{
    CDialogEx::DoDataExchange(pDX);
}
 
 
BEGIN_MESSAGE_MAP(CCodeNameDlg, CDialogEx)
    ON_BN_CLICKED(IDOK, &CCodeNameDlg::OnBnClickedOk)
END_MESSAGE_MAP()
 
 
// CCodeNameDlg 消息处理程序
 
 
void CCodeNameDlg::OnBnClickedOk()
{
    // 保存代码名称
    int codeCtrls[CODE_NUM] = { IDC_STATIC_CODE_1, IDC_STATIC_CODE_2, IDC_STATIC_CODE_3 , IDC_STATIC_CODE_4 , IDC_STATIC_CODE_5 , IDC_STATIC_CODE_6 , IDC_STATIC_CODE_7 , IDC_STATIC_CODE_8 , IDC_STATIC_CODE_9 , IDC_STATIC_CODE_10 };
    int nameCtrls[CODE_NUM] = { IDC_EDIT_NAME_1, IDC_EDIT_NAME_2, IDC_EDIT_NAME_3 , IDC_EDIT_NAME_4 , IDC_EDIT_NAME_5 , IDC_EDIT_NAME_6 , IDC_EDIT_NAME_7 , IDC_EDIT_NAME_8 , IDC_EDIT_NAME_9 , IDC_EDIT_NAME_10 };
    for (int i = 0; i < CODE_NUM; i++) {
        CString code;
        ((CStatic*)GetDlgItem(codeCtrls[i]))->GetWindowTextW(code);
        CString name;
        ((CEdit*)GetDlgItem(nameCtrls[i]))->GetWindowTextW(name);
        if (code.GetLength() != 6) {
            continue;
        }
        Constant::codeNameMap[StringUtil::cstring2String(code)] = name;
    }
    ConfigUtil::setCodeNames(Constant::codeNameMap);
    CDialogEx::OnOK();
}
 
 
BOOL CCodeNameDlg::OnInitDialog()
{
    CDialogEx::OnInitDialog();
    if (Constant::codeNameMap.empty()) {
        requestPositions();
    }
    int codeCtrls[CODE_NUM] ={IDC_STATIC_CODE_1, IDC_STATIC_CODE_2, IDC_STATIC_CODE_3 , IDC_STATIC_CODE_4 , IDC_STATIC_CODE_5 , IDC_STATIC_CODE_6 , IDC_STATIC_CODE_7 , IDC_STATIC_CODE_8 , IDC_STATIC_CODE_9 , IDC_STATIC_CODE_10};
    int nameCtrls[CODE_NUM] = { IDC_EDIT_NAME_1, IDC_EDIT_NAME_2, IDC_EDIT_NAME_3 , IDC_EDIT_NAME_4 , IDC_EDIT_NAME_5 , IDC_EDIT_NAME_6 , IDC_EDIT_NAME_7 , IDC_EDIT_NAME_8 , IDC_EDIT_NAME_9 , IDC_EDIT_NAME_10 };
 
 
    int index = 0;
    for (std::map<std::string, CString>::iterator e = Constant::codeNameMap.begin(); e != Constant::codeNameMap.end(); e++) {
        string code = (*e).first;
        CString name = (*e).second;
        ((CStatic*)GetDlgItem(codeCtrls[index]))->SetWindowTextW(CString(code.c_str()));
        ((CEdit*)GetDlgItem(nameCtrls[index]))->SetWindowTextW(name);
        index++;
    }
    
 
 
 
 
 
 
    
 
    return TRUE;
}
 
void CCodeNameDlg::requestPositions()
{
    string result = NetworkApi::get_all_positions();
    auto doc = JsonUtil::parseUTF16(result);
    if (doc.IsObject() && doc[L"code"] == 0) {
        auto array = doc[L"data"].GetArray();
        for (int i = 0; i < array.Size(); i++) {
            auto  data = array[i].GetObjectW();
            CString codew = data[L"code"].GetString();
            string code = StringUtil::cstring2String(codew);
            CString codeName = data[L"code_name"].GetString();
            Constant::codeNameMap[code] = codeName;
        }
    }
    cout << result << endl;
}