|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201 |
- using BPASmartClient.Academy._50L;
- using LiveCharts.Definitions.Charts;
- using OxyPlot;
- using OxyPlot.Axes;
- using OxyPlot.Series;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Shapes;
- using System.Diagnostics;
- using ThingsGateway.Foundation.Extension.Generic;
- using static System.Windows.Forms.LinkLabel;
- using System.Windows;
- using System.Windows.Media;
- using OxyPlot.Wpf;
-
- namespace BPASmartClient.Academy.ViewModel
- {
- internal class HistoryChart50LViewModel : NotifyBase
- {
- public HistoryChart50LViewModel()
- {
- LoadNames(SqliteOperate.GetInstance.FindNames(SelectTime));
-
- Select = new BPARelayCommand(() => { LoadNames(SqliteOperate.GetInstance.FindNames(SelectTime)); });
-
- FindProductCommand = new BPARelayCommand(() => { LoadNames(SqliteOperate.GetInstance.FindNames(ProductNum)); });
-
- InspectDataCommand = new BPARelayCommand<string>(s => { OxyInit(s); });
-
- CheckedCommand = new BPARelayCommand<string>(async s =>
- {
- if (int.TryParse(s, out int index))
- {
- if (VisStatus.Length == OxyDataModels.Count && index >= 0 && index < VisStatus.Length)
- {
- IsEnable = false;
-
- await Task.Run(() =>
- {
- sw.Start();
- if (VisStatus[index]) OxyModel.Series.Add(OxyDataModels[index].Line);
- else OxyModel.Series.Remove(OxyDataModels[index].Line);
- OxyModel.InvalidatePlot(true); //重新加载曲线
- IsEnable = true;
- Debug.WriteLine(sw.ElapsedMilliseconds);
- sw.Restart();
- });
-
- }
- }
- });
- }
-
- Stopwatch sw = new Stopwatch();
-
- private void OxyInit(string num)
- {
- OxyModel.Series.Clear();
- OxyDataModels.Clear();
- OxyModel = new PlotModel() { Title = num };
- OxyDataModels.Add(new OxyDataModel(CreateLine("反应釜温度")));
- OxyDataModels.Add(new OxyDataModel(CreateLine("反应釜蒸汽压力")));
- OxyDataModels.Add(new OxyDataModel(CreateLine("反应釜蒸汽流量")));
- OxyDataModels.Add(new OxyDataModel(CreateLine("冷凝水罐温度")));
- OxyDataModels.Add(new OxyDataModel(CreateLine("冷凝水罐湿度")));
- OxyDataModels.Add(new OxyDataModel(CreateLine("负压流量")));
- OxyDataModels.Add(new OxyDataModel(CreateLine("称重水罐重量")));
- OxyDataModels.Add(new OxyDataModel(CreateLine("比例阀实际开度")));
-
- SqliteOperate.GetInstance.QueryableByNum(num).ForEach(item =>
- {
- double x = DateTimeAxis.ToDouble(item.Createtime);
- OxyDataModels[0].dataPoints.Add(new DataPoint(x, item.Temperature));
- OxyDataModels[1].dataPoints.Add(new DataPoint(x, item.SteamPressure));
- OxyDataModels[2].dataPoints.Add(new DataPoint(x, item.SteamFlowRate));
- OxyDataModels[3].dataPoints.Add(new DataPoint(x, item.CondensateWaterTemperature));
- OxyDataModels[4].dataPoints.Add(new DataPoint(x, item.CondensateWaterHumidity));
- OxyDataModels[5].dataPoints.Add(new DataPoint(x, item.NegativePressureFlowRate));
- OxyDataModels[6].dataPoints.Add(new DataPoint(x, item.WeighingWaterTankWeight));
- OxyDataModels[7].dataPoints.Add(new DataPoint(x, item.ProportionalValveOpening));
- });
- OxyDataModels.ForEach(item => { item.AddRange(); });
- if (!(OxyModel.Axes.Count > 0))
- {
- OxyModel.Axes.Add(new DateTimeAxis()
- {
- Position = OxyPlot.Axes.AxisPosition.Bottom,
- Title = "时间",
- StringFormat = "hh:mm:ss",
- AxislineColor = OxyColor.FromRgb(84, 164, 227)
- });
- OxyModel.Axes.Add(new LinearAxis()
- {
- Key = "y1",
- Title = "温度/℃\r\n压力/kap\r\n流量/m³",
- Position = OxyPlot.Axes.AxisPosition.Left,
- LabelFormatter = value => value.ToString(),
- AxislineColor = OxyColor.Parse("#9C9C9C"),
- AxislineStyle = LineStyle.Solid,
- AxislineThickness = 1,
- });
- }
- }
-
- private LineSeries CreateLine(string title)
- {
- var scb = Application.Current.TryFindResource(title) as SolidColorBrush;
- scb.ToOxyColor();
- return new LineSeries()
- {
- LineStyle = LineStyle.Solid,
- Title = title,
- MarkerFill = scb.ToOxyColor(),
- MarkerSize = 2,
- LineLegendPosition = LineLegendPosition.End
- };
- }
-
- private void LoadNames(List<SaveNameData> data)
- {
- if (data == null) return;
- if (data.Count <= 0)
- {
- MessageNotify.GetInstance.OpenMsg("未查询到有效记录");
- return;
- }
- RecipeCharts.Clear();
- data.ForEach(item =>
- {
- RecipeCharts.Add(new RecipeChart()
- {
- Num = RecipeCharts.Count + 1,
- CreateTime = item.Createtime,
- Name = item.ProductNumber
- });
- });
- }
-
- public List<OxyDataModel> OxyDataModels { get; set; } = new List<OxyDataModel>();
-
- public ObservableCollection<RecipeChart> RecipeCharts { get; set; } = new ObservableCollection<RecipeChart>();
-
- public DateTime SelectTime { get { return _mSelectTime; } set { _mSelectTime = value; OnPropertyChanged(); } }
- private DateTime _mSelectTime = DateTime.Now;
-
- public string ProductNum { get { return _mProductNum; } set { _mProductNum = value; OnPropertyChanged(); } }
- private string _mProductNum;
-
- public PlotModel OxyModel { get { return _mOxyModel; } set { _mOxyModel = value; OnPropertyChanged(); } }
- private PlotModel _mOxyModel = new PlotModel();
-
-
- public bool[] VisStatus { get { return _mVisStatus; } set { _mVisStatus = value; OnPropertyChanged(); } }
- private bool[] _mVisStatus = new bool[8];
-
- public bool IsEnable
- {
- get { return _mIsEnable; }
- set
- {
- _mIsEnable = value;
- LoadingVis = value ? Visibility.Collapsed : Visibility.Visible;
- OnPropertyChanged();
- }
- }
- private bool _mIsEnable = true;
-
- public Visibility LoadingVis { get { return _mLoadingVis; } set { _mLoadingVis = value; OnPropertyChanged(); } }
- private Visibility _mLoadingVis = Visibility.Collapsed;
-
-
- public BPARelayCommand Select { get; set; }
-
- public BPARelayCommand FindProductCommand { get; set; }
-
- public BPARelayCommand<string> InspectDataCommand { get; set; }
-
- public BPARelayCommand<string> CheckedCommand { get; set; }
- }
-
-
- public class OxyDataModel
- {
- public LineSeries Line { get; set; } = new LineSeries();
-
- public List<DataPoint> dataPoints { get; set; } = new List<DataPoint>();
-
- public void AddRange()
- {
- Line.Points.AddRange(dataPoints);
- }
-
- public OxyDataModel(LineSeries line)
- {
- Line = line;
- }
- }
- }
|