using AutoMapper; using CapMachine.Core; using CapMachine.Model; using CapMachine.Wpf.Dtos; using CapMachine.Wpf.PrismEvent; using CapMachine.Wpf.Services; using Prism.Commands; using Prism.Events; using Prism.Services.Dialogs; using System.Collections.ObjectModel; namespace CapMachine.Wpf.ViewModels { /// /// 实时曲线的模型 /// public class RealTimeChartViewModel : NavigationViewModel { /// /// 实例化函数 /// public RealTimeChartViewModel(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()); //都要加载数据 EventAggregator.GetEvent().Publish(new ChartRtSeriesActionMsg() { Machine = "M1", GroupTabIndex = 0, ActionMsg = "Start" }); EventAggregator.GetEvent().Publish(new ChartRtSeriesActionMsg() { Machine = "M1", GroupTabIndex = 1, ActionMsg = "Start" }); EventAggregator.GetEvent().Publish(new ChartRtSeriesActionMsg() { Machine = "M1", GroupTabIndex = 2, ActionMsg = "Start" }); EventAggregator.GetEvent().Publish(new ChartRtSeriesActionMsg() { Machine = "M1", GroupTabIndex = 3, ActionMsg = "Start" }); EventAggregator.GetEvent().Publish(new ChartRtSeriesActionMsg() { Machine = "M1", GroupTabIndex = 4, ActionMsg = "Start" }); EventAggregator.GetEvent().Publish(new ChartRtSeriesActionMsg() { Machine = "M1", GroupTabIndex = 5, ActionMsg = "Start" }); } /// /// 弹窗服务 /// public IDialogService DialogService { get; } /// /// AutoMap映射 /// public IMapper Mapper { get; } public ConfigService ConfigService { get; } /// /// FreeSQL 实例 /// public IFreeSql FreeSql { get; } private List _ListChartTabGroupDto; /// /// Tab集合信息数据 /// public List ListChartTabGroupDto { get { return _ListChartTabGroupDto; } set { _ListChartTabGroupDto = value; RaisePropertyChanged(); } } /// /// 当前的Machine /// private string CurSelectedMachine { get; set; } = "M1"; #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 /// /// 事件聚合器 /// public IEventAggregator EventAggregator { get; } private DelegateCommand _ChartConfigCmd; /// /// 编辑曲线数据 /// public DelegateCommand ChartConfigCmd { set { _ChartConfigCmd = value; } get { if (_ChartConfigCmd == null) { _ChartConfigCmd = new DelegateCommand(() => ChartConfigCmdMethod()); } return _ChartConfigCmd; } } /// /// 编辑曲线数据执行方法 /// private void ChartConfigCmdMethod() { //弹窗 DialogService.ShowDialog("DialogChartRtConfigView", 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) { //取消 } }); } } }