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
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
// CCBBuyDlg.cpp: 实现文件
//
 
#include "common/pch.h"
#include "FloatTrade.h"
#include "CCBBuyDlg.h"
#include "afxdialogex.h"
#include "../common/NetworkApi.h"
#include "../common/StringUtil.h"
#include "../common/JsonUtil.h"
 
 
// CCBBuyDlg 对话框
 
IMPLEMENT_DYNAMIC(CCBBuyDlg, CDialogEx)
 
CCBBuyDlg::CCBBuyDlg(CWnd* pParent /*=nullptr*/)
    : CDialogEx(IDD_DIALOG_CB_TRADE, pParent)
{
 
}
 
CCBBuyDlg::~CCBBuyDlg()
{
}
 
void CCBBuyDlg::DoDataExchange(CDataExchange* pDX)
{
    CDialogEx::DoDataExchange(pDX);
    DDX_Control(pDX, IDC_EDIT_CODE, editCode);
    DDX_Control(pDX, IDC_EDIT_VOLUME, editVolume);
}
 
 
BEGIN_MESSAGE_MAP(CCBBuyDlg, CDialogEx)
    ON_BN_CLICKED(IDC_BUTTON_BUY, &CCBBuyDlg::OnBnClickedButtonBuy)
    ON_BN_CLICKED(IDC_BUTTON_SELL, &CCBBuyDlg::OnBnClickedButtonSell)
END_MESSAGE_MAP()
 
 
// CCBBuyDlg 消息处理程序
 
 
void CCBBuyDlg::OnBnClickedButtonBuy()
{
    CString code;
    editCode.GetWindowTextW(code);
    CString volume;
    editVolume.GetWindowTextW(volume);
    try {
        if (code.GetLength() != 6) {
            throw CString("可转债代码输入不正确");
        }
        if (code.Find(L"11") != 0 && code.Find(L"12") != 0) {
            throw CString("不为可转债代码");
        }
 
        if (volume.GetLength() < 1) {
            throw CString("请输入买入量");
        }
        string result = NetworkApi::buy_cb(StringUtil::cstring2String(code), stoi(StringUtil::cstring2String(volume)));
        auto doc = JsonUtil::parseUTF16(result);
        if (doc.IsObject()) {
            if (doc[L"code"].GetInt() != 0) {
                throw doc[L"msg"].GetString();
            }
            else {
                if (doc[L"data"].HasMember(L"statusMsg")) {
                    CString statusMsg = doc[L"data"][L"statusMsg"].GetString();
                    if (statusMsg.IsEmpty()) {
                        MessageBox(L"下单成功");
                    }
                    else {
                        AfxMessageBox(statusMsg);
                    }
                }
                else if (doc[L"data"].HasMember(L"orderStatusMsg")) {
                    CString statusMsg = doc[L"data"][L"orderStatusMsg"].GetString();
                    if (statusMsg.IsEmpty()) {
                        MessageBox(L"下单成功");
                    }
                    else {
                        AfxMessageBox(statusMsg);
                    }
                }
            }
        }
    }
    catch (CString msg) {
        AfxMessageBox(msg);
    }
    catch (wstring msg) {
        AfxMessageBox(msg.c_str());
    }
 
}
 
 
BOOL CCBBuyDlg::OnInitDialog()
{
    CDialogEx::OnInitDialog();
    editVolume.SetWindowTextW(L"10");
    return TRUE;
}
 
 
void CCBBuyDlg::OnBnClickedButtonSell()
{
    CString code;
    editCode.GetWindowTextW(code);
    CString volume;
    editVolume.GetWindowTextW(volume);
    try {
        if (code.GetLength() != 6) {
            throw CString("可转债代码输入不正确");
        }
        if (code.Find(L"11") != 0 && code.Find(L"12") != 0) {
            throw CString("不为可转债代码");
        }
 
        if (volume.GetLength() < 1) {
            throw CString("请输入买入量");
        }
        string result = NetworkApi::sell_cb(StringUtil::cstring2String(code), stoi(StringUtil::cstring2String(volume)));
        auto doc = JsonUtil::parseUTF16(result);
        if (doc.IsObject()) {
            if (doc[L"code"].GetInt() != 0) {
                throw doc[L"msg"].GetString();
            }
            else {
                if (doc[L"data"].HasMember(L"statusMsg")) {
                    CString statusMsg = doc[L"data"][L"statusMsg"].GetString();
                    if (statusMsg.IsEmpty()) {
                        MessageBox(L"卖出委托成功");
                    }
                    else {
                        AfxMessageBox(statusMsg);
                    }
                }
                else if (doc[L"data"].HasMember(L"orderStatusMsg")) {
                    CString statusMsg = doc[L"data"][L"orderStatusMsg"].GetString();
                    if (statusMsg.IsEmpty()) {
                        MessageBox(L"卖出委托成功");
                    }
                    else {
                        AfxMessageBox(statusMsg);
                    }
                }
            }
        }
    }
    catch (CString msg) {
        AfxMessageBox(msg);
    }
    catch (wstring msg) {
        AfxMessageBox(msg.c_str());
    }
 
}