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

同步乐外卖的客户端,其他问题再慢慢调吧

zhangyang 5 лет назад
Родитель
Сommit
dc73cc5f61
36 измененных файлов с 4061 добавлено и 2646 удалено
  1. 5 5
      zhipuzi_pos_windows/control/CWaimaiOrderInfoUI.cpp
  2. 0 2
      zhipuzi_pos_windows/control/CWaimaiOrderItemUI.h
  3. 111 0
      zhipuzi_pos_windows/helper/CBitmapHelper.cpp
  4. 46 0
      zhipuzi_pos_windows/helper/CBitmapHelper.h
  5. 82 19
      zhipuzi_pos_windows/helper/CLewaimaiString.cpp
  6. 6 6
      zhipuzi_pos_windows/helper/CLewaimaiString.h
  7. 168 168
      zhipuzi_pos_windows/network/CHttpClient.cpp
  8. 39 39
      zhipuzi_pos_windows/network/CHttpClient.h
  9. 369 306
      zhipuzi_pos_windows/network/CMessagePush.cpp
  10. 55 51
      zhipuzi_pos_windows/network/CMessagePush.h
  11. 24 14
      zhipuzi_pos_windows/network/CZhipuziHttpClient.cpp
  12. 17 9
      zhipuzi_pos_windows/network/CZhipuziHttpClient.h
  13. 15 27
      zhipuzi_pos_windows/pch/pch.h
  14. 50 0
      zhipuzi_pos_windows/tool/CComHelper.cpp
  15. 11 0
      zhipuzi_pos_windows/tool/CComHelper.h
  16. 116 0
      zhipuzi_pos_windows/tool/CExceptionDmp.cpp
  17. 11 0
      zhipuzi_pos_windows/tool/CExceptionDmp.h
  18. 883 199
      zhipuzi_pos_windows/tool/CPosPrinter.cpp
  19. 63 44
      zhipuzi_pos_windows/tool/CPosPrinter.h
  20. 246 220
      zhipuzi_pos_windows/tool/CSetting.cpp
  21. 135 129
      zhipuzi_pos_windows/tool/CSetting.h
  22. 266 135
      zhipuzi_pos_windows/tool/CSqlite3.cpp
  23. 15 15
      zhipuzi_pos_windows/tool/CSqlite3.h
  24. 77 77
      zhipuzi_pos_windows/wnd/CChufangSettingWnd.cpp
  25. 240 240
      zhipuzi_pos_windows/wnd/CChufangSettingWnd.h
  26. 300 295
      zhipuzi_pos_windows/wnd/CLoginWnd.cpp
  27. 27 25
      zhipuzi_pos_windows/wnd/CLoginWnd.h
  28. 270 212
      zhipuzi_pos_windows/wnd/CMainWnd.cpp
  29. 7 4
      zhipuzi_pos_windows/wnd/CMainWnd.h
  30. 77 77
      zhipuzi_pos_windows/wnd/CMessageboxWnd.cpp
  31. 68 68
      zhipuzi_pos_windows/wnd/CMessageboxWnd.h
  32. 58 57
      zhipuzi_pos_windows/wnd/CUpdateWnd.cpp
  33. 17 17
      zhipuzi_pos_windows/wnd/CUpdateWnd.h
  34. 77 77
      zhipuzi_pos_windows/wnd/CWaimaiOrderFailReasonWnd.cpp
  35. 107 107
      zhipuzi_pos_windows/wnd/CWaimaiOrderFailReasonWnd.h
  36. 3 2
      zhipuzi_pos_windows/zhipuzi_pos_windows.cpp

+ 5 - 5
zhipuzi_pos_windows/control/CWaimaiOrderInfoUI.cpp

@@ -273,6 +273,7 @@ void CWaimaiOrderInfoUI::Refresh(CWaimaiOrder& order)
 
 	CLabelUI *pStatus = static_cast<CLabelUI *>(this->FindSubControl(_T("waimai_order_info_page_status")));
 	wstring wsStatus = _T("订单状态:") + CLewaimaiString::UTF8ToUnicode(order.m_order_status);
+
 	if (CLewaimaiString::UTF8ToUnicode(order.m_order_status) == _T("交易失败"))
 	{
 		wsStatus += _T(",失败原因:") + CLewaimaiString::UTF8ToUnicode(order.m_failed_reason);
@@ -440,7 +441,7 @@ void CWaimaiOrderInfoUI::Refresh(CWaimaiOrder& order)
 			refund_button->SetVisible(false);
 
 			pRefundStatus->SetVisible(false);
-		}
+		}		
 	}
 	else if (_tcscmp(CLewaimaiString::UTF8ToUnicode(order.m_order_status).c_str(), _T("已取消")) == 0)
 	{
@@ -461,8 +462,6 @@ void CWaimaiOrderInfoUI::Refresh(CWaimaiOrder& order)
 		success_button->SetVisible(false);
 		fail_button->SetVisible(false);
 
-		refund_button->SetVisible(false);
-
 		std::string refund_status = m_order.m_refund_status;
 		if (refund_status == "1")
 		{
@@ -480,8 +479,9 @@ void CWaimaiOrderInfoUI::Refresh(CWaimaiOrder& order)
 			disagree_button->SetVisible(false);
 		}
 
-		pRefundStatus->SetVisible(true);
+		refund_button->SetVisible(false);
 
+		pRefundStatus->SetVisible(true);
 		refundHeight = 30;
 
 		std::wstring refund_status_text = L"退款状态:";
@@ -515,7 +515,7 @@ void CWaimaiOrderInfoUI::Refresh(CWaimaiOrder& order)
 	if (m_order.m_configmemo != "")
 	{
 		configMemoHeight = 30;
-
+		
 		wstring configMemo = L"商家备注:" + CLewaimaiString::UTF8ToUnicode(order.m_configmemo);
 		pConfigmemo->SetText(configMemo.c_str());
 		pConfigmemo->SetVisible(true);

+ 0 - 2
zhipuzi_pos_windows/control/CWaimaiOrderItemUI.h

@@ -44,7 +44,6 @@ private:
 
 	std::string m_is_selftake;
 	std::string m_delivery_date;
-	std::string m_deliverytime;
 
 	std::string m_restaurant_number;
 
@@ -52,4 +51,3 @@ private:
 
 	int m_status = 1; //1:未处理 2:已确认 3:配送中 4:成功 5:失败 6:已取消 7:退款中
 };
-

+ 111 - 0
zhipuzi_pos_windows/helper/CBitmapHelper.cpp

@@ -0,0 +1,111 @@
+#include "../pch/pch.h"
+#include "CBitmapHelper.h"
+
+
+CBitmapHelper::CBitmapHelper()
+{
+}
+
+
+CBitmapHelper::~CBitmapHelper()
+{
+    if(m_bmp != NULL)
+    {
+        delete m_bmp;
+    }
+}
+
+void CBitmapHelper::LockBitmap(Gdiplus::Bitmap *bmp, BitmapData *data)
+{
+    Gdiplus::Rect r(0, 0, bmp->GetWidth(), bmp->GetHeight());
+    bmp->LockBits(&r, ImageLockModeRead | ImageLockModeWrite,
+                  PixelFormat32bppARGB, data);
+}
+
+void CBitmapHelper::UnlockBitmap(Gdiplus::Bitmap *bmp, BitmapData *data)
+{
+    bmp->UnlockBits(data);
+}
+
+void CBitmapHelper::Gray(BitmapData *data)
+{
+    PARGBQuad p = (PARGBQuad)data->Scan0;
+    INT offset = data->Stride - data->Width * sizeof(ARGBQuad);
+
+    for(UINT y = 0; y < data->Height; y++, p = (PARGBQuad)((BYTE*)p + offset))
+    {
+        for(UINT x = 0; x < data->Width; x++, p++)
+            p->Blue = p->Green = p->Red =
+                                     (UINT)(p->Blue * 29 + p->Green * 150 + p->Red * 77 + 128) >> 8;
+
+    }
+}
+
+void CBitmapHelper::GrayAnd2Values(BitmapData *data)
+{
+    PARGBQuad p = (PARGBQuad)data->Scan0;
+    INT offset = data->Stride - data->Width * sizeof(ARGBQuad);
+
+    for(UINT y = 0; y < data->Height; y++, p = (PARGBQuad)((BYTE*)p + offset))
+    {
+        for(UINT x = 0; x < data->Width; x++, p++)
+        {
+            if(((p->Blue * 29 + p->Green * 150 + p->Red * 77 + 128) >> 8) < m_threshold)
+            {
+                //灰度值不够,就变为黑色
+                p->Color &= 0xff000000;
+            }
+            else
+            {
+                //灰度值高,就是白色
+                p->Color |= 0x00ffffff;
+            }
+        }
+    }
+}
+
+/*
+ *加载一张图片,并保存为二值图的格式
+ **/
+void CBitmapHelper::Image2Values()
+{
+    BitmapData data;
+    LockBitmap(m_bmp, &data);
+
+    GrayAnd2Values(&data);
+
+    UnlockBitmap(m_bmp, &data);
+}
+
+Gdiplus::Bitmap* CBitmapHelper::getBmp()
+{
+    return m_bmp;
+}
+
+void CBitmapHelper::ScaleBitmap(UINT nWidth, UINT nHeight)
+{
+    Bitmap * pTemp = new Bitmap(nWidth, nHeight, m_bmp->GetPixelFormat());
+
+    if(pTemp)
+    {
+        Graphics * g = Graphics::FromImage(pTemp);
+
+        if(g)
+        {
+            g->SetInterpolationMode(InterpolationModeHighQualityBicubic);
+
+            g->DrawImage(m_bmp, 0, 0, nWidth, nHeight);
+
+            delete g;
+        }
+    }
+
+    delete m_bmp;
+
+    m_bmp = pTemp;
+}
+
+void CBitmapHelper::LoadImage(std::wstring wsPath)
+{
+	m_bmp = new Gdiplus::Bitmap(wsPath.c_str());
+}

+ 46 - 0
zhipuzi_pos_windows/helper/CBitmapHelper.h

@@ -0,0 +1,46 @@
+#pragma once
+
+#include "../pch/pch.h"
+
+typedef union
+{
+    ARGB Color;
+    struct
+    {
+        BYTE Blue;
+        BYTE Green;
+        BYTE Red;
+        BYTE Alpha;
+    };
+} ARGBQuad, *PARGBQuad;
+
+class CBitmapHelper
+{
+public:
+	CBitmapHelper();
+	~CBitmapHelper();
+
+	void LockBitmap(Gdiplus::Bitmap *bmp, BitmapData *data);
+
+	void UnlockBitmap(Gdiplus::Bitmap *bmp, BitmapData *data);
+
+	//ת³É»Ò¶Èͼ
+	void Gray(BitmapData *data);
+
+	//ת³É¶þֵͼ
+	void GrayAnd2Values(BitmapData *data);
+
+	void Image2Values();
+
+	Gdiplus::Bitmap* getBmp();
+
+	void ScaleBitmap(UINT nWidth, UINT nHeight);
+
+	void LoadImage(std::wstring wsPath);
+
+private:
+    Gdiplus::Bitmap* m_bmp = NULL;
+
+    int m_threshold = 200;
+};
+

+ 82 - 19
zhipuzi_pos_windows/helper/CLewaimaiString.cpp

@@ -168,7 +168,8 @@ std::string CLewaimaiString::UrlDecode(const std::string& str)
     return strTemp;
 }
 
-std::string CLewaimaiString::UnicodeToUTF8(const std::wstring& wstr)
+/*
+std::string CLewaimaiString::UnicodeToUTF8(const std::wstring wstr)
 {
     std::string ret;
 
@@ -184,9 +185,10 @@ std::string CLewaimaiString::UnicodeToUTF8(const std::wstring& wstr)
     }
 
     return ret;
-}
+}*/
 
-std::wstring CLewaimaiString::UTF8ToUnicode(const std::string& str)
+/*
+std::wstring CLewaimaiString::UTF8ToUnicode(const std::string str)
 {
     std::wstring ret;
 
@@ -202,48 +204,109 @@ std::wstring CLewaimaiString::UTF8ToUnicode(const std::string& str)
     }
 
     return ret;
+}*/
+
+std::string CLewaimaiString::UnicodeToUTF8(const std::wstring wstr)
+{
+    char* pElementText;
+    int iTextLen;
+    // wide char to multi char
+    iTextLen = WideCharToMultiByte(CP_UTF8,
+                                   0,
+                                   wstr.c_str(),
+                                   -1,
+                                   NULL,
+                                   0,
+                                   NULL,
+                                   NULL);
+    pElementText = new char[iTextLen + 1];
+    memset((void*)pElementText, 0, sizeof(char) * (iTextLen + 1));
+    ::WideCharToMultiByte(CP_UTF8,
+                          0,
+                          wstr.c_str(),
+                          -1,
+                          pElementText,
+                          iTextLen,
+                          NULL,
+                          NULL);
+    string strText;
+    strText = pElementText;
+    delete[] pElementText;
+    return strText;
+}
+
+std::wstring CLewaimaiString::UTF8ToUnicode(const std::string str)
+{
+    int len = 0;
+    len = str.length();
+    int unicodeLen = ::MultiByteToWideChar(CP_UTF8,
+                                           0,
+                                           str.c_str(),
+                                           -1,
+                                           NULL,
+                                           0);
+    wchar_t* pUnicode;
+    pUnicode = new wchar_t[unicodeLen + 1];
+    memset(pUnicode, 0, (unicodeLen + 1) * sizeof(wchar_t));
+    ::MultiByteToWideChar(CP_UTF8,
+                          0,
+                          str.c_str(),
+                          -1,
+                          (LPWSTR)pUnicode,
+                          unicodeLen);
+    wstring rt;
+    rt = (wchar_t*)pUnicode;
+    delete pUnicode;
+
+    return rt;
 }
 
-std::string CLewaimaiString::UnicodeToANSI(const std::wstring& wstr)
+std::string CLewaimaiString::UnicodeToANSI(const std::wstring wstr)
 {
     unsigned len = wstr.size() * 4;
-	if (len == 0)
-	{
-		return "";
-	}
+    if(len == 0)
+    {
+        return "";
+    }
 
     setlocale(LC_CTYPE, "");
-    char *p = new char[len];
+    char* p = new char[len];
     wcstombs(p, wstr.c_str(), len);
     std::string str1(p);
     delete[] p;
     return str1;
 }
 
-std::wstring CLewaimaiString::ANSIToUnicode(const std::string& str)
+std::wstring CLewaimaiString::ANSIToUnicode(const std::string str)
 {
     unsigned len = str.size() * 2;// 预留字节数
-	if (len == 0)
-	{
-		return L"";
-	}
+    if(len == 0)
+    {
+        return L"";
+    }
 
     setlocale(LC_CTYPE, "");     //必须调用此函数
-    wchar_t *p = new wchar_t[len];// 申请一段内存存放转换后的字符串
+    wchar_t* p = new wchar_t[len];// 申请一段内存存放转换后的字符串
     mbstowcs(p, str.c_str(), len);// 转换
     std::wstring str1(p);
     delete[] p;// 释放申请的内存
     return str1;
 }
 
-std::string CLewaimaiString::UTF8ToANSI(const std::string& str)
+std::string CLewaimaiString::UTF8ToANSI(const std::string str)
 {
-    return UnicodeToANSI(UTF8ToUnicode(str));
+    std::wstring wsUnicode = CLewaimaiString::UTF8ToUnicode(str);
+    std::string sAnsi = CLewaimaiString::UnicodeToANSI(wsUnicode);
+
+    return sAnsi;
 }
 
-std::string CLewaimaiString::ANSIToUTF8(const std::string& str)
+std::string CLewaimaiString::ANSIToUTF8(const std::string str)
 {
-    return UnicodeToUTF8(ANSIToUnicode(str));
+    std::wstring wsUnicode = CLewaimaiString::ANSIToUnicode(str);
+    std::string sUtf8 = CLewaimaiString::UnicodeToUTF8(wsUnicode);
+
+    return sUtf8;
 }
 
 std::string CLewaimaiString::DoubleToString(const double value, unsigned int precisionAfterPoint)

+ 6 - 6
zhipuzi_pos_windows/helper/CLewaimaiString.h

@@ -19,17 +19,17 @@ public:
 
 	static void trim(string &s);
 
-	static std::string UnicodeToUTF8(const std::wstring & wstr);
+	static std::string UnicodeToUTF8(const std::wstring wstr);
 
-	static std::wstring UTF8ToUnicode(const std::string & str);
+	static std::wstring UTF8ToUnicode(const std::string str);
 
-	static std::string UnicodeToANSI(const std::wstring & wstr);
+	static std::string UnicodeToANSI(const std::wstring wstr);
 
-	static std::wstring ANSIToUnicode(const std::string & str);
+	static std::wstring ANSIToUnicode(const std::string str);
 
-	static std::string UTF8ToANSI(const std::string & str);
+	static std::string UTF8ToANSI(const std::string str);
 
-	static std::string ANSIToUTF8(const std::string & str);
+	static std::string ANSIToUTF8(const std::string str);
 
 	static std::string DoubleToString(const double value, unsigned int precisionAfterPoint);
 

+ 168 - 168
zhipuzi_pos_windows/network/CHttpClient.cpp

@@ -4,7 +4,7 @@
 #include <curl/curl.h>
 
 CHttpClient::CHttpClient(void) :
-	m_bDebug(false)
+    m_bDebug(false)
 {
 
 }
@@ -16,107 +16,107 @@ CHttpClient::~CHttpClient(void)
 
 static int OnDebug(CURL *, curl_infotype itype, char * pData, size_t size, void *)
 {
-	if (itype == CURLINFO_TEXT)
-	{
-		//printf("[TEXT]%s\n", pData);
-	}
-	else if (itype == CURLINFO_HEADER_IN)
-	{
-		printf("[HEADER_IN]%s\n", pData);
-	}
-
-	else if (itype == CURLINFO_HEADER_OUT)
-	{
-		printf("[HEADER_OUT]%s\n", pData);
-	}
-
-	else if (itype == CURLINFO_DATA_IN)
-	{
-		printf("[DATA_IN]%s\n", pData);
-	}
-
-	else if (itype == CURLINFO_DATA_OUT)
-	{
-		printf("[DATA_OUT]%s\n", pData);
-	}
-
-	return 0;
+    if(itype == CURLINFO_TEXT)
+    {
+        //printf("[TEXT]%s\n", pData);
+    }
+    else if(itype == CURLINFO_HEADER_IN)
+    {
+        printf("[HEADER_IN]%s\n", pData);
+    }
+
+    else if(itype == CURLINFO_HEADER_OUT)
+    {
+        printf("[HEADER_OUT]%s\n", pData);
+    }
+
+    else if(itype == CURLINFO_DATA_IN)
+    {
+        printf("[DATA_IN]%s\n", pData);
+    }
+
+    else if(itype == CURLINFO_DATA_OUT)
+    {
+        printf("[DATA_OUT]%s\n", pData);
+    }
+
+    return 0;
 }
 
 static size_t OnWriteData(void* buffer, size_t size, size_t nmemb, void* lpVoid)
 {
-	std::string* str = dynamic_cast<std::string*>((std::string *)lpVoid);
+    std::string* str = dynamic_cast<std::string*>((std::string *)lpVoid);
 
-	if (NULL == str || NULL == buffer)
-	{
-		return -1;
-	}
+    if(NULL == str || NULL == buffer)
+    {
+        return -1;
+    }
 
-	char* pData = (char*)buffer;
-	str->append(pData, size * nmemb);
-	return nmemb;
+    char* pData = (char*)buffer;
+    str->append(pData, size * nmemb);
+    return nmemb;
 }
 
 int CHttpClient::Post(const std::string & strUrl, const std::string & strPost, std::string & strResponse)
 {
-	CURLcode res;
-	CURL* curl = curl_easy_init();
-
-	if (NULL == curl)
-	{
-		return CURLE_FAILED_INIT;
-	}
-
-	if (m_bDebug)
-	{
-		curl_easy_setopt(curl, CURLOPT_VERBOSE, 1);
-		curl_easy_setopt(curl, CURLOPT_DEBUGFUNCTION, OnDebug);
-	}
-
-	curl_easy_setopt(curl, CURLOPT_URL, strUrl.c_str());
-	curl_easy_setopt(curl, CURLOPT_POST, 1);
-	curl_easy_setopt(curl, CURLOPT_POSTFIELDS, strPost.c_str());
-	curl_easy_setopt(curl, CURLOPT_READFUNCTION, NULL);
-	curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, OnWriteData);
-	curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void *)&strResponse);
-	curl_easy_setopt(curl, CURLOPT_NOSIGNAL, 1);
-	curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, 8);//连接超时,这个数值如果设置太短可能导致数据请求不到就断开了
-	curl_easy_setopt(curl, CURLOPT_TIMEOUT, 10);//接收数据时超时设置,如果10秒内数据未接收完,直接退出
-	res = curl_easy_perform(curl);
-	curl_easy_cleanup(curl);
-	return res;
+    CURLcode res;
+    CURL* curl = curl_easy_init();
+
+    if(NULL == curl)
+    {
+        return CURLE_FAILED_INIT;
+    }
+
+    if(m_bDebug)
+    {
+        curl_easy_setopt(curl, CURLOPT_VERBOSE, 1);
+        curl_easy_setopt(curl, CURLOPT_DEBUGFUNCTION, OnDebug);
+    }
+
+    curl_easy_setopt(curl, CURLOPT_URL, strUrl.c_str());
+    curl_easy_setopt(curl, CURLOPT_POST, 1);
+    curl_easy_setopt(curl, CURLOPT_POSTFIELDS, strPost.c_str());
+    curl_easy_setopt(curl, CURLOPT_READFUNCTION, NULL);
+    curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, OnWriteData);
+    curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void *)&strResponse);
+    curl_easy_setopt(curl, CURLOPT_NOSIGNAL, 1);
+    curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, 8);//连接超时,这个数值如果设置太短可能导致数据请求不到就断开了
+    curl_easy_setopt(curl, CURLOPT_TIMEOUT, 10);//接收数据时超时设置,如果10秒内数据未接收完,直接退出
+    res = curl_easy_perform(curl);
+    curl_easy_cleanup(curl);
+    return res;
 }
 
 int CHttpClient::Get(const std::string & strUrl, std::string & strResponse)
 {
-	CURLcode res;
-	CURL* curl = curl_easy_init();
-
-	if (NULL == curl)
-	{
-		return CURLE_FAILED_INIT;
-	}
-
-	if (m_bDebug)
-	{
-		curl_easy_setopt(curl, CURLOPT_VERBOSE, 1);
-		curl_easy_setopt(curl, CURLOPT_DEBUGFUNCTION, OnDebug);
-	}
-
-	curl_easy_setopt(curl, CURLOPT_URL, strUrl.c_str());
-	curl_easy_setopt(curl, CURLOPT_READFUNCTION, NULL);
-	curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, OnWriteData);
-	curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void *)&strResponse);
-	/**
-	* 当多个线程都使用超时处理的时候,同时主线程中有sleep或是wait等操作。
-	* 如果不设置这个选项,libcurl将会发信号打断这个wait从而导致程序退出。
-	*/
-	curl_easy_setopt(curl, CURLOPT_NOSIGNAL, 1);
-	curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, 8);//连接超时,这个数值如果设置太短可能导致数据请求不到就断开了
-	curl_easy_setopt(curl, CURLOPT_TIMEOUT, 10);//接收数据时超时设置,如果10秒内数据未接收完,直接退出
-	res = curl_easy_perform(curl);
-	curl_easy_cleanup(curl);
-	return res;
+    CURLcode res;
+    CURL* curl = curl_easy_init();
+
+    if(NULL == curl)
+    {
+        return CURLE_FAILED_INIT;
+    }
+
+    if(m_bDebug)
+    {
+        curl_easy_setopt(curl, CURLOPT_VERBOSE, 1);
+        curl_easy_setopt(curl, CURLOPT_DEBUGFUNCTION, OnDebug);
+    }
+
+    curl_easy_setopt(curl, CURLOPT_URL, strUrl.c_str());
+    curl_easy_setopt(curl, CURLOPT_READFUNCTION, NULL);
+    curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, OnWriteData);
+    curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void *)&strResponse);
+    /**
+    * 当多个线程都使用超时处理的时候,同时主线程中有sleep或是wait等操作。
+    * 如果不设置这个选项,libcurl将会发信号打断这个wait从而导致程序退出。
+    */
+    curl_easy_setopt(curl, CURLOPT_NOSIGNAL, 1);
+    curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, 8);//连接超时,这个数值如果设置太短可能导致数据请求不到就断开了
+    curl_easy_setopt(curl, CURLOPT_TIMEOUT, 10);//接收数据时超时设置,如果10秒内数据未接收完,直接退出
+    res = curl_easy_perform(curl);
+    curl_easy_cleanup(curl);
+    return res;
 }
 
 /*
@@ -124,94 +124,94 @@ int CHttpClient::Get(const std::string & strUrl, std::string & strResponse)
  **/
 int CHttpClient::Posts(const std::string & strUrl, const std::string & strPost, std::string & strResponse, const char * pCaPath)
 {
-	CURLcode res;
-	CURL* curl = curl_easy_init();
-
-	if (NULL == curl)
-	{
-		return CURLE_FAILED_INIT;
-	}
-
-	if (m_bDebug)
-	{
-		curl_easy_setopt(curl, CURLOPT_VERBOSE, 1);
-		curl_easy_setopt(curl, CURLOPT_DEBUGFUNCTION, OnDebug);
-	}
-
-	curl_easy_setopt(curl, CURLOPT_URL, strUrl.c_str());
-	curl_easy_setopt(curl, CURLOPT_POST, 1);
-	curl_easy_setopt(curl, CURLOPT_POSTFIELDS, strPost.c_str());
-	curl_easy_setopt(curl, CURLOPT_READFUNCTION, NULL);
-	curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, OnWriteData);
-	curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void *)&strResponse);
-	curl_easy_setopt(curl, CURLOPT_NOSIGNAL, 1);
-	//curl_easy_setopt(curl, CURLOPT_COOKIE, "lwm_gray_tag=rc");;
-
-	if (NULL == pCaPath)
-	{
-		curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, false);
-		curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, false);
-	}
-
-	else
-	{
-		//缺省情况就是PEM,所以无需设置,另外支持DER
-		//curl_easy_setopt(curl,CURLOPT_SSLCERTTYPE,"PEM");
-		curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, true);
-		curl_easy_setopt(curl, CURLOPT_CAINFO, pCaPath);
-	}
-
-	curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, 8);//连接超时,这个数值如果设置太短可能导致数据请求不到就断开了
-	curl_easy_setopt(curl, CURLOPT_TIMEOUT, 10);//接收数据时超时设置,如果10秒内数据未接收完,直接退出
-	res = curl_easy_perform(curl);
-	curl_easy_cleanup(curl);
-	return res;
+    CURLcode res;
+    CURL* curl = curl_easy_init();
+
+    if(NULL == curl)
+    {
+        return CURLE_FAILED_INIT;
+    }
+
+    if(m_bDebug)
+    {
+        curl_easy_setopt(curl, CURLOPT_VERBOSE, 1);
+        curl_easy_setopt(curl, CURLOPT_DEBUGFUNCTION, OnDebug);
+    }
+
+    curl_easy_setopt(curl, CURLOPT_URL, strUrl.c_str());
+    curl_easy_setopt(curl, CURLOPT_POST, 1);
+    curl_easy_setopt(curl, CURLOPT_POSTFIELDS, strPost.c_str());
+    curl_easy_setopt(curl, CURLOPT_READFUNCTION, NULL);
+    curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, OnWriteData);
+    curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void *)&strResponse);
+    curl_easy_setopt(curl, CURLOPT_NOSIGNAL, 1);
+    //curl_easy_setopt(curl, CURLOPT_COOKIE, "lwm_gray_tag=rc");;
+
+    if(NULL == pCaPath)
+    {
+        curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, false);
+        curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, false);
+    }
+
+    else
+    {
+        //缺省情况就是PEM,所以无需设置,另外支持DER
+        //curl_easy_setopt(curl,CURLOPT_SSLCERTTYPE,"PEM");
+        curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, true);
+        curl_easy_setopt(curl, CURLOPT_CAINFO, pCaPath);
+    }
+
+    curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, 8);//连接超时,这个数值如果设置太短可能导致数据请求不到就断开了
+    curl_easy_setopt(curl, CURLOPT_TIMEOUT, 10);//接收数据时超时设置,如果10秒内数据未接收完,直接退出
+    res = curl_easy_perform(curl);
+    curl_easy_cleanup(curl);
+    return res;
 }
 
 int CHttpClient::Gets(const std::string & strUrl, std::string & strResponse, const char * pCaPath)
 {
-	CURLcode res;
-	CURL* curl = curl_easy_init();
-
-	if (NULL == curl)
-	{
-		return CURLE_FAILED_INIT;
-	}
-
-	if (m_bDebug)
-	{
-		curl_easy_setopt(curl, CURLOPT_VERBOSE, 1);
-		curl_easy_setopt(curl, CURLOPT_DEBUGFUNCTION, OnDebug);
-	}
-
-	curl_easy_setopt(curl, CURLOPT_URL, strUrl.c_str());
-	curl_easy_setopt(curl, CURLOPT_READFUNCTION, NULL);
-	curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, OnWriteData);
-	curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void *)&strResponse);
-	curl_easy_setopt(curl, CURLOPT_NOSIGNAL, 1);
-
-	if (NULL == pCaPath)
-	{
-		curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, false);
-		curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, false);
-	}
-
-	else
-	{
-		curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, true);
-		curl_easy_setopt(curl, CURLOPT_CAINFO, pCaPath);
-	}
-
-	curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, 8);//连接超时,这个数值如果设置太短可能导致数据请求不到就断开了
-	curl_easy_setopt(curl, CURLOPT_TIMEOUT, 10);//接收数据时超时设置,如果10秒内数据未接收完,直接退出
-	res = curl_easy_perform(curl);
-	curl_easy_cleanup(curl);
-	return res;
+    CURLcode res;
+    CURL* curl = curl_easy_init();
+
+    if(NULL == curl)
+    {
+        return CURLE_FAILED_INIT;
+    }
+
+    if(m_bDebug)
+    {
+        curl_easy_setopt(curl, CURLOPT_VERBOSE, 1);
+        curl_easy_setopt(curl, CURLOPT_DEBUGFUNCTION, OnDebug);
+    }
+
+    curl_easy_setopt(curl, CURLOPT_URL, strUrl.c_str());
+    curl_easy_setopt(curl, CURLOPT_READFUNCTION, NULL);
+    curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, OnWriteData);
+    curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void *)&strResponse);
+    curl_easy_setopt(curl, CURLOPT_NOSIGNAL, 1);
+
+    if(NULL == pCaPath)
+    {
+        curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, false);
+        curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, false);
+    }
+
+    else
+    {
+        curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, true);
+        curl_easy_setopt(curl, CURLOPT_CAINFO, pCaPath);
+    }
+
+    curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, 8);//连接超时,这个数值如果设置太短可能导致数据请求不到就断开了
+    curl_easy_setopt(curl, CURLOPT_TIMEOUT, 10);//接收数据时超时设置,如果10秒内数据未接收完,直接退出
+    res = curl_easy_perform(curl);
+    curl_easy_cleanup(curl);
+    return res;
 }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////
 
 void CHttpClient::SetDebug(bool bDebug)
 {
-	m_bDebug = bDebug;
+    m_bDebug = bDebug;
 }

