// SellRuleDlg.cpp: 实现文件
|
//
|
#include "common/pch.h"
|
#include "FloatTrade.h"
|
#include "SellRuleDlg.h"
|
#include "../common/Win32Util.h"
|
#include "../common/NetworkApi.h"
|
#include "../common/StringUtil.h"
|
#include "../common/JsonUtil.h"
|
#include "afxdialogex.h"
|
#include <thread>
|
#include "ConfigUtil.h"
|
#include <ctime>
|
#include <cstring>
|
#include "../common/TimeUtil.h"
|
#include "MyApi.h"
|
|
|
// SellRuleDlg 对话框
|
|
IMPLEMENT_DYNAMIC(SellRuleDlg, CDialogEx)
|
|
|
SellRuleDlg::SellRuleDlg(CString code, CString volume, CWnd* pParent /*=nullptr*/)
|
: CDialogEx(IDD_DIALOG_SELL_RULE, pParent)
|
{
|
this->initCode = code;
|
this->initVolume = volume;
|
}
|
|
SellRuleDlg::~SellRuleDlg()
|
{
|
}
|
|
void SellRuleDlg::DoDataExchange(CDataExchange* pDX)
|
{
|
CDialogEx::DoDataExchange(pDX);
|
DDX_Control(pDX, IDC_STATIC_ID, labelID);
|
DDX_Control(pDX, IDC_EDIT_CODE, editCode);
|
DDX_Control(pDX, IDC_EDIT_BUY1_VOLUME, editBuy1Volume);
|
DDX_Control(pDX, IDC_EDIT_SELL_VOLUME, editSellVolume);
|
DDX_Control(pDX, IDC_EDIT_END_TIME, editEndTime);
|
DDX_Control(pDX, IDC_BUTTON_CLEAR, btnClear);
|
DDX_Control(pDX, IDC_BUTTON_DELETE, btnDel);
|
DDX_Control(pDX, IDC_BUTTON_ADD, btnAdd);
|
DDX_Control(pDX, IDC_LIST_RULES, listRules);
|
DDX_Control(pDX, IDC_COMBO_SELL_PRICE_TYPE, comboSellPriceType);
|
DDX_Control(pDX, IDC_EDIT_CODE2, editCode1);
|
DDX_Control(pDX, IDC_EDIT_BUY1_PRICE2, editBuy1Price1);
|
DDX_Control(pDX, IDC_EDIT_SELL_VOLUME2, editSellVolume1);
|
DDX_Control(pDX, IDC_COMBO_SELL_PRICE_TYPE2, comboSellPriceType1);
|
DDX_Control(pDX, IDC_EDIT_END_TIME2, editEndTime1);
|
DDX_Control(pDX, IDC_STATIC_ID2, labelId1);
|
DDX_Control(pDX, IDC_STATIC_ID3, labelID3);
|
DDX_Control(pDX, IDC_EDIT_CODE3, editCode3);
|
DDX_Control(pDX, IDC_EDIT_BUY1_VOLUME2, editBuy1Volume3);
|
DDX_Control(pDX, IDC_EDIT_END_TIME3, editEndTime3);
|
DDX_Control(pDX, IDC_STATIC_POSITION, labelPosition);
|
DDX_Control(pDX, IDC_STATIC_POSITION2, labelPosition1);
|
DDX_Control(pDX, IDC_STATIC_BUY1_MONEY, labelBuy1Money);
|
}
|
|
|
BEGIN_MESSAGE_MAP(SellRuleDlg, CDialogEx)
|
ON_BN_CLICKED(IDC_BUTTON_CLEAR, &SellRuleDlg::OnBnClickedButtonClear)
|
ON_BN_CLICKED(IDC_BUTTON_DELETE, &SellRuleDlg::OnBnClickedButtonDelete)
|
ON_BN_CLICKED(IDC_BUTTON_ADD, &SellRuleDlg::OnBnClickedButtonAdd)
|
ON_NOTIFY(LVN_ITEMCHANGED, IDC_LIST_RULES, &SellRuleDlg::OnLvnItemchangedListRules)
|
ON_NOTIFY(NM_CUSTOMDRAW, IDC_LIST_RULES, &SellRuleDlg::OnNMCustomdrawListRules)
|
ON_BN_CLICKED(IDC_BUTTON_CLEAR2, &SellRuleDlg::OnBnClickedButtonClear2)
|
ON_BN_CLICKED(IDC_BUTTON_DELETE2, &SellRuleDlg::OnBnClickedButtonDelete2)
|
ON_BN_CLICKED(IDC_BUTTON_ADD2, &SellRuleDlg::OnBnClickedButtonAdd2)
|
ON_WM_CLOSE()
|
ON_BN_CLICKED(IDC_BUTTON_UPDATE, &SellRuleDlg::OnBnClickedButtonUpdate)
|
ON_BN_CLICKED(IDC_BUTTON_UPDATE2, &SellRuleDlg::OnBnClickedButtonUpdate2)
|
ON_BN_CLICKED(IDC_BUTTON_FILL_VOLUME, &SellRuleDlg::OnBnClickedButtonFillVolume)
|
ON_BN_CLICKED(IDC_BUTTON_CLEAR3, &SellRuleDlg::OnBnClickedButtonClear3)
|
ON_BN_CLICKED(IDC_BUTTON_DELETE4, &SellRuleDlg::OnBnClickedButtonDelete4)
|
ON_BN_CLICKED(IDC_BUTTON_UPDATE3, &SellRuleDlg::OnBnClickedButtonUpdate3)
|
ON_BN_CLICKED(IDC_BUTTON_ADD3, &SellRuleDlg::OnBnClickedButtonAdd3)
|
ON_BN_CLICKED(IDC_BUTTON_FILL_VOLUME2, &SellRuleDlg::OnBnClickedButtonFillVolume2)
|
ON_BN_CLICKED(IDC_BUTTON_GET_POSITION, &SellRuleDlg::OnBnClickedButtonGetPosition)
|
ON_BN_CLICKED(IDC_BUTTON_GET_POSITION2, &SellRuleDlg::OnBnClickedButtonGetPosition2)
|
END_MESSAGE_MAP()
|
|
|
// SellRuleDlg 消息处理程序
|
|
|
BOOL SellRuleDlg::OnInitDialog()
|
{
|
CDialogEx::OnInitDialog();
|
// 设置显示的位置
|
int* pos = ConfigUtil::getSellRuleDialogShowPos();
|
int x = pos[0];
|
int y = pos[1];
|
free(pos);
|
if (x > 0 || y > 0)
|
{
|
HWND hwnd = GetSafeHwnd();
|
RECT rect;
|
Win32Util::getWindowRect(hwnd, &rect);
|
::SetWindowPos(hwnd, nullptr, x, y, rect.right - rect.left + 1, rect.bottom - rect.top + 1, SWP_SHOWWINDOW);
|
}
|
|
if (this->initCode) {
|
editCode.SetWindowTextW(this->initCode);
|
editCode1.SetWindowTextW(this->initCode);
|
editCode3.SetWindowTextW(this->initCode);
|
}
|
if (this->initVolume) {
|
editSellVolume.SetWindowTextW(this->initVolume);
|
editSellVolume1.SetWindowTextW(this->initVolume);
|
}
|
editEndTime.SetWindowTextW(L"14:56:58");
|
editEndTime1.SetWindowTextW(L"09:24:59");
|
|
initEndTime3();
|
|
initView();
|
std::thread t1(requestListRules, this);
|
t1.detach();
|
return TRUE; // return TRUE unless you set the focus to a control
|
// 异常: OCX 属性页应返回 FALSE
|
}
|
|
|
|
void SellRuleDlg::OnBnClickedButtonClear()
|
{
|
labelID.SetWindowTextW(L"");
|
editBuy1Volume.SetWindowTextW(L"");
|
editCode.SetWindowTextW(L"");
|
editSellVolume.SetWindowTextW(L"");
|
editEndTime.SetWindowTextW(L"14:56:58");
|
labelPosition.SetWindowTextW(L"");
|
}
|
|
|
void SellRuleDlg::initView()
|
{
|
//初始化列表
|
listRules.SetExtendedStyle(ES_MULTILINE | LVS_EX_FULLROWSELECT | LVS_EX_GRIDLINES | WS_HSCROLL);
|
listRules.ModifyStyle(LVS_SINGLESEL, LVS_REPORT);
|
listRules.SetRowHeigt(48);
|
|
CRect rect;
|
listRules.GetClientRect(&rect);
|
|
int unitSize = (rect.Width() - 5) / 7.5f;
|
|
listRules.InsertColumn(0, _T("代码"), LVCFMT_LEFT, unitSize * 1, 0);
|
listRules.InsertColumn(1, _T("条件"), LVCFMT_LEFT, unitSize * 3, 1);
|
listRules.InsertColumn(2, _T("卖出量(股)"), LVCFMT_LEFT, unitSize * 1.1, 2);
|
listRules.InsertColumn(3, _T("结束时间"), LVCFMT_LEFT, unitSize * 1.3, 3);
|
listRules.InsertColumn(4, _T("状态"), LVCFMT_LEFT, unitSize * 0.8, 4);
|
// listRules.InsertColumn(7, _T("ID"), LVCFMT_LEFT, 50, 7);
|
// listRules.InsertColumn(8, _T("创建时间"), LVCFMT_LEFT, 50, 8);
|
listRules.AutoColumn();
|
|
list<string> types = get_price_types();
|
for (list<string>::iterator e = types.begin(); e != types.end(); ++e) {
|
comboSellPriceType.AddString(CString((*e).c_str()));
|
comboSellPriceType1.AddString(CString((*e).c_str()));
|
}
|
comboSellPriceType.SetCurSel(0);
|
comboSellPriceType1.SetCurSel(1);
|
}
|
|
void SellRuleDlg::showDetail(SellRule rule) {
|
OnBnClickedButtonClear();
|
OnBnClickedButtonClear2();
|
OnBnClickedButtonClear3();
|
if (rule.type == 2) {
|
if (rule.buy1_volume > 0) {
|
labelID.SetWindowTextW(rule.id_);
|
editBuy1Volume.SetWindowTextW(CString(std::to_wstring(rule.buy1_volume).c_str()));
|
editCode.SetWindowTextW(rule.code);
|
editSellVolume.SetWindowTextW(CString(std::to_wstring(rule.sell_volume).c_str()));
|
comboSellPriceType.SetCurSel(rule.sell_price_type);
|
editEndTime.SetWindowTextW(rule.end_time);
|
}
|
else {
|
labelId1.SetWindowTextW(rule.id_);
|
editCode1.SetWindowTextW(rule.code);
|
editSellVolume1.SetWindowTextW(CString(std::to_wstring(rule.sell_volume).c_str()));
|
comboSellPriceType1.SetCurSel(rule.sell_price_type);
|
editEndTime1.SetWindowTextW(rule.end_time);
|
editBuy1Price1.SetWindowTextW(rule.buy1_price);
|
}
|
}
|
else if (rule.type == 1) {
|
labelID3.SetWindowTextW(rule.id_);
|
editBuy1Volume3.SetWindowTextW(CString(std::to_wstring(rule.buy1_volume).c_str()));
|
editCode3.SetWindowTextW(rule.code);
|
editEndTime3.SetWindowTextW(rule.end_time);
|
}
|
}
|
|
void SellRuleDlg::requestListRules(SellRuleDlg* app)
|
{
|
try {
|
list<SellRule> rules = MyApi::listSellRules();
|
|
app->listRules.SetRedraw(false);
|
app->listRules.DeleteAllItems();
|
app->ruleList = rules;
|
int index = 0;
|
list<string> TYPES = get_price_types();
|
for (list<SellRule>::iterator ele = app->ruleList.begin(); ele != app->ruleList.end(); ++ele) {
|
SellRule rule = *ele;
|
|
app->listRules.InsertItem(index, rule.id_);
|
|
app->listRules.SetItemText(index, 0, rule.code);
|
list<string>::iterator its = TYPES.begin();
|
std::advance(its, rule.sell_price_type);
|
string price_type = *its;
|
CString conditionDesc = L"";
|
//通过量来卖
|
if (rule.type == 2) {
|
if (rule.buy1_volume > 0) {
|
conditionDesc.Append(L"当【买1】低于【");
|
conditionDesc.Append(to_wstring(rule.buy1_volume).c_str());
|
conditionDesc.Append(L"】手,以【");
|
conditionDesc.Append(CString(price_type.c_str()));
|
conditionDesc.Append(L"】卖");
|
}
|
else {
|
conditionDesc.Append(L"当【最新价】低于【");
|
conditionDesc.Append(rule.buy1_price);
|
conditionDesc.Append(L"】,以【");
|
conditionDesc.Append(CString(price_type.c_str()));
|
conditionDesc.Append(L"】卖");
|
}
|
}
|
else if (rule.type == 1) {
|
conditionDesc.Append(L"当【买1】低于【");
|
conditionDesc.Append(to_wstring(rule.buy1_volume).c_str());
|
conditionDesc.Append(L"】手,撤买");
|
}
|
app->listRules.SetItemText(index, 1, conditionDesc);
|
app->listRules.SetItemText(index, 2, std::to_wstring(rule.sell_volume).c_str());
|
app->listRules.SetItemText(index, 3, rule.end_time);
|
app->listRules.SetItemText(index, 4, rule.excuted ? L"已执行" : L"未执行");
|
//app->listRules.SetItemText(index, 7, rule.id_);
|
//app->listRules.SetItemText(index, 8, rule.create_time);
|
if (rule.excuted) {
|
app->listRules.SetItemData(index, COLOR_RED);
|
}
|
index++;
|
}
|
app->listRules.SetRedraw(true);
|
}
|
catch (CString st) {
|
AfxMessageBox(st);
|
}
|
catch (wstring st) {
|
AfxMessageBox(CString(st.c_str()));
|
}
|
}
|
|
void SellRuleDlg::initEndTime3()
|
{
|
// 初始化结束时间
|
std::time_t now = std::time(nullptr);
|
string nowday = TimeUtil::toFormatString(now, "%Y-%m-%d");
|
nowday.append(" 14:50:00");
|
time_t max_t = TimeUtil::toTimestamp(nowday, "%Y-%m-%d %H:%M:%S");
|
now += 60 * 10;
|
if (now > max_t) {
|
now = max_t;
|
}
|
// 将时间戳转换为本地时间
|
std::tm local_time;
|
localtime_s(&local_time, &now);
|
char buffer[20];
|
//%Y-%m-%d %H:%M:%S
|
std::strftime(buffer, sizeof(buffer), "%H:%M:%S", &local_time);
|
CString time_str = CString(buffer);
|
editEndTime3.SetWindowTextW(time_str);
|
}
|
|
CodePosition SellRuleDlg::getCodePosition(string code)
|
{
|
|
string result = NetworkApi::get_code_position_info(code);
|
auto doc = JsonUtil::parseUTF16(result);
|
if (doc.IsObject()) {
|
int total = doc[L"data"][L"total"].GetInt();
|
int available = doc[L"data"][L"available"].GetInt();
|
CodePosition codePosition;
|
codePosition.total = total;
|
codePosition.available = available;
|
codePosition.sell_rules_count = doc[L"data"][L"sell_rules_count"].GetInt();
|
codePosition.costPrice = doc[L"data"][L"cost_price"].GetFloat();
|
|
list<int> sellVolumes;
|
if (doc[L"data"].HasMember(L"sell_orders")) {
|
auto sell_orders_array = doc[L"data"][L"sell_orders"].GetArray();
|
|
for (int i = 0; i < sell_orders_array.Size(); i++) {
|
sellVolumes.push_back(sell_orders_array[i].GetInt());
|
}
|
}
|
codePosition.sell_orders = sellVolumes;
|
return codePosition;
|
}
|
throw wstring(L"尚未获取到持仓");
|
}
|
|
void SellRuleDlg::showBuy1Money(string code)
|
{
|
if (code.length() != 6) {
|
return;
|
}
|
CString volume_str;
|
editBuy1Volume.GetWindowTextW(volume_str);
|
if (volume_str.GetLength() <= 0) {
|
return;
|
}
|
|
if (codePriceMap.find(code) == codePriceMap.end()) {
|
return;
|
}
|
|
int volume = stoi(StringUtil::cstring2String(volume_str).c_str());
|
|
|
|
string price_str = codePriceMap[code];
|
double price = stod(price_str.c_str());
|
|
this->editBuy1Volume.SetWindowTextW(to_wstring(volume).c_str());
|
|
int money = (int)(volume * 100 * price);
|
CString money_str;
|
if (money > 100000000) {
|
double money_f = money / 1000000 / 100.0f;
|
money_str.Append(CString(StringUtil::toString(money_f, 2).c_str()));
|
money_str.Append(L"亿");
|
}
|
else {
|
double money_f = round(money / 100.0f) / 100;
|
money_str.Append(CString(StringUtil::toString(money_f, 2).c_str()));
|
money_str.Append(L"万");
|
}
|
this->labelBuy1Money.SetWindowTextW(money_str);
|
|
}
|
|
|
|
void SellRuleDlg::OnBnClickedButtonDelete()
|
{
|
CString id;
|
this->labelID.GetWindowTextW(id);
|
if (id.GetLength() < 1) {
|
AfxMessageBox(L"尚未选中代码");
|
return;
|
}
|
string result = NetworkApi::del_sell_rule(id);
|
rapidjson::GenericDocument<rapidjson::UTF16<>> doc = JsonUtil::parseUTF16(result);
|
if (doc[L"code"].GetInt() == 0) {
|
MessageBox(L"删除成功", L"提示", MB_TASKMODAL);
|
requestListRules(this);
|
}
|
else {
|
AfxMessageBox(doc[L"msg"].GetString());
|
}
|
}
|
|
|
void SellRuleDlg::OnBnClickedButtonAdd()
|
{
|
CString id;
|
CString code;
|
CString buy1Volume;
|
CString buy1Price = L"";
|
CString sellVolume;
|
int sellPriceType = comboSellPriceType.GetCurSel();
|
CString endTime;
|
this->labelID.GetWindowTextW(id);
|
this->editBuy1Volume.GetWindowTextW(buy1Volume);
|
this->editCode.GetWindowTextW(code);
|
this->editSellVolume.GetWindowTextW(sellVolume);
|
this->editEndTime.GetWindowTextW(endTime);
|
if (id.GetLength() > 0) {
|
AfxMessageBox(L"请先清除数据");
|
return;
|
}
|
if (code.GetLength() != 6) {
|
AfxMessageBox(L"代码输入不正确");
|
return;
|
}
|
if (buy1Volume.GetLength() < 1) {
|
AfxMessageBox(L"请输入买1量");
|
return;
|
}
|
if (sellVolume.GetLength() < 1) {
|
AfxMessageBox(L"请输入卖量");
|
return;
|
}
|
|
if (endTime.GetLength() < 1) {
|
AfxMessageBox(L"请输入生效截止时间");
|
return;
|
}
|
|
int buy1Volume_int = stoi(StringUtil::cstring2String(buy1Volume));
|
|
rapidjson::StringBuffer buf;
|
rapidjson::PrettyWriter<rapidjson::StringBuffer> writer(buf);
|
writer.StartObject();
|
writer.Key("code");
|
writer.String(StringUtil::cstring2String(code).c_str());
|
writer.Key("buy1_volume");
|
writer.Int(buy1Volume_int * 100);
|
|
writer.Key("buy1_price");
|
writer.String(StringUtil::cstring2String(buy1Price).c_str());
|
|
writer.Key("sell_volume");
|
writer.Int(stoi(StringUtil::cstring2String(sellVolume)));
|
|
writer.Key("sell_price_type");
|
writer.Int(sellPriceType);
|
|
writer.Key("end_time");
|
writer.String(StringUtil::cstring2String(endTime).c_str());
|
|
writer.Key("type");
|
writer.Int(2);
|
|
writer.EndObject();
|
const char* json_content = buf.GetString();
|
string result = NetworkApi::add_sell_rule(JsonUtil::parseUTF8(json_content));
|
rapidjson::GenericDocument<rapidjson::UTF16<>> doc = JsonUtil::parseUTF16(result);
|
if (doc[L"code"].GetInt() == 0) {
|
MessageBox(L"添加成功", L"提示", MB_TASKMODAL);
|
requestListRules(this);
|
}
|
else {
|
AfxMessageBox(doc[L"msg"].GetString());
|
}
|
}
|
|
void SellRuleDlg::OnBnClickedButtonUpdate()
|
{
|
CString id;
|
CString code;
|
CString buy1Volume;
|
CString buy1Price = L"";
|
CString sellVolume;
|
int sellPriceType = comboSellPriceType.GetCurSel();
|
CString endTime;
|
this->labelID.GetWindowTextW(id);
|
this->editBuy1Volume.GetWindowTextW(buy1Volume);
|
this->editCode.GetWindowTextW(code);
|
this->editSellVolume.GetWindowTextW(sellVolume);
|
this->editEndTime.GetWindowTextW(endTime);
|
if (id.GetLength() == 0) {
|
AfxMessageBox(L"请先选择数据");
|
return;
|
}
|
if (code.GetLength() != 6) {
|
AfxMessageBox(L"代码输入不正确");
|
return;
|
}
|
if (buy1Volume.GetLength() < 1) {
|
AfxMessageBox(L"请输入买1量");
|
return;
|
}
|
if (sellVolume.GetLength() < 1) {
|
AfxMessageBox(L"请输入卖量");
|
return;
|
}
|
|
if (endTime.GetLength() < 1) {
|
AfxMessageBox(L"请输入生效截止时间");
|
return;
|
}
|
|
int buy1Volume_int = stoi(StringUtil::cstring2String(buy1Volume));
|
|
rapidjson::StringBuffer buf;
|
rapidjson::PrettyWriter<rapidjson::StringBuffer> writer(buf);
|
writer.StartObject();
|
writer.Key("id");
|
writer.String(StringUtil::cstring2String(id).c_str());
|
writer.Key("code");
|
writer.String(StringUtil::cstring2String(code).c_str());
|
writer.Key("buy1_volume");
|
writer.Int(buy1Volume_int * 100);
|
|
writer.Key("buy1_price");
|
writer.String(StringUtil::cstring2String(buy1Price).c_str());
|
|
writer.Key("sell_volume");
|
writer.Int(stoi(StringUtil::cstring2String(sellVolume)));
|
|
writer.Key("sell_price_type");
|
writer.Int(sellPriceType);
|
|
writer.Key("end_time");
|
writer.String(StringUtil::cstring2String(endTime).c_str());
|
writer.EndObject();
|
const char* json_content = buf.GetString();
|
string result = NetworkApi::update_sell_rule(JsonUtil::parseUTF8(json_content));
|
rapidjson::GenericDocument<rapidjson::UTF16<>> doc = JsonUtil::parseUTF16(result);
|
if (doc[L"code"].GetInt() == 0) {
|
MessageBox(L"修改成功", L"提示", MB_TASKMODAL);
|
requestListRules(this);
|
}
|
else {
|
AfxMessageBox(doc[L"msg"].GetString());
|
}
|
}
|
|
|
|
void SellRuleDlg::OnLvnItemchangedListRules(NMHDR* pNMHDR, LRESULT* pResult)
|
{
|
NMLISTVIEW* pLV = reinterpret_cast<NMLISTVIEW*>(pNMHDR);
|
// 检查是否为行选中事件,且为选中状态,避免重复触发
|
if ((pLV->uChanged & LVIF_STATE) && (pLV->uNewState & LVIS_SELECTED))
|
{
|
int rowIndex = pLV->iItem;
|
std::list<SellRule>::iterator ele = ruleList.begin();
|
std::advance(ele, rowIndex);
|
SellRule rule = *ele;
|
showDetail(rule);
|
}
|
*pResult = 0;
|
}
|
|
|
void SellRuleDlg::OnNMCustomdrawListRules(NMHDR* pNMHDR, LRESULT* pResult)
|
{
|
LPNMCUSTOMDRAW pNMCD = reinterpret_cast<LPNMCUSTOMDRAW>(pNMHDR);
|
NMLVCUSTOMDRAW* pLVCD = reinterpret_cast<NMLVCUSTOMDRAW*>(pNMHDR);
|
// TODO: 在此添加控件通知处理程序代码
|
|
NMCUSTOMDRAW nmCustomDraw = pLVCD->nmcd;
|
|
if (CDDS_PREPAINT == pLVCD->nmcd.dwDrawStage)
|
{
|
*pResult = CDRF_NOTIFYITEMDRAW;
|
}
|
else if (CDDS_ITEMPREPAINT == pLVCD->nmcd.dwDrawStage)
|
{
|
//整行处理
|
if (COLOR_RED == nmCustomDraw.lItemlParam)
|
{
|
pLVCD->clrText = RGB(206, 38, 26);
|
}
|
else if (COLOR_DEFAULT == nmCustomDraw.lItemlParam)
|
{
|
|
pLVCD->clrText = RGB(96, 96, 96);
|
}
|
*pResult = CDRF_NOTIFYSUBITEMDRAW;
|
}//这上面的都是默认的不用理
|
else if ((CDDS_ITEMPREPAINT | CDDS_SUBITEM) == pLVCD->nmcd.dwDrawStage)
|
{
|
*pResult = 0;
|
// 暂时不处理每一列
|
return;
|
}
|
|
}
|
|
std::list<string> SellRuleDlg::get_price_types()
|
{
|
std::list<string> types;
|
types.push_back("价格笼子");
|
types.push_back("跌停价");
|
types.push_back("涨停价");
|
types.push_back("现价");
|
types.push_back("买5价");
|
return types;
|
}
|
|
|
|
void SellRuleDlg::OnBnClickedButtonClear2()
|
{
|
labelId1.SetWindowTextW(L"");
|
editBuy1Price1.SetWindowTextW(L"");
|
editCode1.SetWindowTextW(L"");
|
editSellVolume1.SetWindowTextW(L"");
|
editEndTime1.SetWindowTextW(L"09:24:59");
|
labelPosition1.SetWindowTextW(L"");
|
}
|
|
|
void SellRuleDlg::OnBnClickedButtonDelete2()
|
{
|
CString id;
|
this->labelId1.GetWindowTextW(id);
|
if (id.GetLength() < 1) {
|
AfxMessageBox(L"尚未选中代码");
|
return;
|
}
|
string result = NetworkApi::del_sell_rule(id);
|
rapidjson::GenericDocument<rapidjson::UTF16<>> doc = JsonUtil::parseUTF16(result);
|
if (doc[L"code"].GetInt() == 0) {
|
MessageBox(L"删除成功", L"提示", MB_TASKMODAL);
|
requestListRules(this);
|
}
|
else {
|
AfxMessageBox(doc[L"msg"].GetString());
|
}
|
}
|
|
|
void SellRuleDlg::OnBnClickedButtonAdd2()
|
{
|
CString id;
|
CString code;
|
CString buy1Volume = L"0";
|
CString buy1Price;
|
CString sellVolume;
|
int sellPriceType = comboSellPriceType1.GetCurSel();
|
CString endTime;
|
this->labelId1.GetWindowTextW(id);
|
this->editBuy1Price1.GetWindowTextW(buy1Price);
|
this->editCode1.GetWindowTextW(code);
|
this->editSellVolume1.GetWindowTextW(sellVolume);
|
this->editEndTime1.GetWindowTextW(endTime);
|
if (id.GetLength() > 0) {
|
AfxMessageBox(L"请先清除数据");
|
return;
|
}
|
if (code.GetLength() != 6) {
|
AfxMessageBox(L"代码输入不正确");
|
return;
|
}
|
if (buy1Volume.GetLength() < 1) {
|
AfxMessageBox(L"请输入买1量");
|
return;
|
}
|
if (sellVolume.GetLength() < 1) {
|
AfxMessageBox(L"请输入卖量");
|
return;
|
}
|
|
if (endTime.GetLength() < 1) {
|
AfxMessageBox(L"请输入生效截止时间");
|
return;
|
}
|
|
int buy1Volume_int = stoi(StringUtil::cstring2String(buy1Volume));
|
|
rapidjson::StringBuffer buf;
|
rapidjson::PrettyWriter<rapidjson::StringBuffer> writer(buf);
|
writer.StartObject();
|
writer.Key("code");
|
writer.String(StringUtil::cstring2String(code).c_str());
|
writer.Key("buy1_volume");
|
writer.Int(buy1Volume_int * 100);
|
|
writer.Key("buy1_price");
|
writer.String(StringUtil::cstring2String(buy1Price).c_str());
|
|
writer.Key("sell_volume");
|
writer.Int(stoi(StringUtil::cstring2String(sellVolume)));
|
|
writer.Key("sell_price_type");
|
writer.Int(sellPriceType);
|
|
writer.Key("end_time");
|
writer.String(StringUtil::cstring2String(endTime).c_str());
|
|
writer.Key("type");
|
writer.Int(2);
|
|
writer.EndObject();
|
const char* json_content = buf.GetString();
|
string result = NetworkApi::add_sell_rule(JsonUtil::parseUTF8(json_content));
|
rapidjson::GenericDocument<rapidjson::UTF16<>> doc = JsonUtil::parseUTF16(result);
|
if (doc[L"code"].GetInt() == 0) {
|
MessageBox(L"添加成功", L"提示", MB_TASKMODAL);
|
requestListRules(this);
|
}
|
else {
|
AfxMessageBox(doc[L"msg"].GetString());
|
}
|
}
|
|
|
void SellRuleDlg::OnClose()
|
{
|
HWND hwnd = GetSafeHwnd();
|
RECT rect;
|
Win32Util::getWindowRect(hwnd, &rect);
|
ConfigUtil::setSellRuleDialogShowPos(rect.left, rect.top);
|
CDialogEx::OnClose();
|
}
|
|
|
|
|
void SellRuleDlg::OnBnClickedButtonUpdate2()
|
{
|
|
CString id;
|
CString code;
|
CString buy1Volume = L"0";
|
CString buy1Price;
|
CString sellVolume;
|
int sellPriceType = comboSellPriceType1.GetCurSel();
|
CString endTime;
|
this->labelId1.GetWindowTextW(id);
|
this->editBuy1Price1.GetWindowTextW(buy1Price);
|
this->editCode1.GetWindowTextW(code);
|
this->editSellVolume1.GetWindowTextW(sellVolume);
|
this->editEndTime1.GetWindowTextW(endTime);
|
if (id.GetLength() == 0) {
|
AfxMessageBox(L"请先选择数据");
|
return;
|
}
|
if (code.GetLength() != 6) {
|
AfxMessageBox(L"代码输入不正确");
|
return;
|
}
|
if (buy1Volume.GetLength() < 1) {
|
AfxMessageBox(L"请输入买1量");
|
return;
|
}
|
if (sellVolume.GetLength() < 1) {
|
AfxMessageBox(L"请输入卖量");
|
return;
|
}
|
|
if (endTime.GetLength() < 1) {
|
AfxMessageBox(L"请输入生效截止时间");
|
return;
|
}
|
|
int buy1Volume_int = stoi(StringUtil::cstring2String(buy1Volume));
|
|
rapidjson::StringBuffer buf;
|
rapidjson::PrettyWriter<rapidjson::StringBuffer> writer(buf);
|
writer.StartObject();
|
writer.Key("id");
|
writer.String(StringUtil::cstring2String(id).c_str());
|
writer.Key("code");
|
writer.String(StringUtil::cstring2String(code).c_str());
|
writer.Key("buy1_volume");
|
writer.Int(buy1Volume_int * 100);
|
|
writer.Key("buy1_price");
|
writer.String(StringUtil::cstring2String(buy1Price).c_str());
|
|
writer.Key("sell_volume");
|
writer.Int(stoi(StringUtil::cstring2String(sellVolume)));
|
|
writer.Key("sell_price_type");
|
writer.Int(sellPriceType);
|
|
writer.Key("end_time");
|
writer.String(StringUtil::cstring2String(endTime).c_str());
|
writer.EndObject();
|
const char* json_content = buf.GetString();
|
string result = NetworkApi::update_sell_rule(JsonUtil::parseUTF8(json_content));
|
rapidjson::GenericDocument<rapidjson::UTF16<>> doc = JsonUtil::parseUTF16(result);
|
if (doc[L"code"].GetInt() == 0) {
|
MessageBox(L"修改成功", L"提示", MB_TASKMODAL);
|
requestListRules(this);
|
}
|
else {
|
AfxMessageBox(doc[L"msg"].GetString());
|
}
|
}
|
|
|
void SellRuleDlg::OnBnClickedButtonFillVolume()
|
{
|
CString code;
|
this->editCode.GetWindowTextW(code);
|
try {
|
Buy1Info info = MyApi::getBuy1Info(StringUtil::cstring2String(code));
|
codePriceMap[StringUtil::cstring2String(code)] = StringUtil::toString(info.price, 2);
|
int volume = (info.volume / 100 ) * 2 / 5;
|
this->editBuy1Volume.SetWindowTextW(to_wstring(volume).c_str());
|
showBuy1Money(StringUtil::cstring2String(code));
|
}
|
catch (CString msg) {
|
AfxMessageBox(msg);
|
}
|
catch (wstring msg) {
|
AfxMessageBox(CString(msg.c_str()));
|
}
|
}
|
|
BOOL SellRuleDlg::PreTranslateMessage(MSG* pMsg)
|
{
|
|
if (pMsg->message == WM_KEYDOWN && pMsg->wParam == VK_RETURN) // 按下 Enter 键
|
{
|
if (CWnd::GetFocus() == GetDlgItem(IDC_EDIT_BUY1_VOLUME)) {
|
// 处理该控件内的回车事件
|
CString code;
|
this->editCode.GetWindowTextW(code);
|
showBuy1Money(StringUtil::cstring2String(code));
|
}
|
|
return TRUE;
|
}
|
|
return CDialogEx::PreTranslateMessage(pMsg);
|
}
|
|
|
void SellRuleDlg::OnBnClickedButtonClear3()
|
{
|
labelID3.SetWindowTextW(L"");
|
editBuy1Volume3.SetWindowTextW(L"");
|
editCode3.SetWindowTextW(L"");
|
|
initEndTime3();
|
}
|
|
|
void SellRuleDlg::OnBnClickedButtonDelete4()
|
{
|
CString id;
|
this->labelID3.GetWindowTextW(id);
|
if (id.GetLength() < 1) {
|
AfxMessageBox(L"尚未选中代码");
|
return;
|
}
|
string result = NetworkApi::del_sell_rule(id);
|
rapidjson::GenericDocument<rapidjson::UTF16<>> doc = JsonUtil::parseUTF16(result);
|
if (doc[L"code"].GetInt() == 0) {
|
MessageBox(L"删除成功", L"提示", MB_TASKMODAL);
|
requestListRules(this);
|
}
|
else {
|
AfxMessageBox(doc[L"msg"].GetString());
|
}
|
}
|
|
|
void SellRuleDlg::OnBnClickedButtonUpdate3()
|
{
|
CString id;
|
CString code;
|
CString buy1Volume;
|
CString buy1Price = L"";
|
CString endTime;
|
this->labelID3.GetWindowTextW(id);
|
this->editBuy1Volume3.GetWindowTextW(buy1Volume);
|
this->editCode3.GetWindowTextW(code);
|
this->editEndTime3.GetWindowTextW(endTime);
|
if (id.GetLength() == 0) {
|
AfxMessageBox(L"请先选择数据");
|
return;
|
}
|
if (code.GetLength() != 6) {
|
AfxMessageBox(L"代码输入不正确");
|
return;
|
}
|
if (buy1Volume.GetLength() < 1) {
|
AfxMessageBox(L"请输入买1量");
|
return;
|
}
|
|
if (endTime.GetLength() < 1) {
|
AfxMessageBox(L"请输入生效截止时间");
|
return;
|
}
|
|
int buy1Volume_int = stoi(StringUtil::cstring2String(buy1Volume));
|
|
rapidjson::StringBuffer buf;
|
rapidjson::PrettyWriter<rapidjson::StringBuffer> writer(buf);
|
writer.StartObject();
|
writer.Key("id");
|
writer.String(StringUtil::cstring2String(id).c_str());
|
writer.Key("code");
|
writer.String(StringUtil::cstring2String(code).c_str());
|
writer.Key("buy1_volume");
|
writer.Int(buy1Volume_int * 100);
|
|
writer.Key("buy1_price");
|
writer.String(StringUtil::cstring2String(buy1Price).c_str());
|
|
writer.Key("end_time");
|
writer.String(StringUtil::cstring2String(endTime).c_str());
|
writer.EndObject();
|
const char* json_content = buf.GetString();
|
string result = NetworkApi::update_sell_rule(JsonUtil::parseUTF8(json_content));
|
rapidjson::GenericDocument<rapidjson::UTF16<>> doc = JsonUtil::parseUTF16(result);
|
if (doc[L"code"].GetInt() == 0) {
|
MessageBox(L"修改成功", L"提示", MB_TASKMODAL);
|
requestListRules(this);
|
}
|
else {
|
AfxMessageBox(doc[L"msg"].GetString());
|
}
|
}
|
|
|
void SellRuleDlg::OnBnClickedButtonAdd3()
|
{
|
CString id;
|
CString code;
|
CString buy1Volume;
|
CString buy1Price = L"";
|
CString endTime;
|
this->labelID3.GetWindowTextW(id);
|
this->editBuy1Volume3.GetWindowTextW(buy1Volume);
|
this->editCode3.GetWindowTextW(code);
|
this->editEndTime3.GetWindowTextW(endTime);
|
if (id.GetLength() > 0) {
|
AfxMessageBox(L"请先清除数据");
|
return;
|
}
|
if (code.GetLength() != 6) {
|
AfxMessageBox(L"代码输入不正确");
|
return;
|
}
|
if (buy1Volume.GetLength() < 1) {
|
AfxMessageBox(L"请输入买1量");
|
return;
|
}
|
|
if (endTime.GetLength() < 1) {
|
AfxMessageBox(L"请输入生效截止时间");
|
return;
|
}
|
|
int buy1Volume_int = stoi(StringUtil::cstring2String(buy1Volume));
|
|
rapidjson::StringBuffer buf;
|
rapidjson::PrettyWriter<rapidjson::StringBuffer> writer(buf);
|
writer.StartObject();
|
writer.Key("code");
|
writer.String(StringUtil::cstring2String(code).c_str());
|
writer.Key("buy1_volume");
|
writer.Int(buy1Volume_int * 100);
|
|
writer.Key("buy1_price");
|
writer.String(StringUtil::cstring2String(buy1Price).c_str());
|
|
writer.Key("end_time");
|
writer.String(StringUtil::cstring2String(endTime).c_str());
|
|
writer.Key("type");
|
writer.Int(1);
|
|
writer.EndObject();
|
const char* json_content = buf.GetString();
|
string result = NetworkApi::add_sell_rule(JsonUtil::parseUTF8(json_content));
|
rapidjson::GenericDocument<rapidjson::UTF16<>> doc = JsonUtil::parseUTF16(result);
|
if (doc[L"code"].GetInt() == 0) {
|
MessageBox(L"添加成功", L"提示", MB_TASKMODAL);
|
requestListRules(this);
|
}
|
else {
|
AfxMessageBox(doc[L"msg"].GetString());
|
}
|
}
|
|
|
void SellRuleDlg::OnBnClickedButtonFillVolume2()
|
{
|
CString code;
|
this->editCode3.GetWindowTextW(code);
|
|
string result = NetworkApi::get_buy1_info(StringUtil::cstring2String(code));
|
auto doc = JsonUtil::parseUTF16(result);
|
if (doc.IsObject()) {
|
if (doc[L"code"].GetInt() == 0) {
|
if (doc.HasMember(L"data")) {
|
int volume = doc[L"data"][L"volume"].GetInt();
|
volume = volume / 100 / 2;
|
this->editBuy1Volume3.SetWindowTextW(to_wstring(volume).c_str());
|
}
|
}
|
else {
|
AfxMessageBox(doc[L"msg"].GetString());
|
}
|
|
}
|
}
|
|
|
void SellRuleDlg::OnBnClickedButtonGetPosition()
|
{
|
try {
|
CString code;
|
this->editCode.GetWindowTextW(code);
|
if (code.GetLength() != 6) {
|
throw wstring(L"代码输入错误");
|
}
|
CodePosition codePosition = getCodePosition(StringUtil::cstring2String(code));
|
CString st;
|
st.Append(to_wstring(codePosition.available).c_str());
|
st.Append(L"/");
|
st.Append(to_wstring(codePosition.total).c_str());
|
labelPosition.SetWindowTextW(st);
|
}
|
catch (wstring msg) {
|
AfxMessageBox(msg.c_str());
|
}
|
}
|
|
|
void SellRuleDlg::OnBnClickedButtonGetPosition2()
|
{
|
try {
|
CString code;
|
this->editCode1.GetWindowTextW(code);
|
if (code.GetLength() != 6) {
|
throw wstring(L"代码输入错误");
|
}
|
CodePosition codePosition = getCodePosition(StringUtil::cstring2String(code));
|
CString st;
|
st.Append(to_wstring(codePosition.available).c_str());
|
st.Append(L"/");
|
st.Append(to_wstring(codePosition.total).c_str());
|
labelPosition1.SetWindowTextW(st);
|
}
|
catch (wstring msg) {
|
AfxMessageBox(msg.c_str());
|
}
|
}
|