From 8ea6d363df77de2dca288397da8d4f9c3d3a5c4d Mon Sep 17 00:00:00 2001
From: admin <weikou2014>
Date: 星期五, 18 十月 2024 18:41:57 +0800
Subject: [PATCH] '项目完善'

---
 FloatTrade/SellRuleDlg.cpp |  147 ++++++++++++++++++++----------------------------
 1 files changed, 62 insertions(+), 85 deletions(-)

diff --git a/FloatTrade/SellRuleDlg.cpp b/FloatTrade/SellRuleDlg.cpp
index 7c3b769..059ecd3 100644
--- a/FloatTrade/SellRuleDlg.cpp
+++ b/FloatTrade/SellRuleDlg.cpp
@@ -13,6 +13,7 @@
 #include <ctime>
 #include <cstring>
 #include "../common/TimeUtil.h"
+#include "MyApi.h"
 
 
 // SellRuleDlg 瀵硅瘽妗�
@@ -198,80 +199,64 @@
 
 void SellRuleDlg::requestListRules(SellRuleDlg* app)
 {
-	string result = NetworkApi::list_sell_rules();
-	auto doc = JsonUtil::parseUTF16(result);
-	if (doc.IsObject()) {
-		if (doc[L"code"].GetInt() == 0) {
-			auto array = doc[L"data"].GetArray();
-			list<SellRule> rules;
-			for (int i = 0; i < array.Size(); i++) {
-				SellRule rule;
-				rule.code = array[i][L"code"].GetString();
-				rule.id_ = array[i][L"id_"].GetString();
-				rule.buy1_volume = array[i][L"buy1_volume"].GetInt() / 100;
-				rule.buy1_price = array[i][L"buy1_price"].GetString();
-				rule.sell_volume = array[i][L"sell_volume"].GetInt();
-				rule.sell_price_type = array[i][L"sell_price_type"].GetInt();
-				rule.create_time = array[i][L"create_time"].GetString();
-				rule.excuted = array[i][L"excuted"].GetInt();
-				rule.end_time = array[i][L"end_time"].GetString();
-				rule.type = array[i][L"type"].GetInt();
-				rules.push_back(rule);
-			}
-			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;
+	try {
+		list<SellRule> rules = MyApi::listSellRules();
 
-				app->listRules.InsertItem(index, rule.id_);
+		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.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) {
+			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(L"銆戞墜锛屼互銆�");
+					conditionDesc.Append(CString(price_type.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);
+				else {
+					conditionDesc.Append(L"褰撱�愭渶鏂颁环銆戜綆浜庛��");
+					conditionDesc.Append(rule.buy1_price);
+					conditionDesc.Append(L"銆戯紝浠ャ��");
+					conditionDesc.Append(CString(price_type.c_str()));
+					conditionDesc.Append(L"銆戝崠");
 				}
-				index++;
 			}
-
+			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);
 	}
-	else {
-		AfxMessageBox(doc[L"msg"].GetString());
+	catch (CString st) {
+		AfxMessageBox(st);
+	}
+	catch (wstring st) {
+		AfxMessageBox(CString(st.c_str()));
 	}
 }
 
@@ -794,27 +779,19 @@
 {
 	CString code;
 	this->editCode.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();
-				double price = doc[L"data"][L"price"].GetDouble();
-				codePriceMap[StringUtil::cstring2String(code)] = StringUtil::toString(price, 2);
-				volume = volume / 100 / 3;
-				this->editBuy1Volume.SetWindowTextW(to_wstring(volume).c_str());
-				showBuy1Money(StringUtil::cstring2String(code));
-			}
-		}
-		else {
-			AfxMessageBox(doc[L"msg"].GetString());
-		}
-
+	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)
@@ -828,7 +805,7 @@
 			this->editCode.GetWindowTextW(code);
 			showBuy1Money(StringUtil::cstring2String(code));
 		}
-		
+
 		return TRUE;
 	}
 

--
Gitblit v1.8.0