diff --git a/UserClass/AsyncTcpServer.cs b/UserClass/AsyncTcpServer.cs index 530198c..e23486c 100644 --- a/UserClass/AsyncTcpServer.cs +++ b/UserClass/AsyncTcpServer.cs @@ -25,6 +25,7 @@ using DyeingComputer.View; using System.Windows; using System.Windows.Controls; using static System.Net.WebRequestMethods; +using System.Collections; namespace DyeingComputer.UserClass {/// @@ -67,6 +68,8 @@ namespace DyeingComputer.UserClass return rt; } + + public static string[] Prohibit = new string[10] { "S01", "S02", "S03", "S05", "S06", "S07", "SL1", "SL2", "SL3", ""};//禁止操作的指令 public static SQLiteHelper SQLiteHelpers = null; //定义数据库 public static readonly string DBAddress = Environment.CurrentDirectory + "\\DataBase\\800COMPUTER.db"; //数据库路径 public static async Task Main() @@ -167,7 +170,7 @@ namespace DyeingComputer.UserClass client.SendAsync("SC820" + "[" + DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss") + "]"); MainWindowViewModel.TX++; } - catch { client.SendAsync("SC920"); } + catch (Exception ex) { client.SendAsync("SC920" + "[" + MainWindowViewModel.S01 + "]" + ex); } } else { client.SendAsync("SC999"); } }//设置系统时间 @@ -348,7 +351,7 @@ namespace DyeingComputer.UserClass client.SendAsync("SC821" + SYSKEY + SYSDAT); } } - catch { client.SendAsync("SC921"); } + catch (Exception ex) { client.SendAsync("SC921" + "[" + MainWindowViewModel.S01 + "]" + ex); } } else { client.SendAsync("SC999"); } }//启停跳步指令 @@ -378,7 +381,7 @@ namespace DyeingComputer.UserClass client.SendAsync("SC830" + "[" + MainWindowViewModel.S01 + "]" + Chart_new.ToJsonString()); MainWindowViewModel.TX++; } - catch { client.SendAsync("SC931"); } + catch (Exception ex) { client.SendAsync("SC931" + "[" + MainWindowViewModel.S01 + "]" + ex); } } else { client.SendAsync("SC999"); } }//当前信息 @@ -391,7 +394,7 @@ namespace DyeingComputer.UserClass client.SendAsync("SC831" + "[" + MainWindowViewModel.S01 + "]" + MainWindowViewModel.dt_TP.ToJsonString()); MainWindowViewModel.TX++; } - catch { client.SendAsync("SC931"); } + catch (Exception ex) { client.SendAsync("SC931" + "[" + MainWindowViewModel.S01 + "]" + ex); } } else { client.SendAsync("SC999"); } }//当前工作表 @@ -403,7 +406,7 @@ namespace DyeingComputer.UserClass { client.SendAsync("SC832" + "[" + MainWindowViewModel.S01 + "]" + MainWindowViewModel.SYSlog); MainWindowViewModel.TX++; } - catch { client.SendAsync("SC932"); } + catch (Exception ex) { client.SendAsync("SC932" + "[" + MainWindowViewModel.S01 + "]" + ex); } } else { client.SendAsync("SC999"); } }//当前细节信息 @@ -416,7 +419,7 @@ namespace DyeingComputer.UserClass client.SendAsync("SC832" + "[" + MainWindowViewModel.S01 + "]" + "sc833"); MainWindowViewModel.TX++; } - catch { client.SendAsync("SC933"); } + catch (Exception ex) { client.SendAsync("SC933" + "[" + MainWindowViewModel.S01 + "]" + ex); } } else { client.SendAsync("SC999"); } }//当前领料单 @@ -428,7 +431,7 @@ namespace DyeingComputer.UserClass { client.SendAsync("SC851" + "[" + MainWindowViewModel.S01 + "]" + JsonConvert.SerializeObject(MainWindowViewModel.dt_d));//数字开关信息 } - catch { client.SendAsync("SC951"); } + catch (Exception ex) { client.SendAsync("SC951" + "[" + MainWindowViewModel.S01 + "]" + ex); } } else { client.SendAsync("SC999"); } }//数字开关表 @@ -440,7 +443,7 @@ namespace DyeingComputer.UserClass { client.SendAsync("SC852" + "[" + MainWindowViewModel.S01 + "]" + MainWindowViewModel.dt_a.ToJsonString());//寄存器信息 } - catch { client.SendAsync("SC952"); } + catch (Exception ex) { client.SendAsync("SC952" + "[" + MainWindowViewModel.S01 + "]" + ex); } } else { client.SendAsync("SC999"); } }//寄存器表 @@ -452,7 +455,7 @@ namespace DyeingComputer.UserClass { client.SendAsync("SC853" + "[" + MainWindowViewModel.S01 + "]" + MainWindowViewModel.dt_m.ToJsonString());//缓存信息 } - catch { client.SendAsync("SC953"); } + catch (Exception ex) { client.SendAsync("SC953" + "[" + MainWindowViewModel.S01 + "]" + ex); } } else { client.SendAsync("SC999"); } }//缓存表 @@ -464,7 +467,7 @@ namespace DyeingComputer.UserClass { client.SendAsync("SC854" + "[" + MainWindowViewModel.S01 + "]" + MainWindowViewModel.dt_ParameterSet.ToJsonString());//缓存信息 } - catch { client.SendAsync("SC954"); } + catch (Exception ex) { client.SendAsync("SC954" + "[" + MainWindowViewModel.S01 + "]" + ex); } } else { client.SendAsync("SC999"); } }//程序设置表 @@ -476,7 +479,7 @@ namespace DyeingComputer.UserClass { client.SendAsync("SC855" + "[" + MainWindowViewModel.S01 + "]" + MainWindowViewModel.dt_SysSet.ToJsonString());//缓存信息 } - catch { client.SendAsync("SC955"); } + catch (Exception ex) { client.SendAsync("SC955" + "[" + MainWindowViewModel.S01 + "]" + ex); } } else { client.SendAsync("SC999"); } }//系统设置表 @@ -500,7 +503,10 @@ namespace DyeingComputer.UserClass client.SendAsync("SC854" + "[" + MainWindowViewModel.S01 + "]" + MainWindowViewModel.dt_ParameterSet.ToJsonString());//缓存信息 } - catch { client.SendAsync("SC961"); } + catch (Exception ex) + { + client.SendAsync("SC961" + "[" + MainWindowViewModel.S01 + "]" + ex); + } } else { client.SendAsync("SC999"); } }//修改软件设置 @@ -513,18 +519,28 @@ namespace DyeingComputer.UserClass Dictionary dat_862; dat_862 = SerializeConvert.JsonDeserializeFromString>(SYSDAT); - Dictionary datagrid_v = new Dictionary();//缓存函数 - datagrid_v.Add("Value", dat_862.GetValue("Value")); + if (((IList)Prohibit).Contains(dat_862.GetValue("ID")))//是否允许操作 + { + client.SendAsync("SC980" + "[" + MainWindowViewModel.S01 + "]" + "Settings that are not allowed to be modified remotely"); + } + else + { + Dictionary datagrid_v = new Dictionary();//缓存函数 + datagrid_v.Add("Value", dat_862.GetValue("Value")); - SQLiteHelpers = new SQLiteHelper(DBAddress); //数据库连接路径 - SQLiteHelpers.Open(); //打开数据库 - SQLiteHelpers.Update("System", datagrid_v, "ParameterID ='" + dat_862.GetValue("ID") + "'", null);//更新 - MainWindowViewModel.dt_SysSet = SQLiteHelpers.ExecuteDataSet("select * from System order by ParameterID asc", null).Tables[0]; - SQLiteHelpers.Close();//关闭数据库 + SQLiteHelpers = new SQLiteHelper(DBAddress); //数据库连接路径 + SQLiteHelpers.Open(); //打开数据库 + SQLiteHelpers.Update("System", datagrid_v, "ParameterID ='" + dat_862.GetValue("ID") + "'", null);//更新 + MainWindowViewModel.dt_SysSet = SQLiteHelpers.ExecuteDataSet("select * from System order by ParameterID asc", null).Tables[0]; + SQLiteHelpers.Close();//关闭数据库 - client.SendAsync("SC855" + "[" + MainWindowViewModel.S01 + "]" + MainWindowViewModel.dt_SysSet.ToJsonString());//缓存信息 + client.SendAsync("SC855" + "[" + MainWindowViewModel.S01 + "]" + MainWindowViewModel.dt_SysSet.ToJsonString());//缓存信息 + } + } + catch (Exception ex) + { + client.SendAsync("SC962" + "[" + MainWindowViewModel.S01 + "]" + ex); } - catch { client.SendAsync("SC962"); } } else { client.SendAsync("SC999"); } }//修改系统 diff --git a/View/WorkOrderView.xaml.cs b/View/WorkOrderView.xaml.cs index 246a147..c2900ea 100644 --- a/View/WorkOrderView.xaml.cs +++ b/View/WorkOrderView.xaml.cs @@ -18,6 +18,7 @@ using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Navigation; using System.Windows.Shapes; +using System.Windows.Threading; using System.Xml.Linq; using static DyeingComputer.UserClass.SqliteHelper; using static DyeingComputer.Windows.ViewProgram; @@ -39,9 +40,6 @@ namespace DyeingComputer.View private void UserControl_Loaded(object sender, RoutedEventArgs e) { - Workorder_sql(); - WpfPlot(); - SQLiteHelpers = new SQLiteHelper(DBAddress); //数据库连接路径 SQLiteHelpers.Open(); //打开数据库 string S09 = SQLiteHelpers.ExecuteScalar("select value from system where ParameterID = 'S09'", null).ToString(); //读取 @@ -51,7 +49,19 @@ namespace DyeingComputer.View if (S09 == "0") WorkOrderView_new.IsEnabled = false;//禁止用户新建 if (S10 == "0") WorkOrderView_del.IsEnabled = false; if (S11 == "0") WorkOrderView_redy.IsEnabled = false; + + DispatcherTimer timer1s = new DispatcherTimer//初始化循环,每1秒调用一次Tick + { + Interval = TimeSpan.FromSeconds(1)//秒 + }; + timer1s.Tick += Tick_Event_1S; + timer1s.Start(); } + void Tick_Event_1S(object sender, EventArgs e) + { + Workorder_sql(); + } + private SQLiteHelper SQLiteHelpers = null; //定义数据库 private readonly string DBAddress = Environment.CurrentDirectory + "\\DataBase\\800COMPUTER.db"; //数据库路径 DataSet sql; //内存数据缓存 @@ -83,24 +93,7 @@ namespace DyeingComputer.View //System.GC.Collect(); } - public void WpfPlot() - { - DateTime[] xs = Generate.ConsecutiveHours(100); - double[] ys = Generate.RandomWalk(100); - - //double q = ploigrid.ActualHeight; - - //WpfPlot_Grid.y. SetAxisLimitsY(yMin: 0, yMax: 150); - // WpfPlot_Grid.Height = 500; - - // WpfPlot_Grid.Plot.Grid.XAxisStyle.IsVisible = true; - // WpfPlot_Grid.Plot.Grid.YAxisStyle.IsVisible = false; - - - // WpfPlot_Grid.Plot.YLabel("Temperature (C)"); - - } - + private void WorkOrderView_lock_Click(object sender, RoutedEventArgs e)//锁定按钮 { if (WorkOrder_Numder == null) return;