Просмотр исходного кода

还差一个退出登录没弄完

zhangyang 6 лет назад
Родитель
Сommit
904a4603c2

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


+ 10 - 2
bin/Win32/Debug/zhipuzi_pos_windows/skin/login.xml

@@ -7,7 +7,11 @@
 			<Button name="closebtn" width="42" height="18" padding="0,6,0,0" tooltip="关闭收银软件" normalimage="file='frame_btn_close_normal.bmp' mask='#FFFF00FF'" hotimage="file='frame_btn_close_hot.bmp' mask='#FFFF00FF'" pushedimage="file='frame_btn_close_down.bmp' mask='#FFFF00FF'"/>
 		</HorizontalLayout>
 		
-		<Control height="60"/>
+		<HorizontalLayout height="60">
+			<Control></Control>
+			<HorizontalLayout bkimage="file='logo_guanwang.png'" width="202" height="43" padding="0,8,0,0"></HorizontalLayout>
+			<Control></Control>
+		</HorizontalLayout>
 		
 		<VerticalLayout height="200">
 			<HorizontalLayout height="50">
@@ -46,6 +50,10 @@
 			<Control></Control>
 		</HorizontalLayout>
 		
-		<Label name="guanwang" text="{u}官方网站{/u}" showhtml="true" float="true" pos="15, 320, 220, 350" />
+		<HorizontalLayout padding="0,0,0,15">
+			<Control></Control>
+			<Button name="guanwang" text="{u}www.zhipuzi.com{/u}" showhtml="true" width="200" align="center"/>
+			<Control></Control>
+		</HorizontalLayout>
     </VerticalLayout>
 </Window>

BIN
bin/Win32/Debug/zhipuzi_pos_windows/skin/logo_guanwang.png


+ 1 - 1
bin/Win32/Debug/zhipuzi_pos_windows/skin/setting.xml

@@ -10,7 +10,7 @@
 					<Option name="setting_system_switch" text="系统设置" group="setting_switch" align="center" height="38" normalimage="file='Btn_White.png' corner='5,5,5,5'" selectedimage="file='Btn_Green_Click.png' corner='5,5,5,5'" hotimage="file='Btn_White_Hover.png' corner='5,5,5,5'" hottextcolor="#CC1010" selectedtextcolor="#FFFFFFFF" />
 					<Option name="setting_system_update" text="更新" group="setting_switch" align="center" height="38" normalimage="file='Btn_White.png' corner='5,5,5,5'" selectedimage="file='Btn_Green_Click.png' corner='5,5,5,5'" hotimage="file='Btn_White_Hover.png' corner='5,5,5,5'" hottextcolor="#CC1010" selectedtextcolor="#FFFFFFFF" />
 
-					<Button name="waimai_order_info_page_disagree" padding="0,50,0,0" width="300" height="38" text="退出登陆" textcolor="#FFFFFFFF" normalimage="file='Btn_Red.png' corner='5,5,5,5'" hotimage="file='Btn_Red_Hover.png' corner='5,5,5,5'" pushedimage="file='Btn_Green_Click.png' corner='5,5,5,5'" />
+					<Button name="setting_logout" padding="0,50,0,0" width="300" height="38" text="退出登陆" textcolor="#FFFFFFFF" normalimage="file='Btn_Red.png' corner='5,5,5,5'" hotimage="file='Btn_Red_Hover.png' corner='5,5,5,5'" pushedimage="file='Btn_Green_Click.png' corner='5,5,5,5'" />
 				</VerticalLayout>
 			</HorizontalLayout>
 

BIN
bin/Win32/Debug/zhipuzi_pos_windows/zhipuzi_pos_windows.exe


BIN
bin/Win32/Debug/zhipuzi_pos_windows_server/zhipuzi_pos_windows_server.exe


+ 46 - 22
lewaimai_dispatch/network/CMessagePush.cpp

