diff --git a/UserClass/AsyncTcpServer.cs b/UserClass/AsyncTcpServer.cs index bc169e1..17cd9bd 100644 --- a/UserClass/AsyncTcpServer.cs +++ b/UserClass/AsyncTcpServer.cs @@ -22,6 +22,8 @@ using static System.Windows.Forms.VisualStyles.VisualStyleElement; using Newtonsoft.Json; using static DyeingComputer.UserClass.SqliteHelper; using DyeingComputer.View; +using System.Windows; +using System.Windows.Controls; namespace DyeingComputer.UserClass {/// @@ -165,30 +167,141 @@ namespace DyeingComputer.UserClass { Dictionary dat_821; dat_821 = SerializeConvert.JsonDeserializeFromString>(SYSDAT); - if (dat_821.GetValue("INSTRUCTION").ToString() == "START") + if (dat_821.GetValue("INSTRUCTION").ToString() == "START") { SQLDATA.TechnologicalProcess_START(dat_821.GetValue("ProgramID").ToString()); } - else if (dat_821.GetValue("INSTRUCTION").ToString() == "STOP") + else if (dat_821.GetValue("INSTRUCTION").ToString() == "STOP") { MainWindowViewModel.WORK_RUN = 0;//停止 MainWindowViewModel.DIDETime = 0; } - else if (dat_821.GetValue("INSTRUCTION").ToString() == "PAUSE") + else if (dat_821.GetValue("INSTRUCTION").ToString() == "PAUSE") { MainWindowViewModel.WORK_RUN = 1;//暂停 } - else if (dat_821.GetValue("INSTRUCTION").ToString() == "CONTINUE") + else if (dat_821.GetValue("INSTRUCTION").ToString() == "CONTINUE") { - MainWindowViewModel.WORK_RUN = 2;//暂停 - } + MainWindowViewModel.WORK_RUN = 2;//暂停 + } else if (dat_821.GetValue("INSTRUCTION").ToString() == "JUMP") { MainWindowViewModel.RUN_DATATABLE = TechnologicalProcessView.sql.Tables[0];//缓存表 MainWindowViewModel.RUN_STEPID = Convert.ToInt16(dat_821.GetValue("ID").ToString());//插入步骤号 - MainWindowViewModel.STEP_START(dat_821.GetValue("Numder").ToString(), Convert.ToDouble(dat_821.GetValue("P1")), - Convert.ToDouble(dat_821.GetValue("P2")), Convert.ToDouble(dat_821.GetValue("P3")), - Convert.ToDouble(dat_821.GetValue("P4")), Convert.ToDouble(dat_821.GetValue("P5"))); + MainWindowViewModel.STEP_START(dat_821.GetValue("Numder").ToString(), Convert.ToDouble(dat_821.GetValue("P1")), + Convert.ToDouble(dat_821.GetValue("P2")), Convert.ToDouble(dat_821.GetValue("P3")), + Convert.ToDouble(dat_821.GetValue("P4")), Convert.ToDouble(dat_821.GetValue("P5"))); + } + else if (dat_821.GetValue("INSTRUCTION").ToString() == "INSERT") + { + int d = Convert.ToInt16( dat_821.GetValue("ID")); + TechnologicalProcessView.SQLiteHelpers = new SQLiteHelper(TechnologicalProcessView.DBAddress); //数据库连接路径 + TechnologicalProcessView.SQLiteHelpers.Open(); //打开数据库 + + string ProgramID = TechnologicalProcessView.SQLiteHelpers.ExecuteScalar("select ProgramID from RUN where Step = '1'", null).ToString(); + string ProgramNAME = TechnologicalProcessView.SQLiteHelpers.ExecuteScalar("select Program from RUN where Step = '1'", null).ToString(); + TechnologicalProcessView.SQLiteHelpers.Close(); + DataRow dr = TechnologicalProcessView.sql.Tables[0].NewRow();//添加表数据 + dr["ProgramID"] = ProgramID; + dr["Program"] = ProgramNAME; + + TechnologicalProcessView.sql.Tables[0].Rows.InsertAt(dr, d - 1); + int a = TechnologicalProcessView.sql.Tables[0].Rows.Count; + for (int i = 0; i < a; i++) + { + DataRow drt = TechnologicalProcessView.sql.Tables[0].Rows[i]; + drt.BeginEdit(); + drt["Step"] = i + 1; + drt.EndEdit(); + } + + DataRow drtt = TechnologicalProcessView.sql.Tables[0].Rows[d - 1]; + drtt.BeginEdit(); + drtt["StepID"] = dat_821.GetValue("STEPID").ToString(); + drtt["StepName"] = dat_821.GetValue("STEPNAME").ToString(); + drtt["ParameterName"] = dat_821.GetValue("PNAME").ToString(); + drtt["Parameter1"] = dat_821.GetValue("P1").ToString(); + drtt["Parameter2"] = dat_821.GetValue("P2").ToString(); + drtt["Parameter3"] = dat_821.GetValue("P3").ToString(); + drtt["Parameter4"] = dat_821.GetValue("P4").ToString(); + drtt["Parameter5"] = dat_821.GetValue("P5").ToString(); + drtt.EndEdit(); + + var _TechnologicalProcessView = Application.Current.Windows.Cast().FirstOrDefault(window => window is TechnologicalProcessView) as TechnologicalProcessView;//跨页面 + _TechnologicalProcessView.Grid.ItemsSource = TechnologicalProcessView.sql.Tables[0].DefaultView; + _TechnologicalProcessView.Grid.SelectedIndex = -1; + + TechnologicalProcessView.SQLiteHelpers = new SQLiteHelper(TechnologicalProcessView.DBAddress); //数据库连接路径 + TechnologicalProcessView.SQLiteHelpers.Open(); //打开数据库 + TechnologicalProcessView.SQLiteHelpers.Delete("RUN", null, null); + DataTable data_t = new DataTable(); + data_t.Columns.Add("DYELOT", typeof(string)); //添加列 + data_t = TechnologicalProcessView.sql.Tables[0].Clone(); + int a = TechnologicalProcessView.sql.Tables[0].Rows.Count; + for (int i = 0; i < a; i++) + { + data_t.Clear();//清空 + + DataRow dt = TechnologicalProcessView.sql.Tables[0].Rows[i];//行转换 + DataRow drT = data_t.NewRow(); + drT.ItemArray = dt.ItemArray; + data_t.Rows.InsertAt(drT, 0); + dr.BeginEdit(); //添加订单号 + dr["DYELOT"] = MainWindowViewModel.WorkNumder; + dr.EndEdit(); + + TechnologicalProcessView.SQLiteHelpers.InsertData("RUN", TechnologicalProcessView.SQLiteHelpers.DataTableToDictionary(data_t));//行插入 + } + + TechnologicalProcessView.SQLiteHelpers.Close(); //关闭连接 + }//插入 + else if (dat_821.GetValue("INSTRUCTION").ToString() == "EDIT") + { + int n = Convert.ToInt16(dat_821.GetValue("ID").ToString()); + + DataRow dr = TechnologicalProcessView.sql.Tables[0].Rows[n - 1]; + dr.BeginEdit(); + dr["StepID"] = dat_821.GetValue("STEPID").ToString(); + dr["StepName"] = dat_821.GetValue("STEPNAME").ToString(); + dr["ParameterName"] = dat_821.GetValue("PNAME").ToString(); + dr["Parameter1"] = dat_821.GetValue("P1").ToString(); + dr["Parameter2"] = dat_821.GetValue("P2").ToString(); + dr["Parameter3"] = dat_821.GetValue("P3").ToString(); + dr["Parameter4"] = dat_821.GetValue("P4").ToString(); + dr["Parameter5"] = dat_821.GetValue("P5").ToString(); + dr.EndEdit(); + + var _TechnologicalProcessView = Application.Current.Windows.Cast().FirstOrDefault(window => window is TechnologicalProcessView) as TechnologicalProcessView;//跨页面 + _TechnologicalProcessView.Grid.ItemsSource = TechnologicalProcessView.sql.Tables[0].DefaultView; + _TechnologicalProcessView.Grid.SelectedIndex = -1; + + TechnologicalProcessView.SQLiteHelpers = new SQLiteHelper(TechnologicalProcessView.DBAddress); //数据库连接路径 + TechnologicalProcessView.SQLiteHelpers.Open(); //打开数据库 + TechnologicalProcessView.SQLiteHelpers.Delete("RUN", null, null); + DataTable data_t = new DataTable(); + data_t.Columns.Add("DYELOT", typeof(string)); //添加列 + data_t = TechnologicalProcessView.sql.Tables[0].Clone(); + int a = TechnologicalProcessView.sql.Tables[0].Rows.Count; + for (int i = 0; i < a; i++) + { + data_t.Clear();//清空 + + DataRow dt = TechnologicalProcessView.sql.Tables[0].Rows[i];//行转换 + DataRow drT = data_t.NewRow(); + drT.ItemArray = dt.ItemArray; + data_t.Rows.InsertAt(drT, 0); + dr.BeginEdit(); //添加订单号 + dr["DYELOT"] = MainWindowViewModel.WorkNumder; + dr.EndEdit(); + + TechnologicalProcessView.SQLiteHelpers.InsertData("RUN", TechnologicalProcessView.SQLiteHelpers.DataTableToDictionary(data_t));//行插入 + } + + TechnologicalProcessView.SQLiteHelpers.Close(); //关闭连接 + } + else if (dat_821.GetValue("INSTRUCTION").ToString() == "DELETE") + { + } client.SendAsync("SC821" + SYSKEY + SYSDAT); } diff --git a/View/TechnologicalProcessView.xaml.cs b/View/TechnologicalProcessView.xaml.cs index 6080c56..d638bab 100644 --- a/View/TechnologicalProcessView.xaml.cs +++ b/View/TechnologicalProcessView.xaml.cs @@ -46,8 +46,8 @@ namespace DyeingComputer.View public static object workName; public static string Program_Name; - private SQLiteHelper SQLiteHelpers = null; //定义数据库 - private readonly string DBAddress = Environment.CurrentDirectory + "\\DataBase\\800COMPUTER.db"; //数据库路径 + public static SQLiteHelper SQLiteHelpers = null; //定义数据库 + public static readonly string DBAddress = Environment.CurrentDirectory + "\\DataBase\\800COMPUTER.db"; //数据库路径 public static DataSet sql; //内存数据缓存 private void TechnologicalProcess_Import() @@ -145,8 +145,8 @@ namespace DyeingComputer.View } private void Address_ButtonClicked(object sender, AddressUpdateEventArgs e)//编辑返回结果 { - int n = StrToInt.To16Convert10(ID); - + int n = Convert.ToInt16(ID); + ID=null; DataRow dr = sql.Tables[0].Rows[n - 1]; dr.BeginEdit(); dr["StepID"] = e.StepID; @@ -223,16 +223,23 @@ namespace DyeingComputer.View SQLiteHelpers.Close(); - if (ID != null) { d = StrToInt.To16Convert10(ID); } else { return; } + if (ID != null) { d = Convert.ToInt16(ID); } else { return; } DataRow dr = sql.Tables[0].NewRow();//添加表数据 dr["ProgramID"] = ProgramID; dr["Program"] = ProgramNAME; sql.Tables[0].Rows.InsertAt(dr, d - 1); - ID = null; + // ID = null; Dat(); - Grid.ItemsSource = sql.Tables[0].DefaultView; //转换显示计划表 + + if (string.IsNullOrEmpty(Numder)) { Numder = null; P1 = "0"; P2 = "0"; P3 = "0"; P4 = "0"; P5 = "0"; } + if (ID == null) ID = sql.Tables[0].Rows.Count.ToString(); + ViewStep viewstop = new ViewStep(null, "0", "0", "0", "0", "0"); + viewstop.data = ID; + viewstop.AddressUpdated += new ViewStep.AddressUpdateHandler(Address_ButtonClicked); + viewstop.ShowDialog(); + //Grid.ItemsSource = sql.Tables[0].DefaultView; //转换显示计划表 } string Numder = null;