427 lines
14 KiB
C#
427 lines
14 KiB
C#
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 Unity;
|
||
using Prism.Services.Dialogs;
|
||
using SWS.Commons;
|
||
using SWS.Service;
|
||
using SWS.Model;
|
||
|
||
namespace SWS.CAD.ViewModels
|
||
{
|
||
public class DialogCableConfigViewModel : DialogBase, IDialogAware
|
||
{
|
||
#region 页面渲染字段
|
||
private ObservableCollection<CableSetInfo> _CableSetInfos = new ObservableCollection<CableSetInfo>();
|
||
/// <summary>
|
||
/// 端子排参数信息列表
|
||
/// </summary>
|
||
public ObservableCollection<CableSetInfo> CableSetInfos
|
||
{
|
||
get { return _CableSetInfos; }
|
||
set
|
||
{
|
||
_CableSetInfos = value;
|
||
RaisePropertyChanged(nameof(CableSetInfos));
|
||
}
|
||
}
|
||
private string _StartCable;
|
||
/// <summary>
|
||
/// 起始电缆
|
||
/// </summary>
|
||
public string StartCable
|
||
{
|
||
get { return _StartCable; }
|
||
set { _StartCable = value; RaisePropertyChanged(nameof(StartCable)); }
|
||
}
|
||
private string _StartChannel;
|
||
/// <summary>
|
||
/// 起始通道
|
||
/// </summary>
|
||
public string StartChannel
|
||
{
|
||
get { return _StartChannel; }
|
||
set { _StartChannel = value; RaisePropertyChanged(nameof(StartChannel)); }
|
||
}
|
||
|
||
|
||
|
||
#region 表格下拉列表
|
||
|
||
private List<string> _StartCables = new List<string>();
|
||
/// <summary>
|
||
/// 起始电缆下拉列表
|
||
/// </summary>
|
||
public List<string> StartCables
|
||
{
|
||
get { return _StartCables; }
|
||
set { _StartCables = value; RaisePropertyChanged(nameof(StartCables)); }
|
||
}
|
||
private List<string> _StartChannels = new List<string>();
|
||
/// <summary>
|
||
/// 起始通道下列列表
|
||
/// </summary>
|
||
public List<string> StartChannels
|
||
{
|
||
get { return _StartChannels; }
|
||
set { _StartChannels = value; RaisePropertyChanged(nameof(StartChannels)); }
|
||
}
|
||
|
||
|
||
#endregion
|
||
private bool _IsEnabledDeleteCableProfile;
|
||
/// <summary>
|
||
/// 是否禁用清除配置按钮
|
||
/// </summary>
|
||
public bool IsEnabledDeleteCableProfile
|
||
{
|
||
get { return _IsEnabledDeleteCableProfile; }
|
||
set { _IsEnabledDeleteCableProfile = value;
|
||
RaisePropertyChanged(nameof(IsEnabledDeleteCableProfile));
|
||
}
|
||
}
|
||
|
||
#endregion
|
||
IOModuleService _iOModuleService;
|
||
public DialogCableConfigViewModel()
|
||
{
|
||
_iOModuleService = GlobalObject.container.Resolve<IOModuleService>();
|
||
|
||
}
|
||
|
||
public string Title => "";
|
||
|
||
public event Action<IDialogResult> RequestClose;
|
||
public bool CanCloseDialog()
|
||
{
|
||
return true;
|
||
}
|
||
|
||
public void OnDialogClosed()
|
||
{
|
||
|
||
}
|
||
|
||
private ec_Cable _ec_Cable;
|
||
private ec_PanelStrip _ec_PanelStrip;
|
||
public async void OnDialogOpened(IDialogParameters parameters)
|
||
{
|
||
title = parameters.GetValue<string>(GlobalObject.dialogPar.title.ToString());
|
||
//title = "";
|
||
//添加起始通道下拉列表数据
|
||
_ec_PanelStrip = parameters.GetValue<ec_PanelStrip>(GlobalObject.dialogPar.para2.ToString());
|
||
foreach (var Channel in _ec_PanelStrip.Channels)
|
||
{
|
||
if (Channel.Terms.Where(t => t.Connection != null).Count() == 0)
|
||
{
|
||
StartChannels.Add(Channel.ChannelName);
|
||
}
|
||
|
||
}
|
||
//添加表格数据
|
||
_ec_Cable = parameters.GetValue<ec_Cable>(GlobalObject.dialogPar.para1.ToString());
|
||
if (_ec_Cable != null)
|
||
{
|
||
//获取所有电缆对信息
|
||
int i = 0;
|
||
int index = 0;
|
||
foreach (var CableSet in _ec_Cable.Sets)
|
||
{
|
||
var CableSetInfo = new CableSetInfo();
|
||
CableSetInfo.CableID = _ec_Cable.CableID;
|
||
CableSetInfo.CableName = _ec_Cable.TagNumber;
|
||
CableSetInfo.CableSetID = CableSet.CableSetID;
|
||
CableSetInfo.CableSetName = CableSet.CableSetName;
|
||
CableSetInfo.UpdateUserID= _ec_Cable.UpdateUserID;
|
||
CableSetInfo.OccupancyState = CableSet.ConnectionInfo;
|
||
CableSetInfo.IsConned = CableSet.IsConned??false;
|
||
if (string.IsNullOrEmpty(CableSet.ConnectionInfo))
|
||
{
|
||
if (i<StartChannels.Count)
|
||
{
|
||
CableSetInfo.ChannelNumber = StartChannels[i];
|
||
}
|
||
|
||
i++;
|
||
}
|
||
else
|
||
{
|
||
CableSetInfo.ChannelNumber = CableSet.ConnectionInfo.Split('/').ToList().LastOrDefault().Split(':').ToList().LastOrDefault().Trim();
|
||
}
|
||
|
||
foreach (var CableSetWire in CableSet.Wires)
|
||
{
|
||
index++;
|
||
|
||
CableSetInfo.Indexs.Add(index.ToString());
|
||
CableSetInfo.Wire_Tags.Add(CableSetWire);
|
||
CableSetInfo.Polaritys.Add(CableSetWire);
|
||
}
|
||
_CableSetInfos.Add(CableSetInfo);
|
||
//判断清除配置按钮是否禁用
|
||
foreach (var item in _CableSetInfos)
|
||
{
|
||
if (item.IsConned)
|
||
{
|
||
IsEnabledDeleteCableProfile = false;
|
||
break;
|
||
}
|
||
}
|
||
|
||
//添加起始电缆下拉列表数据
|
||
//if (!CableSet.CableSetName.Equals("") && string.IsNullOrEmpty(CableSet.ConnectionInfo))
|
||
if (!CableSet.CableSetName.Equals(""))
|
||
{
|
||
if (CableSet.IsConned!=null&& CableSet.IsConned==false)
|
||
{
|
||
StartCables.Add(CableSet.CableSetName);
|
||
}
|
||
|
||
}
|
||
}
|
||
}
|
||
|
||
StartCable = StartCables.FirstOrDefault();
|
||
StartChannel = StartChannels.FirstOrDefault();
|
||
}
|
||
|
||
public override void ExecuteOKCommandAsync(object para)
|
||
{
|
||
|
||
IDialogParameters res = new Prism.Services.Dialogs.DialogParameters();
|
||
|
||
res.Add(GlobalObject.dialogPar.para1.ToString(), CableSetInfos);
|
||
|
||
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 ConnectButtonCmd => new DelegateCommand(ConnectButton_Click);
|
||
/// <summary>
|
||
/// 页面连接按钮
|
||
/// </summary>
|
||
/// <param name="parameter"></param>
|
||
public virtual async void ConnectButton_Click(object parameter)
|
||
{
|
||
//foreach (var CableSetInfo in CableSetInfos)
|
||
//{
|
||
// if (CableSetInfo.CableSetName.Equals(StartCable))
|
||
// {
|
||
// CableSetInfo.ChannelNumber = StartChannel;
|
||
// }
|
||
//}
|
||
int index1= CableSetInfos.Select(C => C.CableSetName).ToList().IndexOf(StartCable);
|
||
int index2= StartChannels.IndexOf(StartChannel);
|
||
List<string> channels = StartChannels.Skip(index2).ToList();
|
||
int j = 0;
|
||
for (int i = 0; i < CableSetInfos.Count; i++)
|
||
{
|
||
if (!CableSetInfos[i].IsConned)
|
||
{
|
||
CableSetInfos[i].ChannelNumber = "";
|
||
if (i >= index1)
|
||
{
|
||
if (j < channels.Count)
|
||
{
|
||
CableSetInfos[i].ChannelNumber = channels[j];
|
||
}
|
||
|
||
j++;
|
||
}
|
||
}
|
||
|
||
|
||
|
||
}
|
||
|
||
|
||
|
||
}
|
||
public ICommand DeleteCableProfileCmd => new DelegateCommand(DeleteCableProfileButton_Click);
|
||
/// <summary>
|
||
/// 清除配置按钮
|
||
/// </summary>
|
||
/// <param name="parameter"></param>
|
||
public virtual async void DeleteCableProfileButton_Click(object parameter)
|
||
{
|
||
var httpres = await _iOModuleService.DeleteCableProfile(_ec_Cable.CableID);
|
||
if (httpres == null)
|
||
{
|
||
RequestClose.Invoke(new DialogResult(ButtonResult.Cancel));
|
||
this.Dispose();
|
||
}
|
||
|
||
}
|
||
public ICommand EditEndCmd => new DelegateCommand(EditEnd);
|
||
/// <summary>
|
||
/// 编辑结束事件
|
||
/// </summary>
|
||
/// <param name="parameter"></param>
|
||
public virtual void EditEnd(object parameter)
|
||
{
|
||
//做个标记表示该项修改过
|
||
|
||
}
|
||
#endregion
|
||
}
|
||
|
||
public class CableSetInfo : DialogBase
|
||
{
|
||
#region 页面渲染字段
|
||
private ObservableCollection<string> _Indexs = new ObservableCollection<string>();
|
||
/// <summary>
|
||
/// 序号
|
||
/// </summary>
|
||
public ObservableCollection<string> Indexs
|
||
{
|
||
get { return _Indexs; }
|
||
set { _Indexs = value;
|
||
RaisePropertyChanged(nameof(Indexs));
|
||
}
|
||
}
|
||
private string _CableSetName;
|
||
/// <summary>
|
||
/// 电缆对
|
||
/// </summary>
|
||
public string CableSetName
|
||
{
|
||
get { return _CableSetName; }
|
||
set { _CableSetName = value;
|
||
RaisePropertyChanged(nameof(CableSetName));
|
||
}
|
||
}
|
||
private ObservableCollection<ec_CableSetWire> _Wire_Tags = new ObservableCollection<ec_CableSetWire>();
|
||
/// <summary>
|
||
/// 线号
|
||
/// </summary>
|
||
public ObservableCollection<ec_CableSetWire> Wire_Tags
|
||
{
|
||
get { return _Wire_Tags; }
|
||
set { _Wire_Tags = value;
|
||
RaisePropertyChanged(nameof(Wire_Tags));
|
||
}
|
||
}
|
||
private ObservableCollection<ec_CableSetWire> _Polaritys = new ObservableCollection<ec_CableSetWire>();
|
||
/// <summary>
|
||
/// 极性
|
||
/// </summary>
|
||
public ObservableCollection<ec_CableSetWire> Polaritys
|
||
{
|
||
get { return _Polaritys; }
|
||
set { _Polaritys = value;
|
||
RaisePropertyChanged(nameof(Polaritys));
|
||
}
|
||
}
|
||
private string _ChannelNumber;
|
||
/// <summary>
|
||
/// 通道号
|
||
/// </summary>
|
||
public string ChannelNumber
|
||
{
|
||
get { return _ChannelNumber; }
|
||
set { _ChannelNumber = value;
|
||
RaisePropertyChanged(nameof(ChannelNumber));
|
||
}
|
||
}
|
||
private string _OccupancyState;
|
||
/// <summary>
|
||
/// 占用状态
|
||
/// </summary>
|
||
public string OccupancyState
|
||
{
|
||
get { return _OccupancyState; }
|
||
set { _OccupancyState = value;
|
||
RaisePropertyChanged(nameof(OccupancyState));
|
||
}
|
||
}
|
||
|
||
#endregion
|
||
#region 扩展字段
|
||
private string _CableID;
|
||
/// <summary>
|
||
/// 电缆ID
|
||
/// </summary>
|
||
public string CableID
|
||
{
|
||
get { return _CableID; }
|
||
set { _CableID = value;
|
||
RaisePropertyChanged(nameof(CableID));
|
||
}
|
||
}
|
||
private string _CableName;
|
||
/// <summary>
|
||
/// 电缆名称,电缆位号
|
||
/// </summary>
|
||
public string CableName
|
||
{
|
||
get { return _CableName; }
|
||
set { _CableName = value;
|
||
RaisePropertyChanged(nameof(CableName));
|
||
}
|
||
}
|
||
private string _CableSetID;
|
||
/// <summary>
|
||
/// 电缆对ID
|
||
/// </summary>
|
||
public string CableSetID
|
||
{
|
||
get { return _CableSetID; }
|
||
set { _CableSetID = value;
|
||
RaisePropertyChanged(nameof(CableSetID));
|
||
}
|
||
}
|
||
private string _StripName;
|
||
/// <summary>
|
||
/// 端子排名称
|
||
/// </summary>
|
||
public string StripName
|
||
{
|
||
get { return _StripName; }
|
||
set { _StripName = value;
|
||
RaisePropertyChanged(nameof(StripName));
|
||
}
|
||
}
|
||
private string _UpdateUserID;
|
||
/// <summary>
|
||
/// 占用人
|
||
/// </summary>
|
||
public string UpdateUserID
|
||
{
|
||
get { return _UpdateUserID; }
|
||
set { _UpdateUserID = value;
|
||
RaisePropertyChanged(nameof(UpdateUserID));
|
||
}
|
||
}
|
||
private bool _IsConned;
|
||
/// <summary>
|
||
/// 是否被连接
|
||
/// </summary>
|
||
public bool IsConned
|
||
{
|
||
get { return _IsConned; }
|
||
set { _IsConned = value;
|
||
RaisePropertyChanged(nameof(IsConned)); }
|
||
}
|
||
|
||
#endregion
|
||
|
||
}
|
||
}
|