Forráskód Böngészése

界面操作添加委托

刘彬 2 napja
szülő
commit
cf33251f5a
1 módosított fájl, 289 hozzáadás és 239 törlés
  1. 289 239
      Core/Management.cs

+ 289 - 239
Core/Management.cs

@@ -43,8 +43,8 @@ namespace DefaultEdit.Core
         private ObservableCollection<RfidInfo> _RfIDList=new ObservableCollection<RfidInfo>();
         public ObservableCollection<RfidInfo> RfIDList { get => _RfIDList; set { SetProperty(ref _RfIDList, value); } }
 
-      //  private ObservableCollection<RfidInfo> _RuningData=new ObservableCollection<RfidInfo>();
-      //  public ObservableCollection<RfidInfo> RuningData { get => _RuningData; set => _RuningData = value; }
+        //  private ObservableCollection<RfidInfo> _RuningData=new ObservableCollection<RfidInfo>();
+        //  public ObservableCollection<RfidInfo> RuningData { get => _RuningData; set => _RuningData = value; }
 
         private CurrConfig _currConfig = new CurrConfig();
 
@@ -103,11 +103,13 @@ namespace DefaultEdit.Core
             stopwatchs[ 0 ] = new Stopwatch();
             stopwatchs[ 1 ] = new Stopwatch();
             stopwatchs[ 2 ] = new Stopwatch();
-            for ( int i = 0; i < 6; i++ )
+            App.Current.Dispatcher.Invoke(( System.Action ) delegate
             {
-                CurrStationRfid.Add("");
-            }
-
+                for ( int i = 0; i < 6; i++ )
+                {
+                    CurrStationRfid.Add("");
+                }
+            });
             RuningToWorkEvent += Management_RuningToWorkEvent; ;
             WorkThread = new Thread(DataBridging);
             WorkThread.Name = "Plc读取";
