Browse Source

10L反应釜实时曲线修改

HK研究所反应釜三屏显示
ZhaoGang 1 week ago
parent
commit
cf5ed16f57
7 changed files with 987 additions and 323 deletions
  1. +26
    -1
      BPASmartClient.Academy/ColorResource.xaml
  2. +25
    -0
      BPASmartClient.Academy/Model/Sqlite.cs
  3. +2
    -2
      BPASmartClient.Academy/View/DeviceChart50LView.xaml.cs
  4. +549
    -311
      BPASmartClient.Academy/View/DeviceChartView.xaml
  5. +3
    -2
      BPASmartClient.Academy/View/DeviceChartView.xaml.cs
  6. +4
    -4
      BPASmartClient.Academy/ViewModel/DeviceChart50LViewModel.cs
  7. +378
    -3
      BPASmartClient.Academy/ViewModel/DeviceChartViewModel.cs

+ 26
- 1
BPASmartClient.Academy/ColorResource.xaml View File

@@ -1,4 +1,5 @@
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<!--#region 50L显示色 -->
<SolidColorBrush x:Key="反应釜温度">#ff0000</SolidColorBrush>
<SolidColorBrush x:Key="反应釜蒸汽压力">#90ee90</SolidColorBrush>
<SolidColorBrush x:Key="反应釜蒸汽流量">#00bfff</SolidColorBrush>
@@ -10,7 +11,7 @@
<SolidColorBrush x:Key="比例阀实际开度">#ff00ff</SolidColorBrush>
<SolidColorBrush x:Key="卤水配制罐重量">#0000ff</SolidColorBrush>
<SolidColorBrush x:Key="反应釜压力">#A26189</SolidColorBrush>
<SolidColorBrush x:Key="反应釜温度_参考">#ff0000</SolidColorBrush>
<SolidColorBrush x:Key="反应釜蒸汽压力_参考">#90ee90</SolidColorBrush>
<SolidColorBrush x:Key="反应釜蒸汽流量_参考">#00bfff</SolidColorBrush>
@@ -22,4 +23,28 @@
<SolidColorBrush x:Key="比例阀实际开度_参考">#ff00ff</SolidColorBrush>
<SolidColorBrush x:Key="卤水配制罐重量_参考">#0000ff</SolidColorBrush>
<SolidColorBrush x:Key="反应釜压力_参考">#A26189</SolidColorBrush>
<!--#endregion-->


<!--#region 10L显示色 -->
<SolidColorBrush x:Key="反应釜温度_10L">#ff0000</SolidColorBrush>
<SolidColorBrush x:Key="反应釜排气温度_10L">#ffa500</SolidColorBrush>
<SolidColorBrush x:Key="配料罐温度_10L">#ff00ff</SolidColorBrush>
<SolidColorBrush x:Key="反应釜转速_10L">#7FFF00</SolidColorBrush>
<SolidColorBrush x:Key="配料罐转速_10L">#705FFF</SolidColorBrush>
<SolidColorBrush x:Key="比例阀开度_10L">#ff00ff</SolidColorBrush>
<SolidColorBrush x:Key="反应釜压力_10L">#A26189</SolidColorBrush>
<SolidColorBrush x:Key="反应釜蒸汽压力_10L">#90ee90</SolidColorBrush>
<SolidColorBrush x:Key="冷却水罐重量_10L">#00ffff</SolidColorBrush>

<SolidColorBrush x:Key="反应釜温度_10L_参考">#ff0000</SolidColorBrush>
<SolidColorBrush x:Key="反应釜排气温度_10L_参考">#ffa500</SolidColorBrush>
<SolidColorBrush x:Key="配料罐温度_10L_参考">#ff00ff</SolidColorBrush>
<SolidColorBrush x:Key="反应釜转速_10L_参考">#7FFF00</SolidColorBrush>
<SolidColorBrush x:Key="配料罐转速_10L_参考">#705FFF</SolidColorBrush>
<SolidColorBrush x:Key="比例阀开度_10L_参考">#ff00ff</SolidColorBrush>
<SolidColorBrush x:Key="反应釜压力_10L_参考">#A26189</SolidColorBrush>
<SolidColorBrush x:Key="反应釜蒸汽压力_10L_参考">#90ee90</SolidColorBrush>
<SolidColorBrush x:Key="冷却水罐重量_10L_参考">#00ffff</SolidColorBrush>
<!--#endregion-->
</ResourceDictionary>

+ 25
- 0
BPASmartClient.Academy/Model/Sqlite.cs View File

@@ -133,5 +133,30 @@ namespace BPASmartClient.Academy.Model
.ToList();
}

public List<SaveNameData> FindNames(DateTime dt)
{
try
{
DateTime startOfDay = new DateTime(dt.Year, dt.Month, dt.Day, 0, 0, 0);
DateTime endOfDay = startOfDay.AddDays(1).AddTicks(-1);
return Db.Queryable<SaveNameData>().Where(p => p.Createtime >= startOfDay && p.Createtime < endOfDay).ToList();
}
catch (Exception ex) { return new List<SaveNameData>(); }
}

public List<SaveNameData> FindNames(string name)
{
try
{
if (string.IsNullOrEmpty(name))
{
MessageNotify.GetInstance.OpenMsg("请输入有效的产品编码!", EnumPromptType.Error, "错误");
return new List<SaveNameData>();
}
return Db.Queryable<SaveNameData>().Where(p => p.ProductNumber == name).ToList();
}
catch (Exception ex) { return new List<SaveNameData>(); }
}

}
}

+ 2
- 2
BPASmartClient.Academy/View/DeviceChart50LView.xaml.cs View File

@@ -1,5 +1,5 @@
using LiveCharts.Definitions.Charts;
using LiveCharts.Wpf;
//using LiveCharts.Definitions.Charts;
//using LiveCharts.Wpf;
using OxyPlot.Axes;
using OxyPlot;
using System;


+ 549
- 311
BPASmartClient.Academy/View/DeviceChartView.xaml View File

