Files
CapMachine/CapMachine.Wpf/ViewModels/HistoryDataViewModel.cs

1240 lines
44 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
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
{
/// <summary>
/// 历史数据模型
/// </summary>
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; }
/// <summary>
/// 实例化函数
/// </summary>
/// <param name="dialogService"></param>
/// <param name="freeSql"></param>
/// <param name="eventAggregator"></param>
/// <param name="mapper"></param>
/// <param name="logger"></param>
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<List<ChartTabGroupDto>>(FreeSql.Select<HistoryChartTabGroup>().Where(a => a.IsEnable == true).ToList());
ListHistoryWorkCondDto = new List<HistoryWorkCondDto>()
{
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<HistoryExp>().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<HistoryChartRtSeriesActionEvent>().Publish(new ChartRtSeriesActionMsg() { Machine = "History", GroupTabIndex = 0, ActionMsg = "Start" });
EventAggregator.GetEvent<HistoryChartRtSeriesActionEvent>().Publish(new ChartRtSeriesActionMsg() { Machine = "History", GroupTabIndex = 1, ActionMsg = "Start" });
EventAggregator.GetEvent<HistoryChartRtSeriesActionEvent>().Publish(new ChartRtSeriesActionMsg() { Machine = "History", GroupTabIndex = 2, ActionMsg = "Start" });
EventAggregator.GetEvent<HistoryChartRtSeriesActionEvent>().Publish(new ChartRtSeriesActionMsg() { Machine = "History", GroupTabIndex = 3, ActionMsg = "Start" });
EventAggregator.GetEvent<HistoryChartRtSeriesActionEvent>().Publish(new ChartRtSeriesActionMsg() { Machine = "History", GroupTabIndex = 4, ActionMsg = "Start" });
EventAggregator.GetEvent<HistoryChartRtSeriesActionEvent>().Publish(new ChartRtSeriesActionMsg() { Machine = "History", GroupTabIndex = 5, ActionMsg = "Start" });
}));
}));
}
private DelegateCommand _TestCmd;
/// <summary>
/// 刷新数据命令
/// </summary>
public DelegateCommand TestCmd
{
set
{
_TestCmd = value;
}
get
{
if (_TestCmd == null)
{
_TestCmd = new DelegateCommand(() => TestCmdMethod());
}
return _TestCmd;
}
}
private bool _IsLeftDrawerOpen;
/// <summary>
/// 左侧的打开
/// </summary>
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(); }
}
/// <summary>
/// tEST
/// </summary>
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<ProStepDrawerEvent>().Publish("Right");
}
private List<ChartTabGroupDto> _ListChartTabGroupDto;
/// <summary>
/// Tab集合信息数据
/// </summary>
public List<ChartTabGroupDto> ListChartTabGroupDto
{
get { return _ListChartTabGroupDto; }
set { _ListChartTabGroupDto = value; RaisePropertyChanged(); }
}
/// <summary>
/// 当前的Machine
/// </summary>
private string CurSelectedMachine { get; set; } = "History";
#region
/// <summary>
/// 当前的文档数据
/// </summary>
public List<CsvRecordModel> CsvRecordModels { get; set; } = new List<CsvRecordModel>();
private List<HistoryExp> _ListHistoryExp;
/// <summary>
/// 试验集合信息数据
/// </summary>
public List<HistoryExp> ListHistoryExp
{
get { return _ListHistoryExp; }
set { _ListHistoryExp = value; RaisePropertyChanged(); }
}
private List<HistoryWorkCondFile> _ListHistoryWorkCondFile;
/// <summary>
/// 试验集合保存的文件信息数据
/// </summary>
public List<HistoryWorkCondFile> ListHistoryWorkCondFile
{
get { return _ListHistoryWorkCondFile; }
set { _ListHistoryWorkCondFile = value; RaisePropertyChanged(); }
}
private List<HistoryWorkCondDto> _ListHistoryWorkCondDto;
/// <summary>
/// 历史工况集合信息数据
/// </summary>
public List<HistoryWorkCondDto> ListHistoryWorkCondDto
{
get { return _ListHistoryWorkCondDto; }
set { _ListHistoryWorkCondDto = value; RaisePropertyChanged(); }
}
private HistoryExp _SelectedHistoryExp;
/// <summary>
/// 当前选中的行数据
/// </summary>
public HistoryExp SelectedHistoryExp
{
get { return _SelectedHistoryExp; }
set { _SelectedHistoryExp = value; RaisePropertyChanged(); }
}
/// <summary>
/// 当前搜索的工况条件
/// </summary>
public ExpSearchDto CurExpSearchDto { get; set; } = new ExpSearchDto() { StartTime = DateTime.Now.AddDays(-1), EndTime = DateTime.Now };
private DelegateCommand<object> _GridSelectionChangedCmd;
/// <summary>
/// 试验信息选中行数据命令
/// </summary>
public DelegateCommand<object> GridSelectionChangedCmd
{
set
{
_GridSelectionChangedCmd = value;
}
get
{
if (_GridSelectionChangedCmd == null)
{
_GridSelectionChangedCmd = new DelegateCommand<object>((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;
/// <summary>
/// 搜索数据
/// </summary>
public DelegateCommand FilterHistoryDataFileCmd
{
set
{
_FilterHistoryDataFileCmd = value;
}
get
{
if (_FilterHistoryDataFileCmd == null)
{
_FilterHistoryDataFileCmd = new DelegateCommand(() => FilterHistoryDataFileCmdMethod());
}
return _FilterHistoryDataFileCmd;
}
}
/// <summary>
/// 搜索的执行方法
/// </summary>
private void FilterHistoryDataFileCmdMethod()
{
var Query = FreeSql.Select<HistoryExp>();
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();
}
/// <summary>
/// Append to the file.
/// </summary>
CsvConfiguration CSVconfig = new CsvConfiguration(CultureInfo.CurrentCulture)
{
// Don't write the header again.
HasHeaderRecord = false,
};
private DelegateCommand<object> _SelectAllFilesCmd;
public DelegateCommand<object> SelectAllFilesCmd
{
set
{
_SelectAllFilesCmd = value;
}
get
{
if (_SelectAllFilesCmd == null)
{
_SelectAllFilesCmd = new DelegateCommand<object>((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;
/// <summary>
/// 获取试验数据的命令
/// </summary>
public DelegateCommand HistoryDataFileCmd
{
set
{
_HistoryDataFileCmd = value;
}
get
{
if (_HistoryDataFileCmd == null)
{
_HistoryDataFileCmd = new DelegateCommand(() => HistoryDataFileCmdMethod());
}
return _HistoryDataFileCmd;
}
}
/// <summary>
/// 获取试验数据的命令的执行方法
/// </summary>
private async void HistoryDataFileCmdMethod()
{
if (SelectedHistoryExp == null)
{
System.Windows.MessageBox.Show("请选中后再操作", "提示", MessageBoxButton.OK, MessageBoxImage.Hand);
return;
}
var files = new List<HistoryWorkCondFile>();
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<CsvRecordModel>();
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<CsvRecordModel>();
if (loaded != null && loaded.Count > 0)
{
CsvRecordModels = loaded
.Where(r => r != null)
.OrderBy(r => r.CreateTime)
.ToList();
Application.Current.Dispatcher.Invoke(() =>
{
EventAggregator.GetEvent<HistoryDataToChartEvent>().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<CsvRecordModel> ReadCsvFile(string filePath)
{
var result = new List<CsvRecordModel>();
lock (ConfigService.CsvFileLock)
{
using (var reader = new StreamReader(filePath, Encoding.UTF8))
using (var csv = new CsvReader(reader, CultureInfo.CurrentCulture))
{
csv.Context.RegisterClassMap<CsvRecordModelMap>();
var list = csv.GetRecords<CsvRecordModel>().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<object> _ReportDataCmd;
/// <summary>
/// 导出数据命令
/// </summary>
public DelegateCommand<object> ReportDataCmd
{
set
{
_ReportDataCmd = value;
}
get
{
if (_ReportDataCmd == null)
{
_ReportDataCmd = new DelegateCommand<object>((p) => ReportDataCmdMethod(p));
}
return _ReportDataCmd;
}
}
/// <summary>
/// 导出数据的方法
/// </summary>
/// <param name="p"></param>
/// <exception cref="NotImplementedException"></exception>
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);
}
}
/// <summary>
/// 获取保存文件的路径
/// </summary>
/// <returns></returns>
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;
}
}
}
/// <summary>
/// 复制文件到指定的文件夹中
/// </summary>
/// <param name="SourceFilePath"></param>
/// <param name="TargetFilePath"></param>
public void CopyToFile(string SourceFilePath, string TargetFilePath)
{
// 生成目标文件的完整路径
string destinationFilePath = Path.Combine(TargetFilePath, Path.GetFileName(SourceFilePath));
// 复制文件
File.Copy(SourceFilePath, destinationFilePath, true); // true 表示如果目标文件已存在,则覆盖
}
/// <summary>
/// 复制文件夹及文件
/// </summary>
/// <param name="sourceFolder">原文件路径</param>
/// <param name="destFolder">目标文件路径</param>
/// <returns></returns>
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;
/// <summary>
/// 选中的Group TabIndex
/// </summary>
public int SeletedGroupTabIndex
{
get { return _SeletedGroupTabIndex; }
set { _SeletedGroupTabIndex = value; RaisePropertyChanged(); }
}
private int _SeletedGroup1ListViewTabIndex;
/// <summary>
/// 选中的Group1的 ListView TabIndex
/// 单游标和双游标的显示数据
/// </summary>
public int SeletedGroup1ListViewTabIndex
{
get { return _SeletedGroup1ListViewTabIndex; }
set { _SeletedGroup1ListViewTabIndex = value; RaisePropertyChanged(); }
}
private int _SeletedGroup2ListViewTabIndex;
/// <summary>
/// 选中的Group2的 ListView TabIndex
/// 单游标和双游标的显示数据
/// </summary>
public int SeletedGroup2ListViewTabIndex
{
get { return _SeletedGroup2ListViewTabIndex; }
set { _SeletedGroup2ListViewTabIndex = value; RaisePropertyChanged(); }
}
private int _SeletedGroup3ListViewTabIndex;
/// <summary>
/// 选中的Group3的 ListView TabIndex
/// 单游标和双游标的显示数据
/// </summary>
public int SeletedGroup3ListViewTabIndex
{
get { return _SeletedGroup3ListViewTabIndex; }
set { _SeletedGroup3ListViewTabIndex = value; RaisePropertyChanged(); }
}
private int _SeletedGroup4ListViewTabIndex;
/// <summary>
/// 选中的Group4的 ListView TabIndex
/// 单游标和双游标的显示数据
/// </summary>
public int SeletedGroup4ListViewTabIndex
{
get { return _SeletedGroup4ListViewTabIndex; }
set { _SeletedGroup4ListViewTabIndex = value; RaisePropertyChanged(); }
}
private int _SeletedGroup5ListViewTabIndex;
/// <summary>
/// 选中的Group5的 ListView TabIndex
/// 单游标和双游标的显示数据
/// </summary>
public int SeletedGroup5ListViewTabIndex
{
get { return _SeletedGroup5ListViewTabIndex; }
set { _SeletedGroup5ListViewTabIndex = value; RaisePropertyChanged(); }
}
private int _SeletedGroup6ListViewTabIndex;
/// <summary>
/// 选中的Group6的 ListView TabIndex
/// 单游标和双游标的显示数据
/// </summary>
public int SeletedGroup6ListViewTabIndex
{
get { return _SeletedGroup6ListViewTabIndex; }
set { _SeletedGroup6ListViewTabIndex = value; RaisePropertyChanged(); }
}
private int _SeletedGroup7ListViewTabIndex;
/// <summary>
/// 选中的Group7的 ListView TabIndex
/// 单游标和双游标的显示数据
/// </summary>
public int SeletedGroup7ListViewTabIndex
{
get { return _SeletedGroup7ListViewTabIndex; }
set { _SeletedGroup7ListViewTabIndex = value; RaisePropertyChanged(); }
}
private int _SeletedGroup8ListViewTabIndex;
/// <summary>
/// 选中的Group8的 ListView TabIndex
/// 单游标和双游标的显示数据
/// </summary>
public int SeletedGroup8ListViewTabIndex
{
get { return _SeletedGroup8ListViewTabIndex; }
set { _SeletedGroup8ListViewTabIndex = value; RaisePropertyChanged(); }
}
#endregion
private DelegateCommand _ChartConfigCmd;
/// <summary>
/// 编辑曲线数据
/// </summary>
public DelegateCommand ChartConfigCmd
{
set
{
_ChartConfigCmd = value;
}
get
{
if (_ChartConfigCmd == null)
{
_ChartConfigCmd = new DelegateCommand(() => ChartConfigCmdMethod());
}
return _ChartConfigCmd;
}
}
/// <summary>
/// 编辑曲线数据执行方法
/// </summary>
private void ChartConfigCmdMethod()
{
//弹窗
DialogService.ShowDialog("DialogHistoryChartRtConfigView", new DialogParameters() { { "TabIndex", SeletedGroupTabIndex } }, (par) =>
{
if (par.Result == ButtonResult.OK)
{
//程序名称
var ReturnValue = par.Parameters.GetValue<string>("Name");
//返回数据刷新Chart
EventAggregator.GetEvent<HistoryChartRtSeriesActionEvent>().Publish(new ChartRtSeriesActionMsg()
{
Machine = CurSelectedMachine,
GroupTabIndex = SeletedGroupTabIndex,
ActionMsg = "Start"
});
}
else if (par.Result == ButtonResult.Cancel)
{
//取消
}
});
}
private DelegateCommand<object> _BtnSwitchGroupCmd;
/// <summary>
/// 切换组的指令
/// </summary>
public DelegateCommand<object> BtnSwitchGroupCmd
{
set
{
_BtnSwitchGroupCmd = value;
}
get
{
if (_BtnSwitchGroupCmd == null)
{
_BtnSwitchGroupCmd = new DelegateCommand<object>((p) => BtnSwitchGroupCmdMethod(p));
}
return _BtnSwitchGroupCmd;
}
}
private void BtnSwitchGroupCmdMethod(object par)
{
var Data = (ChartTabGroupDto)par;
SeletedGroupTabIndex = Data.Index;
EventAggregator.GetEvent<HistoryChartTabGroupSwitchEvent>().Publish(new ChartTabGroupSwitchMsg()
{
Machine = CurSelectedMachine,
GroupTabIndex = SeletedGroupTabIndex
});
//switch (Data.Index)
//{
// case 0:
// SeletedGroupTabIndex = Data.Index;
// EventAggregator.GetEvent<ChartGroupSwitchEvent>().Publish(Data.Name);
// break;
// case 1:
// SeletedGroupTabIndex = Data.Index;
// EventAggregator.GetEvent<ChartGroupSwitchEvent>().Publish(Data.Name);
// break;
// case 2:
// SeletedGroupTabIndex = Data.Index;
// EventAggregator.GetEvent<ChartGroupSwitchEvent>().Publish(Data.Name);
// break;
// default:
// break;
//}
}
private DelegateCommand<object> _BtnChartSetCmd;
/// <summary>
/// Chart 设置命令 多次设置
/// </summary>
public DelegateCommand<object> BtnChartSetCmd
{
set
{
_BtnChartSetCmd = value;
}
get
{
if (_BtnChartSetCmd == null)
{
_BtnChartSetCmd = new DelegateCommand<object>((p) => BtnChartSetCmdMethod(p));
}
return _BtnChartSetCmd;
}
}
private void BtnChartSetCmdMethod(object par)
{
//两个动作曲线显示游标和不同的游标对应不同的ListView信息
var Info = (string)par;
switch (Info)
{
case "单游标":
//单双游标需要界面配合切换ListView信息
SwitchListViewTab(SeletedGroupTabIndex, "单游标");
//Chart操作
EventAggregator.GetEvent<HistoryChartSetEvent>().Publish(new ChartSetMsg() { Machine = CurSelectedMachine, GroupTabIndex = SeletedGroupTabIndex, ChartSetInfo = "单游标" });
break;
case "双游标":
//单双游标需要界面配合切换ListView信息
SwitchListViewTab(SeletedGroupTabIndex, "双游标");
//Chart操作
EventAggregator.GetEvent<HistoryChartSetEvent>().Publish(new ChartSetMsg() { Machine = CurSelectedMachine, GroupTabIndex = SeletedGroupTabIndex, ChartSetInfo = "双游标" });
break;
case "游标置中":
//Chart操作
EventAggregator.GetEvent<HistoryChartSetEvent>().Publish(new ChartSetMsg() { Machine = CurSelectedMachine, GroupTabIndex = SeletedGroupTabIndex, ChartSetInfo = "游标置中" });
break;
case "游标放大":
//Chart操作
EventAggregator.GetEvent<HistoryChartSetEvent>().Publish(new ChartSetMsg() { Machine = CurSelectedMachine, GroupTabIndex = SeletedGroupTabIndex, ChartSetInfo = "游标放大" });
break;
case "保存照片":
//临时的屏蔽状态
ConfigService.ChartSavePageTempState = true;
//Chart操作
EventAggregator.GetEvent<HistoryChartSetEvent>().Publish(new ChartSetMsg() { Machine = CurSelectedMachine, GroupTabIndex = SeletedGroupTabIndex, ChartSetInfo = "保存照片" });
break;
default:
break;
}
}
private DelegateCommand<object> _BtnChartScrollEnableSetCmd;
/// <summary>
/// Chart 启用和非启用的设置命令 带有状态的
/// 实时滚动
/// </summary>
public DelegateCommand<object> BtnChartScrollEnableSetCmd
{
set
{
_BtnChartScrollEnableSetCmd = value;
}
get
{
if (_BtnChartScrollEnableSetCmd == null)
{
_BtnChartScrollEnableSetCmd = new DelegateCommand<object>((p) => BtnChartScrollEnableSetCmdMethod(p));
}
return _BtnChartScrollEnableSetCmd;
}
}
private void BtnChartScrollEnableSetCmdMethod(object par)
{
//是否滚动设置
var Result = (bool)par;
EventAggregator.GetEvent<HistoryChartSetEnableEvent>().Publish(new ChartSetEnableMsg() { Machine = CurSelectedMachine, GroupTabIndex = SeletedGroupTabIndex, ChartSetInfo = "实时滚动", Enable = Result });
}
private DelegateCommand<object> _BtnChartLegendHideEnableSetCmd;
/// <summary>
/// Chart 启用和非启用的设置命令 带有状态的
/// 图例隐藏
/// </summary>
public DelegateCommand<object> BtnChartLegendHideEnableSetCmd
{
set
{
_BtnChartLegendHideEnableSetCmd = value;
}
get
{
if (_BtnChartLegendHideEnableSetCmd == null)
{
_BtnChartLegendHideEnableSetCmd = new DelegateCommand<object>((p) => BtnChartLegendHideEnableSetCmdMethod(p));
}
return _BtnChartLegendHideEnableSetCmd;
}
}
private void BtnChartLegendHideEnableSetCmdMethod(object par)
{
//是否滚动设置
var Result = (bool)par;
EventAggregator.GetEvent<HistoryChartSetEnableEvent>().Publish(new ChartSetEnableMsg() { Machine = CurSelectedMachine, GroupTabIndex = SeletedGroupTabIndex, ChartSetInfo = "隐藏图例", Enable = Result });
}
private DelegateCommand<object> _TabItemCmd;
/// <summary>
/// Tab内容编辑命令
/// </summary>
public DelegateCommand<object> TabItemCmd
{
set
{
_TabItemCmd = value;
}
get
{
if (_TabItemCmd == null)
{
_TabItemCmd = new DelegateCommand<object>((p) => TabItemCmdMethod());
}
return _TabItemCmd;
}
}
private void TabItemCmdMethod()
{
//弹窗
DialogService.ShowDialog("DialogChartGroupTabView", new DialogParameters() { { "Name", "" } }, (par) =>
{
if (par.Result == ButtonResult.OK)
{
//程序名称
ListChartTabGroupDto = par.Parameters.GetValue<List<ChartTabGroupDto>>("NewData");
//返回数据刷新Chart
}
else if (par.Result == ButtonResult.Cancel)
{
//取消
}
});
}
/// <summary>
/// 切换ListViewTab的信息
/// </summary>
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;
/// <summary>
/// 编辑曲线Y轴配置的数据
/// </summary>
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<List<ChartTabGroupDto>>("NewData");
//返回数据刷新Chart
var Data = FreeSql.Select<ConfigChartYAxis>().ToList();
EventAggregator.GetEvent<ChartYAxisConfigEvent>().Publish(new ChartYAxisConfigMsg() { Machine = CurSelectedMachine, GroupTabIndex = SeletedGroupTabIndex, ConfigChartYAxes = Data });
}
else if (par.Result == ButtonResult.Cancel)
{
//取消
}
});
}
}
}