diff --git a/Properties/Resources.zh-TW.resx b/Properties/Resources.zh-TW.resx index 29ed59e..542211c 100644 --- a/Properties/Resources.zh-TW.resx +++ b/Properties/Resources.zh-TW.resx @@ -1078,6 +1078,6 @@ 輸送異常 - + 手/自動 \ No newline at end of file diff --git a/UserControls/info.xaml b/UserControls/info.xaml index 462aafe..826e26d 100644 --- a/UserControls/info.xaml +++ b/UserControls/info.xaml @@ -6,7 +6,7 @@ xmlns:local="clr-namespace:SunlightCentralizedControlManagement_SCCM_.UserControls" xmlns:lang="clr-namespace:SunlightCentralizedControlManagement_SCCM_.Properties" xmlns:lvc="clr-namespace:LiveChartsCore.SkiaSharpView.WPF;assembly=LiveChartsCore.SkiaSharpView.WPF" - mc:Ignorable="d" + mc:Ignorable="d" Loaded="UserControl_Loaded" d:DesignHeight="400" d:DesignWidth="300" Background="White"> @@ -22,7 +22,7 @@ - diff --git a/UserControls/info.xaml.cs b/UserControls/info.xaml.cs index 183d7fe..8f9fbbd 100644 --- a/UserControls/info.xaml.cs +++ b/UserControls/info.xaml.cs @@ -4,13 +4,16 @@ using LiveChartsCore.Kernel.Sketches; using LiveChartsCore.SkiaSharpView; using LiveChartsCore.SkiaSharpView.Painting; using Newtonsoft.Json.Linq; +using ScottPlot; using ScottPlot.Plottables; +using ScottPlot.Statistics; using SkiaSharp; using SunlightCentralizedControlManagement_SCCM_.ViewModel; using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.ComponentModel; +using System.Data.Entity.Core.Common.CommandTrees.ExpressionBuilder; using System.Linq; using System.Runtime.Serialization; using System.Text; @@ -33,23 +36,36 @@ namespace SunlightCentralizedControlManagement_SCCM_.UserControls /// /// info.xaml 的交互逻辑 /// - public partial class info : UserControl + public partial class info : UserControl, INotifyPropertyChanged { - public info() + public event PropertyChangedEventHandler PropertyChanged; + protected virtual void OnPropertyChanged(string propertyName) { - InitializeComponent(); - DataContext = this; //new infoModel(); + if (PropertyChanged != null) + PropertyChanged(this, new PropertyChangedEventArgs(propertyName)); } - - public void DataAdd() + public void RaisePropertyChanged(string propertyName) { + if (PropertyChanged != null) + { + if (propertyName != null) + { + PropertyChanged.Invoke(this, new PropertyChangedEventArgs(propertyName)); + } + } } - private readonly Random _random = new Random(); - private readonly List _values = new List(); - private readonly DateTimeAxis _customAxis; - public ObservableCollection Series { get; set; } - public static ObservableCollection ObservableValues { get; set; } + private ObservableCollection MTH_values = new ObservableCollection(); + public ObservableCollection _series { get; set; } + public ObservableCollection Series + { + get => _series; + set + { + _series = value; + OnPropertyChanged(nameof(Series)); + } + } //x轴时间格式 public Axis[] XAxes { get; set; } = { @@ -83,30 +99,50 @@ namespace SunlightCentralizedControlManagement_SCCM_.UserControls }; - private static ObservableCollection MTH_values; - private void UserControl_Loaded(object sender, RoutedEventArgs e) + public info() { - var MTH_items = new List(); - MTH_values = new ObservableCollection(MTH_items); + InitializeComponent(); + DataContext = this; + } - Series = new ObservableCollection - { - new LineSeries - { - Name = Properties.Resources.Temperature, - Values = MTH_values, - Stroke = new SolidColorPaint(s_red, 2), - GeometrySize = 0, - GeometryStroke = new SolidColorPaint(s_red, 2), - Fill = null, - LineSmoothness = 0, - ScalesYAt = 2, - } - }; + public void DataAdd(double dat) + { + DateTime dateTime = DateTime.Now; + Dispatcher.Invoke(() => + { + // 添加新数据点 + MTH_values.Add(new DateTimePoint(dateTime, dat)); + // 更新X轴范围,始终保持最近6小时 + XAxes[0].MinLimit = dateTime.AddHours(-6).Ticks; + XAxes[0].MaxLimit = dateTime.AddMinutes(1).Ticks; + // 移除6小时前的旧数据 + while (MTH_values.Count > 0 && + MTH_values[0].DateTime < dateTime.AddHours(-6)) + { + MTH_values.RemoveAt(0); + } + }); + } - + private void UserControl_Loaded(object sender, RoutedEventArgs e) + { + // 初始化系列 + Series = new ObservableCollection + { + new LineSeries + { + Name = Properties.Resources.Temperature, + Values = MTH_values, + Stroke = new SolidColorPaint(s_red, 2), + GeometrySize = 0, + GeometryStroke = new SolidColorPaint(s_red, 2), + Fill = null, + LineSmoothness = 0, + ScalesYAt = 0, + } + }; } - } + } } diff --git a/View/Whole.xaml.cs b/View/Whole.xaml.cs index a0eafa8..aa27e21 100644 --- a/View/Whole.xaml.cs +++ b/View/Whole.xaml.cs @@ -86,16 +86,18 @@ namespace SunlightCentralizedControlManagement_SCCM_.View } } + int t30S = 0; private void CountDown() { DispatcherTimer timer1s = new DispatcherTimer//初始化循环,每1秒调用一次Tick { Interval = TimeSpan.FromSeconds(1)//秒 }; - timer1s.Tick += Tick_Event_1S; + timer1s.Tick += Tick_Event_S; timer1s.Start(); }//时间周期初始化 - void Tick_Event_1S(object sender, EventArgs e)//Tick_Event周期执行事件1S + + void Tick_Event_S(object sender, EventArgs e)//Tick_Event周期执行事件1S { for (int i = 0; i < MainWindowViewModel.Machines.Rows.Count; i++) { @@ -114,7 +116,14 @@ namespace SunlightCentralizedControlManagement_SCCM_.View inf[i].Message.Text = (string)Selet_Machines(MainWindowViewModel.Machines, "Message", i); 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")) + { + t30S = 0; + inf[i].DataAdd((double)Selet_Machines(MainWindowViewModel.Machines, "Temperature", i)); + } + else { t30S++; } + } } } }