Browse Source

小修改

liuhao 3 years ago
parent
commit
16916f090f

BIN
TEST_Prj/Test/.vs/Test/v15/.suo


BIN
TEST_Prj/Test/.vs/Test/v15/Server/sqlite3/storage.ide


BIN
TEST_Prj/Test/.vs/Test/v15/Server/sqlite3/storage.ide-shm


BIN
TEST_Prj/Test/.vs/Test/v15/Server/sqlite3/storage.ide-wal


+ 71 - 6
TEST_Prj/Test/Test/Form1.cs

@@ -212,6 +212,21 @@ namespace Test
         {
             return !((s.Poll(10, SelectMode.SelectRead) && (s.Available == 0)) || !s.Connected);
         }
+        void SendMsgdata(string dataStr)
+        {
+            // string strMsg = "服务器" + "\r\n" + "   -->" + dataStr + "\r\n";
+            string strMsg = dataStr;
+            byte[] arrMsg = System.Text.Encoding.UTF8.GetBytes(dataStr); // 将要发送的字符串转换成Utf-8字节数组;
+            byte[] arrSendMsg = new byte[arrMsg.Length];
+            foreach (Socket s in dict.Values)
+            {
+                s.Send(arrMsg);
+
+            }
+
+            ShowMsg("发送消息为:" + strMsg);
+            ShowMsg("  群发完毕!!\r\n");
+        }
         void RecMsg(object sokConnectionparn)
         {
             Socket sokClient = sokConnectionparn as Socket;
@@ -261,6 +276,7 @@ namespace Test
                                 }
                                 // s.Send(arrMsg);
                             }
+                            str_check(strMsg);
                             //ShowMsg("发送消息为:" + strMsg);
                         }
 
