Pārlūkot izejas kodu

增加了一个被挤下线的通知

zhangyang 6 gadi atpakaļ
vecāks
revīzija
c0f3d204e5

BIN
bin/Win32/Debug/lewaimai_pos_windows/db/pos.db


BIN
bin/Win32/Debug/lewaimai_pos_windows/lewaimai_pos_windows.exe


+ 17 - 0
bin/Win32/Debug/lewaimai_pos_windows/skin/messagebox_dlg.xml

@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<Window size="600,300" caption="0,0,0,36" roundcorner="4,4" >
+	<VerticalLayout bkimage="file='Dialog_BG1.png' corner='4,50,4,4'">
+		<HorizontalLayout height="40" inset="10,2,10,0">
+			<Label name="messagebox_dlg_title" text="账号下线通知" width="150" />
+			<Control />
+			<Button name="messagebox_dlg_closebtn" padding="0,4,0,0" width="22" height="22" tooltip="关闭" normalimage="file='Login_TopBar_Close_Btn.png'" hotimage="file='Login_TopBar_Close_Btn_Hover.png'" pushedimage="file='Login_TopBar_Close_Btn_Click.png'"/>
+		</HorizontalLayout>
+		<VerticalLayout inset="15,0,15,15" vscrollbar="true" >
+			<Control height="60" />
+
+			<HorizontalLayout height="56">
+				<Label text="您的账号在别的地方登录,您被迫下线!" align="center"/>
+			</HorizontalLayout>
+		</VerticalLayout>
+	</VerticalLayout>
+</Window>

+ 17 - 0
bin/Win32/Release/lewaimai_pos_windows/skin/messagebox_dlg.xml

@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<Window size="600,300" caption="0,0,0,36" roundcorner="4,4" >
+	<VerticalLayout bkimage="file='Dialog_BG1.png' corner='4,50,4,4'">
+		<HorizontalLayout height="40" inset="10,2,10,0">
+			<Label name="messagebox_dlg_title" text="账号下线通知" width="150" />
+			<Control />
+			<Button name="messagebox_dlg_closebtn" padding="0,4,0,0" width="22" height="22" tooltip="关闭" normalimage="file='Login_TopBar_Close_Btn.png'" hotimage="file='Login_TopBar_Close_Btn_Hover.png'" pushedimage="file='Login_TopBar_Close_Btn_Click.png'"/>
+		</HorizontalLayout>
+		<VerticalLayout inset="15,0,15,15" vscrollbar="true" >
+			<Control height="60" />
+
+			<HorizontalLayout height="56">
+				<Label text="您的账号在别的地方登录,您被迫下线!" align="center"/>
+			</HorizontalLayout>
+		</VerticalLayout>
+	</VerticalLayout>
+</Window>

BIN
bin/x64/Release/lewaimai_pos_windows_server_linux/lewaimai_pos_windows_server_linux


+ 31 - 0
lewaimai_pos_windows/helper/CLewaimaiString.cpp

@@ -322,4 +322,35 @@ vector<string> CLewaimaiString::Split(const string& in, const string& delim)
 	}
 
 	return ret;
+}
+
+/*
+ *nNum是表示替换几个,默认为1表示替换第1个
+ **/
+int CLewaimaiString::Replace(std::wstring& strContent, std::wstring strReplace, std::wstring strDest, int nNum)
+{
+	int nCount = 0;
+	while (true)
+	{
+		size_t pos = strContent.find(strReplace);
+		if (pos != std::wstring::npos)
+		{
+			WCHAR pBuf[1] = { L'\0' };
+			strContent.replace(pos, strReplace.length(), pBuf, 0);
+			strContent.insert(pos, strDest);
+
+			nCount++;
+
+			if (nCount == nNum)
+			{
+				break;
+			}
+		}
+		else
+		{
+			break;
+		}
+	}
+
+	return 0;
 }

+ 2 - 0
lewaimai_pos_windows/helper/CLewaimaiString.h

@@ -39,4 +39,6 @@ public:
 	static bool isIPAddressValid(const char* pszIPAddr);
 
 	static vector<string> Split(const string& in, const string& delim);
+
+	static int Replace(std::wstring& strContent, std::wstring strReplace, std::wstring strDest, int nNum = 1);
 };

+ 2 - 0
lewaimai_pos_windows/helper/define.h

@@ -11,4 +11,6 @@
 
 #define WM_ORDERLIST_REFRESH 10008
 
+#define WM_LOGIN_AGAIN_OUT 10009
+
 

+ 2 - 0
lewaimai_pos_windows/lewaimai_pos_windows.vcxproj

