sc 11 months ago
parent
commit
5be2df4dda
  1. 4
      View/CurveView.xaml
  2. 55
      View/CurveView.xaml.cs
  3. 63
      ViewModel/CurveDiagramViewModel.cs

4
View/CurveView.xaml

@ -100,7 +100,7 @@
</DataGrid.CellStyle> </DataGrid.CellStyle>
<DataGrid.Columns> <DataGrid.Columns>
<!--列信息绑定--> <!--列信息绑定-->
<DataGridTextColumn Header="{x:Static lang:Resources.Machine}" Binding="{Binding Name}" Width="150" IsReadOnly="True"/> <DataGridTextColumn Header="{x:Static lang:Resources.Machine}" Binding="{Binding Machines}" Width="150" IsReadOnly="True"/>
<DataGridTextColumn Header="{x:Static lang:Resources.WorkOrder}" Binding="{Binding WorkOrder}" Width="300" IsReadOnly="True"/> <DataGridTextColumn Header="{x:Static lang:Resources.WorkOrder}" Binding="{Binding WorkOrder}" Width="300" IsReadOnly="True"/>
<DataGridTextColumn Header="{x:Static lang:Resources.ProcessName}" Binding="{Binding ProgramName}" Width="250" IsReadOnly="True"/> <DataGridTextColumn Header="{x:Static lang:Resources.ProcessName}" Binding="{Binding ProgramName}" Width="250" IsReadOnly="True"/>
<DataGridTextColumn Header="{x:Static lang:Resources.StartTime}" Binding="{Binding StartTime}" Width="150" IsReadOnly="True"/> <DataGridTextColumn Header="{x:Static lang:Resources.StartTime}" Binding="{Binding StartTime}" Width="150" IsReadOnly="True"/>
@ -125,7 +125,7 @@
<materialDesign:PackIcon Kind="DateRange" Width="25" Height="40" Margin="10" VerticalAlignment="Center"/> <materialDesign:PackIcon Kind="DateRange" Width="25" Height="40" Margin="10" VerticalAlignment="Center"/>
<TextBlock Text="{x:Static lang:Resources.SelectDate}" VerticalAlignment="Center" Margin="20 10" Foreground="White"/> <TextBlock Text="{x:Static lang:Resources.SelectDate}" VerticalAlignment="Center" Margin="20 10" Foreground="White"/>
<DatePicker x:Name="Sdatepicker" Width="150" FontSize="20" Height="40" FontWeight="Bold" Padding="1,1,0,1" <DatePicker x:Name="Sdatepicker" Width="150" FontSize="20" Height="40" FontWeight="Bold" Padding="1,1,0,1"
Focusable="False" Text="{x:Static lang:Resources.Startdate}"/> Focusable="False" Text="{x:Static lang:Resources.Startdate}" SelectedDateChanged="Sdatepicker_SelectedDateChanged"/>
</StackPanel> </StackPanel>
</ListViewItem> </ListViewItem>
</ListView> </ListView>

55
View/CurveView.xaml.cs

