终端一体化运控平台
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

202 lines
7.6 KiB

  1. using BPASmartClient.Academy._50L;
  2. using LiveCharts.Definitions.Charts;
  3. using OxyPlot;
  4. using OxyPlot.Axes;
  5. using OxyPlot.Series;
  6. using System;
  7. using System.Collections.Generic;
  8. using System.Linq;
  9. using System.Text;
  10. using System.Threading.Tasks;
  11. using System.Windows.Shapes;
  12. using System.Diagnostics;
  13. using ThingsGateway.Foundation.Extension.Generic;
  14. using static System.Windows.Forms.LinkLabel;
  15. using System.Windows;
  16. using System.Windows.Media;
  17. using OxyPlot.Wpf;
  18. namespace BPASmartClient.Academy.ViewModel
  19. {
  20. internal class HistoryChart50LViewModel : NotifyBase
  21. {
  22. public HistoryChart50LViewModel()
  23. {
  24. LoadNames(SqliteOperate.GetInstance.FindNames(SelectTime));
  25. Select = new BPARelayCommand(() => { LoadNames(SqliteOperate.GetInstance.FindNames(SelectTime)); });
  26. FindProductCommand = new BPARelayCommand(() => { LoadNames(SqliteOperate.GetInstance.FindNames(ProductNum)); });
  27. InspectDataCommand = new BPARelayCommand<string>(s => { OxyInit(s); });
  28. CheckedCommand = new BPARelayCommand<string>(async s =>
  29. {
  30. if (int.TryParse(s, out int index))
  31. {
  32. if (VisStatus.Length == OxyDataModels.Count && index >= 0 && index < VisStatus.Length)
  33. {
  34. IsEnable = false;
  35. await Task.Run(() =>
  36. {
  37. sw.Start();
  38. if (VisStatus[index]) OxyModel.Series.Add(OxyDataModels[index].Line);
  39. else OxyModel.Series.Remove(OxyDataModels[index].Line);
  40. OxyModel.InvalidatePlot(true); //重新加载曲线
  41. IsEnable = true;
  42. Debug.WriteLine(sw.ElapsedMilliseconds);
  43. sw.Restart();
  44. });
  45. }
  46. }
  47. });
  48. }
  49. Stopwatch sw = new Stopwatch();
  50. private void OxyInit(string num)
  51. {
  52. OxyModel.Series.Clear();
  53. OxyDataModels.Clear();
  54. OxyModel = new PlotModel() { Title = num };
  55. OxyDataModels.Add(new OxyDataModel(CreateLine("反应釜温度")));
  56. OxyDataModels.Add(new OxyDataModel(CreateLine("反应釜蒸汽压力")));
  57. OxyDataModels.Add(new OxyDataModel(CreateLine("反应釜蒸汽流量")));
  58. OxyDataModels.Add(new OxyDataModel(CreateLine("冷凝水罐温度")));
  59. OxyDataModels.Add(new OxyDataModel(CreateLine("冷凝水罐湿度")));
  60. OxyDataModels.Add(new OxyDataModel(CreateLine("负压流量")));
  61. OxyDataModels.Add(new OxyDataModel(CreateLine("称重水罐重量")));
  62. OxyDataModels.Add(new OxyDataModel(CreateLine("比例阀实际开度")));
  63. SqliteOperate.GetInstance.QueryableByNum(num).ForEach(item =>
  64. {
  65. double x = DateTimeAxis.ToDouble(item.Createtime);
  66. OxyDataModels[0].dataPoints.Add(new DataPoint(x, item.Temperature));
  67. OxyDataModels[1].dataPoints.Add(new DataPoint(x, item.SteamPressure));
  68. OxyDataModels[2].dataPoints.Add(new DataPoint(x, item.SteamFlowRate));
  69. OxyDataModels[3].dataPoints.Add(new DataPoint(x, item.CondensateWaterTemperature));
  70. OxyDataModels[4].dataPoints.Add(new DataPoint(x, item.CondensateWaterHumidity));
  71. OxyDataModels[5].dataPoints.Add(new DataPoint(x, item.NegativePressureFlowRate));
  72. OxyDataModels[6].dataPoints.Add(new DataPoint(x, item.WeighingWaterTankWeight));
  73. OxyDataModels[7].dataPoints.Add(new DataPoint(x, item.ProportionalValveOpening));
  74. });
  75. OxyDataModels.ForEach(item => { item.AddRange(); });
  76. if (!(OxyModel.Axes.Count > 0))
  77. {
  78. OxyModel.Axes.Add(new DateTimeAxis()
  79. {
  80. Position = OxyPlot.Axes.AxisPosition.Bottom,
  81. Title = "时间",
  82. StringFormat = "hh:mm:ss",
  83. AxislineColor = OxyColor.FromRgb(84, 164, 227)
  84. });
  85. OxyModel.Axes.Add(new LinearAxis()
  86. {
  87. Key = "y1",
  88. Title = "温度/℃\r\n压力/kap\r\n流量/m³",
  89. Position = OxyPlot.Axes.AxisPosition.Left,
  90. LabelFormatter = value => value.ToString(),
  91. AxislineColor = OxyColor.Parse("#9C9C9C"),
  92. AxislineStyle = LineStyle.Solid,
  93. AxislineThickness = 1,
  94. });
  95. }
  96. }
  97. private LineSeries CreateLine(string title)
  98. {
  99. var scb = Application.Current.TryFindResource(title) as SolidColorBrush;
  100. scb.ToOxyColor();
  101. return new LineSeries()
  102. {
  103. LineStyle = LineStyle.Solid,
  104. Title = title,
  105. MarkerFill = scb.ToOxyColor(),
  106. MarkerSize = 2,
  107. LineLegendPosition = LineLegendPosition.End
  108. };
  109. }
  110. private void LoadNames(List<SaveNameData> data)
  111. {
  112. if (data == null) return;
  113. if (data.Count <= 0)
  114. {
  115. MessageNotify.GetInstance.OpenMsg("未查询到有效记录");
  116. return;
  117. }
  118. RecipeCharts.Clear();
  119. data.ForEach(item =>
  120. {
  121. RecipeCharts.Add(new RecipeChart()
  122. {
  123. Num = RecipeCharts.Count + 1,
  124. CreateTime = item.Createtime,
  125. Name = item.ProductNumber
  126. });
  127. });
  128. }
  129. public List<OxyDataModel> OxyDataModels { get; set; } = new List<OxyDataModel>();
  130. public ObservableCollection<RecipeChart> RecipeCharts { get; set; } = new ObservableCollection<RecipeChart>();
  131. public DateTime SelectTime { get { return _mSelectTime; } set { _mSelectTime = value; OnPropertyChanged(); } }
  132. private DateTime _mSelectTime = DateTime.Now;
  133. public string ProductNum { get { return _mProductNum; } set { _mProductNum = value; OnPropertyChanged(); } }
  134. private string _mProductNum;
  135. public PlotModel OxyModel { get { return _mOxyModel; } set { _mOxyModel = value; OnPropertyChanged(); } }
  136. private PlotModel _mOxyModel = new PlotModel();
  137. public bool[] VisStatus { get { return _mVisStatus; } set { _mVisStatus = value; OnPropertyChanged(); } }
  138. private bool[] _mVisStatus = new bool[8];
  139. public bool IsEnable
  140. {
  141. get { return _mIsEnable; }
  142. set
  143. {
  144. _mIsEnable = value;
  145. LoadingVis = value ? Visibility.Collapsed : Visibility.Visible;
  146. OnPropertyChanged();
  147. }
  148. }
  149. private bool _mIsEnable = true;
  150. public Visibility LoadingVis { get { return _mLoadingVis; } set { _mLoadingVis = value; OnPropertyChanged(); } }
  151. private Visibility _mLoadingVis = Visibility.Collapsed;
  152. public BPARelayCommand Select { get; set; }
  153. public BPARelayCommand FindProductCommand { get; set; }
  154. public BPARelayCommand<string> InspectDataCommand { get; set; }
  155. public BPARelayCommand<string> CheckedCommand { get; set; }
  156. }
  157. public class OxyDataModel
  158. {
  159. public LineSeries Line { get; set; } = new LineSeries();
  160. public List<DataPoint> dataPoints { get; set; } = new List<DataPoint>();
  161. public void AddRange()
  162. {
  163. Line.Points.AddRange(dataPoints);
  164. }
  165. public OxyDataModel(LineSeries line)
  166. {
  167. Line = line;
  168. }
  169. }
  170. }