diff --git a/UserClass/AsyncSerialPortClient.cs b/UserClass/AsyncSerialPortClient.cs index 12d40d1..3cfb5c8 100644 --- a/UserClass/AsyncSerialPortClient.cs +++ b/UserClass/AsyncSerialPortClient.cs @@ -2,6 +2,7 @@ using ScottPlot.Plottables; using SunlightCentralizedControlManagement_SCCM_.View; using SunlightCentralizedControlManagement_SCCM_.ViewModel; +using SunlightCentralizedControlManagement_SCCM_.WindowsView; using System; using System.Collections.Generic; using System.Data; @@ -17,6 +18,7 @@ using TouchSocket.SerialPorts; using TouchSocket.Sockets; using static SkiaSharp.HarfBuzz.SKShaper; using static SunlightCentralizedControlManagement_SCCM_.UserClass.SqliteHelper; +using static SunlightCentralizedControlManagement_SCCM_.ViewModel.MainWindowViewModel; using static System.Net.Mime.MediaTypeNames; namespace SunlightCentralizedControlManagement_SCCM_.UserClass @@ -95,7 +97,6 @@ namespace SunlightCentralizedControlManagement_SCCM_.UserClass { try { - DAT = DAT.Substring(DAT.IndexOf("]") + 1); Dictionary _dat; _dat = SerializeConvert.JsonDeserializeFromString>(DAT); MainWindowViewModel.SQLiteHelpers.Update("WorkOrder", new Dictionary { { "State", 111 } }, @@ -110,7 +111,6 @@ namespace SunlightCentralizedControlManagement_SCCM_.UserClass { try { - DAT = DAT.Substring(DAT.IndexOf("]") + 1); Dictionary _dat; _dat = SerializeConvert.JsonDeserializeFromString>(DAT); MainWindowViewModel.SQLiteHelpers.Update("WorkorderSteps", new Dictionary { { "Mode", 1 } }, @@ -131,7 +131,6 @@ namespace SunlightCentralizedControlManagement_SCCM_.UserClass { try { - DAT = DAT.Substring(DAT.IndexOf("]") + 1); Dictionary _dat; _dat = SerializeConvert.JsonDeserializeFromString>(DAT); MainWindowViewModel.SQLiteHelpers.Update("WorkOrder", new Dictionary { { "State", 101 } }, @@ -143,9 +142,80 @@ namespace SunlightCentralizedControlManagement_SCCM_.UserClass { try { + Dictionary _dat; + _dat = SerializeConvert.JsonDeserializeFromString>(DAT); + DataTable dataTable = MainWindowViewModel.SQLiteHelpers.ExecuteDataSet("select * from Dyelot where WorkOrder='" + + _dat.GetValue("WorkOrder") + "' AND ReDye ='" + _dat.GetValue("ReDye") + "' AND Step = '"+ _dat.GetValue("Step") + "'", null).Tables[0]; + foreach (DataRow sourceRow in dataTable.Rows) + { + lock (MainWindowViewModel.Dyelot_CALL.Rows.SyncRoot) + { + // 创建新行(基于目标表结构) + DataRow newRow = MainWindowViewModel.Dyelot_CALL.NewRow(); + // 复制源表中存在的列数据 + foreach (DataColumn column in dataTable.Columns) + { + if (MainWindowViewModel.Dyelot_CALL.Columns.Contains(column.ColumnName)) + { + newRow[column.ColumnName] = sourceRow[column.ColumnName]; + } + } + MainWindowViewModel.Dyelot_CALL.Rows.Add(newRow); + + Dictionary Product_ = new Dictionary();//缓存函数 + Product_.Add("State", 202); + Product_.Add("Dyelot", newRow.Field("Dyelot")); + Product_.Add("Step", newRow.Field("Step")); + + newRow.BeginEdit(); + newRow["State"] = 202; + newRow.EndEdit(); + + MainWindowViewModel.SQLiteHelpers.InsertData("DyelotHistory", MainWindowViewModel.SQLiteHelpers.ToDictionary(newRow));// 执行插入 + int index = MainWindowViewModel.SQLiteHelpers.ExecuteDataSet("select * from Machines where Serial='PORT1' AND Station ='" + + Station + "' ", null).Tables[0].Rows[0].Field("ID"); + string dat_ = "SC828[" + Station + "]" + Product_.ToJsonString(); + bool exists = stringQueueSerial_1.Any(item => item.ID == index && item.DAT == dat_); + if (!exists) + { + stringQueueSerial_1.Enqueue(new QueueSerial + { + ID = index, + DAT = dat_ + }); + } + } + } } catch (Exception ex) { LogGing.LogGingDATA("[ERR='" + ex + "']=Exception"); MainWindowViewModel.ERR_c++; } }//获取呼叫领料单 + else if (SYSAPI == "SC822") + { + try + { + DAT = DAT.Substring(DAT.IndexOf("]") + 1); + DataTable dataTable = JsonConvert.DeserializeObject(DAT).Copy();//反序列化 + System.Windows.Application.Current.Dispatcher.Invoke(() => + { + UserWorkOrder userWorkOrder = new UserWorkOrder(); + userWorkOrder.WorkOrderTable = dataTable; + userWorkOrder.Show(); + }); + } + catch (Exception) + { + System.Windows.Application.Current.Dispatcher.Invoke(() => + { + UserInf userInf = new UserInf(); + userInf.Inf_DAT = "没有等待中的工艺"; + userInf.Show(); + userInf.Activate(); + }); + + // LogGing.LogGingDATA("[ERR='" + ex + "']=Exception"); + MainWindowViewModel.ERR_c++; + } + }//可用工单 else if (SYSAPI == "SC830") { try @@ -205,9 +275,13 @@ namespace SunlightCentralizedControlManagement_SCCM_.UserClass { try { + Dictionary _dat; + _dat = SerializeConvert.JsonDeserializeFromString>(DAT); + MainWindowViewModel.dt_TP = MainWindowViewModel.SQLiteHelpers.ExecuteDataSet("select * WorkorderSteps Dyelot where WorkOrder='" + + _dat.GetValue("WorkOrder") + "' AND ReDye ='" + _dat.GetValue("ReDye") + "'", null).Tables[0]; } catch (Exception ex) { LogGing.LogGingDATA("[ERR='" + ex + "']=Exception"); MainWindowViewModel.ERR_c++; } - } + }//当前步骤信息 else if (SYSAPI == "SC832") { try @@ -220,6 +294,11 @@ namespace SunlightCentralizedControlManagement_SCCM_.UserClass { try { + Dictionary _dat; + _dat = SerializeConvert.JsonDeserializeFromString>(DAT); + MonitorView.Product_DAT = MainWindowViewModel.SQLiteHelpers.ExecuteDataSet("select * from Dyelot where WorkOrder='" + + _dat.GetValue("WorkOrder") + "' AND ReDye ='" + _dat.GetValue("ReDye") + "'", null).Tables[0]; + MonitorView.Product_bool = true; } catch (Exception ex) { LogGing.LogGingDATA("[ERR='" + ex + "']=Exception"); MainWindowViewModel.ERR_c++; } }//当前领料单信息 @@ -227,6 +306,7 @@ namespace SunlightCentralizedControlManagement_SCCM_.UserClass { try { + } catch (Exception ex) { LogGing.LogGingDATA("[ERR='" + ex + "']=Exception"); MainWindowViewModel.ERR_c++; } }//数字开关表 @@ -234,6 +314,7 @@ namespace SunlightCentralizedControlManagement_SCCM_.UserClass { try { + } catch (Exception ex) { LogGing.LogGingDATA("[ERR='" + ex + "']=Exception"); MainWindowViewModel.ERR_c++; } }//寄存器表 @@ -242,6 +323,7 @@ namespace SunlightCentralizedControlManagement_SCCM_.UserClass try { + } catch (Exception ex) { LogGing.LogGingDATA("[ERR='" + ex + "']=Exception"); MainWindowViewModel.ERR_c++; } }//缓存表 @@ -273,7 +355,8 @@ namespace SunlightCentralizedControlManagement_SCCM_.UserClass { try { - + MainWindowViewModel.SQLiteHelpers.Update("WorkOrder", new Dictionary { { "State", 109 } }, + "WorkOrder ='" + DAT + "'", null); } catch (Exception ex) { LogGing.LogGingDATA("[ERR='" + ex + "']=Exception"); MainWindowViewModel.ERR_c++; } }//发布失败 @@ -281,13 +364,21 @@ namespace SunlightCentralizedControlManagement_SCCM_.UserClass { try { - + MainWindowViewModel.SQLiteHelpers.Update("WorkOrder", new Dictionary { { "State", 119 } }, + "WorkOrder ='" + DAT + "'", null); } catch (Exception ex) { LogGing.LogGingDATA("[ERR='" + ex + "']=Exception"); MainWindowViewModel.ERR_c++; } }//细节错误 + else if (SYSAPI == "SC921") + { + try + { + } + catch (Exception ex) { LogGing.LogGingDATA("[ERR='" + ex + "']=Exception"); MainWindowViewModel.ERR_c++; } + }//错误 else if (SYSAPI == "SC980") { - + MessageBox.Show(DAT, "SCCM", MessageBoxButton.OK, MessageBoxImage.Question); } } } diff --git a/UserClass/AsyncTcpClient.cs b/UserClass/AsyncTcpClient.cs index e0adfcd..e46fdb4 100644 --- a/UserClass/AsyncTcpClient.cs +++ b/UserClass/AsyncTcpClient.cs @@ -331,7 +331,7 @@ namespace SunlightCentralizedControlManagement_SCCM_.UserClass MainWindowViewModel.dt_TP = JsonConvert.DeserializeObject(DAT);//反序列化 } catch (Exception ex) { LogGing.LogGingDATA("[ERR='" + ex + "']=Exception"); MainWindowViewModel.ERR_c++; } - } + }//步骤信息 else if (SYSAPI == "SC832") { try @@ -403,7 +403,7 @@ namespace SunlightCentralizedControlManagement_SCCM_.UserClass MachinesView.LOG_dataTable = JsonConvert.DeserializeObject(DAT);//反序列化 } catch (Exception ex) { LogGing.LogGingDATA("[ERR='" + ex + "']=Exception"); MainWindowViewModel.ERR_c++; } - } + }//信息 else if (SYSAPI == "SC910") { try diff --git a/ViewModel/MainWindowViewModel.cs b/ViewModel/MainWindowViewModel.cs index 54b66ca..55512e0 100644 --- a/ViewModel/MainWindowViewModel.cs +++ b/ViewModel/MainWindowViewModel.cs @@ -1114,37 +1114,55 @@ namespace SunlightCentralizedControlManagement_SCCM_.ViewModel } else {//串口 + int index = Convert.ToInt16(MachinesRow["ID"]); + string dat_ = "SC827[" + MachinesRow["Station"] + "]"; if (MachinesRow["Serial"].ToString() == "PORT1") { - stringQueueSerial_1.Enqueue(new QueueSerial + bool exists = stringQueueSerial_1.Any(item => item.ID == index && item.DAT == dat_); + if (!exists) { - ID = Convert.ToInt16(MachinesRow["ID"]), - DAT = "SC827[" + MachinesRow["Station"] + "]" - }); + stringQueueSerial_1.Enqueue(new QueueSerial + { + ID = index, + DAT = dat_ + }); + } } else if (MachinesRow["Serial"].ToString() == "PORT2") { - stringQueueSerial_2.Enqueue(new QueueSerial + bool exists = stringQueueSerial_2.Any(item => item.ID == index && item.DAT == dat_); + if (!exists) { - ID = Convert.ToInt16(MachinesRow["ID"]), - DAT = "SC827[" + MachinesRow["Station"] + "]" - }); + stringQueueSerial_2.Enqueue(new QueueSerial + { + ID = Convert.ToInt16(MachinesRow["ID"]), + DAT = "SC827[" + MachinesRow["Station"] + "]" + }); + } } else if (MachinesRow["Serial"].ToString() == "PORT3") { - stringQueueSerial_3.Enqueue(new QueueSerial + bool exists = stringQueueSerial_3.Any(item => item.ID == index && item.DAT == dat_); + if (!exists) { - ID = Convert.ToInt16(MachinesRow["ID"]), - DAT = "SC827[" + MachinesRow["Station"] + "]" - }); + stringQueueSerial_3.Enqueue(new QueueSerial + { + ID = Convert.ToInt16(MachinesRow["ID"]), + DAT = "SC827[" + MachinesRow["Station"] + "]" + }); + } } else if (MachinesRow["Serial"].ToString() == "PORT4") { - stringQueueSerial_4.Enqueue(new QueueSerial + bool exists = stringQueueSerial_4.Any(item => item.ID == index && item.DAT == dat_); + if (!exists) { - ID = Convert.ToInt16(MachinesRow["ID"]), - DAT = "SC827[" + MachinesRow["Station"] + "]" - }); + stringQueueSerial_4.Enqueue(new QueueSerial + { + ID = Convert.ToInt16(MachinesRow["ID"]), + DAT = "SC827[" + MachinesRow["Station"] + "]" + }); + } } } } @@ -1175,37 +1193,55 @@ namespace SunlightCentralizedControlManagement_SCCM_.ViewModel } else {//串口 + int index = Convert.ToInt16(MachinesRow["ID"]); + string dat_ = "SC828[" + MachinesRow["Station"] + "]" + Product_.ToJsonString(); if (MachinesRow["Serial"].ToString() == "PORT1") { - stringQueueSerial_1.Enqueue(new QueueSerial + bool exists = stringQueueSerial_1.Any(item => item.ID == index && item.DAT == dat_); + if (!exists) { - ID = Convert.ToInt16(MachinesRow["ID"]), - DAT = "SC828[" + MachinesRow["Station"] + "]" + Product_.ToJsonString() - }); + stringQueueSerial_1.Enqueue(new QueueSerial + { + ID = index, + DAT = dat_ + }); + } } else if (MachinesRow["Serial"].ToString() == "PORT2") { - stringQueueSerial_2.Enqueue(new QueueSerial + bool exists = stringQueueSerial_2.Any(item => item.ID == index && item.DAT == dat_); + if (!exists) { - ID = Convert.ToInt16(MachinesRow["ID"]), - DAT = "SC828[" + MachinesRow["Station"] + "]" + Product_.ToJsonString() - }); + stringQueueSerial_2.Enqueue(new QueueSerial + { + ID = index, + DAT = dat_ + }); + } } else if (MachinesRow["Serial"].ToString() == "PORT3") { - stringQueueSerial_3.Enqueue(new QueueSerial + bool exists = stringQueueSerial_3.Any(item => item.ID == index && item.DAT == dat_); + if (!exists) { - ID = Convert.ToInt16(MachinesRow["ID"]), - DAT = "SC828[" + MachinesRow["Station"] + "]" + Product_.ToJsonString() - }); + stringQueueSerial_3.Enqueue(new QueueSerial + { + ID = index, + DAT = dat_ + }); + } } else if (MachinesRow["Serial"].ToString() == "PORT4") { - stringQueueSerial_4.Enqueue(new QueueSerial + bool exists = stringQueueSerial_4.Any(item => item.ID == index && item.DAT == dat_); + if (!exists) { - ID = Convert.ToInt16(MachinesRow["ID"]), - DAT = "SC828[" + MachinesRow["Station"] + "]" + Product_.ToJsonString() - }); + stringQueueSerial_4.Enqueue(new QueueSerial + { + ID = index, + DAT = dat_ + }); + } } }