+ 39 - 39
zhipuzi_pos_windows/network/CHttpClient.h

@@ -5,50 +5,50 @@ using namespace std;
 class CHttpClient
 {
 public:
-	CHttpClient();
-	~CHttpClient();
+    CHttpClient();
+    ~CHttpClient();
 
 public:
-	/**
-	* @brief HTTP POST请求
-	* @param strUrl 输入参数,请求的Url地址,如:http://www.baidu.com
-	* @param strPost 输入参数,使用如下格式para1=val1&para2=val2&…
-	* @param strResponse 输出参数,返回的内容
-	* @return 返回是否Post成功
-	*/
-	int Post(const std::string & strUrl, const std::string & strPost, std::string & strResponse);
-
-	/**
-	* @brief HTTP GET请求
-	* @param strUrl 输入参数,请求的Url地址,如:http://www.baidu.com
-	* @param strResponse 输出参数,返回的内容
-	* @return 返回是否Post成功
-	*/
-	int Get(const std::string & strUrl, std::string & strResponse);
-
-	/**
-	* @brief HTTPS POST请求,无证书版本
-	* @param strUrl 输入参数,请求的Url地址,如:https://www.alipay.com
-	* @param strPost 输入参数,使用如下格式ppara1=val1&para2=val2&…
-	* @param strResponse 输出参数,返回的内容
-	* @param pCaPath 输入参数,为CA证书的路径.如果输入为NULL,则不验证服务器端证书的有效性.
-	* @return 返回是否Post成功
-	*/
-	int Posts(const std::string & strUrl, const std::string & strPost, std::string & strResponse, const char * pCaPath = NULL);
-
-	/**
-	* @brief HTTPS GET请求,无证书版本
-	* @param strUrl 输入参数,请求的Url地址,如:https://www.alipay.com
-	* @param strResponse 输出参数,返回的内容
-	* @param pCaPath 输入参数,为CA证书的路径.如果输入为NULL,则不验证服务器端证书的有效性.
-	* @return 返回是否Post成功
-	*/
-	int Gets(const std::string & strUrl, std::string & strResponse, const char * pCaPath = NULL);
+    /**
+    * @brief HTTP POST请求
+    * @param strUrl 输入参数,请求的Url地址,如:http://www.baidu.com
+    * @param strPost 输入参数,使用如下格式para1=val1&para2=val2&…
+    * @param strResponse 输出参数,返回的内容
+    * @return 返回是否Post成功
+    */
+    int Post(const std::string & strUrl, const std::string & strPost, std::string & strResponse);
+
+    /**
+    * @brief HTTP GET请求
+    * @param strUrl 输入参数,请求的Url地址,如:http://www.baidu.com
+    * @param strResponse 输出参数,返回的内容
+    * @return 返回是否Post成功
+    */
+    int Get(const std::string & strUrl, std::string & strResponse);
+
+    /**
+    * @brief HTTPS POST请求,无证书版本
+    * @param strUrl 输入参数,请求的Url地址,如:https://www.alipay.com
+    * @param strPost 输入参数,使用如下格式ppara1=val1&para2=val2&…
+    * @param strResponse 输出参数,返回的内容
+    * @param pCaPath 输入参数,为CA证书的路径.如果输入为NULL,则不验证服务器端证书的有效性.
+    * @return 返回是否Post成功
+    */
+    int Posts(const std::string & strUrl, const std::string & strPost, std::string & strResponse, const char * pCaPath = NULL);
+
+    /**
+    * @brief HTTPS GET请求,无证书版本
+    * @param strUrl 输入参数,请求的Url地址,如:https://www.alipay.com
+    * @param strResponse 输出参数,返回的内容
+    * @param pCaPath 输入参数,为CA证书的路径.如果输入为NULL,则不验证服务器端证书的有效性.
+    * @return 返回是否Post成功
+    */
+    int Gets(const std::string & strUrl, std::string & strResponse, const char * pCaPath = NULL);
 
 public:
-	void SetDebug(bool bDebug);
+    void SetDebug(bool bDebug);
 
 private:
-	bool m_bDebug;
+    bool m_bDebug;
 };
 

+ 369 - 306
zhipuzi_pos_windows/network/CMessagePush.cpp

