1255 lines
56 KiB
C#
Raw Normal View History

2025-08-15 16:34:31 +08:00
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Windows;
using System.Windows.Input;
using System.Windows.Interop;
using Prism.Ioc;
2025-09-04 18:28:02 +08:00
using Prism.Services.Dialogs;
2025-08-15 16:34:31 +08:00
using SWS.CAD.ViewModels.myViewModelBase;
using SWS.CAD.Views.CustomControl;
using SWS.CAD.Views.Dialog;
2025-09-04 18:28:02 +08:00
using SWS.Commons;
using SWS.Model;
using SWS.Service;
2025-08-15 16:34:31 +08:00
using Telerik.Windows.Controls;
using Unity;
namespace SWS.CAD.ViewModels
{
/// <summary>
/// 电缆连接UserControl的ViewModel
/// </summary>
public class DialogCableConnectionViewModel : DialogBase, IDialogAware
{
#region
2025-09-04 18:28:02 +08:00
private ObservableCollection<Model.ec_enginedata_pixel> _AllTagPixels = new ObservableCollection<Model.ec_enginedata_pixel>();
2025-08-15 16:34:31 +08:00
/// <summary>
/// 图纸所有的电缆
/// </summary>
2025-09-04 18:28:02 +08:00
public ObservableCollection<Model.ec_enginedata_pixel> AllTagPixels
2025-08-15 16:34:31 +08:00
{
get { return _AllTagPixels; }
set
{
_AllTagPixels = value;
RaisePropertyChanged(nameof(AllTagPixels));
}
}
2025-09-04 18:28:02 +08:00
private Model.ec_enginedata_pixel _SelectedTagPixels;
2025-08-15 16:34:31 +08:00
/// <summary>
/// 选择的电缆位号
/// </summary>
2025-09-04 18:28:02 +08:00
public Model.ec_enginedata_pixel SelectedTagPixels
2025-08-15 16:34:31 +08:00
{
get { return _SelectedTagPixels; }
set
{
_SelectedTagPixels = value;
RaisePropertyChanged(nameof(SelectedTagPixels));
UpdaTagPixels(_SelectedTagPixels);
}
}
private ObservableCollection<CableConnectionInfo> _CableConnectionInfos = new ObservableCollection<CableConnectionInfo>();
/// <summary>
/// 表格数据源
/// </summary>
public ObservableCollection<CableConnectionInfo> CableConnectionInfos
{
get { return _CableConnectionInfos; }
set
{
_CableConnectionInfos = value;
RaisePropertyChanged(nameof(CableConnectionInfos));
}
}
private CableConnectionInfo _SelectCableConnectionInfo;
/// <summary>
/// 当前选中行
/// </summary>
public CableConnectionInfo SelectCableConnectionInfo
{
get { return _SelectCableConnectionInfo; }
set
{
_SelectCableConnectionInfo = value;
RaisePropertyChanged(nameof(SelectCableConnectionInfo));
}
}
#endregion
//接口服务
private EnginedataService _enginedataService;
IOModuleService _iOModuleService;
ObjectTypeService _objectTypeService;
public DialogCableConnectionViewModel()
{
_enginedataService = GlobalObject.container.Resolve<EnginedataService>();
_iOModuleService = GlobalObject.container.Resolve<IOModuleService>();
_objectTypeService = GlobalObject.container.Resolve<ObjectTypeService>();
}
2025-09-04 18:28:02 +08:00
public string Title => "";
public event Action<IDialogResult> RequestClose;
2025-08-15 16:34:31 +08:00
public bool CanCloseDialog()
{
return true;
}
public void OnDialogClosed()
{
}
public async void OnDialogOpened(IDialogParameters parameters)
{
// 获取对话框窗口实例
var dialogWindow = GlobalObject.container.Resolve<CustomDialogWindow>();
if (dialogWindow != null)
{
// 使用 WindowInteropHelper 设置 Owner
var helper = new WindowInteropHelper(dialogWindow);
helper.Owner = parameters.GetValue<IntPtr>(GlobalObject.dialogPar.info.ToString());
// 确保窗口在 CAD 应用中置顶
dialogWindow.Topmost = false;
}
title = "电缆连接";
//获取图纸所有的电缆对象
string DrawingID = parameters.GetValue<string>(GlobalObject.dialogPar.para1.ToString());
var AllPixel = await _enginedataService.GetTagPixelsByDrawing(DrawingID);
AllTagPixels.AddRange(AllPixel.Where(p => p.ObjectTypeName.EndsWith("电缆")));
string TagNumber = parameters.GetValue<string>(GlobalObject.dialogPar.para2.ToString());
SelectedTagPixels = AllTagPixels.FirstOrDefault(p => p.TagNumber.Equals(TagNumber));
}
public override void ExecuteOKCommandAsync(object para)
{
2025-09-04 18:28:02 +08:00
IDialogParameters res = new Prism.Services.Dialogs.DialogParameters();
2025-08-15 16:34:31 +08:00
//res.Add(GlobalObject.dialogPar.info.ToString(), $"{TextInfo}");
2025-09-04 18:28:02 +08:00
RequestClose.Invoke(new DialogResult(ButtonResult.Yes, res));
2025-08-15 16:34:31 +08:00
}
public override void ExecuteCloseCommand(object parameter)
{
//if (smInfos.Any(s => s.IsModified == true))
//{
// MessageBoxResult resultMessage = MessageBox.Show("修改未保存,是否取消修改", "KunHengCAD", MessageBoxButton.OKCancel, MessageBoxImage.Question);
// if (resultMessage != MessageBoxResult.OK)
// {
// return;
// }
//}
if (parameter as string == "ClickNo")
{
2025-09-04 18:28:02 +08:00
DialogResult res = new DialogResult(ButtonResult.No);
RequestClose.Invoke(res);
2025-08-15 16:34:31 +08:00
}
else
{
2025-09-04 18:28:02 +08:00
RequestClose.Invoke(new DialogResult(ButtonResult.Cancel));
2025-08-15 16:34:31 +08:00
}
this.Dispose();
}
#region
#region
/// <summary>
/// 显示属性弹窗
/// </summary>
private ObservableCollection<propertyModel> ShowPropertyMessage(string title, List<propertyModel> listPropertys)
{
ObservableCollection<propertyModel> ReslistPro = new ObservableCollection<propertyModel>();
//打开窗体
2025-09-04 18:28:02 +08:00
IDialogParameters para = new Prism.Services.Dialogs.DialogParameters();
2025-08-15 16:34:31 +08:00
para.Add(GlobalObject.dialogPar.title.ToString(), title);
para.Add(GlobalObject.dialogPar.para1.ToString(), listPropertys);
var _dialogService = GlobalObject._prismContainer.Resolve<IDialogService>();
_dialogService.ShowDialog(nameof(DialogNewPositional), para, (RES) =>
{
if (RES.Result == ButtonResult.Yes)
{
ReslistPro = RES.Parameters.GetValue<ObservableCollection<propertyModel>>(GlobalObject.dialogPar.para1.ToString());
}
else if (RES.Result == ButtonResult.No)
{
}
});
return ReslistPro;
}
#endregion
#region
private ec_Cable ResCableEngID;
2025-09-04 18:28:02 +08:00
public async void UpdaTagPixels(Model.ec_enginedata_pixel ec_Enginedata_Pixel)
2025-08-15 16:34:31 +08:00
{
IsBusy = true;
try
{
if (ec_Enginedata_Pixel == null) return;
CableConnectionInfos.Clear();
ResCableEngID = await _iOModuleService.GetCableByEngID(ec_Enginedata_Pixel.EngineDataID);
//如果配置不存在
if (ResCableEngID == null)
{
var ResTagInfosByPixels= await _objectTypeService.GetTagInfosByPixels(SelectedTagPixels.DrawingFileID, ec_Enginedata_Pixel.PixelCode);
var listPropertys = new List<propertyModel>();
MessageBoxResult result = System.Windows.MessageBox.Show($"是否为通讯母线?", "KunHengCAD", MessageBoxButton.OKCancel, MessageBoxImage.Question);
if (result == MessageBoxResult.OK)
{
listPropertys = new List<propertyModel>();
Dictionary<string, string> pulldownlist;
2025-09-04 18:28:02 +08:00
listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "电缆对数", GroupName = "基本参数", PropertyValue = "1", ControlTypeName = Model.PROPERTYType.TextBox, });
listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "每电缆对芯数", GroupName = "基本参数", PropertyValue = "2", ControlTypeName = Model.PROPERTYType.TextBox, });
listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "电缆对编号前缀", GroupName = "基本参数", PropertyValue = "Set", ControlTypeName = Model.PROPERTYType.TextBox, });
2025-08-15 16:34:31 +08:00
pulldownlist = new Dictionary<string, string>();
pulldownlist.Add("数字", "数字");
pulldownlist.Add("字母", "字母");
pulldownlist.Add("电缆对序号", "电缆对序号");
2025-09-04 18:28:02 +08:00
listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "编号类型", GroupName = "电芯参数", PropertyValue = "数字", ControlTypeName = Model.PROPERTYType.ComboBox, Item = pulldownlist, });
2025-08-15 16:34:31 +08:00
pulldownlist = new Dictionary<string, string>();
pulldownlist.Add("按电缆编号", "按电缆编号");
pulldownlist.Add("按电缆对编号", "按电缆对编号");
2025-09-04 18:28:02 +08:00
listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "编号规则", GroupName = "电芯参数", PropertyValue = "按电缆对编号", ControlTypeName = Model.PROPERTYType.ComboBox, Item = pulldownlist, });
listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "电芯编号前缀", GroupName = "电芯参数", PropertyValue = "C", ControlTypeName = Model.PROPERTYType.TextBox, });
listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "极性", GroupName = "电芯参数", PropertyValue = "+,-,s", ControlTypeName = Model.PROPERTYType.TextBox, });
2025-08-15 16:34:31 +08:00
//显示属性弹窗
var ReslistPro = ShowPropertyMessage("新建" + ec_Enginedata_Pixel.TagNumber + "电缆配置", listPropertys);
if (ReslistPro == null || ReslistPro.Count() == 0) return;
ec_Cable ec_Cable = new ec_Cable();
ec_Cable.CableClass = "homerun";//母线
ec_Cable.Cable_Format = ResTagInfosByPixels.FirstOrDefault().tags.FirstOrDefault().EngineDataProperty.Where(e => e.PropertyName.Equals("电缆规格")).Select(e => e.PropertyValue).FirstOrDefault();
ec_Cable.EngineerDataID = ec_Enginedata_Pixel.EngineDataID;
ec_Cable.Sets = new List<ec_CableSet>();
int CableSetCount = int.TryParse(ReslistPro.Where(p => p.DisplayText.Equals("电缆对数")).Select(p => p.PropertyValue).FirstOrDefault(), out CableSetCount) ? CableSetCount : 0;
for (int i = 0; i < CableSetCount; i++)
{
ec_CableSet ec_CableSet = new ec_CableSet();
ec_CableSet.CableSetName = ReslistPro.Where(p => p.DisplayText.Equals("电缆对编号前缀")).Select(p => p.PropertyValue).FirstOrDefault() + (i + 1);
ec_CableSet.CableSetSeq = i + 1;
ec_CableSet.Wires = new List<ec_CableSetWire>();
int WireCount = int.TryParse(ReslistPro.Where(p => p.DisplayText.Equals("每电缆对芯数")).Select(p => p.PropertyValue).FirstOrDefault(), out WireCount) ? WireCount : 0;
for (int j = 0; j < WireCount; j++)
{
ec_CableSetWire ec_CableSetWire = new ec_CableSetWire();
ec_CableSetWire.Polarity = ReslistPro.Where(p => p.DisplayText.Equals("极性")).Select(p => p.PropertyValue).FirstOrDefault().Split(',')[Math.Abs(j % 3)];
ec_CableSetWire.SetLevel = j + 1;
string a = ReslistPro.Where(p => p.DisplayText.Equals("电芯编号前缀")).Select(p => p.PropertyValue).FirstOrDefault();//组成线号名的前缀
string Tag = "";//线号名的中间部分
switch (ReslistPro.Where(p => p.DisplayText.Equals("编号规则")).Select(p => p.PropertyValue).FirstOrDefault())
{
case "按电缆编号":
if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("数字"))
{
Tag = (j + 1).ToString();
}
else if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("字母"))
{
Tag = Tag + (char)('A' + j);
}
else if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("电缆对序号"))
{
Tag = (i + 1).ToString();
}
break;
case "按电缆对编号":
a = ec_Enginedata_Pixel.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);
ResCableEngID = await _iOModuleService.GetCableByEngID(ec_Enginedata_Pixel.EngineDataID);
}
else
{
listPropertys = new List<propertyModel>();
Dictionary<string, string> pulldownlist;
2025-09-04 18:28:02 +08:00
listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "电缆对数", GroupName = "基本参数", PropertyValue = "10", ControlTypeName = Model.PROPERTYType.TextBox, });
listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "每电缆对芯数", GroupName = "基本参数", PropertyValue = "2", ControlTypeName = Model.PROPERTYType.TextBox, });
listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "电缆对编号前缀", GroupName = "基本参数", PropertyValue = "Set", ControlTypeName = Model.PROPERTYType.TextBox, });
2025-08-15 16:34:31 +08:00
pulldownlist = new Dictionary<string, string>();
pulldownlist.Add("数字", "数字");
pulldownlist.Add("字母", "字母");
pulldownlist.Add("电缆对序号", "电缆对序号");
2025-09-04 18:28:02 +08:00
listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "编号类型", GroupName = "电芯参数", PropertyValue = "数字", ControlTypeName = Model.PROPERTYType.ComboBox, Item = pulldownlist, });
2025-08-15 16:34:31 +08:00
pulldownlist = new Dictionary<string, string>();
pulldownlist.Add("按电缆编号", "按电缆编号");
pulldownlist.Add("按电缆对编号", "按电缆对编号");
2025-09-04 18:28:02 +08:00
listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "编号规则", GroupName = "电芯参数", PropertyValue = "按电缆对编号", ControlTypeName = Model.PROPERTYType.ComboBox, Item = pulldownlist, });
listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "电芯编号前缀", GroupName = "电芯参数", PropertyValue = "C", ControlTypeName = Model.PROPERTYType.TextBox, });
listPropertys.Add(new propertyModel() { Id = "1", DisplayText = "极性", GroupName = "电芯参数", PropertyValue = "+,-,s", ControlTypeName = Model.PROPERTYType.TextBox, });
2025-08-15 16:34:31 +08:00
//显示属性弹窗
var ReslistPro = ShowPropertyMessage("新建" + ec_Enginedata_Pixel.TagNumber + "电缆配置", listPropertys);
if (ReslistPro == null || ReslistPro.Count == 0) return;
ec_Cable ec_Cable = new ec_Cable();
ec_Cable.CableClass = "conventional";//常规电缆
ec_Cable.EngineerDataID = ec_Enginedata_Pixel.EngineDataID;
ec_Cable.Sets = new List<ec_CableSet>();
int CableSetCount = int.TryParse(ReslistPro.Where(p => p.DisplayText.Equals("电缆对数")).Select(p => p.PropertyValue).FirstOrDefault(), out CableSetCount) ? CableSetCount : 0;
for (int i = 0; i < CableSetCount; i++)
{
ec_CableSet ec_CableSet = new ec_CableSet();
ec_CableSet.CableSetName = ReslistPro.Where(p => p.DisplayText.Equals("电缆对编号前缀")).Select(p => p.PropertyValue).FirstOrDefault() + (i + 1);
ec_CableSet.CableSetSeq = i + 1;
ec_CableSet.Wires = new List<ec_CableSetWire>();
int WireCount = int.TryParse(ReslistPro.Where(p => p.DisplayText.Equals("每电缆对芯数")).Select(p => p.PropertyValue).FirstOrDefault(), out WireCount) ? WireCount : 0;
for (int j = 0; j < WireCount; j++)
{
ec_CableSetWire ec_CableSetWire = new ec_CableSetWire();
ec_CableSetWire.Polarity = ReslistPro.Where(p => p.DisplayText.Equals("极性")).Select(p => p.PropertyValue).FirstOrDefault().Split(',')[Math.Abs(j % 3)];
ec_CableSetWire.SetLevel = j + 1;
string a = ReslistPro.Where(p => p.DisplayText.Equals("电芯编号前缀")).Select(p => p.PropertyValue).FirstOrDefault();//组成线号名的前缀
string Tag = "";//线号名的中间部分
switch (ReslistPro.Where(p => p.DisplayText.Equals("编号规则")).Select(p => p.PropertyValue).FirstOrDefault())
{
case "按电缆编号":
if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("数字"))
{
Tag = (j + 1).ToString();
}
else if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("字母"))
{
Tag = Tag + (char)('A' + j);
}
else if (ReslistPro.Where(p => p.DisplayText.Equals("编号类型")).Select(p => p.PropertyValue).FirstOrDefault().Equals("电缆对序号"))
{
Tag = (i + 1).ToString();
}
break;
case "按电缆对编号":
a = ec_Enginedata_Pixel.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);
ResCableEngID = await _iOModuleService.GetCableByEngID(ec_Enginedata_Pixel.EngineDataID);
}
}
if (ResCableEngID!=null)
{
//端子数如果大于9表格的行数等于端子数
int lineNumber = 0;
foreach (var Set in ResCableEngID.Sets)
{
foreach (var Wire in Set.Wires)
{
lineNumber++;
}
}
lineNumber = lineNumber > 9 ? lineNumber : 9;
//设置From设备列To设备列电缆列
for (int i = 0; i < lineNumber; i++)
{
CableConnectionInfo cableConnectionInfo = new CableConnectionInfo();
//第一行
if (i == 0)
{
if (ResCableEngID.FromPanel != null)
{
cableConnectionInfo.FromPanel = new TemplateInfo() { Type = TemplateType.TextBlock, Value = ResCableEngID.FromPanel.TagNumber, Foreground = "Black" };
}
if (ResCableEngID.ToPanel != null)
{
cableConnectionInfo.ToPanel = new TemplateInfo() { Type = TemplateType.TextBlock, Value = ResCableEngID.ToPanel.TagNumber, Foreground = "Black" };
}
}
//第二行
if (i == 1)
{
if (ResCableEngID.FromPanel != null)
{
cableConnectionInfo.FromPanel = new TemplateInfo() { Type = TemplateType.TextBlock, Value = ResCableEngID.FromPanel.ObjectTypeName, Foreground = "Black" };
}
if (ResCableEngID.ToPanel != null)
{
cableConnectionInfo.ToPanel = new TemplateInfo() { Type = TemplateType.TextBlock, Value = ResCableEngID.ToPanel.ObjectTypeName, Foreground = "Black" };
}
}
//第四行
if (i == 3)
{
cableConnectionInfo.FromPanel = new TemplateInfo() { Type = TemplateType.TextBlock, Value = "请选择端子排↓", Foreground = "Red" };
cableConnectionInfo.ToPanel = new TemplateInfo() { Type = TemplateType.TextBlock, Value = "请选择端子排↓", Foreground = "Red" };
}
//第五行
if (i == 4)
{
var items = new List<string>();
if (ResCableEngID.FromPanel != null)
{
items = ResCableEngID.FromPanel.strips.OrderBy(s => s.Panel_Strip_Seq).Select(s => s.StripName).ToList();
}
items.Insert(0, "未选择端子排");
cableConnectionInfo.FromPanel = new TemplateInfo() { Type = TemplateType.ComboBox, Items = items, SelectItem = "未选择端子排" };
if (ResCableEngID.ToPanel != null)
{
items = ResCableEngID.ToPanel.strips.OrderBy(s => s.Panel_Strip_Seq).Select(s => s.StripName).ToList();
}
items.Insert(0, "未选择端子排");
cableConnectionInfo.ToPanel = new TemplateInfo() { Type = TemplateType.ComboBox, Items = items, SelectItem = "未选择端子排" };
}
//第七行
if (i == 6)
{
cableConnectionInfo.FromPanel = new TemplateInfo() { Type = TemplateType.RadToggleSwitchButton };
cableConnectionInfo.ToPanel = new TemplateInfo() { Type = TemplateType.RadToggleSwitchButton };
}
//第九行
if (i == 8)
{
cableConnectionInfo.FromPanel = new TemplateInfo() { Type = TemplateType.Button, Value = "新增端子排" };
cableConnectionInfo.ToPanel = new TemplateInfo() { Type = TemplateType.Button, Value = "新增端子排" };
}
cableConnectionInfo.TagNumber = ResCableEngID.TagNumber;
CableConnectionInfos.Add(cableConnectionInfo);
}
//设置电缆对,电芯的值
int index = 0;
foreach (var Set in ResCableEngID.Sets)
{
foreach (var Wire in Set.Wires)
{
CableConnectionInfos[index].Set = Set.CableSetName;
CableConnectionInfos[index].Wire = Wire.Wire_Tag;
//设置端子列
if (Wire.ConnectionOnSide1 != null)
{
CableConnectionInfos[index].FromPanelStripTermTemp = Wire.ConnectionOnSide1.Term_No + " : " + Wire.ConnectionOnSide1.StripName;
CableConnectionInfos[index].FromPanelStripTerm = Wire.ConnectionOnSide1.Term_No + " : " + Wire.ConnectionOnSide1.StripName;
CableConnectionInfos[index].FromPanelStripTerms.Add(CableConnectionInfos[index].FromPanelStripTerm);
}
if (Wire.ConnectionOnSide2 != null)
{
CableConnectionInfos[index].ToPanelStripTermTemp = Wire.ConnectionOnSide2.Term_No + " : " + Wire.ConnectionOnSide2.StripName;
CableConnectionInfos[index].ToPanelStripTerm = Wire.ConnectionOnSide2.Term_No + " : " + Wire.ConnectionOnSide2.StripName;
CableConnectionInfos[index].ToPanelStripTerms.Add(CableConnectionInfos[index].ToPanelStripTerm);
}
index++;
}
}
//设置端子列单元格的颜色
foreach (var item in CableConnectionInfos)
{
if (item.FromPanelStripTerm != null || item.FromPanelStripTermTemp != null)
{
if (item.FromPanelStripTerm.Equals(item.FromPanelStripTermTemp))
{
item.FoIsStatusModified = true;
}
}
if (item.ToPanelStripTerm != null || item.ToPanelStripTermTemp != null)
{
if (item.ToPanelStripTerm.Equals(item.ToPanelStripTermTemp))
{
item.ToIsStatusModified = true;
}
}
}
}
}
catch (Exception ex)
{
System.Windows.MessageBox.Show(ex.Message, "错误", MessageBoxButton.OK, MessageBoxImage.Error);
}
finally
{
IsBusy = false;
}
}
#endregion
#region
public ICommand TableButtonCmd => new DelegateCommand(TableButton_Click);
/// <summary>
/// 按钮点击事件
/// </summary>
/// <param name="parameter"></param>
public virtual async void TableButton_Click(object parameter)
{
#region
if (parameter.ToString().Equals("电缆连接"))
{
//需要判断两边是否都连接
var cables = CableConnectionInfos.Where(c => c.FromPanelStripTerm != null && c.ToPanelStripTerm != null).ToList();
if (cables == null || cables.Count() <= 0)
{
MessageBox.Show("左右From,To端子必须对称连接不能一个空白一个连接", "KunHengCAD", MessageBoxButton.OK, MessageBoxImage.Warning);
return;
}
2025-09-04 18:28:02 +08:00
Service.IOModuleService.Connections saveConnections = new Service.IOModuleService.Connections();
2025-08-15 16:34:31 +08:00
saveConnections.Conns = new List<ec_WireTerminal>();
//左边修改的端子
var FoCableLs = CableConnectionInfos.Where(c => !string.IsNullOrEmpty(c.FromPanelStripTerm) && !c.FromPanelStripTerm.Equals(c.FromPanelStripTermTemp));
foreach (var CableConnectionInfo in FoCableLs)
{
//设置删除实体
ec_WireTerminal deleWireTerminal = new ec_WireTerminal();
deleWireTerminal.Cable_Side = 0;
deleWireTerminal.NeedRemove = true;
deleWireTerminal.Strip_Side = 1;
var Set = ResCableEngID.Sets.Where(s => s.CableSetName.Equals(CableConnectionInfo.Set)).FirstOrDefault();
if (Set == null) continue;
var wire = Set.Wires.Where(w => w.Wire_Tag.Equals(CableConnectionInfo.Wire)).FirstOrDefault();
if (wire == null) continue;
deleWireTerminal.WireID = wire.WireID;
//将需要删除的连接添加到集合
saveConnections.Conns.Add(deleWireTerminal);
//获取当前要保存连接的端子
var CurrentTerm = ResFoPanelStrip.Channels.FirstOrDefault().Terms.Where(t => t.Term_No.Equals(CableConnectionInfo.FromPanelStripTerm.Split(':')[0].Trim())).FirstOrDefault();
//设置保存连接实体
ec_WireTerminal saveWireTerminal = new ec_WireTerminal();
saveWireTerminal.Cable_Side = 0;
saveWireTerminal.NeedRemove = false;
saveWireTerminal.Strip_Side = 1;
saveWireTerminal.CableSetName = CableConnectionInfo.Set;
saveWireTerminal.CreateUserID = CurrentTerm.CreateUserID;
saveWireTerminal.TermID = CurrentTerm.TermID;
saveWireTerminal.Polarity = wire.Polarity;
saveWireTerminal.WireID = wire.WireID;
saveWireTerminal.Wire_Tag = wire.Wire_Tag;
saveConnections.Conns.Add(saveWireTerminal);
}
//右边修改的端子
var ToCableLs = CableConnectionInfos.Where(c => !string.IsNullOrEmpty(c.ToPanelStripTerm) && !c.ToPanelStripTerm.Equals(c.ToPanelStripTermTemp));
foreach (var CableConnectionInfo in ToCableLs)
{
//设置删除实体数据
ec_WireTerminal deleWireTerminal = new ec_WireTerminal();
deleWireTerminal.Cable_Side = 1;
deleWireTerminal.NeedRemove = true;
deleWireTerminal.Strip_Side = 0;
var Set = ResCableEngID.Sets.Where(s => s.CableSetName.Equals(CableConnectionInfo.Set)).FirstOrDefault();
if (Set == null) continue;
var wire = Set.Wires.Where(w => w.Wire_Tag.Equals(CableConnectionInfo.Wire)).FirstOrDefault();
if (wire == null) continue;
deleWireTerminal.WireID = wire.WireID;
//将需要删除的连接添加到集合
saveConnections.Conns.Add(deleWireTerminal);
//获取当前要保存连接的端子
var CurrentTerm = ResToPanelStrip.Channels.FirstOrDefault().Terms.Where(t => t.Term_No.Equals(CableConnectionInfo.ToPanelStripTerm.Split(':')[0].Trim())).FirstOrDefault();
//设置保存连接实体
ec_WireTerminal saveWireTerminal = new ec_WireTerminal();
saveWireTerminal.Cable_Side = 1;
saveWireTerminal.NeedRemove = false;
saveWireTerminal.Strip_Side = 0;
saveWireTerminal.CableSetName = CableConnectionInfo.Set;
saveWireTerminal.CreateUserID = CurrentTerm.CreateUserID;
saveWireTerminal.TermID = CurrentTerm.TermID;
saveWireTerminal.Polarity = wire.Polarity;
saveWireTerminal.WireID = wire.WireID;
saveWireTerminal.Wire_Tag = wire.Wire_Tag;
saveConnections.Conns.Add(saveWireTerminal);
}
var ResSaveConnection = await _iOModuleService.SaveConnections(saveConnections);
if (ResSaveConnection != null)
{
//刷新页面
UpdaTagPixels(SelectedTagPixels);
MessageBox.Show("保存成功", "KunHengCAD", MessageBoxButton.OK, MessageBoxImage.Information);
}
return;
}
#endregion
#region
if (parameter.ToString().Equals("关闭"))
{
2025-09-04 18:28:02 +08:00
RequestClose.Invoke(new DialogResult(ButtonResult.Cancel));
2025-08-15 16:34:31 +08:00
this.Dispose();
return;
}
#endregion
#region
if (parameter.ToString().Equals("Fo新增端子排"))
{
var Pannel = ResCableEngID.FromPanel;
//打开窗体
2025-09-04 18:28:02 +08:00
IDialogParameters para = new Prism.Services.Dialogs.DialogParameters();
2025-08-15 16:34:31 +08:00
para.Add(GlobalObject.dialogPar.info.ToString(), "Fo");
para.Add(GlobalObject.dialogPar.para1.ToString(), ResCableEngID);
var _dialogService = GlobalObject._prismContainer.Resolve<IDialogService>();
_dialogService.ShowDialog(nameof(DialogCableConnection_NewStrip), para, (RES) =>
{
if (RES.Result == ButtonResult.Yes)
{
}
else if (RES.Result == ButtonResult.No)
{
}
//新增端子需要更新页面
UpdaTagPixels(SelectedTagPixels);
});
}
if (parameter.ToString().Equals("To新增端子排"))
{
var Pannel = ResCableEngID.ToPanel;
//打开窗体
2025-09-04 18:28:02 +08:00
IDialogParameters para = new Prism.Services.Dialogs.DialogParameters();
2025-08-15 16:34:31 +08:00
para.Add(GlobalObject.dialogPar.info.ToString(), "To");
para.Add(GlobalObject.dialogPar.para1.ToString(), ResCableEngID);
var _dialogService = GlobalObject._prismContainer.Resolve<IDialogService>();
_dialogService.ShowDialog(nameof(DialogCableConnection_NewStrip), para, (RES) =>
{
if (RES.Result == ButtonResult.Yes)
{
}
else if (RES.Result == ButtonResult.No)
{
}
//新增端子需要更新页面
UpdaTagPixels(SelectedTagPixels);
});
}
#endregion
}
#endregion
#region Fo设备列的下拉框选择事件
private ec_PanelStrip ResFoPanelStrip;
public ICommand FoSelectChangedCommand => new DelegateCommand(FoSelectChanged);
/// <summary>
/// 设备列的下拉框选择事件
/// </summary>
/// <param name="parameter"></param>
public virtual async void FoSelectChanged(object parameter)
{
if (parameter == null) return;
var dataItem = parameter as CableConnectionInfo;
// 直接获取选中的值
var selectedValue = dataItem.FromPanel.SelectItem;
if (!selectedValue.Equals("未选择端子排") || selectedValue.Equals(""))
{
//端子排的名获取StripID
var StripID = ResCableEngID.FromPanel.strips.Where(s => s.StripName.Equals(selectedValue)).Select(s => s.StripID).FirstOrDefault();
ResFoPanelStrip = await _iOModuleService.GetPanelStrip(StripID, false, false);
if (ResFoPanelStrip == null) return;
foreach (var item in CableConnectionInfos)
{
if (item.Wire != null)
{
item.FoTermIsRead = false;
}
item.FromPanelStripTerms.Clear();
item.FromPanelStripTerms.AddRange(ResFoPanelStrip.Channels.FirstOrDefault().Terms.Select(t => t.Term_No).Select(t => t = t + " : " + selectedValue));
}
CableConnectionInfo.FoAvailableOptions.Clear();
//获取未连接的端子
var terms = ResFoPanelStrip.Channels.FirstOrDefault().Terms.Where(t => t.Connection == null && t.Connection2 == null).Select(t => t.Term_No).ToList();
CableConnectionInfo.FoAvailableOptions.AddRange(terms.Select(t => t = t + " : " + selectedValue));
}
else
{
foreach (var item in CableConnectionInfos)
{
item.FoTermIsRead = true;
item.FromPanelStripTerms.Clear();
if (item.Set == null || item.Set == null) continue;
var Set = ResCableEngID.Sets.Where(s => s.CableSetName.Equals(item.Set)).FirstOrDefault();
var Wire = Set.Wires.Where(w => w.Wire_Tag.Equals(item.Wire)).FirstOrDefault();
if (Wire.ConnectionOnSide1 != null)
{
item.FromPanelStripTerm = Wire.ConnectionOnSide1.Term_No + " : " + Wire.ConnectionOnSide1.StripName;
item.FromPanelStripTerms.Add(Wire.ConnectionOnSide1.Term_No + " : " + Wire.ConnectionOnSide1.StripName);
}
else
{
continue;
}
}
}
}
#endregion
#region To设备列的下拉框选择事件
private ec_PanelStrip ResToPanelStrip;
public ICommand ToSelectChangedCommand => new DelegateCommand(ToSelectChanged);
/// <summary>
/// 设备列的下拉框选择事件
/// </summary>
/// <param name="parameter"></param>
public virtual async void ToSelectChanged(object parameter)
{
if (parameter == null) return;
var dataItem = parameter as CableConnectionInfo;
// 直接获取选中的值
var selectedValue = dataItem.ToPanel.SelectItem;
if (!selectedValue.Equals("未选择端子排") || selectedValue.Equals(""))
{
//端子排的名获取StripID
var StripID = ResCableEngID.ToPanel.strips.Where(s => s.StripName.Equals(selectedValue)).Select(s => s.StripID).FirstOrDefault();
ResToPanelStrip = await _iOModuleService.GetPanelStrip(StripID, false, false);
if (ResToPanelStrip == null) return;
foreach (var item in CableConnectionInfos)
{
if (item.Wire != null)
{
item.ToTermIsRead = false;
}
item.ToPanelStripTerms.Clear();
item.ToPanelStripTerms.AddRange(ResFoPanelStrip.Channels.FirstOrDefault().Terms.Select(t => t.Term_No).Select(t => t = t + " : " + selectedValue));
}
CableConnectionInfo.ToAvailableOptions.Clear();
//获取未连接的端子
var terms = ResToPanelStrip.Channels.FirstOrDefault().Terms.Where(t => t.Connection == null && t.Connection2 == null).Select(t => t.Term_No).ToList();
CableConnectionInfo.ToAvailableOptions.AddRange(terms.Select(t => t = t + " : " + selectedValue));
}
else
{
foreach (var item in CableConnectionInfos)
{
item.ToTermIsRead = true;
item.ToPanelStripTerms.Clear();
if (item.Set == null || item.Set == null) continue;
var Set = ResCableEngID.Sets.Where(s => s.CableSetName.Equals(item.Set)).FirstOrDefault();
var Wire = Set.Wires.Where(w => w.Wire_Tag.Equals(item.Wire)).FirstOrDefault();
if (Wire.ConnectionOnSide2 != null)
{
item.ToPanelStripTerm = Wire.ConnectionOnSide2.Term_No + " : " + Wire.ConnectionOnSide2.StripName;
item.ToPanelStripTerms.Add(Wire.ConnectionOnSide2.Term_No + " : " + Wire.ConnectionOnSide2.StripName);
}
else
{
continue;
}
}
}
}
#endregion
#region form端子列下拉改变事件
public ICommand FromPanelStripTermCmd => new DelegateCommand(FromPanelStripTerm_SelectChanged);
/// <summary>
/// form端子列下拉改变事件
/// </summary>
/// <param name="parameter"></param>
public virtual async void FromPanelStripTerm_SelectChanged(object parameter)
{
if (SelectCableConnectionInfo.isFoUpdate)
{
if (parameter == null) return;
var dataItem = parameter as CableConnectionInfo;
// 直接获取选中的值
var selectedValue = dataItem.FromPanelStripTerm;
//获取未连接的端子
var terms = ResFoPanelStrip.Channels.FirstOrDefault().Terms.Where(t => t.Connection == null && t.Connection2 == null).Select(t => t.Term_No).ToList();
terms = terms.Select(t => t = t + " : " + ResFoPanelStrip.StripName).ToList();
//获取当前行的索引
var index = CableConnectionInfos.IndexOf(SelectCableConnectionInfo);
//获取选中值索引
var seleValueIndex = SelectCableConnectionInfo.FromPanelStripTerms.IndexOf(selectedValue);
//批量填充选中
if (!CableConnectionInfos.Any(c => c.FoIsChecked = false)) return;
if (!string.IsNullOrEmpty(CableConnectionInfos[index + 1].Wire))
{
if (index < CableConnectionInfos.Count())
{
int i = 0;
foreach (var item in SelectCableConnectionInfo.FromPanelStripTerms)
{
if (i>= seleValueIndex)
{
if (CableConnectionInfo.FoAvailableOptions.Contains(item))
{
CableConnectionInfos[index + 1].FromPanelStripTerm = item;
break;
}
}
i++;
}
}
}
}
}
#endregion
#region To端子列下拉改变事件
public ICommand ToPanelStripTermCmd => new DelegateCommand(ToPanelStripTerm_SelectChanged);
/// <summary>
/// To端子列下拉改变事件
/// </summary>
/// <param name="parameter"></param>
public virtual async void ToPanelStripTerm_SelectChanged(object parameter)
{
if (SelectCableConnectionInfo.isToUpdate)
{
if (parameter == null) return;
var dataItem = parameter as CableConnectionInfo;
// 直接获取选中的值
var selectedValue = dataItem.ToPanelStripTerm;
//获取未连接的端子
var terms = ResToPanelStrip.Channels.FirstOrDefault().Terms.Where(t => t.Connection == null && t.Connection2 == null).Select(t => t.Term_No).ToList();
terms = terms.Select(t => t = t + " : " + ResToPanelStrip.StripName).ToList();
//获取当前行的索引
var index = CableConnectionInfos.IndexOf(SelectCableConnectionInfo);
//获取选中值索引
var seleValueIndex = SelectCableConnectionInfo.ToPanelStripTerms.IndexOf(selectedValue);
//批量填充选中
if (!CableConnectionInfos.Any(c => c.ToIsChecked = false)) return;
if (!string.IsNullOrEmpty(CableConnectionInfos[index + 1].Wire))
{
if (index < CableConnectionInfos.Count())
{
int i = 0;
foreach (var item in SelectCableConnectionInfo.ToPanelStripTerms)
{
if (i >= seleValueIndex)
{
if (CableConnectionInfo.ToAvailableOptions.Contains(item))
{
CableConnectionInfos[index + 1].ToPanelStripTerm = item;
break;
}
}
i++;
}
}
}
}
}
#endregion
#endregion
}
public class CableConnectionInfo : DialogBase
{
#region
private TemplateInfo _FromPanel;
/// <summary>
/// From设备信息
/// </summary>
public TemplateInfo FromPanel
{
get { return _FromPanel; }
set
{
_FromPanel = value;
RaisePropertyChanged(nameof(FromPanel));
}
}
private string _FromPanelStripTerm;
/// <summary>1
/// From端子排端子
/// </summary>
public string FromPanelStripTerm
{
get { return _FromPanelStripTerm; }
set
{
if (_FromPanelStripTerm == value)
{
isFoUpdate = false;
return;
}
isFoUpdate = true;
// 释放旧选项
if (!string.IsNullOrEmpty(_FromPanelStripTerm))
{
if (_FromPanelStripTerm.Split(':')[1].Trim().Equals(value.Split(':')[1].Trim()))
{
FoAvailableOptions.Add(_FromPanelStripTerm);
var templs = FoAvailableOptions.OrderBy(item => FromPanelStripTerms.Contains(item) ? FromPanelStripTerms.IndexOf(item) : int.MaxValue).ToList();
FoAvailableOptions.Clear();
FoAvailableOptions.AddRange(templs);
}
}
_FromPanelStripTerm = value;
// 占用新选项
if (!string.IsNullOrEmpty(value))
{
FoAvailableOptions.Remove(value);
}
RaisePropertyChanged(nameof(FromPanelStripTerm));
if (!string.IsNullOrEmpty(FromPanelStripTermTemp) && !string.IsNullOrEmpty(_FromPanelStripTerm))
{
if (_FromPanelStripTerm.Equals(FromPanelStripTermTemp))
{
FoIsStatusModified = true;
}
else
{
FoIsStatusModified = false;
}
}
}
}
private string _FromPanelStripTermTemp;
/// <summary>
/// 记录改变前Form的端子
/// </summary>
public string FromPanelStripTermTemp
{
get { return _FromPanelStripTermTemp; }
set
{
_FromPanelStripTermTemp = value;
RaisePropertyChanged(nameof(FromPanelStripTermTemp));
}
}
private ObservableCollection<string> _FromPanelStripTerms = new ObservableCollection<string>();
/// <summary>
/// 端子列的下拉列表
/// </summary>
public ObservableCollection<string> FromPanelStripTerms
{
get { return _FromPanelStripTerms; }
set
{
_FromPanelStripTerms = value;
RaisePropertyChanged(nameof(FromPanelStripTerms));
}
}
private string _Wire;
/// <summary>
/// 电芯
/// </summary>
public string Wire
{
get { return _Wire; }
set
{
_Wire = value;
RaisePropertyChanged(nameof(Wire));
}
}
private string _Set;
/// <summary>
/// 电缆对
/// </summary>
public string Set
{
get { return _Set; }
set
{
_Set = value;
RaisePropertyChanged(nameof(Set));
}
}
private string _TagNumber;
/// <summary>
/// 电缆
/// </summary>
public string TagNumber
{
get { return _TagNumber; }
set
{
_TagNumber = value;
RaisePropertyChanged(nameof(TagNumber));
}
}
private string _ToPanelStripTerm;
/// <summary>
/// To端子排端子
/// </summary>
public string ToPanelStripTerm
{
get { return _ToPanelStripTerm; }
set
{
if (_ToPanelStripTerm == value)
{
isToUpdate = false;
return;
}
isToUpdate = true;
// 释放旧选项
if (!string.IsNullOrEmpty(_ToPanelStripTerm))
{
if (_ToPanelStripTerm.Split(':')[1].Trim().Equals(value.Split(':')[1].Trim()))
{
ToAvailableOptions.Add(_ToPanelStripTerm);
var templs = ToAvailableOptions.OrderBy(item => ToPanelStripTerms.Contains(item) ? ToPanelStripTerms.IndexOf(item) : int.MaxValue).ToList();
ToAvailableOptions.Clear();
ToAvailableOptions.AddRange(templs);
}
}
_ToPanelStripTerm = value;
// 占用新选项
if (!string.IsNullOrEmpty(value))
{
ToAvailableOptions.Remove(value);
}
RaisePropertyChanged(nameof(ToPanelStripTerm));
if (!string.IsNullOrEmpty(ToPanelStripTermTemp) && !string.IsNullOrEmpty(_ToPanelStripTerm))
{
if (_ToPanelStripTerm.Equals(ToPanelStripTermTemp))
{
ToIsStatusModified = true;
}
else
{
ToIsStatusModified = false;
}
}
}
}
private string _ToPanelStripTermTemp;
/// <summary>
/// 记录改变前的To设备的端子
/// </summary>
public string ToPanelStripTermTemp
{
get { return _ToPanelStripTermTemp; }
set
{
_ToPanelStripTermTemp = value;
RaisePropertyChanged(nameof(ToPanelStripTermTemp));
}
}
private List<string> _ToPanelStripTerms = new List<string>();
/// <summary>
/// To端子列的下拉列表
/// </summary>
public List<string> ToPanelStripTerms
{
get { return _ToPanelStripTerms; }
set
{
_ToPanelStripTerms = value;
RaisePropertyChanged(nameof(ToPanelStripTerms));
}
}
private TemplateInfo _ToPanel;
/// <summary>
/// To设备信息
/// </summary>
public TemplateInfo ToPanel
{
get { return _ToPanel; }
set
{
_ToPanel = value;
RaisePropertyChanged(nameof(ToPanel));
}
}
#endregion
#region
private bool _FoTermIsRead = true;
/// <summary>
/// 用来设置端子列的单元格是否只读
/// </summary>
public bool FoTermIsRead
{
get { return _FoTermIsRead; }
set
{
_FoTermIsRead = value;
RaisePropertyChanged(nameof(FoTermIsRead));
}
}
private bool _ToTermIsRead = true;
public bool ToTermIsRead
{
get { return _ToTermIsRead; }
set
{
_ToTermIsRead = value;
RaisePropertyChanged(nameof(ToTermIsRead));
}
}
private bool _FoIsChecked = true;
/// <summary>
/// 用来判断批量填充是否选中
/// </summary>
public bool FoIsChecked
{
get { return _FoIsChecked; }
set
{
_FoIsChecked = value;
RaisePropertyChanged(nameof(FoIsChecked));
}
}
private bool _ToIsChecked = true;
/// <summary>
///
/// </summary>
public bool ToIsChecked
{
get { return _ToIsChecked; }
set
{
_ToIsChecked = value;
RaisePropertyChanged(nameof(ToIsChecked));
}
}
private bool _FoIsStatusModified;
/// <summary>
/// 用来记录值是否连接
/// </summary>
public bool FoIsStatusModified
{
get { return _FoIsStatusModified; }
set
{
_FoIsStatusModified = value;
RaisePropertyChanged(nameof(FoIsStatusModified));
}
}
private bool _ToIsStatusModified;
/// <summary>
/// 用来记录值是否连接
/// </summary>
public bool ToIsStatusModified
{
get { return _ToIsStatusModified; }
set
{
_ToIsStatusModified = value;
RaisePropertyChanged(nameof(ToIsStatusModified));
}
}
private bool _isFoUpdate =true;
/// <summary>
/// 用来判断批量填充时是否修改过.为true时from的端子列下拉改变事件会执行
/// </summary>
public bool isFoUpdate
{
get { return _isFoUpdate; }
set {
_isFoUpdate = value;
RaisePropertyChanged(nameof(isFoUpdate));
}
}
private bool _isToUpdate=true;
/// <summary>
/// 用来判断批量填充时是否修改过.为true时To的端子列下拉改变事件会执行
/// </summary>
public bool isToUpdate
{
get { return _isToUpdate; }
set { _isToUpdate = value;
RaisePropertyChanged(nameof(isToUpdate));
}
}
// 共享的可用选项(静态)
public static ObservableCollection<string> FoAvailableOptions = new ObservableCollection<string>();
public static ObservableCollection<string> ToAvailableOptions = new ObservableCollection<string>();
#endregion
}
}