2968 lines
173 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.IO;
using System.Linq;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Input;
using System.Windows.Threading;
using Bricscad.ApplicationServices;
using Bricscad.EditorInput;
using OfficeOpenXml;
using Prism.Events;
using Prism.Ioc;
2025-09-04 18:28:02 +08:00
using Prism.Services.Dialogs;
2025-08-15 16:34:31 +08:00
using SWS.CAD.CADFunc;
using SWS.CAD.Event;
using SWS.CAD.ViewModels.myViewModelBase;
using SWS.CAD.Views.Dialog;
2025-09-04 18:28:02 +08:00
using SWS.Commons;
using SWS.Model;
using SWS.Service;
using SWS.WPF.Views;
2025-08-15 16:34:31 +08:00
using Teigha.DatabaseServices;
using Telerik.Windows.Controls;
using Telerik.Windows.Data;
using Unity;
2025-09-04 18:28:02 +08:00
using static SWS.Service.IOModuleService;
2025-08-15 16:34:31 +08:00
using Application = Bricscad.ApplicationServices.Application;
namespace SWS.CAD.ViewModels
{
public class DialogIODistributionViewModel : DialogBase, IDialogAware
{
#region
2025-09-04 18:28:02 +08:00
private ObservableCollection<Model.TreeModel> _PanelTreels = new ObservableCollection<Model.TreeModel>();
2025-08-15 16:34:31 +08:00
/// <summary>
/// 页面左侧树形结构数据
/// </summary>
2025-09-04 18:28:02 +08:00
public ObservableCollection<Model.TreeModel> PanelTreels
2025-08-15 16:34:31 +08:00
{
get { return _PanelTreels; }
set { _PanelTreels = value; RaisePropertyChanged(nameof(PanelTreels)); }
}
2025-09-04 18:28:02 +08:00
private Model.TreeModel _SelectedTreeNode;
2025-08-15 16:34:31 +08:00
/// <summary>
/// 当前选中的树形节点
/// </summary>
2025-09-04 18:28:02 +08:00
public Model.TreeModel SelectedTreeNode
2025-08-15 16:34:31 +08:00
{
get { return _SelectedTreeNode; }
set
{
_SelectedTreeNode = value;
RaisePropertyChanged(nameof(SelectedTreeNode));
UpdateChannelInfos();
}
}
private ObservableCollection<ChannelInfo> _ChannelInfos = new ObservableCollection<ChannelInfo>();
/// <summary>
/// 通道详细信息数据
/// </summary>
public ObservableCollection<ChannelInfo> ChannelInfos
{
get { return _ChannelInfos; }
set { _ChannelInfos = value; RaisePropertyChanged(nameof(ChannelInfos)); }
}
private ChannelInfo _SelectedChannelInfo;
/// <summary>
/// 当前选中的通道信息
/// </summary>
public ChannelInfo SelectedChannelInfo
{
get { return _SelectedChannelInfo; }
set
{
_SelectedChannelInfo = value;
RaisePropertyChanged(nameof(SelectedChannelInfo));
UpdateButtonEnabled();
}
}
private System.Windows.Visibility _WindowVisibility;
/// <summary>
/// 控制页面显示隐藏
/// </summary>
public System.Windows.Visibility WindowVisibility
{
get { return _WindowVisibility; }
set
{
_WindowVisibility = value;
RaisePropertyChanged(nameof(WindowVisibility));
}
}
private bool _WindowTopmost;
/// <summary>
/// 控制页面置顶
/// </summary>
public bool WindowTopmost
{
get { return _WindowTopmost; }
set
{
_WindowTopmost = value;
RaisePropertyChanged(nameof(WindowTopmost));
}
}
private bool _IsEnabledASButton = false;
/// <summary>
/// 控制关联信号按钮的可用状态
/// </summary>
public bool IsEnabledASButton
{
get { return _IsEnabledASButton; }
set
{
_IsEnabledASButton = value;
RaisePropertyChanged(nameof(IsEnabledASButton));
}
}
private bool _IsEnabledClearButton;
/// <summary>
/// 控制解除信号按钮的可用状态
/// </summary>
public bool IsEnabledClearButton
{
get { return _IsEnabledClearButton; }
set
{
_IsEnabledClearButton = value;
RaisePropertyChanged(nameof(IsEnabledClearButton));
}
}
#endregion
/// <summary>
/// 接口服务
/// </summary>
IOModuleService _iOModuleService;
DataItemService _dataItemService;
SettingsService _SettingsService;
ObjectTypeService _objectTypeService;
WireGroupService _wireGroupService;
IEventAggregator _eventAggregator;
DialogIODistribution view;
public DialogIODistributionViewModel()
{
title = "IO分配";
_iOModuleService = GlobalObject.container.Resolve<IOModuleService>();
_dataItemService = GlobalObject.container.Resolve<DataItemService>();
_SettingsService = GlobalObject.container.Resolve<SettingsService>();
_objectTypeService = GlobalObject.container.Resolve<ObjectTypeService>();
_wireGroupService = GlobalObject.container.Resolve<WireGroupService>();
_eventAggregator = GlobalObject.container.Resolve<IEventAggregator>();
_eventAggregator.GetEvent<GetHandsIdEvent>().Subscribe(onGetHandsId, ThreadOption.UIThread, true);
_eventAggregator.GetEvent<GetdwgFileIdEvent>().Subscribe(onGetdwgFileId, ThreadOption.UIThread, true);
}
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()
{
}
public async void OnDialogOpened(IDialogParameters parameters)
{
IsBusy = true;
PanelTreels.AddRange(await _iOModuleService.GetPanelTree());
IsBusy = false;
}
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.info.ToString(), $"{TextInfo}");
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 (smInfos.Any(s => s.IsModified == true))
//{
// MessageBoxResult resultMessage = MessageBox.Show("修改未保存,是否取消修改", "KunHengCAD", MessageBoxButton.OKCancel, MessageBoxImage.Question);
// if (resultMessage != MessageBoxResult.OK)
// {
// return;
// }
//}
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
#region
private ec_PanelStrip panelStrip;
/// <summary>
/// 选择节点改变时,更新通道信息列表
/// </summary>
///
private async void UpdateChannelInfos()
{
IsBusy = true;
try
{
#region
if (ChannelInfos != null)
{
foreach (var item in ChannelInfos)
{
if (item.IsModified)
{
MessageBoxResult result = System.Windows.MessageBox.Show($"内容已修改,是否保存", "KunHengCAD", MessageBoxButton.OKCancel, MessageBoxImage.Question);
if (result == MessageBoxResult.OK)
{
foreach (var ChannelInfo in ChannelInfos)
{
if (ChannelInfo.IsModified)
{
foreach (var Channel in panelStrip.Channels)
{
if (Channel.ChannelID.Equals(ChannelInfo.ChannelID))
{
Channel.ChannelName = ChannelInfo.ChannelNumber;
if (ChannelInfo.Channel_Seq != null)
{
Channel.Channel_Seq = int.Parse(ChannelInfo.Channel_Seq);
}
Channel.FakeGroupDesc = ChannelInfo.ChineseDescription;
Channel.FakeGroupDescEN = ChannelInfo.EnglishDescription;
Channel.FakeSignalType = ChannelInfo.SignalType;
}
}
}
}
var httpres = await _iOModuleService.SavePanelStrip(panelStrip);
if (httpres != null)
{
System.Windows.MessageBox.Show(httpres.ToString(), "KunHengCAD", MessageBoxButton.OK, MessageBoxImage.Warning); return;
}
}
break;
}
}
}
#endregion
if (SelectedTreeNode == null) return;
ChannelInfos.Clear();
if (SelectedTreeNode.parentId == "" || SelectedTreeNode.parentId == "1") return;
panelStrip = await _iOModuleService.GetPanelStrip(SelectedTreeNode.ID);
if (panelStrip != null && panelStrip.Channels.Count > 0)
{
int index = 0;
foreach (var child in panelStrip.Channels.OrderBy(p => p.Channel_Seq).ToList())
{
ChannelInfo c = new ChannelInfo();
//电缆位号,电缆对,电缆线号,极性
foreach (var Term in child.Terms)
{
index++;
c.Index.Add(index.ToString());
if (Term.Connection != null)
{
c.CableTag = Term.Connection.CableName;
c.CablePair = Term.Connection.CableSetName;
c.CableWires.Add(Term.Connection);
c.Polaritys.Add(Term.Connection);
}
//else if (Term.Connection == null && !child.HomerunCableName.Equals(""))
else if (Term.Connection == null)
{
if (!child.HomerunCableName.Equals(""))
{
c.CableTag = child.HomerunCableName;
}
c.CableWires.Add(new ec_WireTerminal());
c.Polaritys.Add(new ec_WireTerminal());
}
}
c.Terms.AddRange(child.Terms);
//关联信号
c.Signal = child.Signal;
if (child.Signal != null)
{
c.SignalName = child.Signal.Group_Name;
c.GroupOther = child.Signal.Signal_Group;
c.SignalCode = child.Signal.Signal_SeqNo;
c.ChineseDescription = child.Signal.Group_Desc;
c.EnglishDescription = child.Signal.Group_Desc_EN;
c.SignalType = child.Signal.IO_Type;
}
c.ChannelNumber = child.ChannelName;
c.Occupant = child.CreateUserID;
c.SignalType = child.FakeSignalType;
c.Io_Type = panelStrip.IO_TYPE;
c.ChannelID = child.ChannelID;
c.StripID = child.StripID;
c.StripName = panelStrip.StripName;
c.PanelID = panelStrip.PanelID;
c.Channel_Seq = child.Channel_Seq.ToString();
c.lock_flg = child.lock_flg;
c.HomerunCableId = child.HomerunCableId;
ChannelInfos.Add(c);
}
}
}
catch (Exception ex)
{
System.Windows.MessageBox.Show(ex.Message, "错误", MessageBoxButton.OK, MessageBoxImage.Error);
}
finally
{
IsBusy = false;
}
}
#endregion
#region
/// <summary>
/// 更新树形结构的方法
/// </summary>
/// <param name="newNodes"></param>
2025-09-04 18:28:02 +08:00
public void UpdateTreeNodes(List<Model.TreeModel> newNodes)
2025-08-15 16:34:31 +08:00
{
// 1. 保存当前选中节点的 ID避免直接引用可能失效
string selectedNodeId = SelectedTreeNode?.ID;
// 2. 更新数据源(清空后重新添加,或根据业务逻辑更新)
PanelTreels.Clear();
foreach (var node in newNodes)
{
PanelTreels.Add(node);
}
// 3. 延迟恢复选中节点(确保 UI 已更新)
Dispatcher.CurrentDispatcher.BeginInvoke((System.Action)(() =>
{
RestoreSelectedNode(selectedNodeId);
}));
}
/// <summary>
/// 恢复选中节点的核心逻辑
/// </summary>
/// <param name="targetNodeId"></param>
private void RestoreSelectedNode(string targetNodeId)
{
if (string.IsNullOrEmpty(targetNodeId)) return;
// 递归查找目标节点
2025-09-04 18:28:02 +08:00
Model.TreeModel foundNode = FindNodeByNodeId(PanelTreels, targetNodeId);
2025-08-15 16:34:31 +08:00
if (foundNode != null)
{
SelectedTreeNode = foundNode;
}
else
{
// 未找到则默认选中根节点(可选逻辑:选中父节点或第一个节点)
SelectedTreeNode = PanelTreels.FirstOrDefault();
}
}
/// <summary>
/// 递归查找节点
/// </summary>
/// <param name="nodes"></param>
/// <param name="nodeId"></param>
/// <returns></returns>
2025-09-04 18:28:02 +08:00
private Model.TreeModel FindNodeByNodeId(IEnumerable<Model.TreeModel> nodes, string nodeId)
2025-08-15 16:34:31 +08:00
{
foreach (var node in nodes)
{
if (node.ID == nodeId) return node;
var childNode = FindNodeByNodeId(node.ChildNodes, nodeId);
if (childNode != null) return childNode;
}
return null;
}
#endregion
#region
private async void UpdateButtonEnabled()
{
if (SelectedChannelInfo != null)
{
if (!string.IsNullOrEmpty(SelectedChannelInfo.CablePair))
{
IsEnabledASButton = true; //如果通道已经关联了电缆对,则可用
}
else
{
IsEnabledASButton = false;
}
if (SelectedChannelInfo.Signal != null)
{
IsEnabledClearButton = true; //如果通道已经关联了信号,则可用
}
else
{
IsEnabledClearButton = false;
}
}
}
#endregion
#region
/// <summary>
/// 获取所有信号类型的模版设置
/// </summary>
/// <param name="IO_types">有参数表示要查询的信号类型</param>
///
private async Task<List<StripParametersInfo>> GetStripParametersInfos(List<string> IO_types = null)
{
List<ec_projectSettings> projectSettings = await _SettingsService.GetList();
if (IO_types == null)
{
IO_types = new List<string>();
foreach (var item in projectSettings)
{
if (item.SettingName.Split('_').Length >= 3)
{
if (!IO_types.Contains(item.SettingName.Split('_')[2]))
{
IO_types.Add(item.SettingName.Split('_')[2]);
}
}
}
}
ObservableCollection<StripParametersInfo> StripParametersInfos = new ObservableCollection<StripParametersInfo>();
int index = 0;
foreach (var iotype in IO_types)
{
index++;
var projectSettingstemp = projectSettings.Where(p => p.SettingName.Contains(iotype.ToString()));
StripParametersInfos.Add(new StripParametersInfo()
{
Index = index,
IoType = iotype,
MaxCount = projectSettingstemp.Where(p => p.SettingName.Contains(iotype)).Select(p => p.SettingValue).FirstOrDefault(),
CHNoPerStrip = projectSettingstemp.Where(p => p.SettingName.Contains(iotype + "_CHNoPerStrip")).Select(p => p.SettingValue).FirstOrDefault(),
TermNoPerCh = projectSettingstemp.Where(p => p.SettingName.Contains(iotype + "_TermNoPerCh")).Select(p => p.SettingValue).FirstOrDefault(),
ChNamePrefix = projectSettingstemp.Where(p => p.SettingName.Contains(iotype + "_ChNamePrefix")).Select(p => p.SettingValue).FirstOrDefault(),
ChNameStartIndex = projectSettingstemp.Where(p => p.SettingName.Contains(iotype + "_ChNameStartIndex")).Select(p => p.SettingValue).FirstOrDefault(),
TermNamingType = projectSettingstemp.Where(p => p.SettingName.Contains(iotype + "_TermNamingType")).Select(p => p.SettingValue).FirstOrDefault(),
TermNamingRule = projectSettingstemp.Where(p => p.SettingName.Contains(iotype + "_TermNamingRule")).Select(p => p.SettingValue).FirstOrDefault(),
TermNamePrefix = projectSettingstemp.Where(p => p.SettingName.Contains(iotype + "_TermNamePrefix")).Select(p => p.SettingValue).FirstOrDefault(),
TermNameSuffix = projectSettingstemp.Where(p => p.SettingName.Contains(iotype + "_TermNameSuffix")).Select(p => p.SettingValue).FirstOrDefault(),
});
}
return StripParametersInfos.ToList();
}
#endregion
#region
/// <summary>
/// 显示属性弹窗
/// </summary>
private ObservableCollection<propertyModel> ShowPropertyMessage(string title, List<propertyModel> listPropertys)
{
ObservableCollection<propertyModel> ReslistPro = new ObservableCollection<propertyModel>();
//打开窗体
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.title.ToString(), title);
para.Add(GlobalObject.dialogPar.para1.ToString(), listPropertys);
var _dialogService = GlobalObject._prismContainer.Resolve<IDialogService>();
_dialogService.ShowDialog(nameof(DialogNewPositional), para, (RES) =>
{
if (RES.Result == ButtonResult.Yes)
{
ReslistPro = RES.Parameters.GetValue<ObservableCollection<propertyModel>>(GlobalObject.dialogPar.para1.ToString());
}
else if (RES.Result == ButtonResult.No)
{
}
});
return ReslistPro;
}
#endregion
#region
public ICommand EditEndCmd => new DelegateCommand(EditEnd);
/// <summary>
/// 编辑结束事件
/// </summary>
/// <param name="parameter"></param>
public virtual void EditEnd(object parameter)
{
//做个标记表示该项修改过
SelectedChannelInfo.IsModified = true;
}
#endregion
#region
public ICommand MouseRightCmd => new DelegateCommand(MouseRight_Click);
/// <summary>
/// 右键点击事件
/// </summary>
/// <param name="parameter"></param>
public virtual async void MouseRight_Click(object parameter)
{
2025-09-04 18:28:02 +08:00
if (parameter.GetType() == typeof(Model.TreeModel))
2025-08-15 16:34:31 +08:00
{
2025-09-04 18:28:02 +08:00
var treeNode = parameter as Model.TreeModel;
2025-08-15 16:34:31 +08:00
dynamic dynamicObj = treeNode.NodeExtData;
string PanelIDValue = dynamicObj.PanelID;
var panel = await _iOModuleService.GetPanel(PanelIDValue);
if (treeNode.NodeType.Equals("1") && treeNode.ID.Equals(PanelIDValue))//节点为采集箱
{
//设置属性窗口要显示的属性
var listPropertys = new List<propertyModel>();
//通过当前采集箱的信号类型给属性修改页面赋值
List<ec_projectSettings> projectSettings = await _SettingsService.GetList();
var IOTypes = new List<string>();
foreach (var item in projectSettings)
{
if (item.SettingName.Split('_').Length >= 3)
{
if (!IOTypes.Contains(item.SettingName.Split('_')[2]))
{
if (item.SettingName.Split('_')[2].Equals("Pulse") || item.SettingName.Split('_')[2].Equals("RS485/422")) continue;
IOTypes.Add(item.SettingName.Split('_')[2]);
}
}
}
foreach (var iotype in IOTypes)
{
if (panel.allowedIOTypes.Split(',').ToList().Contains(iotype))
{
listPropertys.Add(new propertyModel() { Id = iotype, DisplayText = iotype, GroupName = "IO类型设置", PropertyValue = "true", ControlTypeName = PROPERTYType.CheckBox });
}
else
{
listPropertys.Add(new propertyModel() { Id = iotype, DisplayText = iotype, GroupName = "IO类型设置", PropertyValue = "false", ControlTypeName = PROPERTYType.CheckBox });
}
}
Dictionary<string, string> listPanelTrees = new Dictionary<string, string>();
foreach (var PanelTree in PanelTreels)
{
listPanelTrees.Add(PanelTree.Text, PanelTree.Text);
}
listPropertys.Add(new propertyModel() { Id = "位置选择", DisplayText = "位置选择", GroupName = "采集箱位置", PropertyValue = PanelTreels.Where(p => p.ID.Equals(treeNode.parentId)).Select(p => p.Text).FirstOrDefault(), ControlTypeName = PROPERTYType.ComboBox, Item = listPanelTrees });
//打开窗体
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.title.ToString(), "采集箱属性");
para.Add(GlobalObject.dialogPar.para1.ToString(), listPropertys);
var _dialogService = GlobalObject._prismContainer.Resolve<IDialogService>();
_dialogService.ShowDialog(nameof(DialogNewPositional), para, async (RES) =>
{
if (RES.Result == ButtonResult.Yes)
{
var listPro = RES.Parameters.GetValue<ObservableCollection<propertyModel>>(GlobalObject.dialogPar.para1.ToString());
panel.allowedIOTypes = string.Join(",", listPro.Where(p => p.PropertyValue.ToLower().Equals("true")).Select(p => p.DisplayText));
string positionalvalue = listPro.Where(p => p.DisplayText.Equals("位置选择")).Select(p => p.PropertyValue).FirstOrDefault();
panel.Panel_Loc_ID = PanelTreels.Where(p => p.Text.Equals(positionalvalue)).Select(p => p.ID).FirstOrDefault();
//接口调用成功刷新列表
var httpres = await _iOModuleService.SavePanel(panel);
if (httpres != null)
{
System.Windows.MessageBox.Show(httpres.ToString(), "KunHengCAD", MessageBoxButton.OK, MessageBoxImage.Warning); return;
}
PanelTreels.Clear();
PanelTreels.AddRange(await _iOModuleService.GetPanelTree());
}
else if (RES.Result == ButtonResult.No)
{ }
});
}
}
else if (parameter.GetType() == typeof(string))
{
string PanelID = parameter as string;
ec_PanelStrip panelStrip = await _iOModuleService.GetPanelStrip(PanelID.Split(',')[1]);
panelStrip.PanelID = PanelID.Split(',')[0]; //设置端子排的采集箱ID
//接口调用成功刷新列表
var httpres = await _iOModuleService.SavePanelStrip(panelStrip);
if (httpres != null)
{
System.Windows.MessageBox.Show(httpres.ToString(), "KunHengCAD", MessageBoxButton.OK, MessageBoxImage.Warning); return;
}
PanelTreels.Clear();
PanelTreels.AddRange(await _iOModuleService.GetPanelTree());
}
}
#endregion
private List<string> _handles;
/// <summary>
/// 获取选中图元id
/// </summary>
/// <param name="flag"></param>
private void onGetHandsId(List<string> HandsId)
{
_handles = HandsId;
}
private string _dwgFileId;
/// <summary>
/// 获取选中句柄id
/// </summary>
/// <param name="flag"></param>
private void onGetdwgFileId(string dwgFileId)
{
_dwgFileId = dwgFileId;
}
#region
public ICommand HeadButtonCmd => new DelegateCommand(HeadButton_Click);
/// <summary>
/// 页面左侧按钮
/// </summary>
/// <param name="parameter"></param>
public virtual async void HeadButton_Click(object parameter)
{
#region
if (parameter.ToString().Equals("新增位置"))
{
dynamic dynamicObj = SelectedTreeNode.NodeExtData; // 使用dynamic关键字让编译器在运行时解析类型信息
// 获取DataItemID属性的值
var DataItemIDValue = dynamicObj.DataItemID; // 使用属性名直接访问
//设置属性窗口要显示的属性
var listPropertys = new List<propertyModel>();
listPropertys.Add(new propertyModel() { Id = "text", DisplayText = "位置名称", GroupName = "基本参数", PropertyValue = "", ControlTypeName = PROPERTYType.TextBox });
listPropertys.Add(new propertyModel() { Id = "value", DisplayText = "位置描述", GroupName = "基本参数", PropertyValue = "", ControlTypeName = PROPERTYType.TextBox });
listPropertys.Add(new propertyModel() { Id = "nodeType", DisplayText = "排序号", GroupName = "基本参数", PropertyValue = "0", ControlTypeName = PROPERTYType.TextBox });
//打开窗体
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.title.ToString(), "新增位置参数");
para.Add(GlobalObject.dialogPar.para1.ToString(), listPropertys);
var _dialogService = GlobalObject._prismContainer.Resolve<IDialogService>();
_dialogService.ShowDialog(nameof(DialogNewPositional), para, async (RES) =>
{
if (RES.Result == ButtonResult.Yes)
{
var listPro = RES.Parameters.GetValue<ObservableCollection<propertyModel>>(GlobalObject.dialogPar.para1.ToString());
2025-09-04 18:28:02 +08:00
Model.ec_dataitemdetail ent = new Model.ec_dataitemdetail()
2025-08-15 16:34:31 +08:00
{
DataItemID = DataItemIDValue,
DataItemCode = listPro.Where(p => p.DisplayText.Equals("位置描述")).Select(p => p.PropertyValue).FirstOrDefault(),
DataItemName = listPro.Where(p => p.DisplayText.Equals("位置名称")).Select(p => p.PropertyValue).FirstOrDefault(),
OrderID = int.Parse(listPro.Where(p => p.DisplayText.Equals("排序号")).Select(p => p.PropertyValue).FirstOrDefault()),
};
var httpres = await _dataItemService.SaveDetailForm(ent);
if (httpres != null)
{
System.Windows.MessageBox.Show(httpres.ToString(), "KunHengCAD", MessageBoxButton.OK, MessageBoxImage.Warning); return;
}
PanelTreels.Clear();
PanelTreels.AddRange(await _iOModuleService.GetPanelTree());
}
else if (RES.Result == ButtonResult.No)
{ }
});
return;
}
#endregion
#region
if (parameter.ToString().Equals("新建端子排"))
{
dynamic dynamicObj = SelectedTreeNode.NodeExtData; // 使用dynamic关键字让编译器在运行时解析类型信息
string PanelIDValue = dynamicObj.PanelID; // 使用属性名直接访问
var panel = await _iOModuleService.GetPanel(PanelIDValue);
if (panel != null)
{
if (string.IsNullOrEmpty(panel.allowedIOTypes))
{
System.Windows.MessageBox.Show("该设备未设置支持的信号类型", "KunHengCAD", MessageBoxButton.OK, MessageBoxImage.Warning); return;
}
List<ec_projectSettings> projectSettings = await _SettingsService.GetList();
ObservableCollection<StripParametersInfo> StripParametersInfos = new ObservableCollection<StripParametersInfo>();
int index = 0;
foreach (var iotype in panel.allowedIOTypes.Split(',').ToList())
{
index++;
var projectSettingstemp = projectSettings.Where(p => p.SettingName.Contains(iotype.ToString()));
StripParametersInfos.Add(new StripParametersInfo()
{
Index = index,
IoType = iotype,
MaxCount = projectSettingstemp.Where(p => p.SettingName.Contains(iotype)).Select(p => p.SettingValue).FirstOrDefault(),
CHNoPerStrip = projectSettingstemp.Where(p => p.SettingName.Contains(iotype + "_CHNoPerStrip")).Select(p => p.SettingValue).FirstOrDefault(),
TermNoPerCh = projectSettingstemp.Where(p => p.SettingName.Contains(iotype + "_TermNoPerCh")).Select(p => p.SettingValue).FirstOrDefault(),
ChNamePrefix = projectSettingstemp.Where(p => p.SettingName.Contains(iotype + "_ChNamePrefix")).Select(p => p.SettingValue).FirstOrDefault(),
ChNameStartIndex = projectSettingstemp.Where(p => p.SettingName.Contains(iotype + "_ChNameStartIndex")).Select(p => p.SettingValue).FirstOrDefault(),
TermNamingType = projectSettingstemp.Where(p => p.SettingName.Contains(iotype + "_TermNamingType")).Select(p => p.SettingValue).FirstOrDefault(),
TermNamingRule = projectSettingstemp.Where(p => p.SettingName.Contains(iotype + "_TermNamingRule")).Select(p => p.SettingValue).FirstOrDefault(),
TermNamePrefix = projectSettingstemp.Where(p => p.SettingName.Contains(iotype + "_TermNamePrefix")).Select(p => p.SettingValue).FirstOrDefault(),
TermNameSuffix = projectSettingstemp.Where(p => p.SettingName.Contains(iotype + "_TermNameSuffix")).Select(p => p.SettingValue).FirstOrDefault(),
});
}
//打开窗体
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.title.ToString(), "端子排模版");
para.Add(GlobalObject.dialogPar.para1.ToString(), StripParametersInfos);
para.Add(GlobalObject.dialogPar.para2.ToString(), true);
var _dialogService = GlobalObject._prismContainer.Resolve<IDialogService>();
_dialogService.ShowDialog(nameof(DialogNewStrip), para, (RES) =>
{
if (RES.Result == ButtonResult.Yes)
{
var stripParametersInfo = RES.Parameters.GetValue<StripParametersInfo>(GlobalObject.dialogPar.para1.ToString());
var listPropertys = new List<propertyModel>();
listPropertys.Add(new propertyModel() { Id = "IO_TYPE", DisplayText = "信号类型", GroupName = "基本参数", PropertyValue = stripParametersInfo.IoType, ControlTypeName = PROPERTYType.TextBox, IsEnable = false });
listPropertys.Add(new propertyModel() { Id = "StripName", DisplayText = "端子排名称", GroupName = "基本参数", PropertyValue = "", ControlTypeName = PROPERTYType.TextBox });
listPropertys.Add(new propertyModel() { Id = "CHNoPerStrip", DisplayText = "通道数量", GroupName = "基本参数", PropertyValue = stripParametersInfo.CHNoPerStrip, ControlTypeName = PROPERTYType.TextBox });
listPropertys.Add(new propertyModel() { Id = "TermNoPerCh", DisplayText = "每通道端子数", GroupName = "基本参数", PropertyValue = stripParametersInfo.TermNoPerCh, ControlTypeName = PROPERTYType.TextBox });
listPropertys.Add(new propertyModel() { Id = "nodeType", DisplayText = "排序号", GroupName = "基本参数", PropertyValue = "0", ControlTypeName = PROPERTYType.TextBox });
listPropertys.Add(new propertyModel() { Id = "ChNamePrefix", DisplayText = "通道前缀", GroupName = "通道编号", PropertyValue = stripParametersInfo.ChNamePrefix, ControlTypeName = PROPERTYType.TextBox });
listPropertys.Add(new propertyModel() { Id = "ChNameStartIndex", DisplayText = "通道起始编号", GroupName = "通道编号", PropertyValue = stripParametersInfo.ChNameStartIndex, ControlTypeName = PROPERTYType.TextBox });
Dictionary<string, string> listTermNamingType = new Dictionary<string, string>();
listTermNamingType.Add("数字", "数字");
listTermNamingType.Add("字母", "字母");
listPropertys.Add(new propertyModel() { Id = "TermNamingType", DisplayText = "编号类型", GroupName = "端子编号", PropertyValue = stripParametersInfo.TermNamingType, ControlTypeName = PROPERTYType.ComboBox, Item = listTermNamingType });
Dictionary<string, string> listTermNamingRule = new Dictionary<string, string>();
listTermNamingRule.Add("按端子排全局编号", "按端子排全局编号");
listTermNamingRule.Add("按通道内端子编号", "按通道内端子编号");
listTermNamingRule.Add("按通道编号", "按通道编号");
listPropertys.Add(new propertyModel() { Id = "TermNamingRule", DisplayText = "编号规则", GroupName = "端子编号", PropertyValue = stripParametersInfo.TermNamingRule, ControlTypeName = PROPERTYType.ComboBox, Item = listTermNamingRule });
Dictionary<string, string> listTermNamePrefix = new Dictionary<string, string>();
listTermNamePrefix.Add("通道编号", "通道编号");
listTermNamePrefix.Add("+,-,s", "+,-,s");
listTermNamePrefix.Add("无", "无");
listPropertys.Add(new propertyModel() { Id = "TermNamePrefix", DisplayText = "端子前缀", GroupName = "端子编号", PropertyValue = stripParametersInfo.TermNamePrefix, ControlTypeName = PROPERTYType.ComboBox, Item = listTermNamePrefix });
Dictionary<string, string> listTermNameSuffix = new Dictionary<string, string>();
listTermNameSuffix.Add("通道编号", "通道编号");
listTermNameSuffix.Add("+,-,s", "+,-,s");
listTermNameSuffix.Add("无", "无");
listPropertys.Add(new propertyModel() { Id = "TermNameSuffix", DisplayText = "端子后缀", GroupName = "端子编号", PropertyValue = stripParametersInfo.TermNameSuffix, ControlTypeName = PROPERTYType.ComboBox, Item = listTermNameSuffix });
//打开窗体
2025-09-04 18:28:02 +08:00
para = new Prism.Services.Dialogs.DialogParameters();
2025-08-15 16:34:31 +08:00
para.Add(GlobalObject.dialogPar.title.ToString(), "新建端子排");
para.Add(GlobalObject.dialogPar.para1.ToString(), listPropertys);
_dialogService = GlobalObject._prismContainer.Resolve<IDialogService>();
_dialogService.ShowDialog(nameof(DialogNewPositional), para, async (RES1) =>
{
if (RES1.Result == ButtonResult.Yes)
{
var listPro = RES1.Parameters.GetValue<ObservableCollection<propertyModel>>(GlobalObject.dialogPar.para1.ToString());
#region
int GlobalTermNumber = 0;//全局端子编号
ec_PanelStrip e = new ec_PanelStrip();
e.IO_TYPE = listPro.Where(p => p.DisplayText.Equals("信号类型")).Select(p => p.PropertyValue).FirstOrDefault();
e.StripName = listPro.Where(p => p.DisplayText.Equals("端子排名称")).Select(p => p.PropertyValue).FirstOrDefault();
e.PanelID = panel.PanelID;
int.TryParse(listPro.Where(p => p.DisplayText.Equals("通道数量")).Select(p => p.PropertyValue).FirstOrDefault(), out int CHNoPerStrip);
for (int i = 0; i < CHNoPerStrip; i++)
{
ec_PanelChannel panelChannel = new ec_PanelChannel();
int channel_No = int.TryParse(listPro.Where(p => p.DisplayText.Equals("通道起始编号")).Select(p => p.PropertyValue).FirstOrDefault(), out int channel_no) ? channel_no : 1;
panelChannel.ChannelName = listPro.Where(p => p.DisplayText.Equals("通道前缀")).Select(p => p.PropertyValue).FirstOrDefault() + (channel_No + i);
panelChannel.Channel_Seq = i + 1;
panelChannel.Terms = new List<ec_PanelStripTerm>();
int.TryParse(listPro.Where(p => p.DisplayText.Equals("每通道端子数")).Select(p => p.PropertyValue).FirstOrDefault(), out int TermNoPerCh);
for (int j = 0; j < TermNoPerCh; j++)
{
GlobalTermNumber++;
ec_PanelStripTerm panelTerm = new ec_PanelStripTerm();
string a = "";//组成端子名的前缀
string b = "";//端子名的中间部分
string c = "";//组成端子名的后缀
if (listPro.Where(p => p.DisplayText.Equals("端子前缀")).Select(p => p.PropertyValue).FirstOrDefault() != null)
{
if (listPro.Where(p => p.DisplayText.Equals("端子前缀")).Select(p => p.PropertyValue).FirstOrDefault().Equals("通道编号"))
{
a = (channel_No + i).ToString();
}
else if (listPro.Where(p => p.DisplayText.Equals("端子前缀")).Select(p => p.PropertyValue).FirstOrDefault().Equals("+,-,s"))
{
a = listPro.Where(p => p.DisplayText.Equals("端子前缀")).Select(p => p.PropertyValue).FirstOrDefault().Split(',')[Math.Abs(j % 3 - 3)];
}
}
if (listPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault() != null)
{
if (listPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("数字"))
{
if (listPro.Where(p => p.DisplayText.Equals("编号规则")).Select(p => p.PropertyValue).FirstOrDefault() != null)
{
if (listPro.Where(p => p.DisplayText.Equals("编号规则")).Select(p => p.PropertyValue).FirstOrDefault().Equals("按端子排全局编号"))
{
b = GlobalTermNumber.ToString();
}
else if (listPro.Where(p => p.DisplayText.Equals("编号规则")).Select(p => p.PropertyValue).FirstOrDefault().Equals("按通道内端子编号"))
{
b = (j + 1).ToString();
}
else if (listPro.Where(p => p.DisplayText.Equals("编号规则")).Select(p => p.PropertyValue).FirstOrDefault().Equals("按通道编号"))
{
b = (channel_No + i).ToString();
}
}
}
else if (listPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("字母"))
{
if (listPro.Where(p => p.DisplayText.Equals("编号规则")).Select(p => p.PropertyValue).FirstOrDefault() != null)
{
if (listPro.Where(p => p.DisplayText.Equals("编号规则")).Select(p => p.PropertyValue).FirstOrDefault().Equals("按端子排全局编号"))
{
b = b + (char)('A' + GlobalTermNumber);
}
else if (listPro.Where(p => p.DisplayText.Equals("编号规则")).Select(p => p.PropertyValue).FirstOrDefault().Equals("按通道内端子编号"))
{
b = b + (char)('A' + j);
}
else if (listPro.Where(p => p.DisplayText.Equals("编号规则")).Select(p => p.PropertyValue).FirstOrDefault().Equals("按通道编号"))
{
b = b + (char)('A' + channel_No + j);
}
}
}
}
if (listPro.Where(p => p.DisplayText.Equals("端子后缀")).Select(p => p.PropertyValue).FirstOrDefault() != null)
{
if (listPro.Where(p => p.DisplayText.Equals("端子后缀")).Select(p => p.PropertyValue).FirstOrDefault().Equals("通道编号"))
{
c = (channel_No + i).ToString();
}
else if (listPro.Where(p => p.DisplayText.Equals("端子后缀")).Select(p => p.PropertyValue).FirstOrDefault().Equals("+,-,s"))
{
c = listPro.Where(p => p.DisplayText.Equals("端子后缀")).Select(p => p.PropertyValue).FirstOrDefault().Split(',')[Math.Abs(j % 3 - 3)];
}
}
panelTerm.Term_No = a + b + c;
panelTerm.Term_Seq = j + 1;
panelChannel.Terms.Add(panelTerm);
}
e.Channels.Add(panelChannel);
}
#endregion
var httpres = await _iOModuleService.CreatePanelStripByProfile(e);
if (httpres != null)
{
System.Windows.MessageBox.Show(httpres.ToString(), "KunHengCAD", MessageBoxButton.OK, MessageBoxImage.Warning); return;
}
PanelTreels.Clear();
PanelTreels.AddRange(await _iOModuleService.GetPanelTree());
}
else if (RES.Result == ButtonResult.No)
{ }
});
}
else if (RES.Result == ButtonResult.No)
{ }
});
}
return;
}
#endregion
#region
if (parameter.ToString().Equals("修改位置,端子排信息"))
{
if (SelectedTreeNode.parentId.Equals("0"))//当前选中节点是位置节点时,打开编辑位置参数窗体
{
dynamic dynamicObj = SelectedTreeNode.NodeExtData; // 使用dynamic关键字让编译器在运行时解析类型信息
// 获取DataItemID属性的值
var DataItemIDValue = dynamicObj.DataItemID; // 使用属性名直接访问
var DataItemDetailIDValue = dynamicObj.DataItemDetailID;
var OrderIDValue = dynamicObj.OrderID;
var DataItemCodeValue = dynamicObj.DataItemCode;
var DataItemNameValue = dynamicObj.DataItemName;
var listPropertys = new List<propertyModel>();
listPropertys.Add(new propertyModel() { Id = "text", DisplayText = "位置名称", GroupName = "基本参数", PropertyValue = DataItemNameValue, ControlTypeName = PROPERTYType.TextBox });
listPropertys.Add(new propertyModel() { Id = "value", DisplayText = "位置描述", GroupName = "基本参数", PropertyValue = DataItemCodeValue, ControlTypeName = PROPERTYType.TextBox });
listPropertys.Add(new propertyModel() { Id = "nodeType", DisplayText = "排序号", GroupName = "基本参数", PropertyValue = OrderIDValue, ControlTypeName = PROPERTYType.TextBox });
//打开窗体
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.title.ToString(), "编辑位置参数");
para.Add(GlobalObject.dialogPar.para1.ToString(), listPropertys);
var _dialogService = GlobalObject._prismContainer.Resolve<IDialogService>();
_dialogService.ShowDialog(nameof(DialogNewPositional), para, async (RES) =>
{
if (RES.Result == ButtonResult.Yes)
{
var listPro = RES.Parameters.GetValue<ObservableCollection<propertyModel>>(GlobalObject.dialogPar.para1.ToString());
2025-09-04 18:28:02 +08:00
Model.ec_dataitemdetail ent = new Model.ec_dataitemdetail()
2025-08-15 16:34:31 +08:00
{
DataItemID = DataItemIDValue,
DataItemDetailID = DataItemDetailIDValue,
DataItemCode = listPro.Where(p => p.DisplayText.Equals("位置描述")).Select(p => p.PropertyValue).FirstOrDefault(),
DataItemName = listPro.Where(p => p.DisplayText.Equals("位置名称")).Select(p => p.PropertyValue).FirstOrDefault(),
OrderID = int.Parse(listPro.Where(p => p.DisplayText.Equals("排序号")).Select(p => p.PropertyValue).FirstOrDefault()),
};
var httpres = await _dataItemService.SaveDetailForm(ent);
if (httpres != null)
{
System.Windows.MessageBox.Show(httpres.ToString(), "KunHengCAD", MessageBoxButton.OK, MessageBoxImage.Warning); return;
}
PanelTreels.Clear();
PanelTreels.AddRange(await _iOModuleService.GetPanelTree());
}
else if (RES.Result == ButtonResult.No)
{ }
});
return;
}
else//当前选中节点是端子排是,打开编辑端子排参数窗体
{
dynamic dynamicObj = SelectedTreeNode.NodeExtData; // 使用dynamic关键字让编译器在运行时解析类型信息
var StripNameValue = dynamicObj.StripName; // 使用属性名直接访问
var IO_TYPEValue = dynamicObj.IO_TYPE;
var PanelIDValue = dynamicObj.PanelID;
var StripIDValue = dynamicObj.StripID;
var Panel_Strip_SeqValue = dynamicObj.Panel_Strip_Seq;
var listPropertys = new List<propertyModel>();
listPropertys.Add(new propertyModel() { Id = "StripName", DisplayText = "端子排名称", GroupName = "基本参数", PropertyValue = StripNameValue, ControlTypeName = PROPERTYType.TextBox });
listPropertys.Add(new propertyModel() { Id = "IO_TYPE", DisplayText = "信号类型", GroupName = "基本参数", PropertyValue = IO_TYPEValue, ControlTypeName = PROPERTYType.TextBox });
listPropertys.Add(new propertyModel() { Id = "Panel_Strip_Seq", DisplayText = "排序号", GroupName = "基本参数", PropertyValue = Panel_Strip_SeqValue, ControlTypeName = PROPERTYType.TextBox });
//打开窗体
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.title.ToString(), "编辑端子排");
para.Add(GlobalObject.dialogPar.para1.ToString(), listPropertys);
var _dialogService = GlobalObject._prismContainer.Resolve<IDialogService>();
_dialogService.ShowDialog(nameof(DialogNewPositional), para, async (RES) =>
{
if (RES.Result == ButtonResult.Yes)
{
var listPro = RES.Parameters.GetValue<ObservableCollection<propertyModel>>(GlobalObject.dialogPar.para1.ToString());
ec_PanelStrip ent = new ec_PanelStrip()
{
IO_TYPE = listPro.Where(p => p.DisplayText.Equals("信号类型")).Select(p => p.PropertyValue).FirstOrDefault(),
StripName = listPro.Where(p => p.DisplayText.Equals("端子排名称")).Select(p => p.PropertyValue).FirstOrDefault(),
Panel_Strip_Seq = int.TryParse(listPro.Where(p => p.DisplayText.Equals("排序号")).Select(p => p.PropertyValue).FirstOrDefault(), out int result) ? result : 0,
PanelID = PanelIDValue,
StripID = StripIDValue,
};
var httpres = await _iOModuleService.SavePanelStrip(ent);
if (httpres != null)
{
System.Windows.MessageBox.Show(httpres.ToString(), "KunHengCAD", MessageBoxButton.OK, MessageBoxImage.Warning); return;
}
PanelTreels.Clear();
PanelTreels.AddRange(await _iOModuleService.GetPanelTree());
}
else if (RES.Result == ButtonResult.No)
{ }
});
return;
}
}
#endregion
#region
if (parameter.ToString().Equals("删除节点"))
{
if (SelectedTreeNode.NodeType.Equals("0"))
{
MessageBoxResult result = System.Windows.MessageBox.Show($"确定删除[{SelectedTreeNode.Text}]节点以及子节点吗", "KunHengCAD", MessageBoxButton.OKCancel, MessageBoxImage.Question);
if (result == MessageBoxResult.OK)
{
//var httpres = await _iOModuleService.DeletePanel(SelectedTreeNode.ID);
}
}
else
{
MessageBoxResult result = System.Windows.MessageBox.Show($"确定删除[{SelectedTreeNode.Text}]节点以及子节点吗", "KunHengCAD", MessageBoxButton.OKCancel, MessageBoxImage.Question);
if (result == MessageBoxResult.OK)
{
var httpres = await _iOModuleService.DeletePanelStrip(SelectedTreeNode.ID);
}
}
return;
}
#endregion
#region
if (parameter.ToString().Equals("选择位号关联通道"))
{
if (SelectedChannelInfo == null)
{
System.Windows.MessageBox.Show("请先选定通道", "KunHengCAD", MessageBoxButton.OK, MessageBoxImage.Warning); return;
}
else
{
IsBusy = true;
var listPropertys = new List<propertyModel>();
2025-09-04 18:28:02 +08:00
List<Model.ec_enginedata> AllTagNumbers = await _objectTypeService.GetListBySQL("ObjectTypeName like '%电缆%'");
2025-08-15 16:34:31 +08:00
if (AllTagNumbers == null) return;
Dictionary<string, string> listTagNumbers = new Dictionary<string, string>();
listTagNumbers.Add("新增电缆位号", "新增电缆位号");
foreach (var TagNumber in AllTagNumbers)
{
listTagNumbers.Add(TagNumber.TagNumber, TagNumber.TagNumber);
}
listPropertys.Add(new propertyModel() { Id = "TagNumber", DisplayText = "电缆位号", GroupName = "位号列表", PropertyValue = "", ControlTypeName = PROPERTYType.ComboBox, Item = listTagNumbers, IsReturnChanged = true, WhichPage = "电缆位号选择" });
IsBusy = false;
//打开窗体
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.title.ToString(), "电缆位号选择");
para.Add(GlobalObject.dialogPar.para1.ToString(), listPropertys);
var _dialogService = GlobalObject._prismContainer.Resolve<IDialogService>();
_dialogService.ShowDialog(nameof(DialogNewPositional), para, async (RES) =>
{
if (RES.Result == ButtonResult.Yes)
{
var listPro = RES.Parameters.GetValue<ObservableCollection<propertyModel>>(GlobalObject.dialogPar.para1.ToString());
var selectTagNumber = listPro.Where(p => p.DisplayText.Equals("电缆位号")).Select(p => p.PropertyValue).FirstOrDefault();
var selectTagNumberOB = AllTagNumbers.Where(a => a.TagNumber.Equals(selectTagNumber)).FirstOrDefault();
var ObjectTypePListBy = await _objectTypeService.GetObjectTypePListByIds(selectTagNumberOB.ObjectTypeID);
string CableSpecification = ObjectTypePListBy.Where(q => q.PropertyName.Equals("电缆规格")).Select(s => s.EnumDataCode).FirstOrDefault();
CableSpecification = CableSpecification.Substring(0, CableSpecification.Length - 1);
CableSpecification.Split(',').ToList();
var b = await _objectTypeService.GetLatestSerialNumber(selectTagNumberOB.ObjectTypeID);
//获取位号的电缆属性,判断是否设置电缆规格
var TagNumberBys = await _objectTypeService.GetEngineDataListByTags(selectTagNumberOB.TagNumber);
var TagNumberBy = TagNumberBys.Where(t => t.TagNumber.Equals(selectTagNumberOB.TagNumber)).FirstOrDefault();
if (!CableSpecification.Split(',').ToList().Contains(TagNumberBy.EngineDataProperty.Where(e => e.PropertyName.Equals("电缆规格")).Select(e => e.PropertyValue).FirstOrDefault()))
{
System.Windows.MessageBox.Show("无法获取电缆对信息,请在电缆\"属性面版“输入电缆”电缆规格”属性\r\n如:“1x2x0.75”", "KunHengCAD", MessageBoxButton.OK, MessageBoxImage.Warning); return;
}
//获取电缆的配置,没有则创建新配置
var CableBy = await _iOModuleService.GetCableByEngID(selectTagNumberOB.EngineDataID);
if (CableBy == null)
{
MessageBoxResult result = System.Windows.MessageBox.Show($"是否为通讯母线?", "KunHengCAD", MessageBoxButton.OKCancel, MessageBoxImage.Question);
if (result == MessageBoxResult.OK)
{
listPropertys = new List<propertyModel>();
Dictionary<string, string> pulldownlist;
listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "电缆对数", GroupName = "基本参数", PropertyValue = "1", ControlTypeName = PROPERTYType.TextBox, });
listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "每电缆对芯数", GroupName = "基本参数", PropertyValue = "2", ControlTypeName = PROPERTYType.TextBox, });
listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "电缆对编号前缀", GroupName = "基本参数", PropertyValue = "Set", ControlTypeName = PROPERTYType.TextBox, });
pulldownlist = new Dictionary<string, string>();
pulldownlist.Add("数字", "数字");
pulldownlist.Add("字母", "字母");
pulldownlist.Add("电缆对序号", "电缆对序号");
listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "编号类型", GroupName = "电芯参数", PropertyValue = "数字", ControlTypeName = PROPERTYType.ComboBox, Item = pulldownlist, });
pulldownlist = new Dictionary<string, string>();
pulldownlist.Add("按电缆编号", "按电缆编号");
pulldownlist.Add("按电缆对编号", "按电缆对编号");
listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "编号规则", GroupName = "电芯参数", PropertyValue = "按电缆对编号", ControlTypeName = PROPERTYType.ComboBox, Item = pulldownlist, });
listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "电芯编号前缀", GroupName = "电芯参数", PropertyValue = "C", ControlTypeName = PROPERTYType.TextBox, });
listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "极性", GroupName = "电芯参数", PropertyValue = "+,-,s", ControlTypeName = PROPERTYType.TextBox, });
//显示属性弹窗
var ReslistPro = ShowPropertyMessage("新建" + selectTagNumber + "电缆配置", listPropertys);
if (ReslistPro == null || ReslistPro.Count == 0) return;
ec_Cable ec_Cable = new ec_Cable();
ec_Cable.CableClass = "homerun";//母线
ec_Cable.Cable_Format = TagNumberBy.EngineDataProperty.Where(e => e.PropertyName.Equals("电缆规格")).Select(e => e.PropertyValue).FirstOrDefault();
ec_Cable.EngineerDataID = selectTagNumberOB.EngineDataID;
ec_Cable.Sets = new List<ec_CableSet>();
int CableSetCount = int.TryParse(ReslistPro.Where(p => p.DisplayText.Equals("电缆对数")).Select(p => p.PropertyValue).FirstOrDefault(), out CableSetCount) ? CableSetCount : 0;
for (int i = 0; i < CableSetCount; i++)
{
ec_CableSet ec_CableSet = new ec_CableSet();
ec_CableSet.CableSetName = ReslistPro.Where(p => p.DisplayText.Equals("电缆对编号前缀")).Select(p => p.PropertyValue).FirstOrDefault() + (i + 1);
ec_CableSet.CableSetSeq = i + 1;
ec_CableSet.Wires = new List<ec_CableSetWire>();
int WireCount = int.TryParse(ReslistPro.Where(p => p.DisplayText.Equals("每电缆对芯数")).Select(p => p.PropertyValue).FirstOrDefault(), out WireCount) ? WireCount : 0;
for (int j = 0; j < WireCount; j++)
{
ec_CableSetWire ec_CableSetWire = new ec_CableSetWire();
ec_CableSetWire.Polarity = ReslistPro.Where(p => p.DisplayText.Equals("极性")).Select(p => p.PropertyValue).FirstOrDefault().Split(',')[Math.Abs(j % 3)];
ec_CableSetWire.SetLevel = j + 1;
string a = ReslistPro.Where(p => p.DisplayText.Equals("电芯编号前缀")).Select(p => p.PropertyValue).FirstOrDefault();//组成线号名的前缀
string Tag = "";//线号名的中间部分
switch (ReslistPro.Where(p => p.DisplayText.Equals("编号规则")).Select(p => p.PropertyValue).FirstOrDefault())
{
case "按电缆编号":
if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("数字"))
{
Tag = (j + 1).ToString();
}
else if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("字母"))
{
Tag = Tag + (char)('A' + j);
}
else if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("电缆对序号"))
{
Tag = (i + 1).ToString();
}
break;
case "按电缆对编号":
a = selectTagNumberOB.TagNumber;
break;
}
ec_CableSetWire.Wire_Tag = a + Tag;
ec_CableSet.Wires.Add(ec_CableSetWire);
}
ec_Cable.Sets.Add(ec_CableSet);
}
var httpres = await _iOModuleService.CreateCableByProfile(ec_Cable);
CableBy = await _iOModuleService.GetCableByEngID(selectTagNumberOB.EngineDataID);
}
else
{
listPropertys = new List<propertyModel>();
Dictionary<string, string> pulldownlist;
listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "电缆对数", GroupName = "基本参数", PropertyValue = "10", ControlTypeName = PROPERTYType.TextBox, });
listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "每电缆对芯数", GroupName = "基本参数", PropertyValue = "2", ControlTypeName = PROPERTYType.TextBox, });
listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "电缆对编号前缀", GroupName = "基本参数", PropertyValue = "Set", ControlTypeName = PROPERTYType.TextBox, });
pulldownlist = new Dictionary<string, string>();
pulldownlist.Add("数字", "数字");
pulldownlist.Add("字母", "字母");
pulldownlist.Add("电缆对序号", "电缆对序号");
listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "编号类型", GroupName = "电芯参数", PropertyValue = "数字", ControlTypeName = PROPERTYType.ComboBox, Item = pulldownlist, });
pulldownlist = new Dictionary<string, string>();
pulldownlist.Add("按电缆编号", "按电缆编号");
pulldownlist.Add("按电缆对编号", "按电缆对编号");
listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "编号规则", GroupName = "电芯参数", PropertyValue = "按电缆对编号", ControlTypeName = PROPERTYType.ComboBox, Item = pulldownlist, });
listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "电芯编号前缀", GroupName = "电芯参数", PropertyValue = "C", ControlTypeName = PROPERTYType.TextBox, });
listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "极性", GroupName = "电芯参数", PropertyValue = "+,-,s", ControlTypeName = PROPERTYType.TextBox, });
//显示属性弹窗
var ReslistPro = ShowPropertyMessage("新建" + selectTagNumber + "电缆配置", listPropertys);
if (ReslistPro == null || ReslistPro.Count == 0) return;
ec_Cable ec_Cable = new ec_Cable();
ec_Cable.CableClass = "conventional";//常规电缆
ec_Cable.EngineerDataID = selectTagNumberOB.EngineDataID;
ec_Cable.Sets = new List<ec_CableSet>();
int CableSetCount = int.TryParse(ReslistPro.Where(p => p.DisplayText.Equals("电缆对数")).Select(p => p.PropertyValue).FirstOrDefault(), out CableSetCount) ? CableSetCount : 0;
for (int i = 0; i < CableSetCount; i++)
{
ec_CableSet ec_CableSet = new ec_CableSet();
ec_CableSet.CableSetName = ReslistPro.Where(p => p.DisplayText.Equals("电缆对编号前缀")).Select(p => p.PropertyValue).FirstOrDefault() + (i + 1);
ec_CableSet.CableSetSeq = i + 1;
ec_CableSet.Wires = new List<ec_CableSetWire>();
int WireCount = int.TryParse(ReslistPro.Where(p => p.DisplayText.Equals("每电缆对芯数")).Select(p => p.PropertyValue).FirstOrDefault(), out WireCount) ? WireCount : 0;
for (int j = 0; j < WireCount; j++)
{
ec_CableSetWire ec_CableSetWire = new ec_CableSetWire();
ec_CableSetWire.Polarity = ReslistPro.Where(p => p.DisplayText.Equals("极性")).Select(p => p.PropertyValue).FirstOrDefault().Split(',')[Math.Abs(j % 3)];
ec_CableSetWire.SetLevel = j + 1;
string a = ReslistPro.Where(p => p.DisplayText.Equals("电芯编号前缀")).Select(p => p.PropertyValue).FirstOrDefault();//组成线号名的前缀
string Tag = "";//线号名的中间部分
switch (ReslistPro.Where(p => p.DisplayText.Equals("编号规则")).Select(p => p.PropertyValue).FirstOrDefault())
{
case "按电缆编号":
if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("数字"))
{
Tag = (j + 1).ToString();
}
else if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("字母"))
{
Tag = Tag + (char)('A' + j);
}
else if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("电缆对序号"))
{
Tag = (i + 1).ToString();
}
break;
case "按电缆对编号":
a = selectTagNumberOB.TagNumber;
break;
}
ec_CableSetWire.Wire_Tag = a + Tag;
ec_CableSet.Wires.Add(ec_CableSetWire);
}
ec_Cable.Sets.Add(ec_CableSet);
}
var httpres = await _iOModuleService.CreateCableByProfile(ec_Cable);
CableBy = await _iOModuleService.GetCableByEngID(selectTagNumberOB.EngineDataID);
}
}
if (CableBy != null)
{
if (CableBy.CableClass.Equals("homerun"))//母线电缆
{
//SavePanelStrip
ec_PanelStrip newPanelStrip = new ec_PanelStrip();
newPanelStrip.IO_TYPE = panelStrip.IO_TYPE;
newPanelStrip.PanelID = panelStrip.PanelID;
newPanelStrip.StripID = panelStrip.StripID;
newPanelStrip.StripName = panelStrip.StripName;
newPanelStrip.Channels = new List<ec_PanelChannel>();
foreach (var channel in panelStrip.Channels)
{
ec_PanelChannel newChannel = new ec_PanelChannel();
newChannel.ChannelID = channel.ChannelID;
newChannel.ChannelName = channel.ChannelName;
newChannel.Channel_Seq = channel.Channel_Seq;
newChannel.StripID = channel.StripID;
newChannel.lock_flg = channel.lock_flg;
if (channel.ChannelName.Equals(SelectedChannelInfo.ChannelNumber))
{
newChannel.HomerunCableId = CableBy.CableID;
newChannel.HomerunCableName = CableBy.TagNumber;
}
newChannel.Terms = new List<ec_PanelStripTerm>();
foreach (var term in channel.Terms)
{
ec_PanelStripTerm newTerm = new ec_PanelStripTerm();
newTerm.Connection = new ec_WireTerminal();
newTerm.ChannelID = term.ChannelID;
newTerm.StripID = term.StripID;
newTerm.TermID = term.TermID;
newTerm.Term_No = term.Term_No;
newTerm.Term_Seq = term.Term_Seq;
newChannel.Terms.Add(newTerm);
}
newPanelStrip.Channels.Add(newChannel);
}
var httpres2 = await _iOModuleService.SavePanelStrip(newPanelStrip);
UpdateChannelInfos();
}
else if (CableBy.CableClass.Equals("conventional") || CableBy.CableClass.Equals(""))//常规电缆
{
//打开配置连接窗体
2025-09-04 18:28:02 +08:00
IDialogParameters para1 = new Prism.Services.Dialogs.DialogParameters();
2025-08-15 16:34:31 +08:00
para1.Add(GlobalObject.dialogPar.title.ToString(), "端子排连接" + "电缆配置");
para1.Add(GlobalObject.dialogPar.para1.ToString(), CableBy);
para1.Add(GlobalObject.dialogPar.para2.ToString(), panelStrip);
_dialogService = GlobalObject._prismContainer.Resolve<IDialogService>();
_dialogService.ShowDialog(nameof(DialogCableConfig), para1, async (RES1) =>
{
if (RES1.Result == ButtonResult.Yes)
{
var CableSetInfos = RES1.Parameters.GetValue<ObservableCollection<CableSetInfo>>(GlobalObject.dialogPar.para1.ToString());
//SaveCable
ec_Cable newCable = new ec_Cable();
newCable.CableClass = CableBy.CableClass;
newCable.CableID = CableBy.CableID;
newCable.EngineerDataID = CableBy.EngineerDataID;
newCable.UpdateUserID = CableBy.UpdateUserID;
newCable.Sets = new List<ec_CableSet>();
foreach (var CableBySet in CableBy.Sets)
{
ec_CableSet newCableSet = new ec_CableSet();
newCableSet.CableSetID = CableBySet.CableSetID;
newCableSet.CableSetName = CableBySet.CableSetName;
newCableSet.CableSetSeq = CableBySet.CableSetSeq;
newCableSet.Wires = new List<ec_CableSetWire>();
foreach (var wire in CableBySet.Wires)
{
ec_CableSetWire newWire = new ec_CableSetWire();
newWire.Polarity = wire.Polarity;
newWire.SetLevel = 0;
newWire.WireID = wire.WireID;
newWire.Wire_Tag = wire.Wire_Tag;
newCableSet.Wires.Add(newWire);
}
newCable.Sets.Add(newCableSet);
}
//SavePanelStrip
ec_PanelStrip newPanelStrip = new ec_PanelStrip();
newPanelStrip.IO_TYPE = panelStrip.IO_TYPE;
newPanelStrip.PanelID = panelStrip.PanelID;
newPanelStrip.StripID = panelStrip.StripID;
newPanelStrip.StripName = panelStrip.StripName;
newPanelStrip.Channels = new List<ec_PanelChannel>();
foreach (var channel in panelStrip.Channels)
{
ec_PanelChannel newChannel = new ec_PanelChannel();
newChannel.ChannelID = channel.ChannelID;
newChannel.ChannelName = channel.ChannelName;
newChannel.Channel_Seq = channel.Channel_Seq;
newChannel.StripID = channel.StripID;
newChannel.lock_flg = channel.lock_flg;
newChannel.Terms = new List<ec_PanelStripTerm>();
foreach (var term in channel.Terms)
{
ec_PanelStripTerm newTerm = new ec_PanelStripTerm();
newTerm.Connection = new ec_WireTerminal();
if (CableSetInfos.Where(c => c.ChannelNumber != "").Select(c => c.ChannelNumber).Contains(channel.ChannelName))
{
newTerm.Connection.CableSetName = CableSetInfos.Where(c => c.ChannelNumber.Equals(channel.ChannelName)).FirstOrDefault().CableSetName;
}
newTerm.ChannelID = term.ChannelID;
newTerm.StripID = term.StripID;
newTerm.TermID = term.TermID;
newTerm.Term_No = term.Term_No;
newTerm.Term_Seq = term.Term_Seq;
newChannel.Terms.Add(newTerm);
}
newPanelStrip.Channels.Add(newChannel);
}
//SaveConnection
2025-09-04 18:28:02 +08:00
Service.IOModuleService.Connections newConnections = new Service.IOModuleService.Connections();
2025-08-15 16:34:31 +08:00
newConnections.Conns = new List<ec_WireTerminal>();
foreach (var CableSetInfo in CableSetInfos)
{
if (!string.IsNullOrEmpty(CableSetInfo.ChannelNumber) && !CableSetInfo.IsConned)
{
int i = 0;
foreach (var Wire in CableSetInfo.Wire_Tags)
{
ec_WireTerminal newConnection = new ec_WireTerminal();
newConnection.CableName = CableSetInfo.CableName;
newConnection.CableSetName = CableSetInfo.CableSetName;
newConnection.CableSetID = CableSetInfo.CableSetID;
newConnection.Polarity = Wire.Polarity;
newConnection.StripName = panelStrip.StripName;
newConnection.TermID = "";
newConnection.Term_No = "";
newConnection.UpdateUserID = CableSetInfo.UpdateUserID;
newConnection.WireID = Wire.WireID;
newConnection.Wire_Tag = Wire.Wire_Tag;
var terms = panelStrip.Channels.Where(c => c.ChannelName == CableSetInfo.ChannelNumber).FirstOrDefault().Terms;
if (i < terms.Count)
{
newConnection.TermID = terms[i].TermID;
newConnection.Term_No = terms[i].Term_No;
}
newConnections.Conns.Add(newConnection);
i++;
}
//for (int i = 0; i < terms.Count; i++)
//{
// if(i< newConnections.Conns.Count)
// {
// newConnections.Conns[i].TermID = terms[i].TermID;
// newConnections.Conns[i].Term_No = terms[i].Term_No;
// }
//}
}
}
var httpres = await _iOModuleService.SaveCable(newCable);
var httpres2 = await _iOModuleService.SavePanelStrip(newPanelStrip);
var httpres3 = await _iOModuleService.SaveConnections(newConnections);
UpdateChannelInfos();
}
else if (RES1.Result == ButtonResult.No)
{ }
});
}
}
}
else if (RES.Result == ButtonResult.No)
{
}
});
}
return;
}
#endregion
#region
if (parameter.ToString().Equals("选择电缆关联通道"))
{
if (SelectedChannelInfo == null)
{
System.Windows.MessageBox.Show("请先选定通道", "KunHengCAD", MessageBoxButton.OK, MessageBoxImage.Warning); return;
}
_eventAggregator.GetEvent<IORelationEvent>().Publish(true);
var handId = "";
var dwgName = General.GetDwgName();
var dwg = GlobalObject.ListDwgOpened.FirstOrDefault(a => a.Path == dwgName);
Document doc = Application.DocumentManager.MdiActiveDocument;
Database db = doc.Database;
Editor ed = doc.Editor;
//选择的元素返回的属性信息
2025-09-04 18:28:02 +08:00
Model.ec_enginedata resTagNumberListByPixels = new Model.ec_enginedata();
2025-08-15 16:34:31 +08:00
var listPropertys = new List<propertyModel>();
// 持续选择直到获取有效电缆
bool isValidCable = false;
while (!isValidCable)
{
try
{
// 创建选择选项(禁用回车确认)
PromptEntityOptions options = new PromptEntityOptions("\n请单击选择电缆: ");
options.AllowNone = false; // 禁止空选
// 执行选择(直接单击生效)
PromptEntityResult result = ed.GetEntity(options);
//WindowVisibility = System.Windows.Visibility.Hidden;
if (result.Status == PromptStatus.OK)
{
using (Transaction tr = db.TransactionManager.StartTransaction())
{
// 获取选中的电缆实体
Teigha.DatabaseServices.Entity cable = tr.GetObject(result.ObjectId, OpenMode.ForRead) as Teigha.DatabaseServices.Entity;
//if (cable != null&&cable.XData != null)
if (cable != null)
{
// 获取句柄Handle 是字符串类型)
handId = (cable.Handle.ToString());
var res = await _objectTypeService.GetTagNumberListByPixels(dwg.Id, handId);
if (res == null || !res.Any()) return;
if (res.Count == 1)
{
var item = res[0];
var objTypeName = item.ObjectTypeName;
if (objTypeName.Contains("电缆"))
{
resTagNumberListByPixels = item;
// 显示操作界面
//WindowVisibility = System.Windows.Visibility.Visible;
isValidCable = true; // 校验通过
//WindowTopmost = true;
}
}
}
tr.Commit();
}
}
else if (result.Status == PromptStatus.Cancel)
{
break;
}
}
catch (System.Exception ex)
{
ed.WriteMessage($"\n错误: {ex.Message}");
}
finally
{
//确保选择结束之后显示页面
//WindowVisibility = System.Windows.Visibility.Visible;
}
}
if (isValidCable)//选择的是电缆
{
var ObjectTypePListBy = await _objectTypeService.GetObjectTypePListByIds(resTagNumberListByPixels.ObjectTypeID);
string CableSpecification = ObjectTypePListBy.Where(q => q.PropertyName.Equals("电缆规格")).Select(s => s.EnumDataCode).FirstOrDefault();
CableSpecification = CableSpecification.Substring(0, CableSpecification.Length - 1);
CableSpecification.Split(',').ToList();
var b = await _objectTypeService.GetLatestSerialNumber(SelectedChannelInfo.ChannelID);
var httpres4 = await _objectTypeService.GetTagNumberById(SelectedChannelInfo.ChannelID);
//获取位号的电缆属性,判断是否设置电缆规格
var TagNumberBys = await _objectTypeService.GetEngineDataListByTags(resTagNumberListByPixels.TagNumber);
var TagNumberBy = TagNumberBys.Where(t => t.TagNumber.Equals(resTagNumberListByPixels.TagNumber)).FirstOrDefault();
//if (!CableSpecification.Split(',').ToList().Contains(TagNumberBy.EngineDataProperty.Where(e => e.PropertyName.Equals("电缆规格")).Select(e => e.PropertyValue).FirstOrDefault()))
//{
// System.Windows.MessageBox.Show("无法获取电缆对信息,请在电缆\"属性面版“输入电缆”电缆规格”属性\r\n如:“1x2x0.75”", "KunHengCAD", MessageBoxButton.OK, MessageBoxImage.Warning); return;
//}
//获取电缆的配置,没有则创建新配置
var CableBy = await _iOModuleService.GetCableByEngID(resTagNumberListByPixels?.EngineDataID);
if (CableBy == null)
{
MessageBoxResult result = System.Windows.MessageBox.Show($"是否为通讯母线?", "KunHengCAD", MessageBoxButton.OKCancel, MessageBoxImage.Question);
if (result == MessageBoxResult.OK)
{
listPropertys = new List<propertyModel>();
Dictionary<string, string> pulldownlist;
listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "电缆对数", GroupName = "基本参数", PropertyValue = "1", ControlTypeName = PROPERTYType.TextBox, });
listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "每电缆对芯数", GroupName = "基本参数", PropertyValue = "2", ControlTypeName = PROPERTYType.TextBox, });
listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "电缆对编号前缀", GroupName = "基本参数", PropertyValue = "Set", ControlTypeName = PROPERTYType.TextBox, });
pulldownlist = new Dictionary<string, string>();
pulldownlist.Add("数字", "数字");
pulldownlist.Add("字母", "字母");
pulldownlist.Add("电缆对序号", "电缆对序号");
listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "编号类型", GroupName = "电芯参数", PropertyValue = "数字", ControlTypeName = PROPERTYType.ComboBox, Item = pulldownlist, });
pulldownlist = new Dictionary<string, string>();
pulldownlist.Add("按电缆编号", "按电缆编号");
pulldownlist.Add("按电缆对编号", "按电缆对编号");
listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "编号规则", GroupName = "电芯参数", PropertyValue = "按电缆对编号", ControlTypeName = PROPERTYType.ComboBox, Item = pulldownlist, });
listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "电芯编号前缀", GroupName = "电芯参数", PropertyValue = "C", ControlTypeName = PROPERTYType.TextBox, });
listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "极性", GroupName = "电芯参数", PropertyValue = "+,-,s", ControlTypeName = PROPERTYType.TextBox, });
//显示属性弹窗
var ReslistPro = ShowPropertyMessage("新建" + resTagNumberListByPixels.TagNumber + "电缆配置", listPropertys);
if (ReslistPro == null || ReslistPro.Count == 0) return;
ec_Cable ec_Cable = new ec_Cable();
ec_Cable.CableClass = "homerun";//母线
ec_Cable.Cable_Format = TagNumberBy.EngineDataProperty.Where(e => e.PropertyName.Equals("电缆规格")).Select(e => e.PropertyValue).FirstOrDefault();
ec_Cable.EngineerDataID = resTagNumberListByPixels.EngineDataID;
ec_Cable.Sets = new List<ec_CableSet>();
int CableSetCount = int.TryParse(ReslistPro.Where(p => p.DisplayText.Equals("电缆对数")).Select(p => p.PropertyValue).FirstOrDefault(), out CableSetCount) ? CableSetCount : 0;
for (int i = 0; i < CableSetCount; i++)
{
ec_CableSet ec_CableSet = new ec_CableSet();
ec_CableSet.CableSetName = ReslistPro.Where(p => p.DisplayText.Equals("电缆对编号前缀")).Select(p => p.PropertyValue).FirstOrDefault() + (i + 1);
ec_CableSet.CableSetSeq = i + 1;
ec_CableSet.Wires = new List<ec_CableSetWire>();
int WireCount = int.TryParse(ReslistPro.Where(p => p.DisplayText.Equals("每电缆对芯数")).Select(p => p.PropertyValue).FirstOrDefault(), out WireCount) ? WireCount : 0;
for (int j = 0; j < WireCount; j++)
{
ec_CableSetWire ec_CableSetWire = new ec_CableSetWire();
ec_CableSetWire.Polarity = ReslistPro.Where(p => p.DisplayText.Equals("极性")).Select(p => p.PropertyValue).FirstOrDefault().Split(',')[Math.Abs(j % 3)];
ec_CableSetWire.SetLevel = j + 1;
string a = ReslistPro.Where(p => p.DisplayText.Equals("电芯编号前缀")).Select(p => p.PropertyValue).FirstOrDefault();//组成线号名的前缀
string Tag = "";//线号名的中间部分
switch (ReslistPro.Where(p => p.DisplayText.Equals("编号规则")).Select(p => p.PropertyValue).FirstOrDefault())
{
case "按电缆编号":
if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("数字"))
{
Tag = (j + 1).ToString();
}
else if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("字母"))
{
Tag = Tag + (char)('A' + j);
}
else if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("电缆对序号"))
{
Tag = (i + 1).ToString();
}
break;
case "按电缆对编号":
a = resTagNumberListByPixels.TagNumber;
break;
}
ec_CableSetWire.Wire_Tag = a + Tag;
ec_CableSet.Wires.Add(ec_CableSetWire);
}
ec_Cable.Sets.Add(ec_CableSet);
}
var httpres = await _iOModuleService.CreateCableByProfile(ec_Cable);
CableBy = await _iOModuleService.GetCableByEngID(resTagNumberListByPixels.EngineDataID);
}
else
{
listPropertys = new List<propertyModel>();
Dictionary<string, string> pulldownlist;
listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "电缆对数", GroupName = "基本参数", PropertyValue = "10", ControlTypeName = PROPERTYType.TextBox, });
listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "每电缆对芯数", GroupName = "基本参数", PropertyValue = "2", ControlTypeName = PROPERTYType.TextBox, });
listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "电缆对编号前缀", GroupName = "基本参数", PropertyValue = "Set", ControlTypeName = PROPERTYType.TextBox, });
pulldownlist = new Dictionary<string, string>();
pulldownlist.Add("数字", "数字");
pulldownlist.Add("字母", "字母");
pulldownlist.Add("电缆对序号", "电缆对序号");
listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "编号类型", GroupName = "电芯参数", PropertyValue = "数字", ControlTypeName = PROPERTYType.ComboBox, Item = pulldownlist, });
pulldownlist = new Dictionary<string, string>();
pulldownlist.Add("按电缆编号", "按电缆编号");
pulldownlist.Add("按电缆对编号", "按电缆对编号");
listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "编号规则", GroupName = "电芯参数", PropertyValue = "按电缆对编号", ControlTypeName = PROPERTYType.ComboBox, Item = pulldownlist, });
listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "电芯编号前缀", GroupName = "电芯参数", PropertyValue = "C", ControlTypeName = PROPERTYType.TextBox, });
listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "极性", GroupName = "电芯参数", PropertyValue = "+,-,s", ControlTypeName = PROPERTYType.TextBox, });
//显示属性弹窗
var ReslistPro = ShowPropertyMessage("新建" + resTagNumberListByPixels.TagNumber + "电缆配置", listPropertys);
if (ReslistPro == null || ReslistPro.Count == 0) return;
ec_Cable ec_Cable = new ec_Cable();
ec_Cable.CableClass = "conventional";//常规电缆
ec_Cable.EngineerDataID = resTagNumberListByPixels.EngineDataID;
ec_Cable.Sets = new List<ec_CableSet>();
int CableSetCount = int.TryParse(ReslistPro.Where(p => p.DisplayText.Equals("电缆对数")).Select(p => p.PropertyValue).FirstOrDefault(), out CableSetCount) ? CableSetCount : 0;
for (int i = 0; i < CableSetCount; i++)
{
ec_CableSet ec_CableSet = new ec_CableSet();
ec_CableSet.CableSetName = ReslistPro.Where(p => p.DisplayText.Equals("电缆对编号前缀")).Select(p => p.PropertyValue).FirstOrDefault() + (i + 1);
ec_CableSet.CableSetSeq = i + 1;
ec_CableSet.Wires = new List<ec_CableSetWire>();
int WireCount = int.TryParse(ReslistPro.Where(p => p.DisplayText.Equals("每电缆对芯数")).Select(p => p.PropertyValue).FirstOrDefault(), out WireCount) ? WireCount : 0;
for (int j = 0; j < WireCount; j++)
{
ec_CableSetWire ec_CableSetWire = new ec_CableSetWire();
ec_CableSetWire.Polarity = ReslistPro.Where(p => p.DisplayText.Equals("极性")).Select(p => p.PropertyValue).FirstOrDefault().Split(',')[Math.Abs(j % 3)];
ec_CableSetWire.SetLevel = j + 1;
string a = ReslistPro.Where(p => p.DisplayText.Equals("电芯编号前缀")).Select(p => p.PropertyValue).FirstOrDefault();//组成线号名的前缀
string Tag = "";//线号名的中间部分
switch (ReslistPro.Where(p => p.DisplayText.Equals("编号规则")).Select(p => p.PropertyValue).FirstOrDefault())
{
case "按电缆编号":
if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("数字"))
{
Tag = (j + 1).ToString();
}
else if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("字母"))
{
Tag = Tag + (char)('A' + j);
}
else if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("电缆对序号"))
{
Tag = (i + 1).ToString();
}
break;
case "按电缆对编号":
a = resTagNumberListByPixels.TagNumber;
break;
}
ec_CableSetWire.Wire_Tag = a + Tag;
ec_CableSet.Wires.Add(ec_CableSetWire);
}
ec_Cable.Sets.Add(ec_CableSet);
}
var httpres = await _iOModuleService.CreateCableByProfile(ec_Cable);
CableBy = await _iOModuleService.GetCableByEngID(resTagNumberListByPixels.EngineDataID);
}
}
if (CableBy != null)
{
if (CableBy.CableClass.Equals("homerun"))//母线电缆
{
//SavePanelStrip
ec_PanelStrip newPanelStrip = new ec_PanelStrip();
newPanelStrip.IO_TYPE = panelStrip.IO_TYPE;
newPanelStrip.PanelID = panelStrip.PanelID;
newPanelStrip.StripID = panelStrip.StripID;
newPanelStrip.StripName = panelStrip.StripName;
newPanelStrip.Channels = new List<ec_PanelChannel>();
foreach (var channel in panelStrip.Channels)
{
ec_PanelChannel newChannel = new ec_PanelChannel();
newChannel.ChannelID = channel.ChannelID;
newChannel.ChannelName = channel.ChannelName;
newChannel.Channel_Seq = channel.Channel_Seq;
newChannel.StripID = channel.StripID;
newChannel.lock_flg = channel.lock_flg;
if (channel.ChannelName.Equals(SelectedChannelInfo.ChannelNumber))
{
newChannel.HomerunCableId = CableBy.CableID;
newChannel.HomerunCableName = CableBy.TagNumber;
}
newChannel.Terms = new List<ec_PanelStripTerm>();
foreach (var term in channel.Terms)
{
ec_PanelStripTerm newTerm = new ec_PanelStripTerm();
newTerm.Connection = new ec_WireTerminal();
newTerm.ChannelID = term.ChannelID;
newTerm.StripID = term.StripID;
newTerm.TermID = term.TermID;
newTerm.Term_No = term.Term_No;
newTerm.Term_Seq = term.Term_Seq;
newChannel.Terms.Add(newTerm);
}
newPanelStrip.Channels.Add(newChannel);
}
var httpres2 = await _iOModuleService.SavePanelStrip(newPanelStrip);
UpdateChannelInfos();
}
else if (CableBy.CableClass.Equals("conventional") || CableBy.CableClass.Equals(""))//常规电缆
{
//打开配置连接窗体
2025-09-04 18:28:02 +08:00
IDialogParameters para1 = new Prism.Services.Dialogs.DialogParameters();
2025-08-15 16:34:31 +08:00
para1.Add(GlobalObject.dialogPar.title.ToString(), "端子排连接" + "电缆配置");
para1.Add(GlobalObject.dialogPar.para1.ToString(), CableBy);
para1.Add(GlobalObject.dialogPar.para2.ToString(), panelStrip);
var _dialogService = GlobalObject._prismContainer.Resolve<IDialogService>();
// 获取当前活动窗口作为所有者
var ownerWindow = System.Windows.Application.Current.Windows.OfType<Window>().FirstOrDefault(w => w.IsActive);
_dialogService.ShowDialog(nameof(DialogCableConfig), para1, async (RES1) =>
{
if (RES1.Result == ButtonResult.Yes)
{
var CableSetInfos = RES1.Parameters.GetValue<ObservableCollection<CableSetInfo>>(GlobalObject.dialogPar.para1.ToString());
//SaveCable
ec_Cable newCable = new ec_Cable();
newCable.CableClass = CableBy.CableClass;
newCable.CableID = CableBy.CableID;
newCable.EngineerDataID = CableBy.EngineerDataID;
newCable.UpdateUserID = CableBy.UpdateUserID;
newCable.Sets = new List<ec_CableSet>();
foreach (var CableBySet in CableBy.Sets)
{
ec_CableSet newCableSet = new ec_CableSet();
newCableSet.CableSetID = CableBySet.CableSetID;
newCableSet.CableSetName = CableBySet.CableSetName;
newCableSet.CableSetSeq = CableBySet.CableSetSeq;
newCableSet.Wires = new List<ec_CableSetWire>();
foreach (var wire in CableBySet.Wires)
{
ec_CableSetWire newWire = new ec_CableSetWire();
newWire.Polarity = wire.Polarity;
newWire.SetLevel = 0;
newWire.WireID = wire.WireID;
newWire.Wire_Tag = wire.Wire_Tag;
newCableSet.Wires.Add(newWire);
}
newCable.Sets.Add(newCableSet);
}
//SavePanelStrip
ec_PanelStrip newPanelStrip = new ec_PanelStrip();
newPanelStrip.IO_TYPE = panelStrip.IO_TYPE;
newPanelStrip.PanelID = panelStrip.PanelID;
newPanelStrip.StripID = panelStrip.StripID;
newPanelStrip.StripName = panelStrip.StripName;
newPanelStrip.Channels = new List<ec_PanelChannel>();
foreach (var channel in panelStrip.Channels)
{
ec_PanelChannel newChannel = new ec_PanelChannel();
newChannel.ChannelID = channel.ChannelID;
newChannel.ChannelName = channel.ChannelName;
newChannel.Channel_Seq = channel.Channel_Seq;
newChannel.StripID = channel.StripID;
newChannel.lock_flg = channel.lock_flg;
newChannel.Terms = new List<ec_PanelStripTerm>();
foreach (var term in channel.Terms)
{
ec_PanelStripTerm newTerm = new ec_PanelStripTerm();
newTerm.Connection = new ec_WireTerminal();
if (CableSetInfos.Where(c => c.ChannelNumber != "").Select(c => c.ChannelNumber).Contains(channel.ChannelName))
{
newTerm.Connection.CableSetName = CableSetInfos.Where(c => c.ChannelNumber.Equals(channel.ChannelName)).FirstOrDefault().CableSetName;
}
newTerm.ChannelID = term.ChannelID;
newTerm.StripID = term.StripID;
newTerm.TermID = term.TermID;
newTerm.Term_No = term.Term_No;
newTerm.Term_Seq = term.Term_Seq;
newChannel.Terms.Add(newTerm);
}
newPanelStrip.Channels.Add(newChannel);
}
//SaveConnection
2025-09-04 18:28:02 +08:00
Service.IOModuleService.Connections newConnections = new Service.IOModuleService.Connections();
2025-08-15 16:34:31 +08:00
newConnections.Conns = new List<ec_WireTerminal>();
foreach (var CableSetInfo in CableSetInfos)
{
if (!string.IsNullOrEmpty(CableSetInfo.ChannelNumber) && !CableSetInfo.IsConned)
{
int i = 0;
foreach (var Wire in CableSetInfo.Wire_Tags)
{
ec_WireTerminal newConnection = new ec_WireTerminal();
newConnection.CableName = CableSetInfo.CableName;
newConnection.CableSetName = CableSetInfo.CableSetName;
newConnection.CableSetID = CableSetInfo.CableSetID;
newConnection.Polarity = Wire.Polarity;
newConnection.StripName = panelStrip.StripName;
newConnection.TermID = "";
newConnection.Term_No = "";
newConnection.UpdateUserID = CableSetInfo.UpdateUserID;
newConnection.WireID = Wire.WireID;
newConnection.Wire_Tag = Wire.Wire_Tag;
var terms = panelStrip.Channels.Where(c => c.ChannelName == CableSetInfo.ChannelNumber).FirstOrDefault().Terms;
if (i < terms.Count)
{
newConnection.TermID = terms[i].TermID;
newConnection.Term_No = terms[i].Term_No;
}
newConnections.Conns.Add(newConnection);
i++;
}
//for (int i = 0; i < terms.Count; i++)
//{
// if(i< newConnections.Conns.Count)
// {
// newConnections.Conns[i].TermID = terms[i].TermID;
// newConnections.Conns[i].Term_No = terms[i].Term_No;
// }
//}
}
}
var httpres = await _iOModuleService.SaveCable(newCable);
var httpres2 = await _iOModuleService.SavePanelStrip(newPanelStrip);
var httpres3 = await _iOModuleService.SaveConnections(newConnections);
UpdateChannelInfos();
}
else if (RES1.Result == ButtonResult.No)
{ }
});
}
}
}
return;
}
#endregion
#region
if (parameter.ToString().Equals("解除电缆关联通道"))
{
return;
}
#endregion
#region
if (parameter.ToString().Equals("新增端子排通道"))
{
if (SelectedChannelInfo == null)
{
System.Windows.MessageBox.Show("请先选定通道", "KunHengCAD", MessageBoxButton.OK, MessageBoxImage.Warning); return;
}
else
{
List<string> iotypes = new List<string>();
iotypes.Add(SelectedChannelInfo.Io_Type);
List<StripParametersInfo> stripParametersInfos = new List<StripParametersInfo>(await GetStripParametersInfos(iotypes));
var stripParametersInfo = stripParametersInfos.Where(p => p.IoType.Equals(SelectedChannelInfo.Io_Type)).FirstOrDefault();
var listPropertys = new List<propertyModel>();
listPropertys.Add(new propertyModel() { Id = "通道数量", DisplayText = "通道数量", GroupName = "基本参数", PropertyValue = stripParametersInfo.CHNoPerStrip, ControlTypeName = PROPERTYType.TextBox });
listPropertys.Add(new propertyModel() { Id = "每通道端子数", DisplayText = "每通道端子数", GroupName = "基本参数", PropertyValue = stripParametersInfo.TermNoPerCh, ControlTypeName = PROPERTYType.TextBox });
listPropertys.Add(new propertyModel() { Id = "通道前缀", DisplayText = "通道前缀", GroupName = "通道编号", PropertyValue = stripParametersInfo.ChNamePrefix, ControlTypeName = PROPERTYType.TextBox });
listPropertys.Add(new propertyModel() { Id = "通道起始编号", DisplayText = "通道起始编号", GroupName = "通道编号", PropertyValue = stripParametersInfo.ChNameStartIndex, ControlTypeName = PROPERTYType.TextBox });
Dictionary<string, string> listTermNamingType = new Dictionary<string, string>();
listTermNamingType.Add("数字", "数字");
listTermNamingType.Add("字母", "字母");
listPropertys.Add(new propertyModel() { Id = "TermNamingType", DisplayText = "编号类型", GroupName = "端子编号", PropertyValue = stripParametersInfo.TermNamingType, ControlTypeName = PROPERTYType.ComboBox, Item = listTermNamingType });
Dictionary<string, string> listTermNamingRule = new Dictionary<string, string>();
listTermNamingRule.Add("按端子排全局编号", "按端子排全局编号");
listTermNamingRule.Add("按通道内端子编号", "按通道内端子编号");
listTermNamingRule.Add("按通道编号", "按通道编号");
listPropertys.Add(new propertyModel() { Id = "TermNamingRule", DisplayText = "编号规则", GroupName = "端子编号", PropertyValue = stripParametersInfo.TermNamingRule, ControlTypeName = PROPERTYType.ComboBox, Item = listTermNamingRule });
Dictionary<string, string> listTermNamePrefix = new Dictionary<string, string>();
listTermNamePrefix.Add("通道编号", "通道编号");
listTermNamePrefix.Add("+,-,s", "+,-,s");
listTermNamePrefix.Add("无", "无");
listPropertys.Add(new propertyModel() { Id = "TermNamePrefix", DisplayText = "端子前缀", GroupName = "端子编号", PropertyValue = stripParametersInfo.TermNamePrefix, ControlTypeName = PROPERTYType.ComboBox, Item = listTermNamePrefix });
Dictionary<string, string> listTermNameSuffix = new Dictionary<string, string>();
listTermNameSuffix.Add("通道编号", "通道编号");
listTermNameSuffix.Add("+,-,s", "+,-,s");
listTermNameSuffix.Add("无", "无");
listPropertys.Add(new propertyModel() { Id = "TermNameSuffix", DisplayText = "端子后缀", GroupName = "端子编号", PropertyValue = stripParametersInfo.TermNameSuffix, ControlTypeName = PROPERTYType.ComboBox, Item = listTermNameSuffix });
//打开窗体
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.title.ToString(), "新增端子排通道");
para.Add(GlobalObject.dialogPar.para1.ToString(), listPropertys);
var _dialogService = GlobalObject._prismContainer.Resolve<IDialogService>();
_dialogService.ShowDialog(nameof(DialogNewPositional), para, async (RES) =>
{
if (RES.Result == ButtonResult.Yes)
{
var listPro = RES.Parameters.GetValue<ObservableCollection<propertyModel>>(GlobalObject.dialogPar.para1.ToString());
#region
int GlobalTermNumber = 0;//全局端子编号
ec_PanelStrip e = new ec_PanelStrip();
e.IO_TYPE = panelStrip.IO_TYPE;
e.StripName = panelStrip.StripName;
e.PanelID = panelStrip.PanelID;
e.StripID = panelStrip.StripID;
int.TryParse(listPro.Where(p => p.DisplayText.Equals("通道数量")).Select(p => p.PropertyValue).FirstOrDefault(), out int CHNoPerStrip);
#region
//foreach (var Channel in panelStrip.Channels)
//{
// e.Channels.Add(new ec_PanelChannel()
// {
// ChannelID = Channel.ChannelID,
// ChannelName = Channel.ChannelName,
// Channel_Seq = Channel.Channel_Seq,
// StripID = Channel.StripID,
// });
//}
//foreach (var e_Channel in e.Channels)
//{
// e_Channel.Terms = new List<ec_PanelStripTerm>();
// foreach (var panelStrip_Channel in panelStrip.Channels)
// {
// foreach (var Term in panelStrip_Channel.Terms)
// {
// GlobalTermNumber++;
// e_Channel.Terms.Add(new ec_PanelStripTerm()
// {
// TermID = Term.TermID,
// Term_No = Term.Term_No,
// Term_Seq = Term.Term_Seq,
// ChannelID = Term.ChannelID,
// StripID = Term.StripID,
// });
// }
// }
//}
#endregion
for (int i = 0; i < CHNoPerStrip; i++)
{
ec_PanelChannel panelChannel = new ec_PanelChannel();
int channel_No = int.TryParse(listPro.Where(p => p.DisplayText.Equals("通道起始编号")).Select(p => p.PropertyValue).FirstOrDefault(), out int channel_no) ? channel_no : 1;
panelChannel.ChannelName = listPro.Where(p => p.DisplayText.Equals("通道前缀")).Select(p => p.PropertyValue).FirstOrDefault() + (channel_No + i);
panelChannel.Channel_Seq = e.Channels.Count + 1;
panelChannel.Terms = new List<ec_PanelStripTerm>();
int.TryParse(listPro.Where(p => p.DisplayText.Equals("每通道端子数")).Select(p => p.PropertyValue).FirstOrDefault(), out int TermNoPerCh);
for (int j = 0; j < TermNoPerCh; j++)
{
GlobalTermNumber++;
ec_PanelStripTerm panelTerm = new ec_PanelStripTerm();
string a = "";//组成端子名的前缀
string b = "";//端子名的中间部分
string c = "";//组成端子名的后缀
if (listPro.Where(p => p.DisplayText.Equals("端子前缀")).Select(p => p.PropertyValue).FirstOrDefault() != null)
{
if (listPro.Where(p => p.DisplayText.Equals("端子前缀")).Select(p => p.PropertyValue).FirstOrDefault().Equals("通道编号"))
{
a = (channel_No + i).ToString();
}
else if (listPro.Where(p => p.DisplayText.Equals("端子前缀")).Select(p => p.PropertyValue).FirstOrDefault().Equals("+,-,s"))
{
a = listPro.Where(p => p.DisplayText.Equals("端子前缀")).Select(p => p.PropertyValue).FirstOrDefault().Split(',')[Math.Abs(j % 3)];
}
}
if (listPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault() != null)
{
if (listPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("数字"))
{
if (listPro.Where(p => p.DisplayText.Equals("编号规则")).Select(p => p.PropertyValue).FirstOrDefault() != null)
{
if (listPro.Where(p => p.DisplayText.Equals("编号规则")).Select(p => p.PropertyValue).FirstOrDefault().Equals("按端子排全局编号"))
{
b = GlobalTermNumber.ToString();
}
else if (listPro.Where(p => p.DisplayText.Equals("编号规则")).Select(p => p.PropertyValue).FirstOrDefault().Equals("按通道内端子编号"))
{
b = (j + 1).ToString();
}
else if (listPro.Where(p => p.DisplayText.Equals("编号规则")).Select(p => p.PropertyValue).FirstOrDefault().Equals("按通道编号"))
{
b = (channel_No + i).ToString();
}
}
}
else if (listPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("字母"))
{
if (listPro.Where(p => p.DisplayText.Equals("编号规则")).Select(p => p.PropertyValue).FirstOrDefault() != null)
{
if (listPro.Where(p => p.DisplayText.Equals("编号规则")).Select(p => p.PropertyValue).FirstOrDefault().Equals("按端子排全局编号"))
{
b = b + (char)('A' + GlobalTermNumber);
}
else if (listPro.Where(p => p.DisplayText.Equals("编号规则")).Select(p => p.PropertyValue).FirstOrDefault().Equals("按通道内端子编号"))
{
b = b + (char)('A' + j);
}
else if (listPro.Where(p => p.DisplayText.Equals("编号规则")).Select(p => p.PropertyValue).FirstOrDefault().Equals("按通道编号"))
{
b = b + (char)('A' + channel_No + j);
}
}
}
}
if (listPro.Where(p => p.DisplayText.Equals("端子后缀")).Select(p => p.PropertyValue).FirstOrDefault() != null)
{
if (listPro.Where(p => p.DisplayText.Equals("端子后缀")).Select(p => p.PropertyValue).FirstOrDefault().Equals("通道编号"))
{
c = (channel_No + i).ToString();
}
else if (listPro.Where(p => p.DisplayText.Equals("端子后缀")).Select(p => p.PropertyValue).FirstOrDefault().Equals("+,-,s"))
{
c = listPro.Where(p => p.DisplayText.Equals("端子后缀")).Select(p => p.PropertyValue).FirstOrDefault().Split(',')[Math.Abs(j % 3)];
}
}
panelTerm.Term_No = a + b + c;
panelTerm.Term_Seq = j + 1;
panelChannel.Terms.Add(panelTerm);
}
e.Channels.Add(panelChannel);
}
#endregion
var httpres = await _iOModuleService.SavePanelStrip(e);
if (httpres != null)
{
System.Windows.MessageBox.Show(httpres.ToString(), "KunHengCAD", MessageBoxButton.OK, MessageBoxImage.Warning); return;
}
PanelTreels.Clear();
PanelTreels.AddRange(await _iOModuleService.GetPanelTree());
}
else if (RES.Result == ButtonResult.No)
{
}
});
}
return;
}
#endregion
#region
if (parameter.ToString().Equals("删除端子排通道"))
{
if (SelectedChannelInfo == null)
{
System.Windows.MessageBox.Show("请先选定通道", "KunHengCAD", MessageBoxButton.OK, MessageBoxImage.Warning); return;
}
else
{
MessageBoxResult result = System.Windows.MessageBox.Show($"确定删除[{SelectedChannelInfo.ChannelNumber}]通道以及子节点吗", "KunHengCAD", MessageBoxButton.OKCancel, MessageBoxImage.Question);
if (result == MessageBoxResult.OK)
{
var httpres = await _iOModuleService.DeletePanelChannel(SelectedChannelInfo.ChannelID);
if (httpres!=null)
{
System.Windows.MessageBox.Show(httpres, "KunHengCAD", MessageBoxButton.OK, MessageBoxImage.Warning); return;
}
UpdateChannelInfos();
}
}
return;
}
#endregion
#region 使
if (parameter.ToString().Equals("导出端子排(模块)使用明细表"))
{
// 保存文件
2025-09-04 18:28:02 +08:00
System.Windows.Forms.SaveFileDialog saveDialog = new System.Windows.Forms.SaveFileDialog
2025-08-15 16:34:31 +08:00
{
Filter = "Excel文件|*.xlsx",
DefaultExt = ".xlsx",
FileName = "使用情况明细表.xlsx"
};
if (saveDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
string filePath = saveDialog.FileName;
try
{
using (var package = new ExcelPackage())
{
var worksheet = package.Workbook.Worksheets.Add("使用情况明细表");
// 设置表头
worksheet.Cells[1, 1].Value = "位置";
worksheet.Cells[1, 2].Value = "采集箱";
worksheet.Cells[1, 3].Value = "端子排(模块)";
worksheet.Cells[1, 4].Value = "IO类型";
worksheet.Cells[1, 5].Value = "已用通道数";
worksheet.Cells[1, 6].Value = "已用通道数(仅接线,未有信号)";
worksheet.Cells[1, 7].Value = "空余通道数";
worksheet.Cells[1, 8].Value = "总通道数";
// 填充数据
int row = 2;
2025-09-04 18:28:02 +08:00
Model.TreeModel PanelTree = PanelTreels.Where(p => p.Text.Equals("默认")).FirstOrDefault();
2025-08-15 16:34:31 +08:00
2025-09-04 18:28:02 +08:00
foreach (Model.TreeModel node in PanelTree.ChildNodes)
2025-08-15 16:34:31 +08:00
{
// 使用dynamic关键字让编译器在运行时解析类型信息,使用属性名直接访问
dynamic PanelObj = node.NodeExtData;
string Panel_allowedIOTypesValue = PanelObj.allowedIOTypes; //采集箱的所有io类型
foreach (var item in node.ChildNodes)
{
dynamic StripObj = item.NodeExtData;
//var DataItemIDValue = StripObj.IO_TYPE;
string Strip_ChannelsSparedValue = StripObj.ChannelsSpared;//可用通道
string Strip_ChannelsUsedValue = StripObj.ChannelsUsed;//已用通道
string Strip_ChannelsUsedNoSignalValue = StripObj.ChannelsUsedNoSignal;//已用通道(未有信号)
//int Strip_AllChannelValue = (int.TryParse(Strip_ChannelsSparedValue,out int ChannelsSpared)? ChannelsSpared:0) + (int.TryParse(Strip_ChannelsUsedValue,out int ChannelsUsed)? ChannelsUsed : 0) + (int.TryParse(Strip_ChannelsUsedNoSignalValue,out int ChannelsUsedNoSignal)? ChannelsUsedNoSignal : 0);
int Strip_AllChannelValue = int.Parse(Strip_ChannelsSparedValue) + int.Parse(Strip_ChannelsUsedValue) + int.Parse(Strip_ChannelsUsedNoSignalValue);
worksheet.Cells[row, 1].Value = PanelTree.Text;
worksheet.Cells[row, 2].Value = node.Text;
worksheet.Cells[row, 3].Value = item.Text;
worksheet.Cells[row, 4].Value = Panel_allowedIOTypesValue;
worksheet.Cells[row, 5].Value = Strip_ChannelsUsedValue;
worksheet.Cells[row, 6].Value = Strip_ChannelsUsedNoSignalValue;
worksheet.Cells[row, 7].Value = Strip_ChannelsSparedValue;
worksheet.Cells[row, 8].Value = Strip_AllChannelValue;
row++;
}
}
// 自动调整列宽
worksheet.Cells[worksheet.Dimension.Address].AutoFitColumns();
// 保存文件
File.WriteAllBytes(filePath, package.GetAsByteArray());
}
if (System.Windows.MessageBox.Show("导出成功!是否立即打开文件?",
"操作完成",
MessageBoxButton.YesNo) == MessageBoxResult.Yes)
{
System.Diagnostics.Process.Start(saveDialog.FileName);
}
}
catch (Exception ex)
{
System.Windows.MessageBox.Show("导出时发生错误: " + ex.Message);
}
}
return;
}
#endregion
#region
if (parameter.ToString().Equals("端子排模版设置"))
{
List<ec_projectSettings> projectSettings = await _SettingsService.GetList();
ObservableCollection<StripParametersInfo> StripParametersInfos = new ObservableCollection<StripParametersInfo>();
var IOTypes = new List<string>();
foreach (var item in projectSettings)
{
if (item.SettingName.Split('_').Length >= 3)
{
if (!IOTypes.Contains(item.SettingName.Split('_')[2]))
{
IOTypes.Add(item.SettingName.Split('_')[2]);
}
}
}
int index = 0;
foreach (var iotype in IOTypes)
{
index++;
var projectSettingstemp = projectSettings.Where(p => p.SettingName.Contains(iotype.ToString()));
StripParametersInfos.Add(new StripParametersInfo()
{
Index = index,
IoType = iotype,
MaxCount = projectSettingstemp.Where(p => p.SettingName.Contains(iotype)).Select(p => p.SettingValue).FirstOrDefault(),
CHNoPerStrip = projectSettingstemp.Where(p => p.SettingName.Contains(iotype + "_CHNoPerStrip")).Select(p => p.SettingValue).FirstOrDefault(),
TermNoPerCh = projectSettingstemp.Where(p => p.SettingName.Contains(iotype + "_TermNoPerCh")).Select(p => p.SettingValue).FirstOrDefault(),
ChNamePrefix = projectSettingstemp.Where(p => p.SettingName.Contains(iotype + "_ChNamePrefix")).Select(p => p.SettingValue).FirstOrDefault(),
ChNameStartIndex = projectSettingstemp.Where(p => p.SettingName.Contains(iotype + "_ChNameStartIndex")).Select(p => p.SettingValue).FirstOrDefault(),
TermNamingType = projectSettingstemp.Where(p => p.SettingName.Contains(iotype + "_TermNamingType")).Select(p => p.SettingValue).FirstOrDefault(),
TermNamingRule = projectSettingstemp.Where(p => p.SettingName.Contains(iotype + "_TermNamingRule")).Select(p => p.SettingValue).FirstOrDefault(),
TermNamePrefix = projectSettingstemp.Where(p => p.SettingName.Contains(iotype + "_TermNamePrefix")).Select(p => p.SettingValue).FirstOrDefault(),
TermNameSuffix = projectSettingstemp.Where(p => p.SettingName.Contains(iotype + "_TermNameSuffix")).Select(p => p.SettingValue).FirstOrDefault(),
});
}
//打开窗体
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.title.ToString(), "新增位置参数");
para.Add(GlobalObject.dialogPar.para1.ToString(), StripParametersInfos);
para.Add(GlobalObject.dialogPar.para2.ToString(), false);
var _dialogService = GlobalObject._prismContainer.Resolve<IDialogService>();
_dialogService.ShowDialog(nameof(DialogNewStrip), para, async (RES) =>
{
if (RES.Result == ButtonResult.Yes)
{
var infos = RES.Parameters.GetValue<List<StripParametersInfo>>(GlobalObject.dialogPar.para1.ToString());
foreach (var info in infos)
{
if (info.IsModified)
{
foreach (var item in projectSettings.Where(p => p.SettingName.Contains(info.IoType)))
{
if (item.SettingName.Contains(info.IoType)) item.SettingValue = info.MaxCount;
if (item.SettingName.Contains(info.IoType + "_CHNoPerStrip")) item.SettingValue = info.CHNoPerStrip;
if (item.SettingName.Contains(info.IoType + "_TermNoPerCh")) item.SettingValue = info.TermNoPerCh;
if (item.SettingName.Contains(info.IoType + "_ChNamePrefix")) item.SettingValue = info.ChNamePrefix;
if (item.SettingName.Contains(info.IoType + "_ChNameStartIndex")) item.SettingValue = info.ChNameStartIndex;
if (item.SettingName.Contains(info.IoType + "_TermNamingType")) item.SettingValue = info.TermNamingType;
if (item.SettingName.Contains(info.IoType + "_TermNamingRule")) item.SettingValue = info.TermNamingRule;
if (item.SettingName.Contains(info.IoType + "_TermNamePrefix")) item.SettingValue = info.TermNamePrefix;
if (item.SettingName.Contains(info.IoType + "_TermNameSuffix")) item.SettingValue = info.TermNameSuffix;
}
}
}
var httpres = await _SettingsService.SaveEntitys(projectSettings);
}
else if (RES.Result == ButtonResult.No)
{ }
});
return;
}
#endregion
}
#endregion
#region
public ICommand TableButtonCmd => new DelegateCommand(TableButton_Click);
/// <summary>
/// 表格顶部按钮
/// </summary>
/// <param name="parameter"></param>
public virtual async void TableButton_Click(object parameter)
{
#region (L)
if (parameter.ToString().Equals("上移通道(L)"))
{
if (SelectedChannelInfo == null)
{
System.Windows.MessageBox.Show("请先选定通道", "KunHengCAD", MessageBoxButton.OK, MessageBoxImage.Warning); return;
}
else
{
int index = ChannelInfos.IndexOf(SelectedChannelInfo);
if (index != -1 && index != 0)
{
ChannelInfos[index].Channel_Seq = index.ToString();
ChannelInfos[index].IsModified = true;
ChannelInfos[index - 1].Channel_Seq = (index + 1).ToString();
ChannelInfos[index - 1].IsModified = true;
ChannelInfos.Move(index, index - 1);
//更新序号
int order = 0;
foreach (var ChannelInfo in ChannelInfos)
{
ChannelInfo.Index.Clear();
foreach (var Ter in ChannelInfo.Terms)
{
order++;
ChannelInfo.Index.Add(order.ToString());
}
}
}
}
return;
}
#endregion
#region (D)
if (parameter.ToString().Equals("下移通道(D)"))
{
if (SelectedChannelInfo == null)
{
System.Windows.MessageBox.Show("请先选定通道", "KunHengCAD", MessageBoxButton.OK, MessageBoxImage.Warning); return;
}
else
{
int index = ChannelInfos.IndexOf(SelectedChannelInfo);
if (index != -1 && index != ChannelInfos.Count - 1)
{
ChannelInfos[index].Channel_Seq = (index + 2).ToString();
ChannelInfos[index].IsModified = true;
ChannelInfos[index + 1].Channel_Seq = (index + 1).ToString();
ChannelInfos[index + 1].IsModified = true;
ChannelInfos.Move(index, index + 1);
//更新序号
int order = 0;
foreach (var ChannelInfo in ChannelInfos)
{
ChannelInfo.Index.Clear();
foreach (var Ter in ChannelInfo.Terms)
{
order++;
ChannelInfo.Index.Add(order.ToString());
}
}
}
}
return;
}
#endregion
#region (M)
if (parameter.ToString().Equals("迁移通道(M)"))
{
if (SelectedChannelInfo == null)
{
System.Windows.MessageBox.Show("请先选定通道", "KunHengCAD", MessageBoxButton.OK, MessageBoxImage.Warning); return;
}
else
{
if (string.IsNullOrEmpty(SelectedChannelInfo.CablePair))
{
System.Windows.MessageBox.Show("通道未关联", "KunHengCAD", MessageBoxButton.OK, MessageBoxImage.Warning); return;
}
else
{
//打开通道迁移页面
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(), panelStrip);
var _dialogService = GlobalObject._prismContainer.Resolve<IDialogService>();
_dialogService.ShowDialog(nameof(DialogChannelMigration), para, async (RES) =>
{
if (RES.Result == ButtonResult.Yes)
{
//获取返回的通道
var RespanelStrip = RES.Parameters.GetValue<ec_PanelStrip>(GlobalObject.dialogPar.para2.ToString());
var ResChannel = RES.Parameters.GetValue<ec_PanelChannel>(GlobalObject.dialogPar.para1.ToString());
//先保存迁移通道的连接
Connections resConnections = new Connections();
resConnections.Conns = new List<ec_WireTerminal>();
//save panelStrip
foreach (var Channel in RespanelStrip.Channels)
{
if (Channel.ChannelName.Equals(ResChannel.ChannelName))
{
int i = 0;
foreach (var Term in Channel.Terms)
{
Term.Connection = new ec_WireTerminal();
Term.Connection.CableSetID = SelectedChannelInfo.CablePair;
if (i < SelectedChannelInfo.Terms.Count())
{
if (SelectedChannelInfo.Terms[i].Connection != null)
{
ec_WireTerminal resConnection = new ec_WireTerminal();
resConnection.StripName = RespanelStrip.StripName;
resConnection.TermID = Term.TermID;
resConnection.Term_No = Term.Term_No;
resConnection.CableName = SelectedChannelInfo.Terms[i].Connection.CableName;
resConnection.CableSetName = SelectedChannelInfo.Terms[i].Connection.CableSetName;
resConnection.CableSetID = SelectedChannelInfo.Terms[i].Connection.CableSetID;
resConnection.NeedRemove = false;
resConnection.Polarity = SelectedChannelInfo.Terms[i].Connection.Polarity;
resConnection.WireID = SelectedChannelInfo.Terms[i].Connection.WireID;
resConnection.Wire_Tag = SelectedChannelInfo.Terms[i].Connection.Wire_Tag;
resConnections.Conns.Add(resConnection);
}
}
i++;
}
}
}
//save Connections
//保存当前通道的端子连接
Connections newConnections = new Connections();
newConnections.Conns = new List<ec_WireTerminal>();
foreach (var Channel in panelStrip.Channels)
{
if (Channel.ChannelName.Equals(SelectedChannelInfo.ChannelNumber))
{
foreach (var Term in Channel.Terms)
{
if (Term.Connection != null)
{
ec_WireTerminal newConnection = new ec_WireTerminal();
newConnection.CableSetID = Term.Connection.CableSetID;
newConnection.ID = Term.Connection.ID;
newConnection.NeedRemove = true;
newConnection.StripName = Term.Connection.StripName;
newConnection.TermID = Term.Connection.TermID;
newConnection.Term_No = Term.Connection.Term_No;
newConnection.WireID = Term.Connection.WireID;
newConnections.Conns.Add(newConnection);
//清空选中通道的端子连接
Term.Connection = new ec_WireTerminal();
}
}
break;
}
}
IsBusy = true; BusyContent = "保存中...";
var RespanelStripHttpres = await _iOModuleService.SavePanelStrip(RespanelStrip);
var ResConnectionsHttpres = await _iOModuleService.SaveConnections(resConnections);
var httpres = await _iOModuleService.SavePanelStrip(panelStrip);
var httpres3 = await _iOModuleService.SaveConnections(newConnections);
//更新树形结构
UpdateTreeNodes(await _iOModuleService.GetPanelTree());
UpdateChannelInfos();
IsBusy = false;
}
else if (RES.Result == ButtonResult.No)
{ }
});
}
}
return;
}
#endregion
#region (L)
if (parameter.ToString().Equals("锁定通道(L)"))
{
if (SelectedChannelInfo == null)
{
System.Windows.MessageBox.Show("请先选定通道", "KunHengCAD", MessageBoxButton.OK, MessageBoxImage.Warning); return;
}
else
{
SelectedChannelInfo.lock_flg = 1;
SelectedChannelInfo.IsModified = true;
}
return;
}
#endregion
#region (L)
if (parameter.ToString().Equals("解锁通道(L)"))
{
if (SelectedChannelInfo == null)
{
System.Windows.MessageBox.Show("请先选定通道", "KunHengCAD", MessageBoxButton.OK, MessageBoxImage.Warning); return;
}
else
{
SelectedChannelInfo.lock_flg = 0;
SelectedChannelInfo.IsModified = true;
}
return;
}
#endregion
#region
if (parameter.ToString().Equals("关联信号"))
{
//打开信号管理页面
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(), "关联通道");
para.Add(GlobalObject.dialogPar.info.ToString(), SelectedChannelInfo.Signal != null ? SelectedChannelInfo.Signal : null);//表示已有关联信号
var _dialogService = GlobalObject._prismContainer.Resolve<IDialogService>();
_dialogService.ShowDialog(nameof(DialogSignalManagement), para, (RES) =>
{
if (RES.Result == ButtonResult.Yes)
{
//获取返回的信号信息在页面显示
2025-09-04 18:28:02 +08:00
var signalInfos = RES.Parameters.GetValue<List<SWS.Model.ec_Wire_Group>>(GlobalObject.dialogPar.para1.ToString());
2025-08-15 16:34:31 +08:00
SelectedChannelInfo.SignalName = signalInfos.FirstOrDefault()?.Group_Name;
SelectedChannelInfo.GroupOther = signalInfos.FirstOrDefault()?.Signal_Group;
SelectedChannelInfo.SignalCode = signalInfos.FirstOrDefault()?.Signal_SeqNo;
SelectedChannelInfo.ChineseDescription = signalInfos.FirstOrDefault()?.Group_Desc;
SelectedChannelInfo.EnglishDescription = signalInfos.FirstOrDefault()?.Group_Desc_EN;
SelectedChannelInfo.SignalType = signalInfos.FirstOrDefault()?.IO_Type;
SelectedChannelInfo.Signal = signalInfos.FirstOrDefault();
//调用保存信号的接口
SelectedChannelInfo.IsSaveSignal = true;
}
else if (RES.Result == ButtonResult.No)
{ }
});
return;
}
#endregion
#region
if (parameter.ToString().Equals("解除信号"))
{
2025-09-04 18:28:02 +08:00
Model.WireGroups ent = new Model.WireGroups();
2025-08-15 16:34:31 +08:00
if (SelectedChannelInfo.Signal != null)
{
SelectedChannelInfo.Signal.ChannelID = "";
SelectedChannelInfo.Signal.StripName = "";
}
2025-09-04 18:28:02 +08:00
ent.Signals = new List<SWS.Model.ec_Wire_Group>();
2025-08-15 16:34:31 +08:00
ent.Signals.Add(SelectedChannelInfo.Signal);
//解除信号
var data = await _wireGroupService.SaveSignals(ent);
if (data != null)
{
ChannelInfos.Clear();
UpdateChannelInfos();
}
return;
}
#endregion
#region 线
if (parameter.ToString().Equals("母线详情"))
{
if (SelectedChannelInfo == null)
{
System.Windows.MessageBox.Show("请先选定通道", "KunHengCAD", MessageBoxButton.OK, MessageBoxImage.Warning); return;
}
else
{
if (string.IsNullOrEmpty(SelectedChannelInfo.HomerunCableId))
{
System.Windows.MessageBox.Show("请选母线通道", "KunHengCAD", MessageBoxButton.OK, MessageBoxImage.Warning); return;
}
else
{
//母线详情逻辑
//打开配置连接窗体
var cables = await _iOModuleService.GetCables();
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.info.ToString(), SelectedChannelInfo.CableTag);
para.Add(GlobalObject.dialogPar.para1.ToString(), cables);
var _dialogService = GlobalObject._prismContainer.Resolve<IDialogService>();
_dialogService.ShowDialog(nameof(DialogBusbarManagement), para, async (RES) =>
{
if (RES.Result == ButtonResult.Yes)
{
var ResCables = RES.Parameters.GetValue<List<ec_Cable>>(GlobalObject.dialogPar.para1.ToString());
if (ResCables != null && ResCables.Count() > 0)
{
foreach (var ResCable in ResCables)
{
2025-09-04 18:28:02 +08:00
ResCable.WireGroups = new List<SWS.Model.ec_Wire_Group>();
2025-08-15 16:34:31 +08:00
}
var httpres = await _iOModuleService.SaveCables(ResCables);
}
}
else if (RES.Result == ButtonResult.No)
{ }
});
}
}
return;
}
#endregion
#region
if (parameter.ToString().Equals("批量分配"))
{
//获取到所有预分配的电缆并设置到页面渲染对象中
IsBusy = true;
List<ec_Cable> CablePreAssigns = await _iOModuleService.GetCablePreAssignPreview();
var PreAssignCables = new ObservableCollection<PreAssignCable>();
int index = 0;
foreach (var CablePreAssign in CablePreAssigns)
{
index++;
PreAssignCables.Add(new PreAssignCable(CablePreAssign) { Index = index });
}
IsBusy = false;
//打开窗体
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(), PreAssignCables);
var _dialogService = GlobalObject._prismContainer.Resolve<IDialogService>();
_dialogService.ShowDialog(nameof(DialogCablePreAssignPreview), para, async (RES) =>
{
if (RES.Result == ButtonResult.Yes)
{
}
else if (RES.Result == ButtonResult.No)
{ }
});
return;
}
#endregion
#region
if (parameter.ToString().Equals("保存"))
{
SavePanelStrip();
return;
}
#endregion
}
#endregion
/// <summary>
/// 保存方法
/// </summary>
private async void SavePanelStrip()
{
2025-09-04 18:28:02 +08:00
Model.WireGroups ent = new Model.WireGroups();
2025-08-15 16:34:31 +08:00
foreach (var ChannelInfo in ChannelInfos)
{
if (ChannelInfo.IsModified)
{
foreach (var Channel in panelStrip.Channels)
{
if (Channel.ChannelID.Equals(ChannelInfo.ChannelID))
{
Channel.ChannelName = ChannelInfo.ChannelNumber;
if (ChannelInfo.Channel_Seq != null)
{
Channel.Channel_Seq = int.Parse(ChannelInfo.Channel_Seq);
}
Channel.FakeGroupDesc = ChannelInfo.ChineseDescription;
Channel.FakeGroupDescEN = ChannelInfo.EnglishDescription;
Channel.FakeSignalType = ChannelInfo.SignalType;
Channel.lock_flg = ChannelInfo.lock_flg;
}
}
}
if (ChannelInfo.IsSaveSignal)
{
2025-09-04 18:28:02 +08:00
SWS.Model.ec_Wire_Group ec_Wire_Group = new SWS.Model.ec_Wire_Group();
2025-08-15 16:34:31 +08:00
ec_Wire_Group.ChannelID = ChannelInfo.ChannelID;
ec_Wire_Group.ElecOnly = ChannelInfo.Signal.ElecOnly;
ec_Wire_Group.Group_Desc = ChannelInfo.Signal.Group_Desc;
ec_Wire_Group.Group_Desc_EN = ChannelInfo.Signal.Group_Desc_EN;
ec_Wire_Group.Group_Name = ChannelInfo.Signal.Group_Name;
ec_Wire_Group.IO_Type = ChannelInfo.Signal.IO_Type;
ec_Wire_Group.Signal_Group = ChannelInfo.Signal.Signal_Group;
ec_Wire_Group.Signal_SeqNo = ChannelInfo.Signal.Signal_SeqNo;
ec_Wire_Group.Status = ChannelInfo.Signal.Status;
ec_Wire_Group.StripName = ChannelInfo.StripID;
ec_Wire_Group.VDR_Record = ChannelInfo.Signal.VDR_Record;
ec_Wire_Group.Wire_Group_ID = ChannelInfo.Signal.Wire_Group_ID;
2025-09-04 18:28:02 +08:00
ent.Signals = new List<SWS.Model.ec_Wire_Group>();
2025-08-15 16:34:31 +08:00
ent.Signals.Add(ec_Wire_Group);
}
}
if (ent.Signals != null && ent.Signals.Count() > 0)
{
//保存信号
var data = await _wireGroupService.SaveSignals(ent);
}
var httpres = await _iOModuleService.SavePanelStrip(panelStrip);
if (httpres != null)
{
System.Windows.MessageBox.Show(httpres.ToString(), "KunHengCAD", MessageBoxButton.OK, MessageBoxImage.Warning); return;
}
System.Windows.MessageBox.Show("保存成功", "KunHengCAD", MessageBoxButton.OK, MessageBoxImage.Warning);
ChannelInfos.Clear();
UpdateChannelInfos();
}
#endregion
}
public class ChannelInfo : DialogBase
{
#region
private ObservableCollection<string> _Index = new ObservableCollection<string>();
/// <summary>
/// 序号集合
/// </summary>
public ObservableCollection<string> Index
{
get { return _Index; }
set { _Index = value; }
}
private string _ChannelNumber;
/// <summary>
/// 通道号
/// </summary>
public string ChannelNumber
{
get { return _ChannelNumber; }
set { _ChannelNumber = value; }
}
private ObservableCollection<ec_PanelStripTerm> _Terms = new ObservableCollection<ec_PanelStripTerm>();
/// <summary>
/// 端子号集合
/// </summary>
public ObservableCollection<ec_PanelStripTerm> Terms
{
get { return _Terms; }
set { _Terms = value; }
}
private string _Occupant;
/// <summary>
/// 占用人
/// </summary>
public string Occupant
{
get { return _Occupant; }
set { _Occupant = value; }
}
private string _CableTag;
/// <summary>
/// 电缆位号
/// </summary>
public string CableTag
{
get { return _CableTag; }
set { _CableTag = value; }
}
private string _CablePair;
/// <summary>
/// 电缆对
/// </summary>
public string CablePair
{
get { return _CablePair; }
set { _CablePair = value; }
}
private ObservableCollection<ec_WireTerminal> _CableWires = new ObservableCollection<ec_WireTerminal>();
/// <summary>
/// 电缆线号
/// </summary>
public ObservableCollection<ec_WireTerminal> CableWires
{
get { return _CableWires; }
set { _CableWires = value; }
}
private ObservableCollection<ec_WireTerminal> _Polaritys = new ObservableCollection<ec_WireTerminal>();
/// <summary>
/// 极性
/// </summary>
public ObservableCollection<ec_WireTerminal> Polaritys
{
get { return _Polaritys; }
set { _Polaritys = value; }
}
private string _SignalName;
/// <summary>
/// 信号名称
/// </summary>
public string SignalName
{
get { return _SignalName; }
set { _SignalName = value; }
}
private string _GroupOther;
/// <summary>
/// 组别
/// </summary>
public string GroupOther
{
get { return _GroupOther; }
set
{
_GroupOther = value;
RaisePropertyChanged(nameof(GroupOther));
}
}
private string _SignalCode;
/// <summary>
/// 信号编码
/// </summary>
public string SignalCode
{
get { return _SignalCode; }
set
{
_SignalCode = value;
RaisePropertyChanged(nameof(SignalCode));
}
}
private string _ChineseDescription;
/// <summary>
/// 中文描述
/// </summary>
public string ChineseDescription
{
get { return _ChineseDescription; }
set
{
_ChineseDescription = value;
RaisePropertyChanged(nameof(ChineseDescription));
}
}
private string _EnglishDescription;
/// <summary>
/// 英文描述
/// </summary>
public string EnglishDescription
{
get { return _EnglishDescription; }
set
{
_EnglishDescription = value;
RaisePropertyChanged(nameof(EnglishDescription));
}
}
private string _SignalType;
/// <summary>
/// 信号类型
/// </summary>
public string SignalType
{
get { return _SignalType; }
set
{
_SignalType = value;
RaisePropertyChanged(nameof(SignalType));
}
}
2025-09-04 18:28:02 +08:00
private SWS.Model.ec_Wire_Group _Signal;
2025-08-15 16:34:31 +08:00
/// <summary>
/// 通道关联的信号
/// </summary>
2025-09-04 18:28:02 +08:00
public SWS.Model.ec_Wire_Group Signal
2025-08-15 16:34:31 +08:00
{
get { return _Signal; }
set
{
_Signal = value;
RaisePropertyChanged(nameof(Signal));
}
}
#endregion
#region
private string _Io_Type;
/// <summary>
/// 端子排的信号类型
/// </summary>
public string Io_Type
{
get { return _Io_Type; }
set { _Io_Type = value; }
}
private string _ChannelID;
/// <summary>
/// 通道ID
/// </summary>
public string ChannelID
{
get { return _ChannelID; }
set { _ChannelID = value; }
}
private string _Channel_Seq;
/// <summary>
/// 通道排序
/// </summary>
public string Channel_Seq
{
get { return _Channel_Seq; }
set { _Channel_Seq = value; }
}
private bool _IsModified;
/// <summary>
/// 是否修改
/// </summary>
public bool IsModified
{
get { return _IsModified; }
set { _IsModified = value; RaisePropertyChanged(nameof(IsModified)); }
}
private string _StripID;
/// <summary>
/// 端子排ID
/// </summary>
public string StripID
{
get { return _StripID; }
set { _StripID = value; }
}
private string _StripName;
/// <summary>
/// 端子排名称
/// </summary>
public string StripName
{
get { return _StripName; }
set { _StripName = value; }
}
private string _PanelID;
/// <summary>
/// 采集箱ID
/// </summary>
public string PanelID
{
get { return _PanelID; }
set { _PanelID = value; }
}
private int _lock_flg;
/// <summary>
/// 通道是否锁定
/// </summary>
public int lock_flg
{
get { return _lock_flg; }
set { _lock_flg = value; }
}
private string _HomerunCableId;
/// <summary>
/// 如果是母线,则直接体现在通道上
/// </summary>
public string HomerunCableId
{
get { return _HomerunCableId; }
set { _HomerunCableId = value; }
}
private bool _IsSaveSignal = false;
/// <summary>
/// 是否调用保存信号
/// </summary>
public bool IsSaveSignal
{
get { return _IsSaveSignal; }
set { _IsSaveSignal = value; }
}
#endregion
}
}