@@ -15,15 +15,15 @@ CMessagePush::~CMessagePush()
 
 void CMessagePush::Start()
 {
-    m_is_work = true;
+	m_is_work = true;
 
-    m_nStopNum = 0;
+	m_nStopNum = 0;
 
     //心跳包
-    std::thread(&CMessagePush::KeepAlive, this).detach();
+	std::thread(&CMessagePush::KeepAlive, this).detach();
 
-    //接收消息
-    std::thread(&CMessagePush::ReceiveMessage, this).detach();
+	//接收消息
+	std::thread(&CMessagePush::ReceiveMessage, this).detach();
 
     //处理声音提醒
     std::thread(&CMessagePush::HandleVoice, this).detach();
@@ -31,251 +31,261 @@ void CMessagePush::Start()
     //处理订单确认
     std::thread(&CMessagePush::HandleConfirm, this).detach();
 
-    //处理打印
-    std::thread(&CMessagePush::HandlePrinter, this).detach();
+	//处理打印
+	std::thread(&CMessagePush::HandlePrinter, this).detach();
 
     //处理收银打印
     std::thread(&CMessagePush::HandleShouyinPrinter, this).detach();
 
+	//处理标签打印
+	std::thread(&CMessagePush::HandleBiaoqianPrinter, this).detach();
+
     //处理厨房打印
     std::thread(&CMessagePush::HandleChufangPrinter, this).detach();
 }
 
 void CMessagePush::Stop()
 {
-    m_is_work = false;
-
-    socket_.close();
-
-    m_voice_mutex.lock();
-    while(!m_voice_queue.empty())
-    {
-        m_voice_queue.pop();
-    }
-    m_voice_mutex.unlock();
-
-    m_confirm_mutex.lock();
-    while(!m_confirm_queue.empty())
-    {
-        m_confirm_queue.pop();
-    }
-    m_confirm_mutex.unlock();
-
-    m_printer_mutex.lock();
-    while(!m_printer_queue.empty())
-    {
-        m_printer_queue.pop();
-    }
-    m_printer_mutex.unlock();
-
-    m_shouyin_printer_mutex.lock();
-    while(!m_shouyin_printer_queue.empty())
-    {
-        m_shouyin_printer_queue.pop();
-    }
-    m_shouyin_printer_mutex.unlock();
-
-    m_chufang_printer_mutex.lock();
-    while(!m_chufang_printer_queue.empty())
-    {
-        m_chufang_printer_queue.pop();
-    }
-    m_chufang_printer_mutex.unlock();
+	m_is_work = false;
+
+	socket_.close();
+
+	m_voice_mutex.lock();
+	while (!m_voice_queue.empty())
+	{
+		m_voice_queue.pop();
+	}
+	m_voice_mutex.unlock();
+
+	m_confirm_mutex.lock();
+	while (!m_confirm_queue.empty())
+	{
+		m_confirm_queue.pop();
+	}
+	m_confirm_mutex.unlock();
+
+	m_printer_mutex.lock();
+	while (!m_printer_queue.empty())
+	{
+		m_printer_queue.pop();
+	}
+	m_printer_mutex.unlock();
+
+	m_shouyin_printer_mutex.lock();
+	while (!m_shouyin_printer_queue.empty())
+	{
+		m_shouyin_printer_queue.pop();
+	}
+	m_shouyin_printer_mutex.unlock();
+
+	m_biaoqian_printer_mutex.lock();
+	while (!m_biaoqian_printer_queue.empty())
+	{
+		m_biaoqian_printer_queue.pop();
+	}
+	m_biaoqian_printer_mutex.unlock();
+
+	m_chufang_printer_mutex.lock();
+	while (!m_chufang_printer_queue.empty())
+	{
+		m_chufang_printer_queue.pop();
+	}
+	m_chufang_printer_mutex.unlock();
 }
 
 void CMessagePush::KeepAlive()
 {
-    while(m_is_work)
-    {
-        //生成心跳包
-        rapidjson::Document doc;
-        doc.SetObject();
-        rapidjson::Document::AllocatorType& allocator = doc.GetAllocator(); //获取分配器
-
-        std::string username = CSetting::getUsername();
-        std::string timestamp = to_string(time(NULL));
-        doc.AddMember("username", StringRef(username.c_str(), username.length()), allocator);
-        doc.AddMember("timestamp", StringRef(timestamp.c_str(), timestamp.length()), allocator);
-        doc.AddMember("is_login", "0", allocator);
-
-        rapidjson::StringBuffer buffer;
-        rapidjson::Writer<StringBuffer> writer(buffer);
-        doc.Accept(writer);
-
-        //返回给接入层的消息
-        std::string m_keepalive_msg = buffer.GetString();
-
-        PosMessage new_msg;
-        new_msg.m_length = m_keepalive_msg.length();
-        memcpy(new_msg.data, m_keepalive_msg.c_str(), m_keepalive_msg.length());
-        new_msg.data[new_msg.m_length] = '\0';
-
-        try
-        {
-            socket_.write_some(boost::asio::buffer(&new_msg, sizeof(PosMessage)));
-        }
-        catch(const std::exception& e)
-        {
-            //走到这里来说明心跳包发送失败了,socket失效了
-            std::string err = e.what();
-
-            //先把socket关闭掉
-            socket_.close();
-
-            try
-            {
-                //发送失败,重新建立连接
-                char host[] = "pushserver.zhipuzi.com";
-                char port[] = "9001";
-
-                tcp::resolver resolver(m_io_context);
-                tcp::resolver::results_type endpoints =
-                    resolver.resolve(tcp::v4(), host, port);
-
-                boost::asio::connect(socket_, endpoints);
-
-                //刚刚连接上,这是第一次登陆,发送登陆信息
-                rapidjson::Document doc_1;
-                doc_1.SetObject();
-                rapidjson::Document::AllocatorType& allocator_1 = doc_1.GetAllocator(); //获取分配器
-
-                std::string username_1 = CSetting::getUsername();
-                std::string timestamp_1 = to_string(time(NULL));
-                doc_1.AddMember("username", StringRef(username_1.c_str(), username_1.length()), allocator_1);
-                doc_1.AddMember("timestamp", StringRef(timestamp_1.c_str(), timestamp_1.length()), allocator_1);
-                doc_1.AddMember("is_login", "1", allocator_1);
-
-                rapidjson::StringBuffer buffer_1;
-                rapidjson::Writer<StringBuffer> writer_1(buffer_1);
-                doc_1.Accept(writer_1);
-
-                //返回给接入层的消息
-                std::string m_login_message = buffer_1.GetString();
-
-                PosMessage login_msg;
-                login_msg.m_length = m_login_message.length();
-                memcpy(login_msg.data, m_login_message.c_str(), m_login_message.length());
-                login_msg.data[login_msg.m_length] = '\0';
-
-                socket_.write_some(boost::asio::buffer(boost::asio::buffer(&login_msg, sizeof(PosMessage))));
-            }
-            catch(const std::exception& e)
-            {
-                //重新连接或者重新发送又失败了,可能是网络断了
-                std::string err = e.what();
-                LOG_INFO("write err info:" << err.c_str());
-
-                //关闭无效的连接
-                socket_.close();
-
-                //30秒后再重试
-                CSystem::my_sleep(30);
-
-                continue;
-            }
-        }
-
-        //走到这里,说明心跳包发送成功了,socket是连通的
-
-        //休眠30秒钟,之后再发心跳包
-        CSystem::my_sleep(30);
-    }
-
-    AddStopNum();
+	while (m_is_work)
+	{
+		//生成心跳包
+		rapidjson::Document doc;
+		doc.SetObject();
+		rapidjson::Document::AllocatorType& allocator = doc.GetAllocator(); //获取分配器
+
+		std::string username = CSetting::getUsername();
+		std::string timestamp = to_string(time(NULL));
+		doc.AddMember("username", StringRef(username.c_str(), username.length()), allocator);
+		doc.AddMember("timestamp", StringRef(timestamp.c_str(), timestamp.length()), allocator);
+		doc.AddMember("is_login", "0", allocator);
+
+		rapidjson::StringBuffer buffer;
+		rapidjson::Writer<StringBuffer> writer(buffer);
+		doc.Accept(writer);
+
+		//返回给接入层的消息
+		std::string m_keepalive_msg = buffer.GetString();
+
+		PosMessage new_msg;
+		new_msg.m_length = m_keepalive_msg.length();
+		memcpy(new_msg.data, m_keepalive_msg.c_str(), m_keepalive_msg.length());
+		new_msg.data[new_msg.m_length] = '\0';
+
+		try
+		{
+			socket_.write_some(boost::asio::buffer(&new_msg, sizeof(PosMessage)));
+		}
+		catch (const std::exception& e)
+		{
+			//走到这里来说明心跳包发送失败了,socket失效了
+			std::string err = e.what();
+
+			//先把socket关闭掉
+			socket_.close();
+
+			try
+			{
+				//发送失败,重新建立连接
+				char host[] = "pushserver.lewaimai.com";
+				char port[] = "9001";
+
+				tcp::resolver resolver(m_io_context);
+				tcp::resolver::results_type endpoints =
+					resolver.resolve(tcp::v4(), host, port);
+
+				boost::asio::connect(socket_, endpoints);
+
+				//刚刚连接上,这是第一次登陆,发送登陆信息
+				rapidjson::Document doc_1;
+				doc_1.SetObject();
+				rapidjson::Document::AllocatorType& allocator_1 = doc_1.GetAllocator(); //获取分配器
+
+				std::string username_1 = CSetting::getUsername();
+				std::string timestamp_1 = to_string(time(NULL));
+				doc_1.AddMember("username", StringRef(username_1.c_str(), username_1.length()), allocator_1);
+				doc_1.AddMember("timestamp", StringRef(timestamp_1.c_str(), timestamp_1.length()), allocator_1);
+				doc_1.AddMember("is_login", "1", allocator_1);
+
+				rapidjson::StringBuffer buffer_1;
+				rapidjson::Writer<StringBuffer> writer_1(buffer_1);
+				doc_1.Accept(writer_1);
+
+				//返回给接入层的消息
+				std::string m_login_message = buffer_1.GetString();
+
+				PosMessage login_msg;
+				login_msg.m_length = m_login_message.length();
+				memcpy(login_msg.data, m_login_message.c_str(), m_login_message.length());
+				login_msg.data[login_msg.m_length] = '\0';
+
+				socket_.write_some(boost::asio::buffer(boost::asio::buffer(&login_msg, sizeof(PosMessage))));
+			}
+			catch (const std::exception& e)
+			{
+				//重新连接或者重新发送又失败了,可能是网络断了
+				std::string err = e.what();
+				LOG_INFO("write err info:" << err.c_str());
+
+				//关闭无效的连接
+				socket_.close();
+
+				//30秒后再重试
+				CSystem::my_sleep(30);
+
+				continue;
+			}
+		}
+
+		//走到这里,说明心跳包发送成功了,socket是连通的
+
+		//休眠30秒钟,之后再发心跳包
+		CSystem::my_sleep(30);
+	}
+
+	AddStopNum();
 }
 
 void CMessagePush::ReceiveMessage()
 {
-    while(m_is_work)
-    {
-        try
-        {
-            PosMessage new_msg;
-
-            boost::asio::read(socket_, boost::asio::buffer(&new_msg, sizeof(PosMessage)));
-
-            std::string msg = new_msg.data;
-
-            //收到服务器的消息,对服务器的消息进行处理
-            rapidjson::Document document;
-            document.Parse(msg.c_str());
-            if(!document.IsObject())
-            {
-                LOG_INFO("message 非法!");
-                return;
-            }
-
-            std::string type;
-            if(document["msg_type"].IsInt())
-            {
-                type = to_string(document["msg_type"].GetInt());
-            }
-            else
-            {
-                type = document["msg_type"].GetString();
-            }
-
-            if(type == "1")
-            {
-                std::string order_id = document["waimai_order_id"].GetString();
-                std::string order_no = document["waimai_order_no"].GetString();
-
-                //新订单来了,首先判断是否要语音提醒
-                if(CSetting::GetParam("setting_is_new_waimai_voice") == "1")
-                {
-                    if(CSetting::GetParam("setting_is_new_waimai_autoconfirm") == "1")
-                    {
-                        AddVoice(2);
-                    }
-                    else
-                    {
-                        AddVoice(1);
-                    }
-                }
-
-                //判断是否要自动确认
-                if(CSetting::GetParam("setting_is_new_waimai_autoconfirm") == "1")
-                {
-                    AddConfirm(order_id);
-                }
-
-                //判断是否右下角弹框提醒
-                if(CSetting::GetParam("setting_is_new_waimai_dialog") == "1")
-                {
-
-                }
-
-                AddPinter(order_id, order_no, 1);
-            }
-            else if(type == "2")
-            {
-                AddVoice(3);
-            }
-            else if(type == "3")
-            {
-                AddVoice(4);
-            }
-            else if(type == "0")
-            {
-                //这个表示被人挤下线了
-                PostMessage(m_hwnd, WM_LOGIN_AGAIN_OUT, 0, 0);
-            }
-
-            //处理完了,接着处理下一条
-            continue;
-        }
-        catch(std::exception& e)
-        {
-            std::string err = e.what();
-            LOG_INFO("read err:" << err.c_str());
-
-            //如果这里异常了,说明socket失效了,等2秒重新读
-            CSystem::my_sleep(2);
-            continue;
-        }
-    }
-
-    AddStopNum();
+	while (m_is_work)
+	{
+		try
+		{
+			PosMessage new_msg;
+			
+			boost::asio::read(socket_, boost::asio::buffer(&new_msg, sizeof(PosMessage)));
+
+			std::string msg = new_msg.data;
+
+			//收到服务器的消息,对服务器的消息进行处理
+			rapidjson::Document document;
+			document.Parse(msg.c_str());
+			if (!document.IsObject())
+			{
+				LOG_INFO("message 非法!");
+				return;
+			}
+
+			std::string type;
+			if (document["msg_type"].IsInt())
+			{
+				type = to_string(document["msg_type"].GetInt());
+			}
+			else
+			{
+				type = document["msg_type"].GetString();
+			}
+
+			if (type == "1")
+			{
+				std::string order_id = document["waimai_order_id"].GetString();
+				std::string order_no = document["waimai_order_no"].GetString();
+
+				//新订单来了,首先判断是否要语音提醒
+				if (CSetting::GetParam("setting_is_new_waimai_voice") == "1")
+				{
+					if (CSetting::GetParam("setting_is_new_waimai_autoconfirm") == "1")
+					{
+						AddVoice(2);
+					}
+					else
+					{
+						AddVoice(1);
+					}
+				}
+
+				//判断是否要自动确认
+				if (CSetting::GetParam("setting_is_new_waimai_autoconfirm") == "1")
+				{
+					AddConfirm(order_id);
+				}
+
+				//判断是否右下角弹框提醒
+				if (CSetting::GetParam("setting_is_new_waimai_dialog") == "1")
+				{
+
+				}
+
+				AddPinter(order_id, order_no, 1);
+			}
+			else if (type == "2")
+			{
+				AddVoice(3);
+			}
+			else if (type == "3")
+			{
+				AddVoice(4);
+			}
+			else if (type == "0")
+			{
+				//这个表示被人挤下线了
+				PostMessage(m_hwnd, WM_LOGIN_AGAIN_OUT, 0, 0);
+			}
+
+			//处理完了,接着处理下一条
+			continue;
+		}
+		catch (std::exception& e)
+		{
+			std::string err = e.what();
+			//LOG_INFO("read err:" << err.c_str());
+
+			//如果这里异常了,说明socket失效了,等2秒重新读
+			CSystem::my_sleep(2);
+			continue;
+		}
+	}
+
+	AddStopNum();
 }
 
 /*
@@ -306,7 +316,7 @@ void CMessagePush::AddPinter(std::string order_id, std::string order_no, int pri
     WaimaiPinterInfo newPrinter;
     newPrinter.order_id = order_id;
     newPrinter.order_no = order_no;
-    newPrinter.print_type = print_type;
+	newPrinter.print_type = print_type;
 
     m_printer_queue.push(newPrinter);
 
@@ -322,6 +332,15 @@ void CMessagePush::AddShouyinPrinter(CWaimaiOrder order)
     m_shouyin_printer_mutex.unlock();
 }
 
+void CMessagePush::AddBiaoqianPrinter(CWaimaiOrder order)
+{
+	m_biaoqian_printer_mutex.lock();
+
+	m_biaoqian_printer_queue.push(order);
+
+	m_biaoqian_printer_mutex.unlock();
+}
+
 void CMessagePush::AddChufangPrinter(CWaimaiOrder order)
 {
     m_chufang_printer_mutex.lock();
@@ -350,32 +369,32 @@ void CMessagePush::HandleVoice()
 
         m_voice_mutex.unlock();
 
-        if(voice_type == 1)
-        {
-            wstring path = CSystem::GetProgramDir() + L"\\music\\waimai_new.wav";
-            PlaySound(path.c_str(), NULL, SND_FILENAME | SND_ASYNC);
-        }
-        else if(voice_type == 2)
-        {
-            wstring path = CSystem::GetProgramDir() + L"\\music\\waimai_new_auto.wav";
-            PlaySound(path.c_str(), NULL, SND_FILENAME | SND_ASYNC);
-        }
-        else if(voice_type == 3)
-        {
-            wstring path = CSystem::GetProgramDir() + L"\\music\\waimai_quxiao.wav";
-            PlaySound(path.c_str(), NULL, SND_FILENAME | SND_ASYNC);
-        }
-        else if(voice_type == 4)
-        {
-            wstring path = CSystem::GetProgramDir() + L"\\music\\waimai_tuikuan.wav";
-            PlaySound(path.c_str(), NULL, SND_FILENAME | SND_ASYNC);
-        }
+		if (voice_type == 1)
+		{
+			wstring path = CSystem::GetProgramDir() + L"\\music\\waimai_new.wav";
+			PlaySound(path.c_str(), NULL, SND_FILENAME | SND_ASYNC);
+		}
+		else if (voice_type == 2)
+		{
+			wstring path = CSystem::GetProgramDir() + L"\\music\\waimai_new_auto.wav";
+			PlaySound(path.c_str(), NULL, SND_FILENAME | SND_ASYNC);
+		}
+		else if (voice_type == 3)
+		{
+			wstring path = CSystem::GetProgramDir() + L"\\music\\waimai_quxiao.wav";
+			PlaySound(path.c_str(), NULL, SND_FILENAME | SND_ASYNC);
+		}
+		else if (voice_type == 4)
+		{
+			wstring path = CSystem::GetProgramDir() + L"\\music\\waimai_tuikuan.wav";
+			PlaySound(path.c_str(), NULL, SND_FILENAME | SND_ASYNC);
+		}
 
         //8秒内最多播放一次
         CSystem::my_sleep(8);
     }
 
-    AddStopNum();
+	AddStopNum();
 }
 
 void CMessagePush::HandleConfirm()
@@ -401,7 +420,7 @@ void CMessagePush::HandleConfirm()
         newOrder.ConfirmeOrder(order_id);
     }
 
-    AddStopNum();
+	AddStopNum();
 }
 
 void CMessagePush::HandlePrinter()
@@ -421,55 +440,72 @@ void CMessagePush::HandlePrinter()
         WaimaiPinterInfo printerInfo = m_printer_queue.front();
         std::string order_id = printerInfo.order_id;
         std::string order_no = printerInfo.order_no;
-        int print_type = printerInfo.print_type;
+		int print_type = printerInfo.print_type;
 
         m_printer_queue.pop();
 
         m_printer_mutex.unlock();
 
         CWaimaiOrder order;
-        if(print_type == 1)
-        {
-            if(CSetting::GetParam("setting_is_new_waimai_printer") == "1" || CSetting::GetParam("setting_is_new_waimai_chufang_printer") == "1")
-            {
-                bool ret = order.InitData(order_id, order_no);
-
-                if(ret == false)
-                {
-                    this->AddPinter(order_id, order_no, print_type);
-                    continue;
-                }
-            }
-
-            //判断是否自动打印收银小票
-            if(CSetting::GetParam("setting_is_new_waimai_printer") == "1")
-            {
-                AddShouyinPrinter(order);
-            }
-
-            //判断是否进行自动的厨房打印
-            if(CSetting::GetParam("setting_is_new_waimai_chufang_printer") == "1")
-            {
-                AddChufangPrinter(order);
-            }
-        }
-        else
-        {
-            bool ret = order.InitData(order_id, order_no);
-
-            if(ret == false)
-            {
-                this->AddPinter(order_id, order_no, print_type);
-                continue;
-            }
-
-            AddShouyinPrinter(order);
-
-            AddChufangPrinter(order);
-        }
+		if (print_type == 1)
+		{
+			if (CSetting::GetParam("setting_is_new_waimai_printer") == "1" || CSetting::GetParam("setting_is_new_waimai_biaoqian_printer") == "1" || CSetting::GetParam("setting_is_new_waimai_chufang_printer") == "1")
+			{
+				bool ret = order.InitData(order_id, order_no);
+
+				if (ret == false)
+				{
+					this->AddPinter(order_id, order_no, print_type);
+					continue;
+				}
+			}
+
+			//判断是否自动打印收银小票
+			if (CSetting::GetParam("setting_is_new_waimai_printer") == "1")
+			{
+				AddShouyinPrinter(order);
+			}
+
+			//判断是否自动打印标签小票
+			if (CSetting::GetParam("setting_is_new_waimai_biaoqian_printer") == "1")
+			{
+				AddBiaoqianPrinter(order);
+			}
+
+			//判断是否进行自动的厨房打印
+			if (CSetting::GetParam("setting_is_new_waimai_chufang_printer") == "1")
+			{
+				AddChufangPrinter(order);
+			}
+		}
+		else
+		{
+			bool ret = order.InitData(order_id, order_no);
+
+			if (ret == false)
+			{
+				this->AddPinter(order_id, order_no, print_type);
+				continue;
+			}
+
+			//手动打印的模式下,收银小票一定打印,标签和厨房如果没开就不打印
+			AddShouyinPrinter(order);
+
+			//判断是否自动打印标签小票
+			if (CSetting::GetParam("setting_is_new_waimai_biaoqian_printer") == "1")
+			{
+				AddBiaoqianPrinter(order);
+			}
+
+			//判断是否进行自动的厨房打印
+			if (CSetting::GetParam("setting_is_new_waimai_chufang_printer") == "1")
+			{
+				AddChufangPrinter(order);
+			}
+		}
     }
 
-    AddStopNum();
+	AddStopNum();
 }
 
 void CMessagePush::HandleShouyinPrinter()
@@ -496,7 +532,34 @@ void CMessagePush::HandleShouyinPrinter()
         printer.PrintWaimaiOrderShouyin(order);
     }
 
-    AddStopNum();
+	AddStopNum();
+}
+
+void CMessagePush::HandleBiaoqianPrinter()
+{
+	while (m_is_work)
+	{
+		m_biaoqian_printer_mutex.lock();
+
+		if (m_biaoqian_printer_queue.empty())
+		{
+			m_biaoqian_printer_mutex.unlock();
+
+			CSystem::my_sleep(1);
+			continue;
+		}
+
+		CWaimaiOrder order = m_biaoqian_printer_queue.front();
+
+		m_biaoqian_printer_queue.pop();
+
+		m_biaoqian_printer_mutex.unlock();
+
+		CPosPrinter printer;
+		printer.PrintWaimaiOrderBiaoqian(order);
+	}
+
+	AddStopNum();
 }
 
 void CMessagePush::HandleChufangPrinter()
@@ -523,20 +586,20 @@ void CMessagePush::HandleChufangPrinter()
         printer.PrintWaimaiOrderChufang(order);
     }
 
-    AddStopNum();
+	AddStopNum();
 }
 
 void CMessagePush::AddStopNum()
 {
-    m_nStopNumMutex.lock();
+	m_nStopNumMutex.lock();
 
-    m_nStopNum++;
+	m_nStopNum++;
 
-    m_nStopNumMutex.unlock();
+	m_nStopNumMutex.unlock();
 
-    if(m_nStopNum == 7)
-    {
-        //确认所有子线程都退出了,再删除自己
-        delete this;
-    }
+	if (m_nStopNum == 8)
+	{
+		//确认所有子线程都退出了,再删除自己
+		delete this;
+	}
 }

+ 55 - 51
zhipuzi_pos_windows/network/CMessagePush.h

@@ -8,85 +8,89 @@ using boost::asio::ip::tcp;
 class CClientMessage
 {
 public:
-    int m_type; //消息类型 0:新的外卖订单
+	int m_type; //消息类型 0:新的外卖订单
 
-    std::string m_username;
-    std::string m_order_id;
-    std::string m_order_no;
+	std::string m_username;
+	std::string m_order_id;
+	std::string m_order_no;
 };
 
 class WaimaiPinterInfo
 {
 public:
-    std::string order_id;
-    std::string order_no;
-    int print_type; //打印类型 1:新订单自动打印 2:手动打印
+	std::string order_id;
+	std::string order_no;
+	int print_type; //打印类型 1:新订单自动打印 2:手动打印
 };
 
 class CMessagePush
 {
 public:
-    CMessagePush(HWND hwnd)
-        : socket_(m_io_context)
-    {
-        m_hwnd = hwnd;
-    }
+	CMessagePush(HWND hwnd)
+		: socket_(m_io_context)
+	{
+		m_hwnd = hwnd;
+	}
 
-    ~CMessagePush();
+	~CMessagePush();
 
-    //开始工作
-    void Start();
+	//开始工作
+	void Start();
 
-    //停止工作
-    void Stop();
+	//停止工作
+	void Stop();
 
-    //发送心跳包
-    void KeepAlive();
+	//发送心跳包
+	void KeepAlive();
 
-    //专门处理推送消息
-    void ReceiveMessage();
+	//专门处理推送消息
+	void ReceiveMessage();
 
-    //队列处理
-    void HandleVoice();
-    void HandleConfirm();
-    void HandlePrinter();
-    void HandleShouyinPrinter();
-    void HandleChufangPrinter();
+	//队列处理
+	void HandleVoice();
+	void HandleConfirm();
+	void HandlePrinter();
+	void HandleShouyinPrinter();
+	void HandleBiaoqianPrinter();
+	void HandleChufangPrinter();
 
 
-    void AddVoice(int voice_type);
-    void AddConfirm(std::string order_id);
-    void AddPinter(std::string order_id, std::string order_no, int print_type);
-    void AddShouyinPrinter(CWaimaiOrder order);
-    void AddChufangPrinter(CWaimaiOrder order);
+	void AddVoice(int voice_type);
+	void AddConfirm(std::string order_id);
+	void AddPinter(std::string order_id, std::string order_no, int print_type);
+	void AddShouyinPrinter(CWaimaiOrder order);
+	void AddBiaoqianPrinter(CWaimaiOrder order);
+	void AddChufangPrinter(CWaimaiOrder order);
 
 private:
-    void AddStopNum();
+	void AddStopNum();
 
 private:
-    bool m_is_work;
+	bool m_is_work;
 
-    int m_nStopNum = 0;
-    std::mutex m_nStopNumMutex;
+	int m_nStopNum = 0;
+	std::mutex m_nStopNumMutex;
 
-    boost::asio::io_context m_io_context;
-    tcp::socket socket_;
+	boost::asio::io_context m_io_context;
+	tcp::socket socket_;
 
-    enum { max_length = 1024 };
-    char data_[max_length];
+	enum { max_length = 1024 };
+	char data_[max_length];
 
-    std::queue<int> m_voice_queue;
-    std::queue<std::string> m_confirm_queue;
-    std::queue<WaimaiPinterInfo> m_printer_queue;
-    std::queue<CWaimaiOrder> m_shouyin_printer_queue;
-    std::queue<CWaimaiOrder> m_chufang_printer_queue;
+	std::queue<int> m_voice_queue;
+	std::queue<std::string> m_confirm_queue;
+	std::queue<WaimaiPinterInfo> m_printer_queue;
+	std::queue<CWaimaiOrder> m_shouyin_printer_queue;
+	std::queue<CWaimaiOrder> m_biaoqian_printer_queue;
+	std::queue<CWaimaiOrder> m_chufang_printer_queue;
 
-    std::mutex m_voice_mutex;
-    std::mutex m_confirm_mutex;
-    std::mutex m_printer_mutex;
-    std::mutex m_shouyin_printer_mutex;
-    std::mutex m_chufang_printer_mutex;
+	std::mutex m_voice_mutex;
+	std::mutex m_confirm_mutex;
+	std::mutex m_printer_mutex;
+	std::mutex m_shouyin_printer_mutex;
+	std::mutex m_biaoqian_printer_mutex;
+	std::mutex m_chufang_printer_mutex;
 
-    HWND m_hwnd;
+	HWND m_hwnd;
 };
 

+ 24 - 14
zhipuzi_pos_windows/network/CZhipuziHttpClient.cpp

@@ -7,8 +7,8 @@ CZhipuziHttpClient CZhipuziHttpClient::m_client;
 
 CZhipuziHttpClient::CZhipuziHttpClient()
 {
-    m_username = CSetting::getUsername();
-    m_password = CSetting::getPassword();
+	m_username = CSetting::getUsername();
+	m_password = CSetting::getPassword();
 }
 
 
@@ -18,26 +18,26 @@ CZhipuziHttpClient::~CZhipuziHttpClient()
 
 void CZhipuziHttpClient::Init(std::string username, std::string password)
 {
-    m_client.m_username = username;
-    m_client.m_password = password;
+	m_client.m_username = username;
+	m_client.m_password = password;
 }
 
 bool CZhipuziHttpClient::Login(std::string& errmsg)
 {
-    std::map<string, string> params;
+	std::map<string, string> params;
 
     std::string response;
     bool ret = m_client.RequestPingtai("/userlogin/userlogin", params, response);
 
-    if(!ret)
-    {
-        //网络请求出错
-        LOG_INFO("network failed!");
-        errmsg = "network failed!";
-        return false;
-    }
+	if (!ret)
+	{
+		//网络请求出错
+		LOG_INFO("network failed!");
+		errmsg = "network failed!";
+		return false;
+	}
 
-    LOG_INFO("response:" << response.c_str());
+	//LOG_INFO("response:" << response.c_str());
 
     rapidjson::Document document;
     document.Parse(response.c_str());
@@ -178,7 +178,7 @@ bool CZhipuziHttpClient::RequestPingtai(std::string url, std::map<string, string
 
 	//计算签名
 	std::string postString;
-	for (std::map<string, string>::iterator it = params.begin(); it != params.end();)
+	for (std::map<string, string>::iterator it = params.begin(); it != params.end(); )
 	{
 		postString += it->first + "=" + it->second;
 
@@ -232,6 +232,16 @@ bool CZhipuziHttpClient::RequestPingtai(std::string url, std::map<string, string
 		//ret为0表示没有出错
 		return true;
 	}
+	else
+	{
+		//返回值说明 https://blog.csdn.net/u011857683/article/details/53069268
+		LOG_INFO("request error, ret value:" << ret);
+	}
 
 	return false;
 }
+
+std::string CZhipuziHttpClient::getShopId()
+{
+	return m_client.m_shop_id;
+}

+ 17 - 9
zhipuzi_pos_windows/network/CZhipuziHttpClient.h

@@ -5,26 +5,34 @@
 class CZhipuziHttpClient
 {
 public:
-    CZhipuziHttpClient();
-    ~CZhipuziHttpClient();
+	CZhipuziHttpClient();
+	~CZhipuziHttpClient();
 
 public:
-    static void Init(std::string username, std::string password);
+	static void Init(std::string username, std::string password);
 
-    static bool Login(std::string& errmsg);
+	static bool Login(std::string& errmsg);
+
+	static bool Request(std::string url, std::map<string, string> params, std::string& response);
 
-    static bool Request(std::string url, std::map<string, string> params, std::string& response);
 	static bool RequestPingtai(std::string url, std::map<string, string> params, std::string& response);
+
+	static std::string getShopId();
+
 public:
-    static CZhipuziHttpClient m_client;
+	static CZhipuziHttpClient m_client;
 
 private:
-    std::string m_username;
-    std::string m_password;
+	std::string m_username;
+	std::string m_password;
 
     std::string m_pingtai_url = "https://pf-api.zhipuzi.com/pos";
 	std::string m_yewu_ur = "";
 
 	std::string m_version_type;
 	std::string lwm_sess_token;
-};
+
+	//这个是当前登陆的账号对应的店铺ID(如果是连锁店账号就是返回的第一个店铺),主要用于厨房打印的分类打印时候用于获取商品分类
+	std::string m_shop_id;
+};
+

+ 15 - 27
zhipuzi_pos_windows/pch/pch.h

@@ -1,11 +1,4 @@
-// 入门提示: 
-//   1. 使用解决方案资源管理器窗口添加/管理文件
-//   2. 使用团队资源管理器窗口连接到源代码管理
-//   3. 使用输出窗口查看生成输出和其他消息
-//   4. 使用错误列表窗口查看错误
-//   5. 转到“项目”>“添加新项”以创建新的代码文件,或转到“项目”>“添加现有项”以将现有代码文件添加到项目
-//   6. 将来,若要再次打开此项目,请转到“文件”>“打开”>“项目”并选择 .sln 文件
-
+
 #ifndef PCH_H
 #define PCH_H
 
@@ -34,36 +27,33 @@
 
 using namespace std;
 
-/*
- *boost库的头文件
- **/
+//boost库的头文件
 #include <boost/asio.hpp>
 #include <boost/bind.hpp>
 
-/*
- *操作系统相关的头文件
- **/
-#ifdef _WIN32
+using boost::asio::ip::tcp;
+
+//windows库
 #include <windows.h>
-#include<io.h>
+#include <io.h>
 #include <ShellAPI.h>
-#else
-#include <unistd.h>
-#include <sys/sysinfo.h>
-#endif
-
 #include <atltypes.h>
 #include <objbase.h>
 #include <zmouse.h>
 #include <exdisp.h>
 #include <comdef.h>
+#include <winioctl.h>
+#include <setupapi.h>
 
- /*
-  *UI库用到的一些东西
-  **/
+//UI库
 #include <DuiLib/UIlib.h>
 using namespace DuiLib;
 
+//gdi+
+#include <gdiplus.h>
+using namespace Gdiplus;
+
+//资源文件
 #include "../resource/resource.h"
 
 //json库
@@ -74,9 +64,7 @@ using namespace DuiLib;
 
 using namespace rapidjson;
 
-/*
- *常用的辅助函数
- **/
+//自己写的辅助函数
 #include "../helper/define.h"
 #include "../helper/CRandomHelper.h"
 #include "../helper/CSystem.h"

+ 50 - 0
zhipuzi_pos_windows/tool/CComHelper.cpp

@@ -0,0 +1,50 @@
+#include "../pch/pch.h"
+#include "CComHelper.h"
+
+
+CComHelper::CComHelper()
+{
+}
+
+
+CComHelper::~CComHelper()
+{
+}
+
+std::vector<std::wstring> CComHelper::getComPort()
+{
+	std::vector<std::wstring> comVector;
+
+	HKEY hKey;
+	TCHAR portName[256], commName[256];
+
+	// 打开串口注册表对应的键值  
+	if (ERROR_SUCCESS == ::RegOpenKeyEx(HKEY_LOCAL_MACHINE, L"Hardware\\DeviceMap\\SerialComm", NULL, KEY_READ, &hKey))
+	{
+		int i = 0;
+		int mm = 0;
+		DWORD  dwLong, dwSize;
+		while (TRUE)
+		{
+			dwLong = dwSize = sizeof(portName);
+
+			// 枚举串口
+			if (ERROR_NO_MORE_ITEMS == ::RegEnumValue(hKey, i, portName, &dwLong, NULL, NULL, (PUCHAR)commName, &dwSize))
+			{
+				break;
+			}
+
+			comVector.push_back(commName);
+			i++;
+		}
+		// 关闭注册表
+		RegCloseKey(hKey);
+	}
+	else
+	{
+		MessageBox(NULL, L"您的计算机的注册表上没有HKEY_LOCAL_MACHINE:Hardware\\DeviceMap\\SerialComm项", L"警告", MB_OK);
+	}
+
+	// 返回串口号
+	return comVector;
+}

+ 11 - 0
zhipuzi_pos_windows/tool/CComHelper.h

@@ -0,0 +1,11 @@
+#pragma once
+
+class CComHelper
+{
+public:
+	CComHelper();
+	~CComHelper();
+
+	std::vector<std::wstring> getComPort();
+};
+

+ 116 - 0
zhipuzi_pos_windows/tool/CExceptionDmp.cpp

@@ -0,0 +1,116 @@
+#include "../pch/pch.h"
+#include "CExceptionDmp.h"
+
+#include <Dbghelp.h>
+
+#include <alibabacloud/oss/OssClient.h>
+using namespace AlibabaCloud::OSS;
+
+static CExceptionDmp s_ExceptionDmp;
+
+LONG WINAPI MyUnhandledExceptionFilter(PEXCEPTION_POINTERS pExInfo)
+{
+	wstring wsPath = CSystem::GetProgramDir() + L"\\dump\\";
+	if (!CSystem::IsDirExist(wsPath))
+	{
+		bool flag = CreateDirectory(wsPath.c_str(), NULL);
+		if (flag == false)
+		{
+			LOG_INFO("新建 dump 目录失败!");
+		}
+
+		LOG_INFO("新建 dump 目录成功!");
+	}
+
+	SYSTEMTIME tm;
+	GetLocalTime(&tm);//获取时间
+	TCHAR file_name[128];
+
+	_stprintf_s(file_name, L"%s%d-%02d-%02d-%02d-%02d-%02d.dmp", wsPath.c_str(),
+		tm.wYear, tm.wMonth, tm.wDay, tm.wHour, tm.wMinute, tm.wSecond);//设置dmp文件名称
+
+	std::string version = CSystem::GetVersion();
+	std::string time_now = CLewaimaiTime::DatetimeToString(time(NULL));
+	std::string ossname = version + "/" + time_now + ".dmp";
+
+	HANDLE hFile = CreateFile(file_name, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS,
+		FILE_ATTRIBUTE_NORMAL, NULL);
+	if (hFile != INVALID_HANDLE_VALUE)
+	{
+		MINIDUMP_EXCEPTION_INFORMATION info;//构造dmp异常数据结构
+		info.ThreadId = GetCurrentThreadId();
+		info.ClientPointers = FALSE;
+		info.ExceptionPointers = pExInfo;
+		MiniDumpWriteDump(GetCurrentProcess(), GetCurrentProcessId(), hFile,
+			(MINIDUMP_TYPE)MiniDumpNormal, &info, NULL, NULL);//写dmp文件
+		CloseHandle(hFile);
+
+		CExceptionDmp::UploadDump(file_name, ossname);
+
+		const TCHAR *fmt =
+		{
+			L"程序遇到问题需要关闭,\n\n"
+			L"我们对此引起的不便表示抱歉,\n\n"
+			L"请重新运行软件。\n\n"
+		};
+		TCHAR msg[400];
+		_stprintf_s(msg, fmt, file_name);
+		MessageBox(NULL, msg, L"乐外卖接单软件异常报告", MB_ICONERROR | MB_SYSTEMMODAL);
+	}
+	else
+	{
+		TCHAR info[300] = { L"fail to create dump file:" };
+		_tcscat(info, file_name);
+		MessageBox(NULL, info, L"dump", MB_ICONERROR | MB_SYSTEMMODAL);
+	}
+	return EXCEPTION_EXECUTE_HANDLER;
+}
+
+CExceptionDmp::CExceptionDmp()
+{
+	SetUnhandledExceptionFilter(MyUnhandledExceptionFilter);
+}
+
+
+CExceptionDmp::~CExceptionDmp()
+{
+}
+
+bool CExceptionDmp::UploadDump(std::wstring filePath, std::string ossname)
+{
+	/* 初始化OSS账号信息 */
+	std::string AccessKeyId = "2HUnzc9XJV92PjvW";
+	std::string AccessKeySecret = "20mMc8wuzlfC0r323b6oJqxlBPEyjW";
+	std::string Endpoint = "oss-cn-hangzhou.aliyuncs.com";
+	std::string BucketName = "lewaimai-windows-pos";
+	/* yourObjectName表示上传文件到OSS时需要指定包含文件后缀在内的完整路径,例如abc/efg/123.jpg*/
+	std::string ObjectName = ossname;
+
+	/* 初始化网络等资源 */
+	InitializeSdk();
+
+	ClientConfiguration conf;
+	OssClient client(Endpoint, AccessKeyId, AccessKeySecret, conf);
+	std::shared_ptr<std::iostream> content = std::make_shared<std::fstream>(CLewaimaiString::UnicodeToANSI(filePath), std::ios::in | std::ios::binary);
+	PutObjectRequest request(BucketName, ObjectName, content);
+
+	/*(可选)请参见如下示例设置存储类型及访问权限ACL*/
+	//request.MetaData().addHeader("x-oss-object-acl", "private");
+	//request.MetaData().addHeader("x-oss-storage-class", "Standard");
+
+	auto outcome = client.PutObject(request);
+
+	if (!outcome.isSuccess()) {
+		/* 异常处理 */
+		std::cout << "PutObject fail" <<
+			",code:" << outcome.error().Code() <<
+			",message:" << outcome.error().Message() <<
+			",requestId:" << outcome.error().RequestId() << std::endl;
+		ShutdownSdk();
+		return false;
+	}
+
+	/* 释放网络等资源 */
+	ShutdownSdk();
+	return true;
+}

