终端一体化运控平台
Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.

HistoryChart50LViewModel.cs 8.3 KiB

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