终端一体化运控平台
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.
 
 
 

177 rindas
11 KiB

  1. using BPASmartClient.CustomResource.UserControls.MessageShow;
  2. using BPASmartClient.CustomResource.UserControls;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. using System.Windows;
  9. using System.Windows.Controls;
  10. using System.Windows.Data;
  11. using System.Windows.Documents;
  12. using System.Windows.Input;
  13. using System.Windows.Media;
  14. using System.Windows.Media.Imaging;
  15. using System.Windows.Navigation;
  16. using System.Windows.Shapes;
  17. using System.Windows.Controls.Primitives;
  18. using OxyPlot;
  19. using OxyPlot.Axes;
  20. using LiveCharts.Definitions.Charts;
  21. namespace BPASmartClient.Academy.View
  22. {
  23. /// <summary>
  24. /// HistoryChartView.xaml 的交互逻辑
  25. /// </summary>
  26. public partial class HistoryChartView : UserControl
  27. {
  28. public HistoryChartView()
  29. {
  30. InitializeComponent();
  31. }
  32. public PlotModel plotModel { get; set; } = new PlotModel();
  33. private void Button_Click(object sender, RoutedEventArgs e)
  34. {
  35. Button button = sender as Button;
  36. int num;
  37. bool suc = int.TryParse(button.CommandParameter.ToString(), out num);
  38. RecipeChart recipeChart = Sqlite.GetInstance.recipeCharts.FirstOrDefault(o => o.Num == num);
  39. switch (button.Content.ToString())
  40. {
  41. case "温度曲线":
  42. plotModel.Series.Clear();
  43. plotModel = new PlotModel() { Title = "温度曲线" };
  44. OxyPlot.Series.LineSeries line = new OxyPlot.Series.LineSeries() { LineStyle = LineStyle.Solid, Title = "反应釜温度", MarkerFill = OxyColor.FromRgb(110, 79, 79), MarkerSize = 2, LineLegendPosition = OxyPlot.Series.LineLegendPosition.End };
  45. OxyPlot.Series.LineSeries line_1 = new OxyPlot.Series.LineSeries() { LineStyle = LineStyle.Solid, Title = "反应釜排气温度", MarkerFill = OxyColor.FromRgb(110, 79, 79), MarkerSize = 2, LineLegendPosition = OxyPlot.Series.LineLegendPosition.End };
  46. OxyPlot.Series.LineSeries line_2 = new OxyPlot.Series.LineSeries() { LineStyle = LineStyle.Solid, Title = "配料罐温度", MarkerFill = OxyColor.FromRgb(110, 79, 79), MarkerSize = 2, LineLegendPosition = OxyPlot.Series.LineLegendPosition.End };
  47. List<DataPoint> twValues = new List<DataPoint>();
  48. List<DataPoint> tvValues = new List<DataPoint>();
  49. List<DataPoint> tmValues = new List<DataPoint>();
  50. Sqlite.GetInstance.FindList(recipeChart).ForEach(t =>
  51. {
  52. twValues.Add(new DataPoint(DateTimeAxis.ToDouble(t.Date), t.TempWok));
  53. tvValues.Add(new DataPoint(DateTimeAxis.ToDouble(t.Date), t.TempVent));
  54. tmValues.Add(new DataPoint(DateTimeAxis.ToDouble(t.Date), t.TempMaterial));
  55. });
  56. line.Points.AddRange(twValues);
  57. line_1.Points.AddRange(tvValues);
  58. line_2.Points.AddRange(tmValues);
  59. if (!(plotModel.Axes.Count > 0))
  60. {
  61. plotModel.Axes.Add(new DateTimeAxis() { Position = OxyPlot.Axes.AxisPosition.Bottom, Title = "时间", StringFormat = "hh:mm:ss" });
  62. plotModel.Axes.Add(new LinearAxis() { Key = "y1", Title = "温度/℃", Position = OxyPlot.Axes.AxisPosition.Left, LabelFormatter = value => value.ToString() });
  63. }
  64. plotModel.Series.Add(line);
  65. plotModel.Series.Add(line_1);
  66. plotModel.Series.Add(line_2);
  67. plotModel.InvalidatePlot(true);//重新加载曲线
  68. chartView.Model = plotModel;
  69. break;
  70. case "转速曲线":
  71. plotModel.Series.Clear();
  72. plotModel = new PlotModel() { Title = "转速曲线" };
  73. OxyPlot.Series.LineSeries line_3 = new OxyPlot.Series.LineSeries() { LineStyle = LineStyle.Solid, Title = "反应釜转速", MarkerFill = OxyColor.FromRgb(110, 79, 79), MarkerSize = 2, LineLegendPosition = OxyPlot.Series.LineLegendPosition.End };
  74. OxyPlot.Series.LineSeries line_4 = new OxyPlot.Series.LineSeries() { LineStyle = LineStyle.Solid, Title = "配料罐转速", MarkerFill = OxyColor.FromRgb(110, 79, 79), MarkerSize = 2, LineLegendPosition = OxyPlot.Series.LineLegendPosition.End };
  75. List<DataPoint> m101 = new List<DataPoint>();
  76. List<DataPoint> m102 = new List<DataPoint>();
  77. Sqlite.GetInstance.FindList(recipeChart).ForEach(t =>
  78. {
  79. m101.Add(new DataPoint(DateTimeAxis.ToDouble(t.Date), t.M101_Speed));
  80. m102.Add(new DataPoint(DateTimeAxis.ToDouble(t.Date), t.M102_Speed));
  81. });
  82. line_3.Points.AddRange(m101);
  83. line_4.Points.AddRange(m102);
  84. if (!(plotModel.Axes.Count > 0))
  85. {
  86. plotModel.Axes.Add(new DateTimeAxis() { Position = OxyPlot.Axes.AxisPosition.Bottom, Title = "时间/s", StringFormat = "hh:mm:ss" });
  87. plotModel.Axes.Add(new LinearAxis() { Key = "y1", Title = "转速/%", Position = OxyPlot.Axes.AxisPosition.Left, LabelFormatter = value => value.ToString() });
  88. }
  89. plotModel.Series.Add(line_3);
  90. plotModel.Series.Add(line_4);
  91. plotModel.InvalidatePlot(true);//重新加载曲线
  92. chartView.Model = plotModel;
  93. break;
  94. case "重量曲线":
  95. plotModel.Series.Clear();
  96. plotModel = new PlotModel() { Title = "冷却水罐重量曲线" };
  97. List<DataPoint> ww = new List<DataPoint>();
  98. OxyPlot.Series.LineSeries line_5 = new OxyPlot.Series.LineSeries() { Title = "冷却水罐重量", Color = OxyColor.FromRgb(0, 0, 0), LineStyle = LineStyle.Solid, LineLegendPosition = OxyPlot.Series.LineLegendPosition.End };
  99. Sqlite.GetInstance.FindList(recipeChart).ForEach(t =>
  100. {
  101. ww.Add(new DataPoint(DateTimeAxis.ToDouble(t.Date), t.WeightWok));
  102. });
  103. line_5.Points.AddRange(ww);
  104. if (!(plotModel.Axes.Count > 0))
  105. {
  106. plotModel.Axes.Add(new DateTimeAxis() { Position = OxyPlot.Axes.AxisPosition.Bottom, Title = "时间/s", StringFormat = "hh:mm:ss" });
  107. plotModel.Axes.Add(new LinearAxis() { Key = "y1", Title = "冷却水罐重量/g", Position = OxyPlot.Axes.AxisPosition.Left, LabelFormatter = value => value.ToString("f2") });
  108. }
  109. plotModel.Series.Add(line_5);
  110. plotModel.InvalidatePlot(true);//重新加载曲线
  111. chartView.Model = plotModel;
  112. break;
  113. case "开度曲线":
  114. plotModel.Series.Clear();
  115. plotModel = new PlotModel() { Title = "比例阀开度曲线" };
  116. OxyPlot.Series.LineSeries line_open = new OxyPlot.Series.LineSeries() { LineStyle = LineStyle.Solid, Title = "比例阀开度", MarkerSize = 2, LineLegendPosition = OxyPlot.Series.LineLegendPosition.End };
  117. List<DataPoint> open = new List<DataPoint>();
  118. Sqlite.GetInstance.FindList(recipeChart).ForEach(t =>
  119. {
  120. open.Add(new DataPoint(DateTimeAxis.ToDouble(t.Date), t.OpenValve));
  121. });
  122. line_open.Points.AddRange(open);
  123. if (!(plotModel.Axes.Count > 0))
  124. {
  125. plotModel.Axes.Add(new DateTimeAxis() { Position = OxyPlot.Axes.AxisPosition.Bottom, Title = "时间/s", StringFormat = "hh:mm:ss" });
  126. plotModel.Axes.Add(new LinearAxis() { Key = "y1", Title = "比例阀开度/挡", Position = OxyPlot.Axes.AxisPosition.Left, LabelFormatter = value => value.ToString("f2")});
  127. }
  128. plotModel.Series.Add(line_open);
  129. plotModel.InvalidatePlot(true);//重新加载曲线
  130. chartView.Model = plotModel;
  131. break;
  132. case "压力曲线":
  133. plotModel.Series.Clear();
  134. plotModel = new PlotModel() { Title = "反应釜压力曲线" };
  135. OxyPlot.Series.LineSeries line_pre = new OxyPlot.Series.LineSeries() { LineStyle = LineStyle.Solid, Title = "反应釜压力", MarkerFill = OxyColor.FromRgb(110, 79, 79), MarkerSize = 2, LineLegendPosition = OxyPlot.Series.LineLegendPosition.End };
  136. OxyPlot.Series.LineSeries line_preweek = new OxyPlot.Series.LineSeries() { LineStyle = LineStyle.Solid, Title = "反应釜蒸汽压力", MarkerFill = OxyColor.FromRgb(110, 79, 79), MarkerSize = 2, LineLegendPosition = OxyPlot.Series.LineLegendPosition.End };
  137. List<DataPoint> pressure = new List<DataPoint>();
  138. List<DataPoint> pressure_week = new List<DataPoint>();
  139. Sqlite.GetInstance.FindList(recipeChart).ForEach(t =>
  140. {
  141. pressure.Add(new DataPoint(DateTimeAxis.ToDouble(t.Date), t.PressureWok));
  142. pressure_week.Add(new DataPoint(DateTimeAxis.ToDouble(t.Date), t.PressureWok_Week));
  143. });
  144. line_pre.Points.AddRange(pressure);
  145. line_preweek.Points.AddRange(pressure_week);
  146. if (!(plotModel.Axes.Count > 0))
  147. {
  148. plotModel.Axes.Add(new DateTimeAxis() { Position = OxyPlot.Axes.AxisPosition.Bottom, Title = "时间/s", StringFormat = "hh:mm:ss" });
  149. plotModel.Axes.Add(new LinearAxis() { Key = "y1", Title = "反应釜压力/Mpa", Position = OxyPlot.Axes.AxisPosition.Left, LabelFormatter = value => value.ToString("f2") });
  150. }
  151. plotModel.Series.Add(line_pre);
  152. plotModel.Series.Add(line_preweek);
  153. plotModel.InvalidatePlot(true);//重新加载曲线
  154. chartView.Model = plotModel;
  155. break;
  156. default:
  157. break;
  158. }
  159. App.Current.Dispatcher.Invoke(() =>
  160. {
  161. NoticeDemoViewModel.OpenMsg(EnumPromptType.Info, App.MainWindow, "提示", "你点击了温度按钮", 1, 1);
  162. });
  163. }
  164. private void Popup_MouseLeave(object sender, MouseEventArgs e)
  165. {
  166. Popup popup = sender as Popup;
  167. popup.IsOpen = false;
  168. }
  169. }
  170. }