sc 1 year ago
parent
commit
432184f348
  1. 50
      View/HistoryRecordsView.xaml
  2. 30
      View/HistoryRecordsView.xaml.cs
  3. 184
      ViewModel/HistoryRecordsViewModel.cs

50
View/HistoryRecordsView.xaml

@ -4,12 +4,60 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:viewmodel="clr-namespace:DyeingComputer.ViewModel" xmlns:viewmodel="clr-namespace:DyeingComputer.ViewModel"
xmlns:lang="clr-namespace:DyeingComputer.Properties"
xmlns:lvc="clr-namespace:LiveChartsCore.SkiaSharpView.WPF;assembly=LiveChartsCore.SkiaSharpView.WPF" xmlns:lvc="clr-namespace:LiveChartsCore.SkiaSharpView.WPF;assembly=LiveChartsCore.SkiaSharpView.WPF"
mc:Ignorable="d" mc:Ignorable="d"
d:DataContext="{d:DesignInstance Type=viewmodel:HistoryRecordsViewModel}" d:DataContext="{d:DesignInstance Type=viewmodel:HistoryRecordsViewModel}"
d:DesignHeight="630" d:DesignWidth="1280"> d:DesignHeight="630" d:DesignWidth="1280">
<Grid> <Grid>
<lvc:CartesianChart x:Name="OscChart" MinWidth="1280" MinHeight="600" EasingFunction="{x:Null}" <DataGrid x:Name="gridH" AlternationCount="2" IsReadOnly="True" SelectionChanged="Grid_SelectionChanged"
d:ItemsSource="{d:SampleData ItemCount=90}" AutoGenerateColumns="False" MinColumnWidth="30"
HorizontalGridLinesBrush="#FFC9C9C9" VerticalGridLinesBrush="#FFC9C9C9" GridLinesVisibility="All" BorderBrush="{x:Null}"
BorderThickness="1,1,1,1" ColumnHeaderHeight="40" HorizontalContentAlignment="Right" Grid.ColumnSpan="2" AllowDrop="False"
CanUserReorderColumns="False" CanUserSortColumns="False" CanUserResizeRows="False" CanUserResizeColumns="False"
CanUserAddRows="True" CanUserDeleteRows="False" HeadersVisibility ="Column"
Background="White" SelectionMode="Single" FontSize="15" TabIndex="1" Focusable="True" VerticalAlignment="Top" Height="300">
<DataGrid.RowStyle >
<Style TargetType="{x:Type DataGridRow}">
<Setter Property="Height" Value="30" />
<Setter Property="FontSize" Value="25" />
<Style.Triggers>
<Trigger Property="ItemsControl.AlternationIndex" Value="0">
<Setter Property="Background" Value="#FFFFFFFF" />
</Trigger>
<Trigger Property="ItemsControl.AlternationIndex" Value="1">
<Setter Property="Background" Value="#FFF0F0F0" />
</Trigger>
<Trigger Property="IsMouseOver" Value="False"/>
</Style.Triggers>
</Style>
</DataGrid.RowStyle>
<DataGrid.CellStyle>
<Style TargetType="DataGridCell">
<Setter Property="BorderThickness" Value="0"/>
<Setter Property="MinWidth" Value="20"/>
<Style.Triggers>
<Trigger Property="IsSelected" Value="True">
<Setter Property="Background" Value="#FFC0C0C0"/>
<Setter Property="BorderBrush" Value="#FFC0C0C0"/>
<Setter Property="Foreground" Value="Black"/>
</Trigger>
</Style.Triggers>
</Style>
</DataGrid.CellStyle>
<DataGrid.Columns>
<!--列信息绑定-->
<!--列信息绑定-->
<DataGridTextColumn Header="{x:Static lang:Resources.WorkOrderNumder}" Width="300" Binding="{Binding WorkOrder}" IsReadOnly="True"/>
<DataGridTextColumn Header="{x:Static lang:Resources.ProcessName}" Width="300" Binding="{Binding ProcessName}" IsReadOnly="True"/>
<DataGridTextColumn Header="ProcessID" Binding="{Binding ProcessID}" Width="0" MinWidth="0" MaxWidth="0"/>
<DataGridTextColumn Header="lock" Binding="{Binding lock}" Width="0" MinWidth="0" MaxWidth="0"/>
<DataGridTextColumn Header="{x:Static lang:Resources.StartTime}" Width="300" Binding="{Binding StartTime}" IsReadOnly="True"/>
<DataGridTextColumn Header="{x:Static lang:Resources.EndTime}" Width="300" Binding="{Binding EndTime}" IsReadOnly="True"/>
<DataGridTextColumn Header="{x:Static lang:Resources.Remark}" Width="*" Binding="{Binding Remark}" IsReadOnly="True"/>
</DataGrid.Columns>
</DataGrid>
<lvc:CartesianChart Margin="0,300,0,0" x:Name="chart"
Series="{Binding Series}" YAxes="{Binding YAxes}" XAxes="{Binding XAxes}"/> Series="{Binding Series}" YAxes="{Binding YAxes}" XAxes="{Binding XAxes}"/>
</Grid> </Grid>
</UserControl> </UserControl>

