using AutoMapper;
using CapMachine.Core;
using CapMachine.Model;
using CapMachine.Wpf.Dtos;
using CapMachine.Wpf.PrismEvent;
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)
{
DialogService = dialogService;
FreeSql = freeSql;
EventAggregator = eventAggregator;
Mapper = mapper;
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; }
///
/// 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