diff --git a/UserClass/AsyncTcpClient.cs b/UserClass/AsyncTcpClient.cs index 07513f2..865737b 100644 --- a/UserClass/AsyncTcpClient.cs +++ b/UserClass/AsyncTcpClient.cs @@ -109,16 +109,16 @@ namespace SunlightCentralizedControlManagement_SCCM_.UserClass else if (SYSAPI == "SC831") { DAT = DAT.Substring(DAT.IndexOf("]") + 1); - MonitorView.TechnologicalProcess = JsonConvert.DeserializeObject(DAT);//反序列化 + MainWindowViewModel.dt_TP = JsonConvert.DeserializeObject(DAT);//反序列化 } else if (SYSAPI == "SC832") { - MonitorView.Sys_log = DAT.Substring(DAT.IndexOf("]") + 1); + MainWindowViewModel.MachineLOG = DAT.Substring(DAT.IndexOf("]") + 1); }//当前细节信息 else if (SYSAPI == "SC833") { - MonitorView.Sys_log = DAT.Substring(DAT.IndexOf("]") + 1); + MainWindowViewModel.MachineLOG = DAT.Substring(DAT.IndexOf("]") + 1); }//当前领料单信息 else if (SYSAPI == "SC851") diff --git a/View/MonitorView.xaml b/View/MonitorView.xaml index baa3ee5..7919a68 100644 --- a/View/MonitorView.xaml +++ b/View/MonitorView.xaml @@ -10,8 +10,7 @@ d:DataContext="{d:DesignInstance Type=viewmodel:MainWindowViewModel}" mc:Ignorable="d" d:DesignHeight="1000" d:DesignWidth="1900"> - - + @@ -19,11 +18,12 @@ + CanUserDeleteRows="False" SelectionMode="Single" FontSize="15" Focusable="True" > - - - - - - - - - - - - - - - - - - - - - - - - + CanUserDeleteRows="False" SelectionMode="Single" FontSize="15" Focusable="True" > + + + + + + + + + + + + + + + + + + + + + - - - + + + diff --git a/View/MonitorView.xaml.cs b/View/MonitorView.xaml.cs index 67b3b8b..0ae7ba1 100644 --- a/View/MonitorView.xaml.cs +++ b/View/MonitorView.xaml.cs @@ -37,8 +37,6 @@ namespace SunlightCentralizedControlManagement_SCCM_.View public MonitorView() { InitializeComponent(); - - Griddata.ItemsSource = MainWindowViewModel.Machines.DefaultView; CountDown(); } @@ -49,10 +47,8 @@ namespace SunlightCentralizedControlManagement_SCCM_.View public static string Sys_log; private void Griddata_SelectionChanged(object sender, SelectionChangedEventArgs e)//设备列表 - { - Gridstep.ItemsSource = null; log.Text = null; + { Stop.IsEnabled = true; - int rownum = Griddata.SelectedIndex;//获取鼠标选中行并定义变量 if (rownum != -1)//判断鼠标定位是否有效 { @@ -141,8 +137,7 @@ namespace SunlightCentralizedControlManagement_SCCM_.View }//停止 private void ListViewItem_edit(object sender, MouseButtonEventArgs e) { - if (string.IsNullOrEmpty(Numder)) { Numder = null; P1 = "0"; P2 = "0"; P3 = "0"; P4 = "0"; P5 = "0"; } - if (ID == null) ID = TechnologicalProcess.Rows.Count.ToString(); + if (string.IsNullOrEmpty(Numder)) { Numder = null; P1 = "0"; P2 = "0"; P3 = "0"; P4 = "0"; P5 = "0"; } ViewStep viewstop = new ViewStep(Numder, P1, P2, P3, P4, P5); viewstop.data = ID; viewstop.AddressUpdated += new ViewStep.AddressUpdateHandler(edit_ButtonClicked); @@ -177,7 +172,6 @@ namespace SunlightCentralizedControlManagement_SCCM_.View }//跳步 private void ListViewItem_Insert(object sender, MouseButtonEventArgs e) { - 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(Insert_ButtonClicked); @@ -211,14 +205,12 @@ namespace SunlightCentralizedControlManagement_SCCM_.View { DispatcherTimer timer1s = new DispatcherTimer//初始化循环,每1秒调用一次Tick { - Interval = TimeSpan.FromSeconds(1)//秒 + Interval = TimeSpan.FromSeconds(1.5)//秒 }; timer1s.Tick += Tick_Event_1S; timer1s.Start(); }//时间周期初始化 - public static DataTable TechnologicalProcess =new DataTable(); - void Tick_Event_1S(object sender, EventArgs e)//Tick_Event周期执行事件1S { if (!string.IsNullOrEmpty(machine)) @@ -241,39 +233,26 @@ namespace SunlightCentralizedControlManagement_SCCM_.View else if (machines_info == 2) { MainWindowViewModel.MachiensTcpClient[index].SendAsync("SC833" + MainWindowViewModel.Selet_Machines(MainWindowViewModel.Machines, "SYSKEY", index)); - }//单据 - log.Text = Sys_log; + }//单据 } else - { - log.Text = null; + { + MainWindowViewModel.MachineLOG = null; } if ((State_ == 101) || (State_ == 201) || (State_ == 202) || (State_ == 309))//获得细节信息 { - MainWindowViewModel.MachiensTcpClient[index].SendAsync("SC831" + MainWindowViewModel.Selet_Machines(MainWindowViewModel.Machines, "SYSKEY", index)); - if (TechnologicalProcess.Rows.Count > 0) - { - // Gridstep.ItemsSource = MainWindowViewModel.dt_TP.DefaultView; - // if (!Equals(Gridstep.ItemsSource , TechnologicalProcess.DefaultView)) - // { - MainWindowViewModel.dt_TP = TechnologicalProcess; - // } - } - else - { - // MainWindowViewModel.dt_TP = null; - } + MainWindowViewModel.MachiensTcpClient[index].SendAsync("SC831" + MainWindowViewModel.Selet_Machines(MainWindowViewModel.Machines, "SYSKEY", index)); } else { - // MainWindowViewModel.dt_TP = null; + MainWindowViewModel.dt_TP.Clear(); } } catch (Exception ) - { - log.Text = null; - // MainWindowViewModel.dt_TP = null; + { + // MainWindowViewModel.MachineLOG = null; + // MainWindowViewModel.dt_TP.Clear(); }//返回错误为空 } } diff --git a/ViewModel/MainWindowViewModel.cs b/ViewModel/MainWindowViewModel.cs index c960ad4..728d383 100644 --- a/ViewModel/MainWindowViewModel.cs +++ b/ViewModel/MainWindowViewModel.cs @@ -77,12 +77,7 @@ namespace SunlightCentralizedControlManagement_SCCM_.ViewModel { } } - public string sys_Time; //显示系统时间 - public string Sys_Time //通知UI控件参数改变 - { - get { return sys_Time; } - set { sys_Time = value; OnPropertyChanged("Sys_Time"); } - } + public void CountDown() { DispatcherTimer timer1s = new DispatcherTimer//初始化循环,每1秒调用一次Tick @@ -121,7 +116,15 @@ namespace SunlightCentralizedControlManagement_SCCM_.ViewModel //Updata_Machines(Machines, Convert.ToInt16(dt["ID"]), "State", "800"); } } + for (int i = 0; i < Machinesdata_Count; i++) + { + string mac_s = Selet_Machines(Machines, "State", i).ToString(); + if ((mac_s == "101") || (mac_s == "201") || (mac_s == "202") || (mac_s == "309"))//获取信息 + { + MachiensTcpClient[i].SendAsync("SC830" + Selet_Machines(Machines, "SYSKEY", i).ToString()); + } + } } void Tick_Event_5S(object sender, EventArgs e)//Tick_Event周期执行事件5S { @@ -139,15 +142,7 @@ namespace SunlightCentralizedControlManagement_SCCM_.ViewModel { DATA_view(); - for (int i = 0; i < Machinesdata_Count; i++) - { - string mac_s = Selet_Machines(Machines, "State", i).ToString(); - if ((mac_s == "101")|| (mac_s == "201") || (mac_s == "202")|| (mac_s == "309"))//获取信息 - { - MachiensTcpClient[i].SendAsync("SC830" + Selet_Machines(Machines, "SYSKEY", i).ToString()); - - } - } + } private SQLiteHelper SQLiteHelpers = null; //定义数据库 @@ -192,8 +187,19 @@ namespace SunlightCentralizedControlManagement_SCCM_.ViewModel public static int SYS_AT3; - - + public string sys_Time; //显示系统时间 + public string Sys_Time //通知UI控件参数改变 + { + get { return sys_Time; } + set { sys_Time = value; OnPropertyChanged("Sys_Time"); } + } + public static string MachineLOG; + public string sys_machine; //显示log + public string Sys_machine //通知UI控件参数改变 + { + get { return sys_machine; } + set { sys_machine = value; OnPropertyChanged("Sys_machine"); } + } public static object Selet_Machines(DataTable DB, string name, int key)//查询 { @@ -238,14 +244,24 @@ namespace SunlightCentralizedControlManagement_SCCM_.ViewModel 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_TM = new DataTable(); public static DataTable dt_TP = new DataTable(); private async void DATA_view()//IO显示 { await Task.Run(() => - { + { + try + { + TechnologicalMachine_View = ToObservableCollection(Machines); + } + catch (Exception) { } try { - TechnologicalProcess_View = ToObservableCollection(dt_TP); + if (dt_TP.Rows.Count > 0) + { + TechnologicalProcess_View = ToObservableCollection(dt_TP); + Sys_machine = MachineLOG; + } } catch (Exception) { } }); @@ -254,7 +270,8 @@ namespace SunlightCentralizedControlManagement_SCCM_.ViewModel ObservableCollection sysData_A = new ObservableCollection(); ObservableCollection sysData_D = new ObservableCollection(); ObservableCollection sysData_M = new ObservableCollection(); - ObservableCollection technologicalProcess_View = new ObservableCollection(); + ObservableCollection technologicalProcess_View = new ObservableCollection(); + ObservableCollection technologicalMachine_View = new ObservableCollection(); public ObservableCollection SYSData_A { @@ -285,9 +302,8 @@ namespace SunlightCentralizedControlManagement_SCCM_.ViewModel RaisePropertyChanged("SYSData_M"); } } - public ObservableCollection TechnologicalProcess_View + public ObservableCollection TechnologicalProcess_View { - get { return technologicalProcess_View; } set { @@ -295,6 +311,15 @@ namespace SunlightCentralizedControlManagement_SCCM_.ViewModel RaisePropertyChanged("TechnologicalProcess_View"); } } + public ObservableCollection TechnologicalMachine_View + { + get { return technologicalMachine_View; } + set + { + technologicalMachine_View = value; + RaisePropertyChanged("TechnologicalMachine_View"); + } + } public class DATA_A { public string IOName { get; set; } @@ -319,7 +344,7 @@ namespace SunlightCentralizedControlManagement_SCCM_.ViewModel public string PLC { get; set; } public string type { get; set; } } - public class Technological + public class TechnologicalP { public string ProgramID { get; set; } public string Program { get; set; } @@ -332,13 +357,20 @@ namespace SunlightCentralizedControlManagement_SCCM_.ViewModel 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 class TechnologicalM + { + public string Name { get; set; } + public string WorkOrder { get; set; } + public string Dyelot { get; set; } + public string Temperature { get; set; } + public string WaterLevel { get; set; } + public string Process { get; set; } + public string Step { get; set; } + public string Message { get; set; } + + } public ObservableCollection ToObservableCollection(DataTable dt) where T : class, new() { Type t = typeof(T);