+ 11 - 0
zhipuzi_pos_windows/tool/CExceptionDmp.h

@@ -0,0 +1,11 @@
+#pragma once
+
+class CExceptionDmp
+{
+public:
+	CExceptionDmp();
+	~CExceptionDmp();
+
+	bool static UploadDump(std::wstring filePath, std::string ossname);
+};
+

Разница между файлами не показана из-за своего большого размера
+ 883 - 199
zhipuzi_pos_windows/tool/CPosPrinter.cpp


+ 63 - 44
zhipuzi_pos_windows/tool/CPosPrinter.h

@@ -4,21 +4,20 @@
 #include "../order/CWaimaiOrder.h"
 
 //SetupDiGetInterfaceDeviceDetail所需要的输出长度,定义足够大
-#define INTERFACE_DETAIL_SIZE	1024
+#define INTERFACE_DETAIL_SIZE 1024
 
 //设备数量上限,假设16台上限
 #define MAX_DEVICE 16
 
-//USB类的GUID
-//const GUID USB_GUID = {0xa5dcbf10, 0x6530, 0x11d2, {0x90, 0x1f, 0x00, 0xc0, 0x4f, 0xb9, 0x51, 0xed}};
-const GUID USB_GUID = { 0x28d78fad, 0x5a12, 0x11d1, {0xae, 0x5b, 0x00, 0x00, 0xf8, 0x03, 0xa8, 0xc2 } };
+//USB类的GUID,通过这个去找USB打印机
+const GUID USB_GUID = {0x28d78fad, 0x5a12, 0x11d1, {0xae, 0x5b, 0x00, 0x00, 0xf8, 0x03, 0xa8, 0xc2 }};
 
 //存储打印端口句柄的结构
 class PrinterHandle
 {
 public:
-    HANDLE hPort;
-    int type; //句柄类型 1:usb 2:并口 3:串口
+	HANDLE hPort;
+	int type; //句柄类型 1:usb 2:并口 3:串口
 };
 
 class CPosPrinter
@@ -28,61 +27,81 @@ public:
     ~CPosPrinter();
 
     void PrintWaimaiOrderShouyin(CWaimaiOrder& order);
-    void PrintWaimaiOrderChufang(CWaimaiOrder& order);
+	void PrintWaimaiOrderBiaoqian(CWaimaiOrder& order);
+	void PrintWaimaiOrderChufang(CWaimaiOrder& order);
 
-    void InitUsb();
-    std::vector<std::wstring> getUsbDevices();
+	//usb打印机的类型 1:收银小票打印机 2:标签打印机
+	void InitUsb(int usbType = 1);
+	std::vector<std::wstring> getUsbDevices();
 
 private:
-    void InitBingkou();
-    void InitCom();
+	bool InitBingkou();
+	void InitCom();
 
-    void InitShouyin();
+	void InitShouyin();
 
-    void InitOneUsb(wstring usb_path);
+	//打开某一个指定的usb端口
+	bool InitOneUsb(wstring usb_path);
 
-    int GetDevicePath(LPGUID lpGuid);
-    int GetPrinterType(wstring vid, wstring pid);
+	//usb打印机的类型 1:收银小票打印机 2:标签打印机
+	int GetDevicePath(LPGUID lpGuid, int usbType);
 
-    int WriteData(string meg);
-    int WriteBuf(const char* buf, int len);
+	//判断usb打印机是小票打印机还是标签打印机
+	int GetPrinterType(wstring vid, wstring pid);
 
-    bool PortTest(HANDLE hPort);
+	int WriteData(string meg);
+	int WriteBuf(const unsigned char* buf, int len);
 
-    int POS_Reset(void);
-    int POS_FeedLine(void);
-    int POS_Feed(void);
-    int POS_SetMotionUnit(int x, int y);
+	//端口连通性测试
+	bool PortTest(HANDLE hPort);
 
-    //设置横向跳格位置
-    int POS_SET_MOVE_X();
-    int POS_MOVE_X();
-    int POS_SET_ABS_X(int x, int y);
-    int POS_SET_PRINT_AREA(int x, int y);
+	//小票打印机和厨房打印的处理方法
+	int POS_Reset(void);
+	int POS_FeedLine(void);
+	int POS_Feed(void);
+	int POS_SetMotionUnit(int x, int y);
 
-    int POS_TextOut(string abc, bool is_double_width = false, bool is_double_height = false, int align_type = 0);
+	int POS_SET_MOVE_X();
+	int POS_MOVE_X();
+	int POS_SET_ABS_X(int x, int y);
+	int POS_SET_PRINT_AREA(int x, int y);
 
-    int POS_CutPaper();
-    int POS_OutQRCode();
+	int POS_TextOut(string abc, bool is_double_width = false, bool is_double_height = false, int align_type = 0);
+	int POS_CutPaper();
+	void POS_OutQRCode(std::string dataString);
+	void POS_OutBmp(std::wstring ImagePath);
 
-    //字符空格计算的辅助函数
-    void CalWord(string s, int& nHanzi, int& nZimu);
+	//标签打印机的处理方法
+	void BIAOQIAN_Reset(int nWidth, int nHeight, int nDirection);
+	void BIAOQIAN_FORMFEED();
+	void BIAOQIAN_TEXTOUT(std::string content, int x, int y, int x_multiplication, int y_multiplication);
+	std::string BIAOQIAN_TEXTGet(std::string content, int x, int y, int x_multiplication, int y_multiplication);
+	void BIAOQIAN_PRINT();
+	void BIAOQIAN_CLS();
 
-    //对名字进行换行处理
-    std::vector<std::string> HandleFoodname(std::string oldname, int guige = 1);
-    std::string HandleFoodItemPrice(std::string oldprice, int guige = 1);
-    std::string HandleFoodQuantity(std::string oldquantity, int guige = 1);
-    std::string HandleFoodTotalPrice(std::string oldprice, int guige = 1);
+	//字符空格计算的辅助函数
+	void CalWord(string s,  int& nHanzi, int& nZimu);
+
+	//对小票打印和厨房打印的名字进行换行处理
+	std::vector<std::string> HandleFoodname(std::string oldname, int guige = 1);
+	std::string HandleFoodItemPrice(std::string oldprice, int guige = 1);
+	std::string HandleFoodQuantity(std::string oldquantity, int guige = 1);
+	std::string HandleFoodTotalPrice(std::string oldprice, int guige = 1);
+
+	//对标签打印的名字进行换行处理
+	std::vector<std::string> HandleBiaoqianFoodname(std::string oldname, int nBiaoqianWdith);
 
 private:
-    std::vector<PrinterHandle> m_hPorts;
+	//收银小票打印的句柄组合
+	std::vector<PrinterHandle> m_hPorts;
 
-    boost::asio::io_service m_io;
-    boost::asio::ip::tcp::socket m_socket;
+	//用于厨房打印机和网口类型的收银小票打印
+	boost::asio::io_service m_io;
+	boost::asio::ip::tcp::socket m_socket;
 
-    //这个是当前的输出模式,是收银模式还是厨房打印模式
-    int m_type;
+	//这个是当前的输出模式,是CreateFile模式,还是socket模式
+	int m_type;
 
-    //usb打印机的描述
-    std::vector<std::wstring> m_usb_devices;
+	//usb打印机的描述
+	std::vector<std::wstring> m_usb_devices;
 };

+ 246 - 220
zhipuzi_pos_windows/tool/CSetting.cpp

@@ -23,70 +23,70 @@ CSetting::~CSetting()
 
 void CSetting::SetParam(std::string name, std::string value, bool isSave)
 {
-    m_mutex.lock();
+	m_mutex.lock();
 
-    m_paramsMap[name] = value;
+	m_paramsMap[name] = value;
 
-    m_mutex.unlock();
+	m_mutex.unlock();
 
-    if(isSave)
-    {
-        SaveParams();
-    }
+	if (isSave)
+	{
+		SaveParams();
+	}
 }
 
 std::string CSetting::GetParam(std::string name)
 {
-    m_mutex.lock();
+	m_mutex.lock();
 
-    std::string value = m_paramsMap[name];
+	std::string value = m_paramsMap[name];
 
-    m_mutex.unlock();
+	m_mutex.unlock();
 
-    return value;
+	return value;
 }
 
 void CSetting::AddChufangPrinter(std::string date, std::string name, std::string ip, std::string guige, std::string fendan, std::string fenlei, std::string fenlei_ids, bool isSave)
 {
-    ChufangPrinter newPrinter;
-
-    newPrinter.date = date;
-    newPrinter.name = name;
-    newPrinter.ip = ip;
-    newPrinter.guige = guige;
-    newPrinter.fendan = fendan;
-    newPrinter.fenlei = fenlei;
-    newPrinter.fenlei_ids = fenlei_ids;
-
-    m_chufang_printers.push_back(newPrinter);
-
-    if(isSave)
-    {
-        SaveChufangPrinter();
-    }
+	ChufangPrinter newPrinter;
+
+	newPrinter.date = date;
+	newPrinter.name = name;
+	newPrinter.ip = ip;
+	newPrinter.guige = guige;
+	newPrinter.fendan = fendan;
+	newPrinter.fenlei = fenlei;
+	newPrinter.fenlei_ids = fenlei_ids;
+
+	m_chufang_printers.push_back(newPrinter);
+
+	if (isSave)
+	{
+		SaveChufangPrinter();
+	}
 }
 
 void CSetting::UpdateChufangPrinter(std::string date, std::string name, std::string ip, std::string guige, std::string fendan, std::string fenlei, std::string fenlei_ids, bool isSave)
 {
-    for(std::vector<ChufangPrinter>::iterator it = m_chufang_printers.begin(); it != m_chufang_printers.end(); it++)
-    {
-        if((*it).date == date)
-        {
-            (*it).name = name;
-            (*it).ip = ip;
-            (*it).guige = guige;
-            (*it).fendan = fendan;
-            (*it).fenlei = fenlei;
-            (*it).fenlei_ids = fenlei_ids;
-
-            break;
-        }
-    }
-
-    if(isSave)
-    {
-        SaveChufangPrinter();
-    }
+	for (std::vector<ChufangPrinter>::iterator it = m_chufang_printers.begin(); it != m_chufang_printers.end(); it++)
+	{
+		if ((*it).date == date)
+		{
+			(*it).name = name;
+			(*it).ip = ip;
+			(*it).guige = guige;
+			(*it).fendan = fendan;
+			(*it).fenlei = fenlei;
+			(*it).fenlei_ids = fenlei_ids;
+
+			break;
+		}
+	}
+
+	if (isSave)
+	{
+		SaveChufangPrinter();
+	}
 }
 
 /*
@@ -94,78 +94,78 @@ void CSetting::UpdateChufangPrinter(std::string date, std::string name, std::str
  **/
 void CSetting::DelChufangPrinter(std::string date)
 {
-    for(std::vector<ChufangPrinter>::iterator it = m_chufang_printers.begin(); it != m_chufang_printers.end(); it++)
-    {
-        if((*it).date == date)
-        {
-            m_chufang_printers.erase(it);
+	for (std::vector<ChufangPrinter>::iterator it = m_chufang_printers.begin(); it != m_chufang_printers.end(); it++)
+	{
+		if ((*it).date == date)
+		{
+			m_chufang_printers.erase(it);
 
-            break;
-        }
-    }
+			break;
+		}
+	}
 
-    SaveChufangPrinter();
+	SaveChufangPrinter();
 }
 
 ChufangPrinter CSetting::GetChufangPrinter(std::string date)
 {
-    for(std::vector<ChufangPrinter>::iterator it = m_chufang_printers.begin(); it != m_chufang_printers.end(); it++)
-    {
-        if((*it).date == date)
-        {
-            return (*it);
-        }
-    }
-
-    return ChufangPrinter();
+	for (std::vector<ChufangPrinter>::iterator it = m_chufang_printers.begin(); it != m_chufang_printers.end(); it++)
+	{
+		if ((*it).date == date)
+		{
+			return (*it);
+		}
+	}
+
+	return ChufangPrinter();
 }
 
 void CSetting::Init()
 {
-    //先读取数据库的数据
-    CSqlite3 sqllite;
-    sqllite.InitConfig();
-
-    //再对数据进行初始化,如果没有记录的就加上默认设置
-    m_mutex.lock();
-
-    //外卖设置参数
-    std::string setting_is_new_waimai_voice = "setting_is_new_waimai_voice";
-    if(m_paramsMap.find(setting_is_new_waimai_voice) == m_paramsMap.end())
-    {
-        m_paramsMap[setting_is_new_waimai_voice] = "1";
-    }
-
-    std::string setting_is_new_waimai_autoconfirm = "setting_is_new_waimai_autoconfirm";
-    if(m_paramsMap.find(setting_is_new_waimai_autoconfirm) == m_paramsMap.end())
-    {
-        m_paramsMap[setting_is_new_waimai_autoconfirm] = "1";
-    }
-
-    std::string setting_is_new_waimai_dialog = "setting_is_new_waimai_dialog";
-    if(m_paramsMap.find(setting_is_new_waimai_dialog) == m_paramsMap.end())
-    {
-        m_paramsMap[setting_is_new_waimai_dialog] = "1";
-    }
-
-    //新订单打印设置参数
-    std::string setting_is_new_waimai_printer = "setting_is_new_waimai_printer";
-    if(m_paramsMap.find(setting_is_new_waimai_printer) == m_paramsMap.end())
-    {
-        m_paramsMap[setting_is_new_waimai_printer] = "1";
-    }
-
-    std::string setting_printer_guige = "setting_printer_guige";
-    if(m_paramsMap.find(setting_printer_guige) == m_paramsMap.end())
-    {
-        m_paramsMap[setting_printer_guige] = "58";
-    }
-
-    std::string setting_printer_lianshu = "setting_printer_lianshu";
-    if(m_paramsMap.find(setting_printer_lianshu) == m_paramsMap.end())
-    {
-        m_paramsMap[setting_printer_lianshu] = "1";
-    }
+	//先读取数据库的数据
+	CSqlite3 sqllite;
+	sqllite.InitConfig();
+
+	//再对数据进行初始化,如果没有记录的就加上默认设置
+	m_mutex.lock();
+
+	//外卖设置参数
+	std::string setting_is_new_waimai_voice = "setting_is_new_waimai_voice";
+	if (m_paramsMap.find(setting_is_new_waimai_voice) == m_paramsMap.end())
+	{
+		m_paramsMap[setting_is_new_waimai_voice] = "1";
+	}
+
+	std::string setting_is_new_waimai_autoconfirm = "setting_is_new_waimai_autoconfirm";
+	if (m_paramsMap.find(setting_is_new_waimai_autoconfirm) == m_paramsMap.end())
+	{
+		m_paramsMap[setting_is_new_waimai_autoconfirm] = "1";
+	}
+
+	std::string setting_is_new_waimai_dialog = "setting_is_new_waimai_dialog";
+	if (m_paramsMap.find(setting_is_new_waimai_dialog) == m_paramsMap.end())
+	{
+		m_paramsMap[setting_is_new_waimai_dialog] = "1";
+	}
+
+	//新订单打印设置参数
+	std::string setting_is_new_waimai_printer = "setting_is_new_waimai_printer";
+	if (m_paramsMap.find(setting_is_new_waimai_printer) == m_paramsMap.end())
+	{
+		m_paramsMap[setting_is_new_waimai_printer] = "1";
+	}
+
+	std::string setting_printer_guige = "setting_printer_guige";
+	if (m_paramsMap.find(setting_printer_guige) == m_paramsMap.end())
+	{
+		m_paramsMap[setting_printer_guige] = "58";
+	}
+
+	std::string setting_printer_lianshu = "setting_printer_lianshu";
+	if (m_paramsMap.find(setting_printer_lianshu) == m_paramsMap.end())
+	{
+		m_paramsMap[setting_printer_lianshu] = "1";
+	}
 
 	std::string setting_printer_leixing = "setting_printer_leixing";
 	if (m_paramsMap.find(setting_printer_leixing) == m_paramsMap.end())
@@ -185,128 +185,154 @@ void CSetting::Init()
 		m_paramsMap[setting_printer_wangkou_ip] = "";
 	}
 
-    std::string setting_printer_quhuo_big = "setting_printer_quhuo_big";
-    if(m_paramsMap.find(setting_printer_quhuo_big) == m_paramsMap.end())
-    {
-        m_paramsMap[setting_printer_quhuo_big] = "0";
-    }
-
-    std::string setting_printer_dingdanhao_big = "setting_printer_dingdanhao_big";
-    if(m_paramsMap.find(setting_printer_dingdanhao_big) == m_paramsMap.end())
-    {
-        m_paramsMap[setting_printer_dingdanhao_big] = "0";
-    }
-
-    std::string setting_printer_xiadanshijian_big = "setting_printer_xiadanshijian_big";
-    if(m_paramsMap.find(setting_printer_xiadanshijian_big) == m_paramsMap.end())
-    {
-        m_paramsMap[setting_printer_xiadanshijian_big] = "0";
-    }
-
-    std::string setting_printer_peisongshijian_big = "setting_printer_peisongshijian_big";
-    if(m_paramsMap.find(setting_printer_peisongshijian_big) == m_paramsMap.end())
-    {
-        m_paramsMap[setting_printer_peisongshijian_big] = "0";
-    }
-
-    std::string setting_printer_name_big = "setting_printer_name_big";
-    if(m_paramsMap.find(setting_printer_name_big) == m_paramsMap.end())
-    {
-        m_paramsMap[setting_printer_name_big] = "0";
-    }
-
-    std::string setting_printer_phone_big = "setting_printer_phone_big";
-    if(m_paramsMap.find(setting_printer_phone_big) == m_paramsMap.end())
-    {
-        m_paramsMap[setting_printer_phone_big] = "0";
-    }
-
-    std::string setting_printer_address_big = "setting_printer_address_big";
-    if(m_paramsMap.find(setting_printer_address_big) == m_paramsMap.end())
-    {
-        m_paramsMap[setting_printer_address_big] = "0";
-    }
-
-    std::string setting_printer_shangpin_big = "setting_printer_shangpin_big";
-    if(m_paramsMap.find(setting_printer_shangpin_big) == m_paramsMap.end())
-    {
-        m_paramsMap[setting_printer_shangpin_big] = "0";
-    }
-
-    std::string setting_printer_memo_big = "setting_printer_memo_big";
-    if(m_paramsMap.find(setting_printer_memo_big) == m_paramsMap.end())
-    {
-        m_paramsMap[setting_printer_memo_big] = "0";
-    }
-
-    std::string setting_printer_price_big = "setting_printer_price_big";
-    if(m_paramsMap.find(setting_printer_price_big) == m_paramsMap.end())
-    {
-        m_paramsMap[setting_printer_price_big] = "0";
-    }
-
-    std::string setting_printer_pay_big = "setting_printer_pay_big";
-    if(m_paramsMap.find(setting_printer_pay_big) == m_paramsMap.end())
-    {
-        m_paramsMap[setting_printer_pay_big] = "0";
-    }
-
-    //厨房打印的默认参数
-    std::string setting_is_new_waimai_chufang_printer = "setting_is_new_waimai_chufang_printer";
-    if(m_paramsMap.find(setting_is_new_waimai_chufang_printer) == m_paramsMap.end())
-    {
-        m_paramsMap[setting_is_new_waimai_chufang_printer] = "1";
-    }
-
-    //系统设置的参数
-    std::string setting_is_auto_start = "setting_is_auto_start";
-    if(CSystem::IsAutoStart() == true)
-    {
-        m_paramsMap[setting_is_auto_start] = "1";
-    }
-    else
-    {
-        m_paramsMap[setting_is_auto_start] = "0";
-    }
-
-    std::string setting_is_auto_login = "setting_is_auto_login";
-    if(m_paramsMap.find(setting_is_auto_login) == m_paramsMap.end())
-    {
-        m_paramsMap[setting_is_auto_login] = "0";
-    }
-
-    std::string setting_is_remember_password = "setting_is_remember_password";
-    if(m_paramsMap.find(setting_is_remember_password) == m_paramsMap.end())
-    {
-        m_paramsMap[setting_is_remember_password] = "1";
-    }
-
-    std::string setting_is_close_min = "setting_is_close_min";
-    if(m_paramsMap.find(setting_is_close_min) == m_paramsMap.end())
-    {
-        m_paramsMap[setting_is_close_min] = "1";
-    }
-
-    m_mutex.unlock();
-
-    //设置好默认参数之后,将默认参数写回到数据库
-    SaveParams();
+	std::string setting_printer_quhuo_big = "setting_printer_quhuo_big";
+	if (m_paramsMap.find(setting_printer_quhuo_big) == m_paramsMap.end())
+	{
+		m_paramsMap[setting_printer_quhuo_big] = "0";
+	}
+
+	std::string setting_printer_dingdanhao_big = "setting_printer_dingdanhao_big";
+	if (m_paramsMap.find(setting_printer_dingdanhao_big) == m_paramsMap.end())
+	{
+		m_paramsMap[setting_printer_dingdanhao_big] = "0";
+	}
+
+	std::string setting_printer_xiadanshijian_big = "setting_printer_xiadanshijian_big";
+	if (m_paramsMap.find(setting_printer_xiadanshijian_big) == m_paramsMap.end())
+	{
+		m_paramsMap[setting_printer_xiadanshijian_big] = "0";
+	}
+
+	std::string setting_printer_peisongshijian_big = "setting_printer_peisongshijian_big";
+	if (m_paramsMap.find(setting_printer_peisongshijian_big) == m_paramsMap.end())
+	{
+		m_paramsMap[setting_printer_peisongshijian_big] = "0";
+	}
+
+	std::string setting_printer_name_big = "setting_printer_name_big";
+	if (m_paramsMap.find(setting_printer_name_big) == m_paramsMap.end())
+	{
+		m_paramsMap[setting_printer_name_big] = "0";
+	}
+
+	std::string setting_printer_phone_big = "setting_printer_phone_big";
+	if (m_paramsMap.find(setting_printer_phone_big) == m_paramsMap.end())
+	{
+		m_paramsMap[setting_printer_phone_big] = "0";
+	}
+
+	std::string setting_printer_address_big = "setting_printer_address_big";
+	if (m_paramsMap.find(setting_printer_address_big) == m_paramsMap.end())
+	{
+		m_paramsMap[setting_printer_address_big] = "0";
+	}
+
+	std::string setting_printer_shangpin_big = "setting_printer_shangpin_big";
+	if (m_paramsMap.find(setting_printer_shangpin_big) == m_paramsMap.end())
+	{
+		m_paramsMap[setting_printer_shangpin_big] = "0";
+	}
+
+	std::string setting_printer_memo_big = "setting_printer_memo_big";
+	if (m_paramsMap.find(setting_printer_memo_big) == m_paramsMap.end())
+	{
+		m_paramsMap[setting_printer_memo_big] = "0";
+	}
+
+	std::string setting_printer_price_big = "setting_printer_price_big";
+	if (m_paramsMap.find(setting_printer_price_big) == m_paramsMap.end())
+	{
+		m_paramsMap[setting_printer_price_big] = "0";
+	}
+
+	std::string setting_printer_pay_big = "setting_printer_pay_big";
+	if (m_paramsMap.find(setting_printer_pay_big) == m_paramsMap.end())
+	{
+		m_paramsMap[setting_printer_pay_big] = "0";
+	}
+
+	//标签打印参数设置
+	std::string setting_is_new_waimai_biaoqian_printer = "setting_is_new_waimai_biaoqian_printer";
+	if (m_paramsMap.find(setting_is_new_waimai_biaoqian_printer) == m_paramsMap.end())
+	{
+		m_paramsMap[setting_is_new_waimai_biaoqian_printer] = "0";
+	}
+
+	std::string setting_biaoqian_printer_usb = "setting_biaoqian_printer_usb";
+	if (m_paramsMap.find(setting_biaoqian_printer_usb) == m_paramsMap.end())
+	{
+		m_paramsMap[setting_biaoqian_printer_usb] = "";
+	}
+
+	std::string setting_biaoqian_printer_guige = "setting_biaoqian_printer_guige";
+	if (m_paramsMap.find(setting_biaoqian_printer_guige) == m_paramsMap.end())
+	{
+		m_paramsMap[setting_biaoqian_printer_guige] = "40*30mm";
+	}
+
+	std::string setting_biaoqian_printer_fangxiang = "setting_biaoqian_printer_fangxiang";
+	if (m_paramsMap.find(setting_biaoqian_printer_fangxiang) == m_paramsMap.end())
+	{
+		//1表示正方向,0表示反方向
+		m_paramsMap[setting_biaoqian_printer_fangxiang] = "1";
+	}
+
+	//厨房打印的默认参数
+	std::string setting_is_new_waimai_chufang_printer = "setting_is_new_waimai_chufang_printer";
+	if (m_paramsMap.find(setting_is_new_waimai_chufang_printer) == m_paramsMap.end())
+	{
+		m_paramsMap[setting_is_new_waimai_chufang_printer] = "1";
+	}
+
+	//系统设置的参数
+	std::string setting_is_auto_start = "setting_is_auto_start";
+	if (CSystem::IsAutoStart() == true)
+	{
+		m_paramsMap[setting_is_auto_start] = "1";
+	}
+	else
+	{
+		m_paramsMap[setting_is_auto_start] = "0";
+	}
+
+	std::string setting_is_auto_login = "setting_is_auto_login";
+	if (m_paramsMap.find(setting_is_auto_login) == m_paramsMap.end())
+	{
+		m_paramsMap[setting_is_auto_login] = "0";
+	}
+
+	std::string setting_is_remember_password = "setting_is_remember_password";
+	if (m_paramsMap.find(setting_is_remember_password) == m_paramsMap.end())
+	{
+		m_paramsMap[setting_is_remember_password] = "1";
+	}
+
+	std::string setting_is_close_min = "setting_is_close_min";
+	if (m_paramsMap.find(setting_is_close_min) == m_paramsMap.end())
+	{
+		m_paramsMap[setting_is_close_min] = "1";
+	}
+
+	m_mutex.unlock();
+
+	//设置好默认参数之后,将默认参数写回到数据库
+	SaveParams();
 }
 
 void CSetting::SaveParams()
 {
-    CSqlite3 sqllite;
-    sqllite.SaveParams(m_paramsMap);
+	CSqlite3 sqllite;
+	sqllite.SaveParams(m_paramsMap);
 }
 
 void CSetting::SaveChufangPrinter()
 {
-    CSqlite3 sqllite;
-    sqllite.SaveChufangPrinter(m_chufang_printers);
+	CSqlite3 sqllite;
+	sqllite.SaveChufangPrinter(m_chufang_printers);
 }
 
 void CSetting::SaveUsers()
 {
-    CSqlite3 sqllite;
-    sqllite.SaveUsers(m_users);
+	CSqlite3 sqllite;
+	sqllite.SaveUsers(m_users);
 }