@@ -221,6 +221,7 @@ copy $(ProjectDir)conf\ $(SolutionDir)bin\$(Platform)\$(Configuration)\conf\</Co
     </PostBuildEvent>
   </ItemDefinitionGroup>
   <ItemGroup>
+    <ClInclude Include="wnd\CMessageboxWnd.h" />
     <ClInclude Include="wnd\CUpdateWnd.h" />
     <ClInclude Include="wnd\CWaimaiOrderFailReasonWnd.h" />
     <ClInclude Include="network\PosMessage.h" />
@@ -250,6 +251,7 @@ copy $(ProjectDir)conf\ $(SolutionDir)bin\$(Platform)\$(Configuration)\conf\</Co
     <ClInclude Include="control\OrderListUI.h" />
   </ItemGroup>
   <ItemGroup>
+    <ClCompile Include="wnd\CMessageboxWnd.cpp" />
     <ClCompile Include="wnd\CUpdateWnd.cpp" />
     <ClCompile Include="wnd\CWaimaiOrderFailReasonWnd.cpp" />
     <ClCompile Include="wnd\CChufangSettingWnd.cpp" />

+ 6 - 0
lewaimai_pos_windows/lewaimai_pos_windows.vcxproj.filters

@@ -96,6 +96,9 @@
     <ClInclude Include="network\CLewaimaiHttpClient.h">
       <Filter>头文件</Filter>
     </ClInclude>
+    <ClInclude Include="wnd\CMessageboxWnd.h">
+      <Filter>头文件</Filter>
+    </ClInclude>
   </ItemGroup>
   <ItemGroup>
     <ClCompile Include="pch\pch.cpp">
@@ -170,6 +173,9 @@
     <ClCompile Include="network\CLewaimaiHttpClient.cpp">
       <Filter>源文件</Filter>
     </ClCompile>
+    <ClCompile Include="wnd\CMessageboxWnd.cpp">
+      <Filter>源文件</Filter>
+    </ClCompile>
   </ItemGroup>
   <ItemGroup>
     <Image Include="resource\lewaimai.ico">

+ 15 - 2
lewaimai_pos_windows/network/CMessagePush.cpp

@@ -205,9 +205,17 @@ void CMessagePush::ReceiveMessage()
 				return;
 			}
 
-			int type = document["msg_type"].GetInt();
+			std::string type;
+			if (document["msg_type"].IsInt())
+			{
+				type = to_string(document["msg_type"].GetInt());
+			}
+			else
+			{
+				type = document["msg_type"].GetString();
+			}
 
-			if (type == 1)
+			if (type == "1")
 			{
 				std::string order_id = document["waimai_order_id"].GetString();
 				std::string order_no = document["waimai_order_no"].GetString();
@@ -232,6 +240,11 @@ void CMessagePush::ReceiveMessage()
 
 				AddPinter(order_id, order_no);
 			}
+			else if (type == "0")
+			{
+				//这个表示被人挤下线了
+				PostMessage(m_hwnd, WM_LOGIN_AGAIN_OUT, 0, 0);
+			}
 
 			//处理完了,接着处理下一条
 			continue;

+ 4 - 2
lewaimai_pos_windows/network/CMessagePush.h

@@ -25,10 +25,10 @@ public:
 class CMessagePush
 {
 public:
-	CMessagePush()
+	CMessagePush(HWND hwnd)
 		: socket_(m_io_context)
 	{
-
+		m_hwnd = hwnd;
 	}
 
 	~CMessagePush();
@@ -85,5 +85,7 @@ private:
 	std::mutex m_printer_mutex;
 	std::mutex m_shouyin_printer_mutex;
 	std::mutex m_chufang_printer_mutex;
+
+	HWND m_hwnd;
 };
 

+ 25 - 0
lewaimai_pos_windows/wnd/CLoginWnd.cpp

@@ -2,6 +2,8 @@
 #include "CLoginWnd.h"
 #include "CUpdateWnd.h"
 
+#include "CMessageboxWnd.h"
+
 void CLoginWnd::Init()
 {
 	CLabelUI* version = static_cast<CLabelUI*>(m_pm.FindControl(_T("login_version")));
@@ -65,6 +67,11 @@ void CLoginWnd::Init()
 		CVerticalLayoutUI* pLoading = static_cast<CVerticalLayoutUI*>(m_pm.FindControl(_T("login_loading")));
 		pLoading->SetVisible(false);
 	}
