Forráskód Böngészése

开始优化网络错误提示

zhangyang 5 éve
szülő
commit
65939b90f8

+ 6 - 0
bin/Win32/Debug/zhipuzi_pay_plugin/skin/jiaoyijilu_wnd.xml

@@ -27,6 +27,12 @@
 					<ListHeaderItem text="订单号" enabled="false" dragable="false" />
 				</List>  
 			</HorizontalLayout>
+			<HorizontalLayout name="jiaoyijilu_error" padding="0,50,0,0" height="30">
+				<Control></Control>
+				<Label text="错误信息" font="2" width="120"></Label>
+				<Control></Control>
+			</HorizontalLayout>
+			<Control></Control>
 		</VerticalLayout>
 		<HorizontalLayout height="60">
 			<Button name="jiaoyijilu_list_last" width="70" height="36" padding="20,4,0,0" text="上一页" normalimage="file='Btn_White.png' corner='5,5,5,5'" hotimage="file='Btn_White_Hover.png' corner='5,5,5,5'" pushedimage="file='Btn_White_Click.png' corner='5,5,5,5'" />

+ 1 - 1
zhipuzi_pay_plugin/wnd/CJiaobanWnd.cpp

@@ -225,7 +225,7 @@ void CJiaobanWnd::HandleClickMsg(TNotifyUI& msg)
 
 	if (senderName == _T("jiaoban_closebtn"))
 	{
-		Close(IDCANCEL);
+		m_valueWnd->CloseJiaoban();
 		return;
 	}
 	else if (senderName == L"jiaoban_shangban")

+ 1 - 1
zhipuzi_pay_plugin/wnd/CJiaoyihuizongWnd.cpp

@@ -188,7 +188,7 @@ void CJiaoyihuizongWnd::HandleClickMsg(TNotifyUI& msg)
 
 	if (senderName == _T("jiaoyihuizong_closebtn"))
 	{
-		Close(IDCANCEL);
+		m_valueWnd->CloseJiaoyihuizong();
 		return;
 	}
 	else if (senderName == L"jiaoyihuizong_query")

+ 50 - 7
zhipuzi_pay_plugin/wnd/CJiaoyijiluWnd.cpp

@@ -25,6 +25,8 @@ void CJiaoyijiluWnd::Init()
 	std::string s_start = CLewaimaiTime::DatetimeToDateString(start);
 	pDateStart->SetText(CLewaimaiString::UTF8ToUnicode(s_start).c_str());
 
+	ShowError(false);
+
 	StartQuery();
 }
 
@@ -138,8 +140,7 @@ LRESULT CJiaoyijiluWnd::HandleMessage(UINT uMsg, WPARAM wParam, LPARAM lParam)
 }
 
 LRESULT CJiaoyijiluWnd::MessageHandler(UINT uMsg, WPARAM wParam, LPARAM lParam, bool& bHandled)
