From 1a8f39e83dd72e1a672f83e151c149d15679c3eb Mon Sep 17 00:00:00 2001
From: admin <weikou2014>
Date: 星期一, 04 十二月 2023 16:43:18 +0800
Subject: [PATCH] 'bug修复'

---
 FloatTrade/FloatTradeDlg.cpp |  142 +++++++++++++++++++++++++++-------------------
 1 files changed, 83 insertions(+), 59 deletions(-)

diff --git a/FloatTrade/FloatTradeDlg.cpp b/FloatTrade/FloatTradeDlg.cpp
index 2c29ebf..abdbe71 100644
--- a/FloatTrade/FloatTradeDlg.cpp
+++ b/FloatTrade/FloatTradeDlg.cpp
@@ -86,7 +86,7 @@
 
 void CFloatTradeDlg::showTips(CString message, int msgType)
 {
-	TipDlg *p_MsgWindow=new TipDlg(this);
+	TipDlg* p_MsgWindow = new TipDlg(this);
 	p_MsgWindow->Create(IDD_DIALOG_TIPS, this);
 	if (msgType == MSG_TYPE_INFO) {
 		msgColor = COLOR_BLACK;
@@ -162,25 +162,25 @@
 {
 
 	//璇锋眰缃戠粶鑾峰彇娑堟伅
-		try {
-			wstring result = NetworkApi::getCodeDesc(code);
-			CString resultC(result.c_str());
-			context->setMsg(resultC, MSG_TYPE_INFO, FALSE);
-		}
-		catch (wstring st) {
-			CString msgc;
-			msgc.Append(CString(code.c_str()));
-			msgc.Append(L"锛�");
-			msgc.Append(st.c_str());
-			context->setMsg(msgc, MSG_TYPE_FAIL);
-		}
-		catch (CString st) {
-			CString msgc;
-			msgc.Append(CString(code.c_str()));
-			msgc.Append(L"锛�");
-			msgc.Append(st);
-			context->setMsg(msgc, MSG_TYPE_FAIL);
-		}
+	try {
+		wstring result = NetworkApi::getCodeDesc(code);
+		CString resultC(result.c_str());
+		context->setMsg(resultC, MSG_TYPE_INFO, FALSE);
+	}
+	catch (wstring st) {
+		CString msgc;
+		msgc.Append(CString(code.c_str()));
+		msgc.Append(L"锛�");
+		msgc.Append(st.c_str());
+		context->setMsg(msgc, MSG_TYPE_FAIL);
+	}
+	catch (CString st) {
+		CString msgc;
+		msgc.Append(CString(code.c_str()));
+		msgc.Append(L"锛�");
+		msgc.Append(st);
+		context->setMsg(msgc, MSG_TYPE_FAIL);
+	}
 }
 
 void CFloatTradeDlg::selectSellVolume(string code, int percent)
@@ -195,14 +195,14 @@
 		CButton* pButton = (CButton*)GetDlgItem(v_ids[i]);
 		CString st;
 		st.Append(L"1/");
-		st.Append(to_wstring(i+1).c_str());
+		st.Append(to_wstring(i + 1).c_str());
 		if (i + 1 == percent) {
 			st.Append(L"鈥�");
 		}
 		pButton->SetWindowTextW(st);
 	}
 	sellPercentMap[code] = percent;
-	if (codePosition.available <=0){
+	if (codePosition.available <= 0) {
 		editLeftVolume.SetWindowTextW(L"0");
 		return;
 	}
@@ -232,25 +232,29 @@
 		string result = NetworkApi::get_code_position_info(code);
 		auto doc = JsonUtil::parseUTF16(result);
 		if (doc.IsObject()) {
-		  context->codePosition.total = doc[L"data"][L"total"].GetInt();
-		  context->codePosition.available = doc[L"data"][L"available"].GetInt();
-		  context->codePosition.sell_rules_count = doc[L"data"][L"sell_rules_count"].GetInt();
-		  //璁剧疆鍐呭
-		  context->showCodePositionInfo();
+			context->codePosition.total = doc[L"data"][L"total"].GetInt();
+			context->codePosition.available = doc[L"data"][L"available"].GetInt();
+			context->codePosition.sell_rules_count = doc[L"data"][L"sell_rules_count"].GetInt();
+			//璁剧疆鍐呭
+			context->showCodePositionInfo();
 
-		  if (showCodeDesc && doc[_T("data")].HasMember(L"code_info"))
-		  {
-			  wstring c = doc[_T("data")][_T("code_info")].GetArray()[0].GetString();
-			  wstring name = L"";
-			  if (!doc[_T("data")][_T("code_info")].GetArray()[1].IsNull()) {
-				  name = doc[_T("data")][_T("code_info")].GetArray()[1].GetString();
-			  }
-			  wstring desc = doc[_T("data")][_T("desc")].GetString();
-			  wstring fresult;
-			  fresult.append(c).append(L" ").append(name).append(L"  ").append(desc);
-			  CString resultC(fresult.c_str());
-			  context->setMsg(resultC, MSG_TYPE_INFO, FALSE);
-		  }
+			if (showCodeDesc && doc[_T("data")].HasMember(L"code_info"))
+			{
+				auto data = doc[_T("data")].GetObjectW();
+				wstring c = data[_T("code_info")].GetArray()[0].GetString();
+				wstring name = L"";
+				if (!data[_T("code_info")].GetArray()[1].IsNull()) {
+					name = data[_T("code_info")].GetArray()[1].GetString();
+				}
+				if (data.HasMember(L"desc")) {
+					wstring desc = data[_T("desc")].GetString();
+					wstring fresult;
+					fresult.append(c).append(L" ").append(name).append(L"  ").append(desc);
+					CString resultC(fresult.c_str());
+					context->setMsg(resultC, MSG_TYPE_INFO, FALSE);
+				}
+
+			}
 		}
 	}
 	catch (wstring st) {
@@ -264,7 +268,10 @@
 		Sleep(delayMs);
 	}
 	try {
+		// 娴嬭瘯
 		string result = NetworkApi::get_sell_result(order_ref);
+		//string result =  string(StringUtil::cstring2String(L"{\"code\":0,\"data\":{\"msg\":\"鎴愪氦\"}}"));
+
 		auto doc = JsonUtil::parseUTF16(result);
 		if (doc.IsObject()) {
 			if (doc[L"code"] == 0) {
@@ -287,7 +294,7 @@
 				CString code;
 				context->editCode.GetWindowText(code);
 				if (code && code.GetLength() == 6) {
-					requestCodePosition(StringUtil::cstring2String(code), context,FALSE);
+					requestCodePosition(StringUtil::cstring2String(code), context, FALSE);
 				}
 			}
 			else {
@@ -311,7 +318,7 @@
 void CFloatTradeDlg::showCodePositionInfo()
 {
 	labelTotalPosition.SetWindowTextW(std::to_wstring(codePosition.total).c_str());
-	labelSelledVolume.SetWindowTextW(std::to_wstring(codePosition.total- codePosition.available).c_str());
+	labelSelledVolume.SetWindowTextW(std::to_wstring(codePosition.total - codePosition.available).c_str());
 	editLeftVolume.SetWindowTextW(std::to_wstring(codePosition.available).c_str());
 	if (codePosition.sell_rules_count > 0) {
 		btnSellRule.SetWindowTextW(L"鐩澘涓婂崠鈥�");
@@ -592,8 +599,9 @@
 
 void CFloatTradeDlg::OnClickedBtnAlreadyCanceled()
 {
-	//CString st("娴嬭瘯123123");
-	//showTips(st);
+	//list<HWND> hwnds = Win32Util::searchWindow("鍓睆1");
+	//HWND hwnd = *(hwnds.begin());
+	//::SetWindowPos(hwnd, HWND_TOPMOST,0,0,0,0, SWP_NOMOVE | SWP_NOSIZE);
 	//return;
 
 	// 鎾ゅ崟
@@ -784,12 +792,13 @@
 
 void CFloatTradeDlg::OnClickedBtnSell()
 {
+
 	if (codePosition.total <= 0) {
 		setMsg(L"鏃犳寔浠�", MSG_TYPE_FAIL);
 		return;
 	}
 
-	if (codePosition.available<=0) {
+	if (codePosition.available <= 0) {
 		setMsg(L"宸插崠瀹�", MSG_TYPE_FAIL);
 		return;
 	}
@@ -811,29 +820,44 @@
 	}
 	//0-浠锋牸绗煎瓙 1-璺屽仠浠�  2-娑ㄥ仠浠� 3-鐜颁环
 	int sellPriceType = comboSellPriceType.GetCurSel();
-	if (sellPriceType < 0|| sellPriceType > 10) {
+	if (sellPriceType < 0 || sellPriceType > 10) {
 		setMsg(L"璇烽�夋嫨鍗栦环绫诲瀷", MSG_TYPE_FAIL);
 		return;
 	}
+
 	// 鍗�
 	try {
 		string code = getCode();
 		string result = NetworkApi::sell(code, sell_volume_int, sellPriceType, true);
+		//string result = string( StringUtil::cstring2String( L"{\"code\":0,\"data\":{\"orderRef\":123123}}"));
 		CString msg(code.c_str());
 		msg.Append(L"锛�");
 		auto doc = JsonUtil::parseUTF16(result);
-		if (doc[L"data"].HasMember(L"orderRef")) {
-			msg.Append(_T("鎻愪氦鍗栨垚鍔�"));
-			setMsg(msg, MSG_TYPE_SUCCESS);
-			string orderRef = StringUtil::cstring2String(doc[L"data"][L"orderRef"].GetString());
-			std::thread t1(requestSellResult, orderRef, this, 2000);
-			t1.detach();
+		if (doc.IsObject() && doc.HasMember(L"code")) {
+			if (doc[L"code"] == 0) {
+				if (doc[L"data"].HasMember(L"orderRef")) {
+					msg.Append(_T("鎻愪氦鍗栨垚鍔�"));
+					setMsg(msg, MSG_TYPE_SUCCESS);
+					string orderRef = std::to_string(doc[L"data"][L"orderRef"].GetInt());
+					std::thread t1(requestSellResult, orderRef, this, 2000);
+					t1.detach();
+				}
+				else {
+					msg.Append(doc[L"data"][L"orderStatusMsg"].GetString());
+					setMsg(msg, MSG_TYPE_FAIL);
+				}
+			}
+			else {
+				msg.Append(doc[L"msg"].GetString());
+				setMsg(msg, MSG_TYPE_FAIL);
+			}
 		}
 		else {
-			msg.Append(doc[L"data"][L"orderStatusMsg"].GetString());
+			msg.Append(L"瑙f瀽缁撴灉鍑洪敊");
 			setMsg(msg, MSG_TYPE_FAIL);
 		}
-		
+
+
 	}
 	catch (wstring st) {
 		CString msg(st.c_str());
@@ -917,7 +941,7 @@
 
 LRESULT CFloatTradeDlg::OnFloatMsg(WPARAM wParam, LPARAM lParam)
 {
-	
+
 	FloatMsg* pData = (FloatMsg*)lParam;
 
 	showTips(CString(pData->msg.c_str()), pData->msgType);
@@ -1117,9 +1141,9 @@
 	CString volume;
 	editLeftVolume.GetWindowText(volume);
 	SellRuleDlg dlg(code, volume);
-		//dlg.Create(IDD_BUY,this);
-		//dlg.ShowWindow(SW_SHOW);
-		//return;
+	//dlg.Create(IDD_BUY,this);
+	//dlg.ShowWindow(SW_SHOW);
+	//return;
 	INT_PTR nResponse = dlg.DoModal();
 }
 
@@ -1134,7 +1158,7 @@
 		if (v_ids[i] == nID) {
 			CString codew;
 			editCode.GetWindowTextW(codew);
-			selectSellVolume(StringUtil::cstring2String(codew) ,i + 1);
+			selectSellVolume(StringUtil::cstring2String(codew), i + 1);
 			break;
 		}
 	}

--
Gitblit v1.8.0