+
+	if (m_mode == 2)
+	{
+		PostMessage(WM_LOGIN_AGAIN_OUT);
+	}
 }
 
 void CLoginWnd::Notify(TNotifyUI& msg)
@@ -332,6 +339,12 @@ LRESULT CLoginWnd::MessageHandler(UINT uMsg, WPARAM wParam, LPARAM lParam, bool&
 
 		return true;
 	}
+	else if (uMsg == WM_LOGIN_AGAIN_OUT)
+	{
+		ShowLoginAgainOut();
+
+		return true;
+	}
 
     return false;
 }
@@ -435,6 +448,9 @@ void CLoginWnd::HandleLogin()
         password = pPasswordEdit->GetText().GetData();
     }
 
+	//把第1个中文冒号替换成英文冒号
+	CLewaimaiString::Replace(account, _T(":"), _T(":"), 1);
+
     //LOG_INFO("account:" << account.c_str() << ", password:" << password.c_str());
 
     string s_account = CLewaimaiString::UnicodeToUTF8(account);
@@ -580,3 +596,12 @@ void CLoginWnd::Update()
 	Close();
 }
 
+void CLoginWnd::ShowLoginAgainOut()
+{
+	//这种模式是本人强制挤下线了
+	CMessageboxWnd* pMessagebox = new CMessageboxWnd;
+	pMessagebox->Create(m_hWnd, _T(""), UI_WNDSTYLE_DIALOG, WS_EX_WINDOWEDGE);
+	pMessagebox->SetIcon(IDI_ICON_DUILIB);
+	pMessagebox->CenterWindow();
+	UINT ret = pMessagebox->ShowModal();
+}

+ 10 - 0
lewaimai_pos_windows/wnd/CLoginWnd.h

@@ -29,6 +29,11 @@ public:
 
 	void Init();
 
+	void SetMode(int mode)
+	{
+		m_mode = mode;
+	}
+
 	void Notify(TNotifyUI& msg);
 
 	LRESULT OnCreate(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
@@ -61,9 +66,14 @@ public:
 
 	void Update();
 
+	void ShowLoginAgainOut();
+
 public:
     CPaintManagerUI m_pm;
 
 	std::string m_update_url;
+
+	//模式1:正常的展示登录页面 2:被人挤下线的
+	int m_mode = 1;
 };
 

+ 136 - 113
lewaimai_pos_windows/wnd/CMainWnd.cpp

@@ -17,20 +17,20 @@ void CMainWnd::Init()
     m_pRestoreBtn = static_cast<CButtonUI*>(m_pm.FindControl(_T("restorebtn")));
     m_pMinBtn = static_cast<CButtonUI*>(m_pm.FindControl(_T("minbtn")));
 
-	//初始化外卖订单列表
-	COptionUI* waimai_tab = static_cast<COptionUI*>(m_pm.FindControl(_T("main_waimai")));
-	if (waimai_tab->IsSelected())
-	{
-		OrderListUI* orderlist = static_cast<OrderListUI*>(m_pm.FindControl(_T("orderlist")));
-		orderlist->Refresh();
-	}
+    //初始化外卖订单列表
+    COptionUI* waimai_tab = static_cast<COptionUI*>(m_pm.FindControl(_T("main_waimai")));
+    if(waimai_tab->IsSelected())
+    {
+        OrderListUI* orderlist = static_cast<OrderListUI*>(m_pm.FindControl(_T("orderlist")));
+        orderlist->Refresh();
+    }
 
     //初始化设置中心的状态
     InitSettingStatus();
 
-	//登录成功,启动消息和任务处理
-	m_push = new CMessagePush;
-	m_push->Start();
+    //登录成功,启动消息和任务处理
+    m_push = new CMessagePush(m_hWnd);
+    m_push->Start();
 }
 
 LRESULT CMainWnd::OnCreate(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
@@ -132,7 +132,7 @@ void CMainWnd::HandleClickMsg(TNotifyUI& msg)
         std::string waimai_order_id = item->getOrderID();
         std::string waimai_order_no = item->getOrderNo();
 
-		m_push->AddPinter(waimai_order_id, waimai_order_no);
+        m_push->AddPinter(waimai_order_id, waimai_order_no);
     }
 
     else if(name == _T("waimai_order_list_confirme"))
@@ -175,29 +175,29 @@ void CMainWnd::HandleClickMsg(TNotifyUI& msg)
         CWaimaiOrderItemUI* item = static_cast<CWaimaiOrderItemUI*>(msg.pSender->GetParent()->GetParent());
         std::string waimai_order_id = item->getOrderID();
 