@@ -14,31 +14,55 @@ CMessagePush::~CMessagePush()
 void CMessagePush::Start()
 {
     //心跳包
-    std::thread t_1(&CMessagePush::KeepAlive, this);
-    t_1.detach();
+	std::thread(&CMessagePush::KeepAlive, this).detach();
 
 	//接收消息
-	std::thread t_7(&CMessagePush::ReceiveMessage, this);
-	t_7.detach();
+	std::thread(&CMessagePush::ReceiveMessage, this).detach();
 
     //处理声音提醒
-    std::thread t_2(&CMessagePush::HandleVoice, this);
-    t_2.detach();
+    std::thread(&CMessagePush::HandleVoice, this).detach();
 
     //处理订单确认
-    std::thread t_3(&CMessagePush::HandleConfirm, this);
-    t_3.detach();
+    std::thread(&CMessagePush::HandleConfirm, this).detach();
+
+	//处理打印
+	std::thread(&CMessagePush::HandlePrinter, this).detach();
 
     //处理收银打印
-    std::thread t_4(&CMessagePush::HandleShouyinPrinter, this);
-    t_4.detach();
+    std::thread(&CMessagePush::HandleShouyinPrinter, this).detach();
 
     //处理厨房打印
-    std::thread t_5(&CMessagePush::HandleChufangPrinter, this);
-    t_5.detach();
+    std::thread(&CMessagePush::HandleChufangPrinter, this).detach();
+}
+
+void CMessagePush::Stop()
+{
+	m_is_work = false;
+
+	while (!m_voice_queue.empty())
+	{
+		m_voice_queue.pop();
+	}
+
+	while (!m_confirm_queue.empty())
+	{
+		m_confirm_queue.pop();
+	}
 
-    std::thread t_6(&CMessagePush::HandlePrinter, this);
-    t_6.detach();
+	while (!m_printer_queue.empty())
+	{
+		m_printer_queue.pop();
+	}
+
+	while (!m_shouyin_printer_queue.empty())
+	{
+		m_shouyin_printer_queue.pop();
+	}
+
+	while (!m_chufang_printer_queue.empty())
+	{
+		m_chufang_printer_queue.pop();
+	}
 }
 
 void CMessagePush::KeepAlive()
@@ -50,7 +74,8 @@ void CMessagePush::KeepAlive()
 		doc.SetObject();
 		rapidjson::Document::AllocatorType& allocator = doc.GetAllocator(); //获取分配器
 
-		doc.AddMember("username", "zhangyang", allocator);
+		std::string username = CSetting::getUsername();
+		doc.AddMember("username", StringRef(username.c_str(), username.length()), allocator);
 
 		rapidjson::StringBuffer buffer;
 		rapidjson::Writer<StringBuffer> writer(buffer);