@@ -6,341 +6,579 @@
xmlns:local="clr-namespace:BPASmartClient.Academy.View"
xmlns:lvc="clr-namespace:LiveCharts.Wpf;assembly=LiveCharts.Wpf"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:oxy="http://oxyplot.org/wpf"
xmlns:vm="clr-namespace:BPASmartClient.Academy.ViewModel"
d:DesignHeight="450"
d:DesignWidth="800"
mc:Ignorable="d">
xmlns:oxy="http://oxyplot.org/wpf" xmlns:vm="clr-namespace:BPASmartClient.Academy.ViewModel"
d:DesignHeight="450" d:DesignWidth="800" mc:Ignorable="d">
<UserControl.DataContext>
<vm:DeviceChartViewModel />
</UserControl.DataContext>
<UserControl.Resources>
<Style x:Key="setCheck" TargetType="{x:Type RadioButton}">
<Setter Property="HorizontalContentAlignment" Value="Center" />
<Setter Property="VerticalContentAlignment" Value="Center" />
<Setter Property="HorizontalAlignment" Value="Center" />
<Setter Property="VerticalAlignment" Value="Center" />
<Setter Property="Background" Value="Transparent" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type RadioButton}">
<Border Background="Transparent" BorderThickness="0">
<ContentControl
x:Name="check"
HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}"
VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}"
Content="{TemplateBinding Content}"
Foreground="#777777" />
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter TargetName="check" Property="Foreground" Value="White" />
</Trigger>
<Trigger Property="IsPressed" Value="True">
<Setter TargetName="check" Property="Foreground" Value="White" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</UserControl.Resources>
<Grid>
<UniformGrid
x:Name="ooo"
Grid.Row="1"
Columns="3"
Rows="2">
<!--#region 温度曲线-->
<StackPanel Orientation="Vertical">
<lvc:CartesianChart
x:Name="ppp"
Height="270"
HorizontalAlignment="Stretch"
VerticalAlignment="Top"
AnimationsSpeed="0:0:1"
DataTooltip="{x:Null}"
Hoverable="False"
MouseDoubleClick="DataView_CLick"
ToolTip="温度曲线">
<lvc:CartesianChart.Series>
<lvc:LineSeries
Fill="Transparent"
LineSmoothness="1"
PointGeometry="{x:Null}"
Stroke="Red"
StrokeThickness="2"
Values="{Binding DataFeedback.TempWok}" />
<lvc:LineSeries
Fill="Transparent"
LineSmoothness="1"
PointGeometry="{x:Null}"
Stroke="Blue"
StrokeThickness="2"
Values="{Binding DataFeedback.TempMaterial}" />
<lvc:LineSeries
Fill="Transparent"
LineSmoothness="1"
PointGeometry="{x:Null}"
Stroke="Green"
StrokeThickness="2"
Values="{Binding DataFeedback.TempVent}" />
</lvc:CartesianChart.Series>
<lvc:CartesianChart.AxisY>
<lvc:Axis MaxValue="200" MinValue="0">
<lvc:Axis.Separator>
<lvc:Separator IsEnabled="False" />
</lvc:Axis.Separator>
</lvc:Axis>
</lvc:CartesianChart.AxisY>
<lvc:CartesianChart.AxisX>
<lvc:Axis LabelFormatter="{Binding DateTimeFormatter}" Unit="{Binding AxisUnit}">
<lvc:Axis.Separator>
<lvc:Separator IsEnabled="False" Step="{Binding AxisStep}" />
</lvc:Axis.Separator>
</lvc:Axis>
</lvc:CartesianChart.AxisX>
</lvc:CartesianChart>
<StackPanel Margin="0,10,0,0" Orientation="Horizontal">
<TextBlock Foreground="White" Text="温度曲线/℃" />
<Rectangle
Width="20"
Height="2"
Margin="10,0,0,2"
Fill="Blue" />
<TextBlock Foreground="White" Text="物料罐温度" />
<Rectangle
Width="20"
Height="2"
Margin="10,0,0,2"
Fill="Red" />
<TextBlock Foreground="White" Text="反应釜温度" />
<Rectangle
Width="20"
Height="2"
Margin="10,0,0,2"
Fill="Green" />
<TextBlock Foreground="White" Text="排气温度" />
</StackPanel>
<ScrollViewer x:Name="ooo" Grid.Row="1">
<StackPanel>
<StackPanel Orientation="Vertical">
<StackPanel
Margin="0,0,60,0" HorizontalAlignment="Right" VerticalAlignment="Center" Orientation="Horizontal">
<TextBlock
VerticalAlignment="Center" FontSize="16" Foreground="DeepSkyBlue" Text="产品编号:" />
<TextBox
Width="200" Height="30" Margin="0,0,10,0" VerticalContentAlignment="Center"
Background="Transparent" BorderBrush="DeepSkyBlue" CaretBrush="DeepSkyBlue" FontSize="16"
Foreground="DeepSkyBlue"
Style="{x:Null}"
Text="{Binding ProductNum}" />

</StackPanel>
<!--#endregion-->
<Button
Width="120" Height="30"
Command="{Binding FindProductCommand}"
Content="查询编号"
Style="{StaticResource ButtonStyle}" />

<!--#region 转速曲线-->
<StackPanel Margin="20,0,0,0" Orientation="Vertical">
<lvc:CartesianChart
Height="270"
HorizontalAlignment="Stretch"
VerticalAlignment="Top"
AnimationsSpeed="0:0:1"
DataTooltip="{x:Null}"
Hoverable="False"
MouseDoubleClick="DataView_CLick"
ToolTip="转速曲线">
<lvc:CartesianChart.Series>
<lvc:LineSeries
Fill="Transparent"
LineSmoothness="1"
PointGeometry="{x:Null}"
Stroke="#F44F15"
StrokeThickness="2"
Values="{Binding DataFeedback.M101_Speed}" />
<lvc:LineSeries
Fill="Transparent"
LineSmoothness="1"
PointGeometry="{x:Null}"
Stroke="#423FFD"
StrokeThickness="2"
Values="{Binding DataFeedback.M102_Speed}" />
</lvc:CartesianChart.Series>
<lvc:CartesianChart.AxisY>
<lvc:Axis MinValue="0" MaxValue="100">
<lvc:Axis.Separator>
<lvc:Separator IsEnabled="False" />
</lvc:Axis.Separator>
</lvc:Axis>
</lvc:CartesianChart.AxisY>
<lvc:CartesianChart.AxisX>
<lvc:Axis LabelFormatter="{Binding DateTimeFormatter}" Unit="{Binding AxisUnit}">
<lvc:Axis.Separator>
<lvc:Separator IsEnabled="False" Step="{Binding AxisStep}" />
</lvc:Axis.Separator>
</lvc:Axis>
</lvc:CartesianChart.AxisX>
</lvc:CartesianChart>
<StackPanel Margin="0,10,0,0" Orientation="Horizontal">
<TextBlock Foreground="White" Text="转速曲线/%" />
<Rectangle
Width="20"
Height="2"
Margin="10,0,0,2"
Fill="#423FFD" />
<TextBlock Foreground="White" Text="物料罐转速" />
<Rectangle
Width="20"
Height="2"
Margin="10,0,0,2"
Fill="#F44F15" />
<TextBlock Foreground="White" Text="反应釜转速" />
</StackPanel>
<TextBlock
Margin="30,0,0,0" VerticalAlignment="Center" FontSize="16" Foreground="DeepSkyBlue"
Text="查询时间:" />
<DatePicker
Width="150" Margin="0,0,10,0" BorderBrush="DeepSkyBlue" FontSize="16"
SelectedDate="{Binding SelectTime}"
Style="{DynamicResource PickerStyle}" />

