Przeglądaj źródła

条码秤信息同步改完了

张洋 4 lat temu
rodzic
commit
4eb97a4d06

+ 4 - 0
bin/Win32/Debug/zhipuzi_pos_windows/skin/setting_tiaomacheng.xml

@@ -44,6 +44,10 @@
 		<Button name="setting_tiaomacheng_tongburejian" align="center" width="300" height="44" padding="0,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="52">		
+		<Button name="setting_tiaomacheng_qingkongplu" textcolor="#FFFFFFFF" align="center" width="300" height="44" padding="0,8,0,3" text="清空电子秤所有商品PLU信息" normalimage="file='Btn_Red.png' corner='5,5,5,5'" hotimage="file='Btn_Red_Hover.png' corner='5,5,5,5'" pushedimage="file='Btn_Red_Click.png' corner='5,5,5,5'" />
+	</HorizontalLayout>
+	
 	<HorizontalLayout height="44">
 		<Label text="自动同步快捷热键将根据商品PLU编码生成,比如PLU编码为1,则热键为1,编码为10,则热键为10" width="900"/>
 	</HorizontalLayout>

+ 16 - 1
zhipuzi_pos_windows/helper/CLewaimaiString.cpp

@@ -557,7 +557,22 @@ std::string CLewaimaiString::GetQuweima(std::wstring input)
 		{
 			int front = (short)(cur[0] - '\0');//将字节数组的第一位转换成short类型,这里(short)code[0]也是可以的
 			int back = (short)(cur[1] - '\0');//将字节数组的第二位转换成short类型
-			result += to_string(front - 160) + to_string(back - 160);//计算并返回区位码
+
+			std::string s_front = to_string(front - 160);
+			if (front - 160 < 10)
+			{
+				//前面补0
+				s_front = "0" + s_front;
+			}
+
+			std::string s_back = to_string(back - 160);
+			if (back - 160 < 10)
+			{
+				//前面补0
+				s_back = "0" + s_back;
+			}
+
+			result += s_front + s_back;
 
 			i++;
 			i++;

+ 137 - 75
zhipuzi_pos_windows/page/CSettingPageUI.cpp

@@ -1318,6 +1318,10 @@ void CSettingPageUI::HandleClickMsg(TNotifyUI& msg)
 	{
 		this->StartTongbuRejian();
 	}
+	else if (name == L"setting_tiaomacheng_qingkongplu")
+	{
+		this->StartQiongkongPLU();
+	}
 	else if (name == _T("setting_logout"))
 	{
 		//退出登录
@@ -1672,7 +1676,6 @@ void CSettingPageUI::HandleTongbuBiaoqiancheng()
 	boost::asio::io_service m_io;
 	boost::asio::ip::tcp::socket m_socket(m_io);
 
-	//读取厨房打印机信息
 	std::string ip = CSetting::GetParam("setting_tiaomacheng_ip");
 
 	//初始化连接
@@ -1692,65 +1695,16 @@ void CSettingPageUI::HandleTongbuBiaoqiancheng()
 		return;
 	}
 
-	//这个是要发送的数据
-	{
-		std::string data = "";
-
-		//先发送清空命令
-		data += "!0IA";
-		data += 0x0d;
-		data += 0x0a;
-
-		try
-		{
-			m_socket.write_some(boost::asio::buffer(data.c_str(), data.length()));
-		}
-		catch (const std::exception& e)
-		{
-			LOG_INFO("条码秤发送消息失败,错误信息:" << e.what());
-		}
-
-		boost::array<char, 128> buf;
-		boost::system::error_code error;
-
-		//size_t len = m_socket.read_some(boost::asio::buffer(buf), error);
-		//std::string result = buf.begin();
-	}
-
-	{
-		std::string data = "";
-
-		///再清除记录
-		data += "!0HA";
-		data += 0x0d;
-		data += 0x0a;
-
-		try
-		{
-			m_socket.write_some(boost::asio::buffer(data.c_str(), data.length()));
-		}
-		catch (const std::exception& e)
-		{
-			LOG_INFO("条码秤发送消息失败,错误信息:" << e.what());
-		}
-
-		boost::array<char, 128> buf;
-		boost::system::error_code error;
-
-		//size_t len = m_socket.read_some(boost::asio::buffer(buf), error);
-		//std::string result = buf.begin();
-	}
-
-	//然后开通同步商品
 	//!0V + 4位PLU + A + 7位商品编码 + 6位数价格(单位分) + 模式(0:称重,1:计件,2:定重) + 000000 + 3位有效期 + 2位店号(01-99)+ 000000000000000 + 2位皮重(00-15)+
 	//+	0000000000000000000000000000000B + 商品名称区位码 + CDE + 换行符
-	
-	std::string data = "";
-
 	CSqlite3 sqlite;
 	std::vector<CFood> foods = sqlite.GetFoodForTiaomacheng();
+
+	//注意这里商品只能一条一条的同步,不能很多条的命令拼装在一起同步
 	for (std::vector<CFood>::iterator it = foods.begin(); it != foods.end(); it++)
 	{
+		std::string data = "";
+
 		data += "!0V";
 
 		//处理PLU;
@@ -1758,7 +1712,12 @@ void CSettingPageUI::HandleTongbuBiaoqiancheng()
 		if (n_plu < 1)
 		{
 			//无效的plu
-			continue;;
+			continue;
+		}
+		else if (n_plu > 4000)
+		{
+			//无效的plu
+			continue;
 		}
 
 		string plu = to_string(n_plu);
@@ -1769,10 +1728,15 @@ void CSettingPageUI::HandleTongbuBiaoqiancheng()
 
 		//处理商品编码
 		int n_bianma = atoi(it->weight_food_code.c_str());
-		if (n_plu < 1)
+		if (n_bianma < 1)
 		{
 			//无效的编码
-			continue;;
+			continue;
+		}
+		else if (n_bianma > 999999)
+		{
+			//无效的编码
+			continue;
 		}
 
 		string bianma = to_string(n_bianma);
@@ -1809,23 +1773,27 @@ void CSettingPageUI::HandleTongbuBiaoqiancheng()
 
 		data += 0x0d;
 		data += 0x0a;
-	}
 
-	//网口走这里
-	try
-	{
-		m_socket.write_some(boost::asio::buffer(data.c_str(), data.length()));
-	}
-	catch (const std::exception& e)
-	{
-		LOG_INFO("条码秤发送消息失败,错误信息:" << e.what());
-	}
+		try
+		{
+			m_socket.write_some(boost::asio::buffer(data.c_str(), data.length()));
+		}
+		catch (const std::exception& e)
+		{
+			LOG_INFO("条码秤发送PLU信息失败,错误信息:" << e.what());
+			MessageBoxW(NULL, L"条码秤发送PLU信息失败", L"条码秤发送PLU信息失败", MB_OK);
+			m_socket.close();
+			return;
+		}
 
-	boost::array<char, 128> buf;
-	boost::system::error_code error;
+		char buf[128] = { 0 };
+		boost::system::error_code error;
 
-	size_t len = m_socket.read_some(boost::asio::buffer(buf), error);
-	std::string result = buf.begin();
+		size_t len = m_socket.read_some(boost::asio::buffer(buf), error);
+		std::string result = buf;
+
+		LOG_INFO("发送PLU命令成功,返回信息:" << buf);
+	}
 
 	m_socket.close();
 }