+ 135 - 129
zhipuzi_pos_windows/tool/CSetting.h

@@ -5,151 +5,157 @@
 class ChufangPrinter
 {
 public:
-    std::string date;
-    std::string name;
-    std::string ip;
-    std::string guige;
-    std::string fendan;
-    std::string fenlei;
-    std::string fenlei_ids;
+	std::string date;
+	std::string name;
+	std::string ip;
+	std::string guige;
+	std::string fendan;
+	std::string fenlei;
+	std::string fenlei_ids;
 };
 
 class FoodType
 {
 public:
-    std::string name;
-    std::string type_id;
+	std::string name;
+	std::string type_id;
 };
 
 class CSetting
 {
 public:
-    CSetting();
-    ~CSetting();
-
-    //修改内存中的参数设置
-    static void SetParam(std::string name, std::string value, bool isSave = true);
-    static std::string GetParam(std::string name);
-
-    //厨房打印机相关的参数配置
-    static void AddChufangPrinter(std::string date, std::string name, std::string ip, std::string guige, std::string fendan, std::string fenlei, std::string fenlei_ids, bool isSave = true);
-    static void UpdateChufangPrinter(std::string date, std::string name, std::string ip, std::string guige, std::string fendan, std::string fenlei, std::string fenlei_ids, bool isSave = true);
-    static void DelChufangPrinter(std::string date);
-
-    static ChufangPrinter GetChufangPrinter(std::string date);
-
-    static void SetUser(std::string name, std::string password, bool isSave = true)
-    {
-        m_users[name] = password;
-
-        if(isSave)
-        {
-            SaveUsers();
-        }
-    }
-
-    static std::string GetUser(std::string name)
-    {
-        if(m_users.find(name) == m_users.end())
-        {
-            return "";
-        }
-
-        return m_users[name];
-    }
-
-    static std::map<string, string> getUsers()
-    {
-        return m_users;
-    }
-
-    //刚打开程序的时候,根据数据库初始化内存,并且添加默认参数
-    static void Init();
-
-    static std::string getValue(std::string name)
-    {
-        return m_paramsMap[name];
-    }
-
-    static ChufangPrinter getLastChufangPrinter()
-    {
-        return m_chufang_printers.back();
-    }
-
-    static std::vector<ChufangPrinter>& getChufangPrints()
-    {
-        return m_chufang_printers;
-    }
-
-    static void AddFoodtype(std::string name, std::string type_id)
-    {
-        FoodType newFoodType;
-        newFoodType.name = name;
-        newFoodType.type_id = type_id;
-
-        m_foodtypes.push_back(newFoodType);
-
-        m_foodtype_id_name[type_id] = name;
-    }
-
-    static std::vector<FoodType>& GetFoodtype()
-    {
-        return m_foodtypes;
-    }
-
-    static std::string getFoodtypeName(std::string type_id)
-    {
-        if(m_foodtype_id_name.find(type_id) != m_foodtype_id_name.end())
-        {
-            return m_foodtype_id_name[type_id];
-        }
-
-        //返回这个表示没找到这个分类
-        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;
-    }
-
-    /*
-     *把内存中的参数,写到数据库中
-     **/
-    static void SaveParams();
-
-    /*
-     *把内存中的厨房打印机信息,存到数据库
-     **/
-    static void SaveChufangPrinter();
-
-    static void SaveUsers();
+	CSetting();
+	~CSetting();
+
+	//修改内存中的参数设置
+	static void SetParam(std::string name, std::string value, bool isSave = true);
+	static std::string GetParam(std::string name);
+
+	//厨房打印机相关的参数配置
+	static void AddChufangPrinter(std::string date, std::string name, std::string ip, std::string guige, std::string fendan, std::string fenlei, std::string fenlei_ids, bool isSave = true);
+	static void UpdateChufangPrinter(std::string date, std::string name, std::string ip, std::string guige, std::string fendan, std::string fenlei, std::string fenlei_ids, bool isSave = true);
+	static void DelChufangPrinter(std::string date);
+
+	static ChufangPrinter GetChufangPrinter(std::string date);
+
+	static void SetUser(std::string name, std::string password, bool isSave = true)
+	{
+		m_users[name] = password;
+
+		if (isSave)
+		{
+			SaveUsers();
+		}
+	}
+
+	static std::string GetUser(std::string name)
+	{
+		if (m_users.find(name) == m_users.end())
+		{
+			return "";
+		}
+
+		return m_users[name];
+	}
+
+	static std::map<string, string> getUsers()
+	{
+		return m_users;
+	}
+
+	//刚打开程序的时候,根据数据库初始化内存,并且添加默认参数
+	static void Init();
+
+	static std::string getValue(std::string name)
+	{
+		return m_paramsMap[name];
+	}
+
+	static ChufangPrinter getLastChufangPrinter()
+	{
+		return m_chufang_printers.back();
+	}
+
+	static std::vector<ChufangPrinter>& getChufangPrints()
+	{
+		return m_chufang_printers;
+	}
+
+	static void ClearFoodtype()
+	{
+		m_foodtypes.clear();
+		m_foodtype_id_name.clear();
+	}
+
+	static void AddFoodtype(std::string name, std::string type_id)
+	{
+		FoodType newFoodType;
+		newFoodType.name = name;
+		newFoodType.type_id = type_id;
+
+		m_foodtypes.push_back(newFoodType);
+
+		m_foodtype_id_name[type_id] = name;
+	}
+
+	static std::vector<FoodType>& GetFoodtype()
+	{
+		return m_foodtypes;
+	}
+
+	static std::string getFoodtypeName(std::string type_id)
+	{
+		if (m_foodtype_id_name.find(type_id) != m_foodtype_id_name.end())
+		{
+			return m_foodtype_id_name[type_id];
+		}
+
+		//返回这个表示没找到这个分类
+		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;
+	}
+
+	/*
+	 *把内存中的参数,写到数据库中
+	 **/
+	static void SaveParams();
+
+	/*
+	 *把内存中的厨房打印机信息,存到数据库
+	 **/
+	static void SaveChufangPrinter();
+
+	static void SaveUsers();
 
 private:
-    static std::map<std::string, std::string> m_paramsMap;
-    static std::vector<ChufangPrinter> m_chufang_printers;
+	static std::map<std::string, std::string> m_paramsMap;
+	static std::vector<ChufangPrinter> m_chufang_printers;
 
-    static std::mutex m_mutex;
+	static std::mutex m_mutex;
 
-    static std::vector<FoodType> m_foodtypes;
+	static std::vector<FoodType> m_foodtypes;
 
-    //从商品分类的id到name的映射
-    static std::map<std::string, std::string> m_foodtype_id_name;
+	//从商品分类的id到name的映射
+	static std::map<std::string, std::string> m_foodtype_id_name;
 
-    static std::map<string, string> m_users;
+	static std::map<string, string> m_users;
 
-    static std::string m_username;
-    static std::string m_password;
+	static std::string m_username;
+	static std::string m_password;
 };
 

+ 266 - 135
zhipuzi_pos_windows/tool/CSqlite3.cpp

@@ -6,17 +6,17 @@
 CSqlite3::CSqlite3()
 {
     wstring folderPath = CSystem::GetProgramDir() + L"\\db";
-    if(!CSystem::IsDirExist(folderPath))
-    {
-        LOG_INFO("folderPath:" << folderPath.c_str() << ",没有找到对应的目录,即将创建");
-        bool flag = CreateDirectory(folderPath.c_str(), NULL);
-        if(flag == false)
-        {
-            LOG_INFO("新建 db 目录失败!");
-        }
-
-        LOG_INFO("新建 db 目录成功!");
-    }
+	if (!CSystem::IsDirExist(folderPath))
+	{
+		LOG_INFO("folderPath:" << folderPath.c_str()<<",没有找到对应的目录,即将创建");
+		bool flag = CreateDirectory(folderPath.c_str(), NULL);
+		if (flag == false)
+		{
+			LOG_INFO("新建 db 目录失败!");
+		}
+
+		LOG_INFO("新建 db 目录成功!");
+	}
 
     //如果没有这个文件,这里会创建这个文件
     wstring path = CSystem::GetProgramDir() + L"\\db\\pos.db";
@@ -32,7 +32,7 @@ CSqlite3::CSqlite3()
 
     else
     {
-        LOG_INFO("Opened database successfully");
+        //LOG_INFO("Opened database successfully");
     }
 }
 
@@ -48,7 +48,7 @@ bool CSqlite3::InitConfig()
 {
     //检查有没有pos_config这个表,如果没有就创建
     std::string sql = "SELECT COUNT(*) FROM sqlite_master where type = 'table' and name = 'pos_config';";
-    sqlite3_stmt* stmt = NULL;
+    sqlite3_stmt * stmt = NULL;
 
     if(sqlite3_prepare_v2(m_db, sql.c_str(), -1, &stmt, NULL) == SQLITE_OK)
     {
@@ -78,7 +78,7 @@ bool CSqlite3::InitConfig()
                     }
 
                     //走到这里就是表创建成功了
-                    LOG_INFO("create table success");
+                    //LOG_INFO("create table success");
                     sqlite3_finalize(stmt);
                 }
 
@@ -99,7 +99,7 @@ bool CSqlite3::InitConfig()
             }
 
             std::string sql = "SELECT * FROM pos_config;";
-            sqlite3_stmt* stmt = NULL;
+            sqlite3_stmt * stmt = NULL;
 
             if(sqlite3_prepare_v2(m_db, sql.c_str(), -1, &stmt, NULL) == SQLITE_OK)
             {
@@ -140,91 +140,222 @@ bool CSqlite3::InitConfig()
     sql = "SELECT COUNT(*) FROM sqlite_master where type = 'table' and name = 'pos_chufang_printer';";
 
     //读取厨房打印机的参数
-    if(sqlite3_prepare_v2(m_db, sql.c_str(), -1, &stmt, NULL) == SQLITE_OK)
-    {
-        if(sqlite3_step(stmt) == SQLITE_ROW)
-        {
-            int count = sqlite3_column_int(stmt, 0);
-
-            if(count == 0)
-            {
-                //说明没找到这个表,那么这个时候新建这个表,先释放前面的stmt
-                sqlite3_finalize(stmt);
-                stmt = NULL;
-
-                sql = "CREATE TABLE pos_chufang_printer("  \
-                      "id         INTEGER          PRIMARY KEY AUTOINCREMENT,"\
-                      "date       CHAR(100)        NOT NULL," \
-                      "name       CHAR(100)        NOT NULL," \
-                      "ip         CHAR(100)        NOT NULL," \
-                      "guige      CHAR(100)        NOT NULL," \
-                      "fendan     CHAR(100)        NOT NULL," \
-                      "fenlei     CHAR(100)        NOT NULL," \
-                      "fenlei_ids CHAR(2000)              );";
-
-                if(sqlite3_prepare_v2(m_db, sql.c_str(), -1, &stmt, NULL) == SQLITE_OK)
-                {
-                    //执行该语句
-                    if(sqlite3_step(stmt) != SQLITE_DONE)
-                    {
-                        std::string err = sqlite3_errmsg(m_db);
-                        LOG_INFO("create table fail: " << err.c_str());
-
-                        sqlite3_finalize(stmt);
-                        return false;
-                    }
-
-                    //走到这里就是表创建成功了
-                    LOG_INFO("create table success");
-                    sqlite3_finalize(stmt);
-                }
-
-                else
-                {
-                    LOG_INFO("create table prepare fail: " << sqlite3_errmsg(m_db));
-
-                    sqlite3_finalize(stmt);
-
-                    return false;
-                }
-            }
-
-            else
-            {
-                //说明已经有这个表了,就不用再创建了
-                sqlite3_finalize(stmt);
-            }
-
-            std::string sql = "SELECT * FROM pos_chufang_printer;";
-            sqlite3_stmt* stmt = NULL;
-
-            if(sqlite3_prepare_v2(m_db, sql.c_str(), -1, &stmt, NULL) == SQLITE_OK)
-            {
-                while(sqlite3_step(stmt) == SQLITE_ROW)
-                {
-                    std::string date = (char*)sqlite3_column_text(stmt, 1);
-                    std::string name = (char*)sqlite3_column_text(stmt, 2);
-                    std::string ip = (char*)sqlite3_column_text(stmt, 3);
-                    std::string guige = (char*)sqlite3_column_text(stmt, 4);
-                    std::string fendan = (char*)sqlite3_column_text(stmt, 5);
-                    std::string fenlei = (char*)sqlite3_column_text(stmt, 6);
-                    std::string fenlei_ids = (char*)sqlite3_column_text(stmt, 7);
-
-                    //这里仅仅是把数据库内容读到内存,所以之类用false
-                    CSetting::AddChufangPrinter(date, name, ip, guige, fendan, fenlei, fenlei_ids, false);
-                }
-
-                sqlite3_finalize(stmt);
-            }
-
-            else
-            {
-                //异常情况
-                sqlite3_finalize(stmt);
-                return false;
-            }
-        }
-    }
+	if (sqlite3_prepare_v2(m_db, sql.c_str(), -1, &stmt, NULL) == SQLITE_OK)
+	{
+		if (sqlite3_step(stmt) == SQLITE_ROW)
+		{
+			int count = sqlite3_column_int(stmt, 0);
+
+			if (count == 0)
+			{
+				//说明没找到这个表,那么这个时候新建这个表,先释放前面的stmt
+				sqlite3_finalize(stmt);
+				stmt = NULL;
+
+				sql = "CREATE TABLE pos_chufang_printer("  \
+					"id         INTEGER          PRIMARY KEY AUTOINCREMENT,"\
+					"date       CHAR(100)        NOT NULL," \
+					"name       CHAR(100)        NOT NULL," \
+					"ip         CHAR(100)        NOT NULL," \
+					"guige      CHAR(100)        NOT NULL," \
+					"fendan     CHAR(100)        NOT NULL," \
+					"fenlei     CHAR(100)        NOT NULL," \
+					"fenlei_ids CHAR(2000)              );";
+
+				if (sqlite3_prepare_v2(m_db, sql.c_str(), -1, &stmt, NULL) == SQLITE_OK)
+				{
+					//执行该语句
+					if (sqlite3_step(stmt) != SQLITE_DONE)
+					{
+						std::string err = sqlite3_errmsg(m_db);
+						LOG_INFO("create table fail: " << err.c_str());
+
+						sqlite3_finalize(stmt);
+						return false;
+					}
+
+					//走到这里就是表创建成功了
+					LOG_INFO("create table success");
+					sqlite3_finalize(stmt);
+				}
+
+				else
+				{
+					LOG_INFO("create table prepare fail: " << sqlite3_errmsg(m_db));
+
+					sqlite3_finalize(stmt);
+
+					return false;
+				}
+			}
+
+			else
+			{
+				//说明已经有这个表了,就不用再创建了
+				sqlite3_finalize(stmt);
+			}
+
+			//兼容性检查,判断字段是否存在
+			std::string sql_pandduan = "select COUNT(*) from sqlite_master where type = 'table' and tbl_name = 'pos_chufang_printer' and sql like '%fenlei%';";
+			stmt = NULL;
+
+			if (sqlite3_prepare_v2(m_db, sql_pandduan.c_str(), -1, &stmt, NULL) == SQLITE_OK)
+			{
+				if (sqlite3_step(stmt) == SQLITE_ROW)
+				{
+					int count = sqlite3_column_int(stmt, 0);
+
+					if (count == 0)
+					{
+						//说明没找到这个字段,准备添加字段
+						LOG_INFO("not fount field");
+						sqlite3_finalize(stmt);
+						stmt = NULL;
+
+						sql = "ALTER TABLE pos_chufang_printer "  \
+							"add fenlei     CHAR(100)         NOT NULL DEFAULT '0';";
+
+						LOG_INFO("sql:" << sql.c_str());
+
+						if (sqlite3_prepare_v2(m_db, sql.c_str(), -1, &stmt, NULL) == SQLITE_OK)
+						{
+							//执行该语句
+							if (sqlite3_step(stmt) != SQLITE_DONE)
+							{
+								std::string err = sqlite3_errmsg(m_db);
+								LOG_INFO("alter table fail: " << err.c_str());
+
+								sqlite3_finalize(stmt);
+								return false;
+							}
+
+							//走到这里就是表创建成功了
+							LOG_INFO("alter table success");
+							sqlite3_finalize(stmt);
+						}
+
+						else
+						{
+							LOG_INFO("alter table prepare fail: " << sqlite3_errmsg(m_db));
+
+							sqlite3_finalize(stmt);
+
+							return false;;
+						}
+					}
+
+					else
+					{
+						LOG_INFO("fount field");
+
+						//说明已经有这2个字段了
+						sqlite3_finalize(stmt);
+					}
+				}
+			}
+
+			else
+			{
+				//异常情况
+				sqlite3_finalize(stmt);
+				return false;
+			}
+
+			sql_pandduan = "select COUNT(*) from sqlite_master where type = 'table' and tbl_name = 'pos_chufang_printer' and sql like '%fenlei_ids%';";
+			stmt = NULL;
+
+			if (sqlite3_prepare_v2(m_db, sql_pandduan.c_str(), -1, &stmt, NULL) == SQLITE_OK)
+			{
+				if (sqlite3_step(stmt) == SQLITE_ROW)
+				{
+					int count = sqlite3_column_int(stmt, 0);
+
+					if (count == 0)
+					{
+						//说明没找到这个字段,准备添加字段
+						LOG_INFO("not fount field");
+						sqlite3_finalize(stmt);
+						stmt = NULL;
+
+						sql = "ALTER TABLE pos_chufang_printer "  \
+							"add fenlei_ids CHAR(2000) NOT NULL DEFAULT '';";
+
+						LOG_INFO("sql:" << sql.c_str());
+
+						if (sqlite3_prepare_v2(m_db, sql.c_str(), -1, &stmt, NULL) == SQLITE_OK)
+						{
+							//执行该语句
+							if (sqlite3_step(stmt) != SQLITE_DONE)
+							{
+								std::string err = sqlite3_errmsg(m_db);
+								LOG_INFO("alter table fail: " << err.c_str());
+
+								sqlite3_finalize(stmt);
+								return false;
+							}
+
+							//走到这里就是表创建成功了
+							LOG_INFO("alter table success");
+							sqlite3_finalize(stmt);
+						}
+
+						else
+						{
+							LOG_INFO("alter table prepare fail: " << sqlite3_errmsg(m_db));
+
+							sqlite3_finalize(stmt);
+
+							return false;;
+						}
+					}
+
+					else
+					{
+						LOG_INFO("fount field");
+
+						//说明已经有这2个字段了
+						sqlite3_finalize(stmt);
+					}
+				}
+			}
+
+			else
+			{
+				//异常情况
+				sqlite3_finalize(stmt);
+				return false;
+			}
+
+			std::string sql = "SELECT * FROM pos_chufang_printer;";
+			stmt = NULL;
+
+			if (sqlite3_prepare_v2(m_db, sql.c_str(), -1, &stmt, NULL) == SQLITE_OK)
+			{
+				while (sqlite3_step(stmt) == SQLITE_ROW)
+				{
+					std::string date = (char*)sqlite3_column_text(stmt, 1);
+					std::string name = (char*)sqlite3_column_text(stmt, 2);
+					std::string ip = (char*)sqlite3_column_text(stmt, 3);
+					std::string guige = (char*)sqlite3_column_text(stmt, 4);
+					std::string fendan = (char*)sqlite3_column_text(stmt, 5);
+					std::string fenlei = (char*)sqlite3_column_text(stmt, 6);
+					std::string fenlei_ids = (char*)sqlite3_column_text(stmt, 7);
+
+					//这里仅仅是把数据库内容读到内存,所以之类用false
+					CSetting::AddChufangPrinter(date, name, ip, guige, fendan, fenlei, fenlei_ids, false);
+				}
+
+				sqlite3_finalize(stmt);
+			}
+
+			else
+			{
+				//异常情况
+				sqlite3_finalize(stmt);
+				return false;
+			}
+		}
+	}
 
     sql = "SELECT COUNT(*) FROM sqlite_master where type = 'table' and name = 'pos_user';";
 
@@ -259,7 +390,7 @@ bool CSqlite3::InitConfig()
                     }
 
                     //走到这里就是表创建成功了
-                    LOG_INFO("create table success");
+                    //LOG_INFO("create table success");
                     sqlite3_finalize(stmt);
                 }
 
@@ -280,7 +411,7 @@ bool CSqlite3::InitConfig()
             }
 
             std::string sql = "SELECT * FROM pos_user;";
-            sqlite3_stmt* stmt = NULL;
+            sqlite3_stmt * stmt = NULL;
 
             if(sqlite3_prepare_v2(m_db, sql.c_str(), -1, &stmt, NULL) == SQLITE_OK)
             {
@@ -328,45 +459,45 @@ bool CSqlite3::SaveParams(std::map<std::string, std::string>& params)
 
     if(result == SQLITE_OK)
     {
-        LOG_INFO("save params success");
+        //LOG_INFO("save params success");
         return true;
     }
 
-    LOG_INFO("save params fail");
+    LOG_INFO("save params fail:"<< sqlite3_errmsg(m_db));
     return false;
 }
 
 bool CSqlite3::SaveChufangPrinter(std::vector<ChufangPrinter>& printers)
 {
-    int result = sqlite3_exec(m_db, "BEGIN;", 0, 0, 0);
-
-    std::string sql = "delete from pos_chufang_printer;";
-    result = sqlite3_exec(m_db, sql.c_str(), 0, 0, 0);
-
-    for(std::vector<ChufangPrinter>::iterator it = printers.begin(); it != printers.end(); it++)
-    {
-        std::string date = (*it).date;
-        std::string name = (*it).name;
-        std::string ip = (*it).ip;
-        std::string guige = (*it).guige;
-        std::string fendan = (*it).fendan;
-        std::string fenlei = (*it).fenlei;
-        std::string fenlei_ids = (*it).fenlei_ids;
-
-        sql = "INSERT INTO pos_chufang_printer (date, name, ip, guige, fendan, fenlei, fenlei_ids) VALUES ('" + date + "' ,'" + name + "','" + ip + "','" + guige + "','" + fendan + "','" + fenlei + "','" + fenlei_ids + "')";
-        result = sqlite3_exec(m_db, sql.c_str(), 0, 0, 0);
-    }
-
-    result = sqlite3_exec(m_db, "COMMIT;", 0, 0, 0);
-
-    if(result == SQLITE_OK)
-    {
-        LOG_INFO("save params success");
-        return true;
-    }
-
-    LOG_INFO("save params fail");
-    return false;
+	int result = sqlite3_exec(m_db, "BEGIN;", 0, 0, 0);
+
+	std::string sql = "delete from pos_chufang_printer;";
+	result = sqlite3_exec(m_db, sql.c_str(), 0, 0, 0);
+
+	for (std::vector<ChufangPrinter>::iterator it = printers.begin(); it != printers.end(); it++)
+	{
+		std::string date = (*it).date;
+		std::string name = (*it).name;
+		std::string ip = (*it).ip;
+		std::string guige = (*it).guige;
+		std::string fendan = (*it).fendan;
+		std::string fenlei = (*it).fenlei;
+		std::string fenlei_ids = (*it).fenlei_ids;
+
+		sql = "INSERT INTO pos_chufang_printer (date, name, ip, guige, fendan, fenlei, fenlei_ids) VALUES ('" + date + "' ,'" + name + "','" + ip + "','" + guige + "','" + fendan + "','" + fenlei + "','" + fenlei_ids + "')";
+		result = sqlite3_exec(m_db, sql.c_str(), 0, 0, 0);
+	}
+
+	result = sqlite3_exec(m_db, "COMMIT;", 0, 0, 0);
+
+	if (result == SQLITE_OK)
+	{
+		LOG_INFO("save params success");
+		return true;
+	}
+
+	LOG_INFO("save params fail");
+	return false;
 }
 
 bool CSqlite3::SaveUsers(std::map<string, string> users)
