Browse Source

历史曲线查询

reconfiguration
lyw 2 days ago
parent
commit
1ce3db0540
6 changed files with 564 additions and 15 deletions
  1. +1
    -2
      BPASmartClient.Academy/App.xaml.cs
  2. +125
    -0
      BPASmartClient.Academy/Model/HistorySqlite.cs
  3. +1
    -1
      BPASmartClient.Academy/Model/Sqlite.cs
  4. +287
    -11
      BPASmartClient.Academy/View/HistoryChartView.xaml
  5. +104
    -1
      BPASmartClient.Academy/View/HistoryChartView.xaml.cs
  6. +46
    -0
      BPASmartClient.Academy/ViewModel/HistoryChartViewModel.cs

+ 1
- 2
BPASmartClient.Academy/App.xaml.cs View File

@@ -186,7 +186,7 @@ namespace BPASmartClient.Academy
});
DeviceMonitor.Add(new SubMenumodel()
{
SubMenuName = "数据曲线",
SubMenuName = "历史曲线",
SubMenuPermission = new Permission[] { Permission.管理员, Permission.操作员, Permission.观察员, Permission.技术员 },
AssemblyName = "BPASmartClient.Academy",
ToggleWindowPath = "View.HistoryChartView"
@@ -245,7 +245,6 @@ namespace BPASmartClient.Academy
Simens_PLC.GetInstance.Connect();
Simens_PLC.GetInstance.Init();


}

}


+ 125
- 0
BPASmartClient.Academy/Model/HistorySqlite.cs View File

@@ -0,0 +1,125 @@
using BPASmartClient.Academy.ViewModel;
using BPASmartClient.CustomResource.UserControls.MessageShow;
using BPASmartClient.CustomResource.UserControls;
using Opc.Ua.Server;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Security.RightsManagement;
using System.Text;
using System.Threading.Tasks;

namespace BPASmartClient.Academy.Model
{
public class HistorySqlite
{
private static HistorySqlite _instance;
public static HistorySqlite GetInstance { get; set; } = _instance??=new HistorySqlite();
public string DateString { get; set; }= DateTime.Now.ToString("yyyy-MM-dd");
public HistorySqlite() { }
public SqlSugarScope Db { get; set; }
public ObservableCollection<RecipeChart> recipeCharts { get; set; } = new ObservableCollection<RecipeChart>();
public void FindAllList()
{
string path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "AccessFile\\DB");
try
{
DirectoryInfo directoryInfo = new DirectoryInfo(path);
FileInfo[] files = directoryInfo.GetFiles();
string[] filePath = Directory.GetFiles(path);
recipeCharts.Clear();
int i = 1;
files.ToList().ForEach(e =>
{
Db = new SqlSugarScope(new ConnectionConfig()
{
ConnectionString = $"Data Source = {e.FullName}",
DbType = DbType.Sqlite,
IsAutoCloseConnection = true,
});
Db.Queryable<SaveData>().Select(x => x.Name).Distinct().ToList().ForEach(t =>
{
recipeCharts.Add(new RecipeChart()
{
Num = i++,
Name = t,
CreateTime = DateTime.Parse(e.Name.Replace("data","").Replace(".db",""))
});
});
});
}
catch (UnauthorizedAccessException ex)
{
throw;
}
catch(DirectoryNotFoundException ex)
{
throw;
}
catch(Exception ex)
{
throw;
}
}

public void FindDateList()
{
string path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, $"AccessFile\\DB\\data{DateString}.db");
if (File.Exists(path))
{
recipeCharts.Clear();
Db = new SqlSugarScope(new ConnectionConfig()
{
ConnectionString = $"Data Source = {path}",
DbType = DbType.Sqlite,
IsAutoCloseConnection = true,
});
int i = 1;
Db.Queryable<SaveData>().Select(x => x.Name).Distinct().ToList().ForEach(t =>
{
recipeCharts.Add(new RecipeChart()
{
Num = i++,
Name = t,
CreateTime = DateTime.Parse(DateString)
});
});
}
else
{
App.Current.Dispatcher.Invoke(() =>
{
NoticeDemoViewModel.OpenMsg(EnumPromptType.Info, App.MainWindow, "提示", "未找到相关测试记录!", 1, 1);
});
}
}
public List<SaveData> SelectName(string Name)
{
try
{
return Db.Queryable<SaveData>().Where(o => o.Name == Name).ToList();
}
catch (Exception)
{
return null;
}
}
public List<SaveData> SelectId(string id)
{
try
{
return Db.Queryable<SaveData>().Where(o => o.Id == id).ToList();
}
catch (Exception)
{
return null;
}
}
}
}

