Эх сурвалжийг харах

回传等到时间问题解决

zackhua 6 сар өмнө
parent
commit
fc09f55a6d

+ 2 - 2
ZLPlugin_LisPacs_MR/Properties/AssemblyInfo.cs

@@ -4,12 +4,12 @@ using System.Runtime.InteropServices;
 // General Information about an assembly is controlled through the following 
 // set of attributes. Change these attribute values to modify the information
 // associated with an assembly.
-[assembly: AssemblyTitle("合单项目解决,时间格式解决")]
+[assembly: AssemblyTitle("时间格式解决,回传提示解决")]
 [assembly: AssemblyDescription("")]
 [assembly: AssemblyConfiguration("")]
 [assembly: AssemblyCompany("zlsoft")]
 [assembly: AssemblyProduct("ZLPlugin_LisPacs_MR")]
-[assembly: AssemblyCopyright("Copyright ©  2024-1.0.1.6")]
+[assembly: AssemblyCopyright("Copyright ©  2024-1.0.1.7")]
 [assembly: AssemblyTrademark("")]
 [assembly: AssemblyCulture("")]
 

+ 38 - 0
ZLPlugin_LisPacs_MR/SocketClient.cs

@@ -126,6 +126,44 @@ namespace ZLPlugin_LisPacs_MR
 
 
         }
+
+        /// <summary>
+        /// 循环接收消息  直到有数据
+        /// </summary>
+        public void WhileReceive()
+        {
+            byte[] buffer = new byte[1024*10];
+            int receivedBytes = 0;
+            var begintime = DateTime.Now.Ticks;
+            TimeSpan timeSpan = new TimeSpan();
+            bool flag = true;
+            try
+            {
+                Log.Info("WhileReceive 开始接收消息》》");
+                while (flag)
+                {
+                    // 只循环 20 秒  
+                    timeSpan = new TimeSpan(DateTime.Now.Ticks - begintime);
+                    if (timeSpan.TotalSeconds > 20)
+                    {
+                        flag = false;
+                    }
+                    //传递一个byte数组,用于接收数据。length表示接收了多少字节的数据
+                    receivedBytes = _ClientSocket.Receive(buffer);
+                    if (receivedBytes > 0)
+                    {
+                        Message = Encoding.Default.GetString(buffer, 0, receivedBytes);//只将接收到的数据进行转化
+                        Log.Info("WhileReceive 返回消息》》"+Message);
+                        break;
+                    }
+                }
+            }
+            catch (Exception ex)
+            {
+                Log.Info("接收消息时报错"+ex.Message);
+            }
+        }
+
         /// <summary>
         /// 发送消息到服务端
         /// </summary>

+ 11 - 0
ZLPlugin_LisPacs_MR/Tools.cs

@@ -27,6 +27,17 @@ namespace ZLPlugin_LisPacs_MR
             return longValue.ToString("X").Substring(0, 16);
         }
 
+        public static string Generate16CharGUID()
+        {
+            // 生成Guid
+            Guid guid = Guid.NewGuid();
+
+            // 将Guid转换为字符串并截取前16位
+            string randomString = guid.ToString().Substring(0, 16);
+            Log.Info("Generate16CharGUID=" + randomString);
+            return randomString;
+        }
+
         //获取ip地址
         public static string GetHostIp()
         {

+ 21 - 59
ZLPlugin_LisPacs_MR/clsPlugin.cs

@@ -160,43 +160,24 @@ namespace ZLPlugin_LisPacs_MR
                 Recordset rd = LisPacs_MR_Bll.GetMZPostJson(lngClinicID, code, hrType, totalPrice.ToString(), code);
                 string json = Tools.RecordsetToJson(rd);
                 clientSend.Send(json);
-                //Tools.Delay(10000, 0);
-
-                bool status = true; int i = 0;
-                var begintime = DateTime.Now.Ticks;
-                TimeSpan timeSpan = new TimeSpan();
                 Log.Info("初始化完成!");
-                while (status)
+                try
                 {
-                    timeSpan = new TimeSpan(DateTime.Now.Ticks - begintime);
-                    //Thread.Sleep(3000);
-                    try
-                    {
-                        clientSend.Receive();
-                    }
-                    catch (Exception e)
-                    {
-                    Log.Info("接收失败!" + e.Message);
-                    }
-                    if (timeSpan.TotalSeconds > 10 || !string.IsNullOrWhiteSpace(SocketClient.Message))
-                    {
-                        status = false;
-                    }
-                    Log.Info("timeSpan.TotalSeconds:" + timeSpan.TotalSeconds);
-                    i++;
-
+                    clientSend.WhileReceive();
+                }
+                catch (Exception e)
+                {
+                Log.Info("接收失败!" + e.Message);
                 }
-                Log.Info("22222" + SocketClient.Message);
-
                 if (!string.IsNullOrWhiteSpace(SocketClient.Message))
                 {
-                    Log.Info(SocketClient.Message);
                     ResultsEx rex = new ResultsEx();
                     rex = JSON.JsonToObject<ResultsEx>(Tools.FormatStr(SocketClient.Message), Encoding.UTF8);
                     if (rex.ResultCode == 2)//有互认
                     {
+                        
+                        clientSend.WhileReceive();
                         MessageBox.Show("回传数据至his!");
-                        clientSend.Receive();
                         //SocketClient.Message = null;
                         return SaveData(waittingdate, lngPatientID, lngClinicID, listlis, listpacs, 1);
                     }
@@ -267,11 +248,8 @@ namespace ZLPlugin_LisPacs_MR
                        }
                      #endregion
                  }*/