30
View/HistoryRecordsView.xaml.cs

@ -1,9 +1,14 @@
using DyeingComputer.ViewModel; using DyeingComputer.ViewModel;
using ScottPlot.Hatches;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Data;
using System.Linq; using System.Linq;
using System.Net;
using System.Text; using System.Text;
using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Timers;
using System.Windows; using System.Windows;
using System.Windows.Controls; using System.Windows.Controls;
using System.Windows.Data; using System.Windows.Data;
@ -13,6 +18,7 @@ using System.Windows.Media;
using System.Windows.Media.Imaging; using System.Windows.Media.Imaging;
using System.Windows.Navigation; using System.Windows.Navigation;
using System.Windows.Shapes; using System.Windows.Shapes;
using static DyeingComputer.UserClass.SqliteHelper;
namespace DyeingComputer.View namespace DyeingComputer.View
{ {
@ -21,10 +27,34 @@ namespace DyeingComputer.View
/// </summary> /// </summary>
public partial class HistoryRecordsView : UserControl public partial class HistoryRecordsView : UserControl
{ {
private SQLiteHelper SQLiteHelpers = null; //定义数据库
private readonly string DBAddress = Environment.CurrentDirectory + "\\DataBase\\800COMPUTER.db"; //数据库路径
DataTable GRIDDB = new DataTable();
public HistoryRecordsView() public HistoryRecordsView()
{ {
InitializeComponent(); InitializeComponent();
DataContext = new HistoryRecordsViewModel(); DataContext = new HistoryRecordsViewModel();
SQLiteHelpers = new SQLiteHelper(DBAddress); //数据库连接路径
SQLiteHelpers.Open(); //打开数据库
GRIDDB = SQLiteHelpers.ExecuteDataSet("select * from WorkOrder where StartTime > '" + DateTime.Now.AddDays(-30).ToString("yyyy/MM/dd HH:mm:ss") + "order by StartTime'", null).Tables[0];
SQLiteHelpers.Close();
gridH.ItemsSource = GRIDDB.DefaultView;
} }
private void Grid_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
int rownum = gridH.SelectedIndex;//获取鼠标选中行并定义变量
if (rownum != -1)//判断鼠标定位是否有效
{
HistoryRecordsViewModel.name = (gridH.Columns[0].GetCellContent(gridH.Items[rownum]) as TextBlock).Text;//定位第0列,
HistoryRecordsViewModel.stime = (gridH.Columns[5].GetCellContent(gridH.Items[rownum]) as TextBlock).Text;//定位第1列,
HistoryRecordsViewModel.etime = (gridH.Columns[6].GetCellContent(gridH.Items[rownum]) as TextBlock).Text;//定位第6列
HistoryRecordsViewModel.history_ = true;
// chart.Series = HistoryRecordsViewModel.Series;
}
}
} }
} }

