268 lines
7.5 KiB
C#
Raw Normal View History

2025-09-15 18:35:41 +08:00
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<SignalManagementInfo> _MySignals = new ObservableCollection<SignalManagementInfo>();
/// <summary>
/// 表格数据源
/// </summary>
public ObservableCollection<SignalManagementInfo> MySignals
{
get { return _MySignals; }
set { _MySignals = value; RaisePropertyChanged(nameof(MySignals)); }
}
private SignalManagementInfo _SelectedSignal;
/// <summary>
/// 选中行
/// </summary>
public SignalManagementInfo SelectedSignal
{
get { return _SelectedSignal; }
set { _SelectedSignal = value; RaisePropertyChanged(nameof(SelectedSignal)); }
}
private string _Info;
/// <summary>
/// 列表上方文字
/// </summary>
public string Info
{
get { return _Info; }
set { _Info = value; RaisePropertyChanged(nameof(Info)); }
}
private Visibility _IsVisibility = Visibility.Collapsed;
/// <summary>
/// 控制取消关联按钮是否可见
/// </summary>
public Visibility IsVisibility
{
get { return _IsVisibility; }
set
{
_IsVisibility = value;
RaisePropertyChanged(nameof(IsVisibility));
}
}
/// <summary>
/// 信号接口服务
/// </summary>
WireGroupService _wireGroupService;
public DialogSignalNotice SignalNoticeView { get; set; }
#endregion
public DialogAssociatedSignalViewModel()
{
_wireGroupService = GlobalObject.container.Resolve<WireGroupService>();
}
public string Title => "";
public event Action<IDialogResult> RequestClose;
public bool CanCloseDialog()
{
return true;
}
public void OnDialogClosed()
{
}
public async void OnDialogOpened(IDialogParameters parameters)
{
title = parameters.GetValue<string>(GlobalObject.dialogPar.title.ToString());
Info = parameters.GetValue<string>(GlobalObject.dialogPar.info.ToString());
var signals = parameters.GetValue<ObservableCollection<SignalManagementInfo>>(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<SignalManagementInfo> CancelAssociationls = new List<SignalManagementInfo>();
public ICommand CancelAssociationCmd => new DelegateCommand(CancelAssociation_Click);
/// <summary>
/// 取消关联按钮的点击事件
/// </summary>
/// <param name="parameter"></param>
public virtual void CancelAssociation_Click(object parameter)
{
CancelAssociationls.Add(SelectedSignal);
MySignals.Remove(SelectedSignal);
}
}
public class AssociatedSignalInfo : ViewModelBase
{
#region
private string _Group_Name;
/// <summary>
/// CH.NO
/// </summary>
public string Group_Name
{
get { return _Group_Name; }
set { _Group_Name = value; RaisePropertyChanged(nameof(Group_Name)); }
}
private string _Group_Desc_EN;
/// <summary>
/// 英文描述
/// </summary>
public string Group_Desc_EN
{
get { return _Group_Desc_EN; }
set { _Group_Desc_EN = value; RaisePropertyChanged(nameof(Group_Desc_EN)); }
}
private string _Group_Desc;
/// <summary>
/// 中文描述
/// </summary>
public string Group_Desc
{
get { return _Group_Desc; }
set { _Group_Desc = value; RaisePropertyChanged(nameof(Group_Desc)); }
}
private string _IO_Type;
/// <summary>
/// 信号类型
/// </summary>
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;
/// <summary>
/// 传感器编号
/// </summary>
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)
{
}
}
}