-{
-	
+{	
 	return false;
 }
 
@@ -188,8 +189,12 @@ void CJiaoyijiluWnd::HandleClickMsg(TNotifyUI& msg)
 
 	if (senderName == _T("jiaoyijilu_closebtn"))
 	{
+		if (m_is_query)
+		{
+			//如果正在网络查询,禁止关闭
+			return;
+		}
 		m_valueWnd->CloseJiaoyijilu();
-		return;
 	}
 	else if (senderName == L"jiaoyijilu_list_last")
 	{
@@ -200,6 +205,7 @@ void CJiaoyijiluWnd::HandleClickMsg(TNotifyUI& msg)
 	else if (senderName == L"jiaoyijilu_list_next")
 	{
 		m_curpage++;
+
 		this->StartQuery();
 	}
 	else if (senderName == L"jiaoyijilu_query")
@@ -290,17 +296,24 @@ void CJiaoyijiluWnd::StartRefreshWork()
 	std::string response;
 
 	std::string url = "/saomashoukuan/getlist";
-	CZhipuziHttpClient::Request(url.c_str(), params, response);
+	bool ret = CZhipuziHttpClient::Request(url.c_str(), params, response);
+
+	if (ret == false)
+	{
+		ShowError(true, L"网络错误,请检查网络设置!");
+		return;
+	}
 
 	rapidjson::Document document;
 	document.Parse(response.c_str());
 
-	LOG_INFO(response.c_str());
-
 	if (document.HasParseError())
 	{
 		LOG_INFO("parse response error!");
 		m_is_query = false;
+
+		ShowError(true, L"服务器错误");
+
 		return;
 	}
 
@@ -308,6 +321,9 @@ void CJiaoyijiluWnd::StartRefreshWork()
 	{
 		LOG_INFO("json error!");
 		m_is_query = false;
+
+		ShowError(true, L"服务器错误");
+
 		return;
 	}
 
@@ -316,12 +332,16 @@ void CJiaoyijiluWnd::StartRefreshWork()
 	if (errcode != 0)
 	{
 		LOG_INFO("response failed! message:" << document["errmsg"].GetString());
+
 		wstring errmsg = CLewaimaiString::UTF8ToUnicode(document["errmsg"].GetString());
-		MessageBox(GetHWND(), errmsg.c_str(), L"提示", MB_OK);
+		ShowError(true, errmsg);
+
 		m_is_query = false;
 		return;
 	}
 
+	ShowError(false);
+
 	rapidjson::Value& data = document["data"];
 
 	std::string total_num = data["total_num"].GetString();
@@ -330,6 +350,9 @@ void CJiaoyijiluWnd::StartRefreshWork()
 	CListUI* pJiaoyijiluList = static_cast<CListUI*>(m_pm.FindControl(_T("jiaoyijilu_list")));
 	pJiaoyijiluList->RemoveAll();
 
+	ShowError(true, L"测试错误提示");
+	return;
+
 	rapidjson::Value& rows = data["rows"];
 	for (rapidjson::SizeType i = 0; i < rows.Size(); ++i)
 	{
@@ -396,4 +419,24 @@ void CJiaoyijiluWnd::StartRefreshWork()
 	pPageNum->SetText(pageinfo.c_str());
 
 	m_is_query = false;
+}
+
+void CJiaoyijiluWnd::ShowError(bool is_show, std::wstring msg)
+{
+	CListUI* pJiaoyijiluList = static_cast<CListUI*>(m_pm.FindControl(_T("jiaoyijilu_list")));
+	CLabelUI* errorLabel = static_cast<CLabelUI*>(m_pm.FindControl(_T("jiaoyijilu_error")));
+
+	if (is_show)
+	{		
+		pJiaoyijiluList->RemoveAll();
+		
+		errorLabel->SetText(msg.c_str());
+		errorLabel->SetVisible(true);
+
+		m_is_query = false;
+	}
+	else
+	{
+		errorLabel->SetVisible(false);
+	}
 }

+ 2 - 0
zhipuzi_pay_plugin/wnd/CJiaoyijiluWnd.h

@@ -76,6 +76,8 @@ public:
 
 	void StartRefreshWork();
 
+	void ShowError(bool is_show, std::wstring msg = L"");
+
 public:
 	CPaintManagerUI m_pm;
 

+ 73 - 61
zhipuzi_pay_plugin/wnd/CValueWnd.cpp

@@ -28,9 +28,6 @@ void CValueWnd::Init()
 	//抢焦点
 	std::thread(&CValueWnd::TopMostWnd, this).detach();
 
-	//任务+1
-	m_nTaskNum++;
-
 	//注册热键
 	UpdateRegisterHotKey();
 
@@ -85,7 +82,7 @@ void CValueWnd::Init()
  **/
 void CValueWnd::TopMostWnd()
 {
-	while (m_is_quit == false)
+	while (m_is_topmost)
 	{
 		::SetWindowPos(m_hWnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE);
 
@@ -97,9 +94,17 @@ void CValueWnd::TopMostWnd()
 		Sleep(100);
 	}
 
-	m_nTaskNum--;
+	m_is_topmost = true;
+}
 
-	//线程退出
+void CValueWnd::StopTopMostWnd()
+{
+	m_is_topmost = false;
+
+	while (m_is_topmost == false)
+	{
+		Sleep(120);
+	}
 }
 
 void CValueWnd::RestartWatch()
@@ -946,19 +951,16 @@ void CValueWnd::ShowJiaoyihuizong()
 		pjiaoyihuizongFrame->Create(NULL, _T(""), UI_WNDSTYLE_DIALOG, WS_EX_TOOLWINDOW);
 		pjiaoyihuizongFrame->SetIcon(IDI_ICON_DUILIB);
 		pjiaoyihuizongFrame->CenterWindow();
-		UINT ret = pjiaoyihuizongFrame->ShowModal();
-
-		m_is_show_jiaoyihuizong = false;
-
-		if (ret == IDOK)
-		{
+		pjiaoyihuizongFrame->ShowWindow(true);		
+	}
+}
 
-		}
-		else if (ret == IDCANCEL)
-		{
+void CValueWnd::CloseJiaoyihuizong()
+{
+	m_is_show_jiaoyihuizong = false;
 
-		}
-	}
+	m_jiaoyihuizongWnd->Close();
+	m_jiaoyihuizongWnd = NULL;
 }
 
 void CValueWnd::ShowJiaoban()
