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; using Prism.Services.Dialogs; using SWS.CAD.CADFunc; using SWS.CAD.Event; using SWS.CAD.ViewModels.myViewModelBase; using SWS.CAD.Views.Dialog; using SWS.Commons; using SWS.Model; using SWS.Service; using SWS.WPF.Views; using Teigha.DatabaseServices; using Telerik.Windows.Controls; using Telerik.Windows.Data; using Unity; using static SWS.Service.IOModuleService; using Application = Bricscad.ApplicationServices.Application; namespace SWS.CAD.ViewModels { public class DialogIODistributionViewModel : DialogBase, IDialogAware { #region 字段 private ObservableCollection _PanelTreels = new ObservableCollection(); /// /// 页面左侧树形结构数据 /// public ObservableCollection PanelTreels { get { return _PanelTreels; } set { _PanelTreels = value; RaisePropertyChanged(nameof(PanelTreels)); } } private Model.TreeModel _SelectedTreeNode; /// /// 当前选中的树形节点 /// public Model.TreeModel SelectedTreeNode { get { return _SelectedTreeNode; } set { _SelectedTreeNode = value; RaisePropertyChanged(nameof(SelectedTreeNode)); UpdateChannelInfos(); } } private ObservableCollection _ChannelInfos = new ObservableCollection(); /// /// 通道详细信息数据 /// public ObservableCollection ChannelInfos { get { return _ChannelInfos; } set { _ChannelInfos = value; RaisePropertyChanged(nameof(ChannelInfos)); } } private ChannelInfo _SelectedChannelInfo; /// /// 当前选中的通道信息 /// public ChannelInfo SelectedChannelInfo { get { return _SelectedChannelInfo; } set { _SelectedChannelInfo = value; RaisePropertyChanged(nameof(SelectedChannelInfo)); UpdateButtonEnabled(); } } private System.Windows.Visibility _WindowVisibility; /// /// 控制页面显示隐藏 /// public System.Windows.Visibility WindowVisibility { get { return _WindowVisibility; } set { _WindowVisibility = value; RaisePropertyChanged(nameof(WindowVisibility)); } } private bool _WindowTopmost; /// /// 控制页面置顶 /// public bool WindowTopmost { get { return _WindowTopmost; } set { _WindowTopmost = value; RaisePropertyChanged(nameof(WindowTopmost)); } } private bool _IsEnabledASButton = false; /// /// 控制关联信号按钮的可用状态 /// public bool IsEnabledASButton { get { return _IsEnabledASButton; } set { _IsEnabledASButton = value; RaisePropertyChanged(nameof(IsEnabledASButton)); } } private bool _IsEnabledClearButton; /// /// 控制解除信号按钮的可用状态 /// public bool IsEnabledClearButton { get { return _IsEnabledClearButton; } set { _IsEnabledClearButton = value; RaisePropertyChanged(nameof(IsEnabledClearButton)); } } #endregion /// /// 接口服务 /// IOModuleService _iOModuleService; DataItemService _dataItemService; SettingsService _SettingsService; ObjectTypeService _objectTypeService; WireGroupService _wireGroupService; IEventAggregator _eventAggregator; DialogIODistribution view; public DialogIODistributionViewModel() { title = "IO分配"; _iOModuleService = GlobalObject.container.Resolve(); _dataItemService = GlobalObject.container.Resolve(); _SettingsService = GlobalObject.container.Resolve(); _objectTypeService = GlobalObject.container.Resolve(); _wireGroupService = GlobalObject.container.Resolve(); _eventAggregator = GlobalObject.container.Resolve(); _eventAggregator.GetEvent().Subscribe(onGetHandsId, ThreadOption.UIThread, true); _eventAggregator.GetEvent().Subscribe(onGetdwgFileId, ThreadOption.UIThread, true); } public string Title => ""; public event Action RequestClose; 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) { IDialogParameters res = new Prism.Services.Dialogs.DialogParameters(); //res.Add(GlobalObject.dialogPar.info.ToString(), $"{TextInfo}"); RequestClose.Invoke(new DialogResult(ButtonResult.Yes, res)); } 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") { DialogResult res = new DialogResult(ButtonResult.No); RequestClose.Invoke(res); } else { RequestClose.Invoke(new DialogResult(ButtonResult.Cancel)); } this.Dispose(); } #region 方法 #region 节点改变时,更新通信消息信息表 private ec_PanelStrip panelStrip; /// /// 选择节点改变时,更新通道信息列表 /// /// 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 更新树形结构 /// /// 更新树形结构的方法 /// /// public void UpdateTreeNodes(List newNodes) { // 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); })); } /// /// 恢复选中节点的核心逻辑 /// /// private void RestoreSelectedNode(string targetNodeId) { if (string.IsNullOrEmpty(targetNodeId)) return; // 递归查找目标节点 Model.TreeModel foundNode = FindNodeByNodeId(PanelTreels, targetNodeId); if (foundNode != null) { SelectedTreeNode = foundNode; } else { // 未找到则默认选中根节点(可选逻辑:选中父节点或第一个节点) SelectedTreeNode = PanelTreels.FirstOrDefault(); } } /// /// 递归查找节点 /// /// /// /// private Model.TreeModel FindNodeByNodeId(IEnumerable nodes, string nodeId) { 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 获取所有信号类型的模版设置 /// /// 获取所有信号类型的模版设置 /// /// 有参数表示要查询的信号类型 /// private async Task> GetStripParametersInfos(List IO_types = null) { List projectSettings = await _SettingsService.GetList(); if (IO_types == null) { IO_types = new List(); 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 StripParametersInfos = new ObservableCollection(); 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 显示属性弹窗 /// /// 显示属性弹窗 /// private ObservableCollection ShowPropertyMessage(string title, List listPropertys) { ObservableCollection ReslistPro = new ObservableCollection(); //打开窗体 IDialogParameters para = new Prism.Services.Dialogs.DialogParameters(); para.Add(GlobalObject.dialogPar.title.ToString(), title); para.Add(GlobalObject.dialogPar.para1.ToString(), listPropertys); var _dialogService = GlobalObject._prismContainer.Resolve(); _dialogService.ShowDialog(nameof(DialogNewPositional), para, (RES) => { if (RES.Result == ButtonResult.Yes) { ReslistPro = RES.Parameters.GetValue>(GlobalObject.dialogPar.para1.ToString()); } else if (RES.Result == ButtonResult.No) { } }); return ReslistPro; } #endregion #region 表格编辑事件 public ICommand EditEndCmd => new DelegateCommand(EditEnd); /// /// 编辑结束事件 /// /// public virtual void EditEnd(object parameter) { //做个标记表示该项修改过 SelectedChannelInfo.IsModified = true; } #endregion #region 树形结构右键点击事件 public ICommand MouseRightCmd => new DelegateCommand(MouseRight_Click); /// /// 右键点击事件 /// /// public virtual async void MouseRight_Click(object parameter) { if (parameter.GetType() == typeof(Model.TreeModel)) { var treeNode = parameter as Model.TreeModel; 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(); //通过当前采集箱的信号类型给属性修改页面赋值 List projectSettings = await _SettingsService.GetList(); var IOTypes = new List(); 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 listPanelTrees = new Dictionary(); 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 }); //打开窗体 IDialogParameters para = new Prism.Services.Dialogs.DialogParameters(); para.Add(GlobalObject.dialogPar.title.ToString(), "采集箱属性"); para.Add(GlobalObject.dialogPar.para1.ToString(), listPropertys); var _dialogService = GlobalObject._prismContainer.Resolve(); _dialogService.ShowDialog(nameof(DialogNewPositional), para, async (RES) => { if (RES.Result == ButtonResult.Yes) { var listPro = RES.Parameters.GetValue>(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 _handles; /// /// 获取选中图元id /// /// private void onGetHandsId(List HandsId) { _handles = HandsId; } private string _dwgFileId; /// /// 获取选中句柄id /// /// private void onGetdwgFileId(string dwgFileId) { _dwgFileId = dwgFileId; } #region 页面左侧按钮 public ICommand HeadButtonCmd => new DelegateCommand(HeadButton_Click); /// /// 页面左侧按钮 /// /// 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(); 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 }); //打开窗体 IDialogParameters para = new Prism.Services.Dialogs.DialogParameters(); para.Add(GlobalObject.dialogPar.title.ToString(), "新增位置参数"); para.Add(GlobalObject.dialogPar.para1.ToString(), listPropertys); var _dialogService = GlobalObject._prismContainer.Resolve(); _dialogService.ShowDialog(nameof(DialogNewPositional), para, async (RES) => { if (RES.Result == ButtonResult.Yes) { var listPro = RES.Parameters.GetValue>(GlobalObject.dialogPar.para1.ToString()); Model.ec_dataitemdetail ent = new Model.ec_dataitemdetail() { 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 projectSettings = await _SettingsService.GetList(); ObservableCollection StripParametersInfos = new ObservableCollection(); 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(), }); } //打开窗体 IDialogParameters para = new Prism.Services.Dialogs.DialogParameters(); 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(); _dialogService.ShowDialog(nameof(DialogNewStrip), para, (RES) => { if (RES.Result == ButtonResult.Yes) { var stripParametersInfo = RES.Parameters.GetValue(GlobalObject.dialogPar.para1.ToString()); var listPropertys = new List(); 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 listTermNamingType = new Dictionary(); listTermNamingType.Add("数字", "数字"); listTermNamingType.Add("字母", "字母"); listPropertys.Add(new propertyModel() { Id = "TermNamingType", DisplayText = "编号类型", GroupName = "端子编号", PropertyValue = stripParametersInfo.TermNamingType, ControlTypeName = PROPERTYType.ComboBox, Item = listTermNamingType }); Dictionary listTermNamingRule = new Dictionary(); listTermNamingRule.Add("按端子排全局编号", "按端子排全局编号"); listTermNamingRule.Add("按通道内端子编号", "按通道内端子编号"); listTermNamingRule.Add("按通道编号", "按通道编号"); listPropertys.Add(new propertyModel() { Id = "TermNamingRule", DisplayText = "编号规则", GroupName = "端子编号", PropertyValue = stripParametersInfo.TermNamingRule, ControlTypeName = PROPERTYType.ComboBox, Item = listTermNamingRule }); Dictionary listTermNamePrefix = new Dictionary(); 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 listTermNameSuffix = new Dictionary(); listTermNameSuffix.Add("通道编号", "通道编号"); listTermNameSuffix.Add("+,-,s", "+,-,s"); listTermNameSuffix.Add("无", "无"); listPropertys.Add(new propertyModel() { Id = "TermNameSuffix", DisplayText = "端子后缀", GroupName = "端子编号", PropertyValue = stripParametersInfo.TermNameSuffix, ControlTypeName = PROPERTYType.ComboBox, Item = listTermNameSuffix }); //打开窗体 para = new Prism.Services.Dialogs.DialogParameters(); para.Add(GlobalObject.dialogPar.title.ToString(), "新建端子排"); para.Add(GlobalObject.dialogPar.para1.ToString(), listPropertys); _dialogService = GlobalObject._prismContainer.Resolve(); _dialogService.ShowDialog(nameof(DialogNewPositional), para, async (RES1) => { if (RES1.Result == ButtonResult.Yes) { var listPro = RES1.Parameters.GetValue>(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(); 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(); 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 }); //打开窗体 IDialogParameters para = new Prism.Services.Dialogs.DialogParameters(); para.Add(GlobalObject.dialogPar.title.ToString(), "编辑位置参数"); para.Add(GlobalObject.dialogPar.para1.ToString(), listPropertys); var _dialogService = GlobalObject._prismContainer.Resolve(); _dialogService.ShowDialog(nameof(DialogNewPositional), para, async (RES) => { if (RES.Result == ButtonResult.Yes) { var listPro = RES.Parameters.GetValue>(GlobalObject.dialogPar.para1.ToString()); Model.ec_dataitemdetail ent = new Model.ec_dataitemdetail() { 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(); 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 }); //打开窗体 IDialogParameters para = new Prism.Services.Dialogs.DialogParameters(); para.Add(GlobalObject.dialogPar.title.ToString(), "编辑端子排"); para.Add(GlobalObject.dialogPar.para1.ToString(), listPropertys); var _dialogService = GlobalObject._prismContainer.Resolve(); _dialogService.ShowDialog(nameof(DialogNewPositional), para, async (RES) => { if (RES.Result == ButtonResult.Yes) { var listPro = RES.Parameters.GetValue>(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(); List AllTagNumbers = await _objectTypeService.GetListBySQL("ObjectTypeName like '%电缆%'"); if (AllTagNumbers == null) return; Dictionary listTagNumbers = new Dictionary(); 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; //打开窗体 IDialogParameters para = new Prism.Services.Dialogs.DialogParameters(); para.Add(GlobalObject.dialogPar.title.ToString(), "电缆位号选择"); para.Add(GlobalObject.dialogPar.para1.ToString(), listPropertys); var _dialogService = GlobalObject._prismContainer.Resolve(); _dialogService.ShowDialog(nameof(DialogNewPositional), para, async (RES) => { if (RES.Result == ButtonResult.Yes) { var listPro = RES.Parameters.GetValue>(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(); Dictionary 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(); pulldownlist.Add("数字", "数字"); pulldownlist.Add("字母", "字母"); pulldownlist.Add("电缆对序号", "电缆对序号"); listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "编号类型", GroupName = "电芯参数", PropertyValue = "数字", ControlTypeName = PROPERTYType.ComboBox, Item = pulldownlist, }); pulldownlist = new Dictionary(); 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(); 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(); 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(); Dictionary 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(); pulldownlist.Add("数字", "数字"); pulldownlist.Add("字母", "字母"); pulldownlist.Add("电缆对序号", "电缆对序号"); listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "编号类型", GroupName = "电芯参数", PropertyValue = "数字", ControlTypeName = PROPERTYType.ComboBox, Item = pulldownlist, }); pulldownlist = new Dictionary(); 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(); 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(); 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(); 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(); 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(""))//常规电缆 { //打开配置连接窗体 IDialogParameters para1 = new Prism.Services.Dialogs.DialogParameters(); para1.Add(GlobalObject.dialogPar.title.ToString(), "端子排连接" + "电缆配置"); para1.Add(GlobalObject.dialogPar.para1.ToString(), CableBy); para1.Add(GlobalObject.dialogPar.para2.ToString(), panelStrip); _dialogService = GlobalObject._prismContainer.Resolve(); _dialogService.ShowDialog(nameof(DialogCableConfig), para1, async (RES1) => { if (RES1.Result == ButtonResult.Yes) { var CableSetInfos = RES1.Parameters.GetValue>(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(); 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(); 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(); 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(); 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 Service.IOModuleService.Connections newConnections = new Service.IOModuleService.Connections(); newConnections.Conns = new List(); 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().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; //选择的元素返回的属性信息 Model.ec_enginedata resTagNumberListByPixels = new Model.ec_enginedata(); var listPropertys = new List(); // 持续选择直到获取有效电缆 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(); Dictionary 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(); pulldownlist.Add("数字", "数字"); pulldownlist.Add("字母", "字母"); pulldownlist.Add("电缆对序号", "电缆对序号"); listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "编号类型", GroupName = "电芯参数", PropertyValue = "数字", ControlTypeName = PROPERTYType.ComboBox, Item = pulldownlist, }); pulldownlist = new Dictionary(); 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(); 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(); 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(); Dictionary 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(); pulldownlist.Add("数字", "数字"); pulldownlist.Add("字母", "字母"); pulldownlist.Add("电缆对序号", "电缆对序号"); listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "编号类型", GroupName = "电芯参数", PropertyValue = "数字", ControlTypeName = PROPERTYType.ComboBox, Item = pulldownlist, }); pulldownlist = new Dictionary(); 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(); 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(); 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(); 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(); 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(""))//常规电缆 { //打开配置连接窗体 IDialogParameters para1 = new Prism.Services.Dialogs.DialogParameters(); 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(); // 获取当前活动窗口作为所有者 var ownerWindow = System.Windows.Application.Current.Windows.OfType().FirstOrDefault(w => w.IsActive); _dialogService.ShowDialog(nameof(DialogCableConfig), para1, async (RES1) => { if (RES1.Result == ButtonResult.Yes) { var CableSetInfos = RES1.Parameters.GetValue>(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(); 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(); 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(); 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(); 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 Service.IOModuleService.Connections newConnections = new Service.IOModuleService.Connections(); newConnections.Conns = new List(); 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 iotypes = new List(); iotypes.Add(SelectedChannelInfo.Io_Type); List stripParametersInfos = new List(await GetStripParametersInfos(iotypes)); var stripParametersInfo = stripParametersInfos.Where(p => p.IoType.Equals(SelectedChannelInfo.Io_Type)).FirstOrDefault(); var listPropertys = new List(); 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 listTermNamingType = new Dictionary(); listTermNamingType.Add("数字", "数字"); listTermNamingType.Add("字母", "字母"); listPropertys.Add(new propertyModel() { Id = "TermNamingType", DisplayText = "编号类型", GroupName = "端子编号", PropertyValue = stripParametersInfo.TermNamingType, ControlTypeName = PROPERTYType.ComboBox, Item = listTermNamingType }); Dictionary listTermNamingRule = new Dictionary(); listTermNamingRule.Add("按端子排全局编号", "按端子排全局编号"); listTermNamingRule.Add("按通道内端子编号", "按通道内端子编号"); listTermNamingRule.Add("按通道编号", "按通道编号"); listPropertys.Add(new propertyModel() { Id = "TermNamingRule", DisplayText = "编号规则", GroupName = "端子编号", PropertyValue = stripParametersInfo.TermNamingRule, ControlTypeName = PROPERTYType.ComboBox, Item = listTermNamingRule }); Dictionary listTermNamePrefix = new Dictionary(); 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 listTermNameSuffix = new Dictionary(); listTermNameSuffix.Add("通道编号", "通道编号"); listTermNameSuffix.Add("+,-,s", "+,-,s"); listTermNameSuffix.Add("无", "无"); listPropertys.Add(new propertyModel() { Id = "TermNameSuffix", DisplayText = "端子后缀", GroupName = "端子编号", PropertyValue = stripParametersInfo.TermNameSuffix, ControlTypeName = PROPERTYType.ComboBox, Item = listTermNameSuffix }); //打开窗体 IDialogParameters para = new Prism.Services.Dialogs.DialogParameters(); para.Add(GlobalObject.dialogPar.title.ToString(), "新增端子排通道"); para.Add(GlobalObject.dialogPar.para1.ToString(), listPropertys); var _dialogService = GlobalObject._prismContainer.Resolve(); _dialogService.ShowDialog(nameof(DialogNewPositional), para, async (RES) => { if (RES.Result == ButtonResult.Yes) { var listPro = RES.Parameters.GetValue>(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(); // 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(); 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("导出端子排(模块)使用明细表")) { // 保存文件 System.Windows.Forms.SaveFileDialog saveDialog = new System.Windows.Forms.SaveFileDialog { 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; Model.TreeModel PanelTree = PanelTreels.Where(p => p.Text.Equals("默认")).FirstOrDefault(); foreach (Model.TreeModel node in PanelTree.ChildNodes) { // 使用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 projectSettings = await _SettingsService.GetList(); ObservableCollection StripParametersInfos = new ObservableCollection(); var IOTypes = new List(); 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(), }); } //打开窗体 IDialogParameters para = new Prism.Services.Dialogs.DialogParameters(); 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(); _dialogService.ShowDialog(nameof(DialogNewStrip), para, async (RES) => { if (RES.Result == ButtonResult.Yes) { var infos = RES.Parameters.GetValue>(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); /// /// 表格顶部按钮 /// /// 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 { //打开通道迁移页面 IDialogParameters para = new Prism.Services.Dialogs.DialogParameters(); para.Add(GlobalObject.dialogPar.para1.ToString(), panelStrip); var _dialogService = GlobalObject._prismContainer.Resolve(); _dialogService.ShowDialog(nameof(DialogChannelMigration), para, async (RES) => { if (RES.Result == ButtonResult.Yes) { //获取返回的通道 var RespanelStrip = RES.Parameters.GetValue(GlobalObject.dialogPar.para2.ToString()); var ResChannel = RES.Parameters.GetValue(GlobalObject.dialogPar.para1.ToString()); //先保存迁移通道的连接 Connections resConnections = new Connections(); resConnections.Conns = new List(); //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(); 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("关联信号")) { //打开信号管理页面 IDialogParameters para = new Prism.Services.Dialogs.DialogParameters(); para.Add(GlobalObject.dialogPar.para1.ToString(), "关联通道"); para.Add(GlobalObject.dialogPar.info.ToString(), SelectedChannelInfo.Signal != null ? SelectedChannelInfo.Signal : null);//表示已有关联信号 var _dialogService = GlobalObject._prismContainer.Resolve(); _dialogService.ShowDialog(nameof(DialogSignalManagement), para, (RES) => { if (RES.Result == ButtonResult.Yes) { //获取返回的信号信息在页面显示 var signalInfos = RES.Parameters.GetValue>(GlobalObject.dialogPar.para1.ToString()); 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("解除信号")) { Model.WireGroups ent = new Model.WireGroups(); if (SelectedChannelInfo.Signal != null) { SelectedChannelInfo.Signal.ChannelID = ""; SelectedChannelInfo.Signal.StripName = ""; } ent.Signals = new List(); 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(); IDialogParameters para = new Prism.Services.Dialogs.DialogParameters(); para.Add(GlobalObject.dialogPar.info.ToString(), SelectedChannelInfo.CableTag); para.Add(GlobalObject.dialogPar.para1.ToString(), cables); var _dialogService = GlobalObject._prismContainer.Resolve(); _dialogService.ShowDialog(nameof(DialogBusbarManagement), para, async (RES) => { if (RES.Result == ButtonResult.Yes) { var ResCables = RES.Parameters.GetValue>(GlobalObject.dialogPar.para1.ToString()); if (ResCables != null && ResCables.Count() > 0) { foreach (var ResCable in ResCables) { ResCable.WireGroups = new List(); } var httpres = await _iOModuleService.SaveCables(ResCables); } } else if (RES.Result == ButtonResult.No) { } }); } } return; } #endregion #region 批量分配 if (parameter.ToString().Equals("批量分配")) { //获取到所有预分配的电缆并设置到页面渲染对象中 IsBusy = true; List CablePreAssigns = await _iOModuleService.GetCablePreAssignPreview(); var PreAssignCables = new ObservableCollection(); int index = 0; foreach (var CablePreAssign in CablePreAssigns) { index++; PreAssignCables.Add(new PreAssignCable(CablePreAssign) { Index = index }); } IsBusy = false; //打开窗体 IDialogParameters para = new Prism.Services.Dialogs.DialogParameters(); para.Add(GlobalObject.dialogPar.para1.ToString(), PreAssignCables); var _dialogService = GlobalObject._prismContainer.Resolve(); _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 /// /// 保存方法 /// private async void SavePanelStrip() { Model.WireGroups ent = new Model.WireGroups(); 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) { SWS.Model.ec_Wire_Group ec_Wire_Group = new SWS.Model.ec_Wire_Group(); 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; ent.Signals = new List(); 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 _Index = new ObservableCollection(); /// /// 序号集合 /// public ObservableCollection Index { get { return _Index; } set { _Index = value; } } private string _ChannelNumber; /// /// 通道号 /// public string ChannelNumber { get { return _ChannelNumber; } set { _ChannelNumber = value; } } private ObservableCollection _Terms = new ObservableCollection(); /// /// 端子号集合 /// public ObservableCollection Terms { get { return _Terms; } set { _Terms = value; } } private string _Occupant; /// /// 占用人 /// public string Occupant { get { return _Occupant; } set { _Occupant = value; } } private string _CableTag; /// /// 电缆位号 /// public string CableTag { get { return _CableTag; } set { _CableTag = value; } } private string _CablePair; /// /// 电缆对 /// public string CablePair { get { return _CablePair; } set { _CablePair = value; } } private ObservableCollection _CableWires = new ObservableCollection(); /// /// 电缆线号 /// public ObservableCollection CableWires { get { return _CableWires; } set { _CableWires = value; } } private ObservableCollection _Polaritys = new ObservableCollection(); /// /// 极性 /// public ObservableCollection Polaritys { get { return _Polaritys; } set { _Polaritys = value; } } private string _SignalName; /// /// 信号名称 /// public string SignalName { get { return _SignalName; } set { _SignalName = value; } } private string _GroupOther; /// /// 组别 /// public string GroupOther { get { return _GroupOther; } set { _GroupOther = value; RaisePropertyChanged(nameof(GroupOther)); } } private string _SignalCode; /// /// 信号编码 /// public string SignalCode { get { return _SignalCode; } set { _SignalCode = value; RaisePropertyChanged(nameof(SignalCode)); } } private string _ChineseDescription; /// /// 中文描述 /// public string ChineseDescription { get { return _ChineseDescription; } set { _ChineseDescription = value; RaisePropertyChanged(nameof(ChineseDescription)); } } private string _EnglishDescription; /// /// 英文描述 /// public string EnglishDescription { get { return _EnglishDescription; } set { _EnglishDescription = value; RaisePropertyChanged(nameof(EnglishDescription)); } } private string _SignalType; /// /// 信号类型 /// public string SignalType { get { return _SignalType; } set { _SignalType = value; RaisePropertyChanged(nameof(SignalType)); } } private SWS.Model.ec_Wire_Group _Signal; /// /// 通道关联的信号 /// public SWS.Model.ec_Wire_Group Signal { get { return _Signal; } set { _Signal = value; RaisePropertyChanged(nameof(Signal)); } } #endregion #region 扩展字段 private string _Io_Type; /// /// 端子排的信号类型 /// public string Io_Type { get { return _Io_Type; } set { _Io_Type = value; } } private string _ChannelID; /// /// 通道ID /// public string ChannelID { get { return _ChannelID; } set { _ChannelID = value; } } private string _Channel_Seq; /// /// 通道排序 /// public string Channel_Seq { get { return _Channel_Seq; } set { _Channel_Seq = value; } } private bool _IsModified; /// /// 是否修改 /// public bool IsModified { get { return _IsModified; } set { _IsModified = value; RaisePropertyChanged(nameof(IsModified)); } } private string _StripID; /// /// 端子排ID /// public string StripID { get { return _StripID; } set { _StripID = value; } } private string _StripName; /// /// 端子排名称 /// public string StripName { get { return _StripName; } set { _StripName = value; } } private string _PanelID; /// /// 采集箱ID /// public string PanelID { get { return _PanelID; } set { _PanelID = value; } } private int _lock_flg; /// /// 通道是否锁定 /// public int lock_flg { get { return _lock_flg; } set { _lock_flg = value; } } private string _HomerunCableId; /// /// 如果是母线,则直接体现在通道上 /// public string HomerunCableId { get { return _HomerunCableId; } set { _HomerunCableId = value; } } private bool _IsSaveSignal = false; /// /// 是否调用保存信号 /// public bool IsSaveSignal { get { return _IsSaveSignal; } set { _IsSaveSignal = value; } } #endregion } }