</StackPanel>
<!--#endregion-->
<Button
Width="120" Height="30"
Command="{Binding Select}"
Content="查询"
Style="{StaticResource ButtonStyle}" />
<Button
Command="{Binding ShowRefrenceWindowCommand}"
Content="打开参照曲线选择"
Style="{StaticResource ButtonStyle}" />
<Button
Command="{Binding HiddenRefrenceWindowCommand}"
Content="关闭参照曲线选择"
Style="{StaticResource ButtonStyle}" />
</StackPanel>
<!--#region 表格-->
<Grid
Grid.Column="0" Margin="20,20,20,0" d:Visibility="Visible" Background="Transparent"
Visibility="{Binding ReferenceWindownVisiblity}">
<Grid.RowDefinitions>
<RowDefinition Height="50" />
<RowDefinition />
</Grid.RowDefinitions>
<!--#region 标题-->
<Grid Background="#ff0C255F">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="50" />
<ColumnDefinition />
<ColumnDefinition Width="400" />
<ColumnDefinition Width="150" />
</Grid.ColumnDefinitions>
<Border
Grid.ColumnSpan="1" BorderBrush="#777777" BorderThickness="0.8" />
<Border
Grid.ColumnSpan="2" BorderBrush="#777777" BorderThickness="0,0.8,0.8,0.8" />
<Border
Grid.ColumnSpan="3" BorderBrush="#777777" BorderThickness="0,0.8,0.8,0.8" />
<Border
Grid.ColumnSpan="4" BorderBrush="#777777" BorderThickness="0,0.8,0.8,0.8" />
<TextBlock
HorizontalAlignment="Center" VerticalAlignment="Center" FontSize="16" Foreground="White"
Text="序号" />
<TextBlock
Grid.Column="1" HorizontalAlignment="Center" VerticalAlignment="Center" FontSize="16"
Foreground="White" Text="配方名称" />
<TextBlock
Grid.Column="2" HorizontalAlignment="Center" VerticalAlignment="Center" FontSize="16"
Foreground="White" Text="创建时间" />
<TextBlock
Grid.Column="3" HorizontalAlignment="Center" VerticalAlignment="Center" FontSize="16"
Foreground="White" Text="操作" />
</Grid>
<!--#endregion-->
<!--#region 表格内容-->
<ScrollViewer
Grid.Row="1" HorizontalScrollBarVisibility="Hidden" VerticalScrollBarVisibility="Hidden">
<ItemsControl ItemsSource="{Binding RecipeCharts}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<Grid>
<Grid
Height="30" Margin="0,1" Background="#163175">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="50" />
<ColumnDefinition />
<ColumnDefinition Width="400" />
<ColumnDefinition Width="150" />
</Grid.ColumnDefinitions>
<Border
Grid.ColumnSpan="1" BorderBrush="#777777" BorderThickness="0.4" />
<Border
Grid.ColumnSpan="2" BorderBrush="#777777" BorderThickness="0,0.4,0.4,0.4" />
<Border
Grid.ColumnSpan="3" BorderBrush="#777777" BorderThickness="0,0.4,0.4,0.4" />
<Border
Grid.ColumnSpan="4" BorderBrush="#777777" BorderThickness="0,0.4,0.4,0.4" />
<TextBlock
x:Name="num" HorizontalAlignment="Center" VerticalAlignment="Center" FontSize="16"
Foreground="White"
Text="{Binding Num}" />
<TextBlock
Grid.Column="1" Margin="5,0,0,0" HorizontalAlignment="Left" VerticalAlignment="Center"
FontSize="16" Foreground="White"
Text="{Binding Name}" />
<TextBlock
Grid.Column="2" HorizontalAlignment="Center" VerticalAlignment="Center" FontSize="16"
Foreground="White"
Text="{Binding CreateTime, StringFormat={}{0:yyyy-MM-dd HH:mm:ss}}" />
<RadioButton
x:Name="ceshi" Grid.Column="3"
Command="{Binding DataContext.InspectDataCommand, RelativeSource={RelativeSource AncestorType={x:Type UserControl}, Mode=FindAncestor}}"
CommandParameter="{Binding Id}"
Content="添加参照" FontSize="16" Foreground="White"
Style="{StaticResource setCheck}" />
</Grid>
</Grid>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</ScrollViewer>
<!--#endregion-->
</Grid>

<!--#region 比例阀开度曲线 -->
<StackPanel Orientation="Vertical">
<lvc:CartesianChart
Height="270"
HorizontalAlignment="Stretch"
VerticalAlignment="Top"
AnimationsSpeed="0:0:1"
DataTooltip="{x:Null}"
Hoverable="False"
MouseDoubleClick="DataView_CLick"
ToolTip="比例阀开度曲线">
<lvc:CartesianChart.Series>
<lvc:LineSeries
Fill="Transparent"
LineSmoothness="1"
PointGeometry="{x:Null}"
Stroke="White"
StrokeThickness="2"
Values="{Binding DataFeedback.OpenValve}" />
</lvc:CartesianChart.Series>
<lvc:CartesianChart.AxisY>
<lvc:Axis MaxValue="100" MinValue="0">
<lvc:Axis.Separator>
<lvc:Separator IsEnabled="False" />
</lvc:Axis.Separator>
</lvc:Axis>
</lvc:CartesianChart.AxisY>
<lvc:CartesianChart.AxisX>
<lvc:Axis LabelFormatter="{Binding DateTimeFormatter}" Unit="{Binding AxisUnit}">
<lvc:Axis.Separator>
<lvc:Separator IsEnabled="False" Step="{Binding AxisStep}" />
</lvc:Axis.Separator>
</lvc:Axis>
</lvc:CartesianChart.AxisX>
</lvc:CartesianChart>
<StackPanel Margin="0,10,0,0" Orientation="Horizontal">
<TextBlock Foreground="White" Text="比例阀开度曲线/%" />
<Rectangle
Width="20"
Height="2"
Margin="20,0,0,2"
Fill="White" />
<TextBlock Foreground="White" Text="比例阀开度" />
<!--#endregion-->
</StackPanel>
<UniformGrid Columns="2" Rows="3">
<!--#region 废弃-->
<!--#region 温度曲线-->
<!--
<StackPanel Orientation="Vertical">
<lvc:CartesianChart
x:Name="ppp" Height="270" HorizontalAlignment="Stretch" VerticalAlignment="Top"
AnimationsSpeed="0:0:1"
DataTooltip="{x:Null}"
Hoverable="False" MouseDoubleClick="DataView_CLick" ToolTip="温度曲线">
<lvc:CartesianChart.Series>
<lvc:LineSeries
Fill="Transparent" LineSmoothness="1"
PointGeometry="{x:Null}"
Stroke="Red" StrokeThickness="2"
Values="{Binding DataFeedback.TempWok}" />
<lvc:LineSeries
Fill="Transparent" LineSmoothness="1"
PointGeometry="{x:Null}"
Stroke="Blue" StrokeThickness="2"
Values="{Binding DataFeedback.TempMaterial}" />
<lvc:LineSeries
Fill="Transparent" LineSmoothness="1"
PointGeometry="{x:Null}"
Stroke="Green" StrokeThickness="2"
Values="{Binding DataFeedback.TempVent}" />
</lvc:CartesianChart.Series>
<lvc:CartesianChart.AxisY>
<lvc:Axis MaxValue="200" MinValue="0">
<lvc:Axis.Separator>
<lvc:Separator IsEnabled="False" />
</lvc:Axis.Separator>
</lvc:Axis>
</lvc:CartesianChart.AxisY>
<lvc:CartesianChart.AxisX>
<lvc:Axis LabelFormatter="{Binding DateTimeFormatter}" Unit="{Binding AxisUnit}">
<lvc:Axis.Separator>
<lvc:Separator IsEnabled="False" Step="{Binding AxisStep}" />
</lvc:Axis.Separator>
</lvc:Axis>
</lvc:CartesianChart.AxisX>
</lvc:CartesianChart>
<StackPanel Margin="0,10,0,0" Orientation="Horizontal">
<TextBlock Foreground="White" Text="温度曲线/℃" />
<Rectangle
Width="20" Height="2" Margin="10,0,0,2" Fill="Blue" />
<TextBlock Foreground="White" Text="物料罐温度" />
<Rectangle
Width="20" Height="2" Margin="10,0,0,2" Fill="Red" />
<TextBlock Foreground="White" Text="反应釜温度" />
<Rectangle
Width="20" Height="2" Margin="10,0,0,2" Fill="Green" />
<TextBlock Foreground="White" Text="排气温度" />
</StackPanel>

</StackPanel>
<!--#endregion-->
</StackPanel>
-->
<!--#endregion-->