@@ -125,313 +127,361 @@ namespace DefaultEdit.Core
         }
         private async void Management_RuningToWorkEvent(string key, bool value)
         {
-            switch ( key )
+            try
             {
-                case "1工位离心开始":
-                    if ( value )
-                    {
-                        stopwatchs[ 0 ].Restart();
-                        if ( RfIDList.Count != 0 )
+                switch ( key )
+                {
+                    case "1工位离心开始":
+                        if ( value )
                         {
-                            int index= RfIDList.ToList().FindIndex(x => x.StationId == 1);
-                            if ( index != -1 )
-                            {
-                                RfIDList[ index ].StationId = 2;
-                                CurrStationRfid[ 1 ] = RfIDList[ index ].Rfid;
-                                RfIDList[index].State = "离心中";
-                                LogHelper.Info(RfIDList[ index ].Rfid + " 1工位离心开始");
-                            }
-                            else
+                            stopwatchs[ 0 ].Restart();
+                            if ( RfIDList.Count != 0 )
                             {
+                                int index= RfIDList.ToList().FindIndex(x => x.StationId == 1);
+                                if ( index != -1 )
+                                {
+                                    App.Current.Dispatcher.Invoke(( System.Action ) delegate
+                                    {
+                                        RfIDList[ index ].StationId = 2;
+                                        CurrStationRfid[ 1 ] = RfIDList[ index ].Rfid;
+                                        RfIDList[ index ].State = "离心中";
+                                    });
+                                    LogHelper.Info(RfIDList[ index ].Rfid + " 1工位离心开始");
+                                }
+                                else
+                                {
 
-                                LogHelper.Info(" 1工位离心开始");
-                            }
-                            index = RfIDList.ToList().FindIndex(x => x.StationId == 1);
-                            if ( index != -1 )
-                            {
-                                RfIDList[ index ].StationId = 2;
-                                CurrStationRfid[ 2 ] = RfIDList[ index ].Rfid;
-                                RfIDList[index].State = "离心中";
-                                LogHelper.Info(RfIDList[ index ].Rfid + " 1工位离心开始");
+                                    LogHelper.Info(" 1工位离心开始");
+                                }
+                                index = RfIDList.ToList().FindIndex(x => x.StationId == 1);
+                                if ( index != -1 )
+                                {
+                                    App.Current.Dispatcher.Invoke(( System.Action ) delegate
+                                    {
+                                        RfIDList[ index ].StationId = 2;
+                                        CurrStationRfid[ 2 ] = RfIDList[ index ].Rfid;
+                                        RfIDList[ index ].State = "离心中";
+                                    });
+                                    LogHelper.Info(RfIDList[ index ].Rfid + " 1工位离心开始");
+                                }
+                                else
+                                {
+
+                                    LogHelper.Info(" 1工位离心开始");
+                                }
                             }
                             else
                             {
 
                                 LogHelper.Info(" 1工位离心开始");
                             }
+                            LogHelper.Debuginfo("1工位离心开始已置位");
                         }
                         else
                         {
-
-                            LogHelper.Info(" 1工位离心开始");
+                            LogHelper.Debuginfo("1工位离心开始已复位");
                         }
-                        LogHelper.Debuginfo("1工位离心开始已置位");
-                    }
-                    else
-                    {
-                        LogHelper.Debuginfo("1工位离心开始已复位");
-                    }
-                    break;
-                case "1工位离心完成":
-                    if ( value )
-                    {
-                        stopwatchs[ 0 ].Stop();
-                        if ( RfIDList.Count != 0 )
+                        break;
+                    case "1工位离心完成":
+                        if ( value )
                         {
-                            int index= RfIDList.ToList().FindIndex(x => x.StationId == 2);
-                            if ( index != -1 )
-                            {
-                                RfIDList[ index ].StationId = 3;
-                                RfIDList[index].State = "离心完成";
-                                LogHelper.Info(CurrStationRfid[ 1 ] + " 1工位离心完成");
-                            }
-                            else
+                            stopwatchs[ 0 ].Stop();
+                            if ( RfIDList.Count != 0 )
                             {
-                                LogHelper.Info(" 1工位离心完成");
+                                int index= RfIDList.ToList().FindIndex(x => x.StationId == 2);
+                                if ( index != -1 )
+                                {
+                                    App.Current.Dispatcher.Invoke(( System.Action ) delegate
+                                    {
+                                        RfIDList[ index ].StationId = 3;
+                                        RfIDList[ index ].State = "离心完成";
+                                    });
+                                    LogHelper.Info(CurrStationRfid[ 1 ] + " 1工位离心完成");
+                                }
+                                else
+                                {
+                                    LogHelper.Info(" 1工位离心完成");
 
-                            }
+                                }
 
-                            index = RfIDList.ToList().FindIndex(x => x.StationId == 2);
-                            if ( index != -1 )
-                            {
-                                RfIDList[ index ].StationId = 3;
-                                RfIDList[index].State = "离心完成";
-                                LogHelper.Info(CurrStationRfid[ 2 ] + " 1工位离心完成");
+                                index = RfIDList.ToList().FindIndex(x => x.StationId == 2);
+                                if ( index != -1 )
+                                {
+                                    App.Current.Dispatcher.Invoke(( System.Action ) delegate
+                                    {
+                                        RfIDList[ index ].StationId = 3;
+                                        RfIDList[ index ].State = "离心完成";
+                                    });
+                                    LogHelper.Info(CurrStationRfid[ 2 ] + " 1工位离心完成");
+                                }
+                                else
+                                {
+                                    LogHelper.Info(" 1工位离心完成");
+
+                                }
+                                App.Current.Dispatcher.Invoke(( System.Action ) delegate
+                                {
+                                    CurrStationRfid[ 1 ] = "";
+                                    CurrStationRfid[ 2 ] = "";
+                                });
                             }
                             else
                             {
                                 LogHelper.Info(" 1工位离心完成");
 
                             }
-                            CurrStationRfid[ 1 ] = "";
-                            CurrStationRfid[ 2 ] = "";
+                            LogHelper.Debuginfo("1工位离心完成已置位");
                         }
                         else
                         {
-                            LogHelper.Info(" 1工位离心完成");
-
+                            LogHelper.Debuginfo("1工位离心完成已复位");
                         }
-                        LogHelper.Debuginfo("1工位离心完成已置位");
-                    }
-                    else
-                    {
-                        LogHelper.Debuginfo("1工位离心完成已复位");
-                    }
-                    break;
-                case "2工位离心开始":
-                    if ( value )
-                    {
-                        stopwatchs[ 1 ].Restart();
-                        if ( RfIDList.Count != 0 )
+                        break;
+                    case "2工位离心开始":
+                        if ( value )
                         {
-                            int index = RfIDList.ToList().FindIndex(x => x.StationId == 3);
-                            if ( index != -1 )
+                            stopwatchs[ 1 ].Restart();
+                            if ( RfIDList.Count != 0 )
                             {
-                                RfIDList[ index ].StationId = 4;
-                                CurrStationRfid[ 3 ] = RfIDList[ index ].Rfid;
-                                RfIDList[ index ].State = "离心中";
-                                LogHelper.Info(RfIDList[ index ].Rfid + " 2工位离心开始");
-                            }
-                            else
-                            {
-                                LogHelper.Info(" 2工位离心开始");
-                            }
-                            index = RfIDList.ToList().FindIndex(x => x.StationId == 1);
-                            if ( index != -1 )
-                            {
-                                RfIDList[ index ].StationId = 4;
-                                CurrStationRfid[ 4 ] = RfIDList[ index ].Rfid;
-                                RfIDList[ index ].State = "离心中";
-                                LogHelper.Info(RfIDList[ index ].Rfid + " 2工位离心开始");
+                                int index = RfIDList.ToList().FindIndex(x => x.StationId == 3);
+                                if ( index != -1 )
+                                {
+                                    App.Current.Dispatcher.Invoke(( System.Action ) delegate
+                                    {
+                                        RfIDList[ index ].StationId = 4;
+                                        CurrStationRfid[ 3 ] = RfIDList[ index ].Rfid;
+                                        RfIDList[ index ].State = "离心中";
+                                    });
+                                    LogHelper.Info(RfIDList[ index ].Rfid + " 2工位离心开始");
+                                }
+                                else
+                                {
+                                    LogHelper.Info(" 2工位离心开始");
+                                }
+                                index = RfIDList.ToList().FindIndex(x => x.StationId == 1);
+                                if ( index != -1 )
+                                {
+                                    App.Current.Dispatcher.Invoke(( System.Action ) delegate
+                                    {
+                                        RfIDList[ index ].StationId = 4;
+                                        CurrStationRfid[ 4 ] = RfIDList[ index ].Rfid;
+                                        RfIDList[ index ].State = "离心中";
+                                    });
+                                    LogHelper.Info(RfIDList[ index ].Rfid + " 2工位离心开始");
+                                }
+                                else
+                                {
+                                    LogHelper.Info(" 2工位离心开始");
+                                }
                             }
                             else
                             {
                                 LogHelper.Info(" 2工位离心开始");
                             }
+                            LogHelper.Debuginfo("2工位离心开始已置位");
                         }
                         else
                         {
-                            LogHelper.Info(" 2工位离心开始");
+                            LogHelper.Debuginfo("2工位离心开始已复位");
                         }
-                        LogHelper.Debuginfo("2工位离心开始已置位");
-                    }
-                    else
-                    {
-                        LogHelper.Debuginfo("2工位离心开始已复位");
-                    }
-                    break;
-                case "2工位离心完成":
-                    if ( value )
-                    {
-                        stopwatchs[ 1 ].Stop();
-                        if ( RfIDList.Count != 0 )
+                        break;
+                    case "2工位离心完成":
+                        if ( value )
                         {
-                            int index= RfIDList.ToList().FindIndex(x => x.StationId == 4);
-                            if ( index != -1 )
+                            stopwatchs[ 1 ].Stop();
+                            if ( RfIDList.Count != 0 )
                             {
-                                RfIDList[ index ].StationId = 5;
-                                RfIDList[ index ].State = "离心完成";
-                                LogHelper.Info(CurrStationRfid[ 3 ] + " 2工位离心完成");
+                                int index= RfIDList.ToList().FindIndex(x => x.StationId == 4);
+                                if ( index != -1 )
+                                {
+                                    App.Current.Dispatcher.Invoke(( System.Action ) delegate
+                                    {
+                                        RfIDList[ index ].StationId = 5;
+                                        RfIDList[ index ].State = "离心完成";
+                                    });
+                                    LogHelper.Info(CurrStationRfid[ 3 ] + " 2工位离心完成");
+                                }
+                                else
+                                {
+                                    LogHelper.Info(" 2工位离心完成");
+                                }
+                                index = RfIDList.ToList().FindIndex(x => x.StationId == 4);
+                                if ( index != -1 )
+                                {
+                                    App.Current.Dispatcher.Invoke(( System.Action ) delegate
+                                    {
+                                        RfIDList[ index ].StationId = 5;
+                                        RfIDList[ index ].State = "离心完成";
+                                    });
+                                    LogHelper.Info(CurrStationRfid[ 4 ] + " 1工位离心完成");
+                                }
+                                else
+                                {
+                                    LogHelper.Info(" 1工位离心完成");
+
+                                }
+                                App.Current.Dispatcher.Invoke(( System.Action ) delegate
+                                {
+                                    CurrStationRfid[ 3 ] = "";
+                                    CurrStationRfid[ 4 ] = "";
+                                });
                             }
                             else
                             {
                                 LogHelper.Info(" 2工位离心完成");
                             }
-                            index = RfIDList.ToList().FindIndex(x => x.StationId == 4);
-                            if ( index != -1 )
-                            {
-                                RfIDList[ index ].StationId = 5;
-                                RfIDList[ index ].State = "离心完成";
-                                LogHelper.Info(CurrStationRfid[ 4 ] + " 1工位离心完成");
-                            }
-                            else
-                            {
-                                LogHelper.Info(" 1工位离心完成");
-
-                            }
-                            CurrStationRfid[ 3 ] = "";
-                            CurrStationRfid[ 4 ] = "";
+                            LogHelper.Debuginfo("2工位离心完成已置位");
                         }
                         else
                         {
-                            LogHelper.Info(" 2工位离心完成");
+                            LogHelper.Debuginfo("2工位离心完成已复位");
                         }
-                        LogHelper.Debuginfo("2工位离心完成已置位");
-                    }
-                    else
-                    {
-                        LogHelper.Debuginfo("2工位离心完成已复位");
-                    }
-                    break;
-                case "脱模开始":
-                    if ( value )
-                    {
-                        LogHelper.Info(CurrConfig.Rfid + " 脱模开始");
-                        PlateInPlace(CurrConfig.Rfid);
-                        LogHelper.Debuginfo("脱模开始已置位");
-                    }
-                    else
-                    {
-                        LogHelper.Debuginfo("脱模开始已复位");
-                    }
-                    break;
-                case "脱模完成":
-                    if ( value )
-                    {
-
-                        LogHelper.Info(CurrConfig.Rfid + " 脱模完成");
-                        if ( processDataModels.Count != 0 )
+                        break;
+                    case "脱模开始":
+                        if ( value )
                         {
-                            ProcessDataModel  data=processDataModels.ToList().Find(it=>it.BoardId== CurrConfig.Rfid);
-                            if ( data != null )
-                            {
-                                PrintInfo(data, "手动");
-                            }
-                            else 
-                            {
-                                LogHelper.Info(" 网板信息没找到");
-                            }
+                            LogHelper.Info(CurrConfig.Rfid + " 脱模开始");
+                            PlateInPlace(CurrConfig.Rfid);
+                            LogHelper.Debuginfo("脱模开始已置位");
                         }
-                        LogHelper.Debuginfo("脱模完成已置位");
-                    }
-                    else
-                    {
-                        LogHelper.Debuginfo("脱模完成已复位");
-                    }
-                    break;
-                case "固化开始":
-                    if ( value )
-                    {
-                        stopwatchs[ 2 ].Restart();
-                        if ( RfIDList.Count != 0 )
+                        else
                         {
-                            int index= RfIDList.ToList().FindIndex(x => x.StationId ==5 );
-                            if ( index != -1 )
+                            LogHelper.Debuginfo("脱模开始已复位");
+                        }
+                        break;
+                    case "脱模完成":
+                        if ( value )
+                        {
+
+                            LogHelper.Info(CurrConfig.Rfid + " 脱模完成");
+                            if ( processDataModels.Count != 0 )
                             {
-                                RfIDList[ index ].StationId = 6;
-                                CurrStationRfid[ 5 ] = RfIDList[ index ].Rfid;
-                                RfIDList[ index ].State = "固化中";
-                                LogHelper.Info(RfIDList[ index ].Rfid + " 固化开始");
+                                ProcessDataModel  data=processDataModels.ToList().Find(it=>it.BoardId== CurrConfig.Rfid);
+                                if ( data != null )
+                                {
+                                    PrintInfo(data, "手动");
+                                }
+                                else
+                                {
+                                    LogHelper.Info(" 网板信息没找到");
+                                }
                             }
-                            else
+                            LogHelper.Debuginfo("脱模完成已置位");
+                        }
+                        else
+                        {
+                            LogHelper.Debuginfo("脱模完成已复位");
+                        }
+                        break;
+                    case "固化开始":
+                        if ( value )
+                        {
+                            stopwatchs[ 2 ].Restart();
+                            if ( RfIDList.Count != 0 )
                             {
-                                LogHelper.Info(" 固化开始");
-                            }
+                                int index= RfIDList.ToList().FindIndex(x => x.StationId ==5 );
+                                if ( index != -1 )
+                                {
+                                    App.Current.Dispatcher.Invoke(( System.Action ) delegate
+                                    {
+                                        RfIDList[ index ].StationId = 6;
+                                        CurrStationRfid[ 5 ] = RfIDList[ index ].Rfid;
+                                        RfIDList[ index ].State = "固化中";
+                                    });
+                                   LogHelper.Info(RfIDList[ index ].Rfid + " 固化开始");
+                                }
+                                else
+                                {
+                                    LogHelper.Info(" 固化开始");
+                                }
 
-                            index = RfIDList.ToList().FindIndex(x => x.StationId == 5);
-                            if ( index != -1 )
-                            {
-                                RfIDList[ index ].StationId = 6;
-                                CurrStationRfid[ 6 ] = RfIDList[ index ].Rfid;
-                                RfIDList[ index ].State = "固化中";
-                                LogHelper.Info(RfIDList[ index ].Rfid + " 固化开始");
+                                index = RfIDList.ToList().FindIndex(x => x.StationId == 5);
+                                if ( index != -1 )
+                                {
+                                    App.Current.Dispatcher.Invoke(( System.Action ) delegate
+                                    {
+                                        RfIDList[ index ].StationId = 6;
+                                        CurrStationRfid[ 6 ] = RfIDList[ index ].Rfid;
+                                        RfIDList[ index ].State = "固化中";
+                                    });
+                                    LogHelper.Info(RfIDList[ index ].Rfid + " 固化开始");
+                                }
+                                else
+                                {
+                                    LogHelper.Info(" 固化开始");
+                                }
                             }
                             else
                             {
                                 LogHelper.Info(" 固化开始");
                             }
+                            LogHelper.Debuginfo("固化开始已置位");
                         }
                         else
                         {
-                            LogHelper.Info(" 固化开始");
+                            LogHelper.Debuginfo("固化开始已复位");
                         }
-                        LogHelper.Debuginfo("固化开始已置位");
-                    }
-                    else
-                    {
-                        LogHelper.Debuginfo("固化开始已复位");
-                    }
-                    break;
-                case "固化完成":
-                    if ( value )
-                    {
-                        stopwatchs[ 2 ].Stop();
-                        if ( RfIDList.Count != 0 )
+                        break;
+                    case "固化完成":
+                        if ( value )
                         {
-                            int index= RfIDList.ToList().FindIndex(x => x.StationId ==6 );
-                            if ( index != -1 )
+                            stopwatchs[ 2 ].Stop();
+                            if ( RfIDList.Count != 0 )
                             {
-                                RfIDList.RemoveAt(index);
-                                LogHelper.Info(RfIDList[ index ].Rfid + " 固化完成");
-                            }
-                            else
-                            {
-                                LogHelper.Info(" 固化完成");
-                            }
+                                int index= RfIDList.ToList().FindIndex(x => x.StationId ==6 );
+                                if ( index != -1 )
+                                {
+                                    App.Current.Dispatcher.Invoke(( System.Action ) delegate
+                                    {
+                                        RfIDList.RemoveAt(index);
+                                    });
+                                    LogHelper.Info(RfIDList[ index ].Rfid + " 固化完成");
+                                }
+                                else
+                                {
+                                    LogHelper.Info(" 固化完成");
+                                }
 
-                            index = RfIDList.ToList().FindIndex(x => x.StationId == 6);
-                            if ( index != -1 )
-                            {
-                                RfIDList[index].StationId=100;
-                                LogHelper.Info(RfIDList[ index ].Rfid + " 固化完成");
+                                index = RfIDList.ToList().FindIndex(x => x.StationId == 6);
+                                if ( index != -1 )
+                                {
+                                    App.Current.Dispatcher.Invoke(( System.Action ) delegate
+                                    {
+                                        RfIDList[ index ].StationId = 100;
+                                    });
+                                    LogHelper.Info(RfIDList[ index ].Rfid + " 固化完成");
+                                }
+                                else
+                                {
+                                    LogHelper.Info(" 固化完成");
+                                }
+                                //CurrStationRfid[5] = RfIDList[index].Rfid;
+                                //CurrStationRfid[6] = RfIDList[index].Rfid;
+                                int hour= DateTime.Now.Hour;
+                                ProduceData[ hour ] = ProduceData[ hour ] + 2;
+                                for ( int i = hour + 1; i < ProduceData.Length; i++ )
+                                {
+                                    ProduceData[ i ] = 0;
+                                }
+                                ProduceDataToChangeEvent?.Invoke();
                             }
                             else
                             {
                                 LogHelper.Info(" 固化完成");
                             }
-                            //CurrStationRfid[5] = RfIDList[index].Rfid;
-                            //CurrStationRfid[6] = RfIDList[index].Rfid;
-                            int hour= DateTime.Now.Hour;
-                            ProduceData[ hour ] = ProduceData[ hour ] + 2;
-                            for ( int i = hour + 1; i < ProduceData.Length; i++ )
-                            {
-                                ProduceData[ i ] = 0;
-                            }
-                            ProduceDataToChangeEvent?.Invoke();
+                            LogHelper.Debuginfo("固化完成已置位");
                         }
                         else
                         {
-                            LogHelper.Info(" 固化完成");
+                            LogHelper.Debuginfo("固化完成已复位");
                         }
-                        LogHelper.Debuginfo("固化完成已置位");
-                    }
-                    else
-                    {
-                        LogHelper.Debuginfo("固化完成已复位");
-                    }
-                    break;
-                default:
-                    break;
+                        break;
+                    default:
+                        break;
+                }
+            } catch ( Exception e ) 
+            {
+                LogHelper.Error(e.Message);
             }
 
         }
