wanghan hace 3 meses
padre
commit
03d07d601a

+ 7 - 7
LogForceTestApp.Modules.MainModule/ViewModels/KBWindowViewModel.cs

@@ -165,7 +165,7 @@ namespace LogoForceTestApp.Modules.MainModule.ViewModels
                 }
                 catch (ObjectDisposedException ex)
                 {
-                    _logger.Information("KB_Main:" + ex);
+                    _logger.Error("KB_Main:" + ex);
                 }
                 finally
                 {
@@ -230,7 +230,7 @@ namespace LogoForceTestApp.Modules.MainModule.ViewModels
             }
             catch (Exception ex)
             {
-                _logger.Information("KB_ShowOutWork:" + ex);
+                _logger.Error("KB_ShowOutWork:" + ex);
             }
         }
         public IEnumerable<ISeries> Series12 { get; set; }
@@ -342,7 +342,7 @@ namespace LogoForceTestApp.Modules.MainModule.ViewModels
             }
             catch (Exception ex)
             {
-                _logger.Information("KB_ShowQuality:" + ex);
+                _logger.Error("KB_ShowQuality:" + ex);
             }
         }
         #region 生产问题
@@ -601,7 +601,7 @@ namespace LogoForceTestApp.Modules.MainModule.ViewModels
             }
             catch (Exception ex)
             {
-                _logger.Information("KB_ShowHouse:" + ex);
+                _logger.Error("KB_ShowHouse:" + ex);
             }
         }
         public IEnumerable<ISeries> Series13 { get; set; }
@@ -944,7 +944,7 @@ namespace LogoForceTestApp.Modules.MainModule.ViewModels
             }
             catch (Exception ex)
             {
-                _logger.Information("KB_ShowProcess:" + ex);
+                _logger.Error("KB_ShowProcess:" + ex);
             }
         }
 
@@ -1054,7 +1054,7 @@ namespace LogoForceTestApp.Modules.MainModule.ViewModels
             }
             catch (Exception ex)
             {
-                _logger.Information("KB_ShowOrder:"+ex);
+                _logger.Error("KB_ShowOrder:"+ex);
             }
         }
         #endregion
@@ -1078,7 +1078,7 @@ namespace LogoForceTestApp.Modules.MainModule.ViewModels
             }
             catch (Exception ex)
             {
-                _logger.Information("KB_ShowNowProcess:" + ex);
+                _logger.Error("KB_ShowNowProcess:" + ex);
             }
         }
         #endregion

+ 84 - 56
LogForceTestApp.Modules.MainModule/ViewModels/MainPageViewModel.cs

@@ -58,6 +58,7 @@ using static SkiaSharp.HarfBuzz.SKShaper;
 using System.Windows.Forms;
 using Application = System.Windows.Application;
 using LogoForceTestApp.Modules.MainModule.Views;
+using HslCommunication.BasicFramework;
 
 namespace LogoForceTestApp.Modules.MainModule.ViewModels
 {
@@ -1152,7 +1153,8 @@ namespace LogoForceTestApp.Modules.MainModule.ViewModels
                                 }
                                 catch (Exception ex)
                                 {
-                                    WriteLog("FIX1:" + ex.Message, LogType.Error);
+                                    WriteLog("FIX1:" + ex.Message, LogType.Error); 
+                                    _logger.Error("FIX1:" + ex);
                                 }
                             }
                         }
@@ -1226,6 +1228,7 @@ namespace LogoForceTestApp.Modules.MainModule.ViewModels
                                 catch (Exception ex)
                                 {
                                     WriteLog("FIX2:" + ex.Message, LogType.Error);
+                                    _logger.Error("FIX2:" + ex);
                                 }
                             }
                         }
@@ -1299,6 +1302,7 @@ namespace LogoForceTestApp.Modules.MainModule.ViewModels
                                 catch (Exception ex)
                                 {
                                     WriteLog("FIX3:" + ex.Message, LogType.Error);
+                                    _logger.Error("FIX3:" + ex);
                                 }
                             }
                         }
@@ -1308,7 +1312,8 @@ namespace LogoForceTestApp.Modules.MainModule.ViewModels
                 }
                 catch (Exception ex)
                 {
-                    WriteLog($"TCPReceived:{ex.Message}");
+                    WriteLog($"TCPReceived:{ex.Message}",LogType.Error);
+                    _logger.Error("TCPReceived:" + ex);
                 }
                 return EasyTask.CompletedTask;
             };
@@ -1451,6 +1456,7 @@ namespace LogoForceTestApp.Modules.MainModule.ViewModels
                         catch (Exception ex)
                         {
                             WriteLog("TEST1:" + ex.Message, LogType.Error);
+                            _logger.Error("TEST1:" + ex);
                         }
                     }
                     else
