diff --git a/InSituLaboratory.Entities/Sensor/CH4IsotopeModel.cs b/InSituLaboratory.Entities/Sensor/CH4IsotopeModel.cs new file mode 100644 index 0000000..78f2bfa --- /dev/null +++ b/InSituLaboratory.Entities/Sensor/CH4IsotopeModel.cs @@ -0,0 +1,105 @@ +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; + +namespace InSituLaboratory.Entities.Sensor +{ + /// + /// 甲烷同位素分析仪 + /// + public class CH4IsotopeModel + { + /// + /// 主键 + /// + [Key] + 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; } + + /// + /// C1浓度 + /// + public float C1 { get; set; } + + /// + /// C2浓度 + /// + public float C2 { get; set; } + + /// + /// 丰度 + /// + public float Abundance { get; set; } + + + [NotMapped] + public int DataIdNum { get; set; } + + + public ChartsModel CH4IsotopeChartsC1 { get; set; } = new ChartsModel() + { + Values = new ChartValues(), + Value_Name = "C1浓度", + X_Time = new List(), + Y_MinValue = Convert.ToInt32(tools.GetAppSetting("甲烷同位素分析仪C1浓度Min")), + Y_MaxValue = Convert.ToInt32(tools.GetAppSetting("甲烷同位素分析仪C1浓度Max")) + + }; + + public ChartsModel CH4IsotopeChartsC2 { get; set; } = new ChartsModel() + { + Values = new ChartValues(), + Value_Name = "C2浓度", + X_Time = new List(), + Y_MinValue = Convert.ToInt32(tools.GetAppSetting("甲烷同位素分析仪C2浓度Min")), + Y_MaxValue = Convert.ToInt32(tools.GetAppSetting("甲烷同位素分析仪C2浓度Max")) + + }; + + public ChartsModel CH4IsotopeChartsAbundance { 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 86f3fe2..6880555 100644 --- a/InSituLaboratory.IService/Sensor/ISensorService.cs +++ b/InSituLaboratory.IService/Sensor/ISensorService.cs @@ -101,6 +101,34 @@ namespace InSituLaboratory.IService.Sensor #endregion + #region 甲烷同位素分析仪 + + /// + /// 获取甲烷同位素分析仪数据 + /// + /// + IEnumerable GetCh4Isotope(); + + /// + /// 获取甲烷同位素分析仪数据--图表 + /// + /// + /// + /// + /// + /// + IEnumerable GetCh4ISotopeData(); + + /// + /// 获取甲烷同位素分析仪数据--分页 按时间倒序排序 + /// + /// + /// + /// + /// + /// + IEnumerable GetCh4ISotopeData(string key, int pageSize, int pageIndex, out int totalCount); + #endregion } } diff --git a/InSituLaboratory.Models/Sendsor/CH4IsotopeModels.cs b/InSituLaboratory.Models/Sendsor/CH4IsotopeModels.cs new file mode 100644 index 0000000..d51d50f --- /dev/null +++ b/InSituLaboratory.Models/Sendsor/CH4IsotopeModels.cs @@ -0,0 +1,70 @@ +using InSituLaboratory.Entities; +using LiveCharts; +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations.Schema; +using System.ComponentModel.DataAnnotations; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace InSituLaboratory.Models.Sendsor +{ + /// + /// 甲烷同位素分析仪 + /// + public class CH4IsotopeModels + { + /// + /// 主键 + /// + 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; } + + /// + /// C1浓度 + /// + public float C1 { get; set; } + + /// + /// C2浓度 + /// + public float C2 { get; set; } + + /// + /// 丰度 + /// + public float Abundance { get; set; } + + } +} diff --git a/InSituLaboratory.ORM/NoimptyDbContext.cs b/InSituLaboratory.ORM/NoimptyDbContext.cs index 9894716..ca01787 100644 --- a/InSituLaboratory.ORM/NoimptyDbContext.cs +++ b/InSituLaboratory.ORM/NoimptyDbContext.cs @@ -78,5 +78,6 @@ namespace InSituLaboratory.ORM public virtual DbSet MEMSSpModel { get; set; } public virtual DbSet MEMSZpModel { get; set; } public virtual DbSet ColorMSModel { get; set; } + public virtual DbSet CH4IsotopeModel { get; set; } } } diff --git a/InSituLaboratory.Service/Sensor/SensorService.cs b/InSituLaboratory.Service/Sensor/SensorService.cs index 8119b75..5b0cb37 100644 --- a/InSituLaboratory.Service/Sensor/SensorService.cs +++ b/InSituLaboratory.Service/Sensor/SensorService.cs @@ -147,5 +147,48 @@ namespace InSituLaboratory.Service.Sensor #endregion + + #region 甲烷同位素分析仪 + + /// + /// 获取甲烷同位素分析仪数据 + /// + /// + public IEnumerable GetCh4Isotope() + { + return this.Query(m => true).OrderByDescending(n => n.CreateTime).AsNoTracking(); + } + + /// + /// 获取甲烷同位素分析仪数据---图表 + /// + /// + /// + /// + /// + /// + public IEnumerable GetCh4ISotopeData() + { + return this.Query(m => true).OrderBy(m => m.CreateTime).AsNoTracking().ToList(); + } + + /// + /// 获取甲烷同位素分析仪数据--分页 按时间倒序排序 + /// + /// + /// + /// + /// + /// + public IEnumerable GetCh4ISotopeData(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 + } } diff --git a/InSituLaboratory/App.config b/InSituLaboratory/App.config index 6799887..94f36f7 100644 --- a/InSituLaboratory/App.config +++ b/InSituLaboratory/App.config @@ -53,6 +53,13 @@ + + + + + + + diff --git a/InSituLaboratory/Base/CSVDownload.cs b/InSituLaboratory/Base/CSVDownload.cs index d15c404..a0b240b 100644 --- a/InSituLaboratory/Base/CSVDownload.cs +++ b/InSituLaboratory/Base/CSVDownload.cs @@ -234,6 +234,7 @@ namespace InSituLaboratory.Base } #endregion + #region ColorMSModel /// /// 获取类的属性集合(以便生成CSV文件的所有Column标题) @@ -331,5 +332,95 @@ namespace InSituLaboratory.Base return successFlag; } #endregion + + + #region CH4IsotopeModel + /// + /// 获取类的属性集合(以便生成CSV文件的所有Column标题) + /// + /// + public static PropertyInfo[] GetCH4IsotopeInfoArray() + { + PropertyInfo[] props = null; + try + { + Type type = typeof(CH4IsotopeModels); + 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 SaveCh4IsotopeDataToCSVFile(ObservableCollection BaseStationList, string filePath) + { + bool successFlag = true; + + StringBuilder strColumn = new StringBuilder(); + StringBuilder strValue = new StringBuilder(); + StreamWriter sw = null; + PropertyInfo[] props = GetCH4IsotopeInfoArray(); + + 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].C1); + strValue.Append(","); + strValue.Append(BaseStationList[i].C2); + strValue.Append(","); + strValue.Append(BaseStationList[i].Abundance); + + + 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/CH4IsotopeViewModel.cs b/InSituLaboratory/ViewModels/Pages/Sensor/CH4IsotopeViewModel.cs index fb78d75..ae4fcc5 100644 --- a/InSituLaboratory/ViewModels/Pages/Sensor/CH4IsotopeViewModel.cs +++ b/InSituLaboratory/ViewModels/Pages/Sensor/CH4IsotopeViewModel.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,178 @@ namespace InSituLaboratory.ViewModels.Pages.Sensor /// public class CH4IsotopeViewModel : ViewModelBase { - public CH4IsotopeViewModel(IRegionManager regionManager) : base(regionManager) + + #region 实体类 + public CH4IsotopeModel cH4IsotopeModel { get; set; } = new CH4IsotopeModel(); + public PaginationModel PaginationModel { get; set; } = new PaginationModel(); + + public ObservableCollection cH4IsotopeModellist { get; set; } = new ObservableCollection(); + public ObservableCollection cH4IsotopeModelslist { get; set; } = new ObservableCollection(); + + public DispatcherTimer timerDownloadDataMsgHidden = new DispatcherTimer(); + #endregion + + ISensorService _iSensorService; + public CH4IsotopeViewModel(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() + { + ///状态数据展示 + cH4IsotopeModellist.Clear(); + cH4IsotopeModelslist.Clear(); + cH4IsotopeModel.CH4IsotopeChartsC1.Values.Clear(); + cH4IsotopeModel.CH4IsotopeChartsC1.X_Time.Clear(); + cH4IsotopeModel.CH4IsotopeChartsC2.Values.Clear(); + cH4IsotopeModel.CH4IsotopeChartsC2.X_Time.Clear(); + cH4IsotopeModel.CH4IsotopeChartsAbundance.Values.Clear(); + cH4IsotopeModel.CH4IsotopeChartsAbundance.X_Time.Clear(); + + var CH4Isotopelistforchart = _iSensorService.GetCh4ISotopeData(); + var CH4Isotopelist = _iSensorService.GetCh4ISotopeData(SearchKey, PaginationModel.PageSize, PaginationModel.PageIndex, out int totalCount); + + + ///状态监控 + if (CH4Isotopelist.Count() != 0) + { + var data = _iSensorService.GetCh4Isotope().FirstOrDefault(); + cH4IsotopeModel.Tem = data.Tem; + cH4IsotopeModel.Hum = data.Hum; + cH4IsotopeModel.Pressure = data.Pressure; + cH4IsotopeModel.Insulation = data.Insulation; + cH4IsotopeModel.SamplingTime = data.SamplingTime; + } + + ///列表清单数据 + int index = 0; + foreach (var item in CH4Isotopelist) + { + index++; + cH4IsotopeModellist.Add(new CH4IsotopeModel + { + 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, + C1 = item.C1, + C2 = item.C2, + Abundance = item.Abundance + }); + } + + ///图表数据及下载 + int indexm = 0; + foreach (var item in CH4Isotopelistforchart) + { + indexm++; + cH4IsotopeModelslist.Add(new CH4IsotopeModels + { + Id = indexm, + SamplingTime = item.SamplingTime, + CreateTime = item.CreateTime, + Tem = item.Tem, + Hum = item.Hum, + Pressure = item.Pressure, + Insulation = item.Insulation, + C1 = item.C1, + C2 = item.C2, + Abundance = item.Abundance + }); + if (cH4IsotopeModel.CH4IsotopeChartsC1.Values.Count >= Convert.ToInt32(tools.GetAppSetting("Chart_Limit"))) + { + cH4IsotopeModel.CH4IsotopeChartsC1.Values.RemoveAt(0); + cH4IsotopeModel.CH4IsotopeChartsC1.X_Time.RemoveAt(0); + } + if (cH4IsotopeModel.CH4IsotopeChartsC2.Values.Count >= Convert.ToInt32(tools.GetAppSetting("Chart_Limit"))) + { + cH4IsotopeModel.CH4IsotopeChartsC2.Values.RemoveAt(0); + cH4IsotopeModel.CH4IsotopeChartsC2.X_Time.RemoveAt(0); + } + if (cH4IsotopeModel.CH4IsotopeChartsAbundance.Values.Count >= Convert.ToInt32(tools.GetAppSetting("Chart_Limit"))) + { + cH4IsotopeModel.CH4IsotopeChartsAbundance.Values.RemoveAt(0); + cH4IsotopeModel.CH4IsotopeChartsAbundance.X_Time.RemoveAt(0); + } + + cH4IsotopeModel.CH4IsotopeChartsC1.Values.Add(Convert.ToSingle(item.C1)); + cH4IsotopeModel.CH4IsotopeChartsC1.X_Time.Add(item.SamplingTime.ToShortTimeString()); + cH4IsotopeModel.CH4IsotopeChartsC2.Values.Add(Convert.ToSingle(item.C2)); + cH4IsotopeModel.CH4IsotopeChartsC2.X_Time.Add(item.SamplingTime.ToShortTimeString()); + cH4IsotopeModel.CH4IsotopeChartsAbundance.Values.Add(Convert.ToSingle(item.Abundance)); + cH4IsotopeModel.CH4IsotopeChartsAbundance.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.SaveCh4IsotopeDataToCSVFile(cH4IsotopeModelslist, 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/CH4IsotopeView.xaml b/InSituLaboratory/Views/Pages/Sensor/CH4IsotopeView.xaml index 331ad9d..d2f7a96 100644 --- a/InSituLaboratory/Views/Pages/Sensor/CH4IsotopeView.xaml +++ b/InSituLaboratory/Views/Pages/Sensor/CH4IsotopeView.xaml @@ -3,10 +3,289 @@ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" + xmlns:converters="clr-namespace:InSituLaboratory.Base;assembly=InSituLaboratory.Base" + xmlns:zxc="clr-namespace:InSituLaboratory.Controls;assembly=InSituLaboratory.Controls" + xmlns:lvc="clr-namespace:LiveCharts.Wpf;assembly=LiveCharts.Wpf" xmlns:local="clr-namespace:InSituLaboratory.Views.Pages.Sensor" - mc:Ignorable="d" - d:DesignHeight="450" d:DesignWidth="800"> + mc:Ignorable="d" Template="{StaticResource PageSearchAndDownloadTempalte}" + FontFamily="{StaticResource DigitalDisplay}"> + + + + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/InSituLaboratory/Views/Pages/Sensor/CH4IsotopeView.xaml.cs b/InSituLaboratory/Views/Pages/Sensor/CH4IsotopeView.xaml.cs index a0ccf2a..54d3c20 100644 --- a/InSituLaboratory/Views/Pages/Sensor/CH4IsotopeView.xaml.cs +++ b/InSituLaboratory/Views/Pages/Sensor/CH4IsotopeView.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; + } + } } }