@@ -984,31 +986,54 @@ void CValueWnd::ShowJiaoban()
 		pjiaobanFrame->Create(NULL, _T(""), UI_WNDSTYLE_DIALOG, WS_EX_TOOLWINDOW);
 		pjiaobanFrame->SetIcon(IDI_ICON_DUILIB);
 		pjiaobanFrame->CenterWindow();
-		UINT ret = pjiaobanFrame->ShowModal();
+		pjiaobanFrame->ShowWindow(true);		
+	}
+}
 
-		m_is_show_jiaoban = false;
+void CValueWnd::CloseJiaoban()
+{
+	m_is_show_jiaoban = false;
 
-		if (ret == IDOK)
-		{
+	m_jiaobanWnd->Close();
+	m_jiaobanWnd = NULL;
+}
 
-		}
-		else if (ret == IDCANCEL)
-		{
+/*
+ *执行退出前的清理工作,暂停所有工作线程,清理对象
+ *返回true表示清理成功,返回false表示清理失败
+ **/
+bool CValueWnd::Clear()
+{
+	if (m_is_show_shoukuan || m_is_show_tuikuan)
+	{
+		//如果收款和退款窗口都没关闭,不允许进行清理
+		return false;
+	}
 
-		}
+	//清理窗口
+	if (m_is_show_jiaoyijilu)
+	{
+		CloseJiaoyijilu();
 	}
-}
 
-void CValueWnd::Logout()
-{
-	//先正常关闭设置窗口
-	m_is_show_setting = false;
-	m_settingWnd->Close();
-	m_settingWnd = NULL;
+	if (m_is_show_jiaoyihuizong)
+	{
+		CloseJiaoyihuizong();
+	}
+
+	if (m_is_show_jiaoban)
+	{
+		CloseJiaoban();
+	}
 
-	//先做一些清理工作
-	m_is_quit = true;
+	if (m_is_show_setting)
+	{
+		CloseSystemSetting();
+	}
 
+	//清理抢焦点的
+	StopTopMostWnd();
+	
 	//取消注册的快捷键
 	UnregisterHotKey(m_hWnd, WM_MYHOTKEY_SHOUKUAN);
 
@@ -1034,6 +1059,16 @@ void CValueWnd::Logout()
 
 	this->Close();
 
+	return true;
+}
+
+void CValueWnd::Logout()
+{
+	if (!this->Clear())
+	{
+		return;
+	}
+
 	//退出登录,取消自动登录
 	CSetting::SetParam("setting_is_auto_login", "0", true);
 
@@ -1053,33 +1088,10 @@ void CValueWnd::Logout()
 
 void CValueWnd::QuitApp()
 {
-	//先做一些清理工作
-	m_is_quit = true;
-
-	//取消注册的快捷键
-	UnregisterHotKey(m_hWnd, WM_MYHOTKEY_SHOUKUAN);
-
-	//删除右下角的托盘
-	Shell_NotifyIcon(NIM_DELETE, &m_trayIcon);
-
-	//注意这里不能delete,这个对象会delete自己
-	m_push->Stop();
-
-	pMenu->Close();
-
-	pDingweiWnd->Close();
-
-	pDingweiInfoWnd->Close();
-
-	pOcrWnd->Close();
-
-	//注销Hook
-	UninstallHook();
-
-	//暂停数据监控
-	StopWatch();
-
-	this->Close();
+	if (!this->Clear())
+	{
+		return;
+	}
 
 	//直接退出整个程序
 	PostQuitMessage(0);

+ 6 - 6
zhipuzi_pay_plugin/wnd/CValueWnd.h

@@ -103,17 +103,20 @@ public:
 
 	//显示交易汇总页面
 	void ShowJiaoyihuizong();
+	void CloseJiaoyihuizong();
 
 	//显示交班页面
 	void ShowJiaoban();
+	void CloseJiaoban();
 
+	bool Clear();
 	void Logout();
-
 	void QuitApp();
 
 	void Init();
 
 	void TopMostWnd();
+	void StopTopMostWnd();
 
 	void RestartWatch();
 
@@ -220,11 +223,8 @@ private:
 
 	std::string m_catch_string;
 
-	//退出清理相关的
-	bool m_is_quit = false;
-
-	//这个表示有多少准备工作要做,或者说退出前有多少东西要清理
-	int m_nTaskNum = 0;
+	//抢焦点的状态相关的
+	bool m_is_topmost = true;
 
 	//表示各个监控的状态
 	bool m_is_xunichuangkou_working = false;