@ -5,6 +5,7 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Data; using System.Data;
using System.Linq; using System.Linq;
using System.Net;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Windows; using System.Windows;
@ -18,6 +19,7 @@ using System.Windows.Media.Imaging;
using System.Windows.Navigation; using System.Windows.Navigation;
using System.Windows.Shapes; using System.Windows.Shapes;
using System.Xaml; using System.Xaml;
using static SunlightCentralizedControlManagement_SCCM_.UserClass.SqliteHelper;
namespace SunlightCentralizedControlManagement_SCCM_.View namespace SunlightCentralizedControlManagement_SCCM_.View
{ {
@ -26,7 +28,11 @@ namespace SunlightCentralizedControlManagement_SCCM_.View
/// </summary> /// </summary>
public partial class CurveView : UserControl public partial class CurveView : UserControl
{ {
private SQLiteHelper SQLiteHelpers = null; //定义数据库
private readonly string DBAddress = Environment.CurrentDirectory + "\\DataBase\\SCCM.db"; //数据库路径
public static DataTable WorkOrder = new DataTable(); //设备表缓存
private readonly UserClass.IniFile.IniFiles Configini = new UserClass.IniFile.IniFiles(Convert.ToString(System.AppDomain.CurrentDomain.BaseDirectory) + "SCCM.ini"); private readonly UserClass.IniFile.IniFiles Configini = new UserClass.IniFile.IniFiles(Convert.ToString(System.AppDomain.CurrentDomain.BaseDirectory) + "SCCM.ini");
private string SYS_machines =null;
public CurveView() public CurveView()
{ {
@ -56,41 +62,64 @@ namespace SunlightCentralizedControlManagement_SCCM_.View
private void UserControl_Loaded(object sender, RoutedEventArgs e) private void UserControl_Loaded(object sender, RoutedEventArgs e)
{ {
Griddata.ItemsSource = MainWindowViewModel.Machines.DefaultView; Griddata.ItemsSource = MainWindowViewModel.Machines.DefaultView;
Sdatepicker.Text = DateTime.Now.ToString("yyyy/MM/dd");
} }
private void WorkOrderNumder_Click(object sender, RoutedEventArgs e) private void WorkOrderNumder_Click(object sender, RoutedEventArgs e)
{ {
CurveDiagramViewModel.Curve(Select_WorkOrderNumder.Text);
// OscChart.CoreChart..;
} }
private void ListViewItem_Before(object sender, MouseButtonEventArgs e) private void ListViewItem_Before(object sender, MouseButtonEventArgs e)//前一天
{ {
Sdatepicker.Text = DateTime.Parse(Sdatepicker.Text).AddDays(-1).ToString("yyyy/MM/dd");
if (!string.IsNullOrEmpty(SYS_machines)) { }
} }
private void ListViewItem_Today(object sender, MouseButtonEventArgs e) private void ListViewItem_Today(object sender, MouseButtonEventArgs e)//今天
{ {
Sdatepicker.Text = DateTime.Now.ToString("yyyy/MM/dd");
if (!string.IsNullOrEmpty(SYS_machines)) { }
} }
private void ListViewItem_DayAfter(object sender, MouseButtonEventArgs e) private void ListViewItem_DayAfter(object sender, MouseButtonEventArgs e)//后一天
{ {
Sdatepicker.Text = DateTime.Parse(Sdatepicker.Text).AddDays(1).ToString("yyyy/MM/dd");
if (!string.IsNullOrEmpty(SYS_machines)) { }
} }
private void Griddata_MouseDoubleClick(object sender, MouseButtonEventArgs e) private void Griddata_MouseDoubleClick(object sender, MouseButtonEventArgs e)//选择机台
{ {
int rownum = Griddata.SelectedIndex;//获取鼠标选中行并定义变量
if (rownum != -1)//判断鼠标定位是否有效
{
SYS_machines = (Griddata.Columns[1].GetCellContent(Griddata.Items[rownum]) as TextBlock).Text;//定位第1列,
}
}
private void GridWorkOrder_MouseDoubleClick(object sender, MouseButtonEventArgs e)//选择料单
{
int rownum = Griddata.SelectedIndex;//获取鼠标选中行并定义变量
if (rownum != -1)//判断鼠标定位是否有效
{
SYS_machines = (Griddata.Columns[1].GetCellContent(Griddata.Items[rownum]) as TextBlock).Text;//定位第1列,
}
} }
private void GridWorkOrder_MouseDoubleClick(object sender, MouseButtonEventArgs e) private void Sdatepicker_SelectedDateChanged(object sender, SelectionChangedEventArgs e)//
{ {
string SysTime = DateTime.Parse(sender.ToString()).ToString("yyyy/MM/dd");
string SysTimeDays = DateTime.Parse(sender.ToString()).AddDays(1).ToString("yyyy/MM/dd");
SQLiteHelpers = new SQLiteHelper(DBAddress); //数据库连接路径
SQLiteHelpers.Open(); //打开数据库
WorkOrder = SQLiteHelpers.ExecuteDataSet("select * from WorkOrder where " + "StartTime>='" + SysTime + "'and StartTime<='" + SysTimeDays + "'", null).Tables[0]; //读取表写入缓存
SQLiteHelpers.Close();
GridWorkOrder.ItemsSource = WorkOrder.DefaultView;
} }
} }
} }

63
ViewModel/CurveDiagramViewModel.cs

@ -23,12 +23,32 @@ using LiveChartsCore.Motion;
using SunlightCentralizedControlManagement_SCCM_.Properties; using SunlightCentralizedControlManagement_SCCM_.Properties;
using static SunlightCentralizedControlManagement_SCCM_.UserClass.SqliteHelper; using static SunlightCentralizedControlManagement_SCCM_.UserClass.SqliteHelper;
using TouchSocket.Core; using TouchSocket.Core;
using System.ComponentModel;
using System.Runtime.CompilerServices;
namespace SunlightCentralizedControlManagement_SCCM_.ViewModel namespace SunlightCentralizedControlManagement_SCCM_.ViewModel
{ {
public class NotifyPropertyBase : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
public void Notify([CallerMemberName] string propName = "")
{
if (PropertyChanged != null)
PropertyChanged(this, new PropertyChangedEventArgs(propName));
}
protected void SetProperty<T>(ref T prop, T value, [CallerMemberName] string propertyName = null)
{
if (EqualityComparer<T>.Default.Equals(prop, value) == false)
{
prop = value;
Notify(propertyName);
}
}
}
public partial class CurveDiagramViewModel : ObservableObject//ViewModelBase public partial class CurveDiagramViewModel : ObservableObject//ViewModelBase
{ {
public ISeries[] Series { get; set; } public static ISeries[] Series { get; set; }
//x轴时间格式 //x轴时间格式
public Axis[] XAxes { get; set; } = public Axis[] XAxes { get; set; } =
{ {
@ -104,31 +124,36 @@ namespace SunlightCentralizedControlManagement_SCCM_.ViewModel
}, //PH轴 }, //PH轴
}; };
private readonly Random _r = new Random(); private static Random _r = new Random();
private readonly ObservableCollection<DateTimePoint> MTT_values; private static ObservableCollection<DateTimePoint> MTT_values;
private readonly ObservableCollection<DateTimePoint> MTL_values; private static ObservableCollection<DateTimePoint> MTL_values;
private readonly ObservableCollection<DateTimePoint> MTH_values; private static ObservableCollection<DateTimePoint> MTH_values;
private readonly ObservableCollection<DateTimePoint> MST_values; private static ObservableCollection<DateTimePoint> MST_values;
private readonly ObservableCollection<DateTimePoint> MUT_values; private static ObservableCollection<DateTimePoint> MUT_values;
private readonly ObservableCollection<DateTimePoint> STTA_values; private static ObservableCollection<DateTimePoint> STTA_values;
private readonly ObservableCollection<DateTimePoint> STLA_values; private static ObservableCollection<DateTimePoint> STLA_values;
private readonly ObservableCollection<DateTimePoint> STTB_values; private static ObservableCollection<DateTimePoint> STTB_values;
private readonly ObservableCollection<DateTimePoint> STLB_values; private static ObservableCollection<DateTimePoint> STLB_values;
private readonly ObservableCollection<DateTimePoint> STTC_values; private static ObservableCollection<DateTimePoint> STTC_values;
private readonly ObservableCollection<DateTimePoint> STLC_values; private static ObservableCollection<DateTimePoint> STLC_values;
private SQLiteHelper SQLiteHelpers = null; //定义数据库 private static SQLiteHelper SQLiteHelpers = null; //定义数据库
private readonly string ChartAdress = Environment.CurrentDirectory + "\\DataBase\\Chart.db"; //数据库路径 private static string ChartAdress = Environment.CurrentDirectory + "\\DataBase\\Chart.db"; //数据库路径
DataTable CDB = new DataTable(); static DataTable CDB = new DataTable();
private int CDB_Count;//长度 private static int CDB_Count;//长度
public CurveDiagramViewModel() public CurveDiagramViewModel()
{ {
if (!string.IsNullOrEmpty(MainWindowViewModel.SYS_WorkNumder))
Curve("");
}
public static void Curve(string SYSWorkNumder)
{
if (!string.IsNullOrEmpty(SYSWorkNumder))
{ {
SQLiteHelpers = new SQLiteHelper(ChartAdress); //数据库连接路径 SQLiteHelpers = new SQLiteHelper(ChartAdress); //数据库连接路径
SQLiteHelpers.Open(); //打开数据库 SQLiteHelpers.Open(); //打开数据库
CDB = SQLiteHelpers.ExecuteDataSet("select * from Chart where DYELOT = '" + MainWindowViewModel.SYS_WorkNumder + "'order by Time", null).Tables[0]; CDB = SQLiteHelpers.ExecuteDataSet("select * from Chart where DYELOT = '" + SYSWorkNumder + "'order by Time", null).Tables[0];
SQLiteHelpers.Close(); SQLiteHelpers.Close();
CDB_Count = CDB.Rows.Count; CDB_Count = CDB.Rows.Count;

Loading…
Cancel
Save