009_DI-Elec/newFront/c#前端/SWS.CAD/ViewModels/DialogIODistributionVM/DialogCablePreAssignPreviewViewModel.cs
CHEN-ZW\acer e24ee57355 1
2025-09-23 16:38:40 +08:00

300 lines
9.5 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using SWS.CAD.ViewModels.myViewModelBase;
using System.Windows.Input;
using Telerik.Windows.Controls;
using Prism.Ioc;
using SWS.CAD.Views.Dialog;
using Prism.Services.Dialogs;
using SWS.Commons;
using SWS.Model;
using System.Windows;
using SWS.Service;
using Unity;
namespace SWS.CAD.ViewModels
{
public class DialogCablePreAssignPreviewViewModel : DialogBase, IDialogAware
{
#region
private ObservableCollection<PreAssignCable> _PreAssignCables = new ObservableCollection<PreAssignCable>();
/// <summary>
/// 端子排参数信息列表
/// </summary>
public ObservableCollection<PreAssignCable> PreAssignCables
{
get { return _PreAssignCables; }
set
{
_PreAssignCables = value;
RaisePropertyChanged(nameof(PreAssignCables));
}
}
#endregion
IOModuleService _iOModuleService;
public DialogCablePreAssignPreviewViewModel()
{
_iOModuleService = GlobalObject.container.Resolve<IOModuleService>();
}
public string Title => "";
public event Action<IDialogResult> RequestClose;
public bool CanCloseDialog()
{
return true;
}
public void OnDialogClosed()
{
}
private List<ec_Cable> CablePreAssigns;
public void OnDialogOpened(IDialogParameters parameters)
{
//title = parameters.GetValue<string>(GlobalObject.dialogPar.title.ToString());
title = "待分配的信号预览和统计";
_PreAssignCables = parameters.GetValue<ObservableCollection<PreAssignCable>>(GlobalObject.dialogPar.para1.ToString());
}
public override async void ExecuteOKCommandAsync(object parameter)
{
bool isShowDialog = false;
List<string> cableids = new List<string>();
foreach (var preAssignCable in PreAssignCables)
{
if (preAssignCable.IsChecked)
{
cableids.Add(preAssignCable.CableId);
}
}
if (cableids != null && cableids.Count() > 0)
{
bool AcceptNearbyPanel;
MessageBoxResult result = System.Windows.MessageBox.Show($"遇到I/O类型不合适的采集箱是否需要自动更换就近的采集箱", "KunHengCAD", MessageBoxButton.YesNo, MessageBoxImage.Question);
if (result == MessageBoxResult.Yes)
{
AcceptNearbyPanel = true;
}
else
{
AcceptNearbyPanel = false;
}
var ResHttp = await _iOModuleService.AutoAssignCable2channel_step1(cableids, AcceptNearbyPanel) as learunHttpRes<object>;
if (ResHttp.code == 200)
{
isShowDialog = true;
}
else
{
if (AcceptNearbyPanel)
{
result = System.Windows.MessageBox.Show($"{ResHttp.info}", "KunHengCAD", MessageBoxButton.YesNo, MessageBoxImage.Question);
if (result == MessageBoxResult.Yes)
{
return;
}
else
{
isShowDialog = true;
}
}
else
{
var info = ResHttp.info;
// 找到第一个句号的位置
int firstPeriodIndex = info.IndexOf('。');
if (firstPeriodIndex >= 0)
{
// 从第一个句号后开始找第二个句号
int secondPeriodIndex = info.IndexOf('。', firstPeriodIndex + 1);
if (secondPeriodIndex >= 0)
{
// 截取到第二个句号(包括句号)
info = info.Substring(0, secondPeriodIndex + 1);
}
}
System.Windows.MessageBox.Show($"{info}", "KunHengCAD", MessageBoxButton.OK, MessageBoxImage.Warning); return;
}
}
if (isShowDialog)
{
//打开窗体
IDialogParameters para = new Prism.Services.Dialogs.DialogParameters();
para.Add(GlobalObject.dialogPar.para1.ToString(), PreAssignCables);
var _dialogService = GlobalObject._prismContainer.Resolve<IDialogService>();
_dialogService.ShowDialog(nameof(DialogCablePreAssignResult), para, (RES) =>
{
if (RES.Result == ButtonResult.Yes)
{
}
else if (RES.Result == ButtonResult.No)
{ }
});
}
}
else
{
System.Windows.MessageBox.Show("未勾选预分配电缆", "KunHengCAD", MessageBoxButton.OK, MessageBoxImage.Warning); return;
}
//返回的结果
//IDialogParameters res = new Prism.Services.Dialogs.DialogParameters();
//res.Add(GlobalObject.dialogPar.para1.ToString(), SelectedStripParametersInfo);
//RequestClose.Invoke(new DialogResult(ButtonResult.Yes, res));
}
public override void ExecuteCloseCommand(object parameter)
{
if (parameter as string == "ClickNo")
{
DialogResult res = new DialogResult(ButtonResult.No);
RequestClose.Invoke(res);
}
else
{
RequestClose.Invoke(new DialogResult(ButtonResult.Cancel));
}
this.Dispose();
}
#region
public ICommand EditEndCmd => new DelegateCommand(EditEnd);
/// <summary>
/// 编辑结束事件
/// </summary>
/// <param name="parameter"></param>
public virtual void EditEnd(object parameter)
{
//做个标记表示该项修改过
}
#region
public ICommand ButtonCommand => new DelegateCommand(Button_Click);
/// <summary>
/// 页面左侧按钮
/// </summary>
/// <param name="parameter"></param>
public virtual void Button_Click(object parameter)
{
if (parameter.ToString().Equals("全选"))
{
foreach (var item in PreAssignCables)
{
item.IsChecked = true;
}
return;
}
if (parameter.ToString().Equals("清空"))
{
foreach (var item in PreAssignCables)
{
item.IsChecked = false;
}
return;
}
}
#endregion
#endregion
}
public class PreAssignCable : DialogBase
{
#region
private string _CableId;
public string CableId
{
get { return _CableId; }
set { _CableId = value; }
}
private int _Index;
/// <summary>
/// 序号
/// </summary>
public int Index
{
get { return _Index; }
set { _Index = value; }
}
private bool _IsChecked;
/// <summary>
/// 选择
/// </summary>
public bool IsChecked
{
get { return _IsChecked; }
set
{
_IsChecked = value;
RaisePropertyChanged(nameof(IsChecked));
}
}
private string _TagNumber;
/// <summary>
/// 电缆位号
/// </summary>
public string TagNumber
{
get { return _TagNumber; }
set { _TagNumber = value; }
}
private string _PreAssignIOType;
/// <summary>
/// 预分配的信号类型
/// </summary>
public string PreAssignIOType
{
get { return _PreAssignIOType; }
set { _PreAssignIOType = value; }
}
private string _CableClass;
/// <summary>
/// 是否为母线
/// </summary>
public string CableClass
{
get { return _CableClass; }
set { _CableClass = value; }
}
private string _ToPanel_TagNumber;
/// <summary>
/// 预分配的系统柜
/// </summary>
public string ToPanel_TagNumber
{
get { return _ToPanel_TagNumber; }
set { _ToPanel_TagNumber = value; }
}
public PreAssignCable()
{
}
public PreAssignCable(ec_Cable ec_Cable)
{
CableId = ec_Cable.CableID;
TagNumber = ec_Cable.TagNumber;
PreAssignIOType = ec_Cable.PreAssignIOType;
CableClass = ec_Cable.CableClass.Equals("homerun") ? "是" : "否";
ToPanel_TagNumber = ec_Cable.AssignedPanel != null ? ec_Cable.AssignedPanel.TagNumber : null;
}
#endregion
}
}