+ 1
- 1
BPASmartClient.Academy/Model/Sqlite.cs View File

@@ -19,7 +19,7 @@ namespace BPASmartClient.Academy.Model
get
{
Directory.CreateDirectory(AppDomain.CurrentDomain.BaseDirectory);
return Path.Combine(AppDomain.CurrentDomain.BaseDirectory, $"AccessFile\\DB{DateTime.Now.ToString("yyyy-MM-dd")}\\data.db");
return Path.Combine(AppDomain.CurrentDomain.BaseDirectory, $"AccessFile\\DB\\data{DateTime.Now.ToString("yyyy-MM-dd")}.db");
}
}
public SqlSugarScope Db = new SqlSugarScope(new ConnectionConfig()


+ 287
- 11
BPASmartClient.Academy/View/HistoryChartView.xaml View File

@@ -1,16 +1,292 @@
<UserControl x:Class="BPASmartClient.Academy.View.HistoryChartView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:BPASmartClient.Academy.View"
xmlns:vm ="clr-namespace:BPASmartClient.Academy.ViewModel"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800">
<UserControl
x:Class="BPASmartClient.Academy.View.HistoryChartView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:BPASmartClient.Academy.View"
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">
<UserControl.DataContext>
<vm:HistoryChartViewModel/>
<vm:HistoryChartViewModel />
</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>
<Grid.RowDefinitions>
<RowDefinition Height="50" />
<RowDefinition />
</Grid.RowDefinitions>
<StackPanel
Margin="0,0,60,0"
HorizontalAlignment="Right"
VerticalAlignment="Center"
Orientation="Horizontal">
<DatePicker
Margin="0,0,60,0"
SelectedDate="{Binding SelectTime}"
Style="{DynamicResource PickerStyle}" />
<Button
Width="120"
Height="30"
Command="{Binding Select}"
Content="查询"
Style="{StaticResource ButtonStyle}" />
</StackPanel>

<Grid Grid.Row="1">
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition Width="2*" />
</Grid.ColumnDefinitions>
<!--#region 表格-->
<Grid
Grid.Column="0"
Margin="20,20,20,300"
Background="Transparent">
<Grid.RowDefinitions>
<RowDefinition Height="50" />
<RowDefinition />
</Grid.RowDefinitions>
<!--#region 标题-->
<Grid Background="#ff0C255F">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="100" />
<ColumnDefinition Width="180" />
<ColumnDefinition Width="120" />
<ColumnDefinition Width="1*" />
</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="100" />
<ColumnDefinition Width="180" />
<ColumnDefinition Width="120" />
<ColumnDefinition Width="1*" />
</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"
HorizontalAlignment="Center"
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}}" />
<RadioButton
x:Name="ceshi"
Grid.Column="3"
Content="查看"
FontSize="16"
Foreground="White"
GroupName="sss"
Style="{StaticResource setCheck}" />
</Grid>
<Popup
HorizontalAlignment="Center"
VerticalAlignment="Center"
AllowsTransparency="True"
IsOpen="{Binding ElementName=ceshi, Path=IsChecked, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}"
MouseLeave="Popup_MouseLeave"
Placement="Bottom"
PlacementTarget="{Binding ElementName=ceshi}">
<Grid
Width="200"
Height="200"
Background="Transparent">
<Path
Fill="#ff0C255F"
Stroke="White"
StrokeThickness="1">
<Path.Data>
<GeometryGroup>
<PathGeometry>
<PathFigure StartPoint="0,10">
<LineSegment Point="0,200" />
<LineSegment Point="200,200" />
<LineSegment Point="200,10" />
<LineSegment Point="60,10" />
<LineSegment Point="50,0" />
<LineSegment Point="40,10" />
<LineSegment Point="0,10" />
</PathFigure>
</PathGeometry>
</GeometryGroup>
</Path.Data>
</Path>