<!--#region 压力曲线 -->
<StackPanel Orientation="Vertical">
<lvc:CartesianChart
Height="270"
HorizontalAlignment="Stretch"
VerticalAlignment="Top"
AnimationsSpeed="0:0:1"
DataTooltip="{x:Null}"
Hoverable="False"
MouseDoubleClick="DataView_CLick"
ToolTip="压力曲线">
<lvc:CartesianChart.Series>
<lvc:LineSeries
Fill="Transparent"
LineSmoothness="1"
PointGeometry="{x:Null}"
Stroke="#F1C74B"
StrokeThickness="2"
Values="{Binding DataFeedback.PressureWok}" />
<lvc:LineSeries
Fill="Transparent"
LineSmoothness="1"
PointGeometry="{x:Null}"
Stroke="#FF1FFF"
StrokeThickness="2"
Values="{Binding DataFeedback.PressureWok_Week}" />
</lvc:CartesianChart.Series>
<lvc:CartesianChart.AxisY>
<lvc:Axis
LabelFormatter="{Binding doubleFormatter}"
MaxValue="0.6"
MinValue="-0.1">
<lvc:Axis.Separator>
<lvc:Separator IsEnabled="False" />
</lvc:Axis.Separator>
</lvc:Axis>
</lvc:CartesianChart.AxisY>
<lvc:CartesianChart.AxisX>
<lvc:Axis LabelFormatter="{Binding DateTimeFormatter}" Unit="{Binding AxisUnit}">
<lvc:Axis.Separator>
<lvc:Separator IsEnabled="False" Step="{Binding AxisStep}" />
</lvc:Axis.Separator>
</lvc:Axis>
</lvc:CartesianChart.AxisX>
</lvc:CartesianChart>
<StackPanel Margin="0,10,0,0" Orientation="Horizontal">
<TextBlock Foreground="White" Text="压力曲线/Mpa" />
<Rectangle
Width="20"
Height="2"
Margin="20,0,0,2"
Fill="#F1C74B" />
<TextBlock Foreground="White" Text="反应釜压力" />
<Rectangle
Width="20"
Height="2"
Margin="20,0,0,2"
Fill="#FF1FFF" />
<TextBlock Foreground="White" Text="反应釜蒸汽压力" />
</StackPanel>
<!--#region 转速曲线-->
<!--
<StackPanel Margin="20,0,0,0" Orientation="Vertical">
<lvc:CartesianChart
Height="270" HorizontalAlignment="Stretch" VerticalAlignment="Top" AnimationsSpeed="0:0:1"
DataTooltip="{x:Null}"
Hoverable="False" MouseDoubleClick="DataView_CLick" ToolTip="转速曲线">
<lvc:CartesianChart.Series>
<lvc:LineSeries
Fill="Transparent" LineSmoothness="1"
PointGeometry="{x:Null}"
Stroke="#F44F15" StrokeThickness="2"
Values="{Binding DataFeedback.M101_Speed}" />
<lvc:LineSeries
Fill="Transparent" LineSmoothness="1"
PointGeometry="{x:Null}"
Stroke="#423FFD" StrokeThickness="2"
Values="{Binding DataFeedback.M102_Speed}" />
</lvc:CartesianChart.Series>
<lvc:CartesianChart.AxisY>
<lvc:Axis MaxValue="100" MinValue="0">
<lvc:Axis.Separator>
<lvc:Separator IsEnabled="False" />
</lvc:Axis.Separator>
</lvc:Axis>
</lvc:CartesianChart.AxisY>
<lvc:CartesianChart.AxisX>
<lvc:Axis LabelFormatter="{Binding DateTimeFormatter}" Unit="{Binding AxisUnit}">
<lvc:Axis.Separator>
<lvc:Separator IsEnabled="False" Step="{Binding AxisStep}" />
</lvc:Axis.Separator>
</lvc:Axis>
</lvc:CartesianChart.AxisX>
</lvc:CartesianChart>
<StackPanel Margin="0,10,0,0" Orientation="Horizontal">
<TextBlock Foreground="White" Text="转速曲线/%" />
<Rectangle
Width="20" Height="2" Margin="10,0,0,2" Fill="#423FFD" />
<TextBlock Foreground="White" Text="物料罐转速" />
<Rectangle
Width="20" Height="2" Margin="10,0,0,2" Fill="#F44F15" />
<TextBlock Foreground="White" Text="反应釜转速" />
</StackPanel>

</StackPanel>
<!--#endregion-->
</StackPanel>
-->
<!--#endregion-->

<!--#region 重量曲线 -->
<StackPanel Margin="0,20,0,0" Orientation="Vertical">
<lvc:CartesianChart
Height="270"
HorizontalAlignment="Stretch"
VerticalAlignment="Top"
AnimationsSpeed="0:0:1"
DataTooltip="{x:Null}"
Hoverable="False"
MouseDoubleClick="DataView_CLick"
ToolTip="重量曲线">
<lvc:CartesianChart.Series>
<lvc:LineSeries
Fill="Transparent"
LineSmoothness="1"
PointGeometry="{x:Null}"
Stroke="#fe43fe"
StrokeThickness="2"
Values="{Binding DataFeedback.WeightWok}" />
</lvc:CartesianChart.Series>
<lvc:CartesianChart.AxisY>
<lvc:Axis>
<lvc:Axis.Separator>
<lvc:Separator IsEnabled="False" />
</lvc:Axis.Separator>
</lvc:Axis>
</lvc:CartesianChart.AxisY>
<lvc:CartesianChart.AxisX>
<lvc:Axis LabelFormatter="{Binding DateTimeFormatter}" Unit="{Binding AxisUnit}">
<lvc:Axis.Separator>
<lvc:Separator IsEnabled="False" Step="{Binding AxisStep}" />
</lvc:Axis.Separator>
</lvc:Axis>
</lvc:CartesianChart.AxisX>
</lvc:CartesianChart>
<StackPanel Margin="0,10,0,0" Orientation="Horizontal">
<TextBlock Foreground="White" Text="重量曲线/kg" />
<Rectangle
Width="20"
Height="2"
Margin="20,0,0,2"
Fill="#fe43fe" />
<TextBlock Foreground="White" Text="冷却水罐重量" />
</StackPanel>
<!--#region 比例阀开度曲线-->
<!--
<StackPanel Orientation="Vertical">
<lvc:CartesianChart
Height="270" HorizontalAlignment="Stretch" VerticalAlignment="Top" AnimationsSpeed="0:0:1"
DataTooltip="{x:Null}"
Hoverable="False" MouseDoubleClick="DataView_CLick" ToolTip="比例阀开度曲线">
<lvc:CartesianChart.Series>
<lvc:LineSeries
Fill="Transparent" LineSmoothness="1"
PointGeometry="{x:Null}"
Stroke="White" StrokeThickness="2"
Values="{Binding DataFeedback.OpenValve}" />
</lvc:CartesianChart.Series>
<lvc:CartesianChart.AxisY>
<lvc:Axis MaxValue="100" MinValue="0">
<lvc:Axis.Separator>
<lvc:Separator IsEnabled="False" />
</lvc:Axis.Separator>
</lvc:Axis>
</lvc:CartesianChart.AxisY>
<lvc:CartesianChart.AxisX>
<lvc:Axis LabelFormatter="{Binding DateTimeFormatter}" Unit="{Binding AxisUnit}">
<lvc:Axis.Separator>
<lvc:Separator IsEnabled="False" Step="{Binding AxisStep}" />
</lvc:Axis.Separator>
</lvc:Axis>
</lvc:CartesianChart.AxisX>
</lvc:CartesianChart>
<StackPanel Margin="0,10,0,0" Orientation="Horizontal">
<TextBlock Foreground="White" Text="比例阀开度曲线/%" />
<Rectangle
Width="20" Height="2" Margin="20,0,0,2" Fill="White" />
<TextBlock Foreground="White" Text="比例阀开度" />
</StackPanel>

</StackPanel>
-->
<!--#endregion-->