-                string hisApplyId =Tools.Generate16CharUUID();
-                Log.Info("hisApplyId=" + hisApplyId);
+               
                 string patientSource = ""; //病人来源
-
-
                 string code = "";  // 又算开单唯一id
                 string billProjectNames = "";  //开单项目名称
                 List<Codes> listlis;
@@ -279,6 +257,8 @@ namespace ZLPlugin_LisPacs_MR
                 LisPacs_MR_Bll.GetTreatmentId(ss_list, out code, out listlis, out listpacs,out billProjectNames);
                 Log.Info("code=="+code);
                 Log.Info("billProjectNames==" + billProjectNames);
+                string hisApplyId = Tools.Generate16CharGUID();
+                Log.Info("hisApplyId=" + hisApplyId);
                 Recordset rd = new Recordset();
                 decimal totalPrice = 0;
                 int hrType = 0;
@@ -356,32 +336,16 @@ namespace ZLPlugin_LisPacs_MR
                 string json = Tools.RecordsetToJson(rd);
                 Log.Info("save发送json ===" + json);
                 socketClient.Send(json);
-                //Tools.Delay(waittingdate, 0);
-                bool status = true; int i = 0;
-                var begintime = DateTime.Now.Ticks;
-                TimeSpan timeSpan = new TimeSpan();
-                Log.Info("初始化完成!");
-                while (status)
+                
+                try
                 {
-                    timeSpan = new TimeSpan(DateTime.Now.Ticks - begintime);
-                    //Thread.Sleep(3000);
-                    try
-                    {
-                        socketClient.Receive();
-                    }
-                    catch (Exception e)
-                    {
-                        Log.Info("接收失败!"+ e.Message);
-                    }
-                    if (timeSpan.TotalSeconds > 10 || !string.IsNullOrWhiteSpace(SocketClient.Message))
-                    {
-                        status = false;
-                    }
-                    Log.Info("timeSpan.TotalSeconds:" + timeSpan.TotalSeconds);
-                    i++;
-
+                    socketClient.WhileReceive();
+                }
+                catch (Exception e)
+                {
+                    Log.Info("接收失败!"+ e.Message);
                 }
-                Log.Info("22222"+SocketClient.Message);
+                    
                 Log.Info("退出循环!");
                 Log.Info("listlis count!" + listlis.Count);
                 Log.Info("listpacs count!" + listpacs.Count);
@@ -391,12 +355,10 @@ namespace ZLPlugin_LisPacs_MR
                     rex = JSON.JsonToObject<ResultsEx>(Tools.FormatStr(SocketClient.Message), Encoding.UTF8);
                     if (rex.ResultCode == 2)//有互认
                     {
+                        socketClient.WhileReceive();
                         MessageBox.Show("回传数据至his!");
-                        socketClient.Receive();
-                        //  SocketClient.Message = null;
-                        Log.Info("2:" + SocketClient.Message);
                         SaveData(waittingdate, lngPatientID, lngClinicID, listlis, listpacs, -1);
-                            //保存开单项目
+                        //保存开单项目
                         int ii = LisPacs_MR_Bll.InsertHuRenBillProject(Dns.GetHostName(), lngPatientID, billProjectNames, 999, Tools.GetHostIp(), Infos.UserInfo.ID.ToString(), hisApplyId, hrType.ToString(), Infos.UserInfo.姓名, patientSource);
                         Log.Info("开单状态="+ ii);
                         socketClient.Close();