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

同步最新智铺子收银软件的代码

zhangyang 6 лет назад
Родитель
Сommit
1820280b64

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


+ 21 - 0
bin/Win32/Debug/zhipuzi_pos_windows/skin/setting.xml

@@ -51,6 +51,27 @@
 							<ListLabelElement text="4联" />
 						</Combo>
 					</HorizontalLayout>
+					<HorizontalLayout height="44">
+						<Label text="打印机接口类型" width="260"/>
+						<Combo name="setting_printer_leixing" padding="0,9,0,0" width="140" height="26" tooltip="请点击这里选择您的打印机接口类型" normalimage="file='Setting_Combox_Normal.png' corner='2,2,24,2'" hotimage="file='Setting_Combox_Hover.png' corner='2,2,24,2'" pushedimage="Setting_Combox_Click.png' corner='2,2,24,2'" textpadding="10,1,1,1" >
+							<ListLabelElement text="智能识别模式" selected="true" />
+							<ListLabelElement text="usb" />
+							<ListLabelElement text="并口" />
+							<ListLabelElement text="串口" />
+							<ListLabelElement text="网口" />
+						</Combo>
+					</HorizontalLayout>
+					<HorizontalLayout height="44" name="setting_printer_usb_layout">
+						<Label text="usb打印设备选择" width="260"/>
+						<Combo name="setting_printer_usb" padding="0,9,0,0" width="800" height="26" tooltip="请点击这里选择您的打印机接口类型" normalimage="file='Setting_Combox_Normal.png' corner='2,2,24,2'" hotimage="file='Setting_Combox_Hover.png' corner='2,2,24,2'" pushedimage="Setting_Combox_Click.png' corner='2,2,24,2'" textpadding="10,1,1,1" >
+						</Combo>
+					</HorizontalLayout>
+					<HorizontalLayout height="56" name="setting_printer_wangkou_layout">
+						<Label text="网口IP地址" width="260"/>
+						<Edit name="setting_printer_wangkou_ip" width="200" height="32" padding="0,12,0,12" normalimage="file='Chat_InputBox_BG.png' corner='4,4,4,4'" hotimage="file='Chat_InputBox_BG_Hover.png' corner='4,4,4,4'" />
+
+						<Button name="setting_printer_wangkouk_save_btn" align="center" width="100" height="38" padding="20,8,0,3" text="保存" normalimage="file='Btn_White.png' corner='5,5,5,5'" hotimage="file='Btn_White_Hover.png' corner='5,5,5,5'" pushedimage="file='Btn_White_Click.png' corner='5,5,5,5'" />
+					</HorizontalLayout>
 					<HorizontalLayout height="44" padding="0,20,0,0">
 						<Label text="小票格式设置" width="260" />
 					</HorizontalLayout>

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


+ 1 - 1
zhipuzi_pos_windows/control/OrderListUI.cpp

@@ -68,7 +68,7 @@ void OrderListUI::HandleRefresh(OrderListStatus* status)
 	params["page"] = to_string(status->m_page);
 	std::string response;
 
-	CZhipuziHttpClient::RequestOld(url.c_str(), params, response);
+	CZhipuziHttpClient::Request(url.c_str(), params, response);
 
 	//走到这里,网络请求结束了,对比状态是否发生了改变
 	if (status->m_page != m_page || status->m_status != m_status)

+ 175 - 151
zhipuzi_pos_windows/network/CHttpClient.cpp

@@ -4,7 +4,7 @@
 #include <curl/curl.h>
 
 CHttpClient::CHttpClient(void) :
-    m_bDebug(false)
+	m_bDebug(false)
 {
 
 }
@@ -14,180 +14,204 @@ CHttpClient::~CHttpClient(void)
 
 }
 
-static int OnDebug(CURL*, curl_infotype itype, char* pData, size_t size, 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);
-    if(NULL == str || NULL == buffer)
-    {
-        return -1;
-    }
-
-    char* pData = (char*)buffer;
-    str->append(pData, size * nmemb);
-    return nmemb;
+	std::string* str = dynamic_cast<std::string*>((std::string *)lpVoid);
+
+	if (NULL == str || NULL == buffer)
+	{
+		return -1;
+	}
+
+	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)
+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)
+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;
 }
 
 /*
  *返回值说明 https://blog.csdn.net/u011857683/article/details/53069268
  **/
-int CHttpClient::Posts(const std::string& strUrl, const std::string& strPost, std::string& strResponse, const char* pCaPath)
+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);
-    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)
+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;
 };
 

+ 75 - 58
zhipuzi_pos_windows/network/CZhipuziHttpClient.cpp

@@ -27,7 +27,7 @@ bool CZhipuziHttpClient::Login(std::string& errmsg)
     std::map<string, string> params;
 
     std::string response;
-    bool ret = m_client.RequestNew("/login/login", params, response);
+    bool ret = m_client.RequestPingtai("/userlogin/userlogin", params, response);
 
     if(!ret)
     {
@@ -52,7 +52,7 @@ bool CZhipuziHttpClient::Login(std::string& errmsg)
     {
         rapidjson::Value& v_errcode = document["errcode"];
         int errcode = v_errcode.GetInt();
-        if(errcode == -1)
+        if(errcode == -1 || errcode < 0)
         {
             LOG_INFO("login failed! message:" << document["errmsg"].GetString());
             errmsg = std::string(document["errmsg"].GetString());
@@ -71,22 +71,38 @@ bool CZhipuziHttpClient::Login(std::string& errmsg)
         }
     }
 
+	rapidjson::Value& v_data = document["data"];
+
+	rapidjson::Value& v_version_type = v_data["version_type"];
+	m_client.m_version_type = v_version_type.GetString();
+
+	if (m_client.m_version_type == "1")
+	{
+		m_client.m_yewu_ur = "https://cyapi.zhipuzi.com/pos";
+	}
+	else
+	{
+		m_client.m_yewu_ur = "https://lsapi.zhipuzi.com/pos";
+	}
+
+	rapidjson::Value& v_lwm_sess_token = v_data["lwm_sess_token"];
+	m_client.lwm_sess_token = v_lwm_sess_token.GetString();
+
     LOG_INFO("login success!");
 
     return true;
 }
 
