|
- 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 Id)
- {
- OxyModel.Series.Clear();
- OxyDataModels.Clear();
- OxyModel = new PlotModel() { Title = RecipeCharts.FirstOrDefault(r=>r.Id==Id).Name };
- 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("反应釜编码器值")));
- OxyDataModels.Add(new OxyDataModel(CreateLine("比例阀实际开度")));
- OxyDataModels.Add(new OxyDataModel(CreateLine("卤水配制罐重量")));
- OxyDataModels.Add(new OxyDataModel(CreateLine("反应釜压力")));
- SqliteOperate.GetInstance.QueryableById(Id).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.ReactEncoderValue));
- OxyDataModels[8].dataPoints.Add(new DataPoint(x, item.ProportionalValveOpening));
- OxyDataModels[9].dataPoints.Add(new DataPoint(x, item.BrineTankWeight));
- OxyDataModels[10].dataPoints.Add(new DataPoint(x, item.ReactPressure));
-
- });
- 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压力/MPa\r\n流量/m³\r\n重量/Kg\r\n开度/%\r\n开度/%RH",
- 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;
- var color= scb.ToOxyColor();
- return new LineSeries()
- {
- LineStyle = LineStyle.Solid,
- Title = title,
- MarkerFill = scb.ToOxyColor(),
- MarkerSize = 2,
- LineLegendPosition = LineLegendPosition.End,
- Color=color,
- };
- }
-
- 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,
- Id=item.Id,
- });
- });
- }
-
- 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[11];
-
- 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;
- }
- }
- }
|