diff --git a/App.xaml.cs b/App.xaml.cs index 1f92128..bd0897c 100644 --- a/App.xaml.cs +++ b/App.xaml.cs @@ -1,4 +1,7 @@ using DyeingComputer.UserClass; +using LiveChartsCore; +using LiveChartsCore.SkiaSharpView; +using SkiaSharp; using System; using System.Collections.Generic; using System.ComponentModel; @@ -55,6 +58,16 @@ namespace DyeingComputer base.OnStartup(e); AppDomain.CurrentDomain.AssemblyResolve += OnResolveAssembly; this.DispatcherUnhandledException += App_DispatcherUnhandledException; + + LiveCharts.Configure(config => config.HasGlobalSKTypeface(SKFontManager.Default.MatchCharacter('温'))); + LiveCharts.Configure(config => config.HasGlobalSKTypeface(SKFontManager.Default.MatchCharacter('度'))); + LiveCharts.Configure(config => config.HasGlobalSKTypeface(SKFontManager.Default.MatchCharacter('水'))); + LiveCharts.Configure(config => config.HasGlobalSKTypeface(SKFontManager.Default.MatchCharacter('位'))); + LiveCharts.Configure(config => config.HasGlobalSKTypeface(SKFontManager.Default.MatchCharacter('主'))); + LiveCharts.Configure(config => config.HasGlobalSKTypeface(SKFontManager.Default.MatchCharacter('附'))); + LiveCharts.Configure(config => config.HasGlobalSKTypeface(SKFontManager.Default.MatchCharacter('料'))); + LiveCharts.Configure(config => config.HasGlobalSKTypeface(SKFontManager.Default.MatchCharacter('药'))); + LiveCharts.Configure(config => config.HasGlobalSKTypeface(SKFontManager.Default.MatchCharacter('缸'))); } private UserClass.IniFile.IniFiles Configini = new UserClass.IniFile.IniFiles(Convert.ToString(System.AppDomain.CurrentDomain.BaseDirectory) + "DyeingComputer.ini"); diff --git a/View/CurveDiagramView.xaml b/View/CurveDiagramView.xaml index 88530e7..7ad3e36 100644 --- a/View/CurveDiagramView.xaml +++ b/View/CurveDiagramView.xaml @@ -5,12 +5,13 @@ xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:lvc="clr-namespace:LiveChartsCore.SkiaSharpView.WPF;assembly=LiveChartsCore.SkiaSharpView.WPF" xmlns:viewmodel="clr-namespace:DyeingComputer.ViewModel" + mc:Ignorable="d" Loaded="UserControl_Loaded" d:DataContext="{d:DesignInstance Type=viewmodel:CurveDiagramViewModel}" - mc:Ignorable="d" Loaded="UserControl_Loaded" - d:DesignHeight="630" d:DesignWidth="1280" VerticalAlignment="Top"> + d:DesignHeight="630" d:DesignWidth="1280"> - - - + diff --git a/View/CurveDiagramView.xaml.cs b/View/CurveDiagramView.xaml.cs index b447587..bd61a2c 100644 --- a/View/CurveDiagramView.xaml.cs +++ b/View/CurveDiagramView.xaml.cs @@ -46,23 +46,14 @@ namespace DyeingComputer.View { SQLiteHelpers = new SQLiteHelper(ChartAdress); //数据库连接路径 SQLiteHelpers.Open(); //打开数据库 - CDB = SQLiteHelpers.ExecuteDataSet("select * from Chart where DYELOT = '" + MainWindowViewModel.WorkNumder + "'", null).Tables[0]; + CDB = SQLiteHelpers.ExecuteDataSet("select * from Chart where DYELOT = '" + MainWindowViewModel.WorkNumder + "'order by Time", null).Tables[0]; SQLiteHelpers.Close(); - - - - - } + - OscChart.Series = new ISeries[] { new LineSeries - { - Values = new double[] { 2, 1, 3, 5, 3, 4, 6 }, - Fill = null - } }; } diff --git a/ViewModel/CurveDiagramViewModel.cs b/ViewModel/CurveDiagramViewModel.cs index 01b67d9..c187ec0 100644 --- a/ViewModel/CurveDiagramViewModel.cs +++ b/ViewModel/CurveDiagramViewModel.cs @@ -8,24 +8,97 @@ using System.Text; using System.Threading.Tasks; using static DyeingComputer.UserClass.SqliteHelper; using CommunityToolkit.Mvvm.ComponentModel; +using LiveChartsCore.Kernel.Sketches; +using LiveChartsCore.SkiaSharpView.Painting; +using ScottPlot.Colormaps; +using System.Drawing; +using System.Windows.Media.TextFormatting; +using System.Xml.Linq; +using SkiaSharp; namespace DyeingComputer.ViewModel { - public class CurveDiagramViewModel : ObservableObject - { - - public ISeries[] Series { get; set; } = new ISeries[] - { + public partial class CurveDiagramViewModel : ObservableObject//ViewModelBase + { + public ISeries[] Series { get; set; } = + { new LineSeries - { - Values = new double[] { 2, 1, 3, 5, 3, 4, 6 }, - Fill = null + { + Name = Properties.Resources.Temperature +"1", + Values = new double[] { 5, 0, 1000, 0, 5, 0 }, + Fill = null, + GeometrySize = 0, + // use the line smoothness property to control the curve + // it goes from 0 to 1 + // where 0 is a straight line and 1 the most curved + LineSmoothness = 1, + ScalesYAt = 0, + }, + new LineSeries + { + Name = Properties.Resources.Temperature +"2", + Values = new double[] { 7, 2, 7, 2, 7, 2 ,6,67,5,66,56,5}, + Fill = null, + GeometrySize = 0, + LineSmoothness = 1, + ScalesYAt = 0, + }, + + new LineSeries + { + Name = Properties.Resources.Flowmeter, + Values = new double[] { 7, 2, 7, 5467,6,67,5,66,56,5}, + Fill = null, + GeometrySize = 0, + LineSmoothness = 1, + ScalesYAt = 1, } }; + // You can use the DateTimeAxis class to define a date time based axis + + // The first parameter is the time between each point, in this case 1 day + // you can also use 1 year, 1 month, 1 hour, 1 minute, 1 second, 1 millisecond, etc + // The second parameter is a function that receives the value and returns the label + public Axis[] XAxes { get; set; } = + { new DateTimeAxis(TimeSpan.FromSeconds(5) , date => date.ToString("yyyy-MM-dd HH:mm:ss")) }; + + private static readonly SKColor s_blue = new SKColor(25, 118, 210); + private static readonly SKColor s_red = new SKColor(229, 57, 53); + private static readonly SKColor s_yellow = new SKColor(198, 167, 0); + + public ICartesianAxis[] YAxes { get; set; } ={ + new Axis //“units” 和 “tens” 系列将在此轴上缩放 + { + Name = Properties.Resources.Temperature +" ( °C )", + NameTextSize = 24, + NamePaint = new SolidColorPaint(s_blue), + NamePadding = new LiveChartsCore.Drawing.Padding(0, 20), + Padding = new LiveChartsCore.Drawing.Padding(0, 0, 20, 0), + TextSize = 16, + LabelsPaint = new SolidColorPaint(s_blue), + TicksPaint = new SolidColorPaint(s_blue), + SubticksPaint = new SolidColorPaint(s_blue), + DrawTicksPath = true + }, + new Axis // the "hundreds" series will be scaled on this axis + { + Name = Properties.Resources.Flowmeter +" ( L )", + NameTextSize = 24, + NamePaint = new SolidColorPaint(s_red), + NamePadding = new LiveChartsCore.Drawing.Padding(0, 20), + Padding = new LiveChartsCore.Drawing.Padding(20, 0, 0, 0), + TextSize = 16, + LabelsPaint = new SolidColorPaint(s_red), + TicksPaint = new SolidColorPaint(s_red), + SubticksPaint = new SolidColorPaint(s_red), + DrawTicksPath = true, + ShowSeparatorLines = false, + Position = LiveChartsCore.Measure.AxisPosition.End + }, }; public CurveDiagramViewModel() { - + } } } diff --git a/ViewModel/MainWindowViewModel.cs b/ViewModel/MainWindowViewModel.cs index 05b2241..2ec2c0e 100644 --- a/ViewModel/MainWindowViewModel.cs +++ b/ViewModel/MainWindowViewModel.cs @@ -67,9 +67,9 @@ namespace DyeingComputer.ViewModel Sys_workSTEPID = -1; WorkNumder = "----------"; SYS_SET(); //crbl - CountDown(); //启动循环任务 SQL_data(); //读数据库 - UPort(); //启动串口 + UPort(); //启动串口 + CountDown(); //启动循环任务 } private static int MT05;//主缸排水延时 @@ -118,6 +118,9 @@ namespace DyeingComputer.ViewModel MT40 = Convert.ToInt16(Selet_con("MT40"));// MT41 = Convert.ToInt16(Selet_con("MT41"));// MU01 = Convert.ToInt16(Selet_con("MU01"));//呼叫操作员 + MS01 = Convert.ToDouble(Selet_con("MS01")); + MS02 = Convert.ToDouble(Selet_con("MS02")); + MS03 = Convert.ToDouble(Selet_con("MS03")); S16 = Convert.ToInt16(Selet_sys("S16"));//工作信息 SM01 = Convert.ToInt16(Selet_sys("SM01"));//FG @@ -234,7 +237,16 @@ namespace DyeingComputer.ViewModel LOG_view(); IO_view(); - if (!string.IsNullOrEmpty(Name_err.ToString())) Status_Str = Name_err.ToString(); + if (!string.IsNullOrEmpty(Name_err.ToString())) + { + Status_Str = Name_err.ToString(); + if (Alert_red) { Alert_red = false; Alert_bell = false; }//关报警 + } + else + { + Alert_red = !Alert_red; + Alert_bell = !Alert_bell; + } } void Tick_Event_5S(object sender, EventArgs e)//Tick_Event周期执行事件5S {