diff --git a/View/MonitorView.xaml b/View/MonitorView.xaml index 6fb06a4..baa3ee5 100644 --- a/View/MonitorView.xaml +++ b/View/MonitorView.xaml @@ -6,6 +6,8 @@ xmlns:local="clr-namespace:SunlightCentralizedControlManagement_SCCM_.View" xmlns:lang="clr-namespace:SunlightCentralizedControlManagement_SCCM_.Properties" xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes" + xmlns:viewmodel="clr-namespace:SunlightCentralizedControlManagement_SCCM_.ViewModel" + d:DataContext="{d:DesignInstance Type=viewmodel:MainWindowViewModel}" mc:Ignorable="d" d:DesignHeight="1000" d:DesignWidth="1900"> @@ -70,7 +72,8 @@ dat_821 = new Dictionary(); dat_821.Clear(); @@ -172,12 +177,31 @@ namespace SunlightCentralizedControlManagement_SCCM_.View }//跳步 private void ListViewItem_Insert(object sender, MouseButtonEventArgs e) { - if (ID == null) ID = (TechnologicalProcess.Rows.Count-1).ToString(); + if (ID == null) ID = (TechnologicalProcess.Rows.Count).ToString(); ViewStep viewstop = new ViewStep(null, "0", "0", "0", "0", "0"); viewstop.data = ID; - viewstop.AddressUpdated += new ViewStep.AddressUpdateHandler(Address_ButtonClicked); + viewstop.AddressUpdated += new ViewStep.AddressUpdateHandler(Insert_ButtonClicked); viewstop.ShowDialog(); }//插入 + private void Insert_ButtonClicked(object sender, AddressUpdateEventArgs e)//编辑返回结果 + { + Dictionary dat_821 = new Dictionary(); + dat_821.Clear(); + dat_821.Add("INSTRUCTION", "INSERT"); + dat_821.Add("StepID", e.StepID); + dat_821.Add("StepName", e.StepNAME); + dat_821.Add("ParameterName", e.PNAME); + dat_821.Add("Parameter1", e.P1); + dat_821.Add("Parameter2", e.P2); + dat_821.Add("Parameter3", e.P3); + dat_821.Add("Parameter4", e.P4); + dat_821.Add("Parameter5", e.P5); + dat_821.Add("ID", ID); + + DataRow drEmployee = MainWindowViewModel.Machines.Select("NAME='" + machine + "'").First(); + int index = Convert.ToInt16(drEmployee.Field("ID")); + MainWindowViewModel.MachiensTcpClient[index].SendAsync("SC821" + MainWindowViewModel.Selet_Machines(MainWindowViewModel.Machines, "SYSKEY", index) + dat_821.ToJsonString()); + } private void ListViewItem_Delete(object sender, MouseButtonEventArgs e) { @@ -230,25 +254,31 @@ namespace SunlightCentralizedControlManagement_SCCM_.View MainWindowViewModel.MachiensTcpClient[index].SendAsync("SC831" + MainWindowViewModel.Selet_Machines(MainWindowViewModel.Machines, "SYSKEY", index)); if (TechnologicalProcess.Rows.Count > 0) { - DataView dataView = TechnologicalProcess.DefaultView; - if (Gridstep.ItemsSource != dataView) - { - Gridstep.ItemsSource = dataView; - } + // Gridstep.ItemsSource = MainWindowViewModel.dt_TP.DefaultView; + // if (!Equals(Gridstep.ItemsSource , TechnologicalProcess.DefaultView)) + // { + MainWindowViewModel.dt_TP = TechnologicalProcess; + // } } else { - Gridstep.ItemsSource = null; + // MainWindowViewModel.dt_TP = null; } } else { - Gridstep.ItemsSource = null; + // MainWindowViewModel.dt_TP = null; } } - catch (Exception ) { log.Text = null; Gridstep.ItemsSource = null; }//返回错误为空 - } + catch (Exception ) + { + log.Text = null; + // MainWindowViewModel.dt_TP = null; + }//返回错误为空 + } } - + + } + } diff --git a/ViewModel/MainWindowViewModel.cs b/ViewModel/MainWindowViewModel.cs index df1a45b..c960ad4 100644 --- a/ViewModel/MainWindowViewModel.cs +++ b/ViewModel/MainWindowViewModel.cs @@ -5,18 +5,22 @@ using SunlightCentralizedControlManagement_SCCM_.Properties; using SunlightCentralizedControlManagement_SCCM_.UserClass; using System; using System.Collections.Generic; +using System.Collections.ObjectModel; using System.ComponentModel; using System.Data; using System.Data.SqlClient; using System.Linq; +using System.Reflection; using System.Text; using System.Threading.Tasks; using System.Windows.Controls; +using System.Windows.Forms; using System.Windows.Media; using System.Windows.Threading; using TouchSocket.Core; using TouchSocket.Sockets; using static SunlightCentralizedControlManagement_SCCM_.UserClass.SqliteHelper; +using static System.Net.WebRequestMethods; namespace SunlightCentralizedControlManagement_SCCM_.ViewModel { @@ -121,6 +125,7 @@ namespace SunlightCentralizedControlManagement_SCCM_.ViewModel } void Tick_Event_5S(object sender, EventArgs e)//Tick_Event周期执行事件5S { + for (int i = 0; i < Machinesdata_Count; i++) { if (Selet_Machines(Machines, "State", i).ToString() == "801") @@ -132,6 +137,8 @@ namespace SunlightCentralizedControlManagement_SCCM_.ViewModel } void DisTimer_500MS(object sender, EventArgs e)//Tick_Event周期执行事件500MS { + DATA_view(); + for (int i = 0; i < Machinesdata_Count; i++) { string mac_s = Selet_Machines(Machines, "State", i).ToString(); @@ -157,6 +164,7 @@ namespace SunlightCentralizedControlManagement_SCCM_.ViewModel CountDown(); TcpClientNEW(); SQL_LINK(); + } public static TcpClient[] MachiensTcpClient = new TcpClient[999]; @@ -224,5 +232,159 @@ namespace SunlightCentralizedControlManagement_SCCM_.ViewModel // LogGing.LogGingDATA("SDTD:" + ex.ToString()); } } + + + + public static DataTable dt_d = new DataTable("DIO"); + public static DataTable dt_a = new DataTable("AIO"); + public static DataTable dt_m = new DataTable("M"); + public static DataTable dt_TP = new DataTable(); + private async void DATA_view()//IO显示 + { + await Task.Run(() => + { + try + { + TechnologicalProcess_View = ToObservableCollection(dt_TP); + } + catch (Exception) { } + }); + } + + ObservableCollection sysData_A = new ObservableCollection(); + ObservableCollection sysData_D = new ObservableCollection(); + ObservableCollection sysData_M = new ObservableCollection(); + ObservableCollection technologicalProcess_View = new ObservableCollection(); + public ObservableCollection SYSData_A + { + + get { return sysData_A; } + set + { + sysData_A = value; + RaisePropertyChanged("SYSData_A"); + } + } + public ObservableCollection SYSData_D + { + + get { return sysData_D; } + set + { + sysData_D = value; + RaisePropertyChanged("SYSData_D"); + } + } + public ObservableCollection SYSData_M + { + + get { return sysData_M; } + set + { + sysData_M = value; + RaisePropertyChanged("SYSData_M"); + } + } + public ObservableCollection TechnologicalProcess_View + { + + get { return technologicalProcess_View; } + set + { + technologicalProcess_View = value; + RaisePropertyChanged("TechnologicalProcess_View"); + } + } + public class DATA_A + { + public string IOName { get; set; } + public int AIO { get; set; } + public string ID { get; set; } + public string PLC { get; set; } + public string type { get; set; } + } + public class DATA_D + { + public string IOName { get; set; } + public bool DIO { get; set; } + public string ID { get; set; } + public string PLC { get; set; } + public string type { get; set; } + } + public class DATA_M + { + public string IOName { get; set; } + public double Value { get; set; } + public string ID { get; set; } + public string PLC { get; set; } + public string type { get; set; } + } + public class Technological + { + public string ProgramID { get; set; } + public string Program { get; set; } + public double Step { get; set; } + public string StepID { get; set; } + public string StepName { get; set; } + public string ParameterName { get; set; } + public string Parameter1 { get; set; } + public string Parameter2 { get; set; } + public string Parameter3 { get; set; } + public string Parameter4 { get; set; } + public string Parameter5 { get; set; } + public string Parameter6 { get; set; } + public string Parameter7 { get; set; } + public string Parameter8 { get; set; } + public string Parameter9 { get; set; } + public string Parameter10 { get; set; } + public string DYELOT { get; set; } + } + public ObservableCollection ToObservableCollection(DataTable dt) where T : class, new() + { + Type t = typeof(T); + PropertyInfo[] propertys = t.GetProperties(); + ObservableCollection lst = new ObservableCollection(); + string typeName = string.Empty; + foreach (DataRow dr in dt.Rows) + { + T entity = new T(); + foreach (PropertyInfo pi in propertys) + { + typeName = pi.Name; + if (dt.Columns.Contains(typeName)) + { + if (!pi.CanWrite) continue; + object value = dr[typeName]; + if (value == DBNull.Value) continue; + if (pi.PropertyType == typeof(string)) + { + pi.SetValue(entity, value.ToString(), null); + } + else if (pi.PropertyType == typeof(int) || pi.PropertyType == typeof(int?)) + { + pi.SetValue(entity, int.Parse(value.ToString()), null); + } + else if (pi.PropertyType == typeof(DateTime?) || pi.PropertyType == typeof(DateTime)) + { + pi.SetValue(entity, DateTime.Parse(value.ToString()), null); + } + else if (pi.PropertyType == typeof(float)) + { + pi.SetValue(entity, float.Parse(value.ToString()), null); + } + else if (pi.PropertyType == typeof(double)) + { + pi.SetValue(entity, double.Parse(value.ToString()), null); + } + else + { + pi.SetValue(entity, value, null); + } + } + } + lst.Add(entity); + } + return lst; + } } }