-bool CZhipuziHttpClient::RequestOld(std::string url, std::map<string, string> params, std::string& response)
+bool CZhipuziHttpClient::Request(std::string url, std::map<string, string> params, std::string& response)
 {
     std::string timestamp = to_string(time(NULL));
     std::string nonce = "123456";
 
     //先添加默认参数,用于计算签名
-    params["machinecode"] = m_client.m_machinecode;
     params["username"] = m_client.m_username;
     params["nonce"] = nonce;
     params["timestamp"] = timestamp;
-    params["url"] = m_client.m_old_url + url;
+    params["url"] = m_client.m_yewu_ur + url;
 
     //计算签名
     std::string postString;
@@ -135,7 +151,7 @@ bool CZhipuziHttpClient::RequestOld(std::string url, std::map<string, string> pa
     LOG_INFO("postString:" << postString.c_str());
 
     CHttpClient m_httpClient;
-    int ret = m_httpClient.Posts(m_client.m_old_url + url, postString, response, NULL);
+    int ret = m_httpClient.Posts(m_client.m_yewu_ur + url, postString, response, NULL);
 
     LOG_INFO("response:" << response.c_str());
 
@@ -148,74 +164,75 @@ bool CZhipuziHttpClient::RequestOld(std::string url, std::map<string, string> pa
     return false;
 }
 
-bool CZhipuziHttpClient::RequestNew(std::string url, std::map<string, string> params, std::string& response)
+bool CZhipuziHttpClient::RequestPingtai(std::string url, std::map<string, string> params, std::string& response)
 {
-    std::string timestamp = to_string(time(NULL));
-    std::string nonce = "123456";
+	std::string timestamp = to_string(time(NULL));
+	std::string nonce = "123456";
 
-    std::string lwm_appid = "84b19199fd221a78c491cd553cbb4ab7";
-    std::string open_secret = "#repast!@#AfAS#@!";
+	//先添加默认参数,用于计算签名
+	params["username"] = m_client.m_username;
+	params["nonce"] = nonce;
+	params["timestamp"] = timestamp;
+	params["url"] = m_client.m_pingtai_url + url;
 
-    //先添加默认参数,用于计算签名
-    params["machinecode"] = m_client.m_machinecode;
-    params["username"] = CLewaimaiString::UrlEncode(m_client.m_username);
-    params["password"] = md5(m_client.m_password);
-    params["lwm_appid"] = "84b19199fd221a78c491cd553cbb4ab7";
-    params["nonce"] = nonce;
-    params["timestamp"] = timestamp;
+	params["timestamp"] = "1564301876";
 
-    //计算签名
-    std::string postString;
-    for(std::map<string, string>::iterator it = params.begin(); it != params.end();)
-    {
-        postString += it->first + "=" + it->second;
+	//计算签名
+	std::string postString;
+	for (std::map<string, string>::iterator it = params.begin(); it != params.end();)
+	{
+		postString += it->first + "=" + it->second;
 
-        it++;
+		it++;
 
-        if(it != params.end())
-        {
-            postString += "&";
-        }
-    }
+		if (it != params.end())
+		{
+			postString += "&";
+		}
+	}
 
-    LOG_INFO("postString:" << postString.c_str());
+	LOG_INFO("postString:" << postString.c_str());
 
-    //用于计算签名的临时变量
-    string tmp = md5(postString);
-    tmp += open_secret;
+	//用于计算签名的临时变量
+	std::string password = md5(m_client.m_password);
+	transform(password.begin(), password.end(), password.begin(), ::toupper);
 
-    std::string sign = md5(tmp);
-    transform(sign.begin(), sign.end(), sign.begin(), ::toupper);
-    LOG_INFO("sign:" << sign.c_str());
+	string tmp = postString + password;
 
-    //加上签名,去掉url,计算post
-    params["sign"] = sign;
+	std::string sign = md5(tmp);
+	transform(sign.begin(), sign.end(), sign.begin(), ::toupper);
+	LOG_INFO("sign:" << sign.c_str());
 
-    postString = "";
-    for(std::map<string, string>::iterator it = params.begin(); it != params.end();)
-    {
-        postString += it->first + "=" + it->second;
+	//加上签名,去掉url,计算post
+	params["sign"] = sign;
+	params.erase("url");
 
-        it++;
+	//未签名之前,不能进行urlencode,签名完成之后可以(params的value必须为utf8格式)
+	postString = "";
+	for (std::map<string, string>::iterator it = params.begin(); it != params.end();)
+	{
+		postString += it->first + "=" + CLewaimaiString::UrlEncode(it->second);
 
-        if(it != params.end())
-        {
-            postString += "&";
-        }
-    }
+		it++;
 
-    LOG_INFO("postString:" << postString.c_str());
+		if (it != params.end())
+		{
+			postString += "&";
+		}
+	}
 
-    CHttpClient m_httpClient;
-    int ret = m_httpClient.Posts(m_client.m_new_url + url, postString, response, NULL);
+	LOG_INFO("postString:" << postString.c_str());
 
-    LOG_INFO("response:" << response.c_str());
+	CHttpClient m_httpClient;
+	int ret = m_httpClient.Posts(m_client.m_pingtai_url + url, postString, response, NULL);
 
-    if(ret == 0)
-    {
-        //ret为0表示没有出错
-        return true;
-    }
+	LOG_INFO("response:" << response.c_str());
 
-    return false;
+	if (ret == 0)
+	{
+		//ret为0表示没有出错
+		return true;
+	}
+
+	return false;
 }

+ 7 - 7
zhipuzi_pos_windows/network/CZhipuziHttpClient.h

@@ -13,18 +13,18 @@ public:
 
     static bool Login(std::string& errmsg);
 
-    static bool RequestOld(std::string url, std::map<string, string> params, std::string& response);
-    static bool RequestNew(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);
 public:
     static CZhipuziHttpClient m_client;
 
 private:
     std::string m_username;
     std::string m_password;
-    std::string m_machinecode = "e6bc5694877b2aec";
 
-    std::string m_old_url = "https://cyapi.zhipuzi.com/pos";
-    std::string m_new_url = "https://pf-api.zhipuzi.com/pos";
-};
+    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;
+};

+ 6 - 6
zhipuzi_pos_windows/order/CWaimaiOrder.cpp

@@ -18,7 +18,7 @@ bool CWaimaiOrder::InitData(std::string order_id, std::string order_no)
     params["order_no"] = order_no;
 
     std::string response;