@@ -1840,7 +1808,6 @@ void CSettingPageUI::HandleTongbuRejian()
 	boost::asio::io_service m_io;
 	boost::asio::ip::tcp::socket m_socket(m_io);
 
-	//读取厨房打印机信息
 	std::string ip = CSetting::GetParam("setting_tiaomacheng_ip");
 
 	//初始化连接
@@ -1998,14 +1965,109 @@ void CSettingPageUI::HandleTongbuRejian()
 	}
 	catch (const std::exception& e)
 	{
-		LOG_INFO("条码秤发送消息失败,错误信息:" << e.what());
+		LOG_INFO("条码秤同步热键失败,错误信息:" << e.what());
+		MessageBoxW(NULL, L"条码秤同步热键失败", L"条码秤同步热键失败", MB_OK);
+		m_socket.close();
+		return;
 	}
 
-	boost::array<char, 128> buf;
+	char buf[128] = { 0 };
 	boost::system::error_code error;
 
 	size_t len = m_socket.read_some(boost::asio::buffer(buf), error);
-	std::string result = buf.begin();
+	std::string result = buf;
+
+	LOG_INFO("条码秤同步热键成功,返回信息:" << buf);
 
 	m_socket.close();
+}
+
+void CSettingPageUI::StartQiongkongPLU()
+{
+	std::thread(&CSettingPageUI::HandleQiongkongPLU, this).detach();
+}
+
+void CSettingPageUI::HandleQiongkongPLU()
+{
+	boost::asio::io_service m_io;
+	boost::asio::ip::tcp::socket m_socket(m_io);
+
+	std::string ip = CSetting::GetParam("setting_tiaomacheng_ip");
+
+	//初始化连接
+	try
+	{
+		boost::asio::ip::tcp::endpoint ep(boost::asio::ip::address::from_string(ip.c_str()), 4001);
+		m_socket.connect(ep);
+	}
+	catch (std::exception& e)
+	{
+		std::string err = e.what();
+		LOG_INFO("条码秤连接失败,IP地址:" << ip.c_str() << ",错误信息:" << err.c_str());
+
+		m_errinfo = L"条码秤连接失败,请检查IP设置,IP地址:" + CLewaimaiString::UTF8ToUnicode(ip);
+		MessageBoxW(NULL, m_errinfo.c_str(), L"条码秤连接失败", MB_OK);
+
+		return;
+	}
+
+	if (1)
+	{
+		std::string data = "";
+
+		//先发送清空命令
+		data += "!0IA";
+		data += 0x0d;
+		data += 0x0a;
+
+		try
+		{
+			m_socket.write_some(boost::asio::buffer(data.c_str(), data.length()));
+		}
+		catch (const std::exception& e)
+		{
+			LOG_INFO("条码秤发送清空PLU失败,错误信息:" << e.what());
+			MessageBoxW(NULL, L"条码秤发送清空PLU失败", L"条码秤发送清空PLU失败", MB_OK);
+			m_socket.close();
+			return;
+		}
+
+		char buf[128] = { 0 };
+		boost::system::error_code error;
+
+		size_t len = m_socket.read_some(boost::asio::buffer(buf), error);
+		std::string result = buf;
+
+		LOG_INFO("发送清空PLU命令成功,返回信息:" << buf);
+	}
+
+	if (1)
+	{
+		std::string data = "";
+
+		///再清除记录
+		data += "!0HA";
+		data += 0x0d;
+		data += 0x0a;
+
+		try
+		{
+			m_socket.write_some(boost::asio::buffer(data.c_str(), data.length()));
+		}
+		catch (const std::exception& e)
+		{
+			LOG_INFO("条码秤发送清空历史记录失败,错误信息:" << e.what());
+			MessageBoxW(NULL, L"条码秤发送清空历史记录失败", L"条码秤发送清空历史记录失败", MB_OK);
+			m_socket.close();
+			return;
+		}
+
+		char buf[128] = { 0 };
+		boost::system::error_code error;
+
+		size_t len = m_socket.read_some(boost::asio::buffer(buf), error);
+		std::string result = buf;
+
+		LOG_INFO("发送清空历史记录命令成功,返回信息:" << buf);
+	}
 }

+ 6 - 0
zhipuzi_pos_windows/page/CSettingPageUI.h

@@ -32,9 +32,15 @@ public:
 
 	void HandleTongbuBiaoqiancheng();
 
+	//开始同步热键到标签秤
 	void StartTongbuRejian();
 
 	void HandleTongbuRejian();
+
+	//开始清空标签秤已有PLU
+	void StartQiongkongPLU();
+
+	void HandleQiongkongPLU();
 private:
 	std::wstring m_errinfo;
 };