diff --git a/ConvertMoels/BoolRBConvert.cs b/ConvertMoels/BoolRBConvert.cs new file mode 100644 index 0000000..3c91032 --- /dev/null +++ b/ConvertMoels/BoolRBConvert.cs @@ -0,0 +1,32 @@ +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Data; + +namespace SunlightCentralizedControlManagement_SCCM_.ConvertMoels +{ + internal class BoolRBConvert : IValueConverter + { + public object Convert(object value, Type targetType, object parameter, CultureInfo culture) + { + bool G =(Boolean) value; + // bool G = (bool)value; + if (!G)//判断单元格值是否为零 + { + return "";//零返回 + } + else + { + return "red";//非零返回红色 + } + } + + public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) + { + return ""; + } + } +} diff --git a/ConvertMoels/IORBConvert.cs b/ConvertMoels/IORBConvert.cs index 6786d93..247e017 100644 --- a/ConvertMoels/IORBConvert.cs +++ b/ConvertMoels/IORBConvert.cs @@ -6,7 +6,7 @@ using System.Text; using System.Threading.Tasks; using System.Windows.Data; -namespace DyeingComputer.ConvertMoels +namespace SunlightCentralizedControlManagement_SCCM_.ConvertMoels { internal class IORBConvert : IValueConverter { diff --git a/MainWindow.xaml b/MainWindow.xaml index 844fecf..3f6cf9f 100644 --- a/MainWindow.xaml +++ b/MainWindow.xaml @@ -91,7 +91,7 @@ - + diff --git a/MainWindow.xaml.cs b/MainWindow.xaml.cs index 781e5a3..22a8b53 100644 --- a/MainWindow.xaml.cs +++ b/MainWindow.xaml.cs @@ -86,6 +86,10 @@ namespace SunlightCentralizedControlManagement_SCCM_ { Picture.Content = new View.MonitorView(); } + private void ListViewItem_Machine(object sender, MouseButtonEventArgs e) + { + Picture.Content = new View.MachinesView(); + } private void ListViewItem_Curve(object sender, MouseButtonEventArgs e) { Picture.Content = new View.CurveView(); diff --git a/SunlightCentralizedControlManagement_SCCM_.csproj b/SunlightCentralizedControlManagement_SCCM_.csproj index 71ea356..65ec867 100644 --- a/SunlightCentralizedControlManagement_SCCM_.csproj +++ b/SunlightCentralizedControlManagement_SCCM_.csproj @@ -77,6 +77,7 @@ MSBuild:Compile Designer + @@ -103,6 +104,9 @@ CurveDiagram.xaml + + MachinesView.xaml + SYSSetView.xaml @@ -164,6 +168,10 @@ Designer MSBuild:Compile + + MSBuild:Compile + Designer + MSBuild:Compile Designer diff --git a/UserClass/AsyncTcpClient.cs b/UserClass/AsyncTcpClient.cs index 09dc783..9c3ab64 100644 --- a/UserClass/AsyncTcpClient.cs +++ b/UserClass/AsyncTcpClient.cs @@ -171,8 +171,20 @@ namespace SunlightCentralizedControlManagement_SCCM_.UserClass else if (SYSAPI == "SC851") { DAT = DAT.Substring(DAT.IndexOf("]") + 1); - DataTable obj = JsonConvert.DeserializeObject(DAT);//反序列化 + MainWindowViewModel.dt_d = JsonConvert.DeserializeObject(DAT);//反序列化 }//数字开关表 + else if (SYSAPI == "SC852") + { + DAT = DAT.Substring(DAT.IndexOf("]") + 1); + MainWindowViewModel.dt_a = JsonConvert.DeserializeObject(DAT);//反序列化 + }//寄存器表 + else if (SYSAPI == "SC853") + { + DAT = DAT.Substring(DAT.IndexOf("]") + 1); + MainWindowViewModel.dt_m = JsonConvert.DeserializeObject(DAT);//反序列化 + }//缓存表 + + return EasyTask.CompletedTask; }; diff --git a/View/MachinesView.xaml b/View/MachinesView.xaml new file mode 100644 index 0000000..c74de68 --- /dev/null +++ b/View/MachinesView.xaml @@ -0,0 +1,295 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/View/MachinesView.xaml.cs b/View/MachinesView.xaml.cs new file mode 100644 index 0000000..cc04c1f --- /dev/null +++ b/View/MachinesView.xaml.cs @@ -0,0 +1,169 @@ +using SkiaSharp; +using SunlightCentralizedControlManagement_SCCM_.UserClass; +using SunlightCentralizedControlManagement_SCCM_.ViewModel; +using System; +using System.Collections; +using System.Collections.Generic; +using System.Data; +using System.Linq; +using System.Net; +using System.Net.NetworkInformation; +using System.Net.Sockets; +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 static SunlightCentralizedControlManagement_SCCM_.UserClass.SqliteHelper; + +namespace SunlightCentralizedControlManagement_SCCM_.View +{ + /// + /// MachinesSet.xaml 的交互逻辑 + /// + public partial class MachinesView : UserControl + { + public MachinesView() + { + InitializeComponent(); + CountDown(); + } + + private SQLiteHelper SQLiteHelpers = null; //定义数据库 + private readonly string DBAddress = Environment.CurrentDirectory + "\\DataBase\\SCCM.db"; //数据库路径 + private readonly UserClass.IniFile.IniFiles Configini = new UserClass.IniFile.IniFiles(Convert.ToString(System.AppDomain.CurrentDomain.BaseDirectory) + "SCCM.ini"); + private string SYS_machines = null; + private void UserControl_Loaded(object sender, RoutedEventArgs e) + { + Griddata.ItemsSource = MainWindowViewModel.Machines.DefaultView; + } + string machine; + private void Griddata_MouseDoubleClick(object sender, MouseButtonEventArgs e) + { + int rownum = Griddata.SelectedIndex;//获取鼠标选中行并定义变量 + if (rownum != -1)//判断鼠标定位是否有效 + { + machine = (Griddata.Columns[1].GetCellContent(Griddata.Items[rownum]) as TextBlock).Text;//定位第1列, + } + } + + private void ListViewItem_MouseLeftButtonUp(object sender, MouseButtonEventArgs e) + { + + } + private void Grid_D_SelectionChanged(object sender, SelectionChangedEventArgs e) + { + + } + + private void Grid_A_SelectionChanged(object sender, SelectionChangedEventArgs e) + { + + } + + private void Grid_M_SelectionChanged(object sender, SelectionChangedEventArgs e) + { + + } + + + private void Grid_D_CellEditEnding(object sender, DataGridCellEditEndingEventArgs e) + { + string ID; + string newValue = (e.EditingElement as TextBox).Text;//获得输入单元格信息 + + int rownum = Grid_D.SelectedIndex;//获取鼠标选中行并定义变量 + if (rownum != -1)//判断鼠标定位是否有效 + { + ID = (Grid_D.Columns[0].GetCellContent(Grid_D.Items[rownum]) as TextBlock).Text;//定位第0列, + + Dictionary datagrid_v = new Dictionary();//缓存函数 + datagrid_v.Add("PLC", newValue); + SQLiteHelpers = new SQLiteHelper(DBAddress); //数据库连接路径 + SQLiteHelpers.Open(); //打开数据库 + SQLiteHelpers.Update("IOName", datagrid_v, "ID ='" + ID + "'", null);//更新 + SQLiteHelpers.Close();//关闭数据库 + } + IO_data();//重新获得io表 + MainWindowViewModel.D_view = true; + } + + private void Grid_D_BeginningEdit(object sender, DataGridBeginningEditEventArgs e) + { + MainWindowViewModel.D_view = false; + } + + private void Grid_A_CellEditEnding(object sender, DataGridCellEditEndingEventArgs e) + { + string ID; + string newValue = (e.EditingElement as TextBox).Text;//获得输入单元格信息 + + int rownum = Grid_A.SelectedIndex;//获取鼠标选中行并定义变量 + if (rownum != -1)//判断鼠标定位是否有效 + { + ID = (Grid_A.Columns[0].GetCellContent(Grid_A.Items[rownum]) as TextBlock).Text;//定位第0列, + + Dictionary datagrid_v = new Dictionary();//缓存函数 + datagrid_v.Add("PLC", newValue); + SQLiteHelpers = new SQLiteHelper(DBAddress); //数据库连接路径 + SQLiteHelpers.Open(); //打开数据库 + SQLiteHelpers.Update("IOName", datagrid_v, "ID ='" + ID + "'", null);//更新 + SQLiteHelpers.Close();//关闭数据库 + } + IO_data();//重新获得io表 + MainWindowViewModel.A_view = true; + } + + private void Grid_A_BeginningEdit(object sender, DataGridBeginningEditEventArgs e) + { + MainWindowViewModel.A_view = false; + } + + private void IO_data() + { + if (!string.IsNullOrEmpty(machine)) + { + 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))//获得细节信息 + { + MainWindowViewModel.stringQueue.Enqueue(new MainWindowViewModel.QueueString + { + ID = index, + DAT = "SC851" + MainWindowViewModel.Selet_Machines(MainWindowViewModel.Machines, "SYSKEY", index) + }); + MainWindowViewModel.stringQueue.Enqueue(new MainWindowViewModel.QueueString + { + ID = index, + DAT = "SC852" + MainWindowViewModel.Selet_Machines(MainWindowViewModel.Machines, "SYSKEY", index) + }); + MainWindowViewModel.stringQueue.Enqueue(new MainWindowViewModel.QueueString + { + ID = index, + DAT = "SC853" + MainWindowViewModel.Selet_Machines(MainWindowViewModel.Machines, "SYSKEY", index) + }); + } + } + } + + public void CountDown() + { + DispatcherTimer timer1s = new DispatcherTimer//初始化循环,每1秒调用一次Tick + { + Interval = TimeSpan.FromSeconds(1.5)//秒 + }; + timer1s.Tick += Tick_Event_1S; + timer1s.Start(); + }//时间周期初始化 + void Tick_Event_1S(object sender, EventArgs e)//Tick_Event周期执行事件1S + { IO_data(); } + } +} diff --git a/View/MonitorView.xaml b/View/MonitorView.xaml index b9adf16..6658421 100644 --- a/View/MonitorView.xaml +++ b/View/MonitorView.xaml @@ -23,9 +23,8 @@ diff --git a/ViewModel/MainWindowViewModel.cs b/ViewModel/MainWindowViewModel.cs index 25e4bc1..80444f0 100644 --- a/ViewModel/MainWindowViewModel.cs +++ b/ViewModel/MainWindowViewModel.cs @@ -97,7 +97,7 @@ namespace SunlightCentralizedControlManagement_SCCM_.ViewModel DispatcherTimer dis50ms = new DispatcherTimer { - Interval = TimeSpan.FromMilliseconds(50) //毫秒 + Interval = TimeSpan.FromMilliseconds(100) //毫秒 }; dis50ms.Tick += new EventHandler(DisTimer_50MS);//每一秒执行的方法 dis50ms.Start();//计时开始 @@ -276,10 +276,37 @@ namespace SunlightCentralizedControlManagement_SCCM_.ViewModel public static DataTable dt_TM = new DataTable(); public static DataTable dt_TP = new DataTable(); public static bool TechnologicalProcess_bool =true; + public static bool A_view =true; + public static bool D_view =true; + public static bool IO_view; private async void DATA_view()//IO显示 { await Task.Run(() => { + try + { + if (dt_m.Rows.Count > 0) + { + SYSData_M = ToObservableCollection(dt_m); + } + } + catch (Exception ) { } + try + { + if (dt_a.Rows.Count > 0) + { + if ((bool)A_view) SYSData_A = ToObservableCollection(dt_a); + } + } + catch (Exception ) { } + try + { + if (dt_d.Rows.Count > 0) + { + if ((bool)D_view) SYSData_D = ToObservableCollection(dt_d); + } + } + catch (Exception) { } try { TechnologicalMachine_View = ToObservableCollection(Machines);