-    bool ret = CZhipuziHttpClient::RequestOld("/waimaiorder/getorderdetail", params, response);
+    bool ret = CZhipuziHttpClient::Request("/waimaiorder/getorderdetail", params, response);
     if(!ret)
     {
         LOG_INFO("网络请求出错");
@@ -191,7 +191,7 @@ bool CWaimaiOrder::ConfirmeOrder(std::string order_id)
     params["id"] = order_id;
     std::string response;
 
-    CZhipuziHttpClient::RequestOld(url.c_str(), params, response);
+    CZhipuziHttpClient::Request(url.c_str(), params, response);
 
     rapidjson::Document document;
     document.Parse(response.c_str());
@@ -233,7 +233,7 @@ bool CWaimaiOrder::SuccessOrder(std::string order_id)
     params["id"] = order_id;
     std::string response;
 
-    CZhipuziHttpClient::RequestOld(url.c_str(), params, response);
+    CZhipuziHttpClient::Request(url.c_str(), params, response);
 
     rapidjson::Document document;
     document.Parse(response.c_str());
@@ -276,7 +276,7 @@ bool CWaimaiOrder::FailOrder(std::string order_id, std::string reason)
     params["failed_reason"] = reason;
     std::string response;
 
-    CZhipuziHttpClient::RequestOld(url.c_str(), params, response);
+    CZhipuziHttpClient::Request(url.c_str(), params, response);
 
     rapidjson::Document document;
     document.Parse(response.c_str());
@@ -318,7 +318,7 @@ bool CWaimaiOrder::AgreeRefund(std::string order_id)
     params["order_id"] = order_id;
     std::string response;
 
-    CZhipuziHttpClient::RequestOld(url.c_str(), params, response);
+    CZhipuziHttpClient::Request(url.c_str(), params, response);
 
     rapidjson::Document document;
     document.Parse(response.c_str());
@@ -360,7 +360,7 @@ bool CWaimaiOrder::DisagreeRefund(std::string order_id)
     params["order_id"] = order_id;
     std::string response;
 
-    CZhipuziHttpClient::RequestOld(url.c_str(), params, response);
+    CZhipuziHttpClient::Request(url.c_str(), params, response);
 
     rapidjson::Document document;
     document.Parse(response.c_str());

+ 161 - 53
zhipuzi_pos_windows/tool/CPosPrinter.cpp

@@ -6,7 +6,7 @@
 
 using boost::asio::ip::tcp;
 
-CPosPrinter::CPosPrinter(): m_socket(m_io)
+CPosPrinter::CPosPrinter() : m_socket(m_io)
 {
 }
 
@@ -15,29 +15,13 @@ CPosPrinter::~CPosPrinter()
 {
 }
 
-/*
- *找到所有可用的小票打印机,包括USB、并口、串口3个类型
- **/
-bool CPosPrinter::InitShouyin()
+void CPosPrinter::InitUsb()
 {
-    //先找USB的
-
-    //设备路径
-    TCHAR* szDevicePath[MAX_DEVICE];
-
     //设置中文字符
     setlocale(LC_CTYPE, "chs");
 
-    TCHAR* Port = NULL;
-
-    //分配需要的空间
-    for(int i = 0; i < MAX_DEVICE; i++)
-    {
-        szDevicePath[i] = new TCHAR[MAX_PATH];
-    }
-
     //取设备路径
-    int nDevice = GetDevicePath((LPGUID)&USB_GUID, szDevicePath);
+    int nDevice = GetDevicePath((LPGUID)&USB_GUID);
     LOG_INFO("可用的USB打印机数量:" << nDevice);
 
     //添加usb端口
@@ -45,10 +29,9 @@ bool CPosPrinter::InitShouyin()
 
     while(i < nDevice)
     {
-        Port = szDevicePath[i++];
-        LOG_INFO("准备打开端口 Port = " << Port);
+        LOG_INFO("准备打开端口 Port = " << m_usb_devices[i].c_str());
 
-        HANDLE hPort = CreateFile(Port, GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, FILE_FLAG_OVERLAPPED, NULL);
+        HANDLE hPort = CreateFile(m_usb_devices[i].c_str(), GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_OVERLAPPED, NULL);
 
         if(hPort == INVALID_HANDLE_VALUE)
         {
@@ -84,12 +67,54 @@ bool CPosPrinter::InitShouyin()
             //端口打印机没有连接,那么就直接关闭掉并口,避免占用
             CloseHandle(hPort);
         }
+
+        i++;
     }
+}
 
-    //开始添加并口的端口
+void CPosPrinter::InitOneUsb(wstring usb_path)
+{
+    HANDLE hPort = CreateFile(usb_path.c_str(), GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_OVERLAPPED, NULL);
+
+    if(hPort == INVALID_HANDLE_VALUE)
+    {
+        // 打开端口失败
+        DWORD error = GetLastError();
+
+        if(error == 2)
+        {
+            //没有指定的文件
+            LOG_INFO("没有找对对应的usb端口");
+        }
+        else if(error == 5)
+        {
+            LOG_INFO("usb端口被占用!");
+        }
+    }
+
+    LOG_INFO("打开usb端口,准备进行打印机检测! hPort:" << hPort);
+
+    if(PortTest(hPort) == true)
+    {
+        //端口测试连通,保存起来
+        PrinterHandle newHandle;
+        newHandle.hPort = hPort;
+        newHandle.type = 1;
+
+        m_hPorts.push_back(newHandle);
+    }
+    else
+    {
+        //端口打印机没有连接,那么就直接关闭掉并口,避免占用
+        CloseHandle(hPort);
+    }
+}
+
+void CPosPrinter::InitBingkou()
+{
     std::wstring LptStr = L"lpt1";
 
-    HANDLE hPort = CreateFile(LptStr.c_str(), GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, FILE_FLAG_OVERLAPPED, NULL);
+    HANDLE hPort = CreateFile(LptStr.c_str(), GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_OVERLAPPED, NULL);
 
     if(hPort == INVALID_HANDLE_VALUE)
     {
@@ -125,15 +150,17 @@ bool CPosPrinter::InitShouyin()
             CloseHandle(hPort);
         }
     }
+}
 
-    //开始添加串口
+void CPosPrinter::InitCom()
+{
     int comNum = 10;
 
     for(int i = 1; i <= 10; i++)
     {
         std::wstring com2Str = L"com" + CLewaimaiString::ANSIToUnicode(to_string(i));
 
-        hPort = CreateFile(com2Str.c_str(), GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
+        HANDLE hPort = CreateFile(com2Str.c_str(), GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
 
         if(hPort == INVALID_HANDLE_VALUE)
         {
@@ -192,14 +219,27 @@ bool CPosPrinter::InitShouyin()
             m_hPorts.push_back(newHandle);
         }
     }
+}
 
-    return true;
+/*
+ *找到所有可用的小票打印机,包括USB、并口、串口3个类型,注意这里不包含网口
+ **/
+void CPosPrinter::InitShouyin()
+{
+    //开始添加usb
+    InitUsb();
+
+    //开始添加并口的端口
+    InitBingkou();
+
+    //开始添加串口
+    InitCom();
 }
 
 /*
  *获取CreateFile的USB端口号
  **/
-int CPosPrinter::GetDevicePath(LPGUID lpGuid, LPTSTR* pszDevicePath)
+int CPosPrinter::GetDevicePath(LPGUID lpGuid)
 {
     HDEVINFO hDevInfoSet;
     SP_DEVINFO_DATA spDevInfoData;
@@ -300,13 +340,27 @@ int CPosPrinter::GetDevicePath(LPGUID lpGuid, LPTSTR* pszDevicePath)
 
                 if(bResult)
                 {
+                    wstring DevicePath = pDetail->DevicePath;
+
+                    wstring vid = DevicePath.substr(DevicePath.find(_T("vid_"), 0) + 4, 4);
+                    wstring pid = DevicePath.substr(DevicePath.find(_T("pid_"), 0) + 4, 4);
+
+                    LOG_INFO("Vid:" << vid.c_str() << ", Pid:" << pid.c_str());
+
+                    if(GetPrinterType(vid, pid) == 2)
+                    {
+                        //标签打印机,暂时不处理打印
+                        LOG_INFO("标签打印机,暂时不打印!");
+                        continue;
+                    }
+
                     // 复制设备路径到输出缓冲区
-                    ::_tcscpy_s(pszDevicePath[nCount], 256, pDetail->DevicePath);
+                    m_usb_devices.push_back(DevicePath);
 
                     // 调整计数值
                     nCount++;
 
-                    //LOG_INFO("Cnt = " << nCount << ",pDetail->DevicePath =" << pDetail->DevicePath);
+                    LOG_INFO("Cnt = " << nCount << ",pDetail->DevicePath =" << pDetail->DevicePath);
                 }
             }
         }
@@ -324,18 +378,65 @@ int CPosPrinter::GetDevicePath(LPGUID lpGuid, LPTSTR* pszDevicePath)
     return nCount;
 }
 
