From 1ce3db0540cbe34ab3d80fb014ac24680d225eff Mon Sep 17 00:00:00 2001 From: lyw <刘耀文@DESKTOP-E1TI268> Date: Fri, 20 Sep 2024 18:02:24 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8E=86=E5=8F=B2=E6=9B=B2=E7=BA=BF=E6=9F=A5?= =?UTF-8?q?=E8=AF=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- BPASmartClient.Academy/App.xaml.cs | 3 +- BPASmartClient.Academy/Model/HistorySqlite.cs | 125 ++++++++ BPASmartClient.Academy/Model/Sqlite.cs | 2 +- .../View/HistoryChartView.xaml | 298 +++++++++++++++++- .../View/HistoryChartView.xaml.cs | 105 +++++- .../ViewModel/HistoryChartViewModel.cs | 46 +++ 6 files changed, 564 insertions(+), 15 deletions(-) create mode 100644 BPASmartClient.Academy/Model/HistorySqlite.cs diff --git a/BPASmartClient.Academy/App.xaml.cs b/BPASmartClient.Academy/App.xaml.cs index 859c4845..97014c62 100644 --- a/BPASmartClient.Academy/App.xaml.cs +++ b/BPASmartClient.Academy/App.xaml.cs @@ -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(); - } } diff --git a/BPASmartClient.Academy/Model/HistorySqlite.cs b/BPASmartClient.Academy/Model/HistorySqlite.cs new file mode 100644 index 00000000..06006444 --- /dev/null +++ b/BPASmartClient.Academy/Model/HistorySqlite.cs @@ -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 recipeCharts { get; set; } = new ObservableCollection(); + 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().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().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 SelectName(string Name) + { + try + { + return Db.Queryable().Where(o => o.Name == Name).ToList(); + } + catch (Exception) + { + return null; + } + } + public List SelectId(string id) + { + try + { + return Db.Queryable().Where(o => o.Id == id).ToList(); + } + catch (Exception) + { + return null; + } + } + } +} diff --git a/BPASmartClient.Academy/Model/Sqlite.cs b/BPASmartClient.Academy/Model/Sqlite.cs index 88c69012..54a05226 100644 --- a/BPASmartClient.Academy/Model/Sqlite.cs +++ b/BPASmartClient.Academy/Model/Sqlite.cs @@ -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() diff --git a/BPASmartClient.Academy/View/HistoryChartView.xaml b/BPASmartClient.Academy/View/HistoryChartView.xaml index 793c303a..6f2169bc 100644 --- a/BPASmartClient.Academy/View/HistoryChartView.xaml +++ b/BPASmartClient.Academy/View/HistoryChartView.xaml @@ -1,16 +1,292 @@ - + - + + + + - + + + + + + +