using SunlightCentralizedControlManagement_SCCM_.ViewModel; using System; using System.Collections.Generic; using System.Data; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows; using System.Windows.Controls; using System.Windows.Data; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Navigation; using System.Windows.Shapes; using System.Windows.Threading; using System.Xml.Linq; using TouchSocket.Core; using TouchSocket.Sockets; using static System.Windows.Forms.VisualStyles.VisualStyleElement.Rebar; namespace SunlightCentralizedControlManagement_SCCM_.View { /// /// MonitorView.xaml 的交互逻辑 /// public partial class MonitorView : UserControl { public MonitorView() { InitializeComponent(); Griddata.ItemsSource = MainWindowViewModel.Machines.DefaultView; CountDown(); } private string machine; private string workOrder; private string dyelot; private int machines_info=0; 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)//判断鼠标定位是否有效 { machine = (Griddata.Columns[0].GetCellContent(Griddata.Items[rownum]) as TextBlock).Text;//定位第1列, workOrder = (Griddata.Columns[1].GetCellContent(Griddata.Items[rownum]) as TextBlock).Text;//定位第列, dyelot = (Griddata.Columns[2].GetCellContent(Griddata.Items[rownum]) as TextBlock).Text;//定位第列, machin_LOG.Text = Properties.Resources.Machine+":"+machine+" "+Properties.Resources.WorkOrder+":"+workOrder; } } private void Gridstep_SelectionChanged(object sender, SelectionChangedEventArgs e) { Insert.IsEnabled = true; edit.IsEnabled = true; Paused.IsEnabled = true; Resume.IsEnabled = true; } private void ListViewItem_DyeingMachine(object sender, MouseButtonEventArgs e) { machines_info = 0; }//信息 private void ListViewItem_Conveyor(object sender, MouseButtonEventArgs e) { machines_info = 1; }//输送 private void ListViewItem_Receipt(object sender, MouseButtonEventArgs e) { machines_info = 2; }//单据 private void ListViewItem_Resume(object sender, MouseButtonEventArgs e) { if (!string.IsNullOrEmpty(machine)) { Dictionary dat_821 = new Dictionary(); dat_821.Clear(); dat_821.Add("INSTRUCTION", "CONTINUE"); 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()); } Insert.IsEnabled = false; edit.IsEnabled = false; Paused.IsEnabled = false; Resume.IsEnabled = false; }//恢复 private void ListViewItem_Paused(object sender, MouseButtonEventArgs e) { if (!string.IsNullOrEmpty(machine)) { Dictionary dat_821 = new Dictionary(); dat_821.Clear(); dat_821.Add("INSTRUCTION", "PAUSE"); 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_Stop(object sender, MouseButtonEventArgs e) { if (!string.IsNullOrEmpty(machine)) { Dictionary dat_821 = new Dictionary(); dat_821.Clear(); dat_821.Add("INSTRUCTION", "STOP"); 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_edit(object sender, MouseButtonEventArgs e) { }//编辑 private void ListViewItem_Jump(object sender, MouseButtonEventArgs e) { }//跳步 private void ListViewItem_Insert(object sender, MouseButtonEventArgs e) { }//插入 private void ListViewItem_Delete(object sender, MouseButtonEventArgs e) { }//删除 public void CountDown() { DispatcherTimer timer1s = new DispatcherTimer//初始化循环,每1秒调用一次Tick { Interval = TimeSpan.FromSeconds(1)//秒 }; 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)) { try { DataRow drEmployee = MainWindowViewModel.Machines.Select("NAME='" + machine + "'").First(); int State_ = Convert.ToInt16(drEmployee.Field("State")); int index = Convert.ToInt16(drEmployee.Field("ID")); if ((State_ == 101) || (State_ == 201) || (State_ == 202) || (State_ == 309))//获得细节信息 { if (machines_info == 0) { MainWindowViewModel.MachiensTcpClient[index].SendAsync("SC832" + MainWindowViewModel.Selet_Machines(MainWindowViewModel.Machines, "SYSKEY", index)); }//信息 else if (machines_info == 1) { }//输送状态 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; } 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 = TechnologicalProcess.DefaultView; } else { Gridstep.ItemsSource = null; } } else { Gridstep.ItemsSource = null; } } catch (Exception ) { log.Text = null; Gridstep.ItemsSource = null; }//返回错误为空 } } } }