@@ -475,6 +491,7 @@ namespace Test
         public string GetProductType(string findstr,string barCode)
         {
             string v_id = ""; string v_res_id = "";
+            bool findflag = false;
             string sql = string.Format("select * from user where "+ findstr + " = '" + barCode + "'");
           
             MySqlCommand Cmd = new MySqlCommand(sql, conn);
@@ -482,15 +499,16 @@ namespace Test
             //MySqlDataReader find_db = Cmd.ExecuteReader();
             if (find_db.Read())
             {
-                 v_id = find_db["商品名称"].ToString();
-                 v_res_id = find_db["商品价格"].ToString();
+                v_id = find_db["商品名称"].ToString();
+                v_res_id = find_db["商品价格"].ToString();
                 //int v_timing = Convert.ToInt32(db["timing"]);
-                conn.Close();
+                //conn.Close();//
                 Console.WriteLine("v_id" + v_id);
                 Console.WriteLine("v_res_id" + v_res_id);
-
+                findflag = true;
             }
-           
+            conn.Close();
+
             conn.Open();//打开通道,建立连接,可能出现异常,使用try catch语句
             try {
 
@@ -499,11 +517,58 @@ namespace Test
             {
                 MessageBox.Show(ex.Message);
             }
+            if (findflag)
+            {
+                return "名称:" + v_id + "\r\n" + "价格:" + v_res_id + "\r\n";
+            }
+            else return "";
 
-            return "名称:"+ v_id+"\r\n"+"价格:"+ v_res_id+"\r\n";
+        }
+        public static string user_SubstringEx(string sourse, string startstr, string endstr)
+        {
+            string result = string.Empty;
+            int startindex, endindex;
+            try
+            {
+                startindex = sourse.IndexOf(startstr);
+                if (startindex == -1)
+                    return result;
+                string tmpstr = sourse.Substring(startindex + startstr.Length);
+                endindex = tmpstr.IndexOf(endstr);
+                if (endindex == -1)
+                    return result;
+                result = tmpstr.Remove(endindex);
+            }
+            catch (Exception ex)
+            {
+                Console.WriteLine("MidStrEx Err:" + ex.Message);
+            }
 
+            return result;
         }
 
+        public void str_check(string str)
+        {
+            string finddata = "";
+
+            if (str.Contains("esp_send:") == true)//下位机的数据流
+            {
+                if (str.Contains("find:") == true)//查询数据库
+                {
+                    string findStr = user_SubstringEx(str,"find:","\r\n");
+                    if (findStr != "")
+                    {
+                        Console.WriteLine(findStr);
+                        finddata = GetProductType("序列号", findStr);//数据库中查询
+                        SendMsgdata(finddata);
+                    }
+                }
+            }
+            else if (str.Contains("app_send:") == true)//app的数据
+            {
+
+            }
+        }
         /// 获取当前系统时间的方法    
         /// 当前时间     
         static DateTime GetCurrentTime()

+ 336 - 0
TEST_Prj/Test/Test/bin/Debug/Log.txt

@@ -31,3 +31,339 @@
 数据:http://www.cmsoft.cn
 
 客户端异常一个封锁操作被对 WSACancelBlockingCall 的调用中断。
+客户端异常一个封锁操作被对 WSACancelBlockingCall 的调用中断。
+客户端异常一个封锁操作被对 WSACancelBlockingCall 的调用中断。
+客户端连接成功!
+客户端连接成功!
+客户端:192.168.1.179:63688 时间:2021/10/12 16:29:46
+数据:esp_send:find:1234
+
+客户端:192.168.1.179:63688 时间:2021/10/12 16:35:22
+数据:esp_send:find:1234
+
+客户端:192.168.1.179:63688 时间:2021/10/12 16:35:27
+数据:esp_send:find:1234
+
+客户端:192.168.1.179:63688 时间:2021/10/12 16:35:29
+数据:esp_send:find:1234
+
+客户端:192.168.1.179:63688 时间:2021/10/12 16:35:29
+数据:esp_send:find:1234
+
+客户端:192.168.1.179:63688 时间:2021/10/12 16:35:30
+数据:esp_send:find:1234
+
+客户端:192.168.1.179:63688 时间:2021/10/12 16:36:00
+数据:esp_send:find:1234
+
+客户端:192.168.1.179:63688 时间:2021/10/12 16:36:01
+数据:esp_send:find:1234
+
+客户端:192.168.1.179:63688 时间:2021/10/12 16:36:02
+数据:esp_send:find:1234
+
+客户端:192.168.1.179:63688 时间:2021/10/12 16:36:02
+数据:esp_send:find:1234
+
+客户端:192.168.1.179:63688 时间:2021/10/12 16:36:03
+数据:esp_send:find:1234
+
+客户端:192.168.1.179:63688 时间:2021/10/12 16:36:03
+数据:esp_send:find:1234
+
+客户端:192.168.1.179:63688 时间:2021/10/12 16:36:03
+数据:esp_send:find:1234
+
+客户端:192.168.1.179:63688 时间:2021/10/12 16:36:03
+数据:esp_send:find:1234
+
+客户端:192.168.1.179:63688 时间:2021/10/12 16:36:03
+数据:esp_send:find:1234
+
+客户端:192.168.1.179:63688 时间:2021/10/12 16:36:03
+数据:esp_send:find:1234
+
+客户端:192.168.1.179:63688 时间:2021/10/12 16:36:04
+数据:esp_send:find:1234
+
+客户端连接成功!
+客户端:192.168.1.179:62456 时间:2021/10/12 16:37:24
+数据:esp_send:find:1234
+
+
+异常了:Fatal error encountered during command execution.
+客户端连接成功!
+客户端:192.168.1.179:62457 时间:2021/10/12 16:37:55
+数据:esp_send:find:1234
+
+
+异常了:Connection must be valid and open.
+客户端连接成功!
+客户端:192.168.1.179:52371 时间:2021/10/12 16:40:34
+数据:esp_send:find:1234
+
+
+发送消息为:名称:饼干
+价格:52.6
+
+  群发完毕!!
+
+客户端:192.168.1.179:52371 时间:2021/10/12 16:40:40
+数据:esp_send:find:1234
+
+
+发送消息为:名称:饼干
+价格:52.6
+
+  群发完毕!!
+
+客户端:192.168.1.179:52371 时间:2021/10/12 16:40:45
+数据:esp_send:find:1234
+
+
+发送消息为:名称:饼干
+价格:52.6
+
+  群发完毕!!
+
+客户端:192.168.1.179:52371 时间:2021/10/12 16:40:54
+数据:esp_send:find:1234
+
+
+发送消息为:名称:饼干
+价格:52.6
+
+  群发完毕!!
+
+客户端:192.168.1.179:52371 时间:2021/10/12 16:40:59
+数据:esp_send:find:12345
+
+
+发送消息为:
+  群发完毕!!
+
+客户端:192.168.1.179:52371 时间:2021/10/12 16:41:02
+数据:esp_send:find:12345
+
+
+发送消息为:
+  群发完毕!!
+
+客户端:192.168.1.179:52371 时间:2021/10/12 16:41:10
+数据:esp_send:find:8888777
+
+
+发送消息为:名称:梨子
+价格:7.5
+
+  群发完毕!!
+
+客户端:192.168.1.179:52371 时间:2021/10/12 16:41:13
+数据:esp_send:find:8888777
+
+
+发送消息为:名称:梨子
+价格:7.5
+
+  群发完毕!!
+
+客户端:192.168.1.179:52371 时间:2021/10/12 16:41:14
+数据:esp_send:find:8888777
+
+
+发送消息为:名称:梨子
+价格:7.5
+
+  群发完毕!!
+
+客户端:192.168.1.179:52371 时间:2021/10/12 16:41:22
+数据:esp_send:find:1234
+
+
+发送消息为:名称:饼干
+价格:52.6
+
+  群发完毕!!
+
+客户端连接成功!
+客户端:192.168.1.179:52373 时间:2021/10/12 16:41:26
+数据:esp_send:find:1234
+
+
+发送消息为:名称:饼干
+价格:52.6
+
+  群发完毕!!
+
+客户端连接成功!
+客户端:192.168.1.179:52379 时间:2021/10/12 16:42:32
+数据:esp_send:find:1234
+
+
+发送消息为:名称:饼干
+价格:52.6
+
+  群发完毕!!
+
+客户端:192.168.1.179:52379 时间:2021/10/12 16:42:33
+数据:esp_send:find:1234
+
+
+发送消息为:名称:饼干
+价格:52.6
+
+  群发完毕!!
+
+客户端:192.168.1.179:52379 时间:2021/10/12 16:42:38
+数据:esp_send:find:8888777
+
+
+发送消息为:名称:梨子
+价格:7.5
+
+  群发完毕!!
+
+客户端:192.168.1.179:52379 时间:2021/10/12 16:42:39
+数据:esp_send:find:8888777
+
+
+发送消息为:名称:梨子
+价格:7.5
+
+  群发完毕!!
+
+客户端:192.168.1.179:52379 时间:2021/10/12 16:42:41
+数据:esp_send:find:8888777
+
+
+发送消息为:名称:梨子
+价格:7.5
+
+  群发完毕!!
+
+客户端:192.168.1.179:52379 时间:2021/10/12 16:42:42
+数据:esp_send:find:8888777
+
+
+发送消息为:名称:梨子
+价格:7.5
+
+  群发完毕!!
+
+客户端:192.168.1.179:52379 时间:2021/10/12 16:42:43
+数据:esp_send:find:8888777
+
+
+发送消息为:名称:梨子
+价格:7.5
+
+  群发完毕!!
+
+客户端:192.168.1.179:52379 时间:2021/10/12 16:42:44
+数据:esp_send:find:8888777
+
+
+发送消息为:名称:梨子
+价格:7.5
+
+  群发完毕!!
+
+客户端:192.168.1.179:52379 时间:2021/10/12 16:42:44
+数据:esp_send:find:8888777
+
+
+发送消息为:名称:梨子
+价格:7.5
+
+  群发完毕!!
+
+客户端:192.168.1.179:52379 时间:2021/10/12 16:42:45
+数据:esp_send:find:8888777
+
+
+发送消息为:名称:梨子
+价格:7.5
+
+  群发完毕!!
+
+客户端:192.168.1.179:52379 时间:2021/10/12 16:42:45
+数据:esp_send:find:8888777
+
+
+发送消息为:名称:梨子
+价格:7.5
+
+  群发完毕!!
+
+客户端:192.168.1.179:52379 时间:2021/10/12 16:42:46
+数据:esp_send:find:8888777
+
+
+发送消息为:名称:梨子
+价格:7.5
+
+  群发完毕!!
+
+客户端:192.168.1.179:52379 时间:2021/10/12 16:42:46
+数据:esp_send:find:8888777
+
+
+发送消息为:名称:梨子
+价格:7.5
+
+  群发完毕!!
+
+客户端:192.168.1.179:52379 时间:2021/10/12 16:42:47
+数据:esp_send:find:8888777
+
+
+发送消息为:名称:梨子
+价格:7.5
+
+  群发完毕!!
+
+客户端:192.168.1.179:52379 时间:2021/10/12 16:42:47
+数据:esp_send:find:8888777
+
+
+发送消息为:名称:梨子
+价格:7.5
+
+  群发完毕!!
+
+客户端:192.168.1.179:52379 时间:2021/10/12 16:42:48
+数据:esp_send:find:8888777
+
+
+发送消息为:名称:梨子
+价格:7.5
+
+  群发完毕!!
+
+客户端:192.168.1.179:52379 时间:2021/10/12 16:42:48
+数据:esp_send:find:8888777
+
+
+发送消息为:名称:梨子
+价格:7.5
+
+  群发完毕!!
+
+客户端:192.168.1.179:52379 时间:2021/10/12 16:42:49
+数据:esp_send:find:8888777
+
+
+发送消息为:名称:梨子
+价格:7.5
+
+  群发完毕!!
+
+客户端:192.168.1.179:52379 时间:2021/10/12 16:42:49
+数据:esp_send:find:8888777
+
+
+发送消息为:名称:梨子
+价格:7.5
+
+  群发完毕!!
+

BIN
TEST_Prj/Test/Test/bin/Debug/Test.exe


BIN
TEST_Prj/Test/Test/bin/Debug/Test.pdb


BIN
TEST_Prj/Test/Test/obj/Debug/Test.exe


BIN
TEST_Prj/Test/Test/obj/Debug/Test.pdb