@@ -389,10 +520,10 @@ bool CSqlite3::SaveUsers(std::map<string, string> users)
 
     if(result == SQLITE_OK)
     {
-        LOG_INFO("save params success");
+        //LOG_INFO("save params success");
         return true;
     }
 
-    LOG_INFO("save params fail");
+    //LOG_INFO("save params fail");
     return false;
 }

+ 15 - 15
zhipuzi_pos_windows/tool/CSqlite3.h

@@ -7,29 +7,29 @@
 class CSqlite3
 {
 public:
-    CSqlite3();
-    ~CSqlite3();
+	CSqlite3();
+	~CSqlite3();
 
 public:
-    bool InitConfig();
+	bool InitConfig();
 
-    bool SaveParams(std::map<std::string, std::string>& params);
+	bool SaveParams(std::map<std::string, std::string>& params);
 
-    bool SaveChufangPrinter(std::vector<ChufangPrinter>& printers);
+	bool SaveChufangPrinter(std::vector<ChufangPrinter>& printers);
 
-    bool SaveUsers(std::map<string, string> users);
+	bool SaveUsers(std::map<string, string> users);
 
-    void Close()
-    {
-        if(m_db != NULL)
-        {
-            sqlite3_close(m_db);
-        }
-    }
+	void Close()
+	{
+		if (m_db != NULL)
+		{
+			sqlite3_close(m_db);
+		}
+	}
 
 private:
-    int m_rc;
+	int m_rc;
 
-    sqlite3* m_db = NULL;
+	sqlite3* m_db = NULL;
 };
 

+ 77 - 77
zhipuzi_pos_windows/wnd/CChufangSettingWnd.cpp

@@ -3,99 +3,99 @@
 
 LRESULT CChufangSettingWnd::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);
+	POINT pt;
+	pt.x = GET_X_LPARAM(lParam);
+	pt.y = GET_Y_LPARAM(lParam);
+	::ScreenToClient(*this, &pt);
 
-    RECT rcClient;
-    ::GetClientRect(*this, &rcClient);
+	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;
-        }
-    }
+	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;
+	return HTCLIENT;
 }
 
 LRESULT CChufangSettingWnd::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);
-    }
+	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;
+	bHandled = FALSE;
+	return 0;
 }
 
 LRESULT CChufangSettingWnd::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 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 CChufangSettingWnd::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;
+	if (uMsg == WM_KEYDOWN)
+	{
+		if (wParam == VK_RETURN)
+		{
+			return true;
+		}
+		else if (wParam == VK_ESCAPE)
+		{
+			return true;
+		}
+	}
+	return false;
 }
 
 

+ 240 - 240
zhipuzi_pos_windows/wnd/CChufangSettingWnd.h

@@ -8,13 +8,13 @@ class CChufangSettingWnd : public CWindowWnd, public INotifyUI, public IMessageF
 public:
     CChufangSettingWnd(int mode)
     {
-        m_mode = mode;
+		m_mode = mode;
     }
 
-    void SetPrinterDate(std::string date)
-    {
-        m_printer_date = date;
-    }
+	void SetPrinterDate(std::string date)
+	{
+		m_printer_date = date;
+	}
 
     LPCTSTR GetWindowClassName() const
     {
@@ -35,145 +35,145 @@ public:
 
     void Init()
     {
-        CLabelUI* ip_error = static_cast<CLabelUI*>(m_pm.FindControl(_T("chufang_setting_ip_error")));
-        ip_error->SetVisible(false);
-
-        CLabelUI* title = static_cast<CLabelUI*>(m_pm.FindControl(_T("chufang_setting_title")));
-        if(m_mode == 1)
-        {
-            title->SetText(L"新建厨房打印机");
-        }
-        else
-        {
-            title->SetText(L"修改厨房打印机");
-        }
-
-        CEditUI* name = static_cast<CEditUI*>(m_pm.FindControl(_T("chufang_setting_name")));
-        if(m_mode == 1)
-        {
-            name->SetText(L"");
-        }
-        else
-        {
-            ChufangPrinter updatePrinter = CSetting::GetChufangPrinter(m_printer_date);
-            name->SetText(CLewaimaiString::UTF8ToUnicode(updatePrinter.name).c_str());
-        }
-
-
-        CEditUI* ip = static_cast<CEditUI*>(m_pm.FindControl(_T("chufang_setting_ip")));
-        if(m_mode == 1)
-        {
-            ip->SetText(L"");
-        }
-        else
-        {
-            ChufangPrinter updatePrinter = CSetting::GetChufangPrinter(m_printer_date);
-            ip->SetText(CLewaimaiString::UTF8ToUnicode(updatePrinter.ip).c_str());
-        }
-
-
-        CComboUI* com = static_cast<CComboUI*>(m_pm.FindControl(_T("chufang_setting_guige")));
-        if(m_mode == 1)
-        {
-            com->SelectItem(0, false, false);
-        }
-        else
-        {
-            ChufangPrinter updatePrinter = CSetting::GetChufangPrinter(m_printer_date);
-            if(updatePrinter.guige == "58")
-            {
-                com->SetInternVisible(true);
-                com->SelectItem(0, false, false);
-            }
-
-            else
-            {
-                com->SetInternVisible(true);
-                com->SelectItem(1, false, false);
-            }
-        }
-
-        CCheckBoxUI* fendan = static_cast<CCheckBoxUI*>(m_pm.FindControl(_T("chufang_setting_fendan")));
-        if(m_mode == 1)
-        {
-            fendan->Selected(false, false);
-        }
-        else
-        {
-            ChufangPrinter updatePrinter = CSetting::GetChufangPrinter(m_printer_date);
-            if(updatePrinter.fendan == "1")
-            {
-                fendan->Selected(true, false);
-            }
-            else
-            {
-                fendan->Selected(false, false);
-            }
-        }
-
-        CCheckBoxUI* fenlei = static_cast<CCheckBoxUI*>(m_pm.FindControl(_T("chufang_setting_fenlei")));
-        if(m_mode == 1)
-        {
-            fenlei->Selected(false, false);
-        }
-        else
-        {
-            ChufangPrinter updatePrinter = CSetting::GetChufangPrinter(m_printer_date);
-            if(updatePrinter.fenlei == "1")
-            {
-                fenlei->Selected(true, false);
-            }
-            else
-            {
-                fenlei->Selected(false, false);
-            }
-        }
-
-        //把所有分类显示出来
-        CVerticalLayoutUI* pLayout = static_cast<CVerticalLayoutUI*>(m_pm.FindControl(_T("chufang_setting_fenlei_xuanze_area")));
-        pLayout->RemoveAll();
-
-        ChufangPrinter updatePrinter;
-
-        //这个map用于后面判断每个分类ID是否被选中
-        std::map<string, bool> ids_map;
-
-        if(m_mode == 2)
-        {
-            updatePrinter = CSetting::GetChufangPrinter(m_printer_date);
-            std::string foodtype_ids = updatePrinter.fenlei_ids;
-            std::vector<string> ids = CLewaimaiString::Split(foodtype_ids, ",");
-            for(std::vector<string>::iterator it = ids.begin(); it != ids.end(); it++)
-            {
-                ids_map[(*it)] = true;
-            }
-        }
-
-        std::vector<FoodType> foodtypes = CSetting::GetFoodtype();
-        for(std::vector<FoodType>::iterator it = foodtypes.begin(); it != foodtypes.end(); it++)
-        {
-            CDialogBuilder builder;
-            CListContainerElementUI* pEle = static_cast<CListContainerElementUI*>(builder.Create(_T("chufang_printer_setting_fenlei_select.xml"), (UINT)0, NULL, &m_pm));
-
-            CCheckBoxUI* pCheck = static_cast<CCheckBoxUI*>(pEle->FindSubControl(_T("chufang_setting_fenleli_xuanze_checkbox")));
-            pCheck->AddCustomAttribute(L"type_id", CLewaimaiString::UTF8ToUnicode((*it).type_id).c_str());
-
-            if(m_mode == 2)
-            {
-                if(ids_map.find((*it).type_id) != ids_map.end())
-                {
-                    pCheck->Selected(true, false);
-                }
-            }
-
-            CLabelUI* pName = static_cast<CLabelUI*>(pEle->FindSubControl(_T("chufang_setting_fenleli_xuanze_name")));
-            pName->SetText(CLewaimaiString::UTF8ToUnicode((*it).name).c_str());
-
-            pLayout->Add(pEle);
-        }
-
-        CVerticalLayoutUI* pOutLayout = static_cast<CVerticalLayoutUI*>(m_pm.FindControl(_T("chufang_setting_fenlei_xuanze")));
-        pOutLayout->SetFixedHeight(foodtypes.size() * 30 + 30);
+		CLabelUI* ip_error = static_cast<CLabelUI*>(m_pm.FindControl(_T("chufang_setting_ip_error")));
+		ip_error->SetVisible(false);
+
+		CLabelUI* title = static_cast<CLabelUI*>(m_pm.FindControl(_T("chufang_setting_title")));
+		if (m_mode == 1)
+		{
+			title->SetText(L"新建厨房打印机");
+		}
+		else
+		{
+			title->SetText(L"修改厨房打印机");
+		}
+
+		CEditUI* name = static_cast<CEditUI*>(m_pm.FindControl(_T("chufang_setting_name")));
+		if (m_mode == 1)
+		{
+			name->SetText(L"");
+		}
+		else
+		{
+			ChufangPrinter updatePrinter = CSetting::GetChufangPrinter(m_printer_date);
+			name->SetText(CLewaimaiString::UTF8ToUnicode(updatePrinter.name).c_str());
+		}
+		
+
+		CEditUI* ip = static_cast<CEditUI*>(m_pm.FindControl(_T("chufang_setting_ip")));
+		if (m_mode == 1)
+		{
+			ip->SetText(L"");
+		}
+		else
+		{
+			ChufangPrinter updatePrinter = CSetting::GetChufangPrinter(m_printer_date);
+			ip->SetText(CLewaimaiString::UTF8ToUnicode(updatePrinter.ip).c_str());
+		}
+		
+
+		CComboUI* com = static_cast<CComboUI*>(m_pm.FindControl(_T("chufang_setting_guige")));
+		if (m_mode == 1)
+		{
+			com->SelectItem(0, false, false);
+		}
+		else
+		{
+			ChufangPrinter updatePrinter = CSetting::GetChufangPrinter(m_printer_date);
+			if (updatePrinter.guige == "58")
+			{
+				com->SetInternVisible(true);
+				com->SelectItem(0, false, false);
+			}
+
+			else
+			{
+				com->SetInternVisible(true);
+				com->SelectItem(1, false, false);
+			}
+		}		
+
+		CCheckBoxUI* fendan = static_cast<CCheckBoxUI*>(m_pm.FindControl(_T("chufang_setting_fendan")));
+		if (m_mode == 1)
+		{
+			fendan->Selected(false, false);
+		}
+		else
+		{
+			ChufangPrinter updatePrinter = CSetting::GetChufangPrinter(m_printer_date);
+			if (updatePrinter.fendan == "1")
+			{
+				fendan->Selected(true, false);
+			}
+			else
+			{
+				fendan->Selected(false, false);
+			}
+		}
+
+		CCheckBoxUI* fenlei = static_cast<CCheckBoxUI*>(m_pm.FindControl(_T("chufang_setting_fenlei")));
+		if (m_mode == 1)
+		{
+			fenlei->Selected(false, false);
+		}
+		else
+		{
+			ChufangPrinter updatePrinter = CSetting::GetChufangPrinter(m_printer_date);
+			if (updatePrinter.fenlei == "1")
+			{
+				fenlei->Selected(true, false);
+			}
+			else
+			{
+				fenlei->Selected(false, false);
+			}
+		}
+
+		//把所有分类显示出来
+		CVerticalLayoutUI* pLayout = static_cast<CVerticalLayoutUI*>(m_pm.FindControl(_T("chufang_setting_fenlei_xuanze_area")));
+		pLayout->RemoveAll();
+
+		ChufangPrinter updatePrinter;
+
+		//这个map用于后面判断每个分类ID是否被选中
+		std::map<string, bool> ids_map;
+
+		if (m_mode == 2)
+		{
+			updatePrinter = CSetting::GetChufangPrinter(m_printer_date);
+			std::string foodtype_ids = updatePrinter.fenlei_ids;
+			std::vector<string> ids = CLewaimaiString::Split(foodtype_ids, ",");
+			for (std::vector<string>::iterator it = ids.begin(); it != ids.end(); it++)
+			{
+				ids_map[(*it)] = true;
+			}
+		}
+
+		std::vector<FoodType> foodtypes = CSetting::GetFoodtype();
+		for (std::vector<FoodType>::iterator it = foodtypes.begin(); it != foodtypes.end(); it++)
+		{
+			CDialogBuilder builder;
+			CListContainerElementUI* pEle = static_cast<CListContainerElementUI*>(builder.Create(_T("chufang_printer_setting_fenlei_select.xml"), (UINT)0, NULL, &m_pm));
+
+			CCheckBoxUI* pCheck = static_cast<CCheckBoxUI*>(pEle->FindSubControl(_T("chufang_setting_fenleli_xuanze_checkbox")));
+			pCheck->AddCustomAttribute(L"type_id", CLewaimaiString::UTF8ToUnicode((*it).type_id).c_str());
+
+			if (m_mode == 2)
+			{
+				if (ids_map.find((*it).type_id) != ids_map.end())
+				{
+					pCheck->Selected(true, false);
+				}
+			}
+
+			CLabelUI* pName = static_cast<CLabelUI*>(pEle->FindSubControl(_T("chufang_setting_fenleli_xuanze_name")));
+			pName->SetText(CLewaimaiString::UTF8ToUnicode((*it).name).c_str());
+
+			pLayout->Add(pEle);
+		}
+
+		CVerticalLayoutUI* pOutLayout = static_cast<CVerticalLayoutUI*>(m_pm.FindControl(_T("chufang_setting_fenlei_xuanze")));
+		pOutLayout->SetFixedHeight(foodtypes.size() * 30 + 30);
     }
 
     void Notify(TNotifyUI& msg)
@@ -190,96 +190,96 @@ public:
             else if(senderName == _T("chufang_setting_save"))
             {
                 //开始保存厨房打印机的数据
-                CEditUI* pName = static_cast<CEditUI*>(m_pm.FindControl(_T("chufang_setting_name")));
-                wstring wsName = pName->GetText();
-
-                CEditUI* pIP = static_cast<CEditUI*>(m_pm.FindControl(_T("chufang_setting_ip")));
-                wstring wsIP = pIP->GetText();
-
-                //判断IP的格式是否合法
-                if(CLewaimaiString::isIPAddressValid(CLewaimaiString::UnicodeToUTF8(wsIP).c_str()) == false)
-                {
-                    //如果IP格式不合法,就提示
-                    CLabelUI* ip_error = static_cast<CLabelUI*>(m_pm.FindControl(_T("chufang_setting_ip_error")));
-                    ip_error->SetVisible(true);
-
-                    return;
-                }
-
-                CComboUI* com = static_cast<CComboUI*>(m_pm.FindControl(_T("chufang_setting_guige")));
-                wstring wsGuige;
-                if(com->GetCurSel() == 0)
-                {
-                    wsGuige = L"58";
-                }
-                else
-                {
-                    wsGuige = L"80";
-                }
-
-                CCheckBoxUI* pFendan = static_cast<CCheckBoxUI*>(m_pm.FindControl(_T("chufang_setting_fendan")));
-                wstring wsFendan;
-                if(pFendan->IsSelected())
-                {
-                    wsFendan = L"1";
-                }
-                else
-                {
-                    wsFendan = L"0";
-                }
-
-                CCheckBoxUI* pFenlei = static_cast<CCheckBoxUI*>(m_pm.FindControl(_T("chufang_setting_fenlei")));
-                wstring wsFenlei;
-                if(pFenlei->IsSelected())
-                {
-                    wsFenlei = L"1";
-                }
-                else
-                {
-                    wsFenlei = L"0";
-                }
-
-                std::string fenlei_ids = "";
-
-                CVerticalLayoutUI* pLayout = static_cast<CVerticalLayoutUI*>(m_pm.FindControl(_T("chufang_setting_fenlei_xuanze_area")));
-                CDuiPtrArray* pArray = m_pm.FindSubControlsByClass(pLayout, _T("CheckBox"));
-                int size = pArray->GetSize();
-                for(int i = 0; i < size; i++)
-                {
-                    CCheckBoxUI* pBox = static_cast<CCheckBoxUI*>(pArray->GetAt(i));
-
-                    if(pBox->IsSelected())
-                    {
-                        std::wstring ws_type_id = pBox->GetCustomAttribute(_T("type_id"));
-                        std::string type_id = CLewaimaiString::UnicodeToUTF8(ws_type_id);
-
-                        fenlei_ids += type_id + ",";
-                    }
-                }
-
-                fenlei_ids = fenlei_ids.substr(0, fenlei_ids.size() - 1);
-
-                //保存数据到数据库
-
-                std::string date = to_string(time(NULL));
-
-                std::string name = CLewaimaiString::UnicodeToUTF8(wsName);
-                std::string ip = CLewaimaiString::UnicodeToUTF8(wsIP);
-                std::string guige = CLewaimaiString::UnicodeToUTF8(wsGuige);
-                std::string fendan = CLewaimaiString::UnicodeToUTF8(wsFendan);
-                std::string fenlei = CLewaimaiString::UnicodeToUTF8(wsFenlei);
-
-                if(m_mode == 1)
-                {
-                    CSetting::AddChufangPrinter(date, name, ip, guige, fendan, fenlei, fenlei_ids, true);
-                }
-                else
-                {
-                    CSetting::UpdateChufangPrinter(m_printer_date, name, ip, guige, fendan, fenlei, fenlei_ids, true);
-                }
-
-                Close(IDOK);
-                return;
+				CEditUI* pName = static_cast<CEditUI*>(m_pm.FindControl(_T("chufang_setting_name")));
+				wstring wsName = pName->GetText();
+
+				CEditUI* pIP = static_cast<CEditUI*>(m_pm.FindControl(_T("chufang_setting_ip")));
+				wstring wsIP = pIP->GetText();
+
+				//判断IP的格式是否合法
+				if (CLewaimaiString::isIPAddressValid(CLewaimaiString::UnicodeToUTF8(wsIP).c_str()) == false)
+				{
+					//如果IP格式不合法,就提示
+					CLabelUI* ip_error = static_cast<CLabelUI*>(m_pm.FindControl(_T("chufang_setting_ip_error")));
+					ip_error->SetVisible(true);
+
+					return;
+				}
+
+				CComboUI* com = static_cast<CComboUI*>(m_pm.FindControl(_T("chufang_setting_guige")));
+				wstring wsGuige;
+				if (com->GetCurSel() == 0)
+				{
+					wsGuige = L"58";
+				}
+				else
+				{
+					wsGuige = L"80";
+				}
+
+				CCheckBoxUI* pFendan = static_cast<CCheckBoxUI*>(m_pm.FindControl(_T("chufang_setting_fendan")));
+				wstring wsFendan;
+				if (pFendan->IsSelected())
+				{
+					wsFendan = L"1";
+				}
+				else
+				{
+					wsFendan = L"0";
+				}
+
+				CCheckBoxUI* pFenlei = static_cast<CCheckBoxUI*>(m_pm.FindControl(_T("chufang_setting_fenlei")));
+				wstring wsFenlei;
+				if (pFenlei->IsSelected())
+				{
+					wsFenlei = L"1";
+				}
+				else
+				{
+					wsFenlei = L"0";
+				}
+
+				std::string fenlei_ids = "";
+
+				CVerticalLayoutUI* pLayout = static_cast<CVerticalLayoutUI*>(m_pm.FindControl(_T("chufang_setting_fenlei_xuanze_area")));
+				CDuiPtrArray* pArray = m_pm.FindSubControlsByClass(pLayout, _T("CheckBox"));
+				int size = pArray->GetSize();
+				for (int i = 0; i < size; i++)
+				{
+					CCheckBoxUI* pBox = static_cast<CCheckBoxUI*>(pArray->GetAt(i));
+
+					if (pBox->IsSelected())
+					{
+						std::wstring ws_type_id = pBox->GetCustomAttribute(_T("type_id"));
+						std::string type_id = CLewaimaiString::UnicodeToUTF8(ws_type_id);
+
+						fenlei_ids += type_id + ",";
+					}
+				}
+
+				fenlei_ids = fenlei_ids.substr(0, fenlei_ids.size() - 1);
+
+				//保存数据到数据库
+
+				std::string date = to_string(time(NULL));
+
+				std::string name = CLewaimaiString::UnicodeToUTF8(wsName);
+				std::string ip = CLewaimaiString::UnicodeToUTF8(wsIP);
+				std::string guige = CLewaimaiString::UnicodeToUTF8(wsGuige);
+				std::string fendan = CLewaimaiString::UnicodeToUTF8(wsFendan);
+				std::string fenlei = CLewaimaiString::UnicodeToUTF8(wsFenlei);
+
+				if (m_mode == 1)
+				{
+					CSetting::AddChufangPrinter(date, name, ip, guige, fendan, fenlei, fenlei_ids, true);
+				}
+				else
+				{
+					CSetting::UpdateChufangPrinter(m_printer_date, name, ip, guige, fendan, fenlei, fenlei_ids, true);
+				}
+
+				Close(IDOK);
+				return;
             }
         }
     }
@@ -330,18 +330,18 @@ public:
         return 0;
     }
 