184
ViewModel/HistoryRecordsViewModel.cs

@ -14,12 +14,19 @@ using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using static DyeingComputer.UserClass.SqliteHelper; using static DyeingComputer.UserClass.SqliteHelper;
using ScottPlot.Hatches;
using System.Windows.Controls;
using ScottPlot;
using System.Windows.Threading;
using ScottPlot.Statistics;
using System.Management.Instrumentation;
namespace DyeingComputer.ViewModel namespace DyeingComputer.ViewModel
{ {
public partial class HistoryRecordsViewModel : ObservableObject public partial class HistoryRecordsViewModel : ObservableObject
{ {
public ISeries[] Series { get; set; }
public static ISeries[] Series { get; set; }
//x轴时间格式 //x轴时间格式
public Axis[] XAxes { get; set; } = public Axis[] XAxes { get; set; } =
{ {
@ -97,92 +104,128 @@ namespace DyeingComputer.ViewModel
//new AnimatableAxisBounds //new AnimatableAxisBounds
}; };
private readonly Random _r = new Random(); private Random _r = new Random();
private readonly ObservableCollection<DateTimePoint> MTT_values; private ObservableCollection<DateTimePoint> MTT_values;
private readonly ObservableCollection<DateTimePoint> MTL_values; private ObservableCollection<DateTimePoint> MTL_values;
private readonly ObservableCollection<DateTimePoint> MTH_values; private ObservableCollection<DateTimePoint> MTH_values;
private readonly ObservableCollection<DateTimePoint> MST_values; private ObservableCollection<DateTimePoint> MST_values;
private readonly ObservableCollection<DateTimePoint> MUT_values; private ObservableCollection<DateTimePoint> MUT_values;
private readonly ObservableCollection<DateTimePoint> STTA_values; private ObservableCollection<DateTimePoint> STTA_values;
private readonly ObservableCollection<DateTimePoint> STLA_values; private ObservableCollection<DateTimePoint> STLA_values;
private readonly ObservableCollection<DateTimePoint> STTB_values; private ObservableCollection<DateTimePoint> STTB_values;
private readonly ObservableCollection<DateTimePoint> STLB_values; private ObservableCollection<DateTimePoint> STLB_values;
private readonly ObservableCollection<DateTimePoint> STTC_values; private ObservableCollection<DateTimePoint> STTC_values;
private readonly ObservableCollection<DateTimePoint> STLC_values; private ObservableCollection<DateTimePoint> STLC_values;
private SQLiteHelper SQLiteHelpers = null; //定义数据库 private SQLiteHelper SQLiteHelpers = null; //定义数据库
private readonly string ChartAdress = Environment.CurrentDirectory + "\\DataBase\\Chart.db"; //数据库路径 private readonly string ChartAdress = Environment.CurrentDirectory + "\\DataBase\\Chart.db"; //数据库路径
DataTable CDB = new DataTable(); public DataTable CDB = new DataTable();
private int CDB_Count;//长度 private int CDB_Count;//长度
public HistoryRecordsViewModel() public HistoryRecordsViewModel()
{ {
if (MainWindowViewModel.WorkNumder.ToString() != "----------") string Sys_Time = DateTime.Now.AddDays(-2).ToString("yyyy/MM/dd HH:mm:ss");
{ SQLiteHelpers = new SQLiteHelper(ChartAdress); //数据库连接路径
SQLiteHelpers = new SQLiteHelper(ChartAdress); //数据库连接路径 SQLiteHelpers.Open(); //打开数据库
SQLiteHelpers.Open(); //打开数据库 CDB = SQLiteHelpers.ExecuteDataSet("select * from Chart where Time > '" + Sys_Time + "'order by Time", null).Tables[0];
CDB = SQLiteHelpers.ExecuteDataSet("select * from Chart where DYELOT = '" + MainWindowViewModel.WorkNumder + "'order by Time", null).Tables[0]; SQLiteHelpers.Close();
SQLiteHelpers.Close(); CDB_Count = CDB.Rows.Count;
CDB_Count = CDB.Rows.Count;
var MTT_items = new List<DateTimePoint>(); Chart_View();
var MTL_items = new List<DateTimePoint>(); CountDown();
var MTH_items = new List<DateTimePoint>(); }
var MST_items = new List<DateTimePoint>(); public static bool history_ = false;
var MUT_items = new List<DateTimePoint>(); public static string name;
var STTA_items = new List<DateTimePoint>(); public static string stime;
var STLA_items = new List<DateTimePoint>(); public static string etime;
var STTB_items = new List<DateTimePoint>(); public void History()
var STLB_items = new List<DateTimePoint>(); {
var STTC_items = new List<DateTimePoint>(); SQLiteHelpers = new SQLiteHelper(ChartAdress); //数据库连接路径
var STLC_items = new List<DateTimePoint>(); SQLiteHelpers.Open(); //打开数据库
for (var i = 0; i < CDB_Count; i++) CDB = SQLiteHelpers.ExecuteDataSet("select * from Chart where DYELOT = '" + name + "'order by Time", null).Tables[0];
{ SQLiteHelpers.Close();
DateTime TIME = Convert.ToDateTime(CDB.Rows[i].Field<string>("Time")); CDB_Count = CDB.Rows.Count;
MTT_items.Add(new DateTimePoint(TIME, CDB.Rows[i].Field<double>("MTT")));
MTL_items.Add(new DateTimePoint(TIME, CDB.Rows[i].Field<double>("MTL")));
MTH_items.Add(new DateTimePoint(TIME, CDB.Rows[i].Field<double>("MTH")));
MST_items.Add(new DateTimePoint(TIME, CDB.Rows[i].Field<double>("MST")));
MUT_items.Add(new DateTimePoint(TIME, CDB.Rows[i].Field<double>("MUT")));
if (MainWindowViewModel.SM01 == 1)
{
STTA_items.Add(new DateTimePoint(TIME, CDB.Rows[i].Field<double>("STTA")));
STLA_items.Add(new DateTimePoint(TIME, CDB.Rows[i].Field<double>("STLA")));
}
if (MainWindowViewModel.SM02 == 1)
{
STTB_items.Add(new DateTimePoint(TIME, CDB.Rows[i].Field<double>("STTB")));
STLB_items.Add(new DateTimePoint(TIME, CDB.Rows[i].Field<double>("STLB")));
}
if (MainWindowViewModel.SM03 == 1)
{
STTC_items.Add(new DateTimePoint(TIME, CDB.Rows[i].Field<double>("STTC")));
STLC_items.Add(new DateTimePoint(TIME, CDB.Rows[i].Field<double>("STLC")));
}
}
MTT_values = new ObservableCollection<DateTimePoint>(MTT_items); Chart_View();
MTL_values = new ObservableCollection<DateTimePoint>(MTL_items); }
MTH_values = new ObservableCollection<DateTimePoint>(MTH_items); public void CountDown()
MST_values = new ObservableCollection<DateTimePoint>(MST_items); {
MUT_values = new ObservableCollection<DateTimePoint>(MUT_items); DispatcherTimer timer1s = new DispatcherTimer//初始化循环,每1秒调用一次Tick
{
Interval = TimeSpan.FromSeconds(1)//秒
};
timer1s.Tick += Tick_Event_1S;
timer1s.Start();
}
void Tick_Event_1S(object sender, EventArgs e)//Tick_Event周期执行事件1S
{
if (history_)
{
History();
history_ = false;
}
}
public void Chart_View()
{
var MTT_items = new List<DateTimePoint>();
var MTL_items = new List<DateTimePoint>();
var MTH_items = new List<DateTimePoint>();
var MST_items = new List<DateTimePoint>();
var MUT_items = new List<DateTimePoint>();
var STTA_items = new List<DateTimePoint>();
var STLA_items = new List<DateTimePoint>();
var STTB_items = new List<DateTimePoint>();
var STLB_items = new List<DateTimePoint>();
var STTC_items = new List<DateTimePoint>();
var STLC_items = new List<DateTimePoint>();
for (var i = 0; i < CDB_Count; i++)
{
DateTime TIME = Convert.ToDateTime(CDB.Rows[i].Field<string>("Time"));
MTT_items.Add(new DateTimePoint(TIME, CDB.Rows[i].Field<double>("MTT")));
MTL_items.Add(new DateTimePoint(TIME, CDB.Rows[i].Field<double>("MTL")));
MTH_items.Add(new DateTimePoint(TIME, CDB.Rows[i].Field<double>("MTH")));
MST_items.Add(new DateTimePoint(TIME, CDB.Rows[i].Field<double>("MST")));
MUT_items.Add(new DateTimePoint(TIME, CDB.Rows[i].Field<double>("MUT")));
if (MainWindowViewModel.SM01 == 1) if (MainWindowViewModel.SM01 == 1)
{ {
STTA_values = new ObservableCollection<DateTimePoint>(STTA_items); STTA_items.Add(new DateTimePoint(TIME, CDB.Rows[i].Field<double>("STTA")));
STLA_values = new ObservableCollection<DateTimePoint>(STLA_items); STLA_items.Add(new DateTimePoint(TIME, CDB.Rows[i].Field<double>("STLA")));
} }
if (MainWindowViewModel.SM02 == 1) if (MainWindowViewModel.SM02 == 1)
{ {
STTB_values = new ObservableCollection<DateTimePoint>(STTB_items); STTB_items.Add(new DateTimePoint(TIME, CDB.Rows[i].Field<double>("STTB")));
STLB_values = new ObservableCollection<DateTimePoint>(STLB_items); STLB_items.Add(new DateTimePoint(TIME, CDB.Rows[i].Field<double>("STLB")));
} }
if (MainWindowViewModel.SM03 == 1) if (MainWindowViewModel.SM03 == 1)
{ {
STTC_values = new ObservableCollection<DateTimePoint>(STTC_items); STTC_items.Add(new DateTimePoint(TIME, CDB.Rows[i].Field<double>("STTC")));
STLC_values = new ObservableCollection<DateTimePoint>(STLC_items); STLC_items.Add(new DateTimePoint(TIME, CDB.Rows[i].Field<double>("STLC")));
} }
Series = new ISeries[] }
{
MTT_values = new ObservableCollection<DateTimePoint>(MTT_items);
MTL_values = new ObservableCollection<DateTimePoint>(MTL_items);
MTH_values = new ObservableCollection<DateTimePoint>(MTH_items);
MST_values = new ObservableCollection<DateTimePoint>(MST_items);
MUT_values = new ObservableCollection<DateTimePoint>(MUT_items);
if (MainWindowViewModel.SM01 == 1)
{
STTA_values = new ObservableCollection<DateTimePoint>(STTA_items);
STLA_values = new ObservableCollection<DateTimePoint>(STLA_items);
}
if (MainWindowViewModel.SM02 == 1)
{
STTB_values = new ObservableCollection<DateTimePoint>(STTB_items);
STLB_values = new ObservableCollection<DateTimePoint>(STLB_items);
}
if (MainWindowViewModel.SM03 == 1)
{
STTC_values = new ObservableCollection<DateTimePoint>(STTC_items);
STLC_values = new ObservableCollection<DateTimePoint>(STLC_items);
}
Series = new ISeries[]
{
new LineSeries<DateTimePoint> new LineSeries<DateTimePoint>
{ {
Name = Properties.Resources.MasterCylinder +"PH", Name = Properties.Resources.MasterCylinder +"PH",
@ -304,8 +347,7 @@ namespace DyeingComputer.ViewModel
LineSmoothness = 0, LineSmoothness = 0,
ScalesYAt = 1, ScalesYAt = 1,
}, //附缸3 液位 }, //附缸3 液位
}; };
}
} }
} }
} }

Loading…
Cancel
Save