<!--#region 压力曲线-->
<!--
<StackPanel Orientation="Vertical">
<lvc:CartesianChart
Height="270" HorizontalAlignment="Stretch" VerticalAlignment="Top" AnimationsSpeed="0:0:1"
DataTooltip="{x:Null}"
Hoverable="False" MouseDoubleClick="DataView_CLick" ToolTip="压力曲线">
<lvc:CartesianChart.Series>
<lvc:LineSeries
Fill="Transparent" LineSmoothness="1"
PointGeometry="{x:Null}"
Stroke="#F1C74B" StrokeThickness="2"
Values="{Binding DataFeedback.PressureWok}" />
<lvc:LineSeries
Fill="Transparent" LineSmoothness="1"
PointGeometry="{x:Null}"
Stroke="#FF1FFF" StrokeThickness="2"
Values="{Binding DataFeedback.PressureWok_Week}" />
</lvc:CartesianChart.Series>
<lvc:CartesianChart.AxisY>
<lvc:Axis
LabelFormatter="{Binding doubleFormatter}"
MaxValue="0.6" MinValue="-0.1">
<lvc:Axis.Separator>
<lvc:Separator IsEnabled="False" />
</lvc:Axis.Separator>
</lvc:Axis>
</lvc:CartesianChart.AxisY>
<lvc:CartesianChart.AxisX>
<lvc:Axis LabelFormatter="{Binding DateTimeFormatter}" Unit="{Binding AxisUnit}">
<lvc:Axis.Separator>
<lvc:Separator IsEnabled="False" Step="{Binding AxisStep}" />
</lvc:Axis.Separator>
</lvc:Axis>
</lvc:CartesianChart.AxisX>
</lvc:CartesianChart>
<StackPanel Margin="0,10,0,0" Orientation="Horizontal">
<TextBlock Foreground="White" Text="压力曲线/Mpa" />
<Rectangle
Width="20" Height="2" Margin="20,0,0,2" Fill="#F1C74B" />
<TextBlock Foreground="White" Text="反应釜压力" />
<Rectangle
Width="20" Height="2" Margin="20,0,0,2" Fill="#FF1FFF" />
<TextBlock Foreground="White" Text="反应釜蒸汽压力" />
</StackPanel>

</StackPanel>
-->
<!--#endregion-->

<!--#region 重量曲线-->
<!--
<StackPanel Margin="0,20,0,0" Orientation="Vertical">
<lvc:CartesianChart
Height="270" HorizontalAlignment="Stretch" VerticalAlignment="Top" AnimationsSpeed="0:0:1"
DataTooltip="{x:Null}"
Hoverable="False" MouseDoubleClick="DataView_CLick" ToolTip="重量曲线">
<lvc:CartesianChart.Series>
<lvc:LineSeries
Fill="Transparent" LineSmoothness="1"
PointGeometry="{x:Null}"
Stroke="#fe43fe" StrokeThickness="2"
Values="{Binding DataFeedback.WeightWok}" />
</lvc:CartesianChart.Series>
<lvc:CartesianChart.AxisY>
<lvc:Axis>
<lvc:Axis.Separator>
<lvc:Separator IsEnabled="False" />
</lvc:Axis.Separator>
</lvc:Axis>
</lvc:CartesianChart.AxisY>
<lvc:CartesianChart.AxisX>
<lvc:Axis LabelFormatter="{Binding DateTimeFormatter}" Unit="{Binding AxisUnit}">
<lvc:Axis.Separator>
<lvc:Separator IsEnabled="False" Step="{Binding AxisStep}" />
</lvc:Axis.Separator>
</lvc:Axis>
</lvc:CartesianChart.AxisX>
</lvc:CartesianChart>
<StackPanel Margin="0,10,0,0" Orientation="Horizontal">
<TextBlock Foreground="White" Text="重量曲线/kg" />
<Rectangle
Width="20" Height="2" Margin="20,0,0,2" Fill="#fe43fe" />
<TextBlock Foreground="White" Text="冷却水罐重量" />
</StackPanel>

</StackPanel>
-->
<!--#endregion-->
<!--#endregion-->
<!--#region 新图表OxyPlot-->
<!--#region 温度曲线-->
<StackPanel Margin="20" Orientation="Vertical">
<oxy:PlotView
Height="270" HorizontalAlignment="Stretch" VerticalAlignment="Top"
Model="{Binding PlotModels[0]}"
MouseDoubleClick="DataView_CLick" ToolTip="温度曲线">
</oxy:PlotView>
<StackPanel Margin="0,10,0,0" Orientation="Horizontal">
<TextBlock Foreground="White" Text="温度曲线/℃" />
<Rectangle
Width="20" Height="2" Margin="10,0,0,2"
Fill="{StaticResource 配料罐温度_10L}" />
<TextBlock Foreground="White" Text="配料罐温度" />
<Rectangle
Width="20" Height="2" Margin="10,0,0,2"
Fill="{StaticResource 反应釜温度_10L}" />
<TextBlock Foreground="White" Text="反应釜温度" />
<Rectangle
Width="20" Height="2" Margin="10,0,0,2"
Fill="{StaticResource 反应釜排气温度_10L}" />
<TextBlock Foreground="White" Text="反应釜排气温度" />

<Rectangle
Width="20" Height="2" Margin="10,0,0,2"
Fill="{StaticResource 配料罐温度_10L_参考}" />
<TextBlock Foreground="White" Text="配料罐温度_参考" />
<Rectangle
Width="20" Height="2" Margin="10,0,0,2"
Fill="{StaticResource 反应釜温度_10L_参考}" />
<TextBlock Foreground="White" Text="反应釜温度_参考" />

<Rectangle
Width="20" Height="2" Margin="10,0,0,2"
Fill="{StaticResource 反应釜排气温度_10L_参考}" />
<TextBlock Foreground="White" Text="反应釜排气温度_参考" />
</StackPanel>

</StackPanel>
<!--#endregion-->

<!--#region 转速曲线-->
<StackPanel Margin="20" Orientation="Vertical">
<oxy:PlotView
Height="270" HorizontalAlignment="Stretch" VerticalAlignment="Top"
Model="{Binding PlotModels[1]}"
MouseDoubleClick="DataView_CLick" ToolTip="转速曲线">
</oxy:PlotView>
<StackPanel Margin="0,10,0,0" Orientation="Horizontal">
<TextBlock Foreground="White" Text="转速曲线/%" />
<Rectangle
Width="20" Height="2" Margin="10,0,0,2"
Fill="{StaticResource 配料罐转速_10L}" />
<TextBlock Foreground="White" Text="配料罐转速" />
<Rectangle
Width="20" Height="2" Margin="10,0,0,2"
Fill="{StaticResource 反应釜转速_10L}" />
<TextBlock Foreground="White" Text="反应釜转速" />

<Rectangle
Width="20" Height="2" Margin="10,0,0,2"
Fill="{StaticResource 配料罐转速_10L_参考}" />
<TextBlock Foreground="White" Text="配料罐转速_参考" />
<Rectangle
Width="20" Height="2" Margin="10,0,0,2"
Fill="{StaticResource 反应釜转速_10L_参考}" />
<TextBlock Foreground="White" Text="反应釜转速_参考" />
</StackPanel>

</StackPanel>
<!--#endregion-->

<!--#region 比例阀开度曲线-->
<StackPanel Margin="20" Orientation="Vertical">
<oxy:PlotView
Height="270" HorizontalAlignment="Stretch" VerticalAlignment="Top"
Model="{Binding PlotModels[2]}"
MouseDoubleClick="DataView_CLick" ToolTip="比例阀开度曲线">
</oxy:PlotView>
<StackPanel Margin="0,10,0,0" Orientation="Horizontal">
<TextBlock Foreground="White" Text="比例阀开度曲线/%" />
<Rectangle
Width="20" Height="2" Margin="20,0,0,2"
Fill="{StaticResource 比例阀开度_10L}" />
<TextBlock Foreground="White" Text="比例阀开度" />

<Rectangle
Width="20" Height="2" Margin="20,0,0,2"
Fill="{StaticResource 比例阀开度_10L_参考}" />
<TextBlock Foreground="White" Text="比例阀开度_参考" />
</StackPanel>

</StackPanel>
<!--#endregion-->

