diff --git a/View/CurveView.xaml b/View/CurveView.xaml index 25e58a9..faf7ae0 100644 --- a/View/CurveView.xaml +++ b/View/CurveView.xaml @@ -100,7 +100,7 @@ - + @@ -125,7 +125,7 @@ + Focusable="False" Text="{x:Static lang:Resources.Startdate}" SelectedDateChanged="Sdatepicker_SelectedDateChanged"/> diff --git a/View/CurveView.xaml.cs b/View/CurveView.xaml.cs index 115fd95..9d161de 100644 --- a/View/CurveView.xaml.cs +++ b/View/CurveView.xaml.cs @@ -5,6 +5,7 @@ using System; using System.Collections.Generic; using System.Data; using System.Linq; +using System.Net; using System.Text; using System.Threading.Tasks; using System.Windows; @@ -18,6 +19,7 @@ using System.Windows.Media.Imaging; using System.Windows.Navigation; using System.Windows.Shapes; using System.Xaml; +using static SunlightCentralizedControlManagement_SCCM_.UserClass.SqliteHelper; namespace SunlightCentralizedControlManagement_SCCM_.View { @@ -26,7 +28,11 @@ namespace SunlightCentralizedControlManagement_SCCM_.View /// 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 string SYS_machines =null; public CurveView() { @@ -56,41 +62,64 @@ namespace SunlightCentralizedControlManagement_SCCM_.View 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) { - + 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; } } } diff --git a/ViewModel/CurveDiagramViewModel.cs b/ViewModel/CurveDiagramViewModel.cs index b29e39a..8ccce9b 100644 --- a/ViewModel/CurveDiagramViewModel.cs +++ b/ViewModel/CurveDiagramViewModel.cs @@ -23,12 +23,32 @@ using LiveChartsCore.Motion; using SunlightCentralizedControlManagement_SCCM_.Properties; using static SunlightCentralizedControlManagement_SCCM_.UserClass.SqliteHelper; using TouchSocket.Core; +using System.ComponentModel; +using System.Runtime.CompilerServices; 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(ref T prop, T value, [CallerMemberName] string propertyName = null) + { + if (EqualityComparer.Default.Equals(prop, value) == false) + { + prop = value; + Notify(propertyName); + } + } + } public partial class CurveDiagramViewModel : ObservableObject//ViewModelBase { - public ISeries[] Series { get; set; } + public static ISeries[] Series { get; set; } //x轴时间格式 public Axis[] XAxes { get; set; } = { @@ -104,31 +124,36 @@ namespace SunlightCentralizedControlManagement_SCCM_.ViewModel }, //PH轴 }; - private readonly Random _r = new Random(); - private readonly ObservableCollection MTT_values; - private readonly ObservableCollection MTL_values; - private readonly ObservableCollection MTH_values; - private readonly ObservableCollection MST_values; - private readonly ObservableCollection MUT_values; - private readonly ObservableCollection STTA_values; - private readonly ObservableCollection STLA_values; - private readonly ObservableCollection STTB_values; - private readonly ObservableCollection STLB_values; - private readonly ObservableCollection STTC_values; - private readonly ObservableCollection STLC_values; + private static Random _r = new Random(); + private static ObservableCollection MTT_values; + private static ObservableCollection MTL_values; + private static ObservableCollection MTH_values; + private static ObservableCollection MST_values; + private static ObservableCollection MUT_values; + private static ObservableCollection STTA_values; + private static ObservableCollection STLA_values; + private static ObservableCollection STTB_values; + private static ObservableCollection STLB_values; + private static ObservableCollection STTC_values; + private static ObservableCollection STLC_values; - private SQLiteHelper SQLiteHelpers = null; //定义数据库 - private readonly string ChartAdress = Environment.CurrentDirectory + "\\DataBase\\Chart.db"; //数据库路径 - DataTable CDB = new DataTable(); - private int CDB_Count;//长度 + private static SQLiteHelper SQLiteHelpers = null; //定义数据库 + private static string ChartAdress = Environment.CurrentDirectory + "\\DataBase\\Chart.db"; //数据库路径 + static DataTable CDB = new DataTable(); + private static int CDB_Count;//长度 public CurveDiagramViewModel() { - if (!string.IsNullOrEmpty(MainWindowViewModel.SYS_WorkNumder)) + + Curve(""); + } + public static void Curve(string SYSWorkNumder) + { + if (!string.IsNullOrEmpty(SYSWorkNumder)) { SQLiteHelpers = new SQLiteHelper(ChartAdress); //数据库连接路径 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(); CDB_Count = CDB.Rows.Count;