using BPASmartClient.CustomResource.UserControls.MessageShow;
using BPASmartClient.CustomResource.UserControls;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Windows.Controls.Primitives;
using OxyPlot;
using OxyPlot.Axes;
using LiveCharts.Definitions.Charts;
namespace BPASmartClient.Academy.View
{
///
/// HistoryChartView.xaml 的交互逻辑
///
public partial class HistoryChartView : UserControl
{
public HistoryChartView()
{
InitializeComponent();
}
public PlotModel plotModel { get; set; } = new PlotModel();
private void Button_Click(object sender, RoutedEventArgs e)
{
Button button = sender as Button;
int num;
bool suc = int.TryParse(button.CommandParameter.ToString(), out num);
RecipeChart recipeChart = Sqlite.GetInstance.recipeCharts.FirstOrDefault(o => o.Num == num);
switch (button.Content.ToString())
{
case "温度曲线":
plotModel.Series.Clear();
plotModel = new PlotModel() { Title = "温度曲线" };
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 };
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 };
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 };
List twValues = new List();
List tvValues = new List();
List tmValues = new List();
Sqlite.GetInstance.FindList(recipeChart).ForEach(t =>
{
twValues.Add(new DataPoint(DateTimeAxis.ToDouble(t.Date), t.TempWok));
tvValues.Add(new DataPoint(DateTimeAxis.ToDouble(t.Date), t.TempVent));
tmValues.Add(new DataPoint(DateTimeAxis.ToDouble(t.Date), t.TempMaterial));
});
line.Points.AddRange(twValues);
line_1.Points.AddRange(tvValues);
line_2.Points.AddRange(tmValues);
if (!(plotModel.Axes.Count > 0))
{
plotModel.Axes.Add(new DateTimeAxis() { Position = OxyPlot.Axes.AxisPosition.Bottom, Title = "时间", StringFormat = "hh:mm:ss" });
plotModel.Axes.Add(new LinearAxis() { Key = "y1", Title = "温度/℃", Position = OxyPlot.Axes.AxisPosition.Left, LabelFormatter = value => value.ToString() });
}
plotModel.Series.Add(line);
plotModel.Series.Add(line_1);
plotModel.Series.Add(line_2);
plotModel.InvalidatePlot(true);//重新加载曲线
chartView.Model = plotModel;
break;
case "转速曲线":
plotModel.Series.Clear();
plotModel = new PlotModel() { Title = "转速曲线" };
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 };
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 };
List m101 = new List();
List m102 = new List();
Sqlite.GetInstance.FindList(recipeChart).ForEach(t =>
{
m101.Add(new DataPoint(DateTimeAxis.ToDouble(t.Date), t.M101_Speed));
m102.Add(new DataPoint(DateTimeAxis.ToDouble(t.Date), t.M102_Speed));
});
line_3.Points.AddRange(m101);
line_4.Points.AddRange(m102);
if (!(plotModel.Axes.Count > 0))
{
plotModel.Axes.Add(new DateTimeAxis() { Position = OxyPlot.Axes.AxisPosition.Bottom, Title = "时间/s", StringFormat = "hh:mm:ss" });
plotModel.Axes.Add(new LinearAxis() { Key = "y1", Title = "转速/%", Position = OxyPlot.Axes.AxisPosition.Left, LabelFormatter = value => value.ToString() });
}
plotModel.Series.Add(line_3);
plotModel.Series.Add(line_4);
plotModel.InvalidatePlot(true);//重新加载曲线
chartView.Model = plotModel;
break;
case "重量曲线":
plotModel.Series.Clear();
plotModel = new PlotModel() { Title = "冷却水罐重量曲线" };
List ww = new List();
OxyPlot.Series.LineSeries line_5 = new OxyPlot.Series.LineSeries() { Title = "冷却水罐重量", Color = OxyColor.FromRgb(0, 0, 0), LineStyle = LineStyle.Solid, LineLegendPosition = OxyPlot.Series.LineLegendPosition.End };
Sqlite.GetInstance.FindList(recipeChart).ForEach(t =>
{
ww.Add(new DataPoint(DateTimeAxis.ToDouble(t.Date), t.WeightWok));
});
line_5.Points.AddRange(ww);
if (!(plotModel.Axes.Count > 0))
{
plotModel.Axes.Add(new DateTimeAxis() { Position = OxyPlot.Axes.AxisPosition.Bottom, Title = "时间/s", StringFormat = "hh:mm:ss" });
plotModel.Axes.Add(new LinearAxis() { Key = "y1", Title = "冷却水罐重量/g", Position = OxyPlot.Axes.AxisPosition.Left, LabelFormatter = value => value.ToString("f2") });
}
plotModel.Series.Add(line_5);
plotModel.InvalidatePlot(true);//重新加载曲线
chartView.Model = plotModel;
break;
case "开度曲线":
plotModel.Series.Clear();
plotModel = new PlotModel() { Title = "比例阀开度曲线" };
OxyPlot.Series.LineSeries line_open = new OxyPlot.Series.LineSeries() { LineStyle = LineStyle.Solid, Title = "比例阀开度", MarkerSize = 2, LineLegendPosition = OxyPlot.Series.LineLegendPosition.End };
List open = new List();
Sqlite.GetInstance.FindList(recipeChart).ForEach(t =>
{
open.Add(new DataPoint(DateTimeAxis.ToDouble(t.Date), t.OpenValve));
});
line_open.Points.AddRange(open);
if (!(plotModel.Axes.Count > 0))
{
plotModel.Axes.Add(new DateTimeAxis() { Position = OxyPlot.Axes.AxisPosition.Bottom, Title = "时间/s", StringFormat = "hh:mm:ss" });
plotModel.Axes.Add(new LinearAxis() { Key = "y1", Title = "比例阀开度/挡", Position = OxyPlot.Axes.AxisPosition.Left, LabelFormatter = value => value.ToString("f2")});
}
plotModel.Series.Add(line_open);
plotModel.InvalidatePlot(true);//重新加载曲线
chartView.Model = plotModel;
break;
case "压力曲线":
plotModel.Series.Clear();
plotModel = new PlotModel() { Title = "反应釜压力曲线" };
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 };
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 };
List pressure = new List();
List pressure_week = new List();
Sqlite.GetInstance.FindList(recipeChart).ForEach(t =>
{
pressure.Add(new DataPoint(DateTimeAxis.ToDouble(t.Date), t.PressureWok));
pressure_week.Add(new DataPoint(DateTimeAxis.ToDouble(t.Date), t.PressureWok_Week));
});
line_pre.Points.AddRange(pressure);
line_preweek.Points.AddRange(pressure_week);
if (!(plotModel.Axes.Count > 0))
{
plotModel.Axes.Add(new DateTimeAxis() { Position = OxyPlot.Axes.AxisPosition.Bottom, Title = "时间/s", StringFormat = "hh:mm:ss" });
plotModel.Axes.Add(new LinearAxis() { Key = "y1", Title = "反应釜压力/Mpa", Position = OxyPlot.Axes.AxisPosition.Left, LabelFormatter = value => value.ToString("f2") });
}
plotModel.Series.Add(line_pre);
plotModel.Series.Add(line_preweek);
plotModel.InvalidatePlot(true);//重新加载曲线
chartView.Model = plotModel;
break;
default:
break;
}
App.Current.Dispatcher.Invoke(() =>
{
NoticeDemoViewModel.OpenMsg(EnumPromptType.Info, App.MainWindow, "提示", "你点击了温度按钮", 1, 1);
});
}
private void Popup_MouseLeave(object sender, MouseEventArgs e)
{
Popup popup = sender as Popup;
popup.IsOpen = false;
}
}
}