@@ -1473,6 +1479,7 @@ namespace LogoForceTestApp.Modules.MainModule.ViewModels
                         catch (Exception ex)
                         {
                             WriteLog("TEST2:" + ex.Message, LogType.Error);
+                            _logger.Error("TEST2:" + ex);
                         }
                     }
                 }
@@ -1508,6 +1515,7 @@ namespace LogoForceTestApp.Modules.MainModule.ViewModels
                         catch (Exception ex)
                         {
                             WriteLog("TEST3:" + ex.Message, LogType.Error);
+                            _logger.Error("TEST3:" + ex);
                         }
                     }
                 }
@@ -1538,6 +1546,7 @@ namespace LogoForceTestApp.Modules.MainModule.ViewModels
                         catch (Exception ex)
                         {
                             WriteLog("TEST4:" + ex.Message, LogType.Error);
+                            _logger.Error("TEST4:" + ex);
                         }
                     }
                 }
@@ -1565,17 +1574,19 @@ namespace LogoForceTestApp.Modules.MainModule.ViewModels
                 catch (Exception ex)
                 {
                     WriteLog("Timer:" + ex.Message, LogType.Error);
+                    _logger.Error("Timer:" + ex);
                 }
                 await Task.Delay(1000);
             }
         }
 
-        
+
         public void ProcessFinish(object sender, StateEventArgs e)
         {
             try
             {
                 var list = _repository.GetFirstDefault<ProStatus>(c => c.OrdNoS == Order);//查一个值
+                Thread.Sleep(500);
                 if (list != null)
                 {
                     list.RealityS++;
@@ -1591,7 +1602,7 @@ namespace LogoForceTestApp.Modules.MainModule.ViewModels
                     _repository.Update(allnumbers);
                 }
                 ra++;
-                _logger.Information("当天实际产量:"+ra.ToString());
+                _logger.Information("当天实际产量:" + ra.ToString());
 
                 Quest(Order);
 
@@ -1605,6 +1616,7 @@ namespace LogoForceTestApp.Modules.MainModule.ViewModels
             catch (Exception ex)
             {
                 WriteLog("ProcessFinish:" + ex.Message, LogType.Error);
+                _logger.Error("ProcessFinish:" + ex);
             }
         }
         string plannum; double plan;
@@ -1625,75 +1637,87 @@ namespace LogoForceTestApp.Modules.MainModule.ViewModels
                         plannum = list.FAuxQty.ToString();
                         plan = Math.Round(Convert.ToDouble(plannum));
                         WriteLog("切换订单成功");
-                        try
+
+                        var ps = _repository.GetFirstDefault<ProStatus>(c => c.OrdNoS == Order);
+                        if (ps == null)
                         {
-                            var ps = _repository.GetFirstDefault<ProStatus>(c => c.OrdNoS == Order);
-                            if (ps == null)
+                            var outp = new ProStatus()
                             {
-                                var outp = new ProStatus()
-                                {
-                                    Id = Guid.NewGuid(),
-                                    OrdNoS = Order,
-                                    PlanS = plan,
-                                    RealityS = 0,
-                                    OkS = 0,
-                                    NgS = 0,
-                                    ErrS = 0
-                                };
-                                _repository.Add(outp);
-                                //
-                                //打印产品码
-                                var t_pda = customRepo.GetAllQuery<t_PDABarCodeSign>(c => c.FBillNo == Order);
-                                if (t_pda != null)
-                                {
-                                    for (int i = 0; i < t_pda.Count; i++)
-                                    {
-                                        fbarcode.Add(t_pda[i].FBarCode);
-                                        string id = string.Empty;
-                                        foreach (var item in tcpService.SocketClients.GetClients())
-                                        {
-                                            if (item.IP == "192.168.10.15")
-                                            {
-                                                id = item.Id;
-                                                tcpService.Send(id, "print:" + fbarcode[i]+":");
-                                            }
-                                        }
-                                    }
-                                }
-                                //
-                                var allnumbers = _repository.GetFirstDefault<AllNumber>(c => c.DateA == DateTime.Today);
-                                if (allnumbers != null)
-                                {
-                                    allnumbers.PlanA = allnumbers.PlanA + plan;
-                                    _repository.Update(allnumbers);
-                                }
+                                Id = Guid.NewGuid(),
+                                OrdNoS = Order,
+                                PlanS = plan,
+                                RealityS = 0,
+                                OkS = 0,
+                                NgS = 0,
+                                ErrS = 0
+                            };
+                            _repository.Add(outp);
+                            //
+                            Task.Factory.StartNew(PrintCode, TaskCreationOptions.LongRunning);
+
+                            //
+                            var allnumbers = _repository.GetFirstDefault<AllNumber>(c => c.DateA == DateTime.Today);
+                            if (allnumbers != null)
+                            {
+                                allnumbers.PlanA = allnumbers.PlanA + plan;
+                                _repository.Update(allnumbers);
                             }
                         }
-                        catch (Exception ex)
-                        {
-                            WriteLog("OrderEnter2:" + ex.Message, LogType.Error);
-                        }
+
                     }
                     else
                     {
                         WriteLog("订单错误", LogType.Error);
                     }
