using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Linq; using System.Windows.Input; using Prism.Services.Dialogs; using Prism.Ioc; using SWS.Commons; using SWS.Model; using SWS.Service; using SWS.WPF.Views; using Telerik.Windows.Controls; using Unity; using DialogParameters = Prism.Services.Dialogs.DialogParameters; using System.Windows; namespace SWS.WPF.ViewModels { public class DialogAssociatedSignalViewModel : DialogBase, IDialogAware { #region 属性 private ObservableCollection _MySignals = new ObservableCollection(); /// /// 表格数据源 /// public ObservableCollection MySignals { get { return _MySignals; } set { _MySignals = value; RaisePropertyChanged(nameof(MySignals)); } } private SignalManagementInfo _SelectedSignal; /// /// 选中行 /// public SignalManagementInfo SelectedSignal { get { return _SelectedSignal; } set { _SelectedSignal = value; RaisePropertyChanged(nameof(SelectedSignal)); } } private string _Info; /// /// 列表上方文字 /// public string Info { get { return _Info; } set { _Info = value; RaisePropertyChanged(nameof(Info)); } } private Visibility _IsVisibility = Visibility.Collapsed; /// /// 控制取消关联按钮是否可见 /// public Visibility IsVisibility { get { return _IsVisibility; } set { _IsVisibility = value; RaisePropertyChanged(nameof(IsVisibility)); } } /// /// 信号接口服务 /// WireGroupService _wireGroupService; public DialogSignalNotice SignalNoticeView { get; set; } #endregion public DialogAssociatedSignalViewModel() { _wireGroupService = GlobalObject.container.Resolve(); } public string Title => ""; public event Action RequestClose; public bool CanCloseDialog() { return true; } public void OnDialogClosed() { } public async void OnDialogOpened(IDialogParameters parameters) { title = parameters.GetValue(GlobalObject.dialogPar.title.ToString()); Info = parameters.GetValue(GlobalObject.dialogPar.info.ToString()); var signals = parameters.GetValue>(GlobalObject.dialogPar.para1.ToString()); foreach (var item in signals) { if (title.Equals("信号选择框")) { if (item.type.Equals("信号")) { MySignals.Add(item); } } else if (title.Equals("信号关联列表")) { MySignals.Add(item); IsVisibility = Visibility.Visible; } } } public override void ExecuteOKCommandAsync(object para) { IDialogParameters par = new DialogParameters(); if (title.Equals("信号选择框")) { if (SelectedSignal == null) { MessageBox.Show("请选择一个信号!"); return; } } else if (title.Equals("信号关联列表")) { //如何是取消关联,则把取消的列表传回去 par.Add(GlobalObject.dialogPar.para2.ToString(), CancelAssociationls); } par.Add(GlobalObject.dialogPar.para1.ToString(), SelectedSignal); DialogResult result = new DialogResult(ButtonResult.Yes, par); RequestClose.Invoke(result); } public override void ExecuteCloseCommand(object parameter) { if (parameter as string == "ClickNo") { DialogResult result = new DialogResult(ButtonResult.No); RequestClose.Invoke(result); } else { DialogResult result = new DialogResult(ButtonResult.Cancel); RequestClose.Invoke(result); } this.Dispose(); } //全局的取消关联列表 List CancelAssociationls = new List(); public ICommand CancelAssociationCmd => new DelegateCommand(CancelAssociation_Click); /// /// 取消关联按钮的点击事件 /// /// public virtual void CancelAssociation_Click(object parameter) { CancelAssociationls.Add(SelectedSignal); MySignals.Remove(SelectedSignal); } } public class AssociatedSignalInfo : ViewModelBase { #region 字段 private string _Group_Name; /// /// CH.NO /// public string Group_Name { get { return _Group_Name; } set { _Group_Name = value; RaisePropertyChanged(nameof(Group_Name)); } } private string _Group_Desc_EN; /// /// 英文描述 /// public string Group_Desc_EN { get { return _Group_Desc_EN; } set { _Group_Desc_EN = value; RaisePropertyChanged(nameof(Group_Desc_EN)); } } private string _Group_Desc; /// /// 中文描述 /// public string Group_Desc { get { return _Group_Desc; } set { _Group_Desc = value; RaisePropertyChanged(nameof(Group_Desc)); } } private string _IO_Type; /// /// 信号类型 /// public string IO_Type { get { return _IO_Type; } set { _IO_Type = value; RaisePropertyChanged(nameof(IO_Type)); } } private string _Alarm_LL; public string Alarm_LL { get { return _Alarm_LL; } set { _Alarm_LL = value; RaisePropertyChanged(nameof(Alarm_LL)); } } private string _Alarm_L; public string Alarm_L { get { return _Alarm_L; } set { _Alarm_L = value; RaisePropertyChanged(nameof(Alarm_L)); } } private string _Alarm_H; public string Alarm_H { get { return _Alarm_H; } set { _Alarm_H = value; RaisePropertyChanged(nameof(Alarm_H)); } } private string _Alarm_HH; public string Alarm_HH { get { return _Alarm_HH; } set { _Alarm_HH = value; RaisePropertyChanged(nameof(Alarm_HH)); } } private string _SENSOR_CODE; /// /// 传感器编号 /// public string SENSOR_CODE { get { return _SENSOR_CODE; } set { _SENSOR_CODE = value; RaisePropertyChanged(nameof(SENSOR_CODE)); } } #endregion public AssociatedSignalInfo(ec_Wire_Group ec_Wire_Group) { } } }