From 499d0b5730e09463a50c3b4eb6f2dde377c3f9d2 Mon Sep 17 00:00:00 2001 From: MoYue Date: Mon, 2 Sep 2024 10:59:06 +0800 Subject: [PATCH] =?UTF-8?q?=E9=A2=97=E7=B2=92=E7=89=A9=E5=88=86=E6=9E=90?= =?UTF-8?q?=E4=BB=AA=E9=A1=B5=E9=9D=A2=E5=BC=80=E5=8F=91=E5=AE=8C=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Sensor/ParticleAnalyzerModel.cs | 70 ++++- .../Sensor/ISensorService.cs | 29 ++ .../Sendsor/ParticleAnalyzerModels.cs | 85 ++++++ .../Sensor/SensorService.cs | 44 +++ InSituLaboratory/App.config | 8 + InSituLaboratory/Base/CSVDownload.cs | 98 +++++- .../Pages/Sensor/ParticleAnalyzerViewModel.cs | 192 +++++++++++- .../Views/Pages/Sensor/CO2IsotopeView.xaml | 2 +- .../Pages/Sensor/ParticleAnalyzerView.xaml | 282 +++++++++++++++++- .../Pages/Sensor/ParticleAnalyzerView.xaml.cs | 26 ++ 10 files changed, 830 insertions(+), 6 deletions(-) create mode 100644 InSituLaboratory.Models/Sendsor/ParticleAnalyzerModels.cs diff --git a/InSituLaboratory.Entities/Sensor/ParticleAnalyzerModel.cs b/InSituLaboratory.Entities/Sensor/ParticleAnalyzerModel.cs index 3d6bb1d..ef8dc6a 100644 --- a/InSituLaboratory.Entities/Sensor/ParticleAnalyzerModel.cs +++ b/InSituLaboratory.Entities/Sensor/ParticleAnalyzerModel.cs @@ -1,6 +1,8 @@ -using System; +using LiveCharts; +using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; using System.Linq; using System.Text; using System.Threading.Tasks; @@ -48,8 +50,74 @@ namespace InSituLaboratory.Entities.Sensor /// public string? Insulation { get; set; } + /// + /// 颗粒物序号 + /// + public float? ParticleNumber { get; set; } + + /// + /// 坐标X + /// + public float? CoordinateX { get; set; } + + /// + /// 坐标Y + /// + public float? CoordinateY { get; set; } + + /// + /// 类型 + /// + public float? Type { get; set; } + + /// + /// 面积 + /// + public float? Area { get; set; } + + /// + /// 长 + /// + public float? Long { get; set; } + + /// + /// 宽 + /// + public float? Wide { get; set; } + [NotMapped] + public int DataIdNum { get; set; } + + public ChartsModel AreaCharts { get; set; } = new ChartsModel() + { + Values = new ChartValues(), + Value_Name = "面积", + X_Time = new List(), + Y_MinValue = Convert.ToInt32(tools.GetAppSetting("颗粒物分析仪面积Min")), + Y_MaxValue = Convert.ToInt32(tools.GetAppSetting("颗粒物分析仪面积Max")) + + }; + + public ChartsModel LongCharts { get; set; } = new ChartsModel() + { + Values = new ChartValues(), + Value_Name = "长", + X_Time = new List(), + Y_MinValue = Convert.ToInt32(tools.GetAppSetting("颗粒物分析仪长Min")), + Y_MaxValue = Convert.ToInt32(tools.GetAppSetting("颗粒物分析仪长Max")) + + }; + + public ChartsModel WideCharts { get; set; } = new ChartsModel() + { + Values = new ChartValues(), + Value_Name = "宽", + X_Time = new List(), + Y_MinValue = Convert.ToInt32(tools.GetAppSetting("颗粒物分析仪宽Min")), + Y_MaxValue = Convert.ToInt32(tools.GetAppSetting("颗粒物分析仪宽Max")) + + }; } } diff --git a/InSituLaboratory.IService/Sensor/ISensorService.cs b/InSituLaboratory.IService/Sensor/ISensorService.cs index 7b60e71..21a6583 100644 --- a/InSituLaboratory.IService/Sensor/ISensorService.cs +++ b/InSituLaboratory.IService/Sensor/ISensorService.cs @@ -191,6 +191,35 @@ namespace InSituLaboratory.IService.Sensor #endregion + #region 颗粒物分析仪 + /// + /// 获取颗粒物分析仪数据 + /// + /// + IEnumerable GetParticleAnalyzer(); + + /// + /// 获取颗粒物分析仪数据--图表 + /// + /// + /// + /// + /// + /// + IEnumerable GetParticleAnalyzerData(); + + /// + /// 获取颗粒物分析仪数据--分页 按时间倒序排序 + /// + /// + /// + /// + /// + /// + IEnumerable GetParticleAnalyzerData(string key, int pageSize, int pageIndex, out int totalCount); + #endregion + + #region 与下位机通信电源开关类 --- 传感器 /// /// 获取传感器电源开关数据 diff --git a/InSituLaboratory.Models/Sendsor/ParticleAnalyzerModels.cs b/InSituLaboratory.Models/Sendsor/ParticleAnalyzerModels.cs new file mode 100644 index 0000000..6d5a34f --- /dev/null +++ b/InSituLaboratory.Models/Sendsor/ParticleAnalyzerModels.cs @@ -0,0 +1,85 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace InSituLaboratory.Models.Sendsor +{ + /// + /// 颗粒物分析仪 + /// + public class ParticleAnalyzerModels + { + /// + /// 主键 + /// + public int Id { get; set; } + + /// + /// 采样时间 + /// + public DateTime SamplingTime { get; set; } + + /// + /// 记录时间 + /// + public DateTime CreateTime { get; set; } + + /// + /// 故障代码--设备温度 (未开启/未监控 正常 警报 故障) + /// + public string? Tem { get; set; } + + /// + /// 故障代码--设备湿度 (未开启/未监控 正常 警报 故障) + /// + public string? Hum { get; set; } + + /// + /// 故障代码--压力 (未开启/未监控 正常 警报 故障) + /// + public string? Pressure { get; set; } + + /// + /// 故障代码--绝缘 (未开启/未监控 正常 警报 故障) + /// + public string? Insulation { get; set; } + + /// + /// 颗粒物序号 + /// + public float? ParticleNumber { get; set; } + + /// + /// 坐标X + /// + public float? CoordinateX { get; set; } + + /// + /// 坐标Y + /// + public float? CoordinateY { get; set; } + + /// + /// 类型 + /// + public float? Type { get; set; } + + /// + /// 面积 + /// + public float? Area { get; set; } + + /// + /// 长 + /// + public float? Long { get; set; } + + /// + /// 宽 + /// + public float? Wide { get; set; } + } +} diff --git a/InSituLaboratory.Service/Sensor/SensorService.cs b/InSituLaboratory.Service/Sensor/SensorService.cs index 4f65f16..8f5c06c 100644 --- a/InSituLaboratory.Service/Sensor/SensorService.cs +++ b/InSituLaboratory.Service/Sensor/SensorService.cs @@ -278,6 +278,50 @@ namespace InSituLaboratory.Service.Sensor } #endregion + + + #region 颗粒物分析仪 + + /// + /// 获取颗粒物分析仪数据 + /// + /// + public IEnumerable GetParticleAnalyzer() + { + return this.Query(m => true).OrderByDescending(n => n.CreateTime).AsNoTracking(); + } + + /// + /// 获取颗粒物分析仪数据---图表 + /// + /// + /// + /// + /// + /// + public IEnumerable GetParticleAnalyzerData() + { + return this.Query(m => true).OrderBy(m => m.CreateTime).AsNoTracking().ToList(); + } + + /// + /// 获取颗粒物分析仪数据--分页 按时间倒序排序 + /// + /// + /// + /// + /// + /// + public IEnumerable GetParticleAnalyzerData(string key, int pageSize, int pageIndex, out int totalCount) + { + var pResult = this.QueryPage(m => string.IsNullOrEmpty(key) || m.SamplingTime.ToString().Contains(key), pageSize, pageIndex, order => order.SamplingTime.ToString(), false); + + totalCount = pResult.TotalCount; + + return pResult.DataList; + } + + #endregion #region /// /// 获取传感器电源开关数据 diff --git a/InSituLaboratory/App.config b/InSituLaboratory/App.config index 43ef31c..3f25117 100644 --- a/InSituLaboratory/App.config +++ b/InSituLaboratory/App.config @@ -77,6 +77,14 @@ + + + + + + + + diff --git a/InSituLaboratory/Base/CSVDownload.cs b/InSituLaboratory/Base/CSVDownload.cs index 822a40b..c8a84a7 100644 --- a/InSituLaboratory/Base/CSVDownload.cs +++ b/InSituLaboratory/Base/CSVDownload.cs @@ -516,7 +516,7 @@ namespace InSituLaboratory.Base #endregion - #region 二氧化碳同位素分析仪 + #region 测序仪 /// /// 获取类的属性集合(以便生成CSV文件的所有Column标题) /// @@ -603,5 +603,101 @@ namespace InSituLaboratory.Base return successFlag; } #endregion + + #region 颗粒物分析仪 + /// + /// 获取类的属性集合(以便生成CSV文件的所有Column标题) + /// + /// + public static PropertyInfo[] GetParticleInfoArray() + { + PropertyInfo[] props = null; + try + { + Type type = typeof(ParticleAnalyzerModels); + object obj = Activator.CreateInstance(type); + props = type.GetProperties(BindingFlags.Public | BindingFlags.Instance); + } + catch (Exception ex) + { } + return props; + } + + + /// + /// Save the List data to CSV file + /// + /// data source + /// file path + /// success flag + public static bool SaveParticleDataToCSVFile(ObservableCollection BaseStationList, string filePath) + { + bool successFlag = true; + + StringBuilder strColumn = new StringBuilder(); + StringBuilder strValue = new StringBuilder(); + StreamWriter sw = null; + PropertyInfo[] props = GetParticleInfoArray(); + + try + { + sw = new StreamWriter(filePath); + for (int i = 0; i < props.Length; i++) + { + strColumn.Append(props[i].Name); + strColumn.Append(","); + } + strColumn.Remove(strColumn.Length - 1, 1); + sw.WriteLine(strColumn); //write the column name + + for (int i = 0; i < BaseStationList.Count; i++) + { + strValue.Remove(0, strValue.Length); //clear the temp row value + strValue.Append(BaseStationList[i].Id); + strValue.Append(","); + strValue.Append(BaseStationList[i].CreateTime); + strValue.Append(","); + strValue.Append(BaseStationList[i].SamplingTime); + strValue.Append(","); + strValue.Append(BaseStationList[i].Tem); + strValue.Append(","); + strValue.Append(BaseStationList[i].Hum); + strValue.Append(","); + strValue.Append(BaseStationList[i].Pressure); + strValue.Append(","); + strValue.Append(BaseStationList[i].Insulation); + strValue.Append(","); + strValue.Append(BaseStationList[i].ParticleNumber); + strValue.Append(","); + strValue.Append(BaseStationList[i].CoordinateX); + strValue.Append(","); + strValue.Append(BaseStationList[i].CoordinateY); + strValue.Append(","); + strValue.Append(BaseStationList[i].Type); + strValue.Append(","); + strValue.Append(BaseStationList[i].Area); + strValue.Append(","); + strValue.Append(BaseStationList[i].Long); + strValue.Append(","); + strValue.Append(BaseStationList[i].Wide); + + sw.WriteLine(strValue); //write the row value + } + } + catch (Exception ex) + { + successFlag = false; + } + finally + { + if (sw != null) + { + sw.Dispose(); + } + } + + return successFlag; + } + #endregion } } diff --git a/InSituLaboratory/ViewModels/Pages/Sensor/ParticleAnalyzerViewModel.cs b/InSituLaboratory/ViewModels/Pages/Sensor/ParticleAnalyzerViewModel.cs index 5b9052a..b3afe07 100644 --- a/InSituLaboratory/ViewModels/Pages/Sensor/ParticleAnalyzerViewModel.cs +++ b/InSituLaboratory/ViewModels/Pages/Sensor/ParticleAnalyzerViewModel.cs @@ -1,9 +1,20 @@ -using Prism.Regions; +using InSituLaboratory.Base; +using InSituLaboratory.Controls; +using InSituLaboratory.Entities; +using InSituLaboratory.Entities.Sensor; +using InSituLaboratory.IService.Sensor; +using InSituLaboratory.Models.Sendsor; +using Prism.Commands; +using Prism.Regions; using System; using System.Collections.Generic; +using System.Collections.ObjectModel; using System.Linq; using System.Text; using System.Threading.Tasks; +using System.Windows; +using System.Windows.Media; +using System.Windows.Threading; namespace InSituLaboratory.ViewModels.Pages.Sensor { @@ -12,9 +23,186 @@ namespace InSituLaboratory.ViewModels.Pages.Sensor /// public class ParticleAnalyzerViewModel : ViewModelBase { - public ParticleAnalyzerViewModel(IRegionManager regionManager) : base(regionManager) + #region 实体类 + public ParticleAnalyzerModel ParticleModel { get; set; } = new ParticleAnalyzerModel(); + public PaginationModel PaginationModel { get; set; } = new PaginationModel(); + public DispatcherTimer timerDownloadDataMsgHidden = new DispatcherTimer(); + public ObservableCollection ParticleModellist { get; set; } = new ObservableCollection(); + public ObservableCollection ParticleModelslist { get; set; } = new ObservableCollection(); + + + #endregion + + ISensorService _iSensorService; + public ParticleAnalyzerViewModel(IRegionManager regionManager, ISensorService iSensorService) : base(regionManager) { PageTitle = "颗粒物分析仪"; + _iSensorService = iSensorService; + + PaginationModel.NavCommand = new DelegateCommand(index => + { + PaginationModel.PageIndex = int.Parse(index.ToString()); + this.Refresh(); + }); + + this.Refresh(); + + timerDownloadDataMsgHidden.Interval = TimeSpan.FromSeconds(2); + timerDownloadDataMsgHidden.Tick += TimerDownloadDataMsgHidden_Tick; + } + + /// + /// 数据刷新 + /// + public override void Refresh() + { + ParticleModellist.Clear(); + ParticleModelslist.Clear(); + ParticleModel.AreaCharts.Values.Clear(); + ParticleModel.AreaCharts.X_Time.Clear(); + ParticleModel.LongCharts.Values.Clear(); + ParticleModel.LongCharts.X_Time.Clear(); + ParticleModel.WideCharts.Values.Clear(); + ParticleModel.WideCharts.X_Time.Clear(); + + var particaleforChart = _iSensorService.GetParticleAnalyzerData(); + var particalelist = _iSensorService.GetParticleAnalyzerData(SearchKey, PaginationModel.PageSize, PaginationModel.PageIndex, out int totalCount); + + ///状态监控 + if (particalelist.Count() != 0) + { + var data = _iSensorService.GetParticleAnalyzer().FirstOrDefault(); + ParticleModel.Tem = data.Tem; + ParticleModel.Hum = data.Hum; + ParticleModel.Pressure = data.Pressure; + ParticleModel.Insulation = data.Insulation; + ParticleModel.SamplingTime = data.SamplingTime; + } + + ///列表清单数据 + int index = 0; + foreach (var item in particalelist) + { + index++; + ParticleModellist.Add(new ParticleAnalyzerModel + { + DataIdNum = index + (PaginationModel.PageIndex - 1) * PaginationModel.PageSize, + SamplingTime = item.SamplingTime, + CreateTime = item.CreateTime, + Tem = item.Tem, + Hum = item.Hum, + Pressure = item.Pressure, + Insulation = item.Insulation, + ParticleNumber = item.ParticleNumber, + CoordinateX = item.CoordinateX, + CoordinateY = item.CoordinateY, + Type = item.Type, + Area = item.Area, + Long = item.Long, + Wide = item.Wide + }); + } + + ///图表数据及下载 + int indexm = 0; + foreach (var item in particaleforChart) + { + indexm++; + ParticleModelslist.Add(new ParticleAnalyzerModels + { + Id = indexm, + SamplingTime = item.SamplingTime, + CreateTime = item.CreateTime, + Tem = item.Tem, + Hum = item.Hum, + Pressure = item.Pressure, + Insulation = item.Insulation, + ParticleNumber = item.ParticleNumber, + CoordinateX = item.CoordinateX, + CoordinateY = item.CoordinateY, + Type = item.Type, + Area = item.Area, + Long = item.Long, + Wide = item.Wide + }); + if (ParticleModel.AreaCharts.Values.Count >= Convert.ToInt32(tools.GetAppSetting("Chart_Limit"))) + { + ParticleModel.AreaCharts.Values.RemoveAt(0); + ParticleModel.AreaCharts.X_Time.RemoveAt(0); + } + + if (ParticleModel.LongCharts.Values.Count >= Convert.ToInt32(tools.GetAppSetting("Chart_Limit"))) + { + ParticleModel.LongCharts.Values.RemoveAt(0); + ParticleModel.LongCharts.X_Time.RemoveAt(0); + } + + if (ParticleModel.WideCharts.Values.Count >= Convert.ToInt32(tools.GetAppSetting("Chart_Limit"))) + { + ParticleModel.WideCharts.Values.RemoveAt(0); + ParticleModel.WideCharts.X_Time.RemoveAt(0); + } + + + ParticleModel.AreaCharts.Values.Add(Convert.ToSingle(item.Area)); + ParticleModel.AreaCharts.X_Time.Add(item.SamplingTime.ToShortTimeString()); + ParticleModel.LongCharts.Values.Add(Convert.ToSingle(item.Long)); + ParticleModel.LongCharts.X_Time.Add(item.SamplingTime.ToShortTimeString()); + ParticleModel.WideCharts.Values.Add(Convert.ToSingle(item.Wide)); + ParticleModel.WideCharts.X_Time.Add(item.SamplingTime.ToShortTimeString()); + } + + // 刷新分页组件的页码 + PaginationModel.FillPageNumbers(totalCount); + + } + + + /// + /// 数据下载 + /// + public override void DoDownload() + { + DownloadDataBtnIsEnabled = false; + DownloadDataMsgVisibility = Visibility.Visible; + string baseStationFolder = ""; + System.Windows.Forms.FolderBrowserDialog FolderBrowserDialog = new System.Windows.Forms.FolderBrowserDialog(); //选择文件夹 + //注意,此处一定要手动引入System.Window.Forms空间,否则你如果使用默认的DialogResult会发现没有OK属性 + if (FolderBrowserDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK) + { + baseStationFolder = FolderBrowserDialog.SelectedPath + "\\"; + } + + //string baseStationFolder = tools.GetAppSetting("MEMSSPFolder"); + string savePath = CSVDownload.CreateFile(baseStationFolder, "颗粒物分析仪_Data_" + DateTime.Now.ToString("yyyyMMddHHmmss"), "csv"); + + bool result = CSVDownload.SaveParticleDataToCSVFile(ParticleModelslist, savePath); + if (result) + { + DownloadDataMsg = "下载数据成功!"; + DownloadDataMsgForeground = new SolidColorBrush(Colors.Green); + } + else + { + DownloadDataMsg = "下载数据失败!"; + DownloadDataMsgForeground = new SolidColorBrush(Colors.Red); + } + + timerDownloadDataMsgHidden.Start(); + DownloadDataBtnIsEnabled = true; + } + + /// + /// 定时器停止 + /// + /// + /// + private void TimerDownloadDataMsgHidden_Tick(object sender, EventArgs e) + { + DownloadDataMsgVisibility = Visibility.Hidden; + + // 停止定时器 + (sender as DispatcherTimer).Stop(); } } } diff --git a/InSituLaboratory/Views/Pages/Sensor/CO2IsotopeView.xaml b/InSituLaboratory/Views/Pages/Sensor/CO2IsotopeView.xaml index 0d6b5d2..9bac09a 100644 --- a/InSituLaboratory/Views/Pages/Sensor/CO2IsotopeView.xaml +++ b/InSituLaboratory/Views/Pages/Sensor/CO2IsotopeView.xaml @@ -49,7 +49,7 @@ - + diff --git a/InSituLaboratory/Views/Pages/Sensor/ParticleAnalyzerView.xaml b/InSituLaboratory/Views/Pages/Sensor/ParticleAnalyzerView.xaml index 5f88510..096bb64 100644 --- a/InSituLaboratory/Views/Pages/Sensor/ParticleAnalyzerView.xaml +++ b/InSituLaboratory/Views/Pages/Sensor/ParticleAnalyzerView.xaml @@ -9,7 +9,287 @@ xmlns:local="clr-namespace:InSituLaboratory.Views.Pages.Sensor" mc:Ignorable="d" Template="{StaticResource PageSearchAndDownloadTempalte}" FontFamily="{StaticResource DigitalDisplay}"> + + + + + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/InSituLaboratory/Views/Pages/Sensor/ParticleAnalyzerView.xaml.cs b/InSituLaboratory/Views/Pages/Sensor/ParticleAnalyzerView.xaml.cs index 0059728..be8518a 100644 --- a/InSituLaboratory/Views/Pages/Sensor/ParticleAnalyzerView.xaml.cs +++ b/InSituLaboratory/Views/Pages/Sensor/ParticleAnalyzerView.xaml.cs @@ -24,5 +24,31 @@ namespace InSituLaboratory.Views.Pages.Sensor { InitializeComponent(); } + + /// + /// 支持鼠标滚轮上下滚动 + /// + /// + /// + private void ScrollViewer_PreviewMouseWheel(object sender, MouseWheelEventArgs e) + { + ScrollViewer viewer = sv; //sv 为Scrollview的名字,在Xaml文件中定义。 + if (viewer == null) return; + double num = Math.Abs((int)(e.Delta / 2)); + double offset = 0.0; + if (e.Delta > 0) + { + offset = Math.Max((double)0.0, (double)(viewer.VerticalOffset - num));//viewer.VerticalOffset获取包含滚动内容的垂直偏移量的值。 + } + else + { + offset = Math.Min(viewer.ScrollableHeight, viewer.VerticalOffset + num); + } + if (offset != viewer.VerticalOffset) + { + viewer.ScrollToVerticalOffset(offset);//将 ScrollViewer 内的内容滚动到指定的垂直偏移量位置。 + e.Handled = true; + } + } } }