Browse Source

连线逻辑修改

master
sc 7 months ago
parent
commit
3b6ab69a71
  1. 12
      ConvertMoels/StateToColorConvert.cs
  2. 15
      EX/ManualDyelot.xaml.cs
  3. 151
      UserClass/AsyncTcpClient.cs
  4. 4
      View/CurveView.xaml.cs
  5. 47
      ViewModel/MainWindowViewModel.cs

12
ConvertMoels/StateToColorConvert.cs

@ -21,17 +21,17 @@ namespace SunlightCentralizedControlManagement_SCCM_.ConvertMoels
{ {
string i = value.ToString(); string i = value.ToString();
if (i == "201") return "green"; if (i == "201") return "#FF00FF00";
else if (i == "202") return "yellow"; else if (i == "202") return "#FFFFFF00";
else if (i == "309") return "Red"; else if (i == "309") return "#FFFF0000";
else if (i == "800") return "Red"; else if (i == "800") return "#FFFF0000";
else return "block"; else return "#FF000000";
} }
} }
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{ {
return "Gray"; return "#FFF0F0F0";
} }
} }
} }

15
EX/ManualDyelot.xaml.cs

@ -205,10 +205,17 @@ namespace SunlightCentralizedControlManagement_SCCM_.EX
private void comboBoxMachine_DropDownClosed(object sender, EventArgs e) private void comboBoxMachine_DropDownClosed(object sender, EventArgs e)
{ {
if (!string.IsNullOrEmpty(comboBoxMachine.Text)) if (!string.IsNullOrEmpty(comboBoxMachine.Text))
{ {
if (MainWindowViewModel.Machines.Select("NAME = '" + comboBoxMachine.Text + "'").First().Field<string>("WorkOrder") != "------") string Macht= MainWindowViewModel.Selet_Machines(MainWindowViewModel.Machines, "WorkOrder", "NAME = '" + comboBoxMachine.Text + "'").ToString();
{ orders.Text = MainWindowViewModel.Machines.Select("NAME = '" + comboBoxMachine.Text + "'").First().Field<string>("WorkOrder"); }
else { orders.Text = dyelot.Text; } if (Macht != "------")
{
orders.Text = Macht;
}
else
{
orders.Text = dyelot.Text;
}
} }
} }

151
UserClass/AsyncTcpClient.cs