-		CWaimaiOrderFailReasonWnd* pWaimaiFailFrame = new CWaimaiOrderFailReasonWnd();
-		pWaimaiFailFrame->Create(this->GetHWND(), _T(""), UI_WNDSTYLE_DIALOG, WS_EX_WINDOWEDGE);
-		pWaimaiFailFrame->SetIcon(IDI_ICON_DUILIB);
-		pWaimaiFailFrame->CenterWindow();
-		UINT ret = pWaimaiFailFrame->ShowModal();
+        CWaimaiOrderFailReasonWnd* pWaimaiFailFrame = new CWaimaiOrderFailReasonWnd();
+        pWaimaiFailFrame->Create(this->GetHWND(), _T(""), UI_WNDSTYLE_DIALOG, WS_EX_WINDOWEDGE);
+        pWaimaiFailFrame->SetIcon(IDI_ICON_DUILIB);
+        pWaimaiFailFrame->CenterWindow();
+        UINT ret = pWaimaiFailFrame->ShowModal();
 
-		if (ret == IDOK)
-		{
-			std::string sReason = pWaimaiFailFrame->getReason();
+        if(ret == IDOK)
+        {
+            std::string sReason = pWaimaiFailFrame->getReason();
 
-			CWaimaiOrder order;
-			bool ret = order.FailOrder(waimai_order_id, sReason);
+            CWaimaiOrder order;
+            bool ret = order.FailOrder(waimai_order_id, sReason);
 
-			if (ret)
-			{
-				//如果设为失败成功,将被设为失败的订单删除掉
-				OrderListUI* orderlist = static_cast<OrderListUI*>(m_pm.FindControl(_T("orderlist")));
-				int index = orderlist->GetItemIndex(item);
-				orderlist->RemoveAt(index);
-			}
-		}
+            if(ret)
+            {
+                //如果设为失败成功,将被设为失败的订单删除掉
+                OrderListUI* orderlist = static_cast<OrderListUI*>(m_pm.FindControl(_T("orderlist")));
+                int index = orderlist->GetItemIndex(item);
+                orderlist->RemoveAt(index);
+            }
+        }
 
-		delete pWaimaiFailFrame;
+        delete pWaimaiFailFrame;
     }
 
     else if(name == _T("waimai_order_list_agree"))
@@ -296,7 +296,7 @@ void CMainWnd::HandleClickMsg(TNotifyUI& msg)
     {
         CWaimaiOrderInfoUI* order_info_page = static_cast<CWaimaiOrderInfoUI*>(m_pm.FindControl(_T("waimaiorder_info_page")));
 
-		m_push->AddPinter(order_info_page->m_order.m_order_id, order_info_page->m_order.m_order_no);
+        m_push->AddPinter(order_info_page->m_order.m_order_id, order_info_page->m_order.m_order_no);
     }
 
     else if(name == _T("waimai_order_info_page_confirme"))
@@ -352,33 +352,33 @@ void CMainWnd::HandleClickMsg(TNotifyUI& msg)
         std::string waimai_order_id = order_info_page->m_order.m_order_id;
         std::string waimai_order_no = order_info_page->m_order.m_order_no;
 
-		CWaimaiOrderFailReasonWnd* pWaimaiFailFrame = new CWaimaiOrderFailReasonWnd();
-		pWaimaiFailFrame->Create(this->GetHWND(), _T(""), UI_WNDSTYLE_DIALOG, WS_EX_WINDOWEDGE);
-		pWaimaiFailFrame->SetIcon(IDI_ICON_DUILIB);
-		pWaimaiFailFrame->CenterWindow();
-		UINT ret = pWaimaiFailFrame->ShowModal();
+        CWaimaiOrderFailReasonWnd* pWaimaiFailFrame = new CWaimaiOrderFailReasonWnd();
+        pWaimaiFailFrame->Create(this->GetHWND(), _T(""), UI_WNDSTYLE_DIALOG, WS_EX_WINDOWEDGE);
+        pWaimaiFailFrame->SetIcon(IDI_ICON_DUILIB);
+        pWaimaiFailFrame->CenterWindow();
+        UINT ret = pWaimaiFailFrame->ShowModal();
 
