diff --git a/UserControls/info.xaml.cs b/UserControls/info.xaml.cs index 8f9fbbd..83c7df4 100644 --- a/UserControls/info.xaml.cs +++ b/UserControls/info.xaml.cs @@ -13,6 +13,7 @@ using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.ComponentModel; +using System.Data; using System.Data.Entity.Core.Common.CommandTrees.ExpressionBuilder; using System.Linq; using System.Runtime.Serialization; @@ -105,10 +106,8 @@ namespace SunlightCentralizedControlManagement_SCCM_.UserControls DataContext = this; } - public void DataAdd(double dat) + public void DataAdd(DateTime dateTime, double dat) { - DateTime dateTime = DateTime.Now; - Dispatcher.Invoke(() => { // 添加新数据点 @@ -123,7 +122,24 @@ namespace SunlightCentralizedControlManagement_SCCM_.UserControls MTH_values.RemoveAt(0); } }); - } + } + + public void DataROW(DataRow[] dataRows) + { + DateTime dateTime = DateTime.Now; + foreach (DataRow row in dataRows) + { + // 添加新数据点 + MTH_values.Add(new DateTimePoint((DateTime)row["DateTime"], (double)row["DAT"])); + } + Dispatcher.Invoke(() => + { + // 更新X轴范围,始终保持最近6小时 + XAxes[0].MinLimit = dateTime.AddHours(-6).Ticks; + XAxes[0].MaxLimit = dateTime.AddMinutes(1).Ticks; + + }); + } private void UserControl_Loaded(object sender, RoutedEventArgs e) { diff --git a/View/Whole.xaml.cs b/View/Whole.xaml.cs index aa27e21..b64ebbd 100644 --- a/View/Whole.xaml.cs +++ b/View/Whole.xaml.cs @@ -64,7 +64,12 @@ namespace SunlightCentralizedControlManagement_SCCM_.View WholeView.Children.Add(inf[i]); } - + for (int i = 0; i < MainWindowViewModel.Machines.Rows.Count; i++) + { + DataRow[] rows= MainWindowViewModel.Whole_dat.Select("Machine='" + inf[i].name.Text+"'"); + inf[i].DataROW(rows); + } + CountDown(); } @@ -99,6 +104,7 @@ namespace SunlightCentralizedControlManagement_SCCM_.View void Tick_Event_S(object sender, EventArgs e)//Tick_Event周期执行事件1S { + DateTime dateTime = DateTime.Now; for (int i = 0; i < MainWindowViewModel.Machines.Rows.Count; i++) { string State_ = Selet_Machines(MainWindowViewModel.Machines, "State", i).ToString(); @@ -117,13 +123,20 @@ namespace SunlightCentralizedControlManagement_SCCM_.View inf[i].Orders.Text = (string)Selet_Machines(MainWindowViewModel.Machines, "WorkOrder", i); inf[i].time.Text = (string)Selet_Machines(MainWindowViewModel.Machines, "time", i); - if ((t30S > 30)&&(State_!="800")) + if ((t30S > 10)&&(State_!="800")) { t30S = 0; - inf[i].DataAdd((double)Selet_Machines(MainWindowViewModel.Machines, "Temperature", i)); + inf[i].DataAdd(dateTime,(double)Selet_Machines(MainWindowViewModel.Machines, "Temperature", i)); + + DataRow whole_Dat = MainWindowViewModel.Whole_dat.NewRow(); + whole_Dat["Machine"] = Selet_Machines(MainWindowViewModel.Machines, "NAME", i).ToString(); + whole_Dat["DateTime"] = dateTime; + whole_Dat["DAT"] = (double)Selet_Machines(MainWindowViewModel.Machines, "Temperature", i); + MainWindowViewModel.Whole_dat.Rows.Add(whole_Dat); } - else { t30S++; } - } + + } + t30S++; } } } diff --git a/ViewModel/MainWindowViewModel.cs b/ViewModel/MainWindowViewModel.cs index 22792cf..f058bfa 100644 --- a/ViewModel/MainWindowViewModel.cs +++ b/ViewModel/MainWindowViewModel.cs @@ -81,6 +81,7 @@ namespace SunlightCentralizedControlManagement_SCCM_.ViewModel // public static DataRow MachinesROW; public static DataTable USER_data = new DataTable(); public static DataTable Dyelot_CALL = new DataTable(); + public static DataTable Whole_dat = new DataTable(); public static UserControls.info[] inf = new UserControls.info[999]; //定义总览信息卡 public static int ERR_c = 0;//错误计数器 public static bool[] USER_Capacity { set; get; } = new bool[99]; @@ -106,7 +107,11 @@ namespace SunlightCentralizedControlManagement_SCCM_.ViewModel USER_data = SQLiteHelpers.ExecuteDataSet("select * from USER order by Name desc", null).Tables[0]; Dyelot_CALL = SQLiteHelpers.ExecuteDataSet("select * from Dyelot", null).Tables[0].Clone(); SQLiteHelpers.Close(); - + + Whole_dat.Columns.Add("Machine", Type.GetType("System.String")); + Whole_dat.Columns.Add("DateTime", Type.GetType("System.DateTime")); + Whole_dat.Columns.Add("DAT", Type.GetType("System.Double")); + USERCapacity(App.USER_Purview);//App.USER_Purview); CountDown(); TcpClientNEW();