@ -44,76 +44,67 @@ namespace SunlightCentralizedControlManagement_SCCM_.UserClass
tcpClient.Connecting = (client, e) => { return EasyTask.CompletedTask; };//即将连接到服务器,此时已经创建socket,但是还未建立tcp tcpClient.Connecting = (client, e) => { return EasyTask.CompletedTask; };//即将连接到服务器,此时已经创建socket,但是还未建立tcp
tcpClient.Connected = (client, e) => tcpClient.Connected = (client, e) =>
{ {
lock (MainWindowViewModel.Machines) try
{ {
try DataRow drEmployee = MainWindowViewModel.Machines.Select("IP='" + client.IP + "'").First();
{ drEmployee.BeginEdit();
DataRow drEmployee = MainWindowViewModel.Machines.Select("IP='" + client.IP + "'").First(); drEmployee["State"] = "801";
drEmployee.BeginEdit(); drEmployee.EndEdit();
drEmployee["State"] = "801"; drEmployee.AcceptChanges();
drEmployee.EndEdit(); LogGing.LogGingDATA("[IP='" + client.IP + "' AND port='" + client.Port + "']=Link_OK");
drEmployee.AcceptChanges(); }
LogGing.LogGingDATA("[IP='" + client.IP + "' AND port='" + client.Port + "']=Link_OK"); catch (Exception ex)
} {
catch (Exception ex) LogGing.ERRDATA(ex); MainWindowViewModel.ERR_c++;
{
LogGing.ERRDATA(ex); MainWindowViewModel.ERR_c++;
}
} }
return EasyTask.CompletedTask; return EasyTask.CompletedTask;
};//成功连接到服务器 };//成功连接到服务器
tcpClient.Closing = (client, e) => tcpClient.Closing = (client, e) =>
{ {
lock (MainWindowViewModel.Machines) try
{ {
try DataRow drEmployee = MainWindowViewModel.Machines.Select("IP='" + client.IP + "'").First();
{ drEmployee.BeginEdit();
DataRow drEmployee = MainWindowViewModel.Machines.Select("IP='" + client.IP + "'").First(); drEmployee["State"] = "899";
drEmployee.BeginEdit(); drEmployee["WorkOrder"] = "------";
drEmployee["State"] = "899"; drEmployee["Dyelot"] = "";
drEmployee["WorkOrder"] = "------"; drEmployee["Temperature"] = "---.-";
drEmployee["Dyelot"] = ""; drEmployee["WaterLevel"] = "----";
drEmployee["Temperature"] = "---.-"; drEmployee["Process"] = "";
drEmployee["WaterLevel"] = "----"; drEmployee["Step"] = "";
drEmployee["Process"] = ""; drEmployee["Message"] = "";
drEmployee["Step"] = ""; drEmployee.EndEdit();
drEmployee["Message"] = ""; drEmployee.AcceptChanges();
drEmployee.EndEdit(); LogGing.LogGingDATA("[IP='" + client.IP + "' AND port='" + client.Port + "']=Link_STOP");
drEmployee.AcceptChanges(); }
LogGing.LogGingDATA("[IP='" + client.IP + "' AND port='" + client.Port + "']=Link_STOP"); catch (Exception ex)
} {
catch (Exception ex) LogGing.ERRDATA(ex); MainWindowViewModel.ERR_c++;
{
LogGing.ERRDATA(ex); MainWindowViewModel.ERR_c++;
}
} }
return EasyTask.CompletedTask; return EasyTask.CompletedTask;
};//即将从服务器断开连接。此处仅主动断开才有效。 };//即将从服务器断开连接。此处仅主动断开才有效。
tcpClient.Closed = (client, e) => tcpClient.Closed = (client, e) =>
{ {
lock (MainWindowViewModel.Machines) try
{ {
try DataRow drEmployee = MainWindowViewModel.Machines.Select("IP='" + client.IP + "'").First();
{ drEmployee.BeginEdit();
DataRow drEmployee = MainWindowViewModel.Machines.Select("IP='" + client.IP + "'").First(); drEmployee["State"] = "899";
drEmployee.BeginEdit(); drEmployee["WorkOrder"] = "------";
drEmployee["State"] = "899"; drEmployee["Dyelot"] = "";
drEmployee["WorkOrder"] = "------"; drEmployee["Temperature"] = "---.-";
drEmployee["Dyelot"] = ""; drEmployee["WaterLevel"] = "----";
drEmployee["Temperature"] = "---.-"; drEmployee["Process"] = "";
drEmployee["WaterLevel"] = "----"; drEmployee["Step"] = "";
drEmployee["Process"] = ""; drEmployee["Message"] = "";
drEmployee["Step"] = ""; drEmployee.EndEdit();
drEmployee["Message"] = ""; drEmployee.AcceptChanges();
drEmployee.EndEdit(); LogGing.LogGingDATA("[IP='" + client.IP + "' AND port='" + client.Port + "']=Link_INTERRUPT");
drEmployee.AcceptChanges(); }
LogGing.LogGingDATA("[IP='" + client.IP + "' AND port='" + client.Port + "']=Link_INTERRUPT"); catch (Exception ex)
} {
catch (Exception ex) LogGing.ERRDATA(ex); MainWindowViewModel.ERR_c++;
{
LogGing.ERRDATA(ex); MainWindowViewModel.ERR_c++;
}
} }
return EasyTask.CompletedTask; return EasyTask.CompletedTask;
};//从服务器断开连接,当连接不成功时不会触发。 };//从服务器断开连接,当连接不成功时不会触发。
@ -124,27 +115,25 @@ namespace SunlightCentralizedControlManagement_SCCM_.UserClass
string DAT = e.ByteBlock.Span.ToString(Encoding.UTF8); string DAT = e.ByteBlock.Span.ToString(Encoding.UTF8);
if (SYSAPI == "SC800") if (SYSAPI == "SC800")
{ {
lock (MainWindowViewModel.Machines) try
{ {
try DAT = DAT.Substring(DAT.IndexOf("]") + 1);
{ Dictionary<string, object> Chart_new = new Dictionary<string, object>();//缓存函数
DAT = DAT.Substring(DAT.IndexOf("]") + 1); Chart_new = JsonConvert.DeserializeObject<Dictionary<string, object>>(DAT);//反序列化
Dictionary<string, object> Chart_new = new Dictionary<string, object>();//缓存函数 DataRow drEmployee = MainWindowViewModel.Machines.Select("IP='" + client.IP + "'").First();
Chart_new = JsonConvert.DeserializeObject<Dictionary<string, object>>(DAT);//反序列化 drEmployee.BeginEdit();
DataRow drEmployee = MainWindowViewModel.Machines.Select("IP='" + client.IP + "' AND port='" + client.Port + "'").First(); drEmployee["SYSKEY"] = Chart_new.GetValue("SYSKEY").ToString();
drEmployee.BeginEdit(); drEmployee["NAME"] = Chart_new.GetValue("MACHINE").ToString();
drEmployee["SYSKEY"] = Chart_new.GetValue("SYSKEY").ToString(); drEmployee["Groups"] = Chart_new.GetValue("GROUP").ToString();
drEmployee["NAME"] = Chart_new.GetValue("MACHINE").ToString(); drEmployee["State"] = "802";
drEmployee["Groups"] = Chart_new.GetValue("GROUP").ToString(); drEmployee.EndEdit();
drEmployee["State"] = "802"; drEmployee.AcceptChanges();
drEmployee.EndEdit(); }
drEmployee.AcceptChanges(); catch (Exception ex)
} {
catch (Exception ex) LogGing.ERRDATA(ex); MainWindowViewModel.ERR_c++;
{
LogGing.ERRDATA(ex); MainWindowViewModel.ERR_c++;
}
} }
} }
else if (SYSAPI == "SC810") else if (SYSAPI == "SC810")
{ {
@ -172,16 +161,18 @@ namespace SunlightCentralizedControlManagement_SCCM_.UserClass
SQLiteHelpers.Update("WorkOrder", new Dictionary<string, object> { { "State", 101 } }, SQLiteHelpers.Update("WorkOrder", new Dictionary<string, object> { { "State", 101 } },
"WorkOrder ='" + DAT + "'", null); "WorkOrder ='" + DAT + "'", null);
SQLiteHelpers.Close(); SQLiteHelpers.Close();
}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 == "SC830") else if (SYSAPI == "SC830")
{ {
try try
{ {
DAT = DAT.Substring(DAT.IndexOf("]") + 1); DAT = DAT.Substring(DAT.IndexOf("]") + 1);
Dictionary<string, object> _new = new Dictionary<string, object>();//缓存函数 Dictionary<string, object> _new = new Dictionary<string, object>();//缓存函数
_new = JsonConvert.DeserializeObject<Dictionary<string, object>>(DAT);//反序列化 _new = JsonConvert.DeserializeObject<Dictionary<string, object>>(DAT);//反序列化
DataRow drEmployee = MainWindowViewModel.Machines.Select("IP='" + client.IP + "' AND port='" + client.Port + "'").First(); DataRow drEmployee = MainWindowViewModel.Machines.Select("IP='" + client.IP + "'").First();
drEmployee.BeginEdit(); drEmployee.BeginEdit();
drEmployee["Message"] = _new.GetValue("Status"); drEmployee["Message"] = _new.GetValue("Status");
drEmployee["WorkOrder"] = _new.GetValue("WorkNumder"); drEmployee["WorkOrder"] = _new.GetValue("WorkNumder");
@ -191,7 +182,6 @@ namespace SunlightCentralizedControlManagement_SCCM_.UserClass
drEmployee["Step"] = _new.GetValue("Step"); drEmployee["Step"] = _new.GetValue("Step");
drEmployee.EndEdit(); drEmployee.EndEdit();
drEmployee.AcceptChanges(); drEmployee.AcceptChanges();
drEmployee.ClearErrors();
if (_new.GetValue("Status").ToString() != "----------") if (_new.GetValue("Status").ToString() != "----------")
{ {
@ -216,6 +206,7 @@ namespace SunlightCentralizedControlManagement_SCCM_.UserClass
SQLiteHelpers.InsertData("Chart", Chart_new);// 执行插入 SQLiteHelpers.InsertData("Chart", Chart_new);// 执行插入
SQLiteHelpers.Close(); SQLiteHelpers.Close();
} }
} }
catch (Exception ex) { LogGing.LogGingDATA("[ERR='" + ex + "']=Exception"); MainWindowViewModel.ERR_c++; } catch (Exception ex) { LogGing.LogGingDATA("[ERR='" + ex + "']=Exception"); MainWindowViewModel.ERR_c++; }
} }
@ -316,7 +307,7 @@ namespace SunlightCentralizedControlManagement_SCCM_.UserClass
else if (SYSAPI == "SC980") else if (SYSAPI == "SC980")
{ {
DAT = DAT.Substring(DAT.IndexOf("]") + 1); DAT = DAT.Substring(DAT.IndexOf("]") + 1);
MessageBox.Show(DAT,"SCCM", MessageBoxButton.OK, MessageBoxImage.Question); MessageBox.Show(DAT, "SCCM", MessageBoxButton.OK, MessageBoxImage.Question);
} }
return EasyTask.CompletedTask; return EasyTask.CompletedTask;
@ -331,7 +322,7 @@ namespace SunlightCentralizedControlManagement_SCCM_.UserClass
{ {
a.UseCheckClear() a.UseCheckClear()
.SetCheckClearType(CheckClearType.All) .SetCheckClearType(CheckClearType.All)
.SetTick(TimeSpan.FromSeconds(30)) .SetTick(TimeSpan.FromSeconds(60))
.SetOnClose((c, t) => .SetOnClose((c, t) =>
{ {
c.TryShutdown(); c.TryShutdown();

4
View/CurveView.xaml.cs

@ -62,11 +62,9 @@ namespace SunlightCentralizedControlManagement_SCCM_.View
private void UserControl_Loaded(object sender, RoutedEventArgs e) private void UserControl_Loaded(object sender, RoutedEventArgs e)
{ {
Griddata.ItemsSource = MainWindowViewModel.Machines.DefaultView;
Sdatepicker.Text = DateTime.Now.ToString("yyyy/MM/dd"); Sdatepicker.Text = DateTime.Now.ToString("yyyy/MM/dd");
Picture.Content = new View.CurveDiagram(false,"","","", CurveDiagram); Picture.Content = new View.CurveDiagram(false,"","","", CurveDiagram);
Griddata.ItemsSource = MainWindowViewModel.Machines.DefaultView;
} }
private void WorkOrderNumder_Click(object sender, RoutedEventArgs e) private void WorkOrderNumder_Click(object sender, RoutedEventArgs e)

47
ViewModel/MainWindowViewModel.cs

@ -161,7 +161,7 @@ namespace SunlightCentralizedControlManagement_SCCM_.ViewModel
DispatcherTimer dis50ms = new DispatcherTimer DispatcherTimer dis50ms = new DispatcherTimer
{ {
Interval = TimeSpan.FromMilliseconds(50) //毫秒 Interval = TimeSpan.FromMilliseconds(10) //毫秒
}; };
dis50ms.Tick += new EventHandler(DisTimer_50MS);//每一秒执行的方法 dis50ms.Tick += new EventHandler(DisTimer_50MS);//每一秒执行的方法
dis50ms.Start();//计时开始 dis50ms.Start();//计时开始
@ -346,9 +346,9 @@ namespace SunlightCentralizedControlManagement_SCCM_.ViewModel
return index; return index;
} }
} }
catch (Exception) catch (Exception ex)
{ {
// LogGing.LogGingDATA("SDTD:" + ex.ToString()); LogGing.LogGingDATA("SDTD:" + ex.ToString());
return "ERR"; return "ERR";
} }
} }
@ -363,44 +363,15 @@ namespace SunlightCentralizedControlManagement_SCCM_.ViewModel
drEmployee[name] = Value; drEmployee[name] = Value;
drEmployee.EndEdit(); drEmployee.EndEdit();
drEmployee.AcceptChanges(); drEmployee.AcceptChanges();
drEmployee.ClearErrors(); // drEmployee.ClearErrors();
} }
} }
catch (Exception) catch (Exception ex)
{ {
// LogGing.LogGingDATA("SDTD:" + ex.ToString()); LogGing.LogGingDATA("SDTD:" + ex.ToString());
}
}
public static void UpdataMachines(string key, DataRow Value)//更新数据
{
try
{
lock (Machines)
{
DataRow drEmployee = Machines.Select("IP='" + key + "'").First();
drEmployee.BeginEdit();
if (Value["State"] != null) drEmployee["State"] = Value["State"];
if (Value["WorkOrder"] != null) drEmployee["WorkOrder"] = Value["WorkOrder"];
if (Value["Dyelot"] != null) drEmployee["Dyelot"] = Value["Dyelot"];
if (Value["Temperature"] != null) drEmployee["Temperature"] = Value["WorkOrder"];
if (Value["WaterLevel"] != null) drEmployee["WaterLevel"] = Value["WaterLevel"];
if (Value["Process"] != null) drEmployee["Process"] = Value["Process"];
if (Value["Step"] != null) drEmployee["Step"] = Value["Step"];
if (Value["Message"] != null) drEmployee["Message"] = Value["Message"];
if (Value["SYSKEY"] != null) drEmployee["SYSKEY"] = Value["SYSKEY"];
if (Value["Groups"] != null) drEmployee["Groups"] = Value["Groups"];
drEmployee.EndEdit();
drEmployee.AcceptChanges();
drEmployee.ClearErrors();
}
}
catch (Exception)
{
// LogGing.LogGingDATA("SDTD:" + ex.ToString());
} }
} }
public static DataTable dt_d = new DataTable("DIO"); public static DataTable dt_d = new DataTable("DIO");
public static DataTable dt_a = new DataTable("AIO"); public static DataTable dt_a = new DataTable("AIO");

Loading…
Cancel
Save