-    LRESULT OnNcHitTest(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
+	LRESULT OnNcHitTest(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
 
-    LRESULT OnSize(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 HandleMessage(UINT uMsg, WPARAM wParam, LPARAM lParam);
 
-    LRESULT MessageHandler(UINT uMsg, WPARAM wParam, LPARAM lParam, bool& bHandled);
+	LRESULT MessageHandler(UINT uMsg, WPARAM wParam, LPARAM lParam, bool& bHandled);
 
 public:
     CPaintManagerUI m_pm;
 
-    int m_mode; //为1表示新建,为2表示修改
-    std::string m_printer_date; //修改模式下的打印机的日期
+	int m_mode; //为1表示新建,为2表示修改
+	std::string m_printer_date; //修改模式下的打印机的日期
 };
 

+ 300 - 295
zhipuzi_pos_windows/wnd/CLoginWnd.cpp

@@ -1,4 +1,4 @@
-#include "../pch/pch.h"
+#include "../pch/pch.h"
 #include "CLoginWnd.h"
 #include "CUpdateWnd.h"
 
@@ -6,72 +6,73 @@
 
 void CLoginWnd::Init()
 {
-    CLabelUI* version = static_cast<CLabelUI*>(m_pm.FindControl(_T("login_version")));
-    version->SetText((L"智铺子收银软件 " + CLewaimaiString::UTF8ToUnicode(CSystem::GetVersion())).c_str());
+	//刷新版本号
+	CLabelUI* version = static_cast<CLabelUI*>(m_pm.FindControl(_T("login_version")));
+	version->SetText((L"乐外卖接单软件 " + CLewaimaiString::UTF8ToUnicode(CSystem::GetVersion())).c_str());
 
-    std::map<string, string> users = CSetting::getUsers();
+	//初始化下拉框的用户名
+	CComboUI* pCom = static_cast<CComboUI*>(m_pm.FindControl(_T("accountcombo")));
 
-    CComboUI* pCom = static_cast<CComboUI*>(m_pm.FindControl(_T("accountcombo")));
-
-    for(std::map<string, string>::iterator it = users.begin(); it != users.end(); it++)
-    {
-        std::string username = it->first;
-
-        CListLabelElementUI* elem = new CListLabelElementUI();
-        elem->SetText(CLewaimaiString::UTF8ToUnicode(username).c_str());
+	std::map<string, string> users = CSetting::getUsers();
+	for (std::map<string, string>::iterator it = users.begin(); it != users.end(); it++)
+	{
+		std::string username = it->first;
+		
+		CListLabelElementUI* elem = new CListLabelElementUI();
+		elem->SetText(CLewaimaiString::UTF8ToUnicode(username).c_str());
 
-        pCom->Add(elem);
-    }
+		pCom->Add(elem);
+	}
 
-    CCheckBoxUI* pAuto = static_cast<CCheckBoxUI*>(m_pm.FindControl(_T("login_auto_login")));
-    CCheckBoxUI* pRemember = static_cast<CCheckBoxUI*>(m_pm.FindControl(_T("login_remember_password")));
+	CCheckBoxUI* pAuto = static_cast<CCheckBoxUI*>(m_pm.FindControl(_T("login_auto_login")));
+	CCheckBoxUI* pRemember = static_cast<CCheckBoxUI*>(m_pm.FindControl(_T("login_remember_password")));
 
-    if(CSetting::GetParam("setting_is_remember_password") == "1")
-    {
-        pRemember->Selected(true, false);
-    }
-    else
-    {
-        pRemember->Selected(false, false);
-    }
+	if (CSetting::GetParam("setting_is_remember_password") == "1")
+	{
+		pRemember->Selected(true, false);
+	}
+	else
+	{
+		pRemember->Selected(false, false);
+	}
 
-    if(CSetting::GetParam("setting_is_auto_login") == "1")
-    {
-        //自动登录开启了,记住密码一定要开启
-        pAuto->Selected(true, false);
-        pRemember->Selected(true, false);
-    }
-    else
-    {
-        pAuto->Selected(false, false);
-    }
+	if (CSetting::GetParam("setting_is_auto_login") == "1")
+	{
+		//自动登录开启了,记住密码一定要开启
+		pAuto->Selected(true, false);
+		pRemember->Selected(true, false);
+	}
+	else
+	{
+		pAuto->Selected(false, false);
+	}
 
-    std::string last_login_username = CSetting::GetParam("last_login_username");
-    std::string password = CSetting::GetUser(last_login_username);
+	std::string last_login_username = CSetting::GetParam("last_login_username");
+	std::string password = CSetting::GetUser(last_login_username);
 
-    CEditUI* pAccountEdit = static_cast<CEditUI*>(m_pm.FindControl(_T("accountedit")));
-    CEditUI* pPasswordEdit = static_cast<CEditUI*>(m_pm.FindControl(_T("pwdedit")));
+	CEditUI* pAccountEdit = static_cast<CEditUI*>(m_pm.FindControl(_T("accountedit")));
+	CEditUI* pPasswordEdit = static_cast<CEditUI*>(m_pm.FindControl(_T("pwdedit")));
 
-    pAccountEdit->SetText(CLewaimaiString::UTF8ToUnicode(last_login_username).c_str());
-    pPasswordEdit->SetText(CLewaimaiString::UTF8ToUnicode(password).c_str());
+	pAccountEdit->SetText(CLewaimaiString::UTF8ToUnicode(last_login_username).c_str());
+	pPasswordEdit->SetText(CLewaimaiString::UTF8ToUnicode(password).c_str());
 
-    if(CSetting::GetParam("setting_is_auto_login") == "1")
-    {
-        StartLogin();
-    }
-    else
-    {
-        CVerticalLayoutUI* pInput = static_cast<CVerticalLayoutUI*>(m_pm.FindControl(_T("login_input")));
-        pInput->SetVisible(true);
+	if (CSetting::GetParam("setting_is_auto_login") == "1")
+	{
+		StartLogin();
+	}
+	else
+	{
+		CVerticalLayoutUI* pInput = static_cast<CVerticalLayoutUI*>(m_pm.FindControl(_T("login_input")));
+		pInput->SetVisible(true);
 
-        CVerticalLayoutUI* pLoading = static_cast<CVerticalLayoutUI*>(m_pm.FindControl(_T("login_loading")));
-        pLoading->SetVisible(false);
-    }
+		CVerticalLayoutUI* pLoading = static_cast<CVerticalLayoutUI*>(m_pm.FindControl(_T("login_loading")));
+		pLoading->SetVisible(false);
+	}
 
-    if(m_mode == 2)
-    {
-        PostMessage(WM_LOGIN_AGAIN_OUT);
-    }
+	if (m_mode == 2)
+	{
+		PostMessage(WM_LOGIN_AGAIN_OUT);
+	}
 }
 
 void CLoginWnd::Notify(TNotifyUI& msg)
@@ -80,58 +81,58 @@ void CLoginWnd::Notify(TNotifyUI& msg)
     {
         if(msg.pSender->GetName() == _T("closebtn"))
         {
-            PostQuitMessage(0);
+			PostQuitMessage(0);
             return;
         }
         else if(msg.pSender->GetName() == _T("loginBtn"))
         {
-            StartLogin();
+			StartLogin();
             return;
         }
-        else if(msg.pSender->GetName() == _T("login_auto_login"))
-        {
-            CCheckBoxUI* pAuto = static_cast<CCheckBoxUI*>(m_pm.FindControl(_T("login_auto_login")));
-            CCheckBoxUI* pRemember = static_cast<CCheckBoxUI*>(m_pm.FindControl(_T("login_remember_password")));
+		else if (msg.pSender->GetName() == _T("login_auto_login"))
+		{
+			CCheckBoxUI* pAuto = static_cast<CCheckBoxUI*>(m_pm.FindControl(_T("login_auto_login")));
+			CCheckBoxUI* pRemember = static_cast<CCheckBoxUI*>(m_pm.FindControl(_T("login_remember_password")));
 
-            if(!pAuto->IsSelected())
-            {
-                pRemember->Selected(true, false);
-            }
-        }
-        else if(msg.pSender->GetName() == _T("login_remember_password"))
-        {
-            CCheckBoxUI* pAuto = static_cast<CCheckBoxUI*>(m_pm.FindControl(_T("login_auto_login")));
-            CCheckBoxUI* pRemember = static_cast<CCheckBoxUI*>(m_pm.FindControl(_T("login_remember_password")));
+			if (!pAuto->IsSelected())
+			{
+				pRemember->Selected(true, false);
+			}
+		}
+		else if (msg.pSender->GetName() == _T("login_remember_password"))
+		{
+			CCheckBoxUI* pAuto = static_cast<CCheckBoxUI*>(m_pm.FindControl(_T("login_auto_login")));
+			CCheckBoxUI* pRemember = static_cast<CCheckBoxUI*>(m_pm.FindControl(_T("login_remember_password")));
 
-            if(pRemember->IsSelected())
-            {
-                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);
-        }
+			if (pRemember->IsSelected())
+			{
+				pAuto->Selected(false, false);
+			}
+		}
+		else if (msg.pSender->GetName() == _T("guanwang"))
+		{
+			ShellExecute(NULL, _T("open"), _T("explorer.exe"), _T("https://www.lewaimai.com"), NULL, SW_SHOW);
+		}
     }
-    else if(msg.sType == _T("itemselect"))
-    {
-        CDuiString name = msg.pSender->GetName();
+	else if (msg.sType == _T("itemselect"))
+	{
+		CDuiString name = msg.pSender->GetName();
 
-        if(name == _T("accountcombo"))
-        {
-            CComboUI* pCom = static_cast<CComboUI*>(m_pm.FindControl(_T("accountcombo")));
+		if (name == _T("accountcombo"))
+		{
+			CComboUI* pCom = static_cast<CComboUI*>(m_pm.FindControl(_T("accountcombo")));
 
-            std::wstring name = pCom->GetItemAt(pCom->GetCurSel())->GetText();
-            std::string password = CSetting::GetUser(CLewaimaiString::UnicodeToUTF8(name));
-            std::wstring wspassword = CLewaimaiString::UTF8ToUnicode(password);
+			std::wstring name = pCom->GetItemAt(pCom->GetCurSel())->GetText();
+			std::string password = CSetting::GetUser(CLewaimaiString::UnicodeToUTF8(name));
+			std::wstring wspassword = CLewaimaiString::UTF8ToUnicode(password);
 
-            CEditUI* pEdit = static_cast<CEditUI*>(m_pm.FindControl(_T("accountedit")));
-            pEdit->SetText(name.c_str());
+			CEditUI* pEdit = static_cast<CEditUI*>(m_pm.FindControl(_T("accountedit")));
+			pEdit->SetText(name.c_str());
 
-            CEditUI* pPassword = static_cast<CEditUI*>(m_pm.FindControl(_T("pwdedit")));
-            pPassword->SetText(wspassword.c_str());
-        }
-    }
+			CEditUI* pPassword = static_cast<CEditUI*>(m_pm.FindControl(_T("pwdedit")));
+			pPassword->SetText(wspassword.c_str());
+		}
+	}
 }
 
 LRESULT CLoginWnd::OnCreate(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
@@ -140,9 +141,8 @@ LRESULT CLoginWnd::OnCreate(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHand
     styleValue &= ~WS_CAPTION;
     ::SetWindowLong(*this, GWL_STYLE, styleValue | WS_CLIPSIBLINGS | WS_CLIPCHILDREN);
 
-    // 把自己的窗口句柄与窗口绘制管理器挂接在一起
+    // 把自己的窗口句柄与窗口绘制管理器挂接在一起
     m_pm.Init(m_hWnd);
-
     m_pm.AddPreMessageFilter(this);
 
     CDialogBuilder builder;
@@ -150,10 +150,10 @@ LRESULT CLoginWnd::OnCreate(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHand
     CControlUI* pRoot = builder.Create(_T("login.xml"), (UINT)0, NULL, &m_pm);
     ASSERT(pRoot && "Failed to parse XML");
 
-    // 鎶婅繖浜涙帶浠剁粯鍒跺埌鏈�獥鍙d笂
+    // 把这些控件绘制到本窗口上
     m_pm.AttachDialog(pRoot);
 
-    // 鎶婅嚜宸卞姞鍏ュ埌CPaintManagerUI鐨刴_aNotifiers鏁扮粍涓�紝鐢ㄤ簬澶勭悊Notify鍑芥暟
+    // 把自己加入到CPaintManagerUI的m_aNotifiers数组中,用于处理Notify函数
     m_pm.AddNotifier(this);
 
     Init();
@@ -163,17 +163,17 @@ LRESULT CLoginWnd::OnCreate(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHand
 
 LRESULT CLoginWnd::OnClose(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
 {
-    bHandled = FALSE;
-    return 0;
+	bHandled = FALSE;
+	return 0;
 }
 
 /*
- *杩欎釜鏄�獥鍙h�閿€姣佺殑鏃跺€欒皟鐢ㄧ殑
+ *这个是窗口被销毁的时候调用的
  **/
 LRESULT CLoginWnd::OnDestroy(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
 {
-    bHandled = FALSE;
-    return 0;
+	bHandled = FALSE;
+	return 0;
 }
 
 LRESULT CLoginWnd::OnNcActivate(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
@@ -192,14 +192,21 @@ LRESULT CLoginWnd::OnNcCalcSize(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& b
 
 LRESULT CLoginWnd::OnNcPaint(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
 {
-    //鍦ㄨ繖閲岃�缃�劍鐐规墠鏈夌敤
-    CEditUI* pAccountEdit = static_cast<CEditUI*>(m_pm.FindControl(_T("accountedit")));
-    if(pAccountEdit)
-    {
-        pAccountEdit->SetFocus();
-    }
+	//在这里设置焦点才有用
+	CEditUI* pAccountEdit = static_cast<CEditUI*>(m_pm.FindControl(_T("accountedit")));
+	if (pAccountEdit)
+	{
+		//下一个焦点的,就设置为这个控件
+		m_pm.SetFocusNeeded(pAccountEdit);
 
-    return 0;
+		//用户名设置为焦点
+		pAccountEdit->SetFocus();
+
+		//这个干嘛的不知道,但是不加好像不行
+		//m_pm.SetNextTabControl(false);
+	}
+
+	return 0;
 }
 
 LRESULT CLoginWnd::OnNcHitTest(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
@@ -247,80 +254,80 @@ LRESULT CLoginWnd::OnSize(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandle
 
 LRESULT CLoginWnd::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;
+    LRESULT lRes = 0;
+    BOOL bHandled = TRUE;
+    switch(uMsg)
+    {
+    case WM_CREATE:
+        lRes = OnCreate(uMsg, wParam, lParam, bHandled);
+        break;
 	case WM_CLOSE:
 		lRes = OnClose(uMsg, wParam, lParam, bHandled);
 		break;
 	case WM_DESTROY:
 		lRes = OnDestroy(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);
+    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 CLoginWnd::MessageHandler(UINT uMsg, WPARAM wParam, LPARAM lParam, bool& bHandled)
 {
-	if (uMsg == WM_KEYDOWN)
-	{
-		if (wParam == VK_RETURN)
-		{
-			CEditUI* pEdit = static_cast<CEditUI*>(m_pm.FindControl(_T("accountedit")));
-			if (pEdit->GetText().IsEmpty())
-			{
-				pEdit->SetFocus();
-			}
-			else
-			{
-				pEdit = static_cast<CEditUI*>(m_pm.FindControl(_T("pwdedit")));
-				if (pEdit->GetText().IsEmpty())
-				{
-					pEdit->SetFocus();
-				}
-				else
-				{
-					this->HandleLogin();
-				}
-			}
-			return true;
-		}
-		else if (wParam == VK_ESCAPE)
-		{
-			PostQuitMessage(0);
-			return true;
-		}
+    if(uMsg == WM_KEYDOWN)
+    {
+        if(wParam == VK_RETURN)
+        {
+            CEditUI* pEdit = static_cast<CEditUI*>(m_pm.FindControl(_T("accountedit")));
+            if(pEdit->GetText().IsEmpty())
+            {
+                pEdit->SetFocus();
+            }
+            else
+            {
+                pEdit = static_cast<CEditUI*>(m_pm.FindControl(_T("pwdedit")));
+                if(pEdit->GetText().IsEmpty())
+                {
+                    pEdit->SetFocus();
+                }
+                else
+                {
+                    this->HandleLogin();
+                }
+            }
+            return true;
+        }
+        else if(wParam == VK_ESCAPE)
+        {
+            PostQuitMessage(0);
+            return true;
+        }
 
-	}
+    }
 	else if (uMsg == WM_LOGIN_SUCCESS)
 	{
 		LoginSuccess();
@@ -333,7 +340,7 @@ LRESULT CLoginWnd::MessageHandler(UINT uMsg, WPARAM wParam, LPARAM lParam, bool&
 	}
 	else if (uMsg == WM_NEED_UPDATE)
 	{
-		//璇存槑闇€瑕佸崌绾т簡
+		//说明需要升级了
 
 		Update();
 
@@ -346,122 +353,122 @@ LRESULT CLoginWnd::MessageHandler(UINT uMsg, WPARAM wParam, LPARAM lParam, bool&
 		return true;
 	}
 
-	return false;
+    return false;
 }
 
 void CLoginWnd::StartLogin()
 {
-    //隐藏密码输入框,显示进度条
-    CVerticalLayoutUI* pInput = static_cast<CVerticalLayoutUI*>(m_pm.FindControl(_T("login_input")));
-    pInput->SetVisible(false);
+	//隐藏密码输入框,显示进度条
+	CVerticalLayoutUI* pInput = static_cast<CVerticalLayoutUI*>(m_pm.FindControl(_T("login_input")));
+	pInput->SetVisible(false);
 
-    CVerticalLayoutUI* pLoading = static_cast<CVerticalLayoutUI*>(m_pm.FindControl(_T("login_loading")));
-    pLoading->SetVisible(true);
+	CVerticalLayoutUI* pLoading = static_cast<CVerticalLayoutUI*>(m_pm.FindControl(_T("login_loading")));
+	pLoading->SetVisible(true);
 
-    CLabelUI* pLoginResultLabel = static_cast<CLabelUI*>(m_pm.FindControl(_T("loginresult")));
-    pLoginResultLabel->SetVisible(false);
+	CLabelUI* pLoginResultLabel = static_cast<CLabelUI*>(m_pm.FindControl(_T("loginresult")));
+	pLoginResultLabel->SetVisible(false);
 
-    //开启一个线程,开始处理登录
-    std::thread(&CLoginWnd::HandleLogin, this).detach();
+	//开启一个线程,开始处理登录
+	std::thread(&CLoginWnd::HandleLogin, this).detach();
 }
 
 void CLoginWnd::HandleLogin()
 {
 	CLabelUI* pLoginResultLabel = static_cast<CLabelUI*>(m_pm.FindControl(_T("loginresult")));
 
-	//真正登录前,先检测是否有需要更新
-	//std::map<string, string> params;
-
-	//std::string response;
-	//bool ret = CZhipuziHttpClient::Request("/version/getwindowsversion", params, response);
-	//if (!ret)
-	//{
-	//	pLoginResultLabel->SetText(std::wstring(_T("缃戠粶璇锋眰鍑洪敊")).c_str());
-	//	pLoginResultLabel->SetVisible(true);
+	//真正登录前,先检测是否有需要更新
+	std::map<string, string> params;
 
-	//	PostMessage(WM_LOGIN_ERROR);
+	std::string response;
+	bool ret = CLewaimaiHttpClient::Request("/version/getwindowsversion", params, response);
+	if (!ret)
+	{
+		pLoginResultLabel->SetText(std::wstring(_T("网络请求出错")).c_str());
+		pLoginResultLabel->SetVisible(true);
 
-	//	return;
-	//}
+		PostMessage(WM_LOGIN_ERROR);
 
-	//rapidjson::Document document;
-	//document.Parse(response.c_str());
+		return;
+	}
 
-	//if (document.HasParseError())
-	//{
-	//	pLoginResultLabel->SetText(std::wstring(_T("服务器返回数据格式错误")).c_str());
-	//	pLoginResultLabel->SetVisible(true);
+	rapidjson::Document document;
+	document.Parse(response.c_str());
 
-	//	PostMessage(WM_LOGIN_ERROR);
+	if (document.HasParseError())
+	{
+		pLoginResultLabel->SetText(std::wstring(_T("服务器返回数据格式错误")).c_str());
+		pLoginResultLabel->SetVisible(true);
 
-	//	return;
-	//}
-	//else
-	//{
-	//	if (!document.HasMember("errcode") || !document.HasMember("errmsg") || !document.HasMember("data"))
-	//	{
-	//		pLoginResultLabel->SetText(std::wstring(_T("服务器返回数据格式错误")).c_str());
-	//		pLoginResultLabel->SetVisible(true);
+		PostMessage(WM_LOGIN_ERROR);
 
-	//		PostMessage(WM_LOGIN_ERROR);
+		return;
+	}
+	else
+	{
+		if (!document.HasMember("errcode") || !document.HasMember("errmsg") || !document.HasMember("data"))
+		{
+			pLoginResultLabel->SetText(std::wstring(_T("服务器返回数据格式错误")).c_str());
+			pLoginResultLabel->SetVisible(true);
 
-	//		return;
-	//	}
+			PostMessage(WM_LOGIN_ERROR);
 
-	//	rapidjson::Value& v_errcode = document["errcode"];
-	//	int errcode = v_errcode.GetInt();
-	//	if (errcode != 0)
-	//	{
-	//		std::string errmsg = "response failed! message:" + string(document["errmsg"].GetString());
-	//		pLoginResultLabel->SetText(CLewaimaiString::UTF8ToUnicode(errmsg).c_str());
-	//		pLoginResultLabel->SetVisible(true);
+			return;
+		}
 
-	//		PostMessage(WM_LOGIN_ERROR);
+		rapidjson::Value& v_errcode = document["errcode"];
+		int errcode = v_errcode.GetInt();
+		if (errcode != 0)
+		{
+			std::string errmsg = "response failed! message:" + string(document["errmsg"].GetString());
+			pLoginResultLabel->SetText(CLewaimaiString::UTF8ToUnicode(errmsg).c_str());
+			pLoginResultLabel->SetVisible(true);
 
-	//		return;
-	//	}
+			PostMessage(WM_LOGIN_ERROR);
 
-	//	rapidjson::Value& data = document["data"];
+			return;
+		}
 
-	//	std::string newest_version = data["newest_version"].GetString();
-	//	m_update_url = data["url"].GetString();
+		rapidjson::Value& data = document["data"];
 
-	//	if (newest_version > CSystem::GetVersion())
-	//	{
-	//		//璇存槑鏈夋柊鐗堟湰锛岃�鏇存柊
-	//		PostMessage(WM_NEED_UPDATE);
-	//		return;
-	//	}
-	//}
+		std::string newest_version = data["newest_version"].GetString();
+		m_update_url = data["url"].GetString();
 
-	//鍒ゆ柇璐﹀彿瀵嗙爜鏄�惁姝g‘
-	std::wstring account, password;
-	CEditUI* pAccountEdit = static_cast<CEditUI*>(m_pm.FindControl(_T("accountedit")));
-	if (pAccountEdit)
-	{
-		account = pAccountEdit->GetText().GetData();
+		if (newest_version > CSystem::GetVersion())
+		{
+			//说明有新版本,要更新
+			PostMessage(WM_NEED_UPDATE);
+			return;
+		}
 	}
 
-	CEditUI* pPasswordEdit = static_cast<CEditUI*>(m_pm.FindControl(_T("pwdedit")));
-	if (pPasswordEdit)
-	{
-		password = pPasswordEdit->GetText().GetData();
-	}
+    //判断账号密码是否正确
+    std::wstring account, password;
+    CEditUI* pAccountEdit = static_cast<CEditUI*>(m_pm.FindControl(_T("accountedit")));
+    if(pAccountEdit)
+    {
+        account = pAccountEdit->GetText().GetData();
+    }
+
+    CEditUI* pPasswordEdit = static_cast<CEditUI*>(m_pm.FindControl(_T("pwdedit")));
+    if(pPasswordEdit)
+    {
+        password = pPasswordEdit->GetText().GetData();
+    }
 
-	//鎶婄�1涓�腑鏂囧啋鍙锋浛鎹㈡垚鑻辨枃鍐掑彿
-	CLewaimaiString::Replace(account, _T(":"), _T(":"), 1);
+	//把第1个中文冒号替换成英文冒号
+	CLewaimaiString::Replace(account, _T(":"), _T(":"), 1);
 
-	//LOG_INFO("account:" << account.c_str() << ", password:" << password.c_str());
+    //LOG_INFO("account:" << account.c_str() << ", password:" << password.c_str());
 
-	string s_account = CLewaimaiString::UnicodeToUTF8(account);
-	string s_password = CLewaimaiString::UnicodeToUTF8(password);
+    string s_account = CLewaimaiString::UnicodeToUTF8(account);
+    string s_password = CLewaimaiString::UnicodeToUTF8(password);
 
 	CLewaimaiString::trim(s_account);
 	CLewaimaiString::trim(s_password);
 
 	if (s_account.compare("") == 0)
 	{
-		pLoginResultLabel->SetText(std::wstring(_T("用户名不能为空")).c_str());
+		pLoginResultLabel->SetText(std::wstring(_T("用户名不能为空")).c_str());
 		pLoginResultLabel->SetVisible(true);
 
 		PostMessage(WM_LOGIN_ERROR);
@@ -471,7 +478,7 @@ void CLoginWnd::HandleLogin()
 
 	if (s_password.compare("") == 0)
 	{
-		pLoginResultLabel->SetText(std::wstring(_T("瀵嗙爜涓嶈兘涓虹┖")).c_str());
+		pLoginResultLabel->SetText(std::wstring(_T("密码不能为空")).c_str());
 		pLoginResultLabel->SetVisible(true);
 
 		PostMessage(WM_LOGIN_ERROR);
@@ -479,13 +486,13 @@ void CLoginWnd::HandleLogin()
 		return;
 	}
 
-	CZhipuziHttpClient::Init(s_account, s_password);
+    CLewaimaiHttpClient::Init(s_account, s_password);
 
-	std::string errmsg;
-	bool res = CZhipuziHttpClient::Login(errmsg);
+    std::string errmsg;
+    bool res = CLewaimaiHttpClient::Login(errmsg);
 
-	if (res)
-	{
+    if(res)
+    {
 		CCheckBoxUI* pAuto = static_cast<CCheckBoxUI*>(m_pm.FindControl(_T("login_auto_login")));
 		CCheckBoxUI* pRemember = static_cast<CCheckBoxUI*>(m_pm.FindControl(_T("login_remember_password")));
 
@@ -494,7 +501,7 @@ void CLoginWnd::HandleLogin()
 			CSetting::SetParam("setting_is_auto_login", "1", false);
 			CSetting::SetParam("setting_is_remember_password", "1", false);
 
-			//相当于开启自动登录,默认就是开启了记住密码了
+			//相当于开启自动登录,默认就是开启了记住密码了
 			CSetting::SetUser(s_account, s_password, true);
 		}
 		else
@@ -519,57 +526,57 @@ void CLoginWnd::HandleLogin()
 			{
 				CSetting::SetUser(s_account, "", true);
 			}
-		}
+		}		
 
-		//鍦ㄨ繖閲岃�缃�畬鍙傛暟鍚庯紝缁熶竴淇濆瓨鍒版暟鎹�簱
+		//在这里设置完参数后,统一保存到数据库
 		CSetting::SetParam("last_login_username", s_account, true);
 
-		//把用户名和密码保存起来
+		//把用户名和密码保存起来
 		CSetting::SetLoginInfo(s_account, s_password);
 
 		PostMessage(WM_LOGIN_SUCCESS);
 
 		return;
-	}
-	else
-	{
-		//登录失败了
-		CLabelUI* pLoginResultLabel = static_cast<CLabelUI*>(m_pm.FindControl(_T("loginresult")));
-
-		pLoginResultLabel->SetText(std::wstring(_T("登录失败:") + CLewaimaiString::UTF8ToUnicode(errmsg)).c_str());
-		pLoginResultLabel->SetVisible(true);
+    }
+    else
+    {
+        //登录失败了
+		pLoginResultLabel->SetText(std::wstring(_T("登录失败:") + CLewaimaiString::UTF8ToUnicode(errmsg)).c_str());
+        pLoginResultLabel->SetVisible(true);
 
 		PostMessage(WM_LOGIN_ERROR);
-	}
+
+		return;
+    }
 }
 
 void CLoginWnd::LoginSuccess()
 {
-    CMainWnd* pFrame = new CMainWnd();
-    if(pFrame == NULL)
-    {
-        return;
-    }
+	CMainWnd* pFrame = new CMainWnd();
+	if (pFrame == NULL)
+	{
+		return;
+	}
 
-    pFrame->SetIcon(IDI_ICON_DUILIB);
-    pFrame->Create(NULL, _T("智铺子收银软件"), UI_WNDSTYLE_FRAME, 0L, 0, 0, 1024, 768);
-    pFrame->CenterWindow();
+	pFrame->SetIcon(IDI_ICON_DUILIB);
+	pFrame->Create(NULL, _T("乐外卖接单软件"), UI_WNDSTYLE_FRAME, 0L, 0, 0, 1024, 768);
+	pFrame->CenterWindow();
 
-    ::ShowWindow(*pFrame, SW_SHOWMAXIMIZED);
+	::ShowWindow(*pFrame, SW_SHOWMAXIMIZED);
 
-    Close();
+	Close();
 }
 
 void CLoginWnd::LoginError()
 {
-    CVerticalLayoutUI* pInput = static_cast<CVerticalLayoutUI*>(m_pm.FindControl(_T("login_input")));
-    pInput->SetVisible(true);
+	CVerticalLayoutUI* pInput = static_cast<CVerticalLayoutUI*>(m_pm.FindControl(_T("login_input")));
+	pInput->SetVisible(true);
 
-    CVerticalLayoutUI* pLoading = static_cast<CVerticalLayoutUI*>(m_pm.FindControl(_T("login_loading")));
-    pLoading->SetVisible(false);
+	CVerticalLayoutUI* pLoading = static_cast<CVerticalLayoutUI*>(m_pm.FindControl(_T("login_loading")));
+	pLoading->SetVisible(false);
 
-    CLabelUI* pLoginResultLabel = static_cast<CLabelUI*>(m_pm.FindControl(_T("loginresult")));
-    pLoginResultLabel->SetVisible(true);
+	CLabelUI* pLoginResultLabel = static_cast<CLabelUI*>(m_pm.FindControl(_T("loginresult")));
+	pLoginResultLabel->SetVisible(true);
 }
 
 void CLoginWnd::Update()
@@ -588,7 +595,7 @@ void CLoginWnd::Update()
 	pFrame->InitData(url, filename);
 
 	pFrame->SetIcon(IDI_ICON_DUILIB);
-	pFrame->Create(NULL, _T("鑷�姩鏇存柊"), UI_WNDSTYLE_DIALOG, 0, 0, 0, 0, 0, NULL);
+	pFrame->Create(NULL, _T("自动更新"), UI_WNDSTYLE_DIALOG, 0, 0, 0, 0, 0, NULL);
 	pFrame->CenterWindow();
 
 	::ShowWindow(*pFrame, SW_SHOWNORMAL);
@@ -598,12 +605,10 @@ void CLoginWnd::Update()
 
 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();
+	//这种模式是本人强制挤下线了
+	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();
 }
-
-

+ 27 - 25
zhipuzi_pos_windows/wnd/CLoginWnd.h

@@ -23,57 +23,59 @@ public:
 
     void OnFinalMessage(HWND /*hWnd*/)
     {
-        //m_pm.RemovePreMessageFilter(this);
+        m_pm.RemovePreMessageFilter(this);
         delete this;
     };
 
-    void Init();
+	void Init();
 
-    void SetMode(int mode)
-    {
-        m_mode = mode;
-    }
+	void SetMode(int mode)
+	{
+		m_mode = mode;
+	}
 
-    void Notify(TNotifyUI& msg);
+	void Notify(TNotifyUI& msg);
 
-    LRESULT OnCreate(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
+	LRESULT OnCreate(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
 
-    LRESULT OnClose(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
+	LRESULT OnClose(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
 
-    LRESULT OnDestroy(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
+	LRESULT OnDestroy(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
 
-    LRESULT OnNcActivate(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
+	LRESULT OnNcActivate(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
 
-    LRESULT OnNcCalcSize(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
+	LRESULT OnNcCalcSize(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
 
-    LRESULT OnNcPaint(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
+	LRESULT OnNcPaint(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
 
-    LRESULT OnNcHitTest(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
+	LRESULT OnNcHitTest(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
 
-    LRESULT OnSize(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 HandleMessage(UINT uMsg, WPARAM wParam, LPARAM lParam);
 
-    LRESULT MessageHandler(UINT uMsg, WPARAM wParam, LPARAM lParam, bool& bHandled);
+	LRESULT MessageHandler(UINT uMsg, WPARAM wParam, LPARAM lParam, bool& bHandled);
 
-    void StartLogin();
+	void StartLogin();
 
     void HandleLogin();
 
-    void LoginSuccess();
+	void LoginSuccess();
 
-    void LoginError();
+	void LoginError();
 
-    void Update();
+	void Update();
 
-    void ShowLoginAgainOut();
+	void ShowLoginAgainOut();
 
 public:
     CPaintManagerUI m_pm;
 
-    std::string m_update_url;
+	std::string m_update_url;
+
+	//模式1:正常的展示登录页面 2:被人挤下线的
+	int m_mode = 1;
 
-    //模式1:正常的展示登录页面 2:被人挤下线的
-    int m_mode = 1;
+	bool m_is_login_ing = false;
 };
 

Разница между файлами не показана из-за своего большого размера
+ 270 - 212
zhipuzi_pos_windows/wnd/CMainWnd.cpp


+ 7 - 4
zhipuzi_pos_windows/wnd/CMainWnd.h

@@ -8,7 +8,7 @@
 
 class CMessagePush;
 
-class CMainWnd : public CWindowWnd, public INotifyUI
+class CMainWnd : public CWindowWnd, public INotifyUI, public IMessageFilterUI
 {
 public:
     CMainWnd() { };
@@ -25,6 +25,7 @@ public:
 
     void OnFinalMessage(HWND /*hWnd*/)
     {
+		m_pm.RemovePreMessageFilter(this);
         delete this;
     };
 
@@ -65,9 +66,11 @@ public:
 
     LRESULT HandleMessage(UINT uMsg, WPARAM wParam, LPARAM lParam);
 
-    LRESULT OnOrderlistRefresh(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
+	LRESULT MessageHandler(UINT uMsg, WPARAM wParam, LPARAM lParam, bool& bHandled);
 
-    LRESULT OnLoginOut(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
+	LRESULT OnOrderlistRefresh(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
+
+	LRESULT OnLoginOut(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
 
     //添加托盘图标(初始化)
     void AddTrayIcon();
@@ -75,7 +78,7 @@ public:
     //处理托盘图标上的事件
     LRESULT OnTrayIcon(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
 
-    void LoginOut(int mode);
+	void LoginOut(int mode);
 
 public:
     CPaintManagerUI m_pm;

+ 77 - 77
zhipuzi_pos_windows/wnd/CMessageboxWnd.cpp

@@ -3,99 +3,99 @@
 
 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);
+	POINT pt;
+	pt.x = GET_X_LPARAM(lParam);
+	pt.y = GET_Y_LPARAM(lParam);
+	::ScreenToClient(*this, &pt);
 
-    RECT rcClient;
-    ::GetClientRect(*this, &rcClient);
+	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;
-        }
-    }
+	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;
+	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);
-    }
+	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;
+	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 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;
+	if (uMsg == WM_KEYDOWN)
+	{
+		if (wParam == VK_RETURN)
+		{
+			return true;
+		}
+		else if (wParam == VK_ESCAPE)
+		{
+			return true;
+		}
+	}
+	return false;
 }
 
 

+ 68 - 68
zhipuzi_pos_windows/wnd/CMessageboxWnd.h

@@ -6,98 +6,98 @@
 class CMessageboxWnd : public CWindowWnd, public INotifyUI, public IMessageFilterUI
 {
 public:
-    LPCTSTR GetWindowClassName() const
-    {
-        return _T("UIMessageboxFrame");
-    };
+	LPCTSTR GetWindowClassName() const
+	{
+		return _T("UIMessageboxFrame");
+	};
 
-    UINT GetClassStyle() const
-    {
-        return UI_CLASSSTYLE_DIALOG;
-    };
+	UINT GetClassStyle() const
+	{
+		return UI_CLASSSTYLE_DIALOG;
+	};
 
-    void OnFinalMessage(HWND /*hWnd*/)
-    {
-        //WindowImplBase::OnFinalMessage(hWnd);
-        m_pm.RemovePreMessageFilter(this);
+	void OnFinalMessage(HWND /*hWnd*/)
+	{
+		//WindowImplBase::OnFinalMessage(hWnd);
+		m_pm.RemovePreMessageFilter(this);
 
-        //delete this;
-    };
+		//delete this;
+	};
 
-    void Init()
-    {
+	void Init()
+	{
 
-    }
+	}
 
-    void Notify(TNotifyUI& msg)
-    {
-        if(msg.sType == _T("click"))
-        {
-            DuiLib::CDuiString senderName = msg.pSender->GetName();
+	void Notify(TNotifyUI& msg)
+	{
+		if (msg.sType == _T("click"))
+		{
+			DuiLib::CDuiString senderName = msg.pSender->GetName();
 
-            if(senderName == _T("messagebox_dlg_closebtn"))
-            {
-                Close(IDCANCEL);
-                return;
-            }
-        }
-    }
+			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);
+	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.Init(m_hWnd);
 
-        m_pm.AddPreMessageFilter(this);
+		m_pm.AddPreMessageFilter(this);
 
-        CDialogBuilder builder;
+		CDialogBuilder builder;
 
-        CControlUI* pRoot = builder.Create(_T("messagebox_dlg.xml"), (UINT)0, NULL, &m_pm);
-        ASSERT(pRoot && "Failed to parse XML");
+		CControlUI* pRoot = builder.Create(_T("messagebox_dlg.xml"), (UINT)0, NULL, &m_pm);
+		ASSERT(pRoot && "Failed to parse XML");
 
-        // 把这些控件绘制到本窗口上
-        m_pm.AttachDialog(pRoot);
+		// 把这些控件绘制到本窗口上
+		m_pm.AttachDialog(pRoot);
 
-        // 把自己加入到CPaintManagerUI的m_aNotifiers数组中,用于处理Notify函数
-        m_pm.AddNotifier(this);
+		// 把自己加入到CPaintManagerUI的m_aNotifiers数组中,用于处理Notify函数
+		m_pm.AddNotifier(this);
 
-        Init();
+		Init();
 
-        return 0;
-    }
+		return 0;
+	}
 
-    LRESULT OnNcActivate(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
-    {
-        if(::IsIconic(*this))
-        {
-            bHandled = FALSE;
-        }
-        return (wParam == 0) ? TRUE : FALSE;
-    }
+	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 OnNcCalcSize(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
+	{
+		return 0;
+	}
 
-    LRESULT OnNcPaint(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 OnNcHitTest(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
 
-    LRESULT OnSize(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 HandleMessage(UINT uMsg, WPARAM wParam, LPARAM lParam);
 
-    LRESULT MessageHandler(UINT uMsg, WPARAM wParam, LPARAM lParam, bool& bHandled);
+	LRESULT MessageHandler(UINT uMsg, WPARAM wParam, LPARAM lParam, bool& bHandled);
 
 public:
-    CPaintManagerUI m_pm;
+	CPaintManagerUI m_pm;
 };
 

+ 58 - 57
zhipuzi_pos_windows/wnd/CUpdateWnd.cpp

@@ -203,9 +203,9 @@ LRESULT CUpdateWnd::HandleMessage(UINT uMsg, WPARAM wParam, LPARAM lParam)
     case WM_UPDATEPROGRESS:
         lRes = OnRefresh(uMsg, wParam, lParam, bHandled);
         break;
-    case  WM_DOWNLOAD_FINISH:
-        lRes = OnDownloadFinish(uMsg, wParam, lParam, bHandled);
-        break;
+	case  WM_DOWNLOAD_FINISH:
+		lRes = OnDownloadFinish(uMsg, wParam, lParam, bHandled);
+		break;
     default:
         bHandled = FALSE;
     }
@@ -230,29 +230,29 @@ LRESULT CUpdateWnd::MessageHandler(UINT uMsg, WPARAM wParam, LPARAM lParam, bool
 
 std::string CUpdateWnd::GetFileNameFormUrl(std::string url)
 {
-    char fileName[512] = { 0 };
-
-    int urlLen = strlen(url.c_str());
-    char mUrl[512] = { 0 };
-    char fName[256] = { 0 };
-    strcpy(mUrl, url.c_str());
-    int cutIndex = 0;
-    int i = urlLen - 1, j = 0;
-    while(mUrl[--i] != '/');
-    i++;
-    while(mUrl[i] != '\0' && mUrl[i] != '?' && mUrl[i] != '&')
-    {
-        fName[j++] = mUrl[i++];
-    }
-    fName[j] = '\0';
-    strcpy(fileName, fName);
-
-    return fileName;
+	char fileName[512] = { 0 };
+
+	int urlLen = strlen(url.c_str());
+	char mUrl[512] = { 0 };
+	char fName[256] = { 0 };
+	strcpy(mUrl, url.c_str());
+	int cutIndex = 0;
+	int i = urlLen - 1, j = 0;
+	while (mUrl[--i] != '/');
+	i++;
+	while (mUrl[i] != '\0' && mUrl[i] != '?' &&mUrl[i] != '&')
+	{
+		fName[j++] = mUrl[i++];
+	}
+	fName[j] = '\0';
+	strcpy(fileName, fName);
+
+	return fileName;
 }
 
 double CUpdateWnd::getDownloadFileLength(std::string url)
 {
-    CURL* easy_handle = NULL;
+    CURL *easy_handle = NULL;
     int ret = CURLE_OK;
     double size = -1;
 
@@ -268,12 +268,12 @@ double CUpdateWnd::getDownloadFileLength(std::string url)
         // Only get the header data
         ret = curl_easy_setopt(easy_handle, CURLOPT_URL, url.c_str());
 
-        if(url.find("https://") == 0)
-        {
-            ret |= curl_easy_setopt(easy_handle, CURLOPT_SSL_VERIFYPEER, false);
-            ret |= curl_easy_setopt(easy_handle, CURLOPT_SSL_VERIFYHOST, false);
-        }
-
+		if (url.find("https://") == 0)
+		{
+			ret |= curl_easy_setopt(easy_handle, CURLOPT_SSL_VERIFYPEER, false);
+			ret |= curl_easy_setopt(easy_handle, CURLOPT_SSL_VERIFYHOST, false);
+		}
+		
         ret |= curl_easy_setopt(easy_handle, CURLOPT_HEADER, 1L);
         ret |= curl_easy_setopt(easy_handle, CURLOPT_NOBODY, 1L);
         ret |= curl_easy_setopt(easy_handle, CURLOPT_WRITEFUNCTION, nousecb);    // libcurl_a.lib will return error code 23 without this sentence on windows
@@ -302,7 +302,8 @@ double CUpdateWnd::getDownloadFileLength(std::string url)
             break;
         }
 
-    } while(0);
+    }
+    while(0);
 
     curl_easy_cleanup(easy_handle);
 
@@ -311,7 +312,7 @@ double CUpdateWnd::getDownloadFileLength(std::string url)
 
 void CUpdateWnd::Run()
 {
-    m_filepath = m_dir + GetFileNameFormUrl(m_url);
+	m_filepath = m_dir + GetFileNameFormUrl(m_url);
 
     CURLcode res;
 
@@ -333,12 +334,12 @@ void CUpdateWnd::Run()
 
         curl_easy_setopt(m_curl, CURLOPT_URL, m_url.c_str());//在此要注意,此url必须是多字节
 
-        if(m_url.find("https://") == 0)
-        {
-            curl_easy_setopt(m_curl, CURLOPT_SSL_VERIFYPEER, false);
-            curl_easy_setopt(m_curl, CURLOPT_SSL_VERIFYHOST, false);
-        }
-
+		if (m_url.find("https://") == 0)
+		{
+			curl_easy_setopt(m_curl, CURLOPT_SSL_VERIFYPEER, false);
+			curl_easy_setopt(m_curl, CURLOPT_SSL_VERIFYHOST, false);
+		}
+		
         curl_easy_setopt(m_curl, CURLOPT_TIMEOUT, 0);
         curl_easy_setopt(m_curl, CURLOPT_WRITEDATA, m_outfile);
         curl_easy_setopt(m_curl, CURLOPT_WRITEFUNCTION, my_write_func);
@@ -353,15 +354,15 @@ void CUpdateWnd::Run()
         curl_easy_cleanup(m_curl);
     }
 
-    //走到这里,下载完成了
-    HWND hWnd = FindWindow(NULL, L"自动更新");
+	//走到这里,下载完成了
+	HWND hWnd = FindWindow(NULL, L"自动更新");
 
-    if(hWnd)
-    {
-        ::PostMessage(hWnd, WM_DOWNLOAD_FINISH, 0, 0);
-    }
+	if (hWnd)
+	{
+		::PostMessage(hWnd, WM_DOWNLOAD_FINISH, 0, 0);
+	}
 }
-size_t CUpdateWnd::my_write_func(void* ptr, size_t size, size_t nmemb, FILE* stream)
+size_t CUpdateWnd::my_write_func(void *ptr, size_t size, size_t nmemb, FILE *stream)
 {
     size_t nWrite = fwrite(ptr, size, nmemb, stream);
 
@@ -376,20 +377,20 @@ size_t CUpdateWnd::my_write_func(void* ptr, size_t size, size_t nmemb, FILE* str
     }
 }
 
-int CUpdateWnd::my_progress_func(void* progress_data,
+int CUpdateWnd::my_progress_func(void *progress_data,
                                  double t, /* dltotal */
                                  double d, /* dlnow */
                                  double ultotal,
                                  double ulnow)
 {
-    if(t > 0)
-    {
-        CUpdateWnd::m_Percent = d * 100.0 / t;
-    }
-    else
-    {
-        CUpdateWnd::m_Percent = 0;
-    }
+	if (t > 0)
+	{
+		CUpdateWnd::m_Percent = d * 100.0 / t;
+	}
+	else
+	{
+		CUpdateWnd::m_Percent = 0;
+	}
 
     HWND hWnd = FindWindow(NULL, L"自动更新");
 
@@ -401,7 +402,7 @@ int CUpdateWnd::my_progress_func(void* progress_data,
     return 0;
 }
 
-size_t CUpdateWnd::nousecb(char* buffer, size_t x, size_t y, void* userdata)
+size_t CUpdateWnd::nousecb(char *buffer, size_t x, size_t y, void *userdata)
 {
     (void)buffer;
     (void)userdata;
@@ -422,9 +423,9 @@ LRESULT CUpdateWnd::OnRefresh(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHa
 
 LRESULT CUpdateWnd::OnDownloadFinish(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
 {
-    HINSTANCE hNewExe = ShellExecuteA(NULL, "open", m_filepath.c_str(), NULL, NULL, SW_SHOW);
+	HINSTANCE hNewExe = ShellExecuteA(NULL, "open", m_filepath.c_str(), NULL, NULL, SW_SHOW);
 
-    PostQuitMessage(0);
+	PostQuitMessage(0);
 
-    return 0;
-}
+	return 0;
+}

+ 17 - 17
zhipuzi_pos_windows/wnd/CUpdateWnd.h

@@ -20,15 +20,15 @@ public:
 
     void OnFinalMessage(HWND /*hWnd*/)
     {
-        //m_pm.RemovePreMessageFilter(this);
+        m_pm.RemovePreMessageFilter(this);
         delete this;
     };
 
-    void InitData(std::string url, std::string dir)
-    {
-        m_url = url;
-        m_dir = dir;
-    }
+	void InitData(std::string url, std::string dir)
+	{
+		m_url = url;
+		m_dir = dir;
+	}
 
     void Init();
 
@@ -56,30 +56,30 @@ public:
 
     LRESULT OnRefresh(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
 
-    LRESULT OnDownloadFinish(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
+	LRESULT OnDownloadFinish(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
 
-    std::string GetFileNameFormUrl(std::string url);
+	std::string GetFileNameFormUrl(std::string url);
 
-    static size_t nousecb(char* buffer, size_t x, size_t y, void* userdata);
+	static size_t nousecb(char *buffer, size_t x, size_t y, void *userdata);
 
     double getDownloadFileLength(std::string url);
 
     void Run();
 
-    static size_t my_write_func(void* ptr, size_t size, size_t nmemb, FILE* stream);
+    static size_t my_write_func(void *ptr, size_t size, size_t nmemb, FILE *stream);
 
-    static int my_progress_func(void* progress_data,
-                                double t, /* dltotal */
-                                double d, /* dlnow */
-                                double ultotal,
-                                double ulnow);
+    static int my_progress_func(void *progress_data,
+                         double t, /* dltotal */
+                         double d, /* dlnow */
+                         double ultotal,
+                         double ulnow);
 public:
     CPaintManagerUI m_pm;
 
     string m_dir;//目录名
-    std::string m_filepath; //完成文件在本地的路径名
+	std::string m_filepath; //完成文件在本地的路径名
 
-    CURL* m_curl;//libcurl句柄
+	CURL* m_curl;//libcurl句柄
 
     double m_downloadFileLength;//服务器文件长度
 

+ 77 - 77
zhipuzi_pos_windows/wnd/CWaimaiOrderFailReasonWnd.cpp

@@ -3,99 +3,99 @@
 
 LRESULT CWaimaiOrderFailReasonWnd::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);
+	POINT pt;
+	pt.x = GET_X_LPARAM(lParam);
+	pt.y = GET_Y_LPARAM(lParam);
+	::ScreenToClient(*this, &pt);
 
-    RECT rcClient;
-    ::GetClientRect(*this, &rcClient);
+	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;
-        }
-    }
+	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;
+	return HTCLIENT;
 }
 
 LRESULT CWaimaiOrderFailReasonWnd::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);
-    }
+	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;
+	bHandled = FALSE;
+	return 0;
 }
 
 LRESULT CWaimaiOrderFailReasonWnd::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 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 CWaimaiOrderFailReasonWnd::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;
+	if (uMsg == WM_KEYDOWN)
+	{
+		if (wParam == VK_RETURN)
+		{
+			return true;
+		}
+		else if (wParam == VK_ESCAPE)
+		{
+			return true;
+		}
+	}
+	return false;
 }
 
 

+ 107 - 107
zhipuzi_pos_windows/wnd/CWaimaiOrderFailReasonWnd.h

@@ -6,116 +6,116 @@
 class CWaimaiOrderFailReasonWnd : public CWindowWnd, public INotifyUI, public IMessageFilterUI
 {
 public:
-    LPCTSTR GetWindowClassName() const
-    {
-        return _T("UIWaimaiOrderFailFrame");
-    };
+	LPCTSTR GetWindowClassName() const
+	{
+		return _T("UIWaimaiOrderFailFrame");
+	};
+
+	UINT GetClassStyle() const
+	{
+		return UI_CLASSSTYLE_DIALOG;
+	};
+
+	void OnFinalMessage(HWND /*hWnd*/)
+	{
+		//WindowImplBase::OnFinalMessage(hWnd);
+		m_pm.RemovePreMessageFilter(this);
+		
+		//delete this;
+	};
+
+	void Init()
+	{
+		
+	}
+
+	std::string getReason()
+	{
+		return m_reason;
+	}
+
+	void Notify(TNotifyUI& msg)
+	{
+		if (msg.sType == _T("click"))
+		{
+			DuiLib::CDuiString senderName = msg.pSender->GetName();
+
+			if (senderName == _T("waimai_order_fail_dlg_closebtn"))
+			{
+				Close(IDCANCEL);
+				return;
+			}
+			else if (senderName == _T("waimai_order_fail_dlg_save"))
+			{
+				//开始保存厨房打印机的数据
+				CEditUI* pReason = static_cast<CEditUI*>(m_pm.FindControl(_T("waimai_order_fail_dlg_reason")));
+				wstring wsReason = pReason->GetText();
+
+				m_reason = CLewaimaiString::UnicodeToUTF8(wsReason);
+
+				Close(IDOK);
+				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("waimai_order_fail_reason_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);
 
-    UINT GetClassStyle() const
-    {
-        return UI_CLASSSTYLE_DIALOG;
-    };
-
-    void OnFinalMessage(HWND /*hWnd*/)
-    {
-        //WindowImplBase::OnFinalMessage(hWnd);
-        m_pm.RemovePreMessageFilter(this);
-
-        //delete this;
-    };
-
-    void Init()
-    {
-
-    }
-
-    std::string getReason()
-    {
-        return m_reason;
-    }
-
-    void Notify(TNotifyUI& msg)
-    {
-        if(msg.sType == _T("click"))
-        {
-            DuiLib::CDuiString senderName = msg.pSender->GetName();
-
-            if(senderName == _T("waimai_order_fail_dlg_closebtn"))
-            {
-                Close(IDCANCEL);
-                return;
-            }
-            else if(senderName == _T("waimai_order_fail_dlg_save"))
-            {
-                //开始保存厨房打印机的数据
-                CEditUI* pReason = static_cast<CEditUI*>(m_pm.FindControl(_T("waimai_order_fail_dlg_reason")));
-                wstring wsReason = pReason->GetText();
-
-                m_reason = CLewaimaiString::UnicodeToUTF8(wsReason);
-
-                Close(IDOK);
-                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("waimai_order_fail_reason_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);
+	LRESULT MessageHandler(UINT uMsg, WPARAM wParam, LPARAM lParam, bool& bHandled);
 
 public:
-    CPaintManagerUI m_pm;
+	CPaintManagerUI m_pm;
 
-    std::string m_reason;
+	std::string m_reason;
 };
 

+ 3 - 2
zhipuzi_pos_windows/zhipuzi_pos_windows.cpp

@@ -25,7 +25,7 @@ int APIENTRY wWinMain(_In_ HINSTANCE hInstance,
 	CPaintManagerUI::SetResourcePath(CPaintManagerUI::GetInstancePath() + _T("skin"));
 	CPaintManagerUI::SetResourceZip(_T("skin.zpz"));
 #else
-	CPaintManagerUI::SetResourcePath(CPaintManagerUI::GetInstancePath() + _T("skin"));
+    CPaintManagerUI::SetResourcePath(CPaintManagerUI::GetInstancePath() + _T("skin"));
 #endif
 
     HRESULT Hr = ::CoInitialize(NULL);
@@ -44,7 +44,8 @@ int APIENTRY wWinMain(_In_ HINSTANCE hInstance,
     pLogin->Create(NULL, _T("智铺子收银软件登录"), UI_WNDSTYLE_DIALOG, 0, 0, 0, 0, 0, NULL);
     pLogin->SetIcon(IDI_ICON_DUILIB);
     pLogin->CenterWindow();
-    pLogin->ShowModal();
+
+	pLogin->ShowWindow(true);
 
     CPaintManagerUI::MessageLoop();