436 lines
15 KiB
C#
Raw Normal View History

2025-08-15 16:34:31 +08:00
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Windows;
using SWS.CAD.ViewModels.myViewModelBase;
using System.Windows.Input;
using Telerik.Windows.Controls;
using Prism.Ioc;
2025-09-04 18:28:02 +08:00
using Prism.Services.Dialogs;
using SWS.Commons;
using SWS.Model;
using SWS.WPF.Views;
2025-08-15 16:34:31 +08:00
namespace SWS.CAD.ViewModels
{
public class DialogBusbarManagementViewModel : DialogBase, IDialogAware
{
#region
private ObservableCollection<SignalInfo> _SignalInfos = new ObservableCollection<SignalInfo>();
/// <summary>
/// 端子排参数信息列表
/// </summary>
public ObservableCollection<SignalInfo> SignalInfos
{
get { return _SignalInfos; }
set
{
_SignalInfos = value;
RaisePropertyChanged(nameof(SignalInfos));
}
}
private SignalInfo _SelectedSignalInfo;
/// <summary>
/// 当前选中的信号类型
/// </summary>
public SignalInfo SelectedSignalInfo
{
get { return _SelectedSignalInfo; }
set
{
_SelectedSignalInfo = value;
RaisePropertyChanged(nameof(SelectedSignalInfo));
}
}
private bool _IsReadOnly;
/// <summary>
/// 是否可编辑
/// </summary>
public bool IsReadOnly
{
get { return _IsReadOnly; }
set
{
_IsReadOnly = value;
RaisePropertyChanged(nameof(IsReadOnly));
}
}
#region
private ObservableCollection<ec_Cable> _BusbarDropDownList;
/// <summary>
/// 母线下拉列表
/// </summary>
public ObservableCollection<ec_Cable> BusbarDropDownList
{
get { return _BusbarDropDownList; }
set { _BusbarDropDownList = value;
}
}
private ec_Cable _SelectBusbarValue;
/// <summary>
/// 下拉列表选择的母线值
/// </summary>
public ec_Cable SelectBusbarValue
{
get { return _SelectBusbarValue; }
set { _SelectBusbarValue = value;
RaisePropertyChanged(nameof(SelectBusbarValue));
}
}
#endregion
private List<ec_Cable> _UpdateCableLs = new List<ec_Cable>();
/// <summary>
/// 存储要修改的Cable
/// </summary>
public List<ec_Cable> UpdateCableLs
{
get { return _UpdateCableLs; }
set { _UpdateCableLs = value;
RaisePropertyChanged(nameof(UpdateCableLs));
}
}
#endregion
2025-09-04 18:28:02 +08:00
public string Title => "";
public event Action<IDialogResult> RequestClose;
2025-08-15 16:34:31 +08:00
public bool CanCloseDialog()
{
return true;
}
public void OnDialogClosed()
{
}
private List<ec_Cable> Cables;
public async void OnDialogOpened(IDialogParameters parameters)
{
//title = parameters.GetValue<string>(GlobalObject.dialogPar.title.ToString());
title = "母线管理其下信号";
IsReadOnly = true;
Cables = parameters.GetValue<List<ec_Cable>>(GlobalObject.dialogPar.para1.ToString());
BusbarDropDownList = new ObservableCollection<ec_Cable>(Cables);
var BusbarName= parameters.GetValue<string>(GlobalObject.dialogPar.info.ToString());
SelectBusbarValue = Cables.Where(c => c.TagNumber.Equals(BusbarName)).FirstOrDefault();
if (SelectBusbarValue.WireGroups != null)
{
int index = 0;
foreach (var WireGroup in SelectBusbarValue.WireGroups)
{
index++;
SignalInfos.Add(new SignalInfo(WireGroup){Index = index,});
}
}
}
public override void ExecuteOKCommandAsync(object para)
{
2025-09-04 18:28:02 +08:00
IDialogParameters res = new Prism.Services.Dialogs.DialogParameters();
2025-08-15 16:34:31 +08:00
//res.Add(GlobalObject.dialogPar.para1.ToString(), Cables.ToList());
res.Add(GlobalObject.dialogPar.para1.ToString(), UpdateCableLs.ToList());
2025-09-04 18:28:02 +08:00
RequestClose.Invoke(new DialogResult(ButtonResult.Yes, res));
2025-08-15 16:34:31 +08:00
}
public override void ExecuteCloseCommand(object parameter)
{
if (parameter as string == "ClickNo")
{
2025-09-04 18:28:02 +08:00
DialogResult res = new DialogResult(ButtonResult.No);
RequestClose.Invoke(res);
2025-08-15 16:34:31 +08:00
}
else
{
2025-09-04 18:28:02 +08:00
RequestClose.Invoke(new DialogResult(ButtonResult.Cancel));
2025-08-15 16:34:31 +08:00
}
this.Dispose();
}
#region
public ICommand Busbarcmd => new DelegateCommand(BusbarSelectionChanged);
/// <summary>
/// 下拉框选择项改变时
/// </summary>
/// <param name="parameter"></param>
public void BusbarSelectionChanged(object parameter)
{
SignalInfos.Clear();
if (SelectBusbarValue.WireGroups != null)
{
int index = 0;
foreach (var WireGroup in SelectBusbarValue.WireGroups)
{
index++;
SignalInfos.Add(new SignalInfo(WireGroup){Index = index,});
}
}
}
public ICommand EditEndCmd => new DelegateCommand(EditEnd);
/// <summary>
/// 编辑结束事件
/// </summary>
/// <param name="parameter"></param>
public virtual void EditEnd(object parameter)
{
//做个标记表示该项修改过
}
public ICommand NewCom => new DelegateCommand(NewSignal);
/// <summary>
/// 新增母线关联信号
/// </summary>
/// <param name="parameter"></param>
public void NewSignal(object parameter)
{
//打开信号管理页面
2025-09-04 18:28:02 +08:00
IDialogParameters para = new Prism.Services.Dialogs.DialogParameters();
2025-08-15 16:34:31 +08:00
para.Add(GlobalObject.dialogPar.para1.ToString(), "关联母线");
var _dialogService = GlobalObject._prismContainer.Resolve<IDialogService>();
_dialogService.ShowDialog(nameof(DialogSignalManagement), para, (RES) =>
{
if (RES.Result == ButtonResult.Yes)
{
//返回的信号集合
var ResWireGroupIds = RES.Parameters.GetValue<List<SignalManagementInfo>>(GlobalObject.dialogPar.para1.ToString());
//返回的信号添加到表格源数据中
int index = SignalInfos.Count();
foreach (var ResSignalManagementInfo in ResWireGroupIds)
{
index++;
SignalInfos.Add(new SignalInfo(ResSignalManagementInfo) { Index=index});
//源数据中也需要添加
if (!SelectBusbarValue.WireGroupIds.Contains(ResSignalManagementInfo.Wire_Group_ID))
{
SelectBusbarValue.WireGroupIds.Add(ResSignalManagementInfo.Wire_Group_ID);
List<ec_Wire_Group> WireGrouplist = SelectBusbarValue.WireGroups.ToList();
WireGrouplist.Add(new ec_Wire_Group()
{
Group_Name = ResSignalManagementInfo.Group_Name,
Signal_Group = ResSignalManagementInfo.GroupOther,
Signal_SeqNo = ResSignalManagementInfo.Signal_SeqNo,
Group_Desc = ResSignalManagementInfo.Group_Desc,
Group_Desc_EN = ResSignalManagementInfo.Group_Desc_EN,
IO_Type = ResSignalManagementInfo.IO_Type,
Wire_Group_ID = ResSignalManagementInfo.Wire_Group_ID,
});
SelectBusbarValue.WireGroups = WireGrouplist;
}
//添加到要返回的修改列表
if (UpdateCableLs.Contains(SelectBusbarValue))//存在就覆盖
{
UpdateCableLs[UpdateCableLs.IndexOf(SelectBusbarValue)] = SelectBusbarValue;
}
else
{
UpdateCableLs.Add(SelectBusbarValue);
}
}
}
else if (RES.Result == ButtonResult.No)
{ }
});
}
public ICommand DeleteCom => new DelegateCommand(DeleteSignal);
/// <summary>
/// 删除
/// </summary>
/// <param name="parameter"></param>
public void DeleteSignal(object parameter)
{
if (SelectedSignalInfo==null)
{
System.Windows.MessageBox.Show("请选择要删除的信号", "KunHengCAD", MessageBoxButton.OK, MessageBoxImage.Warning); return;
}
else
{
MessageBoxResult result = System.Windows.MessageBox.Show($"确定删除选择的1行数据", "KunHengCAD", MessageBoxButton.OKCancel, MessageBoxImage.Question);
if (result == MessageBoxResult.OK)
{
//删除数据源的信号实例
SelectBusbarValue.WireGroups.ToList().RemoveAll(s => s.Wire_Group_ID.Equals(SelectedSignalInfo.Wire_Group_ID));
List<ec_Wire_Group> WireGrouplist = SelectBusbarValue.WireGroups.ToList();
WireGrouplist.RemoveAll(s => s.Wire_Group_ID.Equals(SelectedSignalInfo.Wire_Group_ID));
SelectBusbarValue.WireGroups = WireGrouplist;
//删除源中的信号id
SelectBusbarValue.WireGroupIds.Remove(SelectedSignalInfo.Wire_Group_ID);
//刷新页面重新赋值
int index = 0;
SignalInfos.Clear();
foreach (var WireGroup in SelectBusbarValue.WireGroups)
{
index++;
SignalInfos.Add(new SignalInfo(WireGroup) { Index = index, });
}
//有修改的Cable保存到UpdateCableLs集合返回给IO页面保存
if (UpdateCableLs.Contains(SelectBusbarValue))//存在就覆盖
{
UpdateCableLs[UpdateCableLs.IndexOf(SelectBusbarValue)] = SelectBusbarValue;
}
else
{
UpdateCableLs.Add(SelectBusbarValue);
}
}
else
{
return;
}
}
}
#endregion
}
public class SignalInfo : DialogBase
{
#region
private int _Index;
/// <summary>
/// 序号
/// </summary>
public int Index
{
get { return _Index; }
set
{
_Index = value;
RaisePropertyChanged(nameof(Index));
}
}
private string _Group_Name;
/// <summary>
/// 信号名称
/// </summary>
public string Group_Name
{
get { return _Group_Name; }
set { _Group_Name = value; RaisePropertyChanged(nameof(Group_Name)); }
}
private string _GroupOther;
/// <summary>
/// 组别
/// </summary>
public string GroupOther
{
get { return _GroupOther; }
set
{
_GroupOther = value;
RaisePropertyChanged(nameof(GroupOther));
}
}
private string _Signal_SeqNo;
/// <summary>
/// 信号编号
/// </summary>
public string Signal_SeqNo
{
get { return _Signal_SeqNo; }
set { _Signal_SeqNo = value; RaisePropertyChanged(nameof(Signal_SeqNo)); }
}
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 _IoType;
/// <summary>
/// 信号类型
/// </summary>
public string IoType
{
get { return _IoType; }
set
{
_IoType = value;
RaisePropertyChanged(nameof(Index));
}
}
#endregion
#region
private string _Wire_Group_ID;
/// <summary>
/// ID
/// </summary>
public string Wire_Group_ID
{
get { return _Wire_Group_ID; }
set { _Wire_Group_ID = value;
RaisePropertyChanged(nameof(Wire_Group_ID));
}
}
private bool _IsModified;
/// <summary>
/// 表示是否修改过
/// </summary>
public bool IsModified
{
get { return _IsModified; }
set
{
_IsModified = value;
RaisePropertyChanged(nameof(IsModified));
}
}
#endregion
public SignalInfo()
{
}
public SignalInfo(ec_Wire_Group WireGroup)
{
Group_Name = WireGroup.Group_Name;
GroupOther = WireGroup.Signal_Group;
Signal_SeqNo = WireGroup.Signal_SeqNo;
Group_Desc = WireGroup.Group_Desc;
Group_Desc_EN = WireGroup.Group_Desc_EN;
IoType = WireGroup.IO_Type;
Wire_Group_ID = WireGroup.Wire_Group_ID;
}
public SignalInfo(SignalManagementInfo SignalInfo)
{
Group_Name = SignalInfo.Group_Name;
GroupOther = SignalInfo.GroupOther;
Signal_SeqNo = SignalInfo.Signal_SeqNo;
Group_Desc = SignalInfo.Group_Desc;
Group_Desc_EN = SignalInfo.Group_Desc_EN;
IoType = SignalInfo.IO_Type;
Wire_Group_ID = SignalInfo.Wire_Group_ID;
}
}
}