@@ -67,7 +92,6 @@ void CMessagePush::KeepAlive()
 		{
 			//走到这里来说明心跳包发送失败了,socket失效了
 			std::string err = e.what();
-			//LOG_INFO("write err info:" << err.c_str());
 
 			//先把socket关闭掉
 			socket_.close();
@@ -113,7 +137,7 @@ void CMessagePush::KeepAlive()
 
 void CMessagePush::ReceiveMessage()
 {
-	while (true)
+	while (m_is_work)
 	{
 		try
 		{
@@ -235,7 +259,7 @@ void CMessagePush::AddChufangPrinter(CWaimaiOrder order)
 
 void CMessagePush::HandleVoice()
 {
-    while(true)
+    while(m_is_work)
     {
         m_voice_mutex.lock();
 
@@ -262,7 +286,7 @@ void CMessagePush::HandleVoice()
 
 void CMessagePush::HandleConfirm()
 {
-    while(true)
+    while(m_is_work)
     {
         m_confirm_mutex.lock();
 
@@ -286,7 +310,7 @@ void CMessagePush::HandleConfirm()
 
 void CMessagePush::HandlePrinter()
 {
-    while(true)
+    while(m_is_work)
     {
         m_printer_mutex.lock();
 
@@ -328,7 +352,7 @@ void CMessagePush::HandlePrinter()
 
 void CMessagePush::HandleShouyinPrinter()
 {
-    while(true)
+    while(m_is_work)
     {
         m_shouyin_printer_mutex.lock();
 
@@ -353,7 +377,7 @@ void CMessagePush::HandleShouyinPrinter()
 
 void CMessagePush::HandleChufangPrinter()
 {
-    while(true)
+    while(m_is_work)
     {
         m_chufang_printer_mutex.lock();
 

+ 2 - 4
lewaimai_dispatch/network/CMessagePush.h

@@ -36,10 +36,8 @@ public:
 	//开始工作
 	void Start();
 
-	void StopWork()
-	{
-		m_is_work = false;
-	}
+	//停止工作
+	void Stop();
 
 	//发送心跳包
 	void KeepAlive();

+ 2 - 0
lewaimai_dispatch/network/CZhipuziHttpClient.cpp

@@ -7,6 +7,8 @@ CZhipuziHttpClient CZhipuziHttpClient::m_client;
 
 CZhipuziHttpClient::CZhipuziHttpClient()
 {
+	m_username = CSetting::getUsername();
+	m_password = CSetting::getPassword();
 }
 
 

+ 2 - 2
lewaimai_dispatch/network/CZhipuziHttpClient.h

@@ -20,8 +20,8 @@ public:
 	static CZhipuziHttpClient m_client;
 
 private:
-	std::string m_username = "zhangyang";
-	std::string m_password = "111111";
+	std::string m_username;
+	std::string m_password;
 	std::string m_machinecode = "e6bc5694877b2aec";
 
 	std::string m_old_url = "https://cyapi.zhipuzi.com/pos";

+ 5 - 2
lewaimai_dispatch/tool/CLewaimaiLog.cpp

@@ -18,12 +18,15 @@ void CLewaimaiLog::Init()
 	//调试模式
 	helpers::LogLog::getLogLog()->setInternalDebugging(false);
 
+	wstring path = CSystem::GetProgramDir() + L"\\log\\pos.log";
+	wstring err_path = CSystem::GetProgramDir() + L"\\log\\pos_error.log";
+
 	SharedFileAppenderPtr append_1(
-		new RollingFileAppender(LOG4CPLUS_TEXT("log/pos.log"), 200 * 1024 * 1024, 100,
+		new RollingFileAppender(path.c_str(), 200 * 1024 * 1024, 100,
 			true, true));
 
 	SharedFileAppenderPtr append_2(
-		new RollingFileAppender(LOG4CPLUS_TEXT("log/pos_error.log"), 200 * 1024 * 1024, 100,
+		new RollingFileAppender(err_path.c_str(), 200 * 1024 * 1024, 100,
 			true, true));
 
 	append_1->setName(LOG4CPLUS_TEXT("lewaimai_dispatch"));

+ 7 - 4
lewaimai_dispatch/tool/CSetting.cpp

@@ -9,6 +9,8 @@ std::mutex CSetting::m_mutex;
 std::vector<FoodType> CSetting::m_foodtypes;
 std::map<std::string, std::string> CSetting::m_foodtype_id_name;
 std::map<string, string> CSetting::m_users;
+std::string CSetting::m_username;
+std::string CSetting::m_password;
 
 CSetting::CSetting()
 {
@@ -120,9 +122,12 @@ ChufangPrinter CSetting::GetChufangPrinter(std::string date)
 
 void CSetting::Init()
 {
-	m_mutex.lock();
+	//先读取数据库的数据
+	CSqlite3 sqllite;
+	sqllite.InitConfig();
 
-	//数据库里面的参数读取完了,接下来对比默认参数
+	//再对数据进行初始化,如果没有记录的就加上默认设置
+	m_mutex.lock();
 
 	//外卖设置参数
 	std::string setting_is_new_waimai_voice = "setting_is_new_waimai_voice";
@@ -198,8 +203,6 @@ void CSetting::Init()
 
 	//设置好默认参数之后,将默认参数写回到数据库
 	SaveParams();
-
-	//厨房打印机没有默认的,这里不需要处理
 }
 
 void CSetting::SaveParams()

+ 19 - 0
lewaimai_dispatch/tool/CSetting.h

@@ -108,6 +108,22 @@ public:
 		return "zhipuzi_not_found_xxx";
 	}
 
+	static void SetLoginInfo(std::string username, std::string password)
+	{
+		m_username = username;
+		m_password = password;
+	}
+
+	static std::string getUsername()
+	{
+		return m_username;
+	}
+
+	static std::string getPassword()
+	{
+		return m_password;
+	}
+
 	/*
 	 *把内存中的参数,写到数据库中
 	 **/
@@ -132,5 +148,8 @@ private:
 	static std::map<std::string, std::string> m_foodtype_id_name;
 
 	static std::map<string, string> m_users;
+
+	static std::string m_username;
+	static std::string m_password;
 };
 

+ 0 - 2
lewaimai_dispatch/tool/CSqlite3.cpp

@@ -100,8 +100,6 @@ bool CSqlite3::InitConfig()
                 }
 
                 sqlite3_finalize(stmt);
-
-                CSetting::Init();
             }
 
             else

+ 7 - 0
lewaimai_dispatch/wnd/CLoginWnd.cpp

@@ -89,6 +89,10 @@ void CLoginWnd::Notify(TNotifyUI& msg)
 				pAuto->Selected(false, false);
 			}
 		}
+		else if (msg.pSender->GetName() == _T("guanwang"))
+		{
+			ShellExecute(NULL, _T("open"), _T("explorer.exe"), _T("https://www.zhipuzi.com"), NULL, SW_SHOW);
+		}
     }
 	else if (msg.sType == _T("itemselect"))
 	{
@@ -366,6 +370,9 @@ void CLoginWnd::HandleLogin()
 		//在这里设置完参数后,统一保存到数据库
 		CSetting::SetParam("last_login_username", s_account, true);
 
+		//把用户名和密码保存起来
+		CSetting::SetLoginInfo(s_account, s_password);
+
         CMainWnd* pFrame = new CMainWnd();
         if(pFrame == NULL)
         {

+ 35 - 14
lewaimai_dispatch/wnd/CMainWnd.cpp

@@ -1,14 +1,13 @@
 #include "../pch/pch.h"
 #include "CMainWnd.h"
+#include "CLoginWnd.h"
 
 #include "CChufangSettingWnd.h"
 
 #include "../control/ControlEx.h"
 #include "../control/CWaimaiOrderInfoUI.h"
 
-#include "../tool/CSetting.h"
-
-
+#include "../network/CMessagePush.h"
 
 void CMainWnd::Init()
 {
@@ -17,11 +16,20 @@ void CMainWnd::Init()
     m_pRestoreBtn = static_cast<CButtonUI*>(m_pm.FindControl(_T("restorebtn")));
     m_pMinBtn = static_cast<CButtonUI*>(m_pm.FindControl(_T("minbtn")));
 
-    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();
 }
 
 LRESULT CMainWnd::OnCreate(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
@@ -123,12 +131,7 @@ void CMainWnd::HandleClickMsg(TNotifyUI& msg)
         std::string waimai_order_id = item->getOrderID();
         std::string waimai_order_no = item->getOrderNo();
 
-        CWaimaiOrder order;
-        order.InitData(waimai_order_id, waimai_order_no);
-
-        CPosPrinter printer;
-        printer.PrintWaimaiOrderShouyin(order);
-        //printer.PrintWaimaiOrderChufang(order);
+		m_push->AddPinter(waimai_order_id, waimai_order_no);
     }
 
     else if(name == _T("waimai_order_list_confirme"))
@@ -279,9 +282,7 @@ void CMainWnd::HandleClickMsg(TNotifyUI& msg)
     {
         CWaimaiOrderInfoUI* order_info_page = static_cast<CWaimaiOrderInfoUI*>(m_pm.FindControl(_T("waimaiorder_info_page")));
 
-        CPosPrinter printer;
-        printer.PrintWaimaiOrderShouyin(order_info_page->m_order);
-        //printer.PrintWaimaiOrderChufang(order_info_page->m_order);
+		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"))
@@ -693,6 +694,26 @@ 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();
+
+		//pLogin->ShowModal();
+
+		::ShowWindow(*pLogin, SW_SHOWNORMAL);
+
+		Close();
+	}
 }
 
 void CMainWnd::HandleSelectChangeMsg(TNotifyUI& msg)

+ 4 - 0
lewaimai_dispatch/wnd/CMainWnd.h

@@ -11,6 +11,8 @@
 #define WM_SHOWTASK 10001
 #define WM_ONCLOSE 10002
 
+class CMessagePush;
+
 class CMainWnd : public CWindowWnd, public INotifyUI
 {
 public:
@@ -109,4 +111,6 @@ private:
 
 	//定义托盘图标对象
 	NOTIFYICONDATA m_trayIcon;
+
+	CMessagePush* m_push;
 };

+ 3 - 9
lewaimai_dispatch/zhipuzi_pos_windows.cpp

@@ -1,7 +1,6 @@
 #include "pch/pch.h"
 
 #include "wnd/CLoginWnd.h"
-#include "network/CMessagePush.h"
 
 int APIENTRY wWinMain(_In_ HINSTANCE hInstance,
                       _In_opt_ HINSTANCE hPrevInstance,
@@ -12,14 +11,8 @@ int APIENTRY wWinMain(_In_ HINSTANCE hInstance,
     CLewaimaiLog log;
     log.Init();
 
-    //读取sqlite里面的设置信息
-    CSqlite3 sqllite;
-    sqllite.InitConfig();
-    sqllite.Close();
-
-    //由这个对象来处理消息推送的接收,以及消息的处理
-    CMessagePush push;
-    push.Start();
+    //初始化系统设置
+	CSetting::Init();
 
     //开始展示窗口
     CPaintManagerUI::SetInstance(hInstance);
@@ -42,6 +35,7 @@ int APIENTRY wWinMain(_In_ HINSTANCE hInstance,
     {
         return 0;
     }
+
     pLogin->Create(NULL, _T("智铺子收银软件登录"), UI_WNDSTYLE_DIALOG, 0, 0, 0, 0, 0, NULL);
     pLogin->SetIcon(IDI_ICON_DUILIB);
     pLogin->CenterWindow();