using AutoMapper; using CapMachine.Core; using CapMachine.Model; using CapMachine.Wpf.Dtos; using CapMachine.Wpf.Models; using CapMachine.Wpf.PrismEvent; using CapMachine.Wpf.Services; using CapMachine.Wpf.Views; using CsvHelper; using CsvHelper.Configuration; using Masuit.Tools; using Masuit.Tools.Win32; using Prism.Commands; using Prism.Events; using Prism.Regions; using Prism.Services.Dialogs; using System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.Globalization; using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows; using System.Windows.Controls; using System.Windows.Forms; using System.Windows.Threading; using Application = System.Windows.Application; namespace CapMachine.Wpf.ViewModels { /// /// 历史数据模型 /// public class HistoryDataViewModel : NavigationViewModel { public IDialogService DialogService { get; } public IFreeSql FreeSql { get; } public IEventAggregator EventAggregator { get; } public IMapper Mapper { get; } public ConfigService ConfigService { get; } public ILogService Logger { get; } /// /// 实例化函数 /// /// /// /// /// /// public HistoryDataViewModel(IDialogService dialogService, IFreeSql freeSql, IEventAggregator eventAggregator, IMapper mapper, ConfigService configService) { DialogService = dialogService; FreeSql = freeSql; EventAggregator = eventAggregator; Mapper = mapper; ConfigService = configService; ListChartTabGroupDto = Mapper.Map>(FreeSql.Select().Where(a => a.IsEnable == true).ToList()); ListHistoryWorkCondDto = new List() { new HistoryWorkCondDto(){ Name="测试名称1",CreateTime=DateTime.Now}, new HistoryWorkCondDto(){ Name="测试名称2",CreateTime=DateTime.Now}, new HistoryWorkCondDto(){ Name="测试名称3",CreateTime=DateTime.Now}, new HistoryWorkCondDto(){ Name="测试名称4",CreateTime=DateTime.Now}, new HistoryWorkCondDto(){ Name="测试名称5",CreateTime=DateTime.Now}, new HistoryWorkCondDto(){ Name="测试名称6",CreateTime=DateTime.Now}, new HistoryWorkCondDto(){ Name="测试名称7",CreateTime=DateTime.Now}, new HistoryWorkCondDto(){ Name="测试名称8",CreateTime=DateTime.Now}, }; //加载试验数据 ListHistoryExp = FreeSql.Select().IncludeMany(a => a.HistoryWorkCondFiles).ToList(); // Task.Run(new Action(() => { Thread.Sleep(1000); Application.Current.Dispatcher.BeginInvoke(DispatcherPriority.Normal, new Action(() => { //Thread.Sleep(TimeSpan.FromSeconds(1)); //都要加载数据 EventAggregator.GetEvent().Publish(new ChartRtSeriesActionMsg() { Machine = "History", GroupTabIndex = 0, ActionMsg = "Start" }); EventAggregator.GetEvent().Publish(new ChartRtSeriesActionMsg() { Machine = "History", GroupTabIndex = 1, ActionMsg = "Start" }); EventAggregator.GetEvent().Publish(new ChartRtSeriesActionMsg() { Machine = "History", GroupTabIndex = 2, ActionMsg = "Start" }); EventAggregator.GetEvent().Publish(new ChartRtSeriesActionMsg() { Machine = "History", GroupTabIndex = 3, ActionMsg = "Start" }); EventAggregator.GetEvent().Publish(new ChartRtSeriesActionMsg() { Machine = "History", GroupTabIndex = 4, ActionMsg = "Start" }); EventAggregator.GetEvent().Publish(new ChartRtSeriesActionMsg() { Machine = "History", GroupTabIndex = 5, ActionMsg = "Start" }); })); })); } private DelegateCommand _TestCmd; /// /// 刷新数据命令 /// public DelegateCommand TestCmd { set { _TestCmd = value; } get { if (_TestCmd == null) { _TestCmd = new DelegateCommand(() => TestCmdMethod()); } return _TestCmd; } } private bool _IsLeftDrawerOpen; /// /// 左侧的打开 /// public bool IsLeftDrawerOpen { get { return _IsLeftDrawerOpen; } set { _IsLeftDrawerOpen = value; RaisePropertyChanged(); } } private bool _IsBusy; public bool IsBusy { get { return _IsBusy; } set { _IsBusy = value; RaisePropertyChanged(); } } private string _BusyMessage = "正在加载,请稍候..."; public string BusyMessage { get { return _BusyMessage; } set { _BusyMessage = value; RaisePropertyChanged(); } } /// /// tEST /// private void TestCmdMethod() { IsLeftDrawerOpen = true; var openDrawerCommand = MaterialDesignThemes.Wpf.DrawerHost.OpenDrawerCommand; // 获取 DrawerHost 的实例 var drawerHost = Application.Current.MainWindow.FindName("HistoryDrawerHost") as MaterialDesignThemes.Wpf.DrawerHost; if (drawerHost != null) { drawerHost.IsLeftDrawerOpen = true; // 打开左侧 Drawer } //RegionManager.RequestNavigate("ProStepDrawerContentRegion", nameof(ProStepConfigPsView)); //EventAggregator.GetEvent().Publish("Right"); } private List _ListChartTabGroupDto; /// /// Tab集合信息数据 /// public List ListChartTabGroupDto { get { return _ListChartTabGroupDto; } set { _ListChartTabGroupDto = value; RaisePropertyChanged(); } } /// /// 当前的Machine /// private string CurSelectedMachine { get; set; } = "History"; #region 试验工况信息 /// /// 当前的文档数据 /// public List CsvRecordModels { get; set; } = new List(); private List _ListHistoryExp; /// /// 试验集合信息数据 /// public List ListHistoryExp { get { return _ListHistoryExp; } set { _ListHistoryExp = value; RaisePropertyChanged(); } } private List _ListHistoryWorkCondFile; /// /// 试验集合保存的文件信息数据 /// public List ListHistoryWorkCondFile { get { return _ListHistoryWorkCondFile; } set { _ListHistoryWorkCondFile = value; RaisePropertyChanged(); } } private List _ListHistoryWorkCondDto; /// /// 历史工况集合信息数据 /// public List ListHistoryWorkCondDto { get { return _ListHistoryWorkCondDto; } set { _ListHistoryWorkCondDto = value; RaisePropertyChanged(); } } private HistoryExp _SelectedHistoryExp; /// /// 当前选中的行数据 /// public HistoryExp SelectedHistoryExp { get { return _SelectedHistoryExp; } set { _SelectedHistoryExp = value; RaisePropertyChanged(); } } /// /// 当前搜索的工况条件 /// public ExpSearchDto CurExpSearchDto { get; set; } = new ExpSearchDto() { StartTime = DateTime.Now.AddDays(-1), EndTime = DateTime.Now }; private DelegateCommand _GridSelectionChangedCmd; /// /// 试验信息选中行数据命令 /// public DelegateCommand GridSelectionChangedCmd { set { _GridSelectionChangedCmd = value; } get { if (_GridSelectionChangedCmd == null) { _GridSelectionChangedCmd = new DelegateCommand((par) => GridSelectionChangedCmdMethod(par)); } return _GridSelectionChangedCmd; } } private void GridSelectionChangedCmdMethod(object par) { if (par == null) { return; } if (par is HistoryExp) { SelectedHistoryExp = par as HistoryExp; var files = SelectedHistoryExp!.HistoryWorkCondFiles!; foreach (var f in files) { if (f != null) f.IsSelected = false; } ListHistoryWorkCondFile = files.ToList(); //ListHistoryWorkCondFile = ListHistoryWorkCondFile.ToList(); return; } if ((par as SelectionChangedEventArgs)!.AddedItems.Count == 0) { return; } //先判断是否是正确的集合数据,防止DataGrid的数据源刷新导致的触发事件 var Selecteddata = (par as SelectionChangedEventArgs)!.AddedItems[0] as HistoryExp; ////选中的行数据 //var Selecteddata = (par as DataGrid)!.SelectedItem as HistoryExp; ////选中的列数据 //var selectedColumn = (par as DataGrid)!.CurrentColumn; //SelectedIndex= ProParsHelper.GetIndexByName(selectedColumn); //SelectedProStepDto = par as ProStepDto; if (Selecteddata != null) { SelectedHistoryExp = Selecteddata; var files = SelectedHistoryExp.HistoryWorkCondFiles!; foreach (var f in files) { if (f != null) f.IsSelected = false; } ListHistoryWorkCondFile = files; ListHistoryWorkCondFile = ListHistoryWorkCondFile.ToList(); } } private DelegateCommand _FilterHistoryDataFileCmd; /// /// 搜索数据 /// public DelegateCommand FilterHistoryDataFileCmd { set { _FilterHistoryDataFileCmd = value; } get { if (_FilterHistoryDataFileCmd == null) { _FilterHistoryDataFileCmd = new DelegateCommand(() => FilterHistoryDataFileCmdMethod()); } return _FilterHistoryDataFileCmd; } } /// /// 搜索的执行方法 /// private void FilterHistoryDataFileCmdMethod() { var Query = FreeSql.Select(); if (!string.IsNullOrEmpty(CurExpSearchDto.ExpName)) { Query = Query.Where(a => a.Name.Contains(CurExpSearchDto.ExpName.Trim())); } if (CurExpSearchDto.StartTime != null && CurExpSearchDto.EndTime != null) { Query = Query.Where(a => a.CreateTime >= CurExpSearchDto.StartTime); Query = Query.Where(a => a.CreateTime <= CurExpSearchDto.EndTime); } //加载试验数据 ListHistoryExp = Query.IncludeMany(a => a.HistoryWorkCondFiles).ToList(); } /// /// Append to the file. /// CsvConfiguration CSVconfig = new CsvConfiguration(CultureInfo.CurrentCulture) { // Don't write the header again. HasHeaderRecord = false, }; private DelegateCommand _SelectAllFilesCmd; public DelegateCommand SelectAllFilesCmd { set { _SelectAllFilesCmd = value; } get { if (_SelectAllFilesCmd == null) { _SelectAllFilesCmd = new DelegateCommand((par) => SelectAllFilesCmdMethod(par)); } return _SelectAllFilesCmd; } } private void SelectAllFilesCmdMethod(object par) { bool isChecked = false; if (par is bool b) { isChecked = b; } else { var nb = par as bool?; if (nb.HasValue) isChecked = nb.Value; else { var sb = par as string; if (!string.IsNullOrWhiteSpace(sb)) { bool.TryParse(sb, out isChecked); } } } if (ListHistoryWorkCondFile == null) return; foreach (var f in ListHistoryWorkCondFile) { if (f != null) f.IsSelected = isChecked; } // 触发刷新 ListHistoryWorkCondFile = ListHistoryWorkCondFile.ToList(); } Stopwatch stopwatch = new Stopwatch(); private DelegateCommand _HistoryDataFileCmd; /// /// 获取试验数据的命令 /// public DelegateCommand HistoryDataFileCmd { set { _HistoryDataFileCmd = value; } get { if (_HistoryDataFileCmd == null) { _HistoryDataFileCmd = new DelegateCommand(() => HistoryDataFileCmdMethod()); } return _HistoryDataFileCmd; } } /// /// 获取试验数据的命令的执行方法 /// private async void HistoryDataFileCmdMethod() { if (SelectedHistoryExp == null) { System.Windows.MessageBox.Show("请选中后再操作", "提示", MessageBoxButton.OK, MessageBoxImage.Hand); return; } var files = new List(); if (ListHistoryWorkCondFile != null) { foreach (var f in ListHistoryWorkCondFile) { if (f != null && f.IsSelected) { files.Add(f); } } } files = files .Where(f => f != null) .GroupBy(f => string.IsNullOrWhiteSpace(f.FilePath) ? $"ID:{f.Id}" : f.FilePath) .Select(g => g.First()) .ToList(); if (files.Count == 0) { System.Windows.MessageBox.Show("请先在右侧勾选至少一个CSV文件", "提示", MessageBoxButton.OK, MessageBoxImage.Information); return; } BusyMessage = "正在加载CSV数据,请稍候..."; IsBusy = true; var loaded = new List(); string errorText = string.Empty; stopwatch.Start(); try { await Task.Run(() => { var errors = new StringBuilder(); for (int i = 0; i < files.Count; i++) { var f = files[i]; try { Application.Current.Dispatcher.Invoke(() => { BusyMessage = $"正在加载({i + 1}/{files.Count}):{System.IO.Path.GetFileName(f?.FilePath)}"; }); if (f == null) continue; if (string.IsNullOrWhiteSpace(f.FilePath)) { errors.AppendLine("发现空的文件地址"); continue; } if (!File.Exists(f.FilePath)) { errors.AppendLine($"没有发现地址对应的文件: {f.FilePath}"); continue; } var rec = ReadCsvFile(f.FilePath); if (rec != null && rec.Count > 0) { loaded.AddRange(rec); } } catch (Exception ex) { errors.AppendLine($"读取CSV失败: {ex.Message}"); } } errorText = errors.ToString(); }); if (!string.IsNullOrWhiteSpace(errorText)) { System.Windows.MessageBox.Show(errorText, "读取提示", MessageBoxButton.OK, MessageBoxImage.Warning); } CsvRecordModels = new List(); if (loaded != null && loaded.Count > 0) { CsvRecordModels = loaded .Where(r => r != null) .OrderBy(r => r.CreateTime) .ToList(); Application.Current.Dispatcher.Invoke(() => { EventAggregator.GetEvent().Publish(new HistoryDataToChartMsg() { Machine = "History", Data = CsvRecordModels }); }); } } finally { stopwatch.Stop(); Console.WriteLine("加载CSV数据耗时::{0}", stopwatch.Elapsed.TotalSeconds.ToString()); stopwatch.Reset(); IsBusy = false; IsLeftDrawerOpen = false; } } private List ReadCsvFile(string filePath) { var result = new List(); lock (ConfigService.CsvFileLock) { using (var reader = new StreamReader(filePath, Encoding.UTF8)) using (var csv = new CsvReader(reader, CultureInfo.CurrentCulture)) { csv.Context.RegisterClassMap(); var list = csv.GetRecords().ToList(); if (list != null && list.Count > 0) { // 过滤无效时间,避免排序异常 result = list.Where(r => r != null && r.CreateTime != default && r.CreateTime != DateTime.MinValue).ToList(); } } } return result; } //ReportDataCmd private DelegateCommand _ReportDataCmd; /// /// 导出数据命令 /// public DelegateCommand ReportDataCmd { set { _ReportDataCmd = value; } get { if (_ReportDataCmd == null) { _ReportDataCmd = new DelegateCommand((p) => ReportDataCmdMethod(p)); } return _ReportDataCmd; } } /// /// 导出数据的方法 /// /// /// private void ReportDataCmdMethod(object par) { if (SelectedHistoryExp != null && SelectedHistoryExp.HistoryWorkCondFiles != null) { switch ((string)par) { case "CSV": var TargetFilePath = GetFilePath(); if (TargetFilePath != null) { lock (ConfigService.CsvFileLock) { foreach (var item in SelectedHistoryExp.HistoryWorkCondFiles) { if (!string.IsNullOrEmpty(item.FilePath)) { if (File.Exists(item.FilePath))//是否存在文件 { //Copy文件 CopyToFile(item.FilePath, TargetFilePath); } else { System.Windows.MessageBox.Show("没有发现地址对应的文件"); } } else { System.Windows.MessageBox.Show("发现空的文件地址"); } } } } break; case "EXCEL": break; default: break; } IsLeftDrawerOpen = false; } else { System.Windows.MessageBox.Show("请选中后再操作", "提示", MessageBoxButton.OK, MessageBoxImage.Hand); } } /// /// 获取保存文件的路径 /// /// public string GetFilePath() { using (var folderBrowserDialog = new FolderBrowserDialog()) { folderBrowserDialog.Description = "请选择一个文件夹"; folderBrowserDialog.ShowNewFolderButton = true; if (folderBrowserDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK) { string selectedPath = folderBrowserDialog.SelectedPath; // 处理选中的文件夹路径 return selectedPath; } else { return null; } } } /// /// 复制文件到指定的文件夹中 /// /// /// public void CopyToFile(string SourceFilePath, string TargetFilePath) { // 生成目标文件的完整路径 string destinationFilePath = Path.Combine(TargetFilePath, Path.GetFileName(SourceFilePath)); // 复制文件 File.Copy(SourceFilePath, destinationFilePath, true); // true 表示如果目标文件已存在,则覆盖 } /// /// 复制文件夹及文件 /// /// 原文件路径 /// 目标文件路径 /// public int CopyFolder2(string sourceFolder, string destFolder) { try { string folderName = System.IO.Path.GetFileName(sourceFolder); string destfolderdir = System.IO.Path.Combine(destFolder, folderName); string[] filenames = System.IO.Directory.GetFileSystemEntries(sourceFolder); foreach (string file in filenames)// 遍历所有的文件和目录 { if (System.IO.Directory.Exists(file)) { string currentdir = System.IO.Path.Combine(destfolderdir, System.IO.Path.GetFileName(file)); if (!System.IO.Directory.Exists(currentdir)) { System.IO.Directory.CreateDirectory(currentdir); } CopyFolder2(file, destfolderdir); } else { string srcfileName = System.IO.Path.Combine(destfolderdir, System.IO.Path.GetFileName(file)); if (!System.IO.Directory.Exists(destfolderdir)) { System.IO.Directory.CreateDirectory(destfolderdir); } System.IO.File.Copy(file, srcfileName); } } return 1; } catch (Exception e) { System.Windows.MessageBox.Show(e.Message); return 0; } } #endregion #region TabIndex信息 private int _SeletedGroupTabIndex; /// /// 选中的Group TabIndex /// public int SeletedGroupTabIndex { get { return _SeletedGroupTabIndex; } set { _SeletedGroupTabIndex = value; RaisePropertyChanged(); } } private int _SeletedGroup1ListViewTabIndex; /// /// 选中的Group1的 ListView TabIndex /// 单游标和双游标的显示数据 /// public int SeletedGroup1ListViewTabIndex { get { return _SeletedGroup1ListViewTabIndex; } set { _SeletedGroup1ListViewTabIndex = value; RaisePropertyChanged(); } } private int _SeletedGroup2ListViewTabIndex; /// /// 选中的Group2的 ListView TabIndex /// 单游标和双游标的显示数据 /// public int SeletedGroup2ListViewTabIndex { get { return _SeletedGroup2ListViewTabIndex; } set { _SeletedGroup2ListViewTabIndex = value; RaisePropertyChanged(); } } private int _SeletedGroup3ListViewTabIndex; /// /// 选中的Group3的 ListView TabIndex /// 单游标和双游标的显示数据 /// public int SeletedGroup3ListViewTabIndex { get { return _SeletedGroup3ListViewTabIndex; } set { _SeletedGroup3ListViewTabIndex = value; RaisePropertyChanged(); } } private int _SeletedGroup4ListViewTabIndex; /// /// 选中的Group4的 ListView TabIndex /// 单游标和双游标的显示数据 /// public int SeletedGroup4ListViewTabIndex { get { return _SeletedGroup4ListViewTabIndex; } set { _SeletedGroup4ListViewTabIndex = value; RaisePropertyChanged(); } } private int _SeletedGroup5ListViewTabIndex; /// /// 选中的Group5的 ListView TabIndex /// 单游标和双游标的显示数据 /// public int SeletedGroup5ListViewTabIndex { get { return _SeletedGroup5ListViewTabIndex; } set { _SeletedGroup5ListViewTabIndex = value; RaisePropertyChanged(); } } private int _SeletedGroup6ListViewTabIndex; /// /// 选中的Group6的 ListView TabIndex /// 单游标和双游标的显示数据 /// public int SeletedGroup6ListViewTabIndex { get { return _SeletedGroup6ListViewTabIndex; } set { _SeletedGroup6ListViewTabIndex = value; RaisePropertyChanged(); } } private int _SeletedGroup7ListViewTabIndex; /// /// 选中的Group7的 ListView TabIndex /// 单游标和双游标的显示数据 /// public int SeletedGroup7ListViewTabIndex { get { return _SeletedGroup7ListViewTabIndex; } set { _SeletedGroup7ListViewTabIndex = value; RaisePropertyChanged(); } } private int _SeletedGroup8ListViewTabIndex; /// /// 选中的Group8的 ListView TabIndex /// 单游标和双游标的显示数据 /// public int SeletedGroup8ListViewTabIndex { get { return _SeletedGroup8ListViewTabIndex; } set { _SeletedGroup8ListViewTabIndex = value; RaisePropertyChanged(); } } #endregion private DelegateCommand _ChartConfigCmd; /// /// 编辑曲线数据 /// public DelegateCommand ChartConfigCmd { set { _ChartConfigCmd = value; } get { if (_ChartConfigCmd == null) { _ChartConfigCmd = new DelegateCommand(() => ChartConfigCmdMethod()); } return _ChartConfigCmd; } } /// /// 编辑曲线数据执行方法 /// private void ChartConfigCmdMethod() { //弹窗 DialogService.ShowDialog("DialogHistoryChartRtConfigView", new DialogParameters() { { "TabIndex", SeletedGroupTabIndex } }, (par) => { if (par.Result == ButtonResult.OK) { //程序名称 var ReturnValue = par.Parameters.GetValue("Name"); //返回数据,刷新Chart EventAggregator.GetEvent().Publish(new ChartRtSeriesActionMsg() { Machine = CurSelectedMachine, GroupTabIndex = SeletedGroupTabIndex, ActionMsg = "Start" }); } else if (par.Result == ButtonResult.Cancel) { //取消 } }); } private DelegateCommand _BtnSwitchGroupCmd; /// /// 切换组的指令 /// public DelegateCommand BtnSwitchGroupCmd { set { _BtnSwitchGroupCmd = value; } get { if (_BtnSwitchGroupCmd == null) { _BtnSwitchGroupCmd = new DelegateCommand((p) => BtnSwitchGroupCmdMethod(p)); } return _BtnSwitchGroupCmd; } } private void BtnSwitchGroupCmdMethod(object par) { var Data = (ChartTabGroupDto)par; SeletedGroupTabIndex = Data.Index; EventAggregator.GetEvent().Publish(new ChartTabGroupSwitchMsg() { Machine = CurSelectedMachine, GroupTabIndex = SeletedGroupTabIndex }); //switch (Data.Index) //{ // case 0: // SeletedGroupTabIndex = Data.Index; // EventAggregator.GetEvent().Publish(Data.Name); // break; // case 1: // SeletedGroupTabIndex = Data.Index; // EventAggregator.GetEvent().Publish(Data.Name); // break; // case 2: // SeletedGroupTabIndex = Data.Index; // EventAggregator.GetEvent().Publish(Data.Name); // break; // default: // break; //} } private DelegateCommand _BtnChartSetCmd; /// /// Chart 设置命令 多次设置 /// public DelegateCommand BtnChartSetCmd { set { _BtnChartSetCmd = value; } get { if (_BtnChartSetCmd == null) { _BtnChartSetCmd = new DelegateCommand((p) => BtnChartSetCmdMethod(p)); } return _BtnChartSetCmd; } } private void BtnChartSetCmdMethod(object par) { //两个动作,曲线显示游标和不同的游标对应不同的ListView信息 var Info = (string)par; switch (Info) { case "单游标": //单双游标需要界面配合切换ListView信息 SwitchListViewTab(SeletedGroupTabIndex, "单游标"); //Chart操作 EventAggregator.GetEvent().Publish(new ChartSetMsg() { Machine = CurSelectedMachine, GroupTabIndex = SeletedGroupTabIndex, ChartSetInfo = "单游标" }); break; case "双游标": //单双游标需要界面配合切换ListView信息 SwitchListViewTab(SeletedGroupTabIndex, "双游标"); //Chart操作 EventAggregator.GetEvent().Publish(new ChartSetMsg() { Machine = CurSelectedMachine, GroupTabIndex = SeletedGroupTabIndex, ChartSetInfo = "双游标" }); break; case "游标置中": //Chart操作 EventAggregator.GetEvent().Publish(new ChartSetMsg() { Machine = CurSelectedMachine, GroupTabIndex = SeletedGroupTabIndex, ChartSetInfo = "游标置中" }); break; case "游标放大": //Chart操作 EventAggregator.GetEvent().Publish(new ChartSetMsg() { Machine = CurSelectedMachine, GroupTabIndex = SeletedGroupTabIndex, ChartSetInfo = "游标放大" }); break; case "保存照片": //临时的屏蔽状态 ConfigService.ChartSavePageTempState = true; //Chart操作 EventAggregator.GetEvent().Publish(new ChartSetMsg() { Machine = CurSelectedMachine, GroupTabIndex = SeletedGroupTabIndex, ChartSetInfo = "保存照片" }); break; default: break; } } private DelegateCommand _BtnChartScrollEnableSetCmd; /// /// Chart 启用和非启用的设置命令 带有状态的 /// 实时滚动 /// public DelegateCommand BtnChartScrollEnableSetCmd { set { _BtnChartScrollEnableSetCmd = value; } get { if (_BtnChartScrollEnableSetCmd == null) { _BtnChartScrollEnableSetCmd = new DelegateCommand((p) => BtnChartScrollEnableSetCmdMethod(p)); } return _BtnChartScrollEnableSetCmd; } } private void BtnChartScrollEnableSetCmdMethod(object par) { //是否滚动设置 var Result = (bool)par; EventAggregator.GetEvent().Publish(new ChartSetEnableMsg() { Machine = CurSelectedMachine, GroupTabIndex = SeletedGroupTabIndex, ChartSetInfo = "实时滚动", Enable = Result }); } private DelegateCommand _BtnChartLegendHideEnableSetCmd; /// /// Chart 启用和非启用的设置命令 带有状态的 /// 图例隐藏 /// public DelegateCommand BtnChartLegendHideEnableSetCmd { set { _BtnChartLegendHideEnableSetCmd = value; } get { if (_BtnChartLegendHideEnableSetCmd == null) { _BtnChartLegendHideEnableSetCmd = new DelegateCommand((p) => BtnChartLegendHideEnableSetCmdMethod(p)); } return _BtnChartLegendHideEnableSetCmd; } } private void BtnChartLegendHideEnableSetCmdMethod(object par) { //是否滚动设置 var Result = (bool)par; EventAggregator.GetEvent().Publish(new ChartSetEnableMsg() { Machine = CurSelectedMachine, GroupTabIndex = SeletedGroupTabIndex, ChartSetInfo = "隐藏图例", Enable = Result }); } private DelegateCommand _TabItemCmd; /// /// Tab内容编辑命令 /// public DelegateCommand TabItemCmd { set { _TabItemCmd = value; } get { if (_TabItemCmd == null) { _TabItemCmd = new DelegateCommand((p) => TabItemCmdMethod()); } return _TabItemCmd; } } private void TabItemCmdMethod() { //弹窗 DialogService.ShowDialog("DialogChartGroupTabView", new DialogParameters() { { "Name", "" } }, (par) => { if (par.Result == ButtonResult.OK) { //程序名称 ListChartTabGroupDto = par.Parameters.GetValue>("NewData"); //返回数据,刷新Chart } else if (par.Result == ButtonResult.Cancel) { //取消 } }); } /// /// 切换ListViewTab的信息 /// private void SwitchListViewTab(int GroupIndex, string Msg) { //全部组同时设置 if (Msg == "单游标") { SeletedGroup1ListViewTabIndex = 0; SeletedGroup2ListViewTabIndex = 0; SeletedGroup3ListViewTabIndex = 0; SeletedGroup4ListViewTabIndex = 0; SeletedGroup5ListViewTabIndex = 0; SeletedGroup6ListViewTabIndex = 0; SeletedGroup7ListViewTabIndex = 0; SeletedGroup8ListViewTabIndex = 0; } else { SeletedGroup1ListViewTabIndex = 1; SeletedGroup2ListViewTabIndex = 1; SeletedGroup3ListViewTabIndex = 1; SeletedGroup4ListViewTabIndex = 1; SeletedGroup5ListViewTabIndex = 1; SeletedGroup6ListViewTabIndex = 1; SeletedGroup7ListViewTabIndex = 1; SeletedGroup8ListViewTabIndex = 1; } //只设置当前组信息 //switch (GroupIndex) // { // case 0: // if (Msg == "单游标") // { // SeletedGroup1ListViewTabIndex = 0; // return; // } // SeletedGroup1ListViewTabIndex = 1; // break; // case 1: // if (Msg == "单游标") // { // SeletedGroup2ListViewTabIndex = 0; // return; // } // SeletedGroup2ListViewTabIndex = 1; // break; // case 2: // if (Msg == "单游标") // { // SeletedGroup3ListViewTabIndex = 0; // return; // } // SeletedGroup3ListViewTabIndex = 1; // break; // case 3: // if (Msg == "单游标") // { // SeletedGroup4ListViewTabIndex = 0; // return; // } // SeletedGroup4ListViewTabIndex = 1; // break; // case 4: // if (Msg == "单游标") // { // SeletedGroup5ListViewTabIndex = 0; // return; // } // SeletedGroup5ListViewTabIndex = 1; // break; // case 5: // if (Msg == "单游标") // { // SeletedGroup6ListViewTabIndex = 0; // return; // } // SeletedGroup6ListViewTabIndex = 1; // break; // case 6: // if (Msg == "单游标") // { // SeletedGroup7ListViewTabIndex = 0; // return; // } // SeletedGroup7ListViewTabIndex = 1; // break; // case 7: // if (Msg == "单游标") // { // SeletedGroup8ListViewTabIndex = 0; // return; // } // SeletedGroup8ListViewTabIndex = 1; // break; // default: // break; // } } private DelegateCommand _ChartYAxisConfigCmd; /// /// 编辑曲线Y轴配置的数据 /// public DelegateCommand ChartYAxisConfigCmd { set { _ChartYAxisConfigCmd = value; } get { if (_ChartYAxisConfigCmd == null) { _ChartYAxisConfigCmd = new DelegateCommand(() => ChartYAxisConfigCmdMethod()); } return _ChartYAxisConfigCmd; } } private void ChartYAxisConfigCmdMethod() { //弹窗 DialogService.ShowDialog("DialogYAxisConfigView", new DialogParameters() { { "Name", "" } }, (par) => { if (par.Result == ButtonResult.OK) { //程序名称 //ListChartTabGroupDto = par.Parameters.GetValue>("NewData"); //返回数据,刷新Chart var Data = FreeSql.Select().ToList(); EventAggregator.GetEvent().Publish(new ChartYAxisConfigMsg() { Machine = CurSelectedMachine, GroupTabIndex = SeletedGroupTabIndex, ConfigChartYAxes = Data }); } else if (par.Result == ButtonResult.Cancel) { //取消 } }); } } }