@@ -578,8 +628,8 @@ namespace DefaultEdit.Core
                                 groupdata = _httpService.GetGroupItems(boardId, CurentApplicationSettings.DeviceId);
                                 if ( !groupdata.Success )
                                 {
-                                   
-                                    if (groupdata.RawText!=null&&groupdata.RawText.Contains("未点检") )
+
+                                    if ( groupdata.RawText != null && groupdata.RawText.Contains("未点检") )
                                     {
                                         var s = MessageBox.Show("设备未点检,请点检后确认!", "提示", MessageBoxButton.OK);
 
@@ -692,7 +742,7 @@ namespace DefaultEdit.Core
                             App.Current.Dispatcher.Invoke(( System.Action ) delegate
                             {
                                 ProcessDataModel data= processDataModels.ToList().Find(it => it.BoardId == boardId);
-                                if ( data != null ) 
+                                if ( data != null )
                                 {
                                     processDataModels.Remove(data);
                                 }
@@ -719,7 +769,7 @@ namespace DefaultEdit.Core
                                 if ( RfIDList.ToList().Find(x => x.Rfid == value) == null )
                                 {
                                     RfIDList.Add(rfidInfo);
-                                   // RuningData.Add(rfidInfo);
+                                    // RuningData.Add(rfidInfo);
                                 }
                             });