+/*
+ *返回打印机的类型, 1:普通热敏打印机 2:标签打印机
+ **/
+int CPosPrinter::GetPrinterType(wstring vid, wstring pid)
+{
+    if(vid == L"6868" && pid == L"0500")
+    {
+        //佳博标签打印机
+        return 2;
+    }
+
+    return 1;
+}
+
+/*
+ *打印收银小票
+ **/
 void CPosPrinter::PrintWaimaiOrderShouyin(CWaimaiOrder& order)
 {
     //设置模式,后面输出数据不会错
     m_type = 1;
 
-    //初始化收银打印机的链接
-    bool ret = InitShouyin();
+    std::string printer_leixing = CSetting::GetParam("setting_printer_leixing");
+    if(printer_leixing == "auto")
+    {
+        InitShouyin();
+    }
+    else if(printer_leixing == "usb")
+    {
+        std::string printer_usb = CSetting::GetParam("setting_printer_usb");
+        std::wstring ws_printer_usb = CLewaimaiString::UTF8ToUnicode(printer_usb);
 
-    if(ret == false)
+        InitOneUsb(ws_printer_usb);
+    }
+    else if(printer_leixing == "bingkou")
+    {
+        InitBingkou();
+    }
+    else if(printer_leixing == "chuankou")
+    {
+        InitCom();
+    }
+    else if(printer_leixing == "wangkou")
     {
-        LOG_INFO("打开收银打印机端口失败!");
-        return;
+        m_type = 2;
+
+        std::string wangkou_ip = CSetting::GetParam("setting_printer_wangkou_ip");
+
+        //初始化连接
+        try
+        {
+            boost::asio::ip::tcp::endpoint ep(boost::asio::ip::address::from_string(wangkou_ip.c_str()), 9100);
+            m_socket.connect(ep);
+        }
+        catch(std::exception& e)
+        {
+            std::string err = e.what();
+            LOG_INFO("连接厨房打印机失败,IP地址:" << wangkou_ip.c_str() << ",错误信息:" << err.c_str());
+        }
     }
 
     //读取当前收银打印机的设置
@@ -489,6 +590,7 @@ void CPosPrinter::PrintWaimaiOrderShouyin(CWaimaiOrder& order)
 
         POS_TextOut(lines);
         POS_FeedLine();
+
         //商品标题
         bool setting_printer_shangpin_big = false;
 
@@ -743,7 +845,6 @@ void CPosPrinter::PrintWaimaiOrderChufang(CWaimaiOrder& order)
         std::string fenlei_ids = printer.fenlei_ids;
 
         std::vector<CWaimaiOrderItem> cur_printer_use;
-
         if(fenlei == "0")
         {
             cur_printer_use = order.m_order_items;
@@ -1032,6 +1133,11 @@ void CPosPrinter::PrintWaimaiOrderChufang(CWaimaiOrder& order)
     }
 }
 
