// 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());
|
}
|
|
}
|