009_DI-Elec/newFront/c#前端/SWS.CAD/ViewModels/DialogIODistributionVM/DialogCablePreAssignResultViewModel.cs

294 lines
9.3 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 SWS.CAD.ViewModels.myViewModelBase;
using System.Windows.Input;
using Telerik.Windows.Controls;
2025-09-04 18:28:02 +08:00
using Prism.Services.Dialogs;
using SWS.Commons;
using SWS.Model;
using SWS.Service;
using Unity;
using System.Linq;
using Telerik.Windows.Controls.MaskedInput.Tokens.Numeric;
2025-08-15 16:34:31 +08:00
namespace SWS.CAD.ViewModels
{
public class DialogCablePreAssignResultViewModel : DialogBase, IDialogAware
{
#region
private ObservableCollection<PreAllocationResult> _PreAllocationResultls = new ObservableCollection<PreAllocationResult>();
2025-08-15 16:34:31 +08:00
/// <summary>
/// 预分配结果表格源
2025-08-15 16:34:31 +08:00
/// </summary>
public ObservableCollection<PreAllocationResult> PreAllocationResultls
2025-08-15 16:34:31 +08:00
{
get { return _PreAllocationResultls; }
2025-08-15 16:34:31 +08:00
set
{
_PreAllocationResultls = value;
RaisePropertyChanged(nameof(PreAllocationResultls));
2025-08-15 16:34:31 +08:00
}
}
private string _SuccessOrFailure = "分配成功";
2025-08-15 16:34:31 +08:00
/// <summary>
/// 选择成功还是选择失败
2025-08-15 16:34:31 +08:00
/// </summary>
public string SuccessOrFailure
2025-08-15 16:34:31 +08:00
{
get { return _SuccessOrFailure; }
2025-08-15 16:34:31 +08:00
set
{
_SuccessOrFailure = value;
RaisePropertyChanged(nameof(SuccessOrFailure));
UpdataPreAssignCables();
2025-08-15 16:34:31 +08:00
}
}
private ObservableCollection<ec_Cable> _PreAssignCables = new ObservableCollection<ec_Cable>();
2025-08-15 16:34:31 +08:00
/// <summary>
/// 左侧预分配电缆列表
2025-08-15 16:34:31 +08:00
/// </summary>
public ObservableCollection<ec_Cable> PreAssignCables
2025-08-15 16:34:31 +08:00
{
get { return _PreAssignCables; }
2025-08-15 16:34:31 +08:00
set
{
_PreAssignCables = value;
RaisePropertyChanged(nameof(PreAssignCables));
2025-08-15 16:34:31 +08:00
}
}
private ec_Cable _SelectedPreAssignCable;
2025-08-15 16:34:31 +08:00
/// <summary>
/// 选择的预分配电缆
2025-08-15 16:34:31 +08:00
/// </summary>
public ec_Cable SelectedPreAssignCable
2025-08-15 16:34:31 +08:00
{
get { return _SelectedPreAssignCable; }
2025-08-15 16:34:31 +08:00
set
{
_SelectedPreAssignCable = value;
RaisePropertyChanged(nameof(SelectedPreAssignCable));
UpdataPreAllocationResultls(_SelectedPreAssignCable);
2025-08-15 16:34:31 +08:00
}
}
#endregion
IOModuleService _iOModuleService;
public DialogCablePreAssignResultViewModel()
{
_iOModuleService = GlobalObject.container.Resolve<IOModuleService>();
}
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> AllPreAssignCables;
2025-08-15 16:34:31 +08:00
public async void OnDialogOpened(IDialogParameters parameters)
{
//title = parameters.GetValue<string>(GlobalObject.dialogPar.title.ToString());
title = "信号预分配结果";
AllPreAssignCables = await _iOModuleService.AutoAssignCable2channel_step2();
UpdataPreAssignCables();
2025-08-15 16:34:31 +08:00
}
public override async void ExecuteOKCommandAsync(object para)
2025-08-15 16:34:31 +08:00
{
2025-09-23 16:38:40 +08:00
//只传入分配成功的电缆
var Cables = new List<ec_Cable>();
if (AllPreAssignCables != null)
{
foreach (var PreAssignCable in AllPreAssignCables)
{
if (PreAssignCable.Sets != null && !string.IsNullOrEmpty(PreAssignCable.Sets.FirstOrDefault().ConnectionInfo))
{
Cables.Add(PreAssignCable);
}
}
}
var resHttp = await _iOModuleService.AutoAssignCable2channel_step3(Cables);
2025-08-15 16:34:31 +08:00
//返回结果
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(), SelectedStripParametersInfo);
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
/// <summary>
/// 修改预分配电缆列表,成功或者失败的电缆列表
/// </summary>
public void UpdataPreAssignCables()
{
PreAssignCables = new ObservableCollection<ec_Cable>();
if (AllPreAssignCables != null)
{
if (SuccessOrFailure.Equals("分配成功"))
{
foreach (var PreAssignCable in AllPreAssignCables)
{
2025-09-23 16:38:40 +08:00
if (PreAssignCable.AssignedPanel!=null)
{
PreAssignCables.Add(PreAssignCable);
}
}
}
else
{
foreach (var PreAssignCable in AllPreAssignCables)
{
2025-09-23 16:38:40 +08:00
if (PreAssignCable.AssignedPanel == null)
{
PreAssignCables.Add(PreAssignCable);
}
}
}
}
}
/// <summary>
/// 修改表格显示数据
/// </summary>
public void UpdataPreAllocationResultls(ec_Cable cable)
{
PreAllocationResultls = new ObservableCollection<PreAllocationResult>();
if (cable == null) return;
2025-09-23 16:38:40 +08:00
if (cable.AssignedPanel != null)
{
foreach (var Set in cable.Sets)
{
PreAllocationResult preAllocationResult = new PreAllocationResult();
preAllocationResult.CablePair = Set.CableSetName;
preAllocationResult.IOType = cable.PreAssignIOType;
2025-09-23 16:38:40 +08:00
preAllocationResult.ToPanel_TagNumber = cable.AssignedPanel == null ? "" : cable.AssignedPanel.TagNumber;
preAllocationResult.Panel_TagNumber = string.IsNullOrEmpty(Set.ConnectionInfo) ? "" : Set.ConnectionInfo.Split('/')[0].Split('')[1].Trim();
preAllocationResult.StripName = string.IsNullOrEmpty(Set.ConnectionInfo) ? "" : Set.ConnectionInfo.Split('/')[1].Split('')[1].Trim();
preAllocationResult.Terms = new ObservableCollection<ec_PanelStripTerm>(Set.AssignedTerms);
PreAllocationResultls.Add(preAllocationResult);
}
}
}
2025-08-15 16:34:31 +08:00
public ICommand EditEndCmd => new DelegateCommand(EditEnd);
/// <summary>
/// 编辑结束事件
/// </summary>
/// <param name="parameter"></param>
public virtual void EditEnd(object parameter)
{
//做个标记表示该项修改过
}
#endregion
}
/// <summary>
/// 预分配结果类
/// </summary>
public class PreAllocationResult : DialogBase
{
private string _CablePair;
/// <summary>
/// 电缆对
/// </summary>
public string CablePair
{
get { return _CablePair; }
2025-09-23 16:38:40 +08:00
set { _CablePair = value;
RaisePropertyChanged(nameof(CablePair));
}
}
private string _IOType;
/// <summary>
/// IO类型
/// </summary>
public string IOType
{
get { return _IOType; }
2025-09-23 16:38:40 +08:00
set { _IOType = value;
RaisePropertyChanged(nameof(IOType));
}
}
2025-08-15 16:34:31 +08:00
private string _ToPanel_TagNumber;
/// <summary>
/// 预分配的系统柜
/// </summary>
public string ToPanel_TagNumber
{
get { return _ToPanel_TagNumber; }
2025-09-23 16:38:40 +08:00
set { _ToPanel_TagNumber = value;
RaisePropertyChanged(nameof(ToPanel_TagNumber));
}
}
private string _Panel_TagNumber;
/// <summary>
/// 实际分配的系统柜
/// </summary>
public string Panel_TagNumber
{
get { return _Panel_TagNumber; }
2025-09-23 16:38:40 +08:00
set { _Panel_TagNumber = value;
RaisePropertyChanged(nameof(Panel_TagNumber));
}
}
private string _StripName;
/// <summary>
/// 实际分配的端子排
/// </summary>
public string StripName
{
get { return _StripName; }
2025-09-23 16:38:40 +08:00
set { _StripName = value;
RaisePropertyChanged(nameof(StripName));
}
}
private ObservableCollection<ec_PanelStripTerm> _Terms;
/// <summary>
/// 实际端子
/// </summary>
public ObservableCollection<ec_PanelStripTerm> Terms
{
get { return _Terms; }
2025-09-23 16:38:40 +08:00
set { _Terms = value;
RaisePropertyChanged(nameof(Terms));
}
}
}
2025-08-15 16:34:31 +08:00
}