diff --git a/Aucma.Core.HwPLc/Impl/MelsecPlc.cs b/Aucma.Core.HwPLc/Impl/MelsecPlc.cs index bc2b6959..edde9f02 100644 --- a/Aucma.Core.HwPLc/Impl/MelsecPlc.cs +++ b/Aucma.Core.HwPLc/Impl/MelsecPlc.cs @@ -100,7 +100,7 @@ namespace Aucma.Core.HwPLc { melsecMcNet.ConnectClose(); IsConnected = false; - Console.WriteLine($"连接失败!【{iP}:{port}】{connect.Message} "); + //Console.WriteLine($"连接失败!【{iP}:{port}】{connect.Message} "); return false; } } diff --git a/Aucma.Core.ProductOffLine/Business/offLineBusiness.cs b/Aucma.Core.ProductOffLine/Business/offLineBusiness.cs index ea9eac5a..c2f7ab18 100644 --- a/Aucma.Core.ProductOffLine/Business/offLineBusiness.cs +++ b/Aucma.Core.ProductOffLine/Business/offLineBusiness.cs @@ -84,12 +84,15 @@ namespace Aucma.Core.ProductOffLine.Business /// /// 扫码信息刷新 /// - /// - /// - /// - /// - public delegate void RefreshScanMateriaCode(string materialCode, string materialName, string spaceName, string materialType); - public event RefreshScanMateriaCode RefreshScanMateriaCodeEvent; + public delegate void RefreshScanMateriaCode(TempInfo tempInfo); + public static event RefreshScanMateriaCode? RefreshScanMateriaCodeEvent; + + + /// + /// 图表刷新 + /// + public delegate void RefreshCharts(); + public static event RefreshCharts? RefreshChartsEvent; /// /// 获取入库方向 /// @@ -101,7 +104,7 @@ namespace Aucma.Core.ProductOffLine.Business public OffLineBusiness() { MvCodeHelper.RefreshMaterialCodeStrEvent += MaterialBarScan; - // test(); + // test(); } #region 变量定义 /// @@ -115,23 +118,29 @@ namespace Aucma.Core.ProductOffLine.Business { // private static readonly log4net.ILog log = LogManager.GetLogger(typeof(OffLineBusiness)); // string result = _productOffLineServices.QueryChecked("1520870000099E2V0004"); - string result = _productOffLineServices.QueryChecked("1530080CD0098E1V1714"); - Console.WriteLine(result); - string strSave = _productOffLineServices.SaveBarcodeInfo("1520870000099E2V0004", "ILS_SORT", result.Replace("0000",""), 1); - // LogHelper.Info("成品码:1520870000099E2V0004"+strSave); + // string result = _productOffLineServices.QueryChecked("1530080CD0098E1V1714"); + // Console.WriteLine(result); + // string strSave = _productOffLineServices.SaveBarcodeInfo("1520870000099E2V0004", "ILS_SORT", result.Replace("0000",""), 1); + // LogHelper.Info("成品码:1520870000099E2V0004"+strSave); // string tt = "Y@1104@16160030000000910780@000010034895@@ @000000@000000009000004899@BCD-160C,家电下乡@@BCD-160C@皓月白-家电下乡@161601300@160@1-00版@家电下乡产品@默认@2010-09-01"; - //Task.Run(() => - //{ - // //while (true) - // //{ - // Thread.Sleep(5000); - // Random random = new Random(); - // MaterialBarScan("32160030000000912" + random.Next(100, 999), "192.168.1.20"); - // // } - - // // Thread.Sleep(1000); - // // MaterialBarScanEvent("33160030000000910780", "192.168.1.20"); - //}); + Task.Run(() => + { + //while (true) + //{ + Thread.Sleep(5000); + Random random = new Random(); + MaterialBarScan("32160030000000912" + random.Next(100, 999), "10.10.92.141"); + Thread.Sleep(3000); + Random random1 = new Random(); + MaterialBarScan("99160030000000912" + random1.Next(100, 999), "10.10.92.141"); + Thread.Sleep(3000); + Random random2 = new Random(); + MaterialBarScan("44160030000000912" + random2.Next(100, 999), "10.10.92.141"); + // } + + // Thread.Sleep(1000); + // MaterialBarScanEvent("33160030000000910780", "192.168.1.20"); + }); } public void MaterialBarScan(string code, string scannerIp) @@ -163,31 +172,50 @@ namespace Aucma.Core.ProductOffLine.Business materialType = TempOffLineInfo1.ProductCode; if (!BackResult) { + log.Info("条码:" + TempOffLineInfo1.ProductSNCode + "对接条码系统处理失败,禁止放行,流程结束"); return; } - TempOffLineInfo1.ProductRefreshFlag = true; + // TempOffLineInfo1.ProductRefreshFlag = true; // 2.更新mes数据库 BackResult = updateMesData(TempOffLineInfo1); BackResult = true; // 测试 // 3.plc放行 if (BackResult) { + bool plcResult = SendAndWaitSignal(ScannerNo, materialType); - if (plcResult) - { - // TempOffLineInfo1.MsgInfo = TempOffLineInfo1.MsgInfo + "plc放行成功"; + //if (plcResult) + //{ + // // TempOffLineInfo1.MsgInfo = TempOffLineInfo1.MsgInfo + "plc放行成功"; - //界面刷新 - // TempOffLineInfo1.ProductRefreshFlag = true; + // //界面刷新 + // // TempOffLineInfo1.ProductRefreshFlag = true; + //} + //else + //{ + // TempOffLineInfo1.MsgInfo = TempOffLineInfo1.MsgInfo + "plc放行异常"; + // TempOffLineInfo1.MsgAlarmFlag = true; + // //界面刷新 + // TempOffLineInfo1.ProductRefreshFlag = true; + //} + log.Info(String.Format("订单号{0} 订单数量{1}", TempOffLineInfo1.ProductOrderNo, TempOffLineInfo1.OrderQty)); + try + { + //刷新统计图表 + RefreshChartsEvent?.Invoke(); } - else + catch(Exception ex) { - TempOffLineInfo1.MsgInfo = TempOffLineInfo1.MsgInfo + "plc放行异常"; - TempOffLineInfo1.MsgAlarmFlag = true; - //界面刷新 - TempOffLineInfo1.ProductRefreshFlag = true; + log.Error("刷新统计图表出错:"+ex.Message.ToString()); } - log.Info(String.Format("订单号{0} 订单数量{1}", TempOffLineInfo1.ProductOrderNo, TempOffLineInfo1.OrderQty)); + } + else + { + log.Info("条码:" + TempOffLineInfo1.ProductSNCode + "更新Mes数据库失败"); + TempOffLineInfo1.MsgInfo = TempOffLineInfo1.MsgInfo + "更新Mes数据库失败"; + TempOffLineInfo1.MsgAlarmFlag = true; + //界面刷新 + RefreshScanMateriaCodeEvent(TempOffLineInfo1); } } @@ -198,15 +226,18 @@ namespace Aucma.Core.ProductOffLine.Business materialType = TempOffLineInfo2.ProductCode; if (!BackResult) { + log.Info("条码:" + TempOffLineInfo1.ProductSNCode + "对接条码系统处理失败,禁止放行,流程结束"); return; } - TempOffLineInfo2.ProductRefreshFlag = true; + // TempOffLineInfo2.ProductRefreshFlag = true; // 2.更新mes数据库 BackResult = updateMesData(TempOffLineInfo2); BackResult = true; // 3.plc放行 if (BackResult) { + + bool plcResult = SendAndWaitSignal(ScannerNo, materialType); //if (plcResult) //{ @@ -223,16 +254,33 @@ namespace Aucma.Core.ProductOffLine.Business // TempOffLineInfo2.ProductRefreshFlag = true; //} log.Info(String.Format("订单号{0} 订单数量{1}", TempOffLineInfo2.ProductOrderNo, TempOffLineInfo2.OrderQty)); + try + { + //刷新统计图表 + RefreshChartsEvent?.Invoke(); + }catch(Exception ex) + { + log.Error("刷新页面异常"+ex.Message.ToString()); + } + + + } + else + { + log.Info("条码:" + TempOffLineInfo2.ProductSNCode + "更新Mes数据库失败"); + TempOffLineInfo2.MsgInfo = TempOffLineInfo2.MsgInfo + "更新Mes数据库失败"; + TempOffLineInfo2.MsgAlarmFlag = true; + //界面刷新 + RefreshScanMateriaCodeEvent(TempOffLineInfo2); } } } catch (Exception ex) { - log.Error(ex.Message.ToString()); + log.Error("MaterialBarScanHandle异常:"+ex.Message.ToString()); } - - + } /// /// 下发plc放行并等待反馈信号 @@ -353,9 +401,10 @@ namespace Aucma.Core.ProductOffLine.Business TempOffLineInfo.MsgInfo += item.QualityDefectName; } TempOffLineInfo.MsgAlarmFlag = true; - //界面刷新 - TempOffLineInfo.ProductRefreshFlag = true; - return false; + //界面刷新 + // TempOffLineInfo.ProductRefreshFlag = true; + RefreshScanMateriaCodeEvent?.Invoke(TempOffLineInfo); + return false; } @@ -405,19 +454,20 @@ namespace Aucma.Core.ProductOffLine.Business TempOffLineInfo.ProductUseInfo = FArrayList[15];//产品用途 TempOffLineInfo.ProductCirculate = FArrayList[16];//流通特性 TempOffLineInfo.ProductCreateDate = FArrayList[17]; - #endregion - //界面刷新 - TempOffLineInfo.ProductRefreshFlag = true; - // 多码系统校验,暂不启用 + #endregion + //界面刷新 + // TempOffLineInfo.ProductRefreshFlag = true; + RefreshScanMateriaCodeEvent?.Invoke(TempOffLineInfo); + // 多码系统校验,暂不启用 // bool flag = TestBarCode(TempOffLineInfo); // if (!flag) // { // return false; // } - log.Info(TempOffLineInfo.ProductSNCode + ", 多码验证通过!"); - //2.上传条码系统 - bool resultUp = uploadSnSysytem(TempOffLineInfo); - return resultUp; + log.Info(TempOffLineInfo.ProductSNCode + ", 多码验证通过!"); + //2.上传条码系统 + bool resultUp = uploadSnSysytem(TempOffLineInfo); + return resultUp; } @@ -427,7 +477,7 @@ namespace Aucma.Core.ProductOffLine.Business #region 实体赋值 TempOffLineInfo.MsgAlarmFlag = true; - TempOffLineInfo.MsgInfo = "获取信息失败. " + BarCode + " 返回值:" + FArrayList[0].ToString(); + TempOffLineInfo.MsgInfo = "条码系统获取信息失败. " + BarCode + " 返回值:" + FArrayList[0].ToString(); TempOffLineInfo.ProductOrderNo = ""; TempOffLineInfo.ProductSaleNo = ""; TempOffLineInfo.ProductSaleLineNo = ""; @@ -448,9 +498,10 @@ namespace Aucma.Core.ProductOffLine.Business TempOffLineInfo.rfid = ""; TempOffLineInfo.sim = ""; TempOffLineInfo.number1 = ""; - #endregion - //界面刷新 - TempOffLineInfo.ProductRefreshFlag = true; + #endregion + //界面刷新 + // TempOffLineInfo.ProductRefreshFlag = true; + RefreshScanMateriaCodeEvent?.Invoke(TempOffLineInfo); return false; } @@ -459,9 +510,10 @@ namespace Aucma.Core.ProductOffLine.Business { TempOffLineInfo.MsgInfo = "获取产品条码异常:" + ex.Message; TempOffLineInfo.MsgAlarmFlag = true; - //界面刷新 - TempOffLineInfo.ProductRefreshFlag = true; - log.Info(BarCode + "条码验证异常:" + ex.Message.ToString()); + //界面刷新 + // TempOffLineInfo.ProductRefreshFlag = true; + RefreshScanMateriaCodeEvent?.Invoke(TempOffLineInfo); + log.Info(BarCode + "条码验证异常:" + ex.Message.ToString()); return false; } } @@ -498,13 +550,14 @@ namespace Aucma.Core.ProductOffLine.Business TempOffLineInfo.MsgInfo = TempOffLineInfo.MsgInfo + ",MES查询订单数据异常"; TempOffLineInfo.MsgAlarmFlag = true; //界面刷新 - TempOffLineInfo.ProductRefreshFlag = true; - // return false; + // TempOffLineInfo.ProductRefreshFlag = true; + RefreshScanMateriaCodeEvent?.Invoke(TempOffLineInfo); + // return false; } //界面刷新 - TempOffLineInfo.ProductRefreshFlag = true; - + // TempOffLineInfo.ProductRefreshFlag = true; + RefreshScanMateriaCodeEvent?.Invoke(TempOffLineInfo); return true; } else @@ -522,7 +575,8 @@ namespace Aucma.Core.ProductOffLine.Business log.Info(TempOffLineInfo.ProductSNCode + "条码重复,本地已存在,放行"); TempOffLineInfo.MsgInfo = TempOffLineInfo.MsgInfo + "条码重复,本地已存在,放行"; //界面刷新 - TempOffLineInfo.ProductRefreshFlag = true; + // TempOffLineInfo.ProductRefreshFlag = true; + RefreshScanMateriaCodeEvent?.Invoke(TempOffLineInfo); return true; // chkout:条码重复是否允许放行 //if (TempOffLineInfo.ChkOut == true) @@ -532,15 +586,18 @@ namespace Aucma.Core.ProductOffLine.Business } else { - log.Info(TempOffLineInfo.ProductSNCode + "条码重复,本地不存在,已插入,放行"); + log.Info(TempOffLineInfo.ProductSNCode + "条码重复,本地不存在,已插入,可以放行"); OffLineInfo info11 = MapperTwo(TempOffLineInfo); + // 产线 + info11.ProductLineCode = "CX_02"; _offLineInfoServices.AddAsync(info11); return true; } } TempOffLineInfo.MsgAlarmFlag = true; //界面刷新 - TempOffLineInfo.ProductRefreshFlag = true; + // TempOffLineInfo.ProductRefreshFlag = true; + RefreshScanMateriaCodeEvent?.Invoke(TempOffLineInfo); return false; } @@ -550,7 +607,8 @@ namespace Aucma.Core.ProductOffLine.Business TempOffLineInfo.MsgInfo = TempOffLineInfo.MsgInfo + ",条码系统保存接口异常"; TempOffLineInfo.MsgAlarmFlag = true; //界面刷新 - TempOffLineInfo.ProductRefreshFlag = true; + // TempOffLineInfo.ProductRefreshFlag = true; + RefreshScanMateriaCodeEvent?.Invoke(TempOffLineInfo); return false; } } @@ -559,7 +617,8 @@ namespace Aucma.Core.ProductOffLine.Business TempOffLineInfo.MsgInfo = TempOffLineInfo.MsgInfo + ",生产单号异常"; TempOffLineInfo.MsgAlarmFlag = true; //界面刷新 - TempOffLineInfo.ProductRefreshFlag = true; + // TempOffLineInfo.ProductRefreshFlag = true; + RefreshScanMateriaCodeEvent?.Invoke(TempOffLineInfo); return false; } } @@ -588,8 +647,10 @@ namespace Aucma.Core.ProductOffLine.Business if(scannerNo == 1) // 扫码器1对应的货道地址,内侧 { + log.Info(TempOffLineInfo1.ProductSNCode + ":内侧下发plc放行信号,入库方向ZR1001,放行信号ZR1003分别写:"+ direction.ToString()+"/1" + ",等待反馈"); TempOffLineInfo1.MsgInfo = TempOffLineInfo1.MsgInfo + "下发放行,"; - TempOffLineInfo1.ProductRefreshFlag = true; + RefreshScanMateriaCodeEvent(TempOffLineInfo1); + //TempOffLineInfo1.ProductRefreshFlag = true; // 写入入库方向,两条道plc地址不同 obj.plc.WriteInt16("ZR1001", direction.ToString()); // 往plc写入放行信号 @@ -597,8 +658,10 @@ namespace Aucma.Core.ProductOffLine.Business } else // 外侧 { + log.Info(TempOffLineInfo2.ProductSNCode + ":外侧下发plc放行信号,入库方向ZR1000,放行信号ZR1002分别写:" + direction.ToString() + "/1" + ",等待反馈"); TempOffLineInfo2.MsgInfo = TempOffLineInfo2.MsgInfo + "下发放行,"; - TempOffLineInfo2.ProductRefreshFlag = true; + RefreshScanMateriaCodeEvent(TempOffLineInfo2); + // TempOffLineInfo2.ProductRefreshFlag = true; // 写入入库方向,两条道plc地址不同 obj.plc.WriteInt16("ZR1000", direction.ToString()); // 往plc写入放行信号 @@ -606,7 +669,7 @@ namespace Aucma.Core.ProductOffLine.Business } - DateTime targetTime = DateTime.Now.AddSeconds(300); + DateTime targetTime = DateTime.Now.AddSeconds(18000); // 5h // 等待plc反馈信号 while (true) { @@ -622,8 +685,10 @@ namespace Aucma.Core.ProductOffLine.Business // 读取plc反馈信号 if (obj.plc.ReadInt32("ZR1003") == 2) { + log.Info(TempOffLineInfo1.ProductSNCode + "内侧plc反馈信号ZR1003读2"); TempOffLineInfo1.MsgInfo = TempOffLineInfo1.MsgInfo + "放行成功"; - TempOffLineInfo1.ProductRefreshFlag = true; + // TempOffLineInfo1.ProductRefreshFlag = true; + RefreshScanMateriaCodeEvent(TempOffLineInfo1); Console.WriteLine("收到plc放行成功"); // 清空数据 // obj.plc.WriteInt32("ZR1001", 0); @@ -639,8 +704,10 @@ namespace Aucma.Core.ProductOffLine.Business // 读取plc反馈信号 if (obj.plc.ReadInt16("ZR1002") == 2) { + log.Info(TempOffLineInfo2.ProductSNCode + "外侧plc反馈信号ZR1002读2"); TempOffLineInfo2.MsgInfo = TempOffLineInfo2.MsgInfo + "放行成功"; - TempOffLineInfo2.ProductRefreshFlag = true; + // TempOffLineInfo2.ProductRefreshFlag = true; + RefreshScanMateriaCodeEvent(TempOffLineInfo2); Console.WriteLine("收到plc放行成功"); // 清空数据 // obj.plc.WriteInt32("ZR1000", 0); diff --git a/Aucma.Core.ProductOffLine/ViewModels/IndexPageViewModel.cs b/Aucma.Core.ProductOffLine/ViewModels/IndexPageViewModel.cs index efcdafeb..89443f65 100644 --- a/Aucma.Core.ProductOffLine/ViewModels/IndexPageViewModel.cs +++ b/Aucma.Core.ProductOffLine/ViewModels/IndexPageViewModel.cs @@ -52,26 +52,41 @@ namespace Aucma.Core.ProductOffLine.ViewModels // 成品下线操作mes数据 private readonly IOffLineInfoServices? _offLineInfoServices = App.ServiceProvider.GetService(); - System.Timers.Timer timer = new System.Timers.Timer(500);//界面刷新定时器 + // System.Timers.Timer timer = new System.Timers.Timer(500);//界面刷新定时器 private readonly IBaseBomInfoServices? _baseBomInfoServices; private OffLineBusiness offLineBusiness = OffLineBusiness.Instance; private static double aaa = 100.0; int a = 0; public IndexPageViewModel() { + OffLineBusiness.RefreshScanMateriaCodeEvent += ModelToPage; + OffLineBusiness.RefreshChartsEvent += RefreshCharts; OffLineQty = "235"; _offLineInfoServices = App.ServiceProvider.GetService(); _baseBomInfoServices = App.ServiceProvider.GetService(); InitEveryDayMethod(); // 刷新界面扫码信息 - RefreshPageListen(); + // RefreshPageListen(); LoadData(); - // offLineBusiness.test(); - - - } + //Task.Run(() => + //{ + // Thread.Sleep(5000); + // InitEveryDayMethod(); + // // Thread.Sleep(5000); + // // InitEveryDayMethod(); + //}); + // offLineBusiness.test(); + } + /// + /// 刷新页面展示图表 + /// + public void RefreshCharts() + { + InitEveryDayMethod(); + AddDataGrid(); + } #region 参数定义 @@ -278,40 +293,40 @@ namespace Aucma.Core.ProductOffLine.ViewModels #region 界面刷新定时器 - public void RefreshPageListen() - { - timer.Elapsed += new System.Timers.ElapsedEventHandler(RefreshPage); - timer.AutoReset = true; - timer.Enabled = true; - timer.Start(); + //public void RefreshPageListen() + //{ + // timer.Elapsed += new System.Timers.ElapsedEventHandler(RefreshPage); + // timer.AutoReset = true; + // timer.Enabled = true; + // timer.Start(); - } + //} /// /// 定时检测两个扫码实体是否需要刷新 /// /// /// - public void RefreshPage(object source, System.Timers.ElapsedEventArgs e) - { + //public void RefreshPage(object source, System.Timers.ElapsedEventArgs e) + //{ - if (OffLineBusiness.TempOffLineInfo1.ProductRefreshFlag == true) - { - OffLineBusiness.TempOffLineInfo1.ProductRefreshFlag = false; - ModelToPage(OffLineBusiness.TempOffLineInfo1); + // if (OffLineBusiness.TempOffLineInfo1.ProductRefreshFlag == true) + // { + // OffLineBusiness.TempOffLineInfo1.ProductRefreshFlag = false; + // ModelToPage(OffLineBusiness.TempOffLineInfo1); - LoadData(); + // LoadData(); - } - else if(OffLineBusiness.TempOffLineInfo2.ProductRefreshFlag == true) - { - OffLineBusiness.TempOffLineInfo2.ProductRefreshFlag = false; - ModelToPage(OffLineBusiness.TempOffLineInfo2); + // } + // else if(OffLineBusiness.TempOffLineInfo2.ProductRefreshFlag == true) + // { + // OffLineBusiness.TempOffLineInfo2.ProductRefreshFlag = false; + // ModelToPage(OffLineBusiness.TempOffLineInfo2); - } - } + // } + //} public void ModelToPage(TempInfo tempInfo) { App.Current.Dispatcher.Invoke(() => @@ -342,151 +357,153 @@ namespace Aucma.Core.ProductOffLine.ViewModels await App.Current.Dispatcher.BeginInvoke((Action)(() => { + Achievement.Clear(); ProductionHourList = new List(); - OffLineQty = "232"; + // OffLineQty = "232"; for (int i = 8; i <= 19; i++) { ProductionHourList.Add(i + ":00"); } + //ChartValues achievement2 = new ChartValues(); + //achievement2.Add(74); + //achievement2.Add(77); + //achievement2.Add(75); + //achievement2.Add(6); + //achievement2.Add(0); + //achievement2.Add(0); + //achievement2.Add(0); + //achievement2.Add(0); + //achievement2.Add(0); + //achievement2.Add(0); + //achievement2.Add(0); + //achievement2.Add(0); + //var column2 = new ColumnSeries(); + //column2.DataLabels = true; + //column2.Title = "产量"; + //column2.Values = achievement2; + //column2.Foreground = Brushes.White; + //Achievement.Add(column2); + + //MaterialNameList.Add("BCD-162CST,炫金色,A"); + //MaterialNameList.Add("BCD-212CHG,炫金色,A"); + //MaterialNameList.Add("BCD-211CGN,星际灰,A"); + //MaterialNameList.Add("BC/BD-310NF,银河灰,A"); + //MaterialNameList.Add("BC/BD-232WD,银河灰,A"); + //MaterialNameList.Add("BC/BD-145NF,炫金色,ZS,A"); + //ChartValues achievement = new ChartValues(); + //achievement.Add(41); + //achievement.Add(37); + //achievement.Add(37); + //achievement.Add(47); + //achievement.Add(39); + //achievement.Add(19); + //var column = new ColumnSeries(); + //column.DataLabels = true; + //column.Title = "型号"; + //column.Values = achievement; + //column.Foreground = Brushes.White; + + //ModelStatistics.Add(column); + #region 小时产量统计 + List listTime = _baseBomInfoServices.getWorkTime().Result; + if (listTime == null) return; + // var aa =_offLineInfoServices.Query(x=>x.ProductScanTime>= listTime[0].startTime && x.ProductScanTime<= listTime[11].startTime) + // List hourAmount = _offLineInfoServices.QueryCharts1("CX_01"); + + List list = _offLineInfoServices.QueryCharts(listTime[0].startTime, listTime[11].startTime).Result; + + if (list == null) return; + List hourList1 = new List(); + // 当班下线数量 + int sum = 0; + foreach (ChartsByTime item in list) + { + DateTime date = DateTime.ParseExact(item.date + ":00:00", "yyyy-MM-dd/HH:mm:ss", CultureInfo.InvariantCulture); + ChartsByTimeAmount hour = new ChartsByTimeAmount(); + hour.ProductCode = item.productLineCode; + hour.ProductDate = date; + hour.ProductAmount = item.Amount; + sum += item.Amount; + hourList1.Add(hour); + } + // 当班下线数量页面赋值 + OffLineQty = sum.ToString(); + if (hourList1 == null) return; + + + var hourList = hourList1.Where(x => x.ProductCode.Equals("CX_02") && x.ProductDate >= listTime[0].startTime && x.ProductDate <= listTime[11].startTime); + + List xList = new List(); ChartValues achievement2 = new ChartValues(); - achievement2.Add(74); - achievement2.Add(77); - achievement2.Add(75); - achievement2.Add(6); - achievement2.Add(0); - achievement2.Add(0); - achievement2.Add(0); - achievement2.Add(0); - achievement2.Add(0); - achievement2.Add(0); - achievement2.Add(0); - achievement2.Add(0); + foreach (var item in hourList) + { + xList.Add(item.ProductDate.Hour.ToString() + ":00"); + achievement2.Add(item.ProductAmount); + } + var column2 = new ColumnSeries(); column2.DataLabels = true; column2.Title = "产量"; column2.Values = achievement2; column2.Foreground = Brushes.White; - Achievement.Add(column2); - - MaterialNameList.Add("BCD-162CST,炫金色,A"); - MaterialNameList.Add("BCD-212CHG,炫金色,A"); - MaterialNameList.Add("BCD-211CGN,星际灰,A"); - MaterialNameList.Add("BC/BD-310NF,银河灰,A"); - MaterialNameList.Add("BC/BD-232WD,银河灰,A"); - MaterialNameList.Add("BC/BD-145NF,炫金色,ZS,A"); + + // Achievement.Clear(); + //Achievement.Add(column2); + if (Achievement.Count > 0) + { + for (int i = 0; i < hourList.Count(); i++) + { + Achievement.FirstOrDefault().Values[i] = hourList.ElementAt(i).ProductAmount; + } + } + else + { + Achievement.Clear(); + Achievement.Add(column2); + } + + ProductionHourList = xList; + #endregion + + + #region 型号统计 + List nameList = new List(); ChartValues achievement = new ChartValues(); - achievement.Add(41); - achievement.Add(37); - achievement.Add(37); - achievement.Add(47); - achievement.Add(39); - achievement.Add(19); var column = new ColumnSeries(); + + List offList = _offLineInfoServices.QueryAsync(x => x.ProductScanTime >= listTime[0].startTime && x.ProductScanTime <= listTime[11].startTime).Result; + var modelList = offList.GroupBy(x => x.ProductModel); + + foreach (var item in modelList) + { + achievement.Add(item.Count()); + nameList.Add(item.Key); + } column.DataLabels = true; column.Title = "型号"; column.Values = achievement; column.Foreground = Brushes.White; - ModelStatistics.Add(column); - #region 小时产量统计 - // List listTime = _baseBomInfoServices.getWorkTime().Result; - // if (listTime == null) return; - // // var aa =_offLineInfoServices.Query(x=>x.ProductScanTime>= listTime[0].startTime && x.ProductScanTime<= listTime[11].startTime) - // // List hourAmount = _offLineInfoServices.QueryCharts1("CX_01"); - - // List list = _offLineInfoServices.QueryCharts(listTime[0].startTime, listTime[11].startTime).Result; - - // if (list == null) return; - // List hourList1 = new List(); - // // 当班下线数量 - // int sum = 0; - // foreach(ChartsByTime item in list) - // { - // DateTime date = DateTime.ParseExact(item.date + ":00:00", "yyyy-MM-dd/HH:mm:ss", CultureInfo.InvariantCulture); - // ChartsByTimeAmount hour = new ChartsByTimeAmount(); - // hour.ProductCode = item.productLineCode; - // hour.ProductDate = date; - // hour.ProductAmount = item.Amount; - // sum += item.Amount; - // hourList1.Add(hour); - // } - // // 当班下线数量页面赋值 - // OffLineQty = sum.ToString(); - // if (hourList1 == null) return; - - - // var hourList = hourList1.Where(x => x.ProductCode.Equals("CX_02") && x.ProductDate>= listTime[0].startTime && x.ProductDate <= listTime[11].startTime); - - // List xList = new List(); - // ChartValues achievement2 = new ChartValues(); - // foreach (var item in hourList) - // { - // xList.Add(item.ProductDate.Hour.ToString()+":00"); - // achievement2.Add(item.ProductAmount); - // } - - // var column2 = new ColumnSeries(); - // column2.DataLabels = true; - // column2.Title = "产量"; - // column2.Values = achievement2; - // column2.Foreground = Brushes.White; - - //// Achievement.Clear(); - // //Achievement.Add(column2); - // if (Achievement.Count > 0) - // { - // for (int i = 0; i < hourList.Count(); i++) - // { - // Achievement.FirstOrDefault().Values[i] = hourList.ElementAt(i).ProductAmount; - // } - // } - // else - // { - // Achievement.Add(column2); - // } - - // ProductionHourList = xList; - #endregion + // x轴 + MaterialNameList = null; + MaterialNameList = nameList; + // y轴 + if (ModelStatistics.Count > 0) + { + for (int i = 0; i < modelList.Count(); i++) + { + Achievement.FirstOrDefault().Values[i] = modelList.ElementAt(i).Count(); + } + } + else + { - // #region 型号统计 - // List nameList = new List(); - // ChartValues achievement = new ChartValues(); - // var column = new ColumnSeries(); - - // List offList = _offLineInfoServices.QueryAsync(x=>x.ProductScanTime>= listTime[0].startTime && x.ProductScanTime <= listTime[11].startTime).Result; - // var modelList = offList.GroupBy(x=>x.ProductRemark); - - // foreach(var item in modelList) - // { - // achievement.Add(item.Count()); - // nameList.Add(item.Key); - // } - // column.DataLabels = true; - // column.Title = "型号"; - // column.Values = achievement; - // column.Foreground = Brushes.White; - - // // x轴 - // MaterialNameList = null; - // MaterialNameList = nameList; - // // y轴 - // if (ModelStatistics.Count > 0) - // { - // for (int i = 0; i < modelList.Count(); i++) - // { - // Achievement.FirstOrDefault().Values[i] = modelList.ElementAt(i).Count(); - // } - - // } - // else - // { - - // ModelStatistics.Add(column); - // } - - })); - //#endregion + ModelStatistics.Add(column); + } + + })); + #endregion } //private async void InitEveryDayMethod() @@ -538,23 +555,59 @@ namespace Aucma.Core.ProductOffLine.ViewModels public void LoadData() { - OffLineInfo record = _offLineInfoServices.FirstAsync().Result; + List listTime = _baseBomInfoServices.getWorkTime().Result; + if (listTime == null) return; + List list = _offLineInfoServices.Query(x => x.ProductScanTime >= listTime[0].startTime && x.ProductScanTime <= listTime[11].endTime); + if(list==null || list.Count<=0) return; + list = list.OrderBy(x=>x.ProductScanTime).ToList(); + // OffLineInfo record = _offLineInfoServices.FirstAsync().Result; Application.Current.Dispatcher.Invoke(() => { - ListItems.Insert(0, new TempInfo() + foreach(OffLineInfo record in list) { - No = ListItems.Count + 1, - ProductOrderNo = record.ProductOrderNo, - ProductSNCode = record.ProductSNCode.Substring(0, record.ProductSNCode.Length - 3) + new Random().Next(100, 1000).ToString(), - ProductModel = record.ProductModel, - ProductRemark = record.ProductRemark, - QualityResult = "成功", - ProductScanTime = DateTime.Now - }); + ListItems.Insert(0, new TempInfo() + { + No = ListItems.Count + 1, + ProductOrderNo = record.ProductOrderNo, + ProductSNCode = record.ProductSNCode, + ProductModel = record.ProductModel, + ProductRemark = record.ProductRemark, + QualityResult = "成功", + ProductScanTime = record.ProductScanTime, + }); + } + }); } + public void AddDataGrid() + { + List listTime = _baseBomInfoServices.getWorkTime().Result; + if (listTime == null) return; + List list = _offLineInfoServices.Query(x => x.ProductScanTime >= listTime[0].startTime && x.ProductScanTime <= listTime[11].endTime); + if (list == null || list.Count <= 0) return; + OffLineInfo record = list.OrderByDescending(x => x.ProductScanTime).FirstOrDefault(); + //OffLineInfo record = _offLineInfoServices.FirstAsync(x=>x.ProductScanTime).Result; + if(record.ProductSNCode!= ListItems[0].ProductSNCode && record.ProductSNCode != ListItems[1].ProductSNCode) + { + Application.Current.Dispatcher.Invoke(() => + { + ListItems.Insert(0, new TempInfo() + { + No = ListItems.Count + 1, + ProductOrderNo = record.ProductOrderNo, + ProductSNCode = record.ProductSNCode, + ProductModel = record.ProductModel, + ProductRemark = record.ProductRemark, + QualityResult = "成功", + ProductScanTime = record.ProductScanTime, + }); + + }); + } + + } } diff --git a/Aucma.Core.ProductOffLine/ViewModels/MainWindowViewModel.cs b/Aucma.Core.ProductOffLine/ViewModels/MainWindowViewModel.cs index a147747a..24be931b 100644 --- a/Aucma.Core.ProductOffLine/ViewModels/MainWindowViewModel.cs +++ b/Aucma.Core.ProductOffLine/ViewModels/MainWindowViewModel.cs @@ -19,7 +19,14 @@ namespace Aucma.Core.ProductOffLine.ViewModels { public partial class MainWindowViewModel : ObservableObject { - + #region 委托定义 + /// + /// 历史记录图表刷新 + /// + public delegate void RefreshCharts(); + public static event RefreshCharts? RefreshChartsEvent; + #endregion + private static readonly log4net.ILog log = LogManager.GetLogger(typeof(MainWindowViewModel)); private IndexPageView firstPage = new IndexPageView();//首页 private StatisticsPageView recordPage = new StatisticsPageView(); // 统计页面 @@ -52,6 +59,7 @@ namespace Aucma.Core.ProductOffLine.ViewModels Task.Run(() => { Thread.Sleep(2000); + //MvCodeHelper1.DeviceListAcq();//获取创建设备 // MvCodeHelper1.StartGrab(); // 开启触发扫码接收数据 Business.MvCodeHelper.Shell(); @@ -63,8 +71,21 @@ namespace Aucma.Core.ProductOffLine.ViewModels //MvCodeHelper1.DeviceListAcq();//获取创建设备 // MvCodeHelper1.StartGrab(); // 开启触发扫码接收数据 Business.MvCodeHelper.Liner(); + }); + + // 心跳线程 + //Task.Run(() => + //{ + // while (true) + // { + // //扫码器心跳监测并重连 + // MvCodeHelper.JudgeShellIsConnectedAndReConnect(); + // Thread.Sleep(2000); + // } + //}); + } catch (Exception ex) { @@ -74,15 +95,15 @@ namespace Aucma.Core.ProductOffLine.ViewModels } #endregion - public void RefreshScanner(string ip) + public void RefreshScanner(string ip,bool flag) { if (ip == "外侧") { - Scanner1State(true); + Scanner1State(flag); ; } else if(ip == "内侧") { - Scanner2State(true); + Scanner2State(flag); } } #region 设备状态刷新 @@ -245,6 +266,7 @@ namespace Aucma.Core.ProductOffLine.ViewModels UserContent = firstPage; break; case "RecordPage": + RefreshChartsEvent?.Invoke(); UserContent = recordPage; break; case "QualityPage": diff --git a/Aucma.Core.ProductOffLine/ViewModels/StatisticsPageViewModel.cs b/Aucma.Core.ProductOffLine/ViewModels/StatisticsPageViewModel.cs index c8deecc2..14ada99d 100644 --- a/Aucma.Core.ProductOffLine/ViewModels/StatisticsPageViewModel.cs +++ b/Aucma.Core.ProductOffLine/ViewModels/StatisticsPageViewModel.cs @@ -13,6 +13,7 @@ using System.Text; using System.Threading.Tasks; using System.Windows; using System.Windows.Documents; +using static System.Windows.Forms.VisualStyles.VisualStyleElement.Tab; namespace Aucma.Core.ProductOffLine.ViewModels { @@ -23,6 +24,7 @@ namespace Aucma.Core.ProductOffLine.ViewModels public StatisticsPageViewModel() { _offLineInfoServices = App.ServiceProvider.GetService(); + MainWindowViewModel.RefreshChartsEvent += LoadData; LoadData(); } @@ -31,13 +33,16 @@ namespace Aucma.Core.ProductOffLine.ViewModels #region 加载DataGrid数据 private void LoadData() { + ListItems.Clear(); + TotalItem.Clear(); Application.Current.Dispatcher.Invoke(() => { - List list = _offLineInfoServices.QueryAsync().Result - .OrderByDescending(x => x.ProductScanTime) - .ToList(); - if (list != null) - { + List list = _offLineInfoServices.QueryAsync(x => x.ProductScanTime >= DateTime.Now.AddDays(-2)).Result; + if(list==null || list.Count<=0) return; + list = list.OrderByDescending(x => x.ProductScanTime).ToList(); + + if (list != null) + { foreach (OffLineInfo record in list) { @@ -59,7 +64,7 @@ namespace Aucma.Core.ProductOffLine.ViewModels } - } + } }); } #endregion @@ -96,45 +101,64 @@ namespace Aucma.Core.ProductOffLine.ViewModels [RelayCommand] private void ExecQuery(object obj) { - //List list; - //var result = (StatisticModel)obj; - //if (string.IsNullOrEmpty(result.BeginTime) && string.IsNullOrEmpty(result.EndTime)) - //{ - // list = await _codeBindingRecordServices.QueryAllByTime(null, null); - //} - //else if (string.IsNullOrEmpty(result.BeginTime)) - //{ - // list = await _codeBindingRecordServices.QueryAllByTime(result.BeginTime, null); - //} - //else if (string.IsNullOrEmpty(result.EndTime)) - //{ - // list = await _codeBindingRecordServices.QueryAllByTime(null, result.EndTime); - //} - //else - //{ - // DateTime theBeginTime = Convert.ToDateTime(result.BeginTime); - // DateTime theEndTime = Convert.ToDateTime(result.EndTime); - // if (theBeginTime > theEndTime) - // { - // MessageBox.Show("结束时间要大于开始时间!"); - // return; - // } - // list = await _codeBindingRecordServices.QueryAllByTime(result.BeginTime, result.EndTime); - //} + List list = null; + var result = (StatisticModel)obj; + if (string.IsNullOrEmpty(result.BeginTime) && string.IsNullOrEmpty(result.EndTime)) + { + return; + } + else if (string.IsNullOrEmpty(result.BeginTime)) + { + DateTime EndTime = Convert.ToDateTime(result.EndTime); + + list = _offLineInfoServices.QueryAsync(x => x.ProductScanTime <= EndTime.AddDays(1)).Result; + } + else if (string.IsNullOrEmpty(result.EndTime)) + { + DateTime BeginTime = Convert.ToDateTime(result.BeginTime); + list = _offLineInfoServices.QueryAsync(x => x.ProductScanTime >= BeginTime).Result; + } + else + { + DateTime BeginTime = Convert.ToDateTime(result.BeginTime); + DateTime EndTime = Convert.ToDateTime(result.EndTime); + if (BeginTime > EndTime) + { + MessageBox.Show("结束时间要大于开始时间!"); + return; + } + list = _offLineInfoServices.QueryAsync(x => x.ProductScanTime >= BeginTime && x.ProductScanTime<= EndTime.AddDays(1)).Result; + } - //if (list != null) - //{ - // System.Windows.Application.Current.Dispatcher.Invoke((Action)(async () => - // { - // MaterialDataGrid.Clear(); - // foreach (CodeBindingRecord item in list) - // { - // MaterialDataGrid.Add(new ReaderInfo() { No = item.ObjId, BoxCode = item.BoxCode, BoxName = item.BoxName, ProductCode = item.ProductCode, BindingResult = item.BindingResult, RecordTime = item.RecordTime1.ToString() }); - // } + if (list != null) + { + list = list.OrderByDescending(x => x.ProductScanTime).ToList(); + + ListItems.Clear(); + TotalItem.Clear(); + Application.Current.Dispatcher.Invoke(() => + { + foreach (OffLineInfo record in list) + { - // })); - //} + ListItems.Add(new TempInfo() { No = ListItems.Count + 1, ProductOrderNo = record.ProductOrderNo, ProductSNCode = record.ProductSNCode, ProductModel = record.ProductModel, ProductRemark = record.ProductRemark, ProductScanTime = record.ProductScanTime }); + + } + var countByProductModel = list.GroupBy(x => x.ProductModel).Select(group => new + { + ProductCode = group.First().ProductCode, + ProductRemark = group.First().ProductRemark, + ProductModel = group.Key, + Count = group.Count() + }).ToList(); + foreach (var item in countByProductModel) + { + + TotalItem.Add(new TempInfo() { No = TotalItem.Count + 1, ProductCode = item.ProductCode, ProductModel = item.ProductModel, ProductRemark = item.ProductRemark, Count = item.Count }); + } + }); + } } #endregion } diff --git a/Aucma.Core.ProductOffLine/Views/IndexPageView.xaml b/Aucma.Core.ProductOffLine/Views/IndexPageView.xaml index d68e2fa9..99b3f38e 100644 --- a/Aucma.Core.ProductOffLine/Views/IndexPageView.xaml +++ b/Aucma.Core.ProductOffLine/Views/IndexPageView.xaml @@ -313,7 +313,7 @@ - + diff --git a/Aucma.Core.ProductOffLine/Views/MainWindow.xaml b/Aucma.Core.ProductOffLine/Views/MainWindow.xaml index 0247f58d..8384ca9a 100644 --- a/Aucma.Core.ProductOffLine/Views/MainWindow.xaml +++ b/Aucma.Core.ProductOffLine/Views/MainWindow.xaml @@ -45,8 +45,8 @@ - - + + diff --git a/Aucma.Core.ProductOffLine/Views/StatisticsPageView.xaml b/Aucma.Core.ProductOffLine/Views/StatisticsPageView.xaml index e490ffa4..d392e0ee 100644 --- a/Aucma.Core.ProductOffLine/Views/StatisticsPageView.xaml +++ b/Aucma.Core.ProductOffLine/Views/StatisticsPageView.xaml @@ -149,7 +149,7 @@ - + diff --git a/Aucma.Core.ProductOffLine/appsettings.json b/Aucma.Core.ProductOffLine/appsettings.json index a34e0593..7fd823cf 100644 --- a/Aucma.Core.ProductOffLine/appsettings.json +++ b/Aucma.Core.ProductOffLine/appsettings.json @@ -208,12 +208,14 @@ "ScannerServer": [ { "Id": 1, - "Ip": "10.10.92.140", + //"Ip": "10.10.92.140", + "Ip": "10.10.92.121", "Name": "内侧扫码器1" }, { "Id": 2, - "Ip": "10.10.92.141", + // "Ip": "10.10.92.141", + "Ip": "10.10.92.122", "Name": "外侧扫码器2" } ],