终端一体化运控平台
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.
 
 
 

209 lignes
8.2 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 Id)
  51. {
  52. OxyModel.Series.Clear();
  53. OxyDataModels.Clear();
  54. OxyModel = new PlotModel() { Title = RecipeCharts.FirstOrDefault(r=>r.Id==Id).Name };
  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. OxyDataModels.Add(new OxyDataModel(CreateLine("比例阀实际开度")));
  64. OxyDataModels.Add(new OxyDataModel(CreateLine("卤水配制罐重量")));
  65. SqliteOperate.GetInstance.QueryableById(Id).ForEach(item =>
  66. {
  67. double x = DateTimeAxis.ToDouble(item.Createtime);
  68. OxyDataModels[0].dataPoints.Add(new DataPoint(x, item.Temperature));
  69. OxyDataModels[1].dataPoints.Add(new DataPoint(x, item.SteamPressure));
  70. OxyDataModels[2].dataPoints.Add(new DataPoint(x, item.SteamFlowRate));
  71. OxyDataModels[3].dataPoints.Add(new DataPoint(x, item.CondensateWaterTemperature));
  72. OxyDataModels[4].dataPoints.Add(new DataPoint(x, item.CondensateWaterHumidity));
  73. OxyDataModels[5].dataPoints.Add(new DataPoint(x, item.NegativePressureFlowRate));
  74. OxyDataModels[6].dataPoints.Add(new DataPoint(x, item.WeighingWaterTankWeight));
  75. OxyDataModels[7].dataPoints.Add(new DataPoint(x, item.ReactEncoderValue));
  76. OxyDataModels[8].dataPoints.Add(new DataPoint(x, item.ProportionalValveOpening));
  77. OxyDataModels[9].dataPoints.Add(new DataPoint(x, item.BrineTankWeight));
  78. });
  79. OxyDataModels.ForEach(item => { item.AddRange(); });
  80. if (!(OxyModel.Axes.Count > 0))
  81. {
  82. OxyModel.Axes.Add(new DateTimeAxis()
  83. {
  84. Position = OxyPlot.Axes.AxisPosition.Bottom,
  85. Title = "时间",
  86. StringFormat = "HH:mm:ss",
  87. AxislineColor = OxyColor.FromRgb(84, 164, 227)
  88. });
  89. OxyModel.Axes.Add(new LinearAxis()
  90. {
  91. Key = "y1",
  92. Title = "温度/℃\r\n压力/MPa\r\n流量/m³\r\n重量/Kg\r\n开度/%",
  93. Position = OxyPlot.Axes.AxisPosition.Left,
  94. LabelFormatter = value => value.ToString(),
  95. AxislineColor = OxyColor.Parse("#9C9C9C"),
  96. AxislineStyle = LineStyle.Solid,
  97. AxislineThickness = 1,
  98. });
  99. }
  100. }
  101. private LineSeries CreateLine(string title)
  102. {
  103. var scb = Application.Current.TryFindResource(title) as SolidColorBrush;
  104. var color= scb.ToOxyColor();
  105. return new LineSeries()
  106. {
  107. LineStyle = LineStyle.Solid,
  108. Title = title,
  109. MarkerFill = scb.ToOxyColor(),
  110. MarkerSize = 2,
  111. LineLegendPosition = LineLegendPosition.End,
  112. Color=color,
  113. };
  114. }
  115. private void LoadNames(List<SaveNameData> data)
  116. {
  117. if (data == null) return;
  118. if (data.Count <= 0)
  119. {
  120. MessageNotify.GetInstance.OpenMsg("未查询到有效记录");
  121. return;
  122. }
  123. RecipeCharts.Clear();
  124. data.ForEach(item =>
  125. {
  126. RecipeCharts.Add(new RecipeChart()
  127. {
  128. Num = RecipeCharts.Count + 1,
  129. CreateTime = item.Createtime,
  130. Name = item.ProductNumber,
  131. Id=item.Id,
  132. });
  133. });
  134. }
  135. public List<OxyDataModel> OxyDataModels { get; set; } = new List<OxyDataModel>();
  136. public ObservableCollection<RecipeChart> RecipeCharts { get; set; } = new ObservableCollection<RecipeChart>();
  137. public DateTime SelectTime { get { return _mSelectTime; } set { _mSelectTime = value; OnPropertyChanged(); } }
  138. private DateTime _mSelectTime = DateTime.Now;
  139. public string ProductNum { get { return _mProductNum; } set { _mProductNum = value; OnPropertyChanged(); } }
  140. private string _mProductNum;
  141. public PlotModel OxyModel { get { return _mOxyModel; } set { _mOxyModel = value; OnPropertyChanged(); } }
  142. private PlotModel _mOxyModel = new PlotModel();
  143. public bool[] VisStatus { get { return _mVisStatus; } set { _mVisStatus = value; OnPropertyChanged(); } }
  144. private bool[] _mVisStatus = new bool[10];
  145. public bool IsEnable
  146. {
  147. get { return _mIsEnable; }
  148. set
  149. {
  150. _mIsEnable = value;
  151. LoadingVis = value ? Visibility.Collapsed : Visibility.Visible;
  152. OnPropertyChanged();
  153. }
  154. }
  155. private bool _mIsEnable = true;
  156. public Visibility LoadingVis { get { return _mLoadingVis; } set { _mLoadingVis = value; OnPropertyChanged(); } }
  157. private Visibility _mLoadingVis = Visibility.Collapsed;
  158. public BPARelayCommand Select { get; set; }
  159. public BPARelayCommand FindProductCommand { get; set; }
  160. public BPARelayCommand<string> InspectDataCommand { get; set; }
  161. public BPARelayCommand<string> CheckedCommand { get; set; }
  162. }
  163. public class OxyDataModel
  164. {
  165. public LineSeries Line { get; set; } = new LineSeries();
  166. public List<DataPoint> dataPoints { get; set; } = new List<DataPoint>();
  167. public void AddRange()
  168. {
  169. Line.Points.AddRange(dataPoints);
  170. }
  171. public OxyDataModel(LineSeries line)
  172. {
  173. Line = line;
  174. }
  175. }
  176. }