-		if (ret == IDOK)
-		{
-			std::string sReason = pWaimaiFailFrame->getReason();
-
-			CWaimaiOrder order;
-			bool ret = order.FailOrder(waimai_order_id, sReason);
+        if(ret == IDOK)
+        {
+            std::string sReason = pWaimaiFailFrame->getReason();
 
-			if (ret)
-			{
-				//订单设为失败,这里怎么处理
-				//请求服务器,获取订单数据
-				CWaimaiOrder new_order;
-				new_order.InitData(waimai_order_id, waimai_order_no);
+            CWaimaiOrder order;
+            bool ret = order.FailOrder(waimai_order_id, sReason);
 
-				//刷新订单详情页数据
-				order_info_page->SetDate(new_order);
-				order_info_page->Refresh(new_order);
-			}
-		}
+            if(ret)
+            {
+                //订单设为失败,这里怎么处理
+                //请求服务器,获取订单数据
+                CWaimaiOrder new_order;
+                new_order.InitData(waimai_order_id, waimai_order_no);
+
+                //刷新订单详情页数据
+                order_info_page->SetDate(new_order);
+                order_info_page->Refresh(new_order);
+            }
+        }
 
-		delete pWaimaiFailFrame;
+        delete pWaimaiFailFrame;
     }
 
     else if(name == _T("waimai_order_info_page_agree"))
@@ -427,28 +427,28 @@ void CMainWnd::HandleClickMsg(TNotifyUI& msg)
         }
     }
 
-	else if (name == _T("waimai_order_info_page_refund"))
-	{
-		CWaimaiOrderInfoUI* order_info_page = static_cast<CWaimaiOrderInfoUI*>(m_pm.FindControl(_T("waimaiorder_info_page")));
+    else if(name == _T("waimai_order_info_page_refund"))
+    {
+        CWaimaiOrderInfoUI* order_info_page = static_cast<CWaimaiOrderInfoUI*>(m_pm.FindControl(_T("waimaiorder_info_page")));
 
-		std::string waimai_order_id = order_info_page->m_order.m_order_id;
-		std::string waimai_order_no = order_info_page->m_order.m_order_no;
+        std::string waimai_order_id = order_info_page->m_order.m_order_id;
+        std::string waimai_order_no = order_info_page->m_order.m_order_no;
 
-		CWaimaiOrder order;
-		bool ret = order.Refund(waimai_order_id);
+        CWaimaiOrder order;
+        bool ret = order.Refund(waimai_order_id);
 
-		if (ret)
-		{
-			//订单设为成功,这里怎么处理
-			//请求服务器,获取订单数据
-			CWaimaiOrder new_order;
-			new_order.InitData(waimai_order_id, waimai_order_no);
+        if(ret)
+        {
+            //订单设为成功,这里怎么处理
+            //请求服务器,获取订单数据
+            CWaimaiOrder new_order;
+            new_order.InitData(waimai_order_id, waimai_order_no);
 
-			//刷新订单详情页数据
-			order_info_page->SetDate(new_order);
-			order_info_page->Refresh(new_order);
-		}
-	}
+            //刷新订单详情页数据
+            order_info_page->SetDate(new_order);
+            order_info_page->Refresh(new_order);
+        }
+    }
 
     //开始处理设置页面的
     else if(name == _T("setting_is_new_waimai_voice"))
@@ -698,24 +698,11 @@ void CMainWnd::HandleClickMsg(TNotifyUI& msg)
 
         pPrinterList->Remove(pEle);
     }
-	else if (name == _T("setting_logout"))
-	{
-		//退出登录
-		CSetting::SetParam("setting_is_auto_login", "0", true);
-
-		CLoginWnd* pLogin = new CLoginWnd();
-		if (pLogin == NULL)
-		{
-			return;
-		}
-		pLogin->Create(NULL, _T("乐外卖接单软件登录"), UI_WNDSTYLE_DIALOG, 0, 0, 0, 0, 0, NULL);
-		pLogin->SetIcon(IDI_ICON_DUILIB);
-		pLogin->CenterWindow();
-
-		::ShowWindow(*pLogin, SW_SHOWNORMAL);
-
-		Close();
-	}
+    else if(name == _T("setting_logout"))
+    {
+        //退出登录
+        LoginOut(1);
+    }
 }
 
 void CMainWnd::HandleSelectChangeMsg(TNotifyUI& msg)
@@ -922,12 +909,19 @@ LRESULT CMainWnd::HandleMessage(UINT uMsg, WPARAM wParam, LPARAM lParam)
     case WM_SYSCOMMAND:
         lRes = OnSysCommand(uMsg, wParam, lParam, bHandled);
         break;
+
     case  WM_SHOWTASK:
         lRes = OnTrayIcon(uMsg, wParam, lParam, bHandled);
         break;