-
-
                 }
                 catch (Exception ex)
                 {
                     WriteLog("OrderEnter1:" + ex.Message, LogType.Error);
+                    _logger.Error("OrderEnter1:" + ex);
                 }
 
             }
             catch (Exception ex)
             {
-                WriteLog("OrderEnter3:" + ex.Message, LogType.Error);
+                WriteLog("OrderEnter2:" + ex.Message, LogType.Error);
+                _logger.Error("OrderEnter2:" + ex);
+            }
+        }
+
+        private void PrintCode()
+        {
+            try
+            {
+                //打印产品码
+                var customRepo = new CustomRepository();
+                var t_pda = customRepo.GetAllQuery<t_PDABarCodeSign>(c => c.FBillNo == Order);
+                if (t_pda != null)
+                {
+                    for (int i = 0; i < t_pda.Count; i++)
+                    {
+                        fbarcode.Add(t_pda[i].FBarCode);
+                        string id = string.Empty;
+                        foreach (var item in tcpService.SocketClients.GetClients())
+                        {
+                            if (item.IP == "192.168.10.15")//15
+                            {
+                                id = item.Id;
+                                Thread.Sleep(500);
+                                tcpService.Send(id, "print:" + fbarcode[i] + ":");
+                            }
+                        }
+                    }
+                    WriteLog("产品码传输完毕");
+                }
+            }
+            catch (Exception ex)
+            {
+                WriteLog("PrintCode:" + ex.Message, LogType.Error);
+                _logger.Error("PrintCode:" + ex);
             }
+
         }
 
-        
         private void UploadOutWork()
         {
             var list = _repository.GetFirstDefault<OutofWork>(c => c.DateOutWork == DateTime.Today);
@@ -1748,7 +1772,7 @@ namespace LogoForceTestApp.Modules.MainModule.ViewModels
             }
         }
 
-        
+
         public void SendPro(string id, string name)
         {
             try
@@ -1768,6 +1792,7 @@ namespace LogoForceTestApp.Modules.MainModule.ViewModels
             catch (Exception ex)
             {
                 WriteLog("SendPro:" + ex.Message, LogType.Error);
+                _logger.Error("SendPro:" + ex);
             }
         }
         string p1 = null, p2 = null, p3 = null, p4 = null, p5 = null, p6 = null, p7 = null,
@@ -2561,6 +2586,7 @@ namespace LogoForceTestApp.Modules.MainModule.ViewModels
                 catch (Exception ex)
                 {
                     WriteLog("RecordOneMessage14:" + ex.Message, LogType.Error);
+                    _logger.Error("RecordOneMessage14:" + ex);
                 }
 
             }));
@@ -2625,6 +2651,7 @@ namespace LogoForceTestApp.Modules.MainModule.ViewModels
                 catch (ObjectDisposedException ex)
                 {
                     WriteLog("Timer_Elapsed:" + ex.Message, LogType.Error);
+                    _logger.Error("Timer_Elapsed:" + ex);
                 }
                 finally
                 {
@@ -2679,9 +2706,9 @@ namespace LogoForceTestApp.Modules.MainModule.ViewModels
                                 }
                             }
                         }
-                        catch (Exception)
+                        catch (Exception ex)
                         {
-
+                            _logger.Error("Timer_Elapsed2.1:" + ex);
                         }
                     }
 
@@ -2732,6 +2759,7 @@ namespace LogoForceTestApp.Modules.MainModule.ViewModels
                 catch (ObjectDisposedException ex)
                 {
                     WriteLog("Timer_Elapsed2:" + ex.Message, LogType.Error);
+                    _logger.Error("Timer_Elapsed2:" + ex);
                 }
                 finally
                 {
@@ -2759,11 +2787,11 @@ namespace LogoForceTestApp.Modules.MainModule.ViewModels
                     {
                         a = type;
                     }
-
                 }
                 catch (ObjectDisposedException ex)
                 {
                     WriteLog("Timer_Elapsed3:" + ex.Message, LogType.Error);
+                    _logger.Error("Timer_Elapsed3:" + ex);
                 }
                 finally
                 {