<!--#region 压力曲线-->
<StackPanel Margin="20" Orientation="Vertical">
<oxy:PlotView
Height="270" HorizontalAlignment="Stretch" VerticalAlignment="Top"
Model="{Binding PlotModels[3]}"
MouseDoubleClick="DataView_CLick" ToolTip="压力曲线">
</oxy:PlotView>
<StackPanel Margin="0,10,0,0" Orientation="Horizontal">
<TextBlock Foreground="White" Text="压力曲线/Mpa" />
<Rectangle
Width="20" Height="2" Margin="20,0,0,2"
Fill="{StaticResource 反应釜压力_10L}" />
<TextBlock Foreground="White" Text="反应釜压力" />
<Rectangle
Width="20" Height="2" Margin="20,0,0,2"
Fill="{StaticResource 反应釜蒸汽压力_10L}" />
<TextBlock Foreground="White" Text="反应釜蒸汽压力" />

<Rectangle
Width="20" Height="2" Margin="20,0,0,2"
Fill="{StaticResource 反应釜压力_10L_参考}" />
<TextBlock Foreground="White" Text="反应釜压力_参考" />
<Rectangle
Width="20" Height="2" Margin="20,0,0,2"
Fill="{StaticResource 反应釜蒸汽压力_10L_参考}" />
<TextBlock Foreground="White" Text="反应釜蒸汽压力_参考" />
</StackPanel>

</StackPanel>
<!--#endregion-->

<!--#region 重量曲线-->
<StackPanel Margin="20" Orientation="Vertical">
<oxy:PlotView
Height="270" HorizontalAlignment="Stretch" VerticalAlignment="Top"
Model="{Binding PlotModels[4]}"
MouseDoubleClick="DataView_CLick" ToolTip="重量曲线">
</oxy:PlotView>
<StackPanel Margin="0,10,0,0" Orientation="Horizontal">
<TextBlock Foreground="White" Text="重量曲线/kg" />
<Rectangle
Width="20" Height="2" Margin="20,0,0,2"
Fill="{StaticResource 冷却水罐重量_10L}" />
<TextBlock Foreground="White" Text="冷却水罐重量" />

<Rectangle
Width="20" Height="2" Margin="20,0,0,2"
Fill="{StaticResource 冷却水罐重量_10L_参考}" />
<TextBlock Foreground="White" Text="冷却水罐重量_参考" />
</StackPanel>

</StackPanel>
<!--#endregion-->
<!--#endregion-->
</UniformGrid>
</StackPanel>
<!--#endregion-->
</UniformGrid>
<!--#region 总曲线 -->
</ScrollViewer>
<!--#region 总曲线-->
<Grid
x:Name="chartGrid"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
Background="White"
x:Name="chartGrid" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Background="White"
Visibility="Collapsed">
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition Width="200" />
</Grid.ColumnDefinitions>
<oxy:PlotView
x:Name="chartView"
Margin="5"
Background="White"
Foreground="Black"
x:Name="chartView" Margin="5" Background="White" Foreground="Black"
PanCursor="Hand" />
<Button
Grid.Column="1"
Width="120"
Height=" 40"
HorizontalAlignment="Center"
VerticalAlignment="Center"
Click="Button_Click"
Content="退出" />
Grid.Column="1" Width="120" Height=" 40" HorizontalAlignment="Center"
VerticalAlignment="Center" Click="Button_Click" Content="退出" />
</Grid>
<!--#endregion-->
</Grid>


+ 3
- 2
BPASmartClient.Academy/View/DeviceChartView.xaml.cs View File

@@ -17,6 +17,7 @@ using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using ThingsGateway.Foundation.Core;
using OxyPlot.Wpf;