<StackPanel
Margin="0,30,0,20"
HorizontalAlignment="Center"
VerticalAlignment="Center"
Orientation="Vertical">
<Border Margin="0,10">
<Button
Width="100"
Height="35"
Click="Button_Click"
CommandParameter="{Binding ElementName=num, Path=Text, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}"
Content="温度曲线"
Style="{StaticResource ButtonStyle}" />
</Border>
<Border Margin="0,10">
<Button
Width="100"
Height="35"
Click="Button_Click"
CommandParameter="{Binding ElementName=num, Path=Text, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}"
Content="转速曲线"
Style="{StaticResource ButtonStyle}" />
</Border>
<Border Margin="0,10">
<Button
Width="100"
Height="35"
Click="Button_Click"
CommandParameter="{Binding ElementName=num, Path=Text, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}"
Content="重量曲线"
Style="{StaticResource ButtonStyle}" />
</Border>
</StackPanel>
</Grid>
</Popup>
</Grid>

</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</ScrollViewer>
<!--#endregion-->
</Grid>

<!--#endregion-->
<!--#region 曲线-->
<oxy:PlotView
x:Name="chartView"
Grid.Column="1"
Margin="5"
Background="White"
Foreground="White"
PanCursor="Hand" />
<!--#endregion-->

</Grid>

</Grid>
</UserControl>

+ 104
- 1
BPASmartClient.Academy/View/HistoryChartView.xaml.cs View File

@@ -1,4 +1,6 @@
using System;
using BPASmartClient.CustomResource.UserControls.MessageShow;
using BPASmartClient.CustomResource.UserControls;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
@@ -12,6 +14,9 @@ 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;

namespace BPASmartClient.Academy.View
{
@@ -24,5 +29,103 @@ namespace BPASmartClient.Academy.View
{
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 = HistorySqlite.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<DataPoint> twValues = new List<DataPoint>();
List<DataPoint> tvValues = new List<DataPoint>();
List<DataPoint> tmValues = new List<DataPoint>();
HistorySqlite.GetInstance.SelectName(recipeChart.Name).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<DataPoint> m101 = new List<DataPoint>();
List<DataPoint> m102 = new List<DataPoint>();
HistorySqlite.GetInstance.SelectName(recipeChart.Name).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 = "转速/rpm", 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<DataPoint> ww = new List<DataPoint>();
OxyPlot.Series.LineSeries line_5 = new OxyPlot.Series.LineSeries() { Title = "冷却水罐重量", Color = OxyColor.FromRgb(0, 0, 0), LineStyle = LineStyle.Solid, LineLegendPosition = OxyPlot.Series.LineLegendPosition.End };
HistorySqlite.GetInstance.SelectName(recipeChart.Name).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 = "冷却水罐重量/kg", Position = OxyPlot.Axes.AxisPosition.Left, LabelFormatter = value => value.ToString("f2") });
}
plotModel.Series.Add(line_5);
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;
}
}
}

+ 46
- 0
BPASmartClient.Academy/ViewModel/HistoryChartViewModel.cs View File

@@ -11,6 +11,52 @@ namespace BPASmartClient.Academy.ViewModel
public HistoryChartViewModel()
{

HistorySqlite.GetInstance.FindAllList();
Select = new BPARelayCommand(() =>
{
HistorySqlite.GetInstance.DateString = SelectTime.ToString("yyyy-MM-dd");
HistorySqlite.GetInstance.FindDateList();
});
}

public ObservableCollection<RecipeChart> RecipeCharts { get; set; }=HistorySqlite.GetInstance.recipeCharts;

private DateTime _selectTime = DateTime.Now;

public DateTime SelectTime
{
get { return _selectTime; }
set { _selectTime = value; OnPropertyChanged(); }
}

public BPARelayCommand Select { get; set; }
}
public class RecipeChart : NotifyBase
{
private int _num;

public int Num
{
get { return _num; }
set { _num = value; OnPropertyChanged(); }
}


private string _name;

public string Name
{
get { return _name; }
set { _name = value; OnPropertyChanged(); }
}

private DateTime _createTime;

public DateTime CreateTime
{
get { return _createTime; }
set { _createTime = value;OnPropertyChanged(); }
}

}
}

Loading…
Cancel
Save