diff --git a/SunlightCentralizedControlManagement_SCCM_.csproj b/SunlightCentralizedControlManagement_SCCM_.csproj index 0f1999d..2239189 100644 --- a/SunlightCentralizedControlManagement_SCCM_.csproj +++ b/SunlightCentralizedControlManagement_SCCM_.csproj @@ -135,6 +135,7 @@ + diff --git a/UserClass/AsyncSerialPortClient.cs b/UserClass/AsyncSerialPortClient.cs index c803d65..04ec44d 100644 --- a/UserClass/AsyncSerialPortClient.cs +++ b/UserClass/AsyncSerialPortClient.cs @@ -6,6 +6,7 @@ using System; using System.Collections.Generic; using System.Data; using System.Linq; +using System.Security.Cryptography; using System.Text; using System.Text.RegularExpressions; using System.Threading; @@ -67,7 +68,6 @@ namespace SunlightCentralizedControlManagement_SCCM_.UserClass { if (sArray[i].Length>5) { - return EasyTask.CompletedTask; ; string SYSAPI = sArray[i].Substring(0, 5); string Station = ClipBetween(sArray[i], '[', ']'); string DAT = sArray[i].Substring(sArray[i].IndexOf("]") + 1); @@ -77,12 +77,14 @@ namespace SunlightCentralizedControlManagement_SCCM_.UserClass { Dictionary _new = new Dictionary();//缓存函数 _new = JsonConvert.DeserializeObject>(DAT);//反序列化 - DataRow drEmployee = MainWindowViewModel.Machines.Select("Station='" + - Station + "' AND Serial = 'PORT1'").First(); - drEmployee.BeginEdit(); - drEmployee["State"] = "802"; - drEmployee.EndEdit(); - drEmployee.AcceptChanges(); + lock (MainWindowViewModel.Machines.Rows.SyncRoot) + { + DataRow drEmployee = MainWindowViewModel.Machines.Select("Station='" + Station + "' AND Serial = 'PORT1'").First(); + drEmployee.BeginEdit(); + drEmployee["State"] = "802"; + drEmployee.EndEdit(); + drEmployee.AcceptChanges(); + } } catch (Exception ex) { @@ -132,32 +134,36 @@ namespace SunlightCentralizedControlManagement_SCCM_.UserClass { Dictionary _new = new Dictionary();//缓存函数 _new = JsonConvert.DeserializeObject>(DAT);//反序列化 - DataRow drEmployee = MainWindowViewModel.Machines.Select("Station='" + - Station + "' AND Serial = 'PORT1'").First(); - drEmployee.BeginEdit(); - drEmployee["ERR"] = _new.GetValue("ERR"); - drEmployee["LOCK"] = _new.GetValue("LOCK"); - drEmployee["Message"] = _new.GetValue("Status"); - drEmployee["WorkOrder"] = _new.GetValue("WorkNumder"); - drEmployee["Temperature"] = _new.GetValue("MTT"); - drEmployee["WaterLevel"] = _new.GetValue("MTL"); - drEmployee["Process"] = _new.GetValue("Process"); - drEmployee["Step"] = _new.GetValue("Step"); - drEmployee["UserButton"] = _new.GetValue("UserButton"); - if (_new.GetValue("UserInfoStart").ToString() != "900") - { drEmployee["UserInfoStart"] = _new.GetValue("UserInfoStart"); } - drEmployee["UserInfo"] = _new.GetValue("UserInfo"); - drEmployee["WORK_RUN"] = _new.GetValue("WORK_RUN"); - drEmployee["RUN_STEPID"] = _new.GetValue("RUN_STEPID"); - drEmployee["CALL"] = _new.GetValue("CALL"); - drEmployee.EndEdit(); - drEmployee.AcceptChanges(); - + string mac; + lock (MainWindowViewModel.Machines.Rows.SyncRoot) + { + DataRow drEmployee = MainWindowViewModel.Machines.Select("Station='" + Station + "' AND Serial = 'PORT1'").First(); + mac = drEmployee["Name"].ToString(); + drEmployee.BeginEdit(); + drEmployee["ERR"] = _new.GetValue("ERR"); + drEmployee["LOCK"] = _new.GetValue("LOCK"); + drEmployee["Message"] = _new.GetValue("Status"); + drEmployee["WorkOrder"] = _new.GetValue("WorkNumder"); + drEmployee["Temperature"] = _new.GetValue("MTT"); + drEmployee["WaterLevel"] = _new.GetValue("MTL"); + drEmployee["Process"] = _new.GetValue("Process"); + drEmployee["Step"] = _new.GetValue("Step"); + drEmployee["UserButton"] = _new.GetValue("UserButton"); + if (_new.GetValue("UserInfoStart").ToString() != "900") + { drEmployee["UserInfoStart"] = _new.GetValue("UserInfoStart"); } + drEmployee["UserInfo"] = _new.GetValue("UserInfo"); + drEmployee["WORK_RUN"] = _new.GetValue("WORK_RUN"); + drEmployee["RUN_STEPID"] = _new.GetValue("RUN_STEPID"); + drEmployee["CALL"] = _new.GetValue("CALL"); + drEmployee.EndEdit(); + drEmployee.AcceptChanges(); + } + if (_new.GetValue("Status").ToString() != "----------") { Dictionary Chart_new = new Dictionary();//缓存函数 Chart_new.Add("WorkOrder", _new.GetValue("WorkNumder")); - Chart_new.Add("Machine", _new.GetValue("Machine")); + Chart_new.Add("Machine", mac); Chart_new.Add("Time", _new.GetValue("Time")); Chart_new.Add("MST", _new.GetValue("MST")); Chart_new.Add("MTT", _new.GetValue("MTT")); @@ -174,7 +180,8 @@ namespace SunlightCentralizedControlManagement_SCCM_.UserClass MainWindowViewModel.SQLiteChartAdress.InsertData("Chart", Chart_new);// 执行插入 } } - catch (Exception ex) { LogGing.LogGingDATA("[ERR='" + ex + "']=Exception"); MainWindowViewModel.ERR_c++; } + catch (Exception ex) { LogGing.LogGingDATA("[ERR='" + ex + "']=Exception"); MainWindowViewModel.ERR_c++; + } }//当前信息 else if (SYSAPI == "SC831") { @@ -416,13 +423,38 @@ namespace SunlightCentralizedControlManagement_SCCM_.UserClass { try { - var t= CRCcheck16.ToCRC16(command); + var t = CRCcheck16.ToCRC16(command); _responseEvent.Reset(); serialPortClients.Send(command); // 发送指令 // 等待500毫秒或直到收到响应 _responseEvent.Wait(TimeSpan.FromMilliseconds(1000)); // 重置事件状态 _responseEvent.Set(); + //清楚了解状态 + string Station = ClipBetween(command, '[', ']'); + lock (MainWindowViewModel.Machines.Rows.SyncRoot) + { + DataRow drEmployee = MainWindowViewModel.Machines.Select("Station='" + + Station + "' AND Serial = 'PORT1'").First(); + if (drEmployee.Field("State") != 800) + { + drEmployee.BeginEdit(); + drEmployee["State"] = "800"; + drEmployee["WorkOrder"] = "------"; + drEmployee["Dyelot"] = ""; + drEmployee["Temperature"] = 0.0; + drEmployee["WaterLevel"] = 0.0; + drEmployee["Process"] = ""; + drEmployee["Step"] = ""; + drEmployee["Message"] = ""; + drEmployee["SYSKEY"] = ""; + drEmployee["WORK_RUN"] = "-1"; + drEmployee["ERR"] = false; + drEmployee.EndEdit(); + drEmployee.AcceptChanges(); + } + } + } catch (Exception) { } } diff --git a/UserClass/AsyncTcpClient.cs b/UserClass/AsyncTcpClient.cs index 395a360..1a02dd7 100644 --- a/UserClass/AsyncTcpClient.cs +++ b/UserClass/AsyncTcpClient.cs @@ -49,12 +49,14 @@ namespace SunlightCentralizedControlManagement_SCCM_.UserClass { try { - DataRow drEmployee = MainWindowViewModel.Machines.Select("IP='" + client.IP + "'").First(); - drEmployee.BeginEdit(); - drEmployee["State"] = "801"; - drEmployee.EndEdit(); - drEmployee.AcceptChanges(); - + lock (MainWindowViewModel.Machines.Rows.SyncRoot) + { + DataRow drEmployee = MainWindowViewModel.Machines.Select("IP='" + client.IP + "'").First(); + drEmployee.BeginEdit(); + drEmployee["State"] = "801"; + drEmployee.EndEdit(); + drEmployee.AcceptChanges(); + } LogGing.LogGingDATA("[IP='" + client.IP + "' AND port='" + client.Port + "']=Link_OK"); } catch (Exception ex) @@ -68,21 +70,24 @@ namespace SunlightCentralizedControlManagement_SCCM_.UserClass { try { - DataRow drEmployee = MainWindowViewModel.Machines.Select("IP='" + client.IP + "'").First(); - drEmployee.BeginEdit(); - drEmployee["State"] = "800"; - drEmployee["WorkOrder"] = "------"; - drEmployee["Dyelot"] = ""; - drEmployee["Temperature"] = 0.0; - drEmployee["WaterLevel"] = "----"; - drEmployee["Process"] = ""; - drEmployee["Step"] = ""; - drEmployee["Message"] = ""; - drEmployee["SYSKEY"] = ""; - drEmployee["WORK_RUN"] = "-1"; - drEmployee["ERR"] = false; - drEmployee.EndEdit(); - drEmployee.AcceptChanges(); + lock (MainWindowViewModel.Machines.Rows.SyncRoot) + { + DataRow drEmployee = MainWindowViewModel.Machines.Select("IP='" + client.IP + "'").First(); + drEmployee.BeginEdit(); + drEmployee["State"] = "800"; + drEmployee["WorkOrder"] = "------"; + drEmployee["Dyelot"] = ""; + drEmployee["Temperature"] = 0.0; + drEmployee["WaterLevel"] = 0.0; + drEmployee["Process"] = ""; + drEmployee["Step"] = ""; + drEmployee["Message"] = ""; + drEmployee["SYSKEY"] = ""; + drEmployee["WORK_RUN"] = "-1"; + drEmployee["ERR"] = false; + drEmployee.EndEdit(); + drEmployee.AcceptChanges(); + } LogGing.LogGingDATA("[IP='" + client.IP + "' AND port='" + client.Port + "']=Link_STOP"); } catch (Exception ex) @@ -95,21 +100,24 @@ namespace SunlightCentralizedControlManagement_SCCM_.UserClass { try { - DataRow drEmployee = MainWindowViewModel.Machines.Select("IP='" + client.IP + "'").First(); - drEmployee.BeginEdit(); - drEmployee["State"] = "800"; - drEmployee["WorkOrder"] = "------"; - drEmployee["Dyelot"] = ""; - drEmployee["Temperature"] = 0.0; - drEmployee["WaterLevel"] = "----"; - drEmployee["Process"] = ""; - drEmployee["Step"] = ""; - drEmployee["Message"] = ""; - drEmployee["SYSKEY"] = ""; - drEmployee["WORK_RUN"] = "-1"; - drEmployee["ERR"] = false; - drEmployee.EndEdit(); - drEmployee.AcceptChanges(); + lock (MainWindowViewModel.Machines.Rows.SyncRoot) + { + DataRow drEmployee = MainWindowViewModel.Machines.Select("IP='" + client.IP + "'").First(); + drEmployee.BeginEdit(); + drEmployee["State"] = "800"; + drEmployee["WorkOrder"] = "------"; + drEmployee["Dyelot"] = ""; + drEmployee["Temperature"] = 0.0; + drEmployee["WaterLevel"] = 0.0; + drEmployee["Process"] = ""; + drEmployee["Step"] = ""; + drEmployee["Message"] = ""; + drEmployee["SYSKEY"] = ""; + drEmployee["WORK_RUN"] = "-1"; + drEmployee["ERR"] = false; + drEmployee.EndEdit(); + drEmployee.AcceptChanges(); + } LogGing.LogGingDATA("[IP='" + client.IP + "' AND port='" + client.Port + "']=Link_INTERRUPT"); } catch (Exception ex) @@ -130,14 +138,17 @@ namespace SunlightCentralizedControlManagement_SCCM_.UserClass DAT = DAT.Substring(DAT.IndexOf("]") + 1); Dictionary Chart_new = new Dictionary();//缓存函数 Chart_new = JsonConvert.DeserializeObject>(DAT);//反序列化 - DataRow drEmployee = MainWindowViewModel.Machines.Select("IP='" + client.IP + "'").First(); - drEmployee.BeginEdit(); - drEmployee["SYSKEY"] = Chart_new.GetValue("SYSKEY").ToString(); - // drEmployee["NAME"] = Chart_new.GetValue("MACHINE").ToString(); - drEmployee["Groups"] = Chart_new.GetValue("GROUP").ToString(); - drEmployee["State"] = "802"; - drEmployee.EndEdit(); - drEmployee.AcceptChanges(); + lock (MainWindowViewModel.Machines.Rows.SyncRoot) + { + DataRow drEmployee = MainWindowViewModel.Machines.Select("IP='" + client.IP + "'").First(); + drEmployee.BeginEdit(); + drEmployee["SYSKEY"] = Chart_new.GetValue("SYSKEY").ToString(); + // drEmployee["NAME"] = Chart_new.GetValue("MACHINE").ToString(); + drEmployee["Groups"] = Chart_new.GetValue("GROUP").ToString(); + drEmployee["State"] = "802"; + drEmployee.EndEdit(); + drEmployee.AcceptChanges(); + } } catch (Exception ex) { @@ -213,38 +224,41 @@ namespace SunlightCentralizedControlManagement_SCCM_.UserClass foreach (DataRow sourceRow in dataTable.Rows) { - // 创建新行(基于目标表结构) - DataRow newRow = MainWindowViewModel.Dyelot_CALL.NewRow(); - // 复制源表中存在的列数据 - foreach (DataColumn column in dataTable.Columns) + lock (MainWindowViewModel.Dyelot_CALL.Rows.SyncRoot) { - if (MainWindowViewModel.Dyelot_CALL.Columns.Contains(column.ColumnName)) + // 创建新行(基于目标表结构) + DataRow newRow = MainWindowViewModel.Dyelot_CALL.NewRow(); + // 复制源表中存在的列数据 + foreach (DataColumn column in dataTable.Columns) { - newRow[column.ColumnName] = sourceRow[column.ColumnName]; + if (MainWindowViewModel.Dyelot_CALL.Columns.Contains(column.ColumnName)) + { + newRow[column.ColumnName] = sourceRow[column.ColumnName]; + } } - } - MainWindowViewModel.Dyelot_CALL.Rows.Add(newRow); + 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")); - Product_.Add("ProductCode", newRow.Field("ProductCode")); - Product_.Add("Amount", newRow.Field("Amount")); - Product_.Add("DispenseEndTime", newRow.Field("DispenseEndTime")); + Dictionary Product_ = new Dictionary();//缓存函数 + Product_.Add("State", 202); + Product_.Add("Dyelot", newRow.Field("Dyelot")); + Product_.Add("Step", newRow.Field("Step")); + Product_.Add("ProductCode", newRow.Field("ProductCode")); + Product_.Add("Amount", newRow.Field("Amount")); + Product_.Add("DispenseEndTime", newRow.Field("DispenseEndTime")); - newRow.BeginEdit(); - newRow["State"] = 202; - newRow.EndEdit(); + newRow.BeginEdit(); + newRow["State"] = 202; + newRow.EndEdit(); - MainWindowViewModel.SQLiteHelpers.InsertData("DyelotHistory", MainWindowViewModel.SQLiteHelpers.ToDictionary(newRow));// 执行插入 - MainWindowViewModel.stringQueue.Enqueue(new MainWindowViewModel.QueueString - { - ID = Convert.ToInt16(MainWindowViewModel.Selet_Machines(MainWindowViewModel.Machines, - "ID", "Name='" + newRow.Field("Machine") + "'")), - DAT = "SC828" + MainWindowViewModel.Selet_Machines(MainWindowViewModel.Machines, - "SYSKEY", "Name='" + newRow.Field("Machine") + "'") + Product_.ToJsonString() - }); + MainWindowViewModel.SQLiteHelpers.InsertData("DyelotHistory", MainWindowViewModel.SQLiteHelpers.ToDictionary(newRow));// 执行插入 + MainWindowViewModel.stringQueue.Enqueue(new MainWindowViewModel.QueueString + { + ID = Convert.ToInt16(MainWindowViewModel.Selet_Machines(MainWindowViewModel.Machines, + "ID", "Name='" + newRow.Field("Machine") + "'")), + DAT = "SC828" + MainWindowViewModel.Selet_Machines(MainWindowViewModel.Machines, + "SYSKEY", "Name='" + newRow.Field("Machine") + "'") + Product_.ToJsonString() + }); + } } } catch (Exception ex) { LogGing.LogGingDATA("[ERR='" + ex + "']=Exception"); MainWindowViewModel.ERR_c++; } @@ -256,31 +270,36 @@ namespace SunlightCentralizedControlManagement_SCCM_.UserClass DAT = DAT.Substring(DAT.IndexOf("]") + 1); Dictionary _new = new Dictionary();//缓存函数 _new = JsonConvert.DeserializeObject>(DAT);//反序列化 - DataRow drEmployee = MainWindowViewModel.Machines.Select("IP='" + client.IP + "'").First(); - drEmployee.BeginEdit(); - drEmployee["ERR"] = _new.GetValue("ERR"); - drEmployee["LOCK"] = _new.GetValue("LOCK"); - drEmployee["Message"] = _new.GetValue("Status"); - drEmployee["WorkOrder"] = _new.GetValue("WorkNumder"); - drEmployee["Temperature"] = _new.GetValue("MTT"); - drEmployee["WaterLevel"] = _new.GetValue("MTL"); - drEmployee["Process"] = _new.GetValue("Process"); - drEmployee["Step"] = _new.GetValue("Step"); - drEmployee["UserButton"] = _new.GetValue("UserButton"); - if (_new.GetValue("UserInfoStart").ToString() != "900") - { drEmployee["UserInfoStart"] = _new.GetValue("UserInfoStart"); } - drEmployee["UserInfo"] = _new.GetValue("UserInfo"); - drEmployee["WORK_RUN"] = _new.GetValue("WORK_RUN"); - drEmployee["RUN_STEPID"] = _new.GetValue("RUN_STEPID"); - drEmployee["CALL"] = _new.GetValue("CALL"); - drEmployee.EndEdit(); - drEmployee.AcceptChanges(); - + string mac; + // 首先确保 DataTable 使用线程安全的访问方式 + lock (MainWindowViewModel.Machines.Rows.SyncRoot) + { + DataRow drEmployee = MainWindowViewModel.Machines.Select("IP='" + client.IP + "'").First(); + mac = drEmployee["Name"].ToString(); + drEmployee.BeginEdit(); + drEmployee["ERR"] = _new.GetValue("ERR"); + drEmployee["LOCK"] = _new.GetValue("LOCK"); + drEmployee["Message"] = _new.GetValue("Status"); + drEmployee["WorkOrder"] = _new.GetValue("WorkNumder"); + drEmployee["Temperature"] = _new.GetValue("MTT"); + drEmployee["WaterLevel"] = _new.GetValue("MTL"); + drEmployee["Process"] = _new.GetValue("Process"); + drEmployee["Step"] = _new.GetValue("Step"); + drEmployee["UserButton"] = _new.GetValue("UserButton"); + if (_new.GetValue("UserInfoStart").ToString() != "900") + { drEmployee["UserInfoStart"] = _new.GetValue("UserInfoStart"); } + drEmployee["UserInfo"] = _new.GetValue("UserInfo"); + drEmployee["WORK_RUN"] = _new.GetValue("WORK_RUN"); + drEmployee["RUN_STEPID"] = _new.GetValue("RUN_STEPID"); + drEmployee["CALL"] = _new.GetValue("CALL"); + drEmployee.EndEdit(); + drEmployee.AcceptChanges(); + } if (_new.GetValue("Status").ToString() != "----------") { Dictionary Chart_new = new Dictionary();//缓存函数 Chart_new.Add("WorkOrder", _new.GetValue("WorkNumder")); - Chart_new.Add("Machine", drEmployee["Name"]); + Chart_new.Add("Machine", mac); Chart_new.Add("Time", DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss")); Chart_new.Add("MST", _new.GetValue("MST")); Chart_new.Add("MTT", _new.GetValue("MTT")); diff --git a/UserClass/DataTableManager .cs b/UserClass/DataTableManager .cs new file mode 100644 index 0000000..eba1be1 --- /dev/null +++ b/UserClass/DataTableManager .cs @@ -0,0 +1,360 @@ +using System; +using System.Collections.Generic; +using System.Data; +using System.Linq; +using System.Text; +using System.Threading; +using System.Threading.Tasks; + +namespace SunlightCentralizedControlManagement_SCCM_.UserClass +{ + /// + /// 线程安全的 DataTable 管理器 + /// 提供对 DataTable 的安全并发访问 + /// + public class DataTableManager : IDisposable + { + private DataTable _dataTable; + private readonly ReaderWriterLockSlim _lock = new ReaderWriterLockSlim(); + private bool _disposed = false; + + #region 构造函数 + public DataTableManager() + { + _dataTable = new DataTable(); + } + + public DataTableManager(DataTable dataTable) + { + _dataTable = dataTable ?? throw new ArgumentNullException(nameof(dataTable)); + } + + public DataTableManager(string tableName) + { + _dataTable = new DataTable(tableName); + } + #endregion + + #region 基本操作 + /// + /// 安全地添加列 + /// + public void AddColumn(string columnName, Type dataType) + { + ExecuteWriteOperation(table => + { + table.Columns.Add(columnName, dataType); + }); + } + + /// + /// 安全地添加行 + /// + public void AddRow(params object[] values) + { + ExecuteWriteOperation(table => + { + DataRow newRow = table.NewRow(); + for (int i = 0; i < Math.Min(values.Length, table.Columns.Count); i++) + { + newRow[i] = values[i] ?? DBNull.Value; + } + table.Rows.Add(newRow); + }); + } + + /// + /// 安全地更新单元格值 + /// + public bool UpdateCell(int rowIndex, string columnName, object value) + { + return ExecuteWriteOperation(table => + { + if (IsValidRowIndex(table, rowIndex) && table.Columns.Contains(columnName)) + { + table.Rows[rowIndex][columnName] = value ?? DBNull.Value; + return true; + } + return false; + }); + } + + /// + /// 安全地删除行 + /// + public bool DeleteRow(int rowIndex) + { + return ExecuteWriteOperation(table => + { + if (IsValidRowIndex(table, rowIndex)) + { + table.Rows[rowIndex].Delete(); + return true; + } + return false; + }); + } + #endregion + + #region 查询操作 + /// + /// 安全地获取行 + /// + public DataRow GetRow(int rowIndex) + { + return ExecuteReadOperation(table => + { + return IsValidRowIndex(table, rowIndex) ? table.Rows[rowIndex] : null; + }); + } + + /// + /// 安全地查找行(使用筛选条件) + /// + public DataRow[] FindRows(string filterExpression) + { + return ExecuteReadOperation(table => + { + try + { + return string.IsNullOrEmpty(filterExpression) + ? table.Select() + : table.Select(filterExpression); + } + catch (EvaluateException) + { + return new DataRow[0]; + } + }); + } + + /// + /// 安全地获取行数 + /// + public int GetRowCount() + { + return ExecuteReadOperation(table => table.Rows.Count); + } + + /// + /// 安全地检查行是否存在 + /// + public bool RowExists(int rowIndex) + { + return ExecuteReadOperation(table => IsValidRowIndex(table, rowIndex)); + } + #endregion + + #region 批量操作 + /// + /// 安全地批量添加行 + /// + public void BulkAddRows(IEnumerable rowsData) + { + ExecuteWriteOperation(table => + { + foreach (var rowData in rowsData) + { + DataRow newRow = table.NewRow(); + for (int i = 0; i < Math.Min(rowData.Length, table.Columns.Count); i++) + { + newRow[i] = rowData[i] ?? DBNull.Value; + } + table.Rows.Add(newRow); + } + }); + } + + /// + /// 安全地清空所有数据 + /// + public void Clear() + { + ExecuteWriteOperation(table => + { + table.Clear(); + }); + } + #endregion + + #region 数据导出 + /// + /// 获取数据快照(线程安全的副本) + /// + public DataTable GetSnapshot() + { + return ExecuteReadOperation(table => + { + return table.Copy(); // 创建数据的独立副本 + }); + } + + /// + /// 获取只读视图 + /// + public DataView GetReadOnlyView() + { + return ExecuteReadOperation(table => + { + return new DataView(table) { AllowEdit = false }; + }); + } + + /// + /// 导出到新 DataTable(包含结构) + /// + public DataTable ExportToDataTable() + { + return ExecuteReadOperation(table => + { + DataTable exported = table.Clone(); + exported.Merge(table, false, MissingSchemaAction.Add); + return exported; + }); + } + #endregion + + #region 锁操作核心 + /// + /// 执行读取操作(共享锁) + /// + private T ExecuteReadOperation(Func operation) + { + _lock.EnterReadLock(); + try + { + return operation(_dataTable); + } + finally + { + _lock.ExitReadLock(); + } + } + + /// + /// 执行写入操作(独占锁) + /// + private void ExecuteWriteOperation(Action operation) + { + _lock.EnterWriteLock(); + try + { + operation(_dataTable); + _dataTable.AcceptChanges(); + } + finally + { + _lock.ExitWriteLock(); + } + } + + private T ExecuteWriteOperation(Func operation) + { + _lock.EnterWriteLock(); + try + { + var result = operation(_dataTable); + _dataTable.AcceptChanges(); + return result; + } + finally + { + _lock.ExitWriteLock(); + } + } + + private bool IsValidRowIndex(DataTable table, int rowIndex) + { + return rowIndex >= 0 && rowIndex < table.Rows.Count; + } + #endregion + + #region 高级功能 + /// + /// 带超时的安全操作 + /// + public bool TryUpdateCell(int rowIndex, string columnName, object value, int timeoutMs = 5000) + { + if (_lock.TryEnterWriteLock(timeoutMs)) + { + try + { + if (IsValidRowIndex(_dataTable, rowIndex) && _dataTable.Columns.Contains(columnName)) + { + _dataTable.Rows[rowIndex][columnName] = value ?? DBNull.Value; + _dataTable.AcceptChanges(); + return true; + } + return false; + } + finally + { + _lock.ExitWriteLock(); + } + } + return false; + } + + /// + /// 执行事务性操作 + /// + public void ExecuteTransaction(Action transaction) + { + _lock.EnterWriteLock(); + try + { + // 开始事务 + _dataTable.BeginLoadData(); + + try + { + transaction(_dataTable); + _dataTable.AcceptChanges(); + } + catch + { + _dataTable.RejectChanges(); + throw; + } + finally + { + _dataTable.EndLoadData(); + } + } + finally + { + _lock.ExitWriteLock(); + } + } + #endregion + + #region 属性和清理 + public string TableName + { + get => ExecuteReadOperation(table => table.TableName); + set => ExecuteWriteOperation(table => table.TableName = value); + } + + public DataColumnCollection Columns + { + get => ExecuteReadOperation(table => table.Columns); + } + + public void Dispose() + { + if (!_disposed) + { + _lock?.Dispose(); + _dataTable?.Dispose(); + _disposed = true; + } + GC.SuppressFinalize(this); + } + + ~DataTableManager() + { + Dispose(); + } + #endregion + } +} diff --git a/View/MachinesSet.xaml.cs b/View/MachinesSet.xaml.cs index 91ea1e5..188aef8 100644 --- a/View/MachinesSet.xaml.cs +++ b/View/MachinesSet.xaml.cs @@ -75,95 +75,103 @@ namespace SunlightCentralizedControlManagement_SCCM_.View if (!string.IsNullOrEmpty(comboBoxMachine.Text)) { Dictionary Machines_DAT = new Dictionary();//缓存函数 - if (MainWindowViewModel.SQLiteHelpers.ExecuteDataSet("select * from Machines where name ='" + comboBoxMachine.Text + "'", null).Tables[0].Rows.Count == 0) - { - DataRow dat_= MainWindowViewModel.Machines.NewRow(); - dat_.BeginEdit(); - dat_["Name"] = comboBoxMachine.Text; - dat_["Groups"] = TextMachineGroup.Text; - dat_["IP"] = IP.Text; - dat_["PORT"] = PORT.Text; - dat_["Serial"] = comboBoxCOM0.Text; - dat_["Model"] = comboBoxtype.Text; - dat_["Station"] = Station.Text; - dat_["ID"] = 999; - dat_["ERR"] = false; - dat_["AUTO"] = false; - dat_["CALL"] = false; - dat_["LOCK"] = false; - dat_["State"] = 800; - dat_["Temperature"] = 0; - dat_["WaterLevel"] = 0; - dat_["WORK_RUN"] = -1; - dat_["UserInfoStart"] = 900; - if (comboBoxtype.Text.Contains( link_model)) - { - dat_["Desktop"] = true; - dat_["Type"] = true; - } - else - { - dat_["Desktop"] = false; - dat_["Type"] = false; - } - dat_.EndEdit(); - MainWindowViewModel.Machines.Rows.Add(dat_); - DatSteps(MainWindowViewModel.Machines); - MainWindowViewModel.SQLiteHelpers.Delete("Machines", null, null);// - for (int x = 0; x < MainWindowViewModel.Machines.Rows.Count; x++) + if (MainWindowViewModel.SQLiteHelpers.ExecuteDataSet("select * from Machines where name ='" + comboBoxMachine.Text + "'", null).Tables[0].Rows.Count == 0) + { + lock (MainWindowViewModel.Machines.Rows.SyncRoot) { - Machines_DAT.Add("ID", MainWindowViewModel.Machines.Rows[x]["ID"]); - Machines_DAT.Add("Name", MainWindowViewModel.Machines.Rows[x]["Name"]); - Machines_DAT.Add("IP", MainWindowViewModel.Machines.Rows[x]["IP"]); - Machines_DAT.Add("PORT", MainWindowViewModel.Machines.Rows[x]["PORT"]); - Machines_DAT.Add("Serial", MainWindowViewModel.Machines.Rows[x]["Serial"]); - Machines_DAT.Add("Station", MainWindowViewModel.Machines.Rows[x]["Station"]); - Machines_DAT.Add("Groups", MainWindowViewModel.Machines.Rows[x]["Groups"]); - Machines_DAT.Add("Desktop", MainWindowViewModel.Machines.Rows[x]["Desktop"]); - Machines_DAT.Add("Dispense", MainWindowViewModel.Machines.Rows[x]["Dispense"]); - Machines_DAT.Add("Type", MainWindowViewModel.Machines.Rows[x]["Type"]); - Machines_DAT.Add("Model", MainWindowViewModel.Machines.Rows[x]["Model"]); - MainWindowViewModel.SQLiteHelpers.InsertData("Machines", Machines_DAT);//行插入 - Machines_DAT.Clear(); + DataRow dat_ = MainWindowViewModel.Machines.NewRow(); + dat_.BeginEdit(); + dat_["Name"] = comboBoxMachine.Text; + dat_["Groups"] = TextMachineGroup.Text; + dat_["IP"] = IP.Text; + dat_["PORT"] = PORT.Text; + dat_["Serial"] = comboBoxCOM0.Text; + dat_["Model"] = comboBoxtype.Text; + dat_["Station"] = Station.Text; + dat_["ID"] = 999; + dat_["ERR"] = false; + dat_["AUTO"] = false; + dat_["CALL"] = false; + dat_["LOCK"] = false; + dat_["State"] = 800; + dat_["Temperature"] = 0; + dat_["WaterLevel"] = 0; + dat_["WORK_RUN"] = -1; + dat_["UserInfoStart"] = 900; + if (comboBoxtype.Text.Contains(link_model)) + { + dat_["Desktop"] = true; + dat_["Type"] = true; + } + else + { + dat_["Desktop"] = false; + dat_["Type"] = false; + } + dat_.EndEdit(); + MainWindowViewModel.Machines.Rows.Add(dat_); + DatSteps(MainWindowViewModel.Machines); + MainWindowViewModel.SQLiteHelpers.Delete("Machines", null, null);// + for (int x = 0; x < MainWindowViewModel.Machines.Rows.Count; x++) + { + Machines_DAT.Add("ID", MainWindowViewModel.Machines.Rows[x]["ID"]); + Machines_DAT.Add("Name", MainWindowViewModel.Machines.Rows[x]["Name"]); + Machines_DAT.Add("IP", MainWindowViewModel.Machines.Rows[x]["IP"]); + Machines_DAT.Add("PORT", MainWindowViewModel.Machines.Rows[x]["PORT"]); + Machines_DAT.Add("Serial", MainWindowViewModel.Machines.Rows[x]["Serial"]); + Machines_DAT.Add("Station", MainWindowViewModel.Machines.Rows[x]["Station"]); + Machines_DAT.Add("Groups", MainWindowViewModel.Machines.Rows[x]["Groups"]); + Machines_DAT.Add("Desktop", MainWindowViewModel.Machines.Rows[x]["Desktop"]); + Machines_DAT.Add("Dispense", MainWindowViewModel.Machines.Rows[x]["Dispense"]); + Machines_DAT.Add("Type", MainWindowViewModel.Machines.Rows[x]["Type"]); + Machines_DAT.Add("Model", MainWindowViewModel.Machines.Rows[x]["Model"]); + MainWindowViewModel.SQLiteHelpers.InsertData("Machines", Machines_DAT);//行插入 + Machines_DAT.Clear(); + } } } else { - DataRow dr = MainWindowViewModel.Machines.Rows[ID_]; - dr.BeginEdit(); - dr["Name"] = comboBoxMachine.Text; - dr["Groups"] = TextMachineGroup.Text; - dr["IP"] = IP.Text; - dr["PORT"] = PORT.Text; - dr["Serial"] = comboBoxCOM0.Text; - dr["Model"] = comboBoxtype.Text; - dr["Station"] = Station.Text; - if (comboBoxtype.Text.Contains(link_model)) - { dr["Desktop"] = true; - dr["Type"] = true; } - else + lock (MainWindowViewModel.Machines.Rows.SyncRoot) { - dr["Desktop"] = false; - dr["Type"] = false; - } - dr.EndEdit(); - MainWindowViewModel.SQLiteHelpers.Delete("Machines", null, null);// - for (int x = 0; x < MainWindowViewModel.Machines.Rows.Count; x++) - { - Machines_DAT.Add("ID", MainWindowViewModel.Machines.Rows[x]["ID"]); - Machines_DAT.Add("Name", MainWindowViewModel.Machines.Rows[x]["Name"]); - Machines_DAT.Add("IP", MainWindowViewModel.Machines.Rows[x]["IP"]); - Machines_DAT.Add("PORT", MainWindowViewModel.Machines.Rows[x]["PORT"]); - Machines_DAT.Add("Serial", MainWindowViewModel.Machines.Rows[x]["Serial"]); - Machines_DAT.Add("Station", MainWindowViewModel.Machines.Rows[x]["Station"]); - Machines_DAT.Add("Groups", MainWindowViewModel.Machines.Rows[x]["Groups"]); - Machines_DAT.Add("Desktop", MainWindowViewModel.Machines.Rows[x]["Desktop"]); - Machines_DAT.Add("Dispense", MainWindowViewModel.Machines.Rows[x]["Dispense"]); - Machines_DAT.Add("Type", MainWindowViewModel.Machines.Rows[x]["Type"]); - Machines_DAT.Add("Model", MainWindowViewModel.Machines.Rows[x]["Model"]); - Machines_DAT.Add("LOCK", "FALSE"); - MainWindowViewModel.SQLiteHelpers.InsertData("Machines", Machines_DAT);//行插入 - Machines_DAT.Clear(); + DataRow dr = MainWindowViewModel.Machines.Rows[ID_]; + dr.BeginEdit(); + dr["Name"] = comboBoxMachine.Text; + dr["Groups"] = TextMachineGroup.Text; + dr["IP"] = IP.Text; + dr["PORT"] = PORT.Text; + dr["Serial"] = comboBoxCOM0.Text; + dr["Model"] = comboBoxtype.Text; + dr["Station"] = Station.Text; + if (comboBoxtype.Text.Contains(link_model)) + { + dr["Desktop"] = true; + dr["Type"] = true; + } + else + { + dr["Desktop"] = false; + dr["Type"] = false; + } + dr.EndEdit(); + MainWindowViewModel.SQLiteHelpers.Delete("Machines", null, null);// + for (int x = 0; x < MainWindowViewModel.Machines.Rows.Count; x++) + { + Machines_DAT.Add("ID", MainWindowViewModel.Machines.Rows[x]["ID"]); + Machines_DAT.Add("Name", MainWindowViewModel.Machines.Rows[x]["Name"]); + Machines_DAT.Add("IP", MainWindowViewModel.Machines.Rows[x]["IP"]); + Machines_DAT.Add("PORT", MainWindowViewModel.Machines.Rows[x]["PORT"]); + Machines_DAT.Add("Serial", MainWindowViewModel.Machines.Rows[x]["Serial"]); + Machines_DAT.Add("Station", MainWindowViewModel.Machines.Rows[x]["Station"]); + Machines_DAT.Add("Groups", MainWindowViewModel.Machines.Rows[x]["Groups"]); + Machines_DAT.Add("Desktop", MainWindowViewModel.Machines.Rows[x]["Desktop"]); + Machines_DAT.Add("Dispense", MainWindowViewModel.Machines.Rows[x]["Dispense"]); + Machines_DAT.Add("Type", MainWindowViewModel.Machines.Rows[x]["Type"]); + Machines_DAT.Add("Model", MainWindowViewModel.Machines.Rows[x]["Model"]); + Machines_DAT.Add("LOCK", "FALSE"); + MainWindowViewModel.SQLiteHelpers.InsertData("Machines", Machines_DAT);//行插入 + Machines_DAT.Clear(); + } } } Griddata.ItemsSource = MainWindowViewModel.Machines.DefaultView; @@ -187,9 +195,11 @@ namespace SunlightCentralizedControlManagement_SCCM_.View MessageBoxResult vr = System.Windows.MessageBox.Show(Properties.Resources.Delete + comboBoxMachine.Text, "SCCM", MessageBoxButton.OKCancel, MessageBoxImage.Question); if (vr == MessageBoxResult.OK) // 如果是确定,就执行下面代码 { - MainWindowViewModel.Machines.Rows.RemoveAt(ID_ - 1); - DatSteps(MainWindowViewModel.Machines); - + lock (MainWindowViewModel.Machines.Rows.SyncRoot) + { + MainWindowViewModel.Machines.Rows.RemoveAt(ID_ - 1); + DatSteps(MainWindowViewModel.Machines); + } Dictionary Machines_DAT = new Dictionary();//缓存函数 MainWindowViewModel.SQLiteHelpers.Delete("Machines", null, null);// diff --git a/View/MonitorView.xaml.cs b/View/MonitorView.xaml.cs index 99f148e..3152a42 100644 --- a/View/MonitorView.xaml.cs +++ b/View/MonitorView.xaml.cs @@ -146,145 +146,151 @@ namespace SunlightCentralizedControlManagement_SCCM_.View { if (!string.IsNullOrEmpty(machine)) { - bool mode = MainWindowViewModel.Machines.Select("NAME='" + machine + "'").First().Field("LOCK"); - - Dictionary dat_ = new Dictionary(); - dat_.Clear(); - - if (!mode) - { - dat_.Add("NAME", "LOCK"); - dat_.Add("VALUE", "True"); - MainWindowViewModel.Updata_Machines(MainWindowViewModel.Machines, "LOCK", "Name='" + machine + "'", "True"); - } - else + lock (MainWindowViewModel.Machines.Rows.SyncRoot) { - dat_.Add("NAME", "LOCK"); - dat_.Add("VALUE", "False"); - MainWindowViewModel.Updata_Machines(MainWindowViewModel.Machines, "LOCK", "Name='" + machine + "'", "False"); - } + bool mode = MainWindowViewModel.Machines.Select("NAME='" + machine + "'").First().Field("LOCK"); - DataRow drEmployee = MainWindowViewModel.Machines.Select("NAME='" + machine + "'").First(); - int index = Convert.ToInt16(drEmployee.Field("ID")); + Dictionary dat_ = new Dictionary(); + dat_.Clear(); - if (drEmployee.Field("Type")) - {//网络 - MainWindowViewModel.stringQueue.Enqueue(new MainWindowViewModel.QueueString + if (!mode) { - ID = index, - DAT = "SC829" + drEmployee.Field("SYSKEY") + dat_.ToJsonString() - }); - } - else - {//串口 - if (drEmployee.Field("Serial") == "PORT1") + dat_.Add("NAME", "LOCK"); + dat_.Add("VALUE", "True"); + MainWindowViewModel.Updata_Machines(MainWindowViewModel.Machines, "LOCK", "Name='" + machine + "'", "True"); + } + else { - stringQueueSerial_1.Enqueue(new QueueSerial + dat_.Add("NAME", "LOCK"); + dat_.Add("VALUE", "False"); + MainWindowViewModel.Updata_Machines(MainWindowViewModel.Machines, "LOCK", "Name='" + machine + "'", "False"); + } + + DataRow drEmployee = MainWindowViewModel.Machines.Select("NAME='" + machine + "'").First(); + int index = Convert.ToInt16(drEmployee.Field("ID")); + + if (drEmployee.Field("Type")) + {//网络 + MainWindowViewModel.stringQueue.Enqueue(new MainWindowViewModel.QueueString { ID = index, - DAT = "SC829" + MainWindowViewModel.Selet_Machines(MainWindowViewModel.Machines, "SYSKEY", "ID='" + index + "'") + dat_.ToJsonString() + DAT = "SC829" + drEmployee.Field("SYSKEY") + dat_.ToJsonString() }); } - else if (drEmployee.Field("Serial") == "PORT2") - { - stringQueueSerial_2.Enqueue(new QueueSerial + else + {//串口 + if (drEmployee.Field("Serial") == "PORT1") { - ID = index, - DAT = "SC829" + drEmployee.Field("Station") + dat_.ToJsonString() - }); + stringQueueSerial_1.Enqueue(new QueueSerial + { + ID = index, + DAT = "SC829" + MainWindowViewModel.Selet_Machines(MainWindowViewModel.Machines, "SYSKEY", "ID='" + index + "'") + dat_.ToJsonString() + }); + } + else if (drEmployee.Field("Serial") == "PORT2") + { + stringQueueSerial_2.Enqueue(new QueueSerial + { + ID = index, + DAT = "SC829" + drEmployee.Field("Station") + dat_.ToJsonString() + }); + } + else if (drEmployee.Field("Serial") == "PORT3") + { + stringQueueSerial_3.Enqueue(new QueueSerial + { + ID = index, + DAT = "SC829" + drEmployee.Field("Station") + dat_.ToJsonString() + }); + } + else if (drEmployee.Field("Serial") == "PORT4") + { + stringQueueSerial_4.Enqueue(new QueueSerial + { + ID = index, + DAT = "SC829" + drEmployee.Field("Station") + dat_.ToJsonString() + }); + } } - else if (drEmployee.Field("Serial") == "PORT3") + if (!mode) { - stringQueueSerial_3.Enqueue(new QueueSerial - { - ID = index, - DAT = "SC829" + drEmployee.Field("Station") + dat_.ToJsonString() - }); + MessageBox.Show(machine + Properties.Resources.user_lock, "800", MessageBoxButton.OK, MessageBoxImage.Information); } - else if (drEmployee.Field("Serial") == "PORT4") + else { - stringQueueSerial_4.Enqueue(new QueueSerial - { - ID = index, - DAT = "SC829" + drEmployee.Field("Station") + dat_.ToJsonString() - }); + MessageBox.Show(machine + Properties.Resources.user_unlock, "800", MessageBoxButton.OK, MessageBoxImage.Information); } } - if (!mode) - { - MessageBox.Show(machine + Properties.Resources.user_lock, "800", MessageBoxButton.OK, MessageBoxImage.Information); - } - else - { - MessageBox.Show(machine + Properties.Resources.user_unlock, "800", MessageBoxButton.OK, MessageBoxImage.Information); - } } }//锁定 private void MenuItem_AUTO_XML(object sender, RoutedEventArgs e) { if (!string.IsNullOrEmpty(machine)) { - bool mode = MainWindowViewModel.Machines.Select("NAME='" + machine + "'").First().Field("AUTO"); - - Dictionary dat_ = new Dictionary(); - dat_.Clear(); - - if (!mode) - { - dat_.Add("NAME", "AUTO"); - dat_.Add("VALUE", "True"); - MainWindowViewModel.Updata_Machines(MainWindowViewModel.Machines, "AUTO", "Name='" + machine + "'", "True"); - } - else + lock (MainWindowViewModel.Machines.Rows.SyncRoot) { - dat_.Add("NAME", "AUTO"); - dat_.Add("VALUE", "FALSE"); - MainWindowViewModel.Updata_Machines(MainWindowViewModel.Machines, "AUTO", "Name='" + machine + "'", "False"); - } + bool mode = MainWindowViewModel.Machines.Select("NAME='" + machine + "'").First().Field("AUTO"); - DataRow drEmployee = MainWindowViewModel.Machines.Select("NAME='" + machine + "'").First(); - int index = Convert.ToInt16(drEmployee.Field("ID")); - if (drEmployee.Field("Type")) - {//网络 - MainWindowViewModel.stringQueue.Enqueue(new MainWindowViewModel.QueueString - { - ID = index, - DAT = "SC829" + drEmployee.Field("SYSKEY") + dat_.ToJsonString() - }); - } - else - {//串口 - if (drEmployee.Field("Serial") == "PORT1") + Dictionary dat_ = new Dictionary(); + dat_.Clear(); + + if (!mode) { - stringQueueSerial_1.Enqueue(new QueueSerial - { - ID = index, - DAT = "SC829" + drEmployee.Field("Station") + dat_.ToJsonString() - }); + dat_.Add("NAME", "AUTO"); + dat_.Add("VALUE", "True"); + MainWindowViewModel.Updata_Machines(MainWindowViewModel.Machines, "AUTO", "Name='" + machine + "'", "True"); } - else if (drEmployee.Field("Serial") == "PORT2") + else { - stringQueueSerial_2.Enqueue(new QueueSerial - { - ID = index, - DAT = "SC829" + drEmployee.Field("Station") + dat_.ToJsonString() - }); + dat_.Add("NAME", "AUTO"); + dat_.Add("VALUE", "FALSE"); + MainWindowViewModel.Updata_Machines(MainWindowViewModel.Machines, "AUTO", "Name='" + machine + "'", "False"); } - else if (drEmployee.Field("Serial") == "PORT3") - { - stringQueueSerial_3.Enqueue(new QueueSerial + + DataRow drEmployee = MainWindowViewModel.Machines.Select("NAME='" + machine + "'").First(); + int index = Convert.ToInt16(drEmployee.Field("ID")); + if (drEmployee.Field("Type")) + {//网络 + MainWindowViewModel.stringQueue.Enqueue(new MainWindowViewModel.QueueString { ID = index, - DAT = "SC829" + drEmployee.Field("Station") + dat_.ToJsonString() + DAT = "SC829" + drEmployee.Field("SYSKEY") + dat_.ToJsonString() }); } - else if (drEmployee.Field("Serial") == "PORT4") - { - stringQueueSerial_4.Enqueue(new QueueSerial + else + {//串口 + if (drEmployee.Field("Serial") == "PORT1") { - ID = index, - DAT = "SC829" + drEmployee.Field("Station") + dat_.ToJsonString() - }); + stringQueueSerial_1.Enqueue(new QueueSerial + { + ID = index, + DAT = "SC829" + drEmployee.Field("Station") + dat_.ToJsonString() + }); + } + else if (drEmployee.Field("Serial") == "PORT2") + { + stringQueueSerial_2.Enqueue(new QueueSerial + { + ID = index, + DAT = "SC829" + drEmployee.Field("Station") + dat_.ToJsonString() + }); + } + else if (drEmployee.Field("Serial") == "PORT3") + { + stringQueueSerial_3.Enqueue(new QueueSerial + { + ID = index, + DAT = "SC829" + drEmployee.Field("Station") + dat_.ToJsonString() + }); + } + else if (drEmployee.Field("Serial") == "PORT4") + { + stringQueueSerial_4.Enqueue(new QueueSerial + { + ID = index, + DAT = "SC829" + drEmployee.Field("Station") + dat_.ToJsonString() + }); + } } } } @@ -296,49 +302,52 @@ namespace SunlightCentralizedControlManagement_SCCM_.View Dictionary dat_821 = new Dictionary(); dat_821.Clear(); dat_821.Add("INSTRUCTION", "STOP"); - DataRow drEmployee = MainWindowViewModel.Machines.Select("NAME='" + machine + "'").First(); - int index = Convert.ToInt16(drEmployee.Field("ID")); - if (drEmployee.Field("Type")) - {//网络 - MainWindowViewModel.stringQueue.Enqueue(new MainWindowViewModel.QueueString - { - ID = index, - DAT = "SC821" + drEmployee.Field("SYSKEY") + dat_821.ToJsonString() - }); - } - else - {//串口 - if (drEmployee.Field("Serial") == "PORT1") - { - stringQueueSerial_1.Enqueue(new QueueSerial + lock (MainWindowViewModel.Machines.Rows.SyncRoot) + { + DataRow drEmployee = MainWindowViewModel.Machines.Select("NAME='" + machine + "'").First(); + int index = Convert.ToInt16(drEmployee.Field("ID")); + if (drEmployee.Field("Type")) + {//网络 + MainWindowViewModel.stringQueue.Enqueue(new MainWindowViewModel.QueueString { ID = index, - DAT = "SC821" + drEmployee.Field("Station") + dat_821.ToJsonString() + DAT = "SC821" + drEmployee.Field("SYSKEY") + dat_821.ToJsonString() }); } - else if (drEmployee.Field("Serial") == "PORT2") - { - stringQueueSerial_2.Enqueue(new QueueSerial + else + {//串口 + if (drEmployee.Field("Serial") == "PORT1") { - ID = index, - DAT = "SC821" + drEmployee.Field("Station") + dat_821.ToJsonString() - }); - } - else if (drEmployee.Field("Serial") == "PORT3") - { - stringQueueSerial_3.Enqueue(new QueueSerial + stringQueueSerial_1.Enqueue(new QueueSerial + { + ID = index, + DAT = "SC821" + drEmployee.Field("Station") + dat_821.ToJsonString() + }); + } + else if (drEmployee.Field("Serial") == "PORT2") { - ID = index, - DAT = "SC821" + drEmployee.Field("Station") + dat_821.ToJsonString() - }); - } - else if (drEmployee.Field("Serial") == "PORT4") - { - stringQueueSerial_4.Enqueue(new QueueSerial + stringQueueSerial_2.Enqueue(new QueueSerial + { + ID = index, + DAT = "SC821" + drEmployee.Field("Station") + dat_821.ToJsonString() + }); + } + else if (drEmployee.Field("Serial") == "PORT3") { - ID = index, - DAT = "SC821" + drEmployee.Field("Station") + dat_821.ToJsonString() - }); + stringQueueSerial_3.Enqueue(new QueueSerial + { + ID = index, + DAT = "SC821" + drEmployee.Field("Station") + dat_821.ToJsonString() + }); + } + else if (drEmployee.Field("Serial") == "PORT4") + { + stringQueueSerial_4.Enqueue(new QueueSerial + { + ID = index, + DAT = "SC821" + drEmployee.Field("Station") + dat_821.ToJsonString() + }); + } } } } @@ -465,12 +474,49 @@ namespace SunlightCentralizedControlManagement_SCCM_.View } int index = Convert.ToInt16(drEmployee.Field("ID")); - MainWindowViewModel.stringQueue.Enqueue(new MainWindowViewModel.QueueString - { - ID = index, - DAT = "SC833" + drEmployee.Field("SYSKEY") - }); - + if (drEmployee.Field("Type")) + {//网络 + MainWindowViewModel.stringQueue.Enqueue(new MainWindowViewModel.QueueString + { + ID = index, + DAT = "SC833" + drEmployee.Field("SYSKEY") + }); + } + else + {//串口 + if (drEmployee.Field("Serial") == "PORT1") + { + stringQueueSerial_1.Enqueue(new QueueSerial + { + ID = index, + DAT = "SC833" + drEmployee.Field("Station") + }); + } + else if (drEmployee.Field("Serial") == "PORT2") + { + stringQueueSerial_2.Enqueue(new QueueSerial + { + ID = index, + DAT = "SC833" + drEmployee.Field("Station") + }); + } + else if (drEmployee.Field("Serial") == "PORT3") + { + stringQueueSerial_3.Enqueue(new QueueSerial + { + ID = index, + DAT = "SC833" + drEmployee.Field("Station") + }); + } + else if (drEmployee.Field("Serial") == "PORT4") + { + stringQueueSerial_4.Enqueue(new QueueSerial + { + ID = index, + DAT = "SC833" + drEmployee.Field("Station") + }); + } + } machines_info = 2; log.Visibility = Visibility.Collapsed; rdp.Visibility = Visibility.Collapsed; @@ -498,11 +544,49 @@ namespace SunlightCentralizedControlManagement_SCCM_.View dat_821.Add("INSTRUCTION", "CONTINUE"); DataRow drEmployee = MainWindowViewModel.Machines.Select("NAME='" + machine + "'").First(); int index = Convert.ToInt16(drEmployee.Field("ID")); - MainWindowViewModel.stringQueue.Enqueue(new MainWindowViewModel.QueueString - { - ID = index, - DAT = "SC821" + drEmployee.Field("SYSKEY") + dat_821.ToJsonString() - }); + if (drEmployee.Field("Type")) + {//网络 + MainWindowViewModel.stringQueue.Enqueue(new MainWindowViewModel.QueueString + { + ID = index, + DAT = "SC821" + drEmployee.Field("SYSKEY") + dat_821.ToJsonString() + }); + } + else + {//串口 + if (drEmployee.Field("Serial") == "PORT1") + { + stringQueueSerial_1.Enqueue(new QueueSerial + { + ID = index, + DAT = "SC821" + drEmployee.Field("Station") + dat_821.ToJsonString() + }); + } + else if (drEmployee.Field("Serial") == "PORT2") + { + stringQueueSerial_2.Enqueue(new QueueSerial + { + ID = index, + DAT = "SC821" + drEmployee.Field("Station") + dat_821.ToJsonString() + }); + } + else if (drEmployee.Field("Serial") == "PORT3") + { + stringQueueSerial_3.Enqueue(new QueueSerial + { + ID = index, + DAT = "SC821" + drEmployee.Field("Station") + dat_821.ToJsonString() + }); + } + else if (drEmployee.Field("Serial") == "PORT4") + { + stringQueueSerial_4.Enqueue(new QueueSerial + { + ID = index, + DAT = "SC821" + drEmployee.Field("Station") + dat_821.ToJsonString() + }); + } + } } Insert.IsHitTestVisible = false; edit.IsHitTestVisible = false; @@ -521,11 +605,49 @@ namespace SunlightCentralizedControlManagement_SCCM_.View dat_821.Add("INSTRUCTION", "PAUSE"); DataRow drEmployee = MainWindowViewModel.Machines.Select("NAME='" + machine + "'").First(); int index = Convert.ToInt16(drEmployee.Field("ID")); - MainWindowViewModel.stringQueue.Enqueue(new MainWindowViewModel.QueueString - { - ID = index, - DAT = "SC821" + drEmployee.Field("SYSKEY") + dat_821.ToJsonString() - }); + if (drEmployee.Field("Type")) + {//网络 + MainWindowViewModel.stringQueue.Enqueue(new MainWindowViewModel.QueueString + { + ID = index, + DAT = "SC821" + drEmployee.Field("SYSKEY") + dat_821.ToJsonString() + }); + } + else + {//串口 + if (drEmployee.Field("Serial") == "PORT1") + { + stringQueueSerial_1.Enqueue(new QueueSerial + { + ID = index, + DAT = "SC821" + drEmployee.Field("Station") + dat_821.ToJsonString() + }); + } + else if (drEmployee.Field("Serial") == "PORT2") + { + stringQueueSerial_2.Enqueue(new QueueSerial + { + ID = index, + DAT = "SC821" + drEmployee.Field("Station") + dat_821.ToJsonString() + }); + } + else if (drEmployee.Field("Serial") == "PORT3") + { + stringQueueSerial_3.Enqueue(new QueueSerial + { + ID = index, + DAT = "SC821" + drEmployee.Field("Station") + dat_821.ToJsonString() + }); + } + else if (drEmployee.Field("Serial") == "PORT4") + { + stringQueueSerial_4.Enqueue(new QueueSerial + { + ID = index, + DAT = "SC821" + drEmployee.Field("Station") + dat_821.ToJsonString() + }); + } + } } Insert.IsHitTestVisible = true; edit.IsHitTestVisible = true; @@ -545,11 +667,49 @@ namespace SunlightCentralizedControlManagement_SCCM_.View dat_821.Add("INSTRUCTION", "STOP"); DataRow drEmployee = MainWindowViewModel.Machines.Select("NAME='" + machine + "'").First(); int index = Convert.ToInt16(drEmployee.Field("ID")); - MainWindowViewModel.stringQueue.Enqueue(new MainWindowViewModel.QueueString - { - ID = index, - DAT = "SC821" + drEmployee.Field("SYSKEY") + dat_821.ToJsonString() - }); + if (drEmployee.Field("Type")) + {//网络 + MainWindowViewModel.stringQueue.Enqueue(new MainWindowViewModel.QueueString + { + ID = index, + DAT = "SC821" + drEmployee.Field("SYSKEY") + dat_821.ToJsonString() + }); + } + else + {//串口 + if (drEmployee.Field("Serial") == "PORT1") + { + stringQueueSerial_1.Enqueue(new QueueSerial + { + ID = index, + DAT = "SC821" + drEmployee.Field("Station") + dat_821.ToJsonString() + }); + } + else if (drEmployee.Field("Serial") == "PORT2") + { + stringQueueSerial_2.Enqueue(new QueueSerial + { + ID = index, + DAT = "SC821" + drEmployee.Field("Station") + dat_821.ToJsonString() + }); + } + else if (drEmployee.Field("Serial") == "PORT3") + { + stringQueueSerial_3.Enqueue(new QueueSerial + { + ID = index, + DAT = "SC821" + drEmployee.Field("Station") + dat_821.ToJsonString() + }); + } + else if (drEmployee.Field("Serial") == "PORT4") + { + stringQueueSerial_4.Enqueue(new QueueSerial + { + ID = index, + DAT = "SC821" + drEmployee.Field("Station") + dat_821.ToJsonString() + }); + } + } } }//停止 private void ListViewItem_edit(object sender, MouseButtonEventArgs e) @@ -607,11 +767,49 @@ namespace SunlightCentralizedControlManagement_SCCM_.View DataRow drEmployee = MainWindowViewModel.Machines.Select("NAME='" + machine + "'").First(); int index = Convert.ToInt16(drEmployee.Field("ID")); - MainWindowViewModel.stringQueue.Enqueue(new MainWindowViewModel.QueueString - { - ID = index, - DAT = "SC821" + drEmployee.Field("SYSKEY") + dat_821.ToJsonString() - }); + if (drEmployee.Field("Type")) + {//网络 + MainWindowViewModel.stringQueue.Enqueue(new MainWindowViewModel.QueueString + { + ID = index, + DAT = "SC821" + drEmployee.Field("SYSKEY") + dat_821.ToJsonString() + }); + } + else + {//串口 + if (drEmployee.Field("Serial") == "PORT1") + { + stringQueueSerial_1.Enqueue(new QueueSerial + { + ID = index, + DAT = "SC821" + drEmployee.Field("Station") + dat_821.ToJsonString() + }); + } + else if (drEmployee.Field("Serial") == "PORT2") + { + stringQueueSerial_2.Enqueue(new QueueSerial + { + ID = index, + DAT = "SC821" + drEmployee.Field("Station") + dat_821.ToJsonString() + }); + } + else if (drEmployee.Field("Serial") == "PORT3") + { + stringQueueSerial_3.Enqueue(new QueueSerial + { + ID = index, + DAT = "SC821" + drEmployee.Field("Station") + dat_821.ToJsonString() + }); + } + else if (drEmployee.Field("Serial") == "PORT4") + { + stringQueueSerial_4.Enqueue(new QueueSerial + { + ID = index, + DAT = "SC821" + drEmployee.Field("Station") + dat_821.ToJsonString() + }); + } + } TechnologicalProcess_bool = true; } private void ListViewItem_Jump(object sender, MouseButtonEventArgs e) @@ -635,11 +833,49 @@ namespace SunlightCentralizedControlManagement_SCCM_.View DataRow drEmployee = MainWindowViewModel.Machines.Select("NAME='" + machine + "'").First(); int index = Convert.ToInt16(drEmployee.Field("ID")); - MainWindowViewModel.stringQueue.Enqueue(new MainWindowViewModel.QueueString - { - ID = index, - DAT = "SC821" + drEmployee.Field("SYSKEY") + dat_821.ToJsonString() - }); + if (drEmployee.Field("Type")) + {//网络 + MainWindowViewModel.stringQueue.Enqueue(new MainWindowViewModel.QueueString + { + ID = index, + DAT = "SC821" + drEmployee.Field("SYSKEY") + dat_821.ToJsonString() + }); + } + else + {//串口 + if (drEmployee.Field("Serial") == "PORT1") + { + stringQueueSerial_1.Enqueue(new QueueSerial + { + ID = index, + DAT = "SC821" + drEmployee.Field("Station") + dat_821.ToJsonString() + }); + } + else if (drEmployee.Field("Serial") == "PORT2") + { + stringQueueSerial_2.Enqueue(new QueueSerial + { + ID = index, + DAT = "SC821" + drEmployee.Field("Station") + dat_821.ToJsonString() + }); + } + else if (drEmployee.Field("Serial") == "PORT3") + { + stringQueueSerial_3.Enqueue(new QueueSerial + { + ID = index, + DAT = "SC821" + drEmployee.Field("Station") + dat_821.ToJsonString() + }); + } + else if (drEmployee.Field("Serial") == "PORT4") + { + stringQueueSerial_4.Enqueue(new QueueSerial + { + ID = index, + DAT = "SC821" + drEmployee.Field("Station") + dat_821.ToJsonString() + }); + } + } TechnologicalProcess_bool = true; }//跳步 @@ -698,11 +934,49 @@ namespace SunlightCentralizedControlManagement_SCCM_.View DataRow drEmployee = MainWindowViewModel.Machines.Select("NAME='" + machine + "'").First(); int index = Convert.ToInt16(drEmployee.Field("ID")); - MainWindowViewModel.stringQueue.Enqueue(new MainWindowViewModel.QueueString - { - ID = index, - DAT = "SC821" + drEmployee.Field("SYSKEY") + dat_821.ToJsonString() - }); + if (drEmployee.Field("Type")) + {//网络 + MainWindowViewModel.stringQueue.Enqueue(new MainWindowViewModel.QueueString + { + ID = index, + DAT = "SC821" + drEmployee.Field("SYSKEY") + dat_821.ToJsonString() + }); + } + else + {//串口 + if (drEmployee.Field("Serial") == "PORT1") + { + stringQueueSerial_1.Enqueue(new QueueSerial + { + ID = index, + DAT = "SC821" + drEmployee.Field("Station") + dat_821.ToJsonString() + }); + } + else if (drEmployee.Field("Serial") == "PORT2") + { + stringQueueSerial_2.Enqueue(new QueueSerial + { + ID = index, + DAT = "SC821" + drEmployee.Field("Station") + dat_821.ToJsonString() + }); + } + else if (drEmployee.Field("Serial") == "PORT3") + { + stringQueueSerial_3.Enqueue(new QueueSerial + { + ID = index, + DAT = "SC821" + drEmployee.Field("Station") + dat_821.ToJsonString() + }); + } + else if (drEmployee.Field("Serial") == "PORT4") + { + stringQueueSerial_4.Enqueue(new QueueSerial + { + ID = index, + DAT = "SC821" + drEmployee.Field("Station") + dat_821.ToJsonString() + }); + } + } } private void ListViewItem_Delete(object sender, MouseButtonEventArgs e) @@ -715,11 +989,49 @@ namespace SunlightCentralizedControlManagement_SCCM_.View dat_821.Add("ID", ID); DataRow drEmployee = MainWindowViewModel.Machines.Select("NAME='" + machine + "'").First(); int index = Convert.ToInt16(drEmployee.Field("ID")); - MainWindowViewModel.stringQueue.Enqueue(new MainWindowViewModel.QueueString - { - ID = index, - DAT = "SC821" + drEmployee.Field("SYSKEY") + dat_821.ToJsonString() - }); + if (drEmployee.Field("Type")) + {//网络 + MainWindowViewModel.stringQueue.Enqueue(new MainWindowViewModel.QueueString + { + ID = index, + DAT = "SC821" + drEmployee.Field("SYSKEY") + dat_821.ToJsonString() + }); + } + else + {//串口 + if (drEmployee.Field("Serial") == "PORT1") + { + stringQueueSerial_1.Enqueue(new QueueSerial + { + ID = index, + DAT = "SC821" + drEmployee.Field("Station") + dat_821.ToJsonString() + }); + } + else if (drEmployee.Field("Serial") == "PORT2") + { + stringQueueSerial_2.Enqueue(new QueueSerial + { + ID = index, + DAT = "SC821" + drEmployee.Field("Station") + dat_821.ToJsonString() + }); + } + else if (drEmployee.Field("Serial") == "PORT3") + { + stringQueueSerial_3.Enqueue(new QueueSerial + { + ID = index, + DAT = "SC821" + drEmployee.Field("Station") + dat_821.ToJsonString() + }); + } + else if (drEmployee.Field("Serial") == "PORT4") + { + stringQueueSerial_4.Enqueue(new QueueSerial + { + ID = index, + DAT = "SC821" + drEmployee.Field("Station") + dat_821.ToJsonString() + }); + } + } MainWindowViewModel.dt_TP.Select("Step="+ID).First().Delete(); MainWindowViewModel.dt_TP.AcceptChanges(); @@ -762,6 +1074,7 @@ namespace SunlightCentralizedControlManagement_SCCM_.View } } private void MenuItem_Delete(object sender, RoutedEventArgs e)//右键删除 + { int rownum = Gridstep.SelectedIndex;//获取鼠标选中行并定义变量 if (rownum != -1)//判断鼠标定位是否有效 @@ -775,11 +1088,49 @@ namespace SunlightCentralizedControlManagement_SCCM_.View dat_821.Add("ID", ID); DataRow drEmployee = MainWindowViewModel.Machines.Select("NAME='" + machine + "'").First(); int index = Convert.ToInt16(drEmployee.Field("ID")); - MainWindowViewModel.stringQueue.Enqueue(new MainWindowViewModel.QueueString - { - ID = index, - DAT = "SC821" + drEmployee.Field("SYSKEY") + dat_821.ToJsonString() - }); + if (drEmployee.Field("Type")) + {//网络 + MainWindowViewModel.stringQueue.Enqueue(new MainWindowViewModel.QueueString + { + ID = index, + DAT = "SC821" + drEmployee.Field("SYSKEY") + dat_821.ToJsonString() + }); + } + else + {//串口 + if (drEmployee.Field("Serial") == "PORT1") + { + stringQueueSerial_1.Enqueue(new QueueSerial + { + ID = index, + DAT = "SC821" + drEmployee.Field("Station") + dat_821.ToJsonString() + }); + } + else if (drEmployee.Field("Serial") == "PORT2") + { + stringQueueSerial_2.Enqueue(new QueueSerial + { + ID = index, + DAT = "SC821" + drEmployee.Field("Station") + dat_821.ToJsonString() + }); + } + else if (drEmployee.Field("Serial") == "PORT3") + { + stringQueueSerial_3.Enqueue(new QueueSerial + { + ID = index, + DAT = "SC821" + drEmployee.Field("Station") + dat_821.ToJsonString() + }); + } + else if (drEmployee.Field("Serial") == "PORT4") + { + stringQueueSerial_4.Enqueue(new QueueSerial + { + ID = index, + DAT = "SC821" + drEmployee.Field("Station") + dat_821.ToJsonString() + }); + } + } MainWindowViewModel.dt_TP.Select("Step=" + ID).First().Delete(); MainWindowViewModel.dt_TP.AcceptChanges(); diff --git a/ViewModel/MainWindowViewModel.cs b/ViewModel/MainWindowViewModel.cs index 9e46afb..f6a1a78 100644 --- a/ViewModel/MainWindowViewModel.cs +++ b/ViewModel/MainWindowViewModel.cs @@ -86,7 +86,8 @@ namespace SunlightCentralizedControlManagement_SCCM_.ViewModel public static SQLiteHelper SQLiteChartAdress = null; //定义数据库 private static readonly string ChartAdress = Environment.CurrentDirectory + "\\DataBase\\Chart.db"; //数据库路径 public static DataTable Machines = new DataTable(); //设备表缓存 - // public static DataRow MachinesROW; + //public static DataTableManager Machines = new DataTableManager("MachinesTa"); + // public static DataRow MachinesROW; public static DataTable USER_data = new DataTable(); public static DataTable Dyelot_CALL = new DataTable(); public static DataTable Whole_dat = new DataTable(); @@ -235,107 +236,27 @@ namespace SunlightCentralizedControlManagement_SCCM_.ViewModel { string WorkOrderdata_m = WorkOrderstepdata.Select()[k].Field("Machines").ToString(); //string m= WorkOrderstepdata.Rows[k].Field("Machines"); - if (Convert.ToBoolean(Selet_Machines(Machines, "Type", "Name='" + WorkOrderdata_m + "'"))) - {//网络 - //string WorkOrderdata_m = WorkOrderstepdata.Select()[k].Field("Machines").ToString(); - DataTable dataTable = SQLiteHelpers.ExecuteDataSet("select * from WorkorderSteps where WorkOrder='" + - WorkOrderstepdata.Select()[k].Field("WorkOrder").ToString() + "'", null).Tables[0]; - int index = Convert.ToInt16(Selet_Machines(Machines, "ID", "Name='" + WorkOrderdata_m + "'").ToString()); - stringQueue.Enqueue(new QueueString - { - ID = index, - DAT = "SC811" + Selet_Machines(Machines, "SYSKEY", "ID='" + index + "'") + dataTable.ToJsonString() - }); - SQLiteHelpers.Update("WorkOrder", new Dictionary { { "State", 112 } }, - "WorkOrder ='" + WorkOrderstepdata.Select()[k].Field("WorkOrder").ToString() + "'", null); - } - else - {//串口 - DataTable dataTable = SQLiteHelpers.ExecuteDataSet("select * from WorkorderSteps where WorkOrder='" + - WorkOrderstepdata.Select()[k].Field("WorkOrder").ToString() + "' AND ReDye ='"+ - WorkOrderstepdata.Select()[k].Field("ReDye").ToString() + "' AND Mode<> '201'", null).Tables[0]; - - int index = Convert.ToInt16(Selet_Machines(Machines, "ID", "Name='" + WorkOrderdata_m + "'").ToString()); - if (Selet_Machines(Machines, "Serial", "Name='" + WorkOrderdata_m + "'").ToString() == "PORT1") - { - stringQueueSerial_1.Enqueue(new QueueSerial - { - ID = index, - DAT = "SC811" + Selet_Machines(Machines, "SYSKEY", "ID='" + index + "'") + dataTable.Rows[0].ToJsonString() - }); - } - else if (Selet_Machines(Machines, "Serial", "Name='" + WorkOrderdata_m + "'").ToString() == "PORT2") - { - stringQueueSerial_2.Enqueue(new QueueSerial - { - ID = index, - DAT = "SC811" + Selet_Machines(Machines, "SYSKEY", "ID='" + index + "'") + dataTable.Rows[0].ToJsonString() - }); - } - else if (Selet_Machines(Machines, "Serial", "Name='" + WorkOrderdata_m + "'").ToString() == "PORT3") - { - stringQueueSerial_3.Enqueue(new QueueSerial - { - ID = index, - DAT = "SC811" + Selet_Machines(Machines, "SYSKEY", "ID='" + index + "'") + dataTable.Rows[0].ToJsonString() - }); - } - else if (Selet_Machines(Machines, "Serial", "Name='" + WorkOrderdata_m + "'").ToString() == "PORT4") - { - stringQueueSerial_4.Enqueue(new QueueSerial - { - ID = index, - DAT = "SC811" + Selet_Machines(Machines, "SYSKEY", "ID='" + index + "'") + dataTable.Rows[0].ToJsonString() - }); - } - } - } - /*下传工单总览*/ - DataTable WorkOrderdata = SQLiteHelpers.ExecuteDataSet("select * from WorkOrder where (State='100' or State='110') AND EndTime >'" + - DateTime.Now.AddHours(-8).ToString("yyyy/MM/dd HH:mm:ss") + "'", null).Tables[0]; //读取表写入缓存 - for (int k = 0; k < WorkOrderdata.Rows.Count; k++) - { - string WorkOrderdata_m = WorkOrderdata.Select()[k].Field("Machines").ToString(); - //string m = WorkOrderdata.Rows[k].Field("Machines"); - if (Convert.ToBoolean( Selet_Machines(Machines, "Type", "Name='" + WorkOrderdata_m + "'"))) - {//网络 - //string WorkOrderdata_m = WorkOrderdata.Select()[k].Field("Machines").ToString(); - string State = Selet_Machines(Machines, "State", "Name='" + WorkOrderdata_m + "'").ToString(); - - if ((State == "101") || (State == "201") || (State == "202") || (State == "309")) - { - DataTable dataTable = WorkOrderdata.Clone(); - // WorkOrderdata.Columns.Remove("Machines"); - DataRow dt_temp = WorkOrderdata.Select()[k]; - dt_temp.BeginEdit(); - dt_temp["State"] = "101"; - dt_temp.EndEdit(); - dataTable.Rows.Add(dt_temp.ItemArray); - + lock (MainWindowViewModel.Machines.Rows.SyncRoot) + { + if (Convert.ToBoolean(Selet_Machines(Machines, "Type", "Name='" + WorkOrderdata_m + "'"))) + {//网络 + //string WorkOrderdata_m = WorkOrderstepdata.Select()[k].Field("Machines").ToString(); + DataTable dataTable = SQLiteHelpers.ExecuteDataSet("select * from WorkorderSteps where WorkOrder='" + + WorkOrderstepdata.Select()[k].Field("WorkOrder").ToString() + "'", null).Tables[0]; int index = Convert.ToInt16(Selet_Machines(Machines, "ID", "Name='" + WorkOrderdata_m + "'").ToString()); stringQueue.Enqueue(new QueueString { ID = index, - DAT = "SC810" + Selet_Machines(Machines, "SYSKEY", "ID='" + index + "'") + DataTableToDictionary(dataTable).ToJsonString() + DAT = "SC811" + Selet_Machines(Machines, "SYSKEY", "ID='" + index + "'") + dataTable.ToJsonString() }); - SQLiteHelpers.Update("WorkOrder", new Dictionary { { "State", 110 } }, - "WorkOrder ='" + WorkOrderdata.Select()[k].Field("WorkOrder").ToString() + "'", null); + SQLiteHelpers.Update("WorkOrder", new Dictionary { { "State", 112 } }, + "WorkOrder ='" + WorkOrderstepdata.Select()[k].Field("WorkOrder").ToString() + "'", null); } - } - else - {//串口 - //string WorkOrderdata_m = WorkOrderdata.Select()[k].Field("Machines").ToString(); - string State = Selet_Machines(Machines, "State", "Name='" + WorkOrderdata_m + "'").ToString(); - - if ((State == "101") || (State == "201") || (State == "202") || (State == "309")) - { - DataTable dataTable = WorkOrderdata.Clone(); - // WorkOrderdata.Columns.Remove("Machines"); - DataRow dt_temp = WorkOrderdata.Select()[k]; - dt_temp.BeginEdit(); - dt_temp["State"] = "101"; - dt_temp.EndEdit(); - dataTable.Rows.Add(dt_temp.ItemArray); + else + {//串口 + DataTable dataTable = SQLiteHelpers.ExecuteDataSet("select * from WorkorderSteps where WorkOrder='" + + WorkOrderstepdata.Select()[k].Field("WorkOrder").ToString() + "' AND ReDye ='" + + WorkOrderstepdata.Select()[k].Field("ReDye").ToString() + "' AND Mode<> '201'", null).Tables[0]; int index = Convert.ToInt16(Selet_Machines(Machines, "ID", "Name='" + WorkOrderdata_m + "'").ToString()); if (Selet_Machines(Machines, "Serial", "Name='" + WorkOrderdata_m + "'").ToString() == "PORT1") @@ -343,7 +264,7 @@ namespace SunlightCentralizedControlManagement_SCCM_.ViewModel stringQueueSerial_1.Enqueue(new QueueSerial { ID = index, - DAT = "SC810" + Selet_Machines(Machines, "SYSKEY", "ID='" + index + "'") + DataTableToDictionary(dataTable).ToJsonString() + DAT = "SC811" + Selet_Machines(Machines, "SYSKEY", "ID='" + index + "'") + dataTable.Rows[0].ToJsonString() }); } else if (Selet_Machines(Machines, "Serial", "Name='" + WorkOrderdata_m + "'").ToString() == "PORT2") @@ -351,7 +272,7 @@ namespace SunlightCentralizedControlManagement_SCCM_.ViewModel stringQueueSerial_2.Enqueue(new QueueSerial { ID = index, - DAT = "SC810" + Selet_Machines(Machines, "SYSKEY", "ID='" + index + "'") + DataTableToDictionary(dataTable).ToJsonString() + DAT = "SC811" + Selet_Machines(Machines, "SYSKEY", "ID='" + index + "'") + dataTable.Rows[0].ToJsonString() }); } else if (Selet_Machines(Machines, "Serial", "Name='" + WorkOrderdata_m + "'").ToString() == "PORT3") @@ -359,7 +280,7 @@ namespace SunlightCentralizedControlManagement_SCCM_.ViewModel stringQueueSerial_3.Enqueue(new QueueSerial { ID = index, - DAT = "SC810" + Selet_Machines(Machines, "SYSKEY", "ID='" + index + "'") + DataTableToDictionary(dataTable).ToJsonString() + DAT = "SC811" + Selet_Machines(Machines, "SYSKEY", "ID='" + index + "'") + dataTable.Rows[0].ToJsonString() }); } else if (Selet_Machines(Machines, "Serial", "Name='" + WorkOrderdata_m + "'").ToString() == "PORT4") @@ -367,172 +288,203 @@ namespace SunlightCentralizedControlManagement_SCCM_.ViewModel stringQueueSerial_4.Enqueue(new QueueSerial { ID = index, - DAT = "SC810" + Selet_Machines(Machines, "SYSKEY", "ID='" + index + "'") + DataTableToDictionary(dataTable).ToJsonString() + DAT = "SC811" + Selet_Machines(Machines, "SYSKEY", "ID='" + index + "'") + dataTable.Rows[0].ToJsonString() }); } - - SQLiteHelpers.Update("WorkOrder", new Dictionary { { "State", 110 } }, - "WorkOrder ='" + WorkOrderdata.Select()[k].Field("WorkOrder").ToString() + "'", null); } } } - /*下传工单设置*/ - DataTable WorkOrderset_ = SQLiteHelpers.ExecuteDataSet("select * from WorkOrder where (State='113'or State='114') AND EndTime >'" + + /*下传工单总览*/ + DataTable WorkOrderdata = SQLiteHelpers.ExecuteDataSet("select * from WorkOrder where (State='100' or State='110') AND EndTime >'" + DateTime.Now.AddHours(-8).ToString("yyyy/MM/dd HH:mm:ss") + "'", null).Tables[0]; //读取表写入缓存 - for (int k = 0; k < WorkOrderset_.Rows.Count; k++) + for (int k = 0; k < WorkOrderdata.Rows.Count; k++) { - string WorkOrderset_m = WorkOrderset_.Select()[k].Field("Machines").ToString(); - //string m = WorkOrderset_.Rows[k].Field("Machines"); - if (Convert.ToBoolean(Selet_Machines(Machines, "Type", "Name='" + WorkOrderset_m + "'"))) - {//网络 - //string WorkOrderset_m = WorkOrderset_.Select()[k].Field("Machines").ToString(); - string WorkOrderset_w = WorkOrderset_.Select()[k].Field("WorkOrder").ToString(); - int index = Convert.ToInt16(Selet_Machines(Machines, "ID", "Name='" + WorkOrderset_m + "'").ToString()); + string WorkOrderdata_m = WorkOrderdata.Select()[k].Field("Machines").ToString(); + //string m = WorkOrderdata.Rows[k].Field("Machines"); + lock (MainWindowViewModel.Machines.Rows.SyncRoot) + { + if (Convert.ToBoolean(Selet_Machines(Machines, "Type", "Name='" + WorkOrderdata_m + "'"))) + {//网络 + //string WorkOrderdata_m = WorkOrderdata.Select()[k].Field("Machines").ToString(); + string State = Selet_Machines(Machines, "State", "Name='" + WorkOrderdata_m + "'").ToString(); - DataTable WorkOrder_set = SQLiteHelpers.ExecuteDataSet("select * from WorkOrderSet where WorkOrder='" + - WorkOrderset_w + "'", null).Tables[0]; //读取表写入缓存 - if (WorkOrder_set.Rows.Count > 0) - { - stringQueue.Enqueue(new QueueString + if ((State == "101") || (State == "201") || (State == "202") || (State == "309")) { - ID = index, - DAT = "SC812" + Selet_Machines(Machines, "SYSKEY", "ID='" + index + "'") + DataTableToDictionary(WorkOrder_set).ToJsonString() - }); - } + DataTable dataTable = WorkOrderdata.Clone(); + // WorkOrderdata.Columns.Remove("Machines"); + DataRow dt_temp = WorkOrderdata.Select()[k]; + dt_temp.BeginEdit(); + dt_temp["State"] = "101"; + dt_temp.EndEdit(); + dataTable.Rows.Add(dt_temp.ItemArray); - SQLiteHelpers.Update("WorkOrder", new Dictionary { { "State", 114 } }, - "WorkOrder ='" + WorkOrderset_.Select()[k].Field("WorkOrder").ToString() + "'", null); - } - else - {//串口 - //string WorkOrderset_m = WorkOrderset_.Select()[k].Field("Machines").ToString(); - string WorkOrderset_w = WorkOrderset_.Select()[k].Field("WorkOrder").ToString(); - - DataTable WorkOrder_set = SQLiteHelpers.ExecuteDataSet("select * from WorkOrderSet where WorkOrder='" + - WorkOrderset_w + "'", null).Tables[0]; //读取表写入缓存 - if (WorkOrder_set.Rows.Count > 0) - { - int index = Convert.ToInt16(Selet_Machines(Machines, "ID", "Name='" + WorkOrderset_m + "'").ToString()); - if (Selet_Machines(Machines, "Serial", "Name='" + WorkOrderset_m + "'").ToString() == "PORT1") - { - stringQueueSerial_1.Enqueue(new QueueSerial + int index = Convert.ToInt16(Selet_Machines(Machines, "ID", "Name='" + WorkOrderdata_m + "'").ToString()); + stringQueue.Enqueue(new QueueString { ID = index, - DAT = "SC812[" + - Selet_Machines(Machines, "Station", "ID='" + k + "'") + "]" + - DataTableToDictionary(WorkOrder_set).ToJsonString() + DAT = "SC810" + Selet_Machines(Machines, "SYSKEY", "ID='" + index + "'") + DataTableToDictionary(dataTable).ToJsonString() }); + SQLiteHelpers.Update("WorkOrder", new Dictionary { { "State", 110 } }, + "WorkOrder ='" + WorkOrderdata.Select()[k].Field("WorkOrder").ToString() + "'", null); } - else if (Selet_Machines(Machines, "Serial", "Name='" + WorkOrderset_m + "'").ToString() == "PORT2") + } + else + {//串口 + //string WorkOrderdata_m = WorkOrderdata.Select()[k].Field("Machines").ToString(); + string State = Selet_Machines(Machines, "State", "Name='" + WorkOrderdata_m + "'").ToString(); + + if ((State == "101") || (State == "201") || (State == "202") || (State == "309")) { - stringQueueSerial_2.Enqueue(new QueueSerial + DataTable dataTable = WorkOrderdata.Clone(); + // WorkOrderdata.Columns.Remove("Machines"); + DataRow dt_temp = WorkOrderdata.Select()[k]; + dt_temp.BeginEdit(); + dt_temp["State"] = "101"; + dt_temp.EndEdit(); + dataTable.Rows.Add(dt_temp.ItemArray); + + int index = Convert.ToInt16(Selet_Machines(Machines, "ID", "Name='" + WorkOrderdata_m + "'").ToString()); + if (Selet_Machines(Machines, "Serial", "Name='" + WorkOrderdata_m + "'").ToString() == "PORT1") { - ID = index, - DAT = "SC812[" + - Selet_Machines(Machines, "Station", "ID='" + k + "'") + "]" + - DataTableToDictionary(WorkOrder_set).ToJsonString() - }); - } - else if (Selet_Machines(Machines, "Serial", "Name='" + WorkOrderset_m + "'").ToString() == "PORT3") - { - stringQueueSerial_3.Enqueue(new QueueSerial + stringQueueSerial_1.Enqueue(new QueueSerial + { + ID = index, + DAT = "SC810" + Selet_Machines(Machines, "SYSKEY", "ID='" + index + "'") + DataTableToDictionary(dataTable).ToJsonString() + }); + } + else if (Selet_Machines(Machines, "Serial", "Name='" + WorkOrderdata_m + "'").ToString() == "PORT2") { - ID = index, - DAT = "SC812[" + - Selet_Machines(Machines, "Station", "ID='" + k + "'") + "]" + - DataTableToDictionary(WorkOrder_set).ToJsonString() - }); - } - else if (Selet_Machines(Machines, "Serial", "Name='" + WorkOrderset_m + "'").ToString() == "PORT4") - { - stringQueueSerial_4.Enqueue(new QueueSerial + stringQueueSerial_2.Enqueue(new QueueSerial + { + ID = index, + DAT = "SC810" + Selet_Machines(Machines, "SYSKEY", "ID='" + index + "'") + DataTableToDictionary(dataTable).ToJsonString() + }); + } + else if (Selet_Machines(Machines, "Serial", "Name='" + WorkOrderdata_m + "'").ToString() == "PORT3") { - ID = index, - DAT = "SC812[" + - Selet_Machines(Machines, "Station", "ID='" + k + "'") + "]" + - DataTableToDictionary(WorkOrder_set).ToJsonString() - }); + stringQueueSerial_3.Enqueue(new QueueSerial + { + ID = index, + DAT = "SC810" + Selet_Machines(Machines, "SYSKEY", "ID='" + index + "'") + DataTableToDictionary(dataTable).ToJsonString() + }); + } + else if (Selet_Machines(Machines, "Serial", "Name='" + WorkOrderdata_m + "'").ToString() == "PORT4") + { + stringQueueSerial_4.Enqueue(new QueueSerial + { + ID = index, + DAT = "SC810" + Selet_Machines(Machines, "SYSKEY", "ID='" + index + "'") + DataTableToDictionary(dataTable).ToJsonString() + }); + } + + SQLiteHelpers.Update("WorkOrder", new Dictionary { { "State", 110 } }, + "WorkOrder ='" + WorkOrderdata.Select()[k].Field("WorkOrder").ToString() + "'", null); } } - SQLiteHelpers.Update("WorkOrder", new Dictionary { { "State", 110 } }, - "WorkOrder ='" + WorkOrderdata.Select()[k].Field("WorkOrder").ToString() + "'", null); - } } - - //系统时间 - Sys_Time = DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss"); - //更新机台状态与发送指令 - foreach (DataRow MachinesRow in Machines.Rows) - { - if (Convert.ToBoolean(MachinesRow["Type"])) + /*下传工单设置*/ + DataTable WorkOrderset_ = SQLiteHelpers.ExecuteDataSet("select * from WorkOrder where (State='113'or State='114') AND EndTime >'" + + DateTime.Now.AddHours(-8).ToString("yyyy/MM/dd HH:mm:ss") + "'", null).Tables[0]; //读取表写入缓存 + for (int k = 0; k < WorkOrderset_.Rows.Count; k++) + { + string WorkOrderset_m = WorkOrderset_.Select()[k].Field("Machines").ToString(); + //string m = WorkOrderset_.Rows[k].Field("Machines"); + lock (MainWindowViewModel.Machines.Rows.SyncRoot) { - if (MachinesRow["State"].ToString() == "802") - { - stringQueue.Enqueue(new QueueString - { - ID = Convert.ToInt16( MachinesRow["ID"]), - DAT = "SC830" + MachinesRow["SYSKEY"] - });//信息插入队列 + if (Convert.ToBoolean(Selet_Machines(Machines, "Type", "Name='" + WorkOrderset_m + "'"))) + {//网络 + //string WorkOrderset_m = WorkOrderset_.Select()[k].Field("Machines").ToString(); + string WorkOrderset_w = WorkOrderset_.Select()[k].Field("WorkOrder").ToString(); + int index = Convert.ToInt16(Selet_Machines(Machines, "ID", "Name='" + WorkOrderset_m + "'").ToString()); - bool mode =Convert.ToBoolean( MachinesRow["LOCK"]) ;//发送锁定状态 - if (mode) + DataTable WorkOrder_set = SQLiteHelpers.ExecuteDataSet("select * from WorkOrderSet where WorkOrder='" + + WorkOrderset_w + "'", null).Tables[0]; //读取表写入缓存 + if (WorkOrder_set.Rows.Count > 0) { - Dictionary dat_829 = new Dictionary(); - dat_829.Clear(); - dat_829.Add("NAME", "LOCK"); - dat_829.Add("VALUE", "True"); - DataRow drEmployee = Machines.Select("ID='" + MachinesRow["ID"] + "'").First(); - int index = Convert.ToInt16(drEmployee.Field("ID")); stringQueue.Enqueue(new QueueString { ID = index, - DAT = "SC829" + Selet_Machines(Machines, "SYSKEY", "ID='" + index + "'") + dat_829.ToJsonString() + DAT = "SC812" + Selet_Machines(Machines, "SYSKEY", "ID='" + index + "'") + DataTableToDictionary(WorkOrder_set).ToJsonString() }); } - Updata_Machines(Machines, "State", "ID='" + MachinesRow["ID"] + "'", "101"); - } - int m_run =Convert.ToInt16( MachinesRow["WORK_RUN"]); - if (m_run == 0) - { - Updata_Machines(Machines, "State", "ID='" + MachinesRow["ID"] + "'", "101");//停止状态 - } - else if (m_run == 1) - { - Updata_Machines(Machines, "State", "ID='" + MachinesRow["ID"] + "'", "101");//暂停状态 - } - else if (m_run == 2) - { - Updata_Machines(Machines, "State", "ID='" + MachinesRow["ID"] + "'", "202");//运行 - } - - if (Convert.ToBoolean(MachinesRow["ERR"])) - { - Updata_Machines(Machines, "State", "ID='" + MachinesRow["ID"] + "'", "309");//错误 + SQLiteHelpers.Update("WorkOrder", new Dictionary { { "State", 114 } }, + "WorkOrder ='" + WorkOrderset_.Select()[k].Field("WorkOrder").ToString() + "'", null); } + else + {//串口 + //string WorkOrderset_m = WorkOrderset_.Select()[k].Field("Machines").ToString(); + string WorkOrderset_w = WorkOrderset_.Select()[k].Field("WorkOrder").ToString(); - string mac_s = MachinesRow["State"].ToString(); - if ((mac_s == "101") || (mac_s == "201") || (mac_s == "202") || (mac_s == "301") || (mac_s == "309"))//获取信息 - { - stringQueueinf.Enqueue(new QueueString + DataTable WorkOrder_set = SQLiteHelpers.ExecuteDataSet("select * from WorkOrderSet where WorkOrder='" + + WorkOrderset_w + "'", null).Tables[0]; //读取表写入缓存 + if (WorkOrder_set.Rows.Count > 0) { - ID = Convert.ToInt16( MachinesRow["ID"]), - DAT = "SC830" + MachinesRow["SYSKEY"] - });//信息插入队列 + int index = Convert.ToInt16(Selet_Machines(Machines, "ID", "Name='" + WorkOrderset_m + "'").ToString()); + if (Selet_Machines(Machines, "Serial", "Name='" + WorkOrderset_m + "'").ToString() == "PORT1") + { + stringQueueSerial_1.Enqueue(new QueueSerial + { + ID = index, + DAT = "SC812[" + + Selet_Machines(Machines, "Station", "ID='" + k + "'") + "]" + + DataTableToDictionary(WorkOrder_set).ToJsonString() + }); + } + else if (Selet_Machines(Machines, "Serial", "Name='" + WorkOrderset_m + "'").ToString() == "PORT2") + { + stringQueueSerial_2.Enqueue(new QueueSerial + { + ID = index, + DAT = "SC812[" + + Selet_Machines(Machines, "Station", "ID='" + k + "'") + "]" + + DataTableToDictionary(WorkOrder_set).ToJsonString() + }); + } + else if (Selet_Machines(Machines, "Serial", "Name='" + WorkOrderset_m + "'").ToString() == "PORT3") + { + stringQueueSerial_3.Enqueue(new QueueSerial + { + ID = index, + DAT = "SC812[" + + Selet_Machines(Machines, "Station", "ID='" + k + "'") + "]" + + DataTableToDictionary(WorkOrder_set).ToJsonString() + }); + } + else if (Selet_Machines(Machines, "Serial", "Name='" + WorkOrderset_m + "'").ToString() == "PORT4") + { + stringQueueSerial_4.Enqueue(new QueueSerial + { + ID = index, + DAT = "SC812[" + + Selet_Machines(Machines, "Station", "ID='" + k + "'") + "]" + + DataTableToDictionary(WorkOrder_set).ToJsonString() + }); + } + } + SQLiteHelpers.Update("WorkOrder", new Dictionary { { "State", 110 } }, + "WorkOrder ='" + WorkOrderdata.Select()[k].Field("WorkOrder").ToString() + "'", null); } } - else - {//串口发送 - if (MachinesRow["State"].ToString() == "802") + } + + //系统时间 + Sys_Time = DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss"); + //更新机台状态与发送指令 + lock (MainWindowViewModel.Machines.Rows.SyncRoot) + { + foreach (DataRow MachinesRow in Machines.Rows) + { + if (Convert.ToBoolean(MachinesRow["Type"])) { - if (MachinesRow["Serial"].ToString() == "PORT1") + if (MachinesRow["State"].ToString() == "802") { - stringQueueSerial_1.Enqueue(new QueueSerial + stringQueue.Enqueue(new QueueString { ID = Convert.ToInt16(MachinesRow["ID"]), - DAT = "SC830[" + MachinesRow["Station"] + "]" - }); + DAT = "SC830" + MachinesRow["SYSKEY"] + });//信息插入队列 bool mode = Convert.ToBoolean(MachinesRow["LOCK"]);//发送锁定状态 if (mode) @@ -541,203 +493,167 @@ namespace SunlightCentralizedControlManagement_SCCM_.ViewModel dat_829.Clear(); dat_829.Add("NAME", "LOCK"); dat_829.Add("VALUE", "True"); - stringQueueSerial_1.Enqueue(new QueueSerial + DataRow drEmployee = Machines.Select("ID='" + MachinesRow["ID"] + "'").First(); + int index = Convert.ToInt16(drEmployee.Field("ID")); + stringQueue.Enqueue(new QueueString { - ID = Convert.ToInt16(MachinesRow["ID"]), - DAT = "SC829[" + MachinesRow["Station"] + "]" + dat_829.ToJsonString() + ID = index, + DAT = "SC829" + Selet_Machines(Machines, "SYSKEY", "ID='" + index + "'") + dat_829.ToJsonString() }); } + + Updata_Machines(Machines, "State", "ID='" + MachinesRow["ID"] + "'", "101"); } - else if (MachinesRow["Serial"].ToString() == "PORT2") + int m_run = Convert.ToInt16(MachinesRow["WORK_RUN"]); + if (m_run == 0) { - stringQueueSerial_2.Enqueue(new QueueSerial + Updata_Machines(Machines, "State", "ID='" + MachinesRow["ID"] + "'", "101");//停止状态 + } + else if (m_run == 1) + { + Updata_Machines(Machines, "State", "ID='" + MachinesRow["ID"] + "'", "101");//暂停状态 + } + else if (m_run == 2) + { + Updata_Machines(Machines, "State", "ID='" + MachinesRow["ID"] + "'", "202");//运行 + } + + if (Convert.ToBoolean(MachinesRow["ERR"])) + { + Updata_Machines(Machines, "State", "ID='" + MachinesRow["ID"] + "'", "309");//错误 + } + + string mac_s = MachinesRow["State"].ToString(); + if ((mac_s == "101") || (mac_s == "201") || (mac_s == "202") || (mac_s == "301") || (mac_s == "309"))//获取信息 + { + stringQueueinf.Enqueue(new QueueString { ID = Convert.ToInt16(MachinesRow["ID"]), - DAT = "SC830[" + MachinesRow["Station"] + "]" - }); - - bool mode = Convert.ToBoolean(MachinesRow["LOCK"]);//发送锁定状态 - if (mode) + DAT = "SC830" + MachinesRow["SYSKEY"] + });//信息插入队列 + } + } + else + {//串口发送 + if (MachinesRow["State"].ToString() == "802") + { + if (MachinesRow["Serial"].ToString() == "PORT1") { - Dictionary dat_829 = new Dictionary(); - dat_829.Clear(); - dat_829.Add("NAME", "LOCK"); - dat_829.Add("VALUE", "True"); - stringQueueSerial_2.Enqueue(new QueueSerial + stringQueueSerial_1.Enqueue(new QueueSerial { ID = Convert.ToInt16(MachinesRow["ID"]), - DAT = "SC829[" + MachinesRow["Station"] + "]" + dat_829.ToJsonString() + DAT = "SC830[" + MachinesRow["Station"] + "]" }); + + bool mode = Convert.ToBoolean(MachinesRow["LOCK"]);//发送锁定状态 + if (mode) + { + Dictionary dat_829 = new Dictionary(); + dat_829.Clear(); + dat_829.Add("NAME", "LOCK"); + dat_829.Add("VALUE", "True"); + stringQueueSerial_1.Enqueue(new QueueSerial + { + ID = Convert.ToInt16(MachinesRow["ID"]), + DAT = "SC829[" + MachinesRow["Station"] + "]" + dat_829.ToJsonString() + }); + } } - } - else if (MachinesRow["Serial"].ToString() == "PORT3") - { - stringQueueSerial_3.Enqueue(new QueueSerial + else if (MachinesRow["Serial"].ToString() == "PORT2") { - ID = Convert.ToInt16(MachinesRow["ID"]), - DAT = "SC830[" + MachinesRow["Station"] + "]" - }); + stringQueueSerial_2.Enqueue(new QueueSerial + { + ID = Convert.ToInt16(MachinesRow["ID"]), + DAT = "SC830[" + MachinesRow["Station"] + "]" + }); - bool mode = Convert.ToBoolean(MachinesRow["LOCK"]);//发送锁定状态 - if (mode) + bool mode = Convert.ToBoolean(MachinesRow["LOCK"]);//发送锁定状态 + if (mode) + { + Dictionary dat_829 = new Dictionary(); + dat_829.Clear(); + dat_829.Add("NAME", "LOCK"); + dat_829.Add("VALUE", "True"); + stringQueueSerial_2.Enqueue(new QueueSerial + { + ID = Convert.ToInt16(MachinesRow["ID"]), + DAT = "SC829[" + MachinesRow["Station"] + "]" + dat_829.ToJsonString() + }); + } + } + else if (MachinesRow["Serial"].ToString() == "PORT3") { - Dictionary dat_829 = new Dictionary(); - dat_829.Clear(); - dat_829.Add("NAME", "LOCK"); - dat_829.Add("VALUE", "True"); stringQueueSerial_3.Enqueue(new QueueSerial { ID = Convert.ToInt16(MachinesRow["ID"]), - DAT = "SC829[" + MachinesRow["Station"] + "]" + dat_829.ToJsonString() + DAT = "SC830[" + MachinesRow["Station"] + "]" }); - } - } - else if (MachinesRow["Serial"].ToString() == "PORT4") - { - stringQueueSerial_4.Enqueue(new QueueSerial - { - ID = Convert.ToInt16(MachinesRow["ID"]), - DAT = "SC830[" + MachinesRow["Station"] + "]" - }); - bool mode = Convert.ToBoolean(MachinesRow["LOCK"]);//发送锁定状态 - if (mode) + bool mode = Convert.ToBoolean(MachinesRow["LOCK"]);//发送锁定状态 + if (mode) + { + Dictionary dat_829 = new Dictionary(); + dat_829.Clear(); + dat_829.Add("NAME", "LOCK"); + dat_829.Add("VALUE", "True"); + stringQueueSerial_3.Enqueue(new QueueSerial + { + ID = Convert.ToInt16(MachinesRow["ID"]), + DAT = "SC829[" + MachinesRow["Station"] + "]" + dat_829.ToJsonString() + }); + } + } + else if (MachinesRow["Serial"].ToString() == "PORT4") { - Dictionary dat_829 = new Dictionary(); - dat_829.Clear(); - dat_829.Add("NAME", "LOCK"); - dat_829.Add("VALUE", "True"); stringQueueSerial_4.Enqueue(new QueueSerial { ID = Convert.ToInt16(MachinesRow["ID"]), - DAT = "SC829[" + MachinesRow["Station"] + "]" + dat_829.ToJsonString() + DAT = "SC830[" + MachinesRow["Station"] + "]" }); - } - } - } - int m_run =Convert.ToInt16( MachinesRow["WORK_RUN"]); - if (m_run == 0) - { - Updata_Machines(Machines, "State", "ID='" + MachinesRow["ID"] + "'", "101");//停止状态 - } - else if (m_run == 1) - { - Updata_Machines(Machines, "State", "ID='" + MachinesRow["ID"] + "'", "101");//暂停状态 - } - else if (m_run == 2) - { - Updata_Machines(Machines, "State", "ID='" + MachinesRow["ID"] + "'", "202");//运行 - } - if (Convert.ToBoolean(MachinesRow["ERR"])) - { - Updata_Machines(Machines, "State", "ID='" + MachinesRow["ID"] + "'", "309");//错误 - } - - string mac_s = MachinesRow["State"].ToString(); - if ((mac_s == "101") || (mac_s == "201") || (mac_s == "202") || (mac_s == "301") || (mac_s == "309"))//获取信息 - { - if (MachinesRow["Serial"].ToString() == "PORT1") - { - stringQueueSerial_1.Enqueue(new QueueSerial - { - ID = Convert.ToInt16(MachinesRow["ID"]), - DAT = "SC830[" + MachinesRow["Station"] + "]" - }); + bool mode = Convert.ToBoolean(MachinesRow["LOCK"]);//发送锁定状态 + if (mode) + { + Dictionary dat_829 = new Dictionary(); + dat_829.Clear(); + dat_829.Add("NAME", "LOCK"); + dat_829.Add("VALUE", "True"); + stringQueueSerial_4.Enqueue(new QueueSerial + { + ID = Convert.ToInt16(MachinesRow["ID"]), + DAT = "SC829[" + MachinesRow["Station"] + "]" + dat_829.ToJsonString() + }); + } + } } - else if (MachinesRow["Serial"].ToString() == "PORT2") + int m_run = Convert.ToInt16(MachinesRow["WORK_RUN"]); + if (m_run == 0) { - stringQueueSerial_2.Enqueue(new QueueSerial - { - ID = Convert.ToInt16(MachinesRow["ID"]), - DAT = "SC830[" + MachinesRow["Station"] + "]" - }); + Updata_Machines(Machines, "State", "ID='" + MachinesRow["ID"] + "'", "101");//停止状态 } - else if (MachinesRow["Serial"].ToString() == "PORT3") + else if (m_run == 1) { - stringQueueSerial_3.Enqueue(new QueueSerial - { - ID = Convert.ToInt16(MachinesRow["ID"]), - DAT = "SC830[" + MachinesRow["Station"] + "]" - }); + Updata_Machines(Machines, "State", "ID='" + MachinesRow["ID"] + "'", "101");//暂停状态 } - else if (MachinesRow["Serial"].ToString() == "PORT4") + else if (m_run == 2) { - stringQueueSerial_4.Enqueue(new QueueSerial - { - ID = Convert.ToInt16(MachinesRow["ID"]), - DAT = "SC830[" + MachinesRow["Station"] + "]" - }); + Updata_Machines(Machines, "State", "ID='" + MachinesRow["ID"] + "'", "202");//运行 } - } - } - } - - if (Time5 > 5) - { - Tick_Event_5S(); - Time5 = 0; - } - else { Time5++; } - if (Time30 > 30) - { - Tick_Event_30S(); - Time30 = 0; - } - else { Time30++; } - } - async void Tick_Event_5S()//Tick_Event周期执行事件5S - { - foreach (DataRow MachinesRow in Machines.Rows) - { - /**发送800指令**/ - if (MachinesRow["State"].ToString() == "801") - { - stringQueue.Enqueue(new QueueString - { - ID = Convert.ToInt16(MachinesRow["ID"]), - DAT = "SC800:SCCM[" + MachinesRow["IP"] + ";" + MachinesRow["PORT"] + "]" - });//信息插入队列 - } - - /**染机用户信息**/ - try - { - if (MachinesRow["UserInfoStart"].ToString() == "901")//打开用户提示信息 - { - MainWindow.InfData.Rows.Add(new object[] { - MachinesRow["Name"],Properties.Resources.Pequest + MachinesRow["UserInfo"], - MachinesRow["SYSKEY"],MachinesRow["ID"]}); - Updata_Machines(Machines, "UserInfoStart", "ID='" + MachinesRow["ID"] + "'", "900"); - } - if (MachinesRow["UserInfoStart"].ToString() == "902")//删除用户提示信息 - { - MainWindow.InfData.Select("ID='" + MachinesRow["ID"] + "'").First().Delete(); - } - } - catch (Exception EX) { LogGing.ERRDATA(EX); } - /**染机呼叫状态**/ - try - { - if (Convert.ToBoolean(MachinesRow["CALL"])) - { - if (Convert.ToBoolean(MachinesRow["Type"])) - {//网络 - stringQueue.Enqueue(new QueueString - { - ID = Convert.ToInt16(MachinesRow["ID"]), - DAT = "SC827" + MachinesRow["SYSKEY"] - }); + if (Convert.ToBoolean(MachinesRow["ERR"])) + { + Updata_Machines(Machines, "State", "ID='" + MachinesRow["ID"] + "'", "309");//错误 } - else - {//串口 + + string mac_s = MachinesRow["State"].ToString(); + if ((mac_s == "101") || (mac_s == "201") || (mac_s == "202") || (mac_s == "301") || (mac_s == "309"))//获取信息 + { if (MachinesRow["Serial"].ToString() == "PORT1") { stringQueueSerial_1.Enqueue(new QueueSerial { ID = Convert.ToInt16(MachinesRow["ID"]), - DAT = "SC827[" + MachinesRow["Station"] + "]" + DAT = "SC830[" + MachinesRow["Station"] + "]" }); } else if (MachinesRow["Serial"].ToString() == "PORT2") @@ -745,7 +661,7 @@ namespace SunlightCentralizedControlManagement_SCCM_.ViewModel stringQueueSerial_2.Enqueue(new QueueSerial { ID = Convert.ToInt16(MachinesRow["ID"]), - DAT = "SC827[" + MachinesRow["Station"] + "]" + DAT = "SC830[" + MachinesRow["Station"] + "]" }); } else if (MachinesRow["Serial"].ToString() == "PORT3") @@ -753,7 +669,7 @@ namespace SunlightCentralizedControlManagement_SCCM_.ViewModel stringQueueSerial_3.Enqueue(new QueueSerial { ID = Convert.ToInt16(MachinesRow["ID"]), - DAT = "SC827[" + MachinesRow["Station"] + "]" + DAT = "SC830[" + MachinesRow["Station"] + "]" }); } else if (MachinesRow["Serial"].ToString() == "PORT4") @@ -761,295 +677,397 @@ namespace SunlightCentralizedControlManagement_SCCM_.ViewModel stringQueueSerial_4.Enqueue(new QueueSerial { ID = Convert.ToInt16(MachinesRow["ID"]), - DAT = "SC827[" + MachinesRow["Station"] + "]" + DAT = "SC830[" + MachinesRow["Station"] + "]" }); } } } } - catch (Exception EX) { LogGing.ERRDATA(EX); } - try - {//处理呼叫请求列表完成发送后(202》203) - if (Dyelot_CALL.Select("State='202'").Count() > 0) + } + if (Time5 > 5) + { + Tick_Event_5S(); + Time5 = 0; + } + else { Time5++; } + if (Time30 > 30) + { + Tick_Event_30S(); + Time30 = 0; + } + else { Time30++; } + } + async void Tick_Event_5S()//Tick_Event周期执行事件5S + { + try + {//处理呼叫请求列表完成发送后(202》203) + if (Dyelot_CALL.Select("State='202'").Count() > 0) + { + DataRow row = Dyelot_CALL.Select("State='202'").First(); + var r = await bDCSqlHelper.UPDATA("Machines", "Name = '" + row.Field("Machine") + "'", row); + if (r > 0) { - DataRow row = Dyelot_CALL.Select("State='202'").First(); - var r = await bDCSqlHelper.UPDATA("Machines", "Name = '" + row.Field("Machine") + "'", row); - if (r > 0) + DataRow[] dataRows = Dyelot_CALL.Select("Dyelot='" + row.Field("Dyelot") + + "' and Redye='" + row.Field("Redye") + + "' and Step='" + row.Field("Step") + "'"); + foreach (DataRow dataRow in dataRows) { - DataRow[] dataRows = Dyelot_CALL.Select("Dyelot='" + row.Field("Dyelot") + - "' and Redye='" + row.Field("Redye") + - "' and Step='" + row.Field("Step") + "'"); - foreach (DataRow dataRow in dataRows) - { - dataRow.BeginEdit(); - dataRow["State"] = 203; - dataRow.EndEdit(); - } - Dictionary dat_ = new Dictionary();//缓存函数 - dat_.Add("State", 203); - SQLiteHelpers.Update("DyelotHistory", dat_, - "Dyelot='" + row.Field("Dyelot") + - "' and Redye='" + row.Field("Redye") + - "' and Step='" + row.Field("Step") + "'", null);// 执行插入 + dataRow.BeginEdit(); + dataRow["State"] = 203; + dataRow.EndEdit(); } + Dictionary dat_ = new Dictionary();//缓存函数 + dat_.Add("State", 203); + SQLiteHelpers.Update("DyelotHistory", dat_, + "Dyelot='" + row.Field("Dyelot") + + "' and Redye='" + row.Field("Redye") + + "' and Step='" + row.Field("Step") + "'", null);// 执行插入 } } - catch (Exception EX) { LogGing.ERRDATA(EX); } - try - {//检查呼叫回复列表确认是否完成(203=>301) - if (Dyelot_CALL.Select("State='203'").Count() > 0) + } + catch (Exception EX) { LogGing.ERRDATA(EX); } + try + {//检查呼叫回复列表确认是否完成(203=>301) + if (Dyelot_CALL.Select("State='203'").Count() > 0) + { + DataTable dt = new DataTable(); + // DataRow[] dataRows = Dyelot_CALL.Select("State='203'"); + foreach (DataRow dataRow in Dyelot_CALL.Select("State='203'")) { - DataTable dt = new DataTable(); - // DataRow[] dataRows = Dyelot_CALL.Select("State='203'"); - foreach (DataRow dataRow in Dyelot_CALL.Select("State='203'")) + if ((dataRow["State"].ToString() != "301") && (dataRow["State"].ToString() != "309")) { - if ((dataRow["State"].ToString() != "301") && (dataRow["State"].ToString() != "309")) + if (dataRow.Field("Type") == 2) { - if (dataRow.Field("Type") == 2) - { - dt = await bDCSqlHelper.SELECT("Machines", "Name = '" + dataRow.Field("Machine") + - "' AND (DyeState = 301 OR DyeState = 309)"); + dt = await bDCSqlHelper.SELECT("Machines", "Name = '" + dataRow.Field("Machine") + + "' AND (DyeState = 301 OR DyeState = 309)"); - if (dt.Rows.Count > 0) + if (dt.Rows.Count > 0) + { + if (dt.Select("DyeState = 301").Count() > 0) { - if (dt.Select("DyeState = 301").Count() > 0) - { - // Dyelot_CALL.Rows.Remove(dataRow); + // Dyelot_CALL.Rows.Remove(dataRow); - DataTable dr = await bDCSqlHelper.SELECT("DyelotsBulkedRecipe", - "Dyelot = '" + dataRow.Field("Dyelot") + - "' AND ReDye = " + dataRow.Field("ReDye") + - " AND StepNumber = " + dataRow.Field("Step")); + DataTable dr = await bDCSqlHelper.SELECT("DyelotsBulkedRecipe", + "Dyelot = '" + dataRow.Field("Dyelot") + + "' AND ReDye = " + dataRow.Field("ReDye") + + " AND StepNumber = " + dataRow.Field("Step")); - foreach (DataRow Row in Dyelot_CALL.Select("Dyelot='" + dataRow["Dyelot"] + "' and Redye ='" + - dataRow["Redye"] + "' AND Step = '" + dataRow["Step"] + "'")) + foreach (DataRow Row in Dyelot_CALL.Select("Dyelot='" + dataRow["Dyelot"] + "' and Redye ='" + + dataRow["Redye"] + "' AND Step = '" + dataRow["Step"] + "'")) + { + if (dr.Rows.Count > 0) { - if (dr.Rows.Count > 0) - { - DataRow data = dr.Select("ProductCode='" + Row.Field("ProductCode") + "'").First(); - Row.BeginEdit(); - Row["State"] = 301; - Row["Amount"] = data.Field("Amount"); - Row["DispenseStartTime"] = data.Field("DispenseStartTime").ToString("yyyy/MM/dd HH:mm:ss"); - Row["DispenseEndTime"] = data.Field("DispenseEndTime").ToString("yyyy/MM/dd HH:mm:ss"); - Row.EndEdit(); - } - else - { - Row.BeginEdit(); - Row["State"] = 301; - Row["Amount"] = 0; - Row["DispenseEndTime"] = DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss"); - Row.EndEdit(); - } + DataRow data = dr.Select("ProductCode='" + Row.Field("ProductCode") + "'").First(); + Row.BeginEdit(); + Row["State"] = 301; + Row["Amount"] = data.Field("Amount"); + Row["DispenseStartTime"] = data.Field("DispenseStartTime").ToString("yyyy/MM/dd HH:mm:ss"); + Row["DispenseEndTime"] = data.Field("DispenseEndTime").ToString("yyyy/MM/dd HH:mm:ss"); + Row.EndEdit(); } - } - else if (dt.Select("DyeState = 309").Count() > 0) - { - foreach (DataRow Row in Dyelot_CALL.Select("Dyelot='" + dataRow["Dyelot"] + "' and Redye ='" + - dataRow["Redye"] + "' AND Step = '" + dataRow["Step"] + "'")) + else { Row.BeginEdit(); - Row["State"] = 309; + Row["State"] = 301; Row["Amount"] = 0; Row["DispenseEndTime"] = DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss"); Row.EndEdit(); } } } + else if (dt.Select("DyeState = 309").Count() > 0) + { + foreach (DataRow Row in Dyelot_CALL.Select("Dyelot='" + dataRow["Dyelot"] + "' and Redye ='" + + dataRow["Redye"] + "' AND Step = '" + dataRow["Step"] + "'")) + { + Row.BeginEdit(); + Row["State"] = 309; + Row["Amount"] = 0; + Row["DispenseEndTime"] = DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss"); + Row.EndEdit(); + } + } } - else if (dataRow.Field("Type") == 3) + } + else if (dataRow.Field("Type") == 3) + { + dt = await bDCSqlHelper.SELECT("Machines", "Name = '" + dataRow.Field("Machine") + + "' AND (PowderState = 301 OR PowderState = 309)"); + if (dt.Rows.Count > 0) { - dt = await bDCSqlHelper.SELECT("Machines", "Name = '" + dataRow.Field("Machine") + - "' AND (PowderState = 301 OR PowderState = 309)"); - if (dt.Rows.Count > 0) + if (dt.Select("PowderState = 301").Count() > 0) { - if (dt.Select("PowderState = 301").Count() > 0) - { - DataTable dr = await bDCSqlHelper.SELECT("DyelotsBulkedRecipe", - "Dyelot = '" + dataRow.Field("Dyelot") + - "' AND ReDye = " + dataRow.Field("ReDye") + - " AND StepNumber = " + dataRow.Field("Step")); + DataTable dr = await bDCSqlHelper.SELECT("DyelotsBulkedRecipe", + "Dyelot = '" + dataRow.Field("Dyelot") + + "' AND ReDye = " + dataRow.Field("ReDye") + + " AND StepNumber = " + dataRow.Field("Step")); - foreach (DataRow Row in Dyelot_CALL.Select("Dyelot='" + dataRow["Dyelot"] + "' and Redye ='" + - dataRow["Redye"] + "' AND Step = '" + dataRow["Step"] + "'")) + foreach (DataRow Row in Dyelot_CALL.Select("Dyelot='" + dataRow["Dyelot"] + "' and Redye ='" + + dataRow["Redye"] + "' AND Step = '" + dataRow["Step"] + "'")) + { + if (dr.Rows.Count > 0) { - if (dr.Rows.Count > 0) - { - DataRow data = dr.Select("ProductCode='" + Row.Field("ProductCode") + "'").First(); - Row.BeginEdit(); - Row["State"] = 301; - Row["Amount"] = data.Field("Amount"); - Row["DispenseStartTime"] = data.Field("DispenseStartTime").ToString("yyyy/MM/dd HH:mm:ss"); - Row["DispenseEndTime"] = data.Field("DispenseEndTime").ToString("yyyy/MM/dd HH:mm:ss"); - Row.EndEdit(); - } - else - { - Row.BeginEdit(); - Row["State"] = 301; - Row["Amount"] = 0; - Row["DispenseEndTime"] = DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss"); - Row.EndEdit(); - } + DataRow data = dr.Select("ProductCode='" + Row.Field("ProductCode") + "'").First(); + Row.BeginEdit(); + Row["State"] = 301; + Row["Amount"] = data.Field("Amount"); + Row["DispenseStartTime"] = data.Field("DispenseStartTime").ToString("yyyy/MM/dd HH:mm:ss"); + Row["DispenseEndTime"] = data.Field("DispenseEndTime").ToString("yyyy/MM/dd HH:mm:ss"); + Row.EndEdit(); } - } - else if (dt.Select("PowderState = 309").Count() > 0) - { - foreach (DataRow Row in Dyelot_CALL.Select("Dyelot='" + dataRow["Dyelot"] + "' and Redye ='" + - dataRow["Redye"] + "' AND Step = '" + dataRow["Step"] + "'")) + else { Row.BeginEdit(); - Row["State"] = 309; + Row["State"] = 301; Row["Amount"] = 0; Row["DispenseEndTime"] = DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss"); Row.EndEdit(); } } } + else if (dt.Select("PowderState = 309").Count() > 0) + { + foreach (DataRow Row in Dyelot_CALL.Select("Dyelot='" + dataRow["Dyelot"] + "' and Redye ='" + + dataRow["Redye"] + "' AND Step = '" + dataRow["Step"] + "'")) + { + Row.BeginEdit(); + Row["State"] = 309; + Row["Amount"] = 0; + Row["DispenseEndTime"] = DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss"); + Row.EndEdit(); + } + } } - else + } + else + { + dt = await bDCSqlHelper.SELECT("Machines", "Name = '" + dataRow.Field("Machine") + + "' AND (ChemicalState = 301 OR ChemicalState = 309)"); + if (dt.Rows.Count > 0) { - dt = await bDCSqlHelper.SELECT("Machines", "Name = '" + dataRow.Field("Machine") + - "' AND (ChemicalState = 301 OR ChemicalState = 309)"); - if (dt.Rows.Count > 0) + if (dt.Select("ChemicalState = 301").Count() > 0) { - if (dt.Select("ChemicalState = 301").Count() > 0) - { - DataTable dr = await bDCSqlHelper.SELECT("DyelotsBulkedRecipe", - "Dyelot = '" + dataRow.Field("Dyelot") + - "' AND ReDye = " + dataRow.Field("ReDye") + - " AND StepNumber = " + dataRow.Field("Step")); + DataTable dr = await bDCSqlHelper.SELECT("DyelotsBulkedRecipe", + "Dyelot = '" + dataRow.Field("Dyelot") + + "' AND ReDye = " + dataRow.Field("ReDye") + + " AND StepNumber = " + dataRow.Field("Step")); - foreach (DataRow Row in Dyelot_CALL.Select("Dyelot='" + dataRow["Dyelot"] + "' and Redye ='" + - dataRow["Redye"] + "' AND Step = '" + dataRow["Step"] + "'")) + foreach (DataRow Row in Dyelot_CALL.Select("Dyelot='" + dataRow["Dyelot"] + "' and Redye ='" + + dataRow["Redye"] + "' AND Step = '" + dataRow["Step"] + "'")) + { + if (dr.Rows.Count > 0) { - if (dr.Rows.Count > 0) - { - DataRow data = dr.Select("ProductCode='" + Row.Field("ProductCode") + "'").First(); - Row.BeginEdit(); - Row["State"] = 301; - Row["Amount"] = data.Field("Amount"); - Row["DispenseStartTime"] = data.Field("DispenseStartTime").ToString("yyyy/MM/dd HH:mm:ss"); - Row["DispenseEndTime"] = data.Field("DispenseEndTime").ToString("yyyy/MM/dd HH:mm:ss"); - Row.EndEdit(); - } - else - { - Row.BeginEdit(); - Row["State"] = 301; - Row["Amount"] = 0; - Row["DispenseEndTime"] = DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss"); - Row.EndEdit(); - } + DataRow data = dr.Select("ProductCode='" + Row.Field("ProductCode") + "'").First(); + Row.BeginEdit(); + Row["State"] = 301; + Row["Amount"] = data.Field("Amount"); + Row["DispenseStartTime"] = data.Field("DispenseStartTime").ToString("yyyy/MM/dd HH:mm:ss"); + Row["DispenseEndTime"] = data.Field("DispenseEndTime").ToString("yyyy/MM/dd HH:mm:ss"); + Row.EndEdit(); } - } - else if (dt.Select("ChemicalState = 309").Count() > 0) - { - foreach (DataRow Row in Dyelot_CALL.Select("Dyelot='" + dataRow["Dyelot"] + "' and Redye ='" + - dataRow["Redye"] + "' AND Step = '" + dataRow["Step"] + "'")) + else { Row.BeginEdit(); - Row["State"] = 309; + Row["State"] = 301; Row["Amount"] = 0; Row["DispenseEndTime"] = DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss"); Row.EndEdit(); } } } + else if (dt.Select("ChemicalState = 309").Count() > 0) + { + foreach (DataRow Row in Dyelot_CALL.Select("Dyelot='" + dataRow["Dyelot"] + "' and Redye ='" + + dataRow["Redye"] + "' AND Step = '" + dataRow["Step"] + "'")) + { + Row.BeginEdit(); + Row["State"] = 309; + Row["Amount"] = 0; + Row["DispenseEndTime"] = DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss"); + Row.EndEdit(); + } + } } - } + } } } - catch (Exception EX) { LogGing.ERRDATA(EX); } - try - {//301列表发送完成至染机(203=>301) - foreach (DataRow row in Dyelot_CALL.Select("State='301' OR State='309'")) + } + catch (Exception EX) { LogGing.ERRDATA(EX); } + + lock (MainWindowViewModel.Machines.Rows.SyncRoot) + { + foreach (DataRow MachinesRow in Machines.Rows) + { + /**发送800指令**/ + if (MachinesRow["State"].ToString() == "801") { - Dictionary Product_ = new Dictionary();//缓存函数 - Product_.Add("State", row.Field("State")); - Product_.Add("Step", row.Field("Step")); - Product_.Add("Dyelot", row.Field("Dyelot")); - Product_.Add("ProductCode", row.Field("ProductCode")); - Product_.Add("Amount", row.Field("Amount")); - Product_.Add("DispenseEndTime", row.Field("DispenseEndTime")); + stringQueue.Enqueue(new QueueString + { + ID = Convert.ToInt16(MachinesRow["ID"]), + DAT = "SC800:SCCM[" + MachinesRow["IP"] + ";" + MachinesRow["PORT"] + "]" + });//信息插入队列 + } - if (Convert.ToBoolean(MachinesRow["Type"])) - {//网络 - stringQueue.Enqueue(new QueueString - { - ID = Convert.ToInt16(Selet_Machines(Machines, - "ID", "Name='" + row.Field("Machine") + "'")), - DAT = "SC828" + Selet_Machines(Machines, - "SYSKEY", "Name='" + row.Field("Machine") + "'") + Product_.ToJsonString() - }); + /**染机用户信息**/ + try + { + if (MachinesRow["UserInfoStart"].ToString() == "901")//打开用户提示信息 + { + MainWindow.InfData.Rows.Add(new object[] { + MachinesRow["Name"],Properties.Resources.Pequest + MachinesRow["UserInfo"], + MachinesRow["SYSKEY"],MachinesRow["ID"]}); + + Updata_Machines(Machines, "UserInfoStart", "ID='" + MachinesRow["ID"] + "'", "900"); } - else - {//串口 - if (MachinesRow["Serial"].ToString() == "PORT1") - { - stringQueueSerial_1.Enqueue(new QueueSerial + if (MachinesRow["UserInfoStart"].ToString() == "902")//删除用户提示信息 + { + MainWindow.InfData.Select("ID='" + MachinesRow["ID"] + "'").First().Delete(); + } + } + catch (Exception EX) { LogGing.ERRDATA(EX); } + /**染机呼叫状态**/ + try + { + if (Convert.ToBoolean(MachinesRow["CALL"])) + { + if (Convert.ToBoolean(MachinesRow["Type"])) + {//网络 + stringQueue.Enqueue(new QueueString { ID = Convert.ToInt16(MachinesRow["ID"]), - DAT = "SC828[" + MachinesRow["Station"] + "]" + Product_.ToJsonString() + DAT = "SC827" + MachinesRow["SYSKEY"] }); } - else if (MachinesRow["Serial"].ToString() == "PORT2") - { - stringQueueSerial_2.Enqueue(new QueueSerial + else + {//串口 + if (MachinesRow["Serial"].ToString() == "PORT1") { - ID = Convert.ToInt16(MachinesRow["ID"]), - DAT = "SC828[" + MachinesRow["Station"] + "]" + Product_.ToJsonString() - }); + stringQueueSerial_1.Enqueue(new QueueSerial + { + ID = Convert.ToInt16(MachinesRow["ID"]), + DAT = "SC827[" + MachinesRow["Station"] + "]" + }); + } + else if (MachinesRow["Serial"].ToString() == "PORT2") + { + 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 + { + ID = Convert.ToInt16(MachinesRow["ID"]), + DAT = "SC827[" + MachinesRow["Station"] + "]" + }); + } + else if (MachinesRow["Serial"].ToString() == "PORT4") + { + stringQueueSerial_4.Enqueue(new QueueSerial + { + ID = Convert.ToInt16(MachinesRow["ID"]), + DAT = "SC827[" + MachinesRow["Station"] + "]" + }); + } } - else if (MachinesRow["Serial"].ToString() == "PORT3") - { - stringQueueSerial_3.Enqueue(new QueueSerial + } + } + catch (Exception EX) { LogGing.ERRDATA(EX); } + try + {//301列表发送完成至染机(203=>301) + foreach (DataRow row in Dyelot_CALL.Select("State='301' OR State='309'")) + { + Dictionary Product_ = new Dictionary();//缓存函数 + Product_.Add("State", row.Field("State")); + Product_.Add("Step", row.Field("Step")); + Product_.Add("Dyelot", row.Field("Dyelot")); + Product_.Add("ProductCode", row.Field("ProductCode")); + Product_.Add("Amount", row.Field("Amount")); + Product_.Add("DispenseEndTime", row.Field("DispenseEndTime")); + + if (Convert.ToBoolean(MachinesRow["Type"])) + {//网络 + stringQueue.Enqueue(new QueueString { - ID = Convert.ToInt16(MachinesRow["ID"]), - DAT = "SC828[" + MachinesRow["Station"] + "]" + Product_.ToJsonString() + ID = Convert.ToInt16(Selet_Machines(Machines, + "ID", "Name='" + row.Field("Machine") + "'")), + DAT = "SC828" + Selet_Machines(Machines, + "SYSKEY", "Name='" + row.Field("Machine") + "'") + Product_.ToJsonString() }); } - else if (MachinesRow["Serial"].ToString() == "PORT4") - { - stringQueueSerial_4.Enqueue(new QueueSerial + else + {//串口 + if (MachinesRow["Serial"].ToString() == "PORT1") { - ID = Convert.ToInt16(MachinesRow["ID"]), - DAT = "SC828[" + MachinesRow["Station"] + "]" + Product_.ToJsonString() - }); + stringQueueSerial_1.Enqueue(new QueueSerial + { + ID = Convert.ToInt16(MachinesRow["ID"]), + DAT = "SC828[" + MachinesRow["Station"] + "]" + Product_.ToJsonString() + }); + } + else if (MachinesRow["Serial"].ToString() == "PORT2") + { + stringQueueSerial_2.Enqueue(new QueueSerial + { + ID = Convert.ToInt16(MachinesRow["ID"]), + DAT = "SC828[" + MachinesRow["Station"] + "]" + Product_.ToJsonString() + }); + } + else if (MachinesRow["Serial"].ToString() == "PORT3") + { + stringQueueSerial_3.Enqueue(new QueueSerial + { + ID = Convert.ToInt16(MachinesRow["ID"]), + DAT = "SC828[" + MachinesRow["Station"] + "]" + Product_.ToJsonString() + }); + } + else if (MachinesRow["Serial"].ToString() == "PORT4") + { + stringQueueSerial_4.Enqueue(new QueueSerial + { + ID = Convert.ToInt16(MachinesRow["ID"]), + DAT = "SC828[" + MachinesRow["Station"] + "]" + Product_.ToJsonString() + }); + } } - } - if (row["State"].ToString() == "309") - { - MainWindow.InfData.Rows.Add(new object[] { row["Machine"], + if (row["State"].ToString() == "309") + { + MainWindow.InfData.Rows.Add(new object[] { row["Machine"], Resources.Step + row["Step"]+ Resources.DispenseException, Selet_Machines(Machines, "SYSKEY", "Name='" + row["Machine"] + "'"), Selet_Machines(Machines, "ID", "Name='" + row["Machine"] + "'")}); + } + Dyelot_CALL.Rows.Remove(row); } - Dyelot_CALL.Rows.Remove(row); } + catch (Exception EX) { LogGing.ERRDATA(EX); } } - catch (Exception EX) { LogGing.ERRDATA(EX); } } } void Tick_Event_30S() { try { - /*曲线图*/ - for (int i = 0; i < Machines.Rows.Count; i++)//曲线图 + lock (MainWindowViewModel.Machines.Rows.SyncRoot) { - string mac_s = Selet_Machines(Machines, "State", "ID='" + i + "'").ToString(); - if ((mac_s == "101") || (mac_s == "201") || (mac_s == "202") || (mac_s == "301") || (mac_s == "309")) + /*曲线图*/ + for (int i = 0; i < Machines.Rows.Count; i++)//曲线图 { - DataRow whole_Dat = Whole_dat.NewRow(); - whole_Dat["Machine"] = Selet_Machines(Machines, "NAME", "ID='" + i + "'").ToString(); - whole_Dat["DateTime"] = DateTime.Now; - whole_Dat["DAT"] = Convert.ToDouble(Selet_Machines(Machines, "Temperature", "ID='" + i + "'")); - Whole_dat.Rows.Add(whole_Dat); + string mac_s = Selet_Machines(Machines, "State", "ID='" + i + "'").ToString(); + if ((mac_s == "101") || (mac_s == "201") || (mac_s == "202") || (mac_s == "301") || (mac_s == "309")) + { + DataRow whole_Dat = Whole_dat.NewRow(); + whole_Dat["Machine"] = Selet_Machines(Machines, "NAME", "ID='" + i + "'").ToString(); + whole_Dat["DateTime"] = DateTime.Now; + whole_Dat["DAT"] = Convert.ToDouble(Selet_Machines(Machines, "Temperature", "ID='" + i + "'")); + Whole_dat.Rows.Add(whole_Dat); + } } } } @@ -1061,31 +1079,37 @@ namespace SunlightCentralizedControlManagement_SCCM_.ViewModel //public static DataRow[] machinesdata = new DataRow[999]; public void ClientNEW() { - foreach (DataRow dataRow in Machines.Rows) + lock (MainWindowViewModel.Machines.Rows.SyncRoot) { - dataRow.BeginEdit(); - dataRow["State"] = 800; - dataRow["Temperature"] = 0; - dataRow["WaterLevel"] = 0; - dataRow["WORK_RUN"] = -1; - dataRow["ERR"] = false; - dataRow["LOCK"] = false; - dataRow["AUTO"] = false; - dataRow["CALL"] = false; - dataRow["UserInfoStart"] = 900; - dataRow.EndEdit(); - dataRow.AcceptChanges(); + foreach (DataRow dataRow in Machines.Rows) + { + dataRow.BeginEdit(); + dataRow["State"] = 800; + dataRow["Temperature"] = 0; + dataRow["WaterLevel"] = 0; + dataRow["WORK_RUN"] = -1; + dataRow["ERR"] = false; + dataRow["LOCK"] = false; + dataRow["AUTO"] = false; + dataRow["CALL"] = false; + dataRow["UserInfoStart"] = 900; + dataRow.EndEdit(); + dataRow.AcceptChanges(); + } } } public void TcpClientNEW() { - foreach (DataRow dataRow in Machines.Rows) + lock (MainWindowViewModel.Machines.Rows.SyncRoot) { - if (Convert.ToBoolean(dataRow["Type"])) + foreach (DataRow dataRow in Machines.Rows) { - MachiensTcpClient[Convert.ToInt16(dataRow["ID"])] = new TcpClient(); - _ = AsyncTcpClient.TcpClient(MachiensTcpClient[Convert.ToInt16(dataRow["ID"])] //建立tcp连接 - , dataRow["IP"].ToString(), dataRow["PORT"].ToString()); + if (Convert.ToBoolean(dataRow["Type"])) + { + MachiensTcpClient[Convert.ToInt16(dataRow["ID"])] = new TcpClient(); + _ = AsyncTcpClient.TcpClient(MachiensTcpClient[Convert.ToInt16(dataRow["ID"])] //建立tcp连接 + , dataRow["IP"].ToString(), dataRow["PORT"].ToString()); + } } } } @@ -1163,19 +1187,22 @@ namespace SunlightCentralizedControlManagement_SCCM_.ViewModel } else { - foreach (DataRow MachinesRow in Machines.Select("Type='false' AND Serial='PORT1'")) + lock (MainWindowViewModel.Machines.Rows.SyncRoot) { - if (MachinesRow["State"].ToString() == "800") + foreach (DataRow MachinesRow in Machines.Select("Type='false' AND Serial='PORT1'")) { - stringQueueSerial_1.Enqueue(new QueueSerial + if (MachinesRow["State"].ToString() == "800") { - ID = Convert.ToInt16(MachinesRow["ID"]), - DAT = "SC800[" + MachinesRow["Station"] + "]" - }); - } - else - { - Thread.Sleep(TimeSpan.FromMilliseconds(5)); + stringQueueSerial_1.Enqueue(new QueueSerial + { + ID = Convert.ToInt16(MachinesRow["ID"]), + DAT = "SC800[" + MachinesRow["Station"] + "]" + }); + } + else + { + Thread.Sleep(TimeSpan.FromMilliseconds(5)); + } } } } @@ -1212,19 +1239,22 @@ namespace SunlightCentralizedControlManagement_SCCM_.ViewModel } else { - foreach (DataRow MachinesRow in Machines.Select("Type='false' AND Serial='PORT2'")) + lock (MainWindowViewModel.Machines.Rows.SyncRoot) { - if (MachinesRow["State"].ToString() == "800") + foreach (DataRow MachinesRow in Machines.Select("Type='false' AND Serial='PORT2'")) { - stringQueueSerial_2.Enqueue(new QueueSerial + if (MachinesRow["State"].ToString() == "800") { - ID = Convert.ToInt16(MachinesRow["ID"]), - DAT = "SC800[" + MachinesRow["Station"] + "]" - }); - } - else - { - Thread.Sleep(TimeSpan.FromMilliseconds(5)); + stringQueueSerial_2.Enqueue(new QueueSerial + { + ID = Convert.ToInt16(MachinesRow["ID"]), + DAT = "SC800[" + MachinesRow["Station"] + "]" + }); + } + else + { + Thread.Sleep(TimeSpan.FromMilliseconds(5)); + } } } } @@ -1261,19 +1291,22 @@ namespace SunlightCentralizedControlManagement_SCCM_.ViewModel } else { - foreach (DataRow MachinesRow in Machines.Select("Type='false' AND Serial='PORT3'")) + lock (MainWindowViewModel.Machines.Rows.SyncRoot) { - if (MachinesRow["State"].ToString() == "800") + foreach (DataRow MachinesRow in Machines.Select("Type='false' AND Serial='PORT3'")) { - stringQueueSerial_3.Enqueue(new QueueSerial + if (MachinesRow["State"].ToString() == "800") { - ID = Convert.ToInt16(MachinesRow["ID"]), - DAT = "SC800[" + MachinesRow["Station"] + "]" - }); - } - else - { - Thread.Sleep(TimeSpan.FromMilliseconds(50)); + stringQueueSerial_3.Enqueue(new QueueSerial + { + ID = Convert.ToInt16(MachinesRow["ID"]), + DAT = "SC800[" + MachinesRow["Station"] + "]" + }); + } + else + { + Thread.Sleep(TimeSpan.FromMilliseconds(50)); + } } } } @@ -1310,19 +1343,22 @@ namespace SunlightCentralizedControlManagement_SCCM_.ViewModel } else { - foreach (DataRow MachinesRow in Machines.Select("Type='false' AND Serial='PORT4'")) + lock (MainWindowViewModel.Machines.Rows.SyncRoot) { - if (MachinesRow["State"].ToString() == "800") + foreach (DataRow MachinesRow in Machines.Select("Type='false' AND Serial='PORT4'")) { - stringQueueSerial_4.Enqueue(new QueueSerial + if (MachinesRow["State"].ToString() == "800") { - ID = Convert.ToInt16(MachinesRow["ID"]), - DAT = "SC800[" + MachinesRow["Station"] + "]" - }); - } - else - { - Thread.Sleep(TimeSpan.FromMilliseconds(50)); + stringQueueSerial_4.Enqueue(new QueueSerial + { + ID = Convert.ToInt16(MachinesRow["ID"]), + DAT = "SC800[" + MachinesRow["Station"] + "]" + }); + } + else + { + Thread.Sleep(TimeSpan.FromMilliseconds(50)); + } } } }