diff --git a/UserClass/AsyncTcpClient.cs b/UserClass/AsyncTcpClient.cs index 470bf8b..906f8bd 100644 --- a/UserClass/AsyncTcpClient.cs +++ b/UserClass/AsyncTcpClient.cs @@ -47,17 +47,45 @@ namespace SunlightCentralizedControlManagement_SCCM_.UserClass return EasyTask.CompletedTask; };//成功连接到服务器 - tcpClient.Closing = (client, e) => { return EasyTask.CompletedTask; };//即将从服务器断开连接。此处仅主动断开才有效。 - tcpClient.Closed = (client, e) => { return EasyTask.CompletedTask; };//从服务器断开连接,当连接不成功时不会触发。 + tcpClient.Closing = (client, e) => + { + DataRow drEmployee = MainWindowViewModel.Machines.Select("IP='" + client.IP + "' AND port='" + client.Port + "'").First(); + drEmployee.BeginEdit(); + drEmployee["State"] = "899"; + drEmployee.EndEdit(); + drEmployee.AcceptChanges(); + drEmployee.ClearErrors(); + + return EasyTask.CompletedTask; };//即将从服务器断开连接。此处仅主动断开才有效。 + tcpClient.Closed = (client, e) => + { + DataRow drEmployee = MainWindowViewModel.Machines.Select("IP='" + client.IP + "' AND port='" + client.Port + "'").First(); + drEmployee.BeginEdit(); + drEmployee["State"] = "899"; + drEmployee.EndEdit(); + drEmployee.AcceptChanges(); + drEmployee.ClearErrors(); + + return EasyTask.CompletedTask; };//从服务器断开连接,当连接不成功时不会触发。 tcpClient.Received = (client, e) => { //从服务器收到信息。但是一般byteBlock和requestInfo会根据适配器呈现不同的值。 - var mes = e.ByteBlock.Span.ToString(Encoding.UTF8); + string SYSAPI = e.ByteBlock.Span.ToString(Encoding.ASCII).Substring(0, 5); + string DAT = e.ByteBlock.Span.ToString(Encoding.ASCII); + + if (SYSAPI == "SC851") + { + + + // client.SendAsync("SC851" + "[" + MainWindowViewModel.S01 + "]" + MainWindowViewModel.dt_d.ToJsonString());//数字开关信息 + + + }//数字开关表 - // tcpClient.Logger.Info($"客户端接收到信息:{mes}"); + // tcpClient.Logger.Info($"客户端接收到信息:{mes}"); return EasyTask.CompletedTask; }; diff --git a/View/MachinesSet.xaml.cs b/View/MachinesSet.xaml.cs index fe559e9..6b9cecf 100644 --- a/View/MachinesSet.xaml.cs +++ b/View/MachinesSet.xaml.cs @@ -65,26 +65,35 @@ namespace SunlightCentralizedControlManagement_SCCM_.View private void Save_Click(object sender, RoutedEventArgs e) { if (!string.IsNullOrEmpty(comboBoxMachine.Text)) - { - - - + { Dictionary dr_new = new Dictionary();//缓存函数 dr_new.Add("Name", comboBoxMachine.Text); dr_new.Add("Groups", TextMachineGroup.Text); - - + dr_new.Add("IP", IP.Text); + dr_new.Add("PORT", PORT.Text); + dr_new.Add("Serial", comboBoxCOM0.Text); + dr_new.Add("Baud", BAUD.Text); SQLiteHelpers = new SQLiteHelper(DBAddress); //数据库连接路径 SQLiteHelpers.Open(); //打开数据库 - - SQLiteHelpers.InsertData("Machines", dr_new); - MainWindowViewModel.Machines = SQLiteHelpers.ExecuteDataSet("select * from Machines Order by id", null).Tables[0]; //读取表写入缓存 - SQLiteHelpers.Close(); - + if (SQLiteHelpers.ExecuteDataSet("select * from Machines where name ='" + comboBoxMachine.Text + "'", null).Tables[0].Rows.Count == 0) + { + SQLiteHelpers.InsertData("Machines", dr_new); + } + else + { + SQLiteHelpers.Update("Machines",dr_new,"name='"+comboBoxMachine.Text+"'",null); + } + MainWindowViewModel.Machines = SQLiteHelpers.ExecuteDataSet("select * from Machines Order by id", null).Tables[0]; //读取表写入缓存 + SQLiteHelpers.Close(); Griddata.ItemsSource = MainWindowViewModel.Machines.DefaultView; comboBoxMachine.Text = null; + TextMachineGroup.Text = null; + IP.Text = null; + PORT.Text = "7789"; + comboBoxCOM0.Text = null; + BAUD.Text = "57600"; } else {