diff --git a/InSituLaboratory.Entities/Sensor/SequencerModel.cs b/InSituLaboratory.Entities/Sensor/SequencerModel.cs index 5a3e977..2f1fd88 100644 --- a/InSituLaboratory.Entities/Sensor/SequencerModel.cs +++ b/InSituLaboratory.Entities/Sensor/SequencerModel.cs @@ -1,4 +1,5 @@ -using System; +using LiveCharts; +using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; @@ -70,8 +71,25 @@ namespace InSituLaboratory.Entities.Sensor public int DataIdNum { get; set; } + public ChartsModel SequencerChartsTem { 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 SequencerChartsCon { 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 c84af73..b3a9ee3 100644 --- a/InSituLaboratory.IService/Sensor/ISensorService.cs +++ b/InSituLaboratory.IService/Sensor/ISensorService.cs @@ -159,6 +159,35 @@ namespace InSituLaboratory.IService.Sensor IEnumerable GetCO2ISotopeData(string key, int pageSize, int pageIndex, out int totalCount); #endregion + #region 测序仪 + + /// + /// 获取测序仪数据 + /// + /// + IEnumerable GetSequencer(); + + /// + /// 获取测序仪数据--图表 + /// + /// + /// + /// + /// + /// + IEnumerable GetSequencerData(); + + /// + /// 获取测序仪数据--分页 按时间倒序排序 + /// + /// + /// + /// + /// + /// + IEnumerable GetSequencerData(string key, int pageSize, int pageIndex, out int totalCount); + #endregion + } } diff --git a/InSituLaboratory.Service/Sensor/SensorService.cs b/InSituLaboratory.Service/Sensor/SensorService.cs index 2c6d692..1f68dbf 100644 --- a/InSituLaboratory.Service/Sensor/SensorService.cs +++ b/InSituLaboratory.Service/Sensor/SensorService.cs @@ -234,6 +234,49 @@ namespace InSituLaboratory.Service.Sensor #endregion + #region 测序仪 + + /// + /// 获取测序仪数据 + /// + /// + public IEnumerable GetSequencer() + { + return this.Query(m => true).OrderByDescending(n => n.CreateTime).AsNoTracking(); + } + + /// + /// 获取测序仪数据---图表 + /// + /// + /// + /// + /// + /// + public IEnumerable GetSequencerData() + { + return this.Query(m => true).OrderBy(m => m.CreateTime).AsNoTracking().ToList(); + } + + /// + /// 获取测序仪数据--分页 按时间倒序排序 + /// + /// + /// + /// + /// + /// + public IEnumerable GetSequencerData(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 8f86080..2275246 100644 --- a/InSituLaboratory/App.config +++ b/InSituLaboratory/App.config @@ -61,7 +61,6 @@ - @@ -70,6 +69,11 @@ + + + + + diff --git a/InSituLaboratory/Base/CSVDownload.cs b/InSituLaboratory/Base/CSVDownload.cs index 15604d0..822a40b 100644 --- a/InSituLaboratory/Base/CSVDownload.cs +++ b/InSituLaboratory/Base/CSVDownload.cs @@ -514,5 +514,94 @@ namespace InSituLaboratory.Base return successFlag; } #endregion + + + #region 二氧化碳同位素分析仪 + /// + /// 获取类的属性集合(以便生成CSV文件的所有Column标题) + /// + /// + public static PropertyInfo[] GetSequencerInfoArray() + { + PropertyInfo[] props = null; + try + { + Type type = typeof(SequencerModels); + 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 SaveSequencerDataToCSVFile(ObservableCollection BaseStationList, string filePath) + { + bool successFlag = true; + + StringBuilder strColumn = new StringBuilder(); + StringBuilder strValue = new StringBuilder(); + StreamWriter sw = null; + PropertyInfo[] props = GetSequencerInfoArray(); + + 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].ReagentTemperature); + strValue.Append(","); + strValue.Append(BaseStationList[i].SampleConcentration); + strValue.Append(","); + strValue.Append(BaseStationList[i].CurrentWorkflow); + + 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/SequencerViewModel.cs b/InSituLaboratory/ViewModels/Pages/Sensor/SequencerViewModel.cs index 41451fa..5a68497 100644 --- a/InSituLaboratory/ViewModels/Pages/Sensor/SequencerViewModel.cs +++ b/InSituLaboratory/ViewModels/Pages/Sensor/SequencerViewModel.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,167 @@ namespace InSituLaboratory.ViewModels.Pages.Sensor /// internal class SequencerViewModel : ViewModelBase { - public SequencerViewModel(IRegionManager regionManager) : base(regionManager) + #region 实体类 + public SequencerModel sequencerModel { get; set; } = new SequencerModel(); + public PaginationModel PaginationModel { get; set; } = new PaginationModel(); + + public ObservableCollection sequencerModellist { get; set; } = new ObservableCollection(); + public ObservableCollection sequencerModelslist { get; set; } = new ObservableCollection(); + + public DispatcherTimer timerDownloadDataMsgHidden = new DispatcherTimer(); + #endregion + + ISensorService _iSensorService; + public SequencerViewModel(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() + { + sequencerModellist.Clear(); + sequencerModelslist.Clear(); + sequencerModel.SequencerChartsTem.Values.Clear(); + sequencerModel.SequencerChartsTem.X_Time.Clear(); + sequencerModel.SequencerChartsCon.Values.Clear(); + sequencerModel.SequencerChartsCon.X_Time.Clear(); + + var sequencerlistforchart = _iSensorService.GetSequencerData(); + var sequencerlist = _iSensorService.GetSequencerData(SearchKey, PaginationModel.PageSize, PaginationModel.PageIndex, out int totalCount); + + ///状态监控 + if (sequencerlist.Count() != 0) + { + var data = _iSensorService.GetSequencer().FirstOrDefault(); + sequencerModel.Tem = data.Tem; + sequencerModel.Hum = data.Hum; + sequencerModel.Pressure = data.Pressure; + sequencerModel.Insulation = data.Insulation; + sequencerModel.SamplingTime = data.SamplingTime; + } + + ///列表清单数据 + int index = 0; + foreach (var item in sequencerlist) + { + index++; + sequencerModellist.Add(new SequencerModel + { + 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, + ReagentTemperature = item.ReagentTemperature, + SampleConcentration = item.SampleConcentration, + CurrentWorkflow = item.CurrentWorkflow + }); + } + + ///图表数据及下载 + int indexm = 0; + foreach (var item in sequencerlistforchart) + { + indexm++; + sequencerModelslist.Add(new SequencerModels + { + Id = indexm, + SamplingTime = item.SamplingTime, + CreateTime = item.CreateTime, + Tem = item.Tem, + Hum = item.Hum, + Pressure = item.Pressure, + Insulation = item.Insulation, + ReagentTemperature = item.ReagentTemperature, + SampleConcentration = item.SampleConcentration, + CurrentWorkflow = item.CurrentWorkflow + }); + if (sequencerModel.SequencerChartsTem.Values.Count >= Convert.ToInt32(tools.GetAppSetting("Chart_Limit"))) + { + sequencerModel.SequencerChartsTem.Values.RemoveAt(0); + sequencerModel.SequencerChartsTem.X_Time.RemoveAt(0); + } + + if (sequencerModel.SequencerChartsCon.Values.Count >= Convert.ToInt32(tools.GetAppSetting("Chart_Limit"))) + { + sequencerModel.SequencerChartsCon.Values.RemoveAt(0); + sequencerModel.SequencerChartsCon.X_Time.RemoveAt(0); + } + + sequencerModel.SequencerChartsTem.Values.Add(Convert.ToSingle(item.ReagentTemperature)); + sequencerModel.SequencerChartsTem.X_Time.Add(item.SamplingTime.ToShortTimeString()); + + sequencerModel.SequencerChartsCon.Values.Add(Convert.ToSingle(item.SampleConcentration)); + sequencerModel.SequencerChartsCon.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.SaveSequencerDataToCSVFile(sequencerModelslist, 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/ParticleAnalyzerView.xaml b/InSituLaboratory/Views/Pages/Sensor/ParticleAnalyzerView.xaml index 05f4fdf..296dd9d 100644 --- a/InSituLaboratory/Views/Pages/Sensor/ParticleAnalyzerView.xaml +++ b/InSituLaboratory/Views/Pages/Sensor/ParticleAnalyzerView.xaml @@ -3,9 +3,12 @@ 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/SequencerView.xaml b/InSituLaboratory/Views/Pages/Sensor/SequencerView.xaml index 8832230..7210148 100644 --- a/InSituLaboratory/Views/Pages/Sensor/SequencerView.xaml +++ b/InSituLaboratory/Views/Pages/Sensor/SequencerView.xaml @@ -3,10 +3,259 @@ 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/SequencerView.xaml.cs b/InSituLaboratory/Views/Pages/Sensor/SequencerView.xaml.cs index f96fe5a..167bb2d 100644 --- a/InSituLaboratory/Views/Pages/Sensor/SequencerView.xaml.cs +++ b/InSituLaboratory/Views/Pages/Sensor/SequencerView.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; + } + } } }