-	case WM_ORDERLIST_REFRESH:
-		lRes = OnOrderlistRefresh(uMsg, wParam, lParam, bHandled);
-		break;
+
+    case WM_ORDERLIST_REFRESH:
+        lRes = OnOrderlistRefresh(uMsg, wParam, lParam, bHandled);
+        break;
+
+    case WM_LOGIN_AGAIN_OUT:
+        lRes = OnLoginOut(uMsg, wParam, lParam, bHandled);
+        break;
+
     default:
         bHandled = FALSE;
     }
@@ -1049,8 +1043,8 @@ LRESULT CMainWnd::OnSize(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled
 
 LRESULT CMainWnd::OnClose(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
 {
-	bHandled = FALSE;
-	return 0;
+    bHandled = FALSE;
+    return 0;
 }
 
 /*
@@ -1058,30 +1052,30 @@ LRESULT CMainWnd::OnClose(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandle
  **/
 LRESULT CMainWnd::OnDestroy(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
 {
-	//直接退出程序,或者退出登录都会执行这个
-	m_push->Stop();
+    //直接退出程序,或者退出登录都会执行这个
+    m_push->Stop();
 
-	bHandled = FALSE;
-	return 0;
+    bHandled = FALSE;
+    return 0;
 }
 
 LRESULT CMainWnd::OnNcActivate(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
 {
-	if (::IsIconic(*this))
-	{
-		bHandled = FALSE;
-	}
-	return (wParam == 0) ? TRUE : FALSE;
+    if(::IsIconic(*this))
+    {
+        bHandled = FALSE;
+    }
+    return (wParam == 0) ? TRUE : FALSE;
 }
 
 LRESULT CMainWnd::OnNcCalcSize(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
 {
-	return 0;
+    return 0;
 }
 
 LRESULT CMainWnd::OnNcPaint(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
 {
-	return 0;
+    return 0;
 }
 
 LRESULT CMainWnd::OnNcHitTest(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
@@ -1215,19 +1209,27 @@ LRESULT CMainWnd::OnTrayIcon(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHan
 
 LRESULT CMainWnd::OnOrderlistRefresh(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
 {
-	OrderListUI* orderlist = static_cast<OrderListUI*>(m_pm.FindControl(_T("orderlist")));
-	orderlist->DoRefresh();
+    OrderListUI* orderlist = static_cast<OrderListUI*>(m_pm.FindControl(_T("orderlist")));
+    orderlist->DoRefresh();
+
+    return 1;
+}
+
+LRESULT CMainWnd::OnLoginOut(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
+{
+    LoginOut(2);
 
-	return 1;
+    bHandled = true;
+    return 1;
 }
 
 void CMainWnd::InitSettingStatus()
 {
-	CLabelUI* name_version = static_cast<CLabelUI*>(m_pm.FindControl(_T("main_name_version")));
-	name_version->SetText((L"乐外卖接单软件 " + CLewaimaiString::UTF8ToUnicode(CSystem::GetVersion())).c_str());
+    CLabelUI* name_version = static_cast<CLabelUI*>(m_pm.FindControl(_T("main_name_version")));
+    name_version->SetText((L"乐外卖接单软件 " + CLewaimaiString::UTF8ToUnicode(CSystem::GetVersion())).c_str());
 
-	CLabelUI* version = static_cast<CLabelUI*>(m_pm.FindControl(_T("setting_version")));
-	version->SetText((L"版本号:" + CLewaimaiString::UTF8ToUnicode(CSystem::GetVersion())).c_str());
+    CLabelUI* version = static_cast<CLabelUI*>(m_pm.FindControl(_T("setting_version")));
+    version->SetText((L"版本号:" + CLewaimaiString::UTF8ToUnicode(CSystem::GetVersion())).c_str());
 
     CCheckBoxUI* box = NULL;
     CComboUI* com = NULL;
@@ -1421,3 +1423,24 @@ void CMainWnd::InitSettingStatus()
     }
 }
 
+void CMainWnd::LoginOut(int mode)
+{
+    CSetting::SetParam("setting_is_auto_login", "0", true);
+
+    CLoginWnd* pLogin = new CLoginWnd();
+    if(pLogin == NULL)
+    {
+        return;
+    }
+
+	//设置模式
+	pLogin->SetMode(mode);
+
+    pLogin->Create(NULL, _T("乐外卖接单软件登录"), UI_WNDSTYLE_DIALOG, 0, 0, 0, 0, 0, NULL);
+    pLogin->SetIcon(IDI_ICON_DUILIB);
+    pLogin->CenterWindow();
+
+    ::ShowWindow(*pLogin, SW_SHOWNORMAL);
+
+    Close();
+}

+ 4 - 0
lewaimai_pos_windows/wnd/CMainWnd.h

@@ -67,12 +67,16 @@ public:
 
 	LRESULT OnOrderlistRefresh(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
 
+	LRESULT OnLoginOut(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
+
     //添加托盘图标(初始化)
     void AddTrayIcon();
 
     //处理托盘图标上的事件
     LRESULT OnTrayIcon(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
 
+	void LoginOut(int mode);
+
 public:
     CPaintManagerUI m_pm;
 

+ 103 - 0
lewaimai_pos_windows/wnd/CMessageboxWnd.cpp

@@ -0,0 +1,103 @@
+#include "../pch/pch.h"
+#include "CMessageboxWnd.h"
+
+LRESULT CMessageboxWnd::OnNcHitTest(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
+{
+	POINT pt;
+	pt.x = GET_X_LPARAM(lParam);
+	pt.y = GET_Y_LPARAM(lParam);
+	::ScreenToClient(*this, &pt);
+
+	RECT rcClient;
+	::GetClientRect(*this, &rcClient);
+
+	RECT rcCaption = m_pm.GetCaptionRect();
+	if (pt.x >= rcClient.left + rcCaption.left && pt.x < rcClient.right - rcCaption.right \
+		&& pt.y >= rcCaption.top && pt.y < rcCaption.bottom)
+	{
+		CControlUI* pControl = static_cast<CControlUI*>(m_pm.FindControl(pt));
+		if (pControl && _tcscmp(pControl->GetClass(), DUI_CTR_BUTTON) != 0)
+		{
+			return HTCAPTION;
+		}
+	}
+
+	return HTCLIENT;
+}
+
+LRESULT CMessageboxWnd::OnSize(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
+{
+	SIZE szRoundCorner = m_pm.GetRoundCorner();
+	if (!::IsIconic(*this) && (szRoundCorner.cx != 0 || szRoundCorner.cy != 0))
+	{
+		CDuiRect rcWnd;
+		::GetWindowRect(*this, &rcWnd);
+		rcWnd.Offset(-rcWnd.left, -rcWnd.top);
+		rcWnd.right++;
+		rcWnd.bottom++;
+		HRGN hRgn = ::CreateRoundRectRgn(rcWnd.left, rcWnd.top, rcWnd.right, rcWnd.bottom, szRoundCorner.cx, szRoundCorner.cy);
+		::SetWindowRgn(*this, hRgn, TRUE);
+		::DeleteObject(hRgn);
+	}
+
+	bHandled = FALSE;
+	return 0;
+}
+
+LRESULT CMessageboxWnd::HandleMessage(UINT uMsg, WPARAM wParam, LPARAM lParam)
+{
+	LRESULT lRes = 0;
+	BOOL bHandled = TRUE;
+	switch (uMsg)
+	{
+	case WM_CREATE:
+		lRes = OnCreate(uMsg, wParam, lParam, bHandled);
+		break;
+	case WM_NCACTIVATE:
+		lRes = OnNcActivate(uMsg, wParam, lParam, bHandled);
+		break;
+	case WM_NCCALCSIZE:
+		lRes = OnNcCalcSize(uMsg, wParam, lParam, bHandled);
+		break;
+	case WM_NCPAINT:
+		lRes = OnNcPaint(uMsg, wParam, lParam, bHandled);
+		break;
+	case WM_NCHITTEST:
+		lRes = OnNcHitTest(uMsg, wParam, lParam, bHandled);
+		break;
+	case WM_SIZE:
+		lRes = OnSize(uMsg, wParam, lParam, bHandled);
+		break;
+	default:
+		bHandled = FALSE;
+	}
+	if (bHandled)
+	{
+		return lRes;
+	}
+	if (m_pm.MessageHandler(uMsg, wParam, lParam, lRes))
+	{
+		return lRes;
+	}
+	return CWindowWnd::HandleMessage(uMsg, wParam, lParam);
+}
+
+LRESULT CMessageboxWnd::MessageHandler(UINT uMsg, WPARAM wParam, LPARAM lParam, bool& bHandled)
+{
+	if (uMsg == WM_KEYDOWN)
+	{
+		if (wParam == VK_RETURN)
+		{
+			return true;
+		}
+		else if (wParam == VK_ESCAPE)
+		{
+			return true;
+		}
+	}
+	return false;
+}
+
+
+
+

+ 103 - 0
lewaimai_pos_windows/wnd/CMessageboxWnd.h

@@ -0,0 +1,103 @@
+#pragma once
+
+#include "../pch/pch.h"
+#include "CMainWnd.h"
+
+class CMessageboxWnd : public CWindowWnd, public INotifyUI, public IMessageFilterUI
+{
+public:
+	LPCTSTR GetWindowClassName() const
+	{
+		return _T("UIMessageboxFrame");
+	};
+
+	UINT GetClassStyle() const
+	{
+		return UI_CLASSSTYLE_DIALOG;
+	};
+
+	void OnFinalMessage(HWND /*hWnd*/)
+	{
+		//WindowImplBase::OnFinalMessage(hWnd);
+		m_pm.RemovePreMessageFilter(this);
+
+		//delete this;
+	};
+
+	void Init()
+	{
+
+	}
+
+	void Notify(TNotifyUI& msg)
+	{
+		if (msg.sType == _T("click"))
+		{
+			DuiLib::CDuiString senderName = msg.pSender->GetName();
+
+			if (senderName == _T("messagebox_dlg_closebtn"))
+			{
+				Close(IDCANCEL);
+				return;
+			}
+		}
+	}
+
+	LRESULT OnCreate(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
+	{
+		LONG styleValue = ::GetWindowLong(*this, GWL_STYLE);
+		styleValue &= ~WS_CAPTION;
+		::SetWindowLong(*this, GWL_STYLE, styleValue | WS_CLIPSIBLINGS | WS_CLIPCHILDREN);
+
+		// 把自己的窗口句柄与窗口绘制管理器挂接在一起
+		m_pm.Init(m_hWnd);
+
+		m_pm.AddPreMessageFilter(this);
+
+		CDialogBuilder builder;
+
+		CControlUI* pRoot = builder.Create(_T("messagebox_dlg.xml"), (UINT)0, NULL, &m_pm);
+		ASSERT(pRoot && "Failed to parse XML");
+
+		// 把这些控件绘制到本窗口上
+		m_pm.AttachDialog(pRoot);
+
+		// 把自己加入到CPaintManagerUI的m_aNotifiers数组中,用于处理Notify函数
+		m_pm.AddNotifier(this);
+
+		Init();
+
+		return 0;
+	}
+
+	LRESULT OnNcActivate(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
+	{
+		if (::IsIconic(*this))
+		{
+			bHandled = FALSE;
+		}
+		return (wParam == 0) ? TRUE : FALSE;
+	}
+
+	LRESULT OnNcCalcSize(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
+	{
+		return 0;
+	}
+
+	LRESULT OnNcPaint(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
+	{
+		return 0;
+	}
+
+	LRESULT OnNcHitTest(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
+
+	LRESULT OnSize(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
+
+	LRESULT HandleMessage(UINT uMsg, WPARAM wParam, LPARAM lParam);
+
+	LRESULT MessageHandler(UINT uMsg, WPARAM wParam, LPARAM lParam, bool& bHandled);
+
+public:
+	CPaintManagerUI m_pm;
+};
+

+ 20 - 0
lewaimai_pos_windows_server/network/CClientSession.cpp

@@ -23,6 +23,26 @@ void CClientSession::start()
  **/
 void CClientSession::stop()
 {
+	//先给客户端发送一个下线通知
+	rapidjson::Document doc;
+	doc.SetObject();
+	rapidjson::Document::AllocatorType& allocator = doc.GetAllocator(); //获取分配器
+
+	std::string timestamp = to_string(time(NULL));
+
+	doc.AddMember("msg_type", "0", allocator);
+	doc.AddMember("timestamp", StringRef(timestamp.c_str(), timestamp.length()), allocator);
+
+	rapidjson::StringBuffer buffer;
+	rapidjson::Writer<StringBuffer> writer(buffer);
+	doc.Accept(writer);
+
+	//返回给接入层的消息
+	std::string login_out_msg = buffer.GetString();
+
+	send_message(login_out_msg);
+
+	//然后关闭socket
 	socket_.close();
 
 	//注意这里不能调用delete this,因为后面会异步返回,要判断状态,如果这里delete了,后面就会内存越界

+ 1 - 1
lewaimai_pos_windows_server/network/CServer.cpp

@@ -298,7 +298,7 @@ void CServer::BindUsername(std::string username, CClientSession* session)
 
 	if (m_clients_map.find(username) != m_clients_map.end() && m_clients_map[username]->GetNum() < session->GetNum())
 	{
-		//之前已经存在了一个,先把直接的关闭掉(这个是服务器端主动的关闭)
+		//之前已经存在了一个,先把之前的关闭掉(这个是服务器端主动的关闭)
 		m_clients_map[username]->stop();
 	}