namespace BPASmartClient.Academy.View
{
@@ -38,9 +39,9 @@ namespace BPASmartClient.Academy.View
double min = DateTimeAxis.ToDouble(System.DateTime.Now.AddMinutes(-10));
double max = DateTimeAxis.ToDouble(System.DateTime.Now);
double maxrange = max - min;
CartesianChart liveCharts = sender as CartesianChart;
PlotView charts = sender as PlotView;
switch (liveCharts.ToolTip)
switch (charts.ToolTip)
{
case "温度曲线":
plotModel.Series.Clear();


+ 4
- 4
BPASmartClient.Academy/ViewModel/DeviceChart50LViewModel.cs View File

@@ -29,10 +29,10 @@ namespace BPASmartClient.Academy.ViewModel
public DeviceChart50LViewModel()
{
DataFeedback = new DataFeedBack_50();
var mapper = Mappers.Xy<DataValue>()
.X(model => model.DateTime.Ticks)
.Y(model => model.Value);
Charting.For<DataValue>(mapper);
//var mapper = Mappers.Xy<DataValue>()
// .X(model => model.DateTime.Ticks)
// .Y(model => model.Value);
//Charting.For<DataValue>(mapper);
DataFeedback = SqliteOperate.GetInstance.DataFeedBacks;

InitialOxyChart();


+ 378
- 3
BPASmartClient.Academy/ViewModel/DeviceChartViewModel.cs View File

@@ -2,12 +2,22 @@
using LiveCharts;
using LiveCharts.Configurations;
using LiveCharts.Wpf;

using OxyPlot;
using OxyPlot.Axes;
using OxyPlot.Series;

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Media;
using System.Windows;
using OxyLineSeries = OxyPlot.Series.LineSeries;
using OxyPlot.Wpf;
using BPASmartClient.Academy._50L;

namespace BPASmartClient.Academy.ViewModel
{
@@ -21,18 +31,383 @@ namespace BPASmartClient.Academy.ViewModel
.Y(model => model.Value);
Charting.For<DataValue>(mapper);
DataFeedback = Simens_PLC.GetInstance.dataFeedback;


InitialOxyChart();
LoadNames(Sqlite.GetInstance.FindNames(SelectTime));

Select = new BPARelayCommand(() => { LoadNames(Sqlite.GetInstance.FindNames(SelectTime)); });

FindProductCommand = new BPARelayCommand(() => { LoadNames(Sqlite.GetInstance.FindNames(ProductNum)); });

InspectDataCommand = new BPARelayCommand<string>(s => { OxyInit(s); });


ShowRefrenceWindowCommand = new BPARelayCommand(() => {
ReferenceWindownVisiblity = Visibility.Visible;
});
HiddenRefrenceWindowCommand = new BPARelayCommand(() => {
ReferenceWindownVisiblity = Visibility.Collapsed;
});
_tokenSource = new CancellationTokenSource();
Task.Factory.StartNew(async (o) =>
{
while (!_tokenSource.IsCancellationRequested)
{
#region 实时数据刷新
for (int i = 0; i < PlotModels.Count; i++)
{
for (int j = 0; j < PlotModels[i].Series.Count; j++)
{
((OxyLineSeries)(PlotModels[i].Series[j])).Points.Clear();
}
}
RefreshOxyPlotSeries(0, 0, DataFeedback.TempWok);
RefreshOxyPlotSeries(0, 1, DataFeedback.TempVent);
RefreshOxyPlotSeries(0, 2, DataFeedback.TempMaterial);

RefreshOxyPlotSeries(1, 0, DataFeedback.M101_Speed);
RefreshOxyPlotSeries(1, 1, DataFeedback.M102_Speed);

RefreshOxyPlotSeries(2, 0, DataFeedback.OpenValve);

RefreshOxyPlotSeries(3, 0, DataFeedback.PressureWok);
RefreshOxyPlotSeries(3, 1, DataFeedback.PressureWok_Week);

RefreshOxyPlotSeries(4, 0, DataFeedback.WeightWok);

#endregion
#region 参照数据刷新
if (ReferenceData != null && ReferenceData.TempWok.Count > 0)
{
DateTime startTime = DataFeedback.TempWok.Min(x => x.DateTime);
DateTime endTime = DataFeedback.TempWok.Max(x => x.DateTime).AddSeconds(6);

//PartReferenceData.Temperature.RemoveWhere(x => x.DateTime < startTime);
AxisXMinValue = startTime;
AxisXMaxValue = endTime;

//PartReferenceData.Temperature.RemoveWhere(x => x.DateTime < startTime);
//PartReferenceData.SteamPressure.RemoveWhere(x => x.DateTime < startTime);
//PartReferenceData.SteamFlowRate.RemoveWhere(x => x.DateTime < startTime);
//PartReferenceData.CondensateWaterTemperature.RemoveWhere(x => x.DateTime < startTime);
//PartReferenceData.CondensateWaterHumidity.RemoveWhere(x => x.DateTime < startTime);
//PartReferenceData.NegativePressureFlowRate.RemoveWhere(x => x.DateTime < startTime);
//PartReferenceData.WeighingWaterTankWeight.RemoveWhere(x => x.DateTime < startTime);
//PartReferenceData.ReactEncoderValue.RemoveWhere(x => x.DateTime < startTime);
//PartReferenceData.ProportionalValveOpening.RemoveWhere(x => x.DateTime < startTime);
//PartReferenceData.BrineTankWeight.RemoveWhere(x => x.DateTime < startTime);
//PartReferenceData.ReactPressure.RemoveWhere(x => x.DateTime < startTime);

PartReferenceData.TempWok.Clear();
PartReferenceData.TempVent.Clear();
PartReferenceData.TempMaterial.Clear();
PartReferenceData.M101_Speed.Clear();
PartReferenceData.M102_Speed.Clear();
PartReferenceData.OpenValve.Clear();
PartReferenceData.PressureWok.Clear();
PartReferenceData.PressureWok_Week.Clear();
PartReferenceData.WeightWok.Clear();

if (ReferenceData.TempWok.Max(x => x.DateTime) >= endTime)
{
PartReferenceData.TempWok.AddRange(ReferenceData.TempWok.Where(x => x.DateTime >= startTime && x.DateTime <= endTime));
PartReferenceData.TempVent.AddRange(ReferenceData.TempVent.Where(x => x.DateTime >= startTime && x.DateTime <= endTime));
PartReferenceData.TempMaterial.AddRange(ReferenceData.TempMaterial.Where(x => x.DateTime >= startTime && x.DateTime <= endTime));
PartReferenceData.M101_Speed.AddRange(ReferenceData.M101_Speed.Where(x => x.DateTime >= startTime && x.DateTime <= endTime));
PartReferenceData.M102_Speed.AddRange(ReferenceData.M102_Speed.Where(x => x.DateTime >= startTime && x.DateTime <= endTime));
PartReferenceData.OpenValve.AddRange(ReferenceData.OpenValve.Where(x => x.DateTime >= startTime && x.DateTime <= endTime));
PartReferenceData.PressureWok.AddRange(ReferenceData.PressureWok.Where(x => x.DateTime >= startTime && x.DateTime <= endTime));
PartReferenceData.PressureWok_Week.AddRange(ReferenceData.PressureWok_Week.Where(x => x.DateTime >= startTime && x.DateTime <= endTime));
PartReferenceData.WeightWok.AddRange(ReferenceData.WeightWok.Where(x => x.DateTime >= startTime && x.DateTime <= endTime));
}
RefreshOxyPlotSeries(0, 3, PartReferenceData.TempWok);
RefreshOxyPlotSeries(0, 4, PartReferenceData.TempVent);
RefreshOxyPlotSeries(0, 5, PartReferenceData.TempMaterial);

RefreshOxyPlotSeries(1, 2, PartReferenceData.M101_Speed);
RefreshOxyPlotSeries(1, 3, PartReferenceData.M102_Speed);

RefreshOxyPlotSeries(2, 1, PartReferenceData.OpenValve);

RefreshOxyPlotSeries(3, 2, PartReferenceData.PressureWok);
RefreshOxyPlotSeries(3, 3, PartReferenceData.PressureWok_Week);

RefreshOxyPlotSeries(4, 1, PartReferenceData.WeightWok);
}
#endregion

for (int i = 0; i < PlotModels.Count; i++)
{
PlotModels[i].InvalidatePlot(true);
}
//await Task.Delay(2000);
Thread.Sleep(2000);
}
}, TaskCreationOptions.LongRunning, _tokenSource.Token);
}

~DeviceChartViewModel()
{
_tokenSource.Cancel(false);
}

#region Private Fields
private CancellationTokenSource _tokenSource;
Stopwatch sw = new Stopwatch();
#endregion

#region Properties
private DataFeedback dataFeedback;
public DataFeedback DataFeedback { get { return dataFeedback; } set { dataFeedback = value; OnPropertyChanged(); } }
public Func<double, string> DateTimeFormatter { get; set; } = value => value>0 ? new DateTime((long)value).ToString("HH:mm:ss"):new DateTime((long)DateTime.Now.Ticks).ToString("HH:mm:ss");

private DataFeedback _referenceData;
public DataFeedback ReferenceData { get { return _referenceData; } set { _referenceData = value; OnPropertyChanged(); } }

private DataFeedback _partReferenceData;
public DataFeedback PartReferenceData { get { return _partReferenceData; } set { _partReferenceData = value; OnPropertyChanged(); } }
public DateTime AxisXMinValue { get { return _axisXMinValue; } set { _axisXMinValue = value; OnPropertyChanged(); } }

private DateTime _axisXMinValue;
public DateTime AxisXMaxValue { get { return _axisXMaxValue; } set { _axisXMaxValue = value; OnPropertyChanged(); } }

private DateTime _axisXMaxValue;
public Func<double, string> DateTimeFormatter { get; set; } = value => value > 0 ? new DateTime((long)value).ToString("HH:mm:ss") : new DateTime((long)DateTime.Now.Ticks).ToString("HH:mm:ss");

public Func<double, string> doubleFormatter { get; set; } = value => value.ToString("F2");

private Visibility _referenceWindownVisiblity = Visibility.Collapsed;
public Visibility ReferenceWindownVisiblity { get { return _referenceWindownVisiblity; } set { _referenceWindownVisiblity = value; OnPropertyChanged(); } }

public double AxisStep { get; set; } = TimeSpan.FromSeconds(2).Ticks;
public double AxisUnit { get; set; } = TimeSpan.TicksPerSecond;

public ObservableCollection<PlotModel> PlotModels { get => _plotModels; set { _plotModels = value; OnPropertyChanged(); } }
private ObservableCollection<PlotModel> _plotModels;

public ObservableCollection<RecipeChart> RecipeCharts { get; set; } = new ObservableCollection<RecipeChart>();

public DateTime SelectTime { get { return _mSelectTime; } set { _mSelectTime = value; OnPropertyChanged(); } }
private DateTime _mSelectTime = DateTime.Now;

public string ProductNum { get { return _mProductNum; } set { _mProductNum = value; OnPropertyChanged(); } }
private string _mProductNum;



public Visibility LoadingVis { get { return _mLoadingVis; } set { _mLoadingVis = value; OnPropertyChanged(); } }
private Visibility _mLoadingVis = Visibility.Collapsed;
#endregion


#region Parivate Methods
private void OxyInit(string Id)
{
ReferenceData = new();
PartReferenceData = new();
List<SaveData>? data = Sqlite.GetInstance.SelectId(Id);
DateTime productStartTime = data.Select(x => x.Date).Min();
data.ForEach(item =>
{
var interval = item.Date - productStartTime;
DateTime time = new DateTime(interval.Ticks);
ReferenceData.M101_Speed.Add(new DataValue() { DateTime = time, Value = item.M101_Speed });
ReferenceData.M102_Speed.Add(new DataValue() { DateTime = time, Value = item.M102_Speed });
ReferenceData.OpenValve.Add(new DataValue() { DateTime = time, Value = item.OpenValve });
ReferenceData.TempWok.Add(new DataValue() { DateTime = time, Value = item.TempWok });
ReferenceData.TempMaterial.Add(new DataValue() { DateTime = time, Value = item.TempMaterial });
ReferenceData.TempVent.Add(new DataValue() { DateTime = time, Value = item.TempVent });
ReferenceData.PressureWok.Add(new DataValue() { DateTime = time, Value = item.PressureWok });
ReferenceData.PressureWok_Week.Add(new DataValue() { DateTime = time, Value = item.PressureWok_Week });
ReferenceData.WeightWok.Add(new DataValue() { DateTime = time, Value = item.WeightWok });
});

}

private void RefreshOxyPlotSeries(int plotIndex, int seriesIndex, ChartValues<DataValue> dataValues)
{
if (plotIndex >= 0 && plotIndex <= PlotModels.Count && seriesIndex >= 0 && seriesIndex <= PlotModels[plotIndex].Series.Count && dataValues != null && dataValues.Count > 0)
{
((OxyLineSeries)(PlotModels[plotIndex].Series[seriesIndex])).Points
.AddRange(dataValues.Select(x => new DataPoint(DateTimeAxis.ToDouble(x.DateTime), Math.Round(x.Value, 2))));
}
}
private void LoadNames(List<SaveNameData> data)
{
if (data == null) return;
if (data.Count <= 0)
{
MessageNotify.GetInstance.OpenMsg("未查询到有效记录");
return;
}
RecipeCharts.Clear();
data.ForEach(item =>
{
RecipeCharts.Add(new RecipeChart()
{
Num = RecipeCharts.Count + 1,
CreateTime = item.Createtime,
Name = item.ProductNumber,
Id = item.Id,
});
});
}

private void InitialOxyChart()
{
PlotModels = new();

#region 创建曲线
OxyLineSeries tempWokSeries = CreateLine("反应釜温度");
OxyLineSeries tempVentSeries = CreateLine("反应釜排气温度");
OxyLineSeries tempMaterialSeries = CreateLine("配料罐温度");
OxyLineSeries m101_SpeedSeries = CreateLine("反应釜转速");
OxyLineSeries m102_SpeedSeries = CreateLine("配料罐转速");
OxyLineSeries openValveSeries = CreateLine("比例阀开度");
OxyLineSeries pressureWokSeries = CreateLine("反应釜压力");
OxyLineSeries pressureWok_WeekSeries = CreateLine("反应釜蒸汽压力");
OxyLineSeries weightWokSeries = CreateLine("冷却水罐重量");

OxyLineSeries reftempWokSeries = CreateLine("反应釜温度_参考",LineStyle.Dot);
OxyLineSeries reftempVentSeries = CreateLine("反应釜排气温度_参考",LineStyle.Dot);
OxyLineSeries reftempMaterialSeries = CreateLine("配料罐温度_参考",LineStyle.Dot);
OxyLineSeries refm101_SpeedSeries = CreateLine("反应釜转速_参考",LineStyle.Dot);
OxyLineSeries refm102_SpeedSeries = CreateLine("配料罐转速_参考",LineStyle.Dot);
OxyLineSeries refopenValveSeries = CreateLine("比例阀开度_参考",LineStyle.Dot);
OxyLineSeries refpressureWokSeries = CreateLine("反应釜压力_参考",LineStyle.Dot);
OxyLineSeries refpressureWok_WeekSeries = CreateLine("反应釜蒸汽压力_参考",LineStyle.Dot);
OxyLineSeries refweightWokSeries = CreateLine("冷却水罐重量_参考",LineStyle.Dot);
#endregion

#region 温度曲线
{
PlotModel tempPlotModel = CreatePlotModel("温度/℃", 0, 200);
tempPlotModel.Series.Add(tempWokSeries);
tempPlotModel.Series.Add(tempVentSeries);
tempPlotModel.Series.Add(tempMaterialSeries);

tempPlotModel.Series.Add(reftempWokSeries);
tempPlotModel.Series.Add(reftempVentSeries);
tempPlotModel.Series.Add(reftempMaterialSeries);
PlotModels.Add(tempPlotModel);
}
#endregion
#region 转速曲线
{
PlotModel tempPlotModel = CreatePlotModel("转速/RPM", 0, 100);
tempPlotModel.Series.Add(m101_SpeedSeries);
tempPlotModel.Series.Add(m102_SpeedSeries);

tempPlotModel.Series.Add(refm101_SpeedSeries);
tempPlotModel.Series.Add(refm102_SpeedSeries);
PlotModels.Add(tempPlotModel);
}
#endregion
#region 比例阀开度曲线
{
PlotModel tempPlotModel = CreatePlotModel("比例阀开度/%", 0, 100);
tempPlotModel.Series.Add(openValveSeries);

tempPlotModel.Series.Add(refopenValveSeries);
PlotModels.Add(tempPlotModel);
}
#endregion
#region 压力曲线
{
PlotModel tempPlotModel = CreatePlotModel("压力/MPa", -0.1, 0.6);
tempPlotModel.Series.Add(pressureWokSeries);
tempPlotModel.Series.Add(pressureWok_WeekSeries);

tempPlotModel.Series.Add(refpressureWokSeries);
tempPlotModel.Series.Add(refpressureWok_WeekSeries);
PlotModels.Add(tempPlotModel);
}
#endregion
#region 重量曲线
{
PlotModel tempPlotModel = CreatePlotModel("重量/Kg", 0, 50);
tempPlotModel.Series.Add(weightWokSeries);

tempPlotModel.Series.Add(refweightWokSeries);
PlotModels.Add(tempPlotModel);
}
#endregion
}
private PlotModel CreatePlotModel(string axisYTitle, double axisYMinValue, double axisYMaxValue)
{
PlotModel plotModel = new PlotModel();
//plotModel.Background = OxyColors.Transparent;
if (!(plotModel.Axes.Count > 0))
{
plotModel.Axes.Add(new DateTimeAxis()
{
Position = OxyPlot.Axes.AxisPosition.Bottom,
//Title = "时间",
StringFormat = "HH:mm:ss",
AxislineColor = OxyColor.FromRgb(84, 164, 227),
AbsoluteMinimum = DateTimeAxis.ToDouble(new DateTime()),
IsZoomEnabled = false,
IsPanEnabled = false,
});
plotModel.Axes.Add(new LinearAxis()
{
//Title = axisYTitle,
Position = OxyPlot.Axes.AxisPosition.Left,
LabelFormatter = value => value.ToString("F2"),
AxislineColor = OxyColor.Parse("#9C9C9C"),
AxislineStyle = LineStyle.Solid,
AxislineThickness = 1,
IsZoomEnabled = false,
IsPanEnabled = false,
AbsoluteMinimum = axisYMinValue,
EdgeRenderingMode = EdgeRenderingMode.PreferSpeed,
AbsoluteMaximum = axisYMaxValue,
});
}
return plotModel;
}

private OxyLineSeries CreateLine(string title, LineStyle lineStyle = LineStyle.Solid)
{
var lineSeries= new OxyLineSeries()
{
LineStyle = lineStyle,
//Title = title,
MarkerSize = 2,
StrokeThickness = 3,
LineLegendPosition = LineLegendPosition.End,
InterpolationAlgorithm = InterpolationAlgorithms.CatmullRomSpline,
CanTrackerInterpolatePoints = false,
};
try
{
var scb = Application.Current.TryFindResource(title) as SolidColorBrush;
var color = scb.ToOxyColor();
lineSeries.Color = color;
lineSeries.MarkerFill = scb.ToOxyColor();
}
catch
{
}
return lineSeries;
}
#endregion



#region Commands

public BPARelayCommand Select { get; set; }

public BPARelayCommand FindProductCommand { get; set; }

public BPARelayCommand<string> InspectDataCommand { get; set; }


public BPARelayCommand ShowRefrenceWindowCommand { get; private set; }
public BPARelayCommand HiddenRefrenceWindowCommand { get; private set; }
#endregion
}
}

Loading…
Cancel
Save