+std::vector<std::wstring> CPosPrinter::getUsbDevices()
+{
+    return m_usb_devices;
+}
+
 int CPosPrinter::WriteData(string msg)
 {
     return WriteBuf(msg.c_str(), msg.length());
@@ -1050,28 +1156,30 @@ int CPosPrinter::WriteBuf(const char* buf, int len)
             if((*it).type == 3)
             {
                 //串口,同步写数据
-                LOG_INFO("before com writefile handle:" << hPort);
+                //LOG_INFO("before com writefile handle:" << hPort);
                 WriteFile(hPort, buf, len, &dwWrite, NULL);
-                LOG_INFO("after com writefile handle:" << hPort);
+                //LOG_INFO("after com writefile handle:" << hPort);
             }
             else
             {
                 //usb和并口,异步写数据
                 OVERLAPPED overlap;
                 memset(&overlap, 0, sizeof(overlap));
-                BOOL rc = WriteFile(hPort, buf, len, &dwWrite, &overlap);
 
+                BOOL rc = WriteFile(hPort, buf, len, &dwWrite, &overlap);
                 if(rc)
                 {
-                    LOG_INFO("writefile success immediately, handle:" << hPort);
+                    //LOG_INFO("writefile success immediately, handle:" << hPort);
                 }
                 else
                 {
                     if(GetLastError() == ERROR_IO_PENDING)
                     {
-                        LOG_INFO("Request queued, waiting... handle:" << hPort);
-                        WaitForSingleObject(hPort, 5000);
-                        LOG_INFO("Request completed, handle:" << hPort);
+                        //LOG_INFO("Request queued, waiting... handle:" << hPort);
+                        WaitForSingleObject(hPort, 1000);
+                        //LOG_INFO("Request completed, handle:" << hPort);
+
+                        //计算写入了多少字节的数据
                         DWORD numread;
                         rc = GetOverlappedResult(
                                  hPort,
@@ -1102,19 +1210,19 @@ int CPosPrinter::WriteBuf(const char* buf, int len)
 }
 
 /*
- *测试这个并口是否连通的
+ *测试打印机是否连接
  **/
 bool CPosPrinter::PortTest(HANDLE hPort)
 {
-    char chInitCode[] = "\x1B\x40";
+    //标签打印机的查询状态指令
+    char chInitCode[2] = { 0x1b, 0x40 };
 
     DWORD dwWrite;
 
     OVERLAPPED overlap;
     memset(&overlap, 0, sizeof(overlap));
 
-    BOOL rc = WriteFile(hPort, chInitCode, (DWORD)2L, &dwWrite, &overlap);
-
+    BOOL rc = WriteFile(hPort, chInitCode, 2, &dwWrite, &overlap);
     if(rc)
     {
         LOG_INFO("writefile success immediately, handle:" << hPort);
@@ -1125,11 +1233,11 @@ bool CPosPrinter::PortTest(HANDLE hPort)
     {
         if(GetLastError() == ERROR_IO_PENDING)
         {
-            DWORD ret = WaitForSingleObject(hPort, 500);
-
+            DWORD ret = WaitForSingleObject(hPort, 1000);
             if(ret == 0)
             {
                 LOG_INFO("printer is connect, handle:" << hPort);
+
                 return true;
             }
             else
@@ -1144,14 +1252,14 @@ bool CPosPrinter::PortTest(HANDLE hPort)
 
 int CPosPrinter::POS_Reset(void)
 {
-    char s[2] = {0x1B, 0x40};
+    char s[2] = { 0x1B, 0x40 };
     WriteBuf(s, 2);
     return 0;
 }
 
 int CPosPrinter::POS_FeedLine(void)
 {
-    char s[1] = {0x0A};
+    char s[1] = { 0x0A };
     WriteBuf(s, 1);
     return 0;
 }
@@ -1175,7 +1283,7 @@ int CPosPrinter::POS_SetMotionUnit(int x, int y)
 
 int CPosPrinter::POS_SET_MOVE_X()
 {
-    char s2[6] = { 0x1B, 0x44, 0x0C, 0x0E, 0x17, 0x00};
+    char s2[6] = { 0x1B, 0x44, 0x0C, 0x0E, 0x17, 0x00 };
     WriteBuf(s2, 6);
     return 0;
 }
@@ -1267,7 +1375,7 @@ int CPosPrinter::POS_TextOut(string abc, bool is_double_width, bool is_double_he
  **/
 int CPosPrinter::POS_CutPaper()
 {
-    char s[4] = { 0x1D, 0x56, 0x01};
+    char s[4] = { 0x1D, 0x56, 0x01 };
     WriteBuf(s, 3);
     return 0;
 }

+ 17 - 4
zhipuzi_pos_windows/tool/CPosPrinter.h

@@ -11,7 +11,7 @@
 
 //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 }};
+const GUID USB_GUID = { 0x28d78fad, 0x5a12, 0x11d1, {0xae, 0x5b, 0x00, 0x00, 0xf8, 0x03, 0xa8, 0xc2 } };
 
 //存储打印端口句柄的结构
 class PrinterHandle
@@ -30,9 +30,19 @@ public:
     void PrintWaimaiOrderShouyin(CWaimaiOrder& order);
     void PrintWaimaiOrderChufang(CWaimaiOrder& order);
 
+    void InitUsb();
+    std::vector<std::wstring> getUsbDevices();
+
 private:
-    bool InitShouyin();
-    int GetDevicePath(LPGUID lpGuid, LPTSTR* pszDevicePath);
+    void InitBingkou();
+    void InitCom();
+
+    void InitShouyin();
+
+    void InitOneUsb(wstring usb_path);
+
+    int GetDevicePath(LPGUID lpGuid);
+    int GetPrinterType(wstring vid, wstring pid);
 
     int WriteData(string meg);
     int WriteBuf(const char* buf, int len);
@@ -56,7 +66,7 @@ private:
     int POS_OutQRCode();
 
     //字符空格计算的辅助函数
-    void CalWord(string s,  int& nHanzi, int& nZimu);
+    void CalWord(string s, int& nHanzi, int& nZimu);
 
     //对名字进行换行处理
     std::vector<std::string> HandleFoodname(std::string oldname, int guige = 1);
@@ -72,4 +82,7 @@ private:
 
     //这个是当前的输出模式,是收银模式还是厨房打印模式
     int m_type;
+
+    //usb打印机的描述
+    std::vector<std::wstring> m_usb_devices;
 };

+ 18 - 0
zhipuzi_pos_windows/tool/CSetting.cpp

@@ -167,6 +167,24 @@ void CSetting::Init()
         m_paramsMap[setting_printer_lianshu] = "1";
     }
 
+	std::string setting_printer_leixing = "setting_printer_leixing";
+	if (m_paramsMap.find(setting_printer_leixing) == m_paramsMap.end())
+	{
+		m_paramsMap[setting_printer_leixing] = "auto";
+	}
+
+	std::string setting_printer_usb = "setting_printer_usb";
+	if (m_paramsMap.find(setting_printer_usb) == m_paramsMap.end())
+	{
+		m_paramsMap[setting_printer_usb] = "";
+	}
+
+	std::string setting_printer_wangkou_ip = "setting_printer_wangkou_ip";
+	if (m_paramsMap.find(setting_printer_wangkou_ip) == m_paramsMap.end())
+	{
+		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())
     {

+ 285 - 223
zhipuzi_pos_windows/wnd/CLoginWnd.cpp

@@ -1,4 +1,4 @@
-#include "../pch/pch.h"
+#include "../pch/pch.h"
 #include "CLoginWnd.h"
 #include "CUpdateWnd.h"
 
@@ -7,7 +7,7 @@
 void CLoginWnd::Init()
 {
     CLabelUI* version = static_cast<CLabelUI*>(m_pm.FindControl(_T("login_version")));
-    version->SetText((L"智铺子收银软件 " + CLewaimaiString::UTF8ToUnicode(CSystem::GetVersion())).c_str());
+    version->SetText((L"智铺子收银软件 " + CLewaimaiString::UTF8ToUnicode(CSystem::GetVersion())).c_str());
 
     std::map<string, string> users = CSetting::getUsers();
 
@@ -37,7 +37,7 @@ void CLoginWnd::Init()
 
     if(CSetting::GetParam("setting_is_auto_login") == "1")
     {
-        //自动登录开启了,记住密码一定要开启
+        //自动登录开启了,记住密码一定要开启
         pAuto->Selected(true, false);
         pRemember->Selected(true, false);
     }
@@ -140,7 +140,7 @@ 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);
@@ -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的m_aNotifiers数组中,用于处理Notify函数
+    // 鎶婅嚜宸卞姞鍏ュ埌CPaintManagerUI鐨刴_aNotifiers鏁扮粍涓�紝鐢ㄤ簬澶勭悊Notify鍑芥暟
     m_pm.AddNotifier(this);
 
     Init();
@@ -168,7 +168,7 @@ LRESULT CLoginWnd::OnClose(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandl
 }
 
 /*
- *这个是窗口被销毁的时候调用的
+ *杩欎釜鏄�獥鍙h�閿€姣佺殑鏃跺€欒皟鐢ㄧ殑
  **/
 LRESULT CLoginWnd::OnDestroy(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
 {
@@ -192,7 +192,7 @@ 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)
     {
@@ -247,111 +247,111 @@ 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;
-    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);
+	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);
 }
 
 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;
-        }
-
-    }
-    else if(uMsg == WM_LOGIN_SUCCESS)
-    {
-        LoginSuccess();
-        return true;
-    }
-    else if(uMsg == WM_LOGIN_ERROR)
-    {
-        LoginError();
-        return true;
-    }
-    else if(uMsg == WM_NEED_UPDATE)
-    {
-        //说明需要升级了
-
-        Update();
-
-        return true;
-    }
-    else if(uMsg == WM_LOGIN_AGAIN_OUT)
-    {
-        ShowLoginAgainOut();
-
-        return true;
-    }
-
-    return false;
+	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();
+		return true;
+	}
+	else if (uMsg == WM_LOGIN_ERROR)
+	{
+		LoginError();
+		return true;
+	}
+	else if (uMsg == WM_NEED_UPDATE)
+	{
+		//璇存槑闇€瑕佸崌绾т簡
+
+		Update();
+
+		return true;
+	}
+	else if (uMsg == WM_LOGIN_AGAIN_OUT)
+	{
+		ShowLoginAgainOut();
+
+		return true;
+	}
+
+	return false;
 }
 
 void CLoginWnd::StartLogin()
 {
-    //隐藏密码输入框,显示进度条
+    //隐藏密码输入框,显示进度条
     CVerticalLayoutUI* pInput = static_cast<CVerticalLayoutUI*>(m_pm.FindControl(_T("login_input")));
     pInput->SetVisible(false);
 
@@ -361,124 +361,186 @@ void CLoginWnd::StartLogin()
     CLabelUI* pLoginResultLabel = static_cast<CLabelUI*>(m_pm.FindControl(_T("loginresult")));
     pLoginResultLabel->SetVisible(false);
 
-    //开启一个线程,开始处理登录
+    //开启一个线程,开始处理登录
     std::thread(&CLoginWnd::HandleLogin, this).detach();
 }
 
 void CLoginWnd::HandleLogin()
 {
-    ////真正登录前,先检测是否有需要更新
-    //CSystem::my_sleep(1);
+	CLabelUI* pLoginResultLabel = static_cast<CLabelUI*>(m_pm.FindControl(_T("loginresult")));
 
-    ////如果需要更新,那么就提示
-    //PostMessage(WM_NEED_UPDATE);
-    //return;
+	//真正登录前,先检测是否有需要更新
+	//std::map<string, string> params;
 
-    //判断账号密码是否正确
-    std::wstring account, password;
-    CEditUI* pAccountEdit = static_cast<CEditUI*>(m_pm.FindControl(_T("accountedit")));
-    if(pAccountEdit)
-    {
-        account = pAccountEdit->GetText().GetData();
-    }
+	//std::string response;
+	//bool ret = CZhipuziHttpClient::Request("/version/getwindowsversion", params, response);
+	//if (!ret)
+	//{
+	//	pLoginResultLabel->SetText(std::wstring(_T("缃戠粶璇锋眰鍑洪敊")).c_str());
+	//	pLoginResultLabel->SetVisible(true);
 
-    CEditUI* pPasswordEdit = static_cast<CEditUI*>(m_pm.FindControl(_T("pwdedit")));
-    if(pPasswordEdit)
-    {
-        password = pPasswordEdit->GetText().GetData();
-    }
+	//	PostMessage(WM_LOGIN_ERROR);
 
-    LOG_INFO("account:" << account.c_str() << ", password:" << password.c_str());
+	//	return;
+	//}
 
-    string s_account = CLewaimaiString::UnicodeToUTF8(account);
-    string s_password = CLewaimaiString::UnicodeToUTF8(password);
+	//rapidjson::Document document;
+	//document.Parse(response.c_str());
 
-    CLewaimaiString::trim(s_account);
-    CLewaimaiString::trim(s_password);
+	//if (document.HasParseError())
+	//{
+	//	pLoginResultLabel->SetText(std::wstring(_T("服务器返回数据格式错误")).c_str());
+	//	pLoginResultLabel->SetVisible(true);
 
-    CLabelUI* pLoginResultLabel = static_cast<CLabelUI*>(m_pm.FindControl(_T("loginresult")));
-    if(s_account.compare("") == 0)
-    {
-        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);
 
-    if(s_password.compare("") == 0)
-    {
-        pLoginResultLabel->SetText(std::wstring(_T("密码不能为空")).c_str());
-        pLoginResultLabel->SetVisible(true);
+	//		return;
+	//	}
+
+	//	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);
+
+	//		PostMessage(WM_LOGIN_ERROR);
+
+	//		return;
+	//	}
+
+	//	rapidjson::Value& data = document["data"];
+
+	//	std::string newest_version = data["newest_version"].GetString();
+	//	m_update_url = data["url"].GetString();
+
+	//	if (newest_version > CSystem::GetVersion())
+	//	{
+	//		//璇存槑鏈夋柊鐗堟湰锛岃�鏇存柊
+	//		PostMessage(WM_NEED_UPDATE);
+	//		return;
+	//	}
+	//}
+
+	//鍒ゆ柇璐﹀彿瀵嗙爜鏄�惁姝g‘
+	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);
+
+	//LOG_INFO("account:" << account.c_str() << ", password:" << password.c_str());
+
+	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->SetVisible(true);
+
+		PostMessage(WM_LOGIN_ERROR);
+
+		return;
+	}
+
+	if (s_password.compare("") == 0)
+	{
+		pLoginResultLabel->SetText(std::wstring(_T("瀵嗙爜涓嶈兘涓虹┖")).c_str());
+		pLoginResultLabel->SetVisible(true);
+
+		PostMessage(WM_LOGIN_ERROR);
+
+		return;
+	}
 
-        PostMessage(WM_LOGIN_ERROR);
+	CZhipuziHttpClient::Init(s_account, s_password);
+
+	std::string errmsg;
+	bool res = CZhipuziHttpClient::Login(errmsg);
+
+	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")));
+
+		if (pAuto->IsSelected())
+		{
+			CSetting::SetParam("setting_is_auto_login", "1", false);
+			CSetting::SetParam("setting_is_remember_password", "1", false);
+
+			//相当于开启自动登录,默认就是开启了记住密码了
+			CSetting::SetUser(s_account, s_password, true);
+		}
+		else
+		{
+			CSetting::SetParam("setting_is_auto_login", "0", false);
+
+			if (pRemember->IsSelected())
+			{
+				CSetting::SetParam("setting_is_remember_password", "1", false);
+			}
+			else
+			{
+				CSetting::SetParam("setting_is_remember_password", "0", false);
+			}
+
+
+			if (pRemember->IsSelected())
+			{
+				CSetting::SetUser(s_account, s_password, true);
+			}
+			else
+			{
+				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);
 
-        return;
-    }
-
-    CZhipuziHttpClient::Init(s_account, s_password);
-
-    std::string errmsg;
-    bool res = CZhipuziHttpClient::Login(errmsg);
-
-    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")));
-
-        if(pAuto->IsSelected())
-        {
-            CSetting::SetParam("setting_is_auto_login", "1", false);
-            CSetting::SetParam("setting_is_remember_password", "1", false);
-
-            //相当于开启自动登录,默认就是开启了记住密码了
-            CSetting::SetUser(s_account, s_password, true);
-        }
-        else
-        {
-            CSetting::SetParam("setting_is_auto_login", "0", false);
-
-            if(pRemember->IsSelected())
-            {
-                CSetting::SetParam("setting_is_remember_password", "1", false);
-            }
-            else
-            {
-                CSetting::SetParam("setting_is_remember_password", "0", false);
-            }
-
-
-            if(pRemember->IsSelected())
-            {
-                CSetting::SetUser(s_account, s_password, true);
-            }
-            else
-            {
-                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);
-
-        PostMessage(WM_LOGIN_ERROR);
-    }
+		PostMessage(WM_LOGIN_ERROR);
+	}
 }
 
 void CLoginWnd::LoginSuccess()
@@ -490,7 +552,7 @@ void CLoginWnd::LoginSuccess()
     }
 
     pFrame->SetIcon(IDI_ICON_DUILIB);
-    pFrame->Create(NULL, _T("智铺子收银软件"), UI_WNDSTYLE_FRAME, 0L, 0, 0, 1024, 768);
+    pFrame->Create(NULL, _T("智铺子收银软件"), UI_WNDSTYLE_FRAME, 0L, 0, 0, 1024, 768);
     pFrame->CenterWindow();
 
     ::ShowWindow(*pFrame, SW_SHOWMAXIMIZED);
@@ -512,31 +574,31 @@ void CLoginWnd::LoginError()
 
 void CLoginWnd::Update()
 {
-    CUpdateWnd* pFrame = new CUpdateWnd();
-    if(pFrame == NULL)
-    {
-        return;
-    }
+	CUpdateWnd* pFrame = new CUpdateWnd();
+	if (pFrame == NULL)
+	{
+		return;
+	}
 
-    TCHAR lpTempPathBuffer[MAX_PATH];
-    DWORD dwRetVal = GetTempPath(MAX_PATH, lpTempPathBuffer);
+	TCHAR lpTempPathBuffer[MAX_PATH];
+	DWORD dwRetVal = GetTempPath(MAX_PATH, lpTempPathBuffer);
 
-    std::string url = "http://down10d.zol.com.cn/zoldownload_os/nsis3.04setup@81_262627.exe";
-    std::string filename = CLewaimaiString::UnicodeToANSI(lpTempPathBuffer);
-    pFrame->InitData(url, filename);
+	std::string url = m_update_url;
+	std::string filename = CLewaimaiString::UnicodeToANSI(lpTempPathBuffer);
+	pFrame->InitData(url, filename);
 
-    pFrame->SetIcon(IDI_ICON_DUILIB);
-    pFrame->Create(NULL, _T("自动更新"), UI_WNDSTYLE_DIALOG, 0, 0, 0, 0, 0, NULL);
-    pFrame->CenterWindow();
+	pFrame->SetIcon(IDI_ICON_DUILIB);
+	pFrame->Create(NULL, _T("鑷�姩鏇存柊"), UI_WNDSTYLE_DIALOG, 0, 0, 0, 0, 0, NULL);
+	pFrame->CenterWindow();
 
-    ::ShowWindow(*pFrame, SW_SHOWNORMAL);
+	::ShowWindow(*pFrame, SW_SHOWNORMAL);
 
-    Close();
+	Close();
 }
 
 void CLoginWnd::ShowLoginAgainOut()
 {
-    //这种模式是本人强制挤下线了
+    //这种模式是本人强制挤下线了
     CMessageboxWnd* pMessagebox = new CMessageboxWnd;
     pMessagebox->Create(m_hWnd, _T(""), UI_WNDSTYLE_DIALOG, WS_EX_WINDOWEDGE);
     pMessagebox->SetIcon(IDI_ICON_DUILIB);

+ 190 - 1
zhipuzi_pos_windows/wnd/CMainWnd.cpp

@@ -489,6 +489,14 @@ void CMainWnd::HandleClickMsg(TNotifyUI& msg)
         }
     }
 
+    else if(name == _T("setting_printer_wangkouk_save_btn"))
+    {
+        CEditUI* wangkou_ip = static_cast<CEditUI*>(m_pm.FindControl(_T("setting_printer_wangkou_ip")));
+        wstring ip = wangkou_ip->GetText();
+
+        CSetting::SetParam("setting_printer_wangkou_ip", CLewaimaiString::UnicodeToUTF8(ip));
+    }
+
     else if(name == _T("setting_printer_quhuo_big"))
     {
         CCheckBoxUI* box = static_cast<CCheckBoxUI*>(m_pm.FindControl(_T("setting_printer_quhuo_big")));
@@ -1041,6 +1049,95 @@ void CMainWnd::HandleItemSelectMsg(TNotifyUI& msg)
             CSetting::SetParam("setting_printer_lianshu", "4");
         }
     }
+    else if(name == _T("setting_printer_leixing"))
+    {
+        CComboUI* com = static_cast<CComboUI*>(m_pm.FindControl(_T("setting_printer_leixing")));
+
+        CHorizontalLayoutUI* usb_layout = static_cast<CHorizontalLayoutUI*>(m_pm.FindControl(_T("setting_printer_usb_layout")));
+        CHorizontalLayoutUI* wangkou_layout = static_cast<CHorizontalLayoutUI*>(m_pm.FindControl(_T("setting_printer_wangkou_layout")));
+
+        if(com->GetCurSel() == 0)
+        {
+            CSetting::SetParam("setting_printer_leixing", "auto");
+
+            usb_layout->SetVisible(false);
+            wangkou_layout->SetVisible(false);
+        }
+        else if(com->GetCurSel() == 1)
+        {
+            CSetting::SetParam("setting_printer_leixing", "usb");
+
+            //显示usb布局
+            usb_layout->SetVisible(true);
+            wangkou_layout->SetVisible(false);
+
+            //usb下拉框默认选中
+            CComboUI* com_usb = static_cast<CComboUI*>(m_pm.FindControl(_T("setting_printer_usb")));
+            com_usb->RemoveAll();
+
+            //数据库中保存的之前的设置
+            std::string setting_printer_usb = CSetting::GetParam("setting_printer_usb");
+            std::wstring ws_setting_printer_usb = CLewaimaiString::UTF8ToUnicode(setting_printer_usb);
+
+            CPosPrinter printer;
+            printer.InitUsb();
+            std::vector<std::wstring> usb_devices = printer.getUsbDevices();
+
+            int i = 0;
+            int nSelect = -1;
+
+            for(std::vector<std::wstring>::iterator it = usb_devices.begin(); it != usb_devices.end(); it++)
+            {
+                CListLabelElementUI* elem = new CListLabelElementUI();
+                elem->SetText((*it).c_str());
+                com_usb->Add(elem);
+
+                if(*it == ws_setting_printer_usb)
+                {
+                    nSelect = i;
+                }
+
+                i++;
+            }
+
+            com_usb->SetInternVisible(true);
+            com_usb->SelectItem(nSelect, false, false);
+            com_usb->SetText(CLewaimaiString::UTF8ToUnicode(setting_printer_usb).c_str());
+        }
+        else if(com->GetCurSel() == 2)
+        {
+            CSetting::SetParam("setting_printer_leixing", "bingkou");
+
+            usb_layout->SetVisible(false);
+            wangkou_layout->SetVisible(false);
+        }
+        else if(com->GetCurSel() == 3)
+        {
+            CSetting::SetParam("setting_printer_leixing", "chuankou");
+
+            usb_layout->SetVisible(false);
+            wangkou_layout->SetVisible(false);
+        }
+        else if(com->GetCurSel() == 4)
+        {
+            CSetting::SetParam("setting_printer_leixing", "wangkou");
+
+            usb_layout->SetVisible(false);
+            wangkou_layout->SetVisible(true);
+
+            std::string setting_printer_wangkou_ip = CSetting::GetParam("setting_printer_wangkou_ip");
+
+            CEditUI* ip_edit = static_cast<CEditUI*>(m_pm.FindControl(_T("setting_printer_wangkou_ip")));
+            ip_edit->SetText(CLewaimaiString::UTF8ToUnicode(setting_printer_wangkou_ip).c_str());
+        }
+    }
+    else if(name == _T("setting_printer_usb"))
+    {
+        CComboUI* com = static_cast<CComboUI*>(m_pm.FindControl(_T("setting_printer_usb")));
+        wstring usb_device = com->GetText();
+
+        CSetting::SetParam("setting_printer_usb", CLewaimaiString::UnicodeToUTF8(usb_device));
+    }
 }
 
 LRESULT CMainWnd::HandleMessage(UINT uMsg, WPARAM wParam, LPARAM lParam)
@@ -1503,6 +1600,98 @@ void CMainWnd::InitSettingStatus()
         com->SetText(L"4联");
     }
 
+    com = static_cast<CComboUI*>(m_pm.FindControl(_T("setting_printer_leixing")));
+    std::string setting_printer_leixing = CSetting::GetParam("setting_printer_leixing");
+
+    CHorizontalLayoutUI* usb_layout = static_cast<CHorizontalLayoutUI*>(m_pm.FindControl(_T("setting_printer_usb_layout")));
+    CHorizontalLayoutUI* wangkou_layout = static_cast<CHorizontalLayoutUI*>(m_pm.FindControl(_T("setting_printer_wangkou_layout")));
+
+    if(setting_printer_leixing == "auto")
+    {
+        com->SetInternVisible(true);
+        com->SelectItem(0, false, false);
+        com->SetText(L"智能识别模式");
+
+        //智能识别模式隐藏这2个
+        usb_layout->SetVisible(false);
+        wangkou_layout->SetVisible(false);
+    }
+    else if(setting_printer_leixing == "usb")
+    {
+        com->SetInternVisible(true);
+        com->SelectItem(1, false, false);
+        com->SetText(L"usb");
+
+        //显示usb布局
+        usb_layout->SetVisible(true);
+        wangkou_layout->SetVisible(false);
+
+        //usb下拉框默认选中
+        CComboUI* com_usb = static_cast<CComboUI*>(m_pm.FindControl(_T("setting_printer_usb")));
+        com_usb->RemoveAll();
+
+        //数据库中保存的之前的设置
+        std::string setting_printer_usb = CSetting::GetParam("setting_printer_usb");
+        std::wstring ws_setting_printer_usb = CLewaimaiString::UTF8ToUnicode(setting_printer_usb);
+
+        CPosPrinter printer;
+        printer.InitUsb();
+        std::vector<std::wstring> usb_devices = printer.getUsbDevices();
+
+        int i = 0;
+        int nSelect = -1;
+
+        for(std::vector<std::wstring>::iterator it = usb_devices.begin(); it != usb_devices.end(); it++)
+        {
+            CListLabelElementUI* elem = new CListLabelElementUI();
+            elem->SetText((*it).c_str());
+            com_usb->Add(elem);
+
+            if(*it == ws_setting_printer_usb)
+            {
+                nSelect = i;
+            }
+
+            i++;
+        }
+
+        com_usb->SetInternVisible(true);
+        com_usb->SelectItem(nSelect, false, false);
+        com_usb->SetText(CLewaimaiString::UTF8ToUnicode(setting_printer_usb).c_str());
+    }
+    else if(setting_printer_leixing == "bingkou")
+    {
+        com->SetInternVisible(true);
+        com->SelectItem(2, false, false);
+        com->SetText(L"并口");
+
+        usb_layout->SetVisible(false);
+        wangkou_layout->SetVisible(false);
+    }
+    else if(setting_printer_leixing == "chuankou")
+    {
+        com->SetInternVisible(true);
+        com->SelectItem(3, false, false);
+        com->SetText(L"串口");
+
+        usb_layout->SetVisible(false);
+        wangkou_layout->SetVisible(false);
+    }
+    else if(setting_printer_leixing == "wangkou")
+    {
+        com->SetInternVisible(true);
+        com->SelectItem(4, false, false);
+        com->SetText(L"网口");
+
+        usb_layout->SetVisible(false);
+        wangkou_layout->SetVisible(true);
+
+        std::string setting_printer_wangkou_ip = CSetting::GetParam("setting_printer_wangkou_ip");
+
+        CEditUI* ip_edit = static_cast<CEditUI*>(m_pm.FindControl(_T("setting_printer_wangkou_ip")));
+        ip_edit->SetText(CLewaimaiString::UTF8ToUnicode(setting_printer_wangkou_ip).c_str());
+    }
+
     box = static_cast<CCheckBoxUI*>(m_pm.FindControl(_T("setting_printer_quhuo_big")));
 
     if(CSetting::GetParam("setting_printer_quhuo_big") == "1")
@@ -1681,7 +1870,7 @@ void CMainWnd::InitSettingStatus()
 
     std::string url = "/goodstype/getgoodstypelist";
 
-    CZhipuziHttpClient::RequestOld(url.c_str(), params, response);
+    CZhipuziHttpClient::Request(url.c_str(), params, response);
 
     rapidjson::Document document;
     document.Parse(response.c_str());

+ 0 - 2
zhipuzi_pos_windows_server/obj/x86/Release/zhipuzi_.e085afd9.tlog/zhipuzi_pos_windows_server_linux.lastbuildstate

@@ -1,2 +0,0 @@
-#TargetFrameworkVersion=:PlatformToolSet=Remote_GCC_1_0:EnableManagedIncrementalBuild=:VCToolArchitecture=:WindowsTargetPlatformVersion=
-Release|x86|E:\work\code\zhipuzi_pos_windows\|

+ 2 - 3
zhipuzi_pos_windows_server/obj/x86/Release/zhipuzi_pos_windows_server_linux.log

@@ -1,3 +1,2 @@
-  Validating sources
-  Copying sources remotely to '172.16.1.71'
-D:\Program Files (x86)\Microsoft Visual Studio\2017\Community\Common7\IDE\VC\VCTargets\Application Type\Linux\1.0\Linux.targets(162,5): error : Could not connect to the remote system. Please verify your connection settings, and that your machine is on the network and reachable.
+  Cleaning remote project directory
+D:\Program Files (x86)\Microsoft Visual Studio\2017\Community\Common7\IDE\VC\VCTargets\Application Type\Linux\1.0\Linux.targets(210,6): error : Could not connect to the remote system. Please verify your connection settings, and that your machine is on the network and reachable.