// CBuyDlg.cpp: 实现文件
|
//
|
|
#include "common/pch.h"
|
#include "FloatTrade.h"
|
#include "CBuyDlg.h"
|
#include "afxdialogex.h"
|
#include "../common/StringUtil.h"
|
#include "../common/NetworkApi.h"
|
#include <regex>
|
using namespace std;
|
|
|
// CBuyDlg 对话框
|
|
IMPLEMENT_DYNAMIC(CBuyDlg, CDialogEx)
|
|
CBuyDlg::CBuyDlg(CString codew, CWnd* pParent /*=nullptr*/)
|
: CDialogEx(IDD_BUY, pParent)
|
{
|
this->codew = codew;
|
}
|
|
CBuyDlg::~CBuyDlg()
|
{
|
}
|
|
void CBuyDlg::DoDataExchange(CDataExchange* pDX)
|
{
|
CDialogEx::DoDataExchange(pDX);
|
DDX_Control(pDX, edit_code, editCode);
|
DDX_Control(pDX, edit_money, editMoney);
|
DDX_Control(pDX, edit_price, editPrice);
|
}
|
|
|
BEGIN_MESSAGE_MAP(CBuyDlg, CDialogEx)
|
ON_BN_CLICKED(btn_sure, &CBuyDlg::OnBnClickedsure)
|
ON_WM_COPYDATA()
|
ON_CBN_SELCHANGE(IDC_COMBO_SELL_FIRST, &CBuyDlg::OnCbnSelchangeComboSellFirst)
|
ON_CBN_SELCHANGE(IDC_COMBO_SELL_LEFT, &CBuyDlg::OnCbnSelchangeComboSellLeft)
|
END_MESSAGE_MAP()
|
|
|
// CBuyDlg 消息处理程序
|
|
|
void CBuyDlg::OnBnClickedsure()
|
{
|
//确定
|
CString codew;
|
CString moneyw;
|
CString pricew;
|
editCode.GetWindowTextW(codew);
|
editMoney.GetWindowTextW(moneyw);
|
editPrice.GetWindowTextW(pricew);
|
//正则判断整数
|
string code = StringUtil::cstring2String(codew);
|
string money= StringUtil::cstring2String(moneyw);
|
string price = StringUtil::cstring2String(pricew);
|
if (!regex_match(code,regex("^\\d{6}$"))) {
|
AfxMessageBox(L"代码格式不正确");
|
return;
|
}
|
|
if (!regex_match(money, regex("^\\d{2,7}$"))) {
|
AfxMessageBox(L"金额必须为(2-7位)整数");
|
return;
|
}
|
|
if (!regex_match(price, regex("^[0-9]+(.[0-9]{0,2})?$"))) {
|
AfxMessageBox(L"价格不正确");
|
return;
|
}
|
|
|
//转换为量
|
int volume = round(std::stoi(money) / stof(price));
|
if (volume % 100 != 0){
|
volume = (volume / 100) * 100;
|
}
|
|
try {
|
NetworkApi::buy(code, volume, 0);
|
MessageBox(_T("下单成功"), _T("下单结果"), MB_TASKMODAL);
|
}
|
catch (CString st) {
|
AfxMessageBox(st);
|
}
|
catch (wstring st) {
|
AfxMessageBox(CString( st.c_str()));
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
BOOL CBuyDlg::OnCopyData(CWnd* pWnd, COPYDATASTRUCT* pCopyDataStruct)
|
{
|
BYTE* pBuf = (BYTE*)(pCopyDataStruct->lpData);
|
DWORD dwSize = (DWORD)(pCopyDataStruct->cbData);
|
|
// 读取数据
|
if (pBuf != nullptr && dwSize > 0)
|
{
|
std::string str(reinterpret_cast<const char*>(pBuf), dwSize);
|
wstring wstr = StringUtil::Unescape(str);
|
rapidjson::GenericDocument<rapidjson::UTF16<>> root;
|
root.Parse(wstr.c_str());
|
|
wstring type = root[_T("type")].GetString();
|
if (type == _T("set_code")) {
|
//this->SetForegroundWindow();
|
//this->SetFocus();
|
wstring codew = root[_T("data")][_T("code")].GetString();
|
editCode.SetWindowTextW(codew.c_str());
|
}
|
}
|
return CDialogEx::OnCopyData(pWnd, pCopyDataStruct);
|
}
|
|
|
BOOL CBuyDlg::OnInitDialog()
|
{
|
CDialogEx::OnInitDialog();
|
|
// 初始化
|
editCode.SetWindowTextW(codew);
|
|
return TRUE; // return TRUE unless you set the focus to a control
|
// 异常: OCX 属性页应返回 FALSE
|
}
|
|
|
void CBuyDlg::OnCbnSelchangeComboSellFirst()
|
{
|
// TODO: 在此添加控件通知处理程序代码
|
}
|
|
|
void CBuyDlg::OnCbnSelchangeComboSellLeft()
|
{
|
// TODO: 在此添加控件通知处理程序代码
|
}
|