2008 lines
82 KiB
C#
Raw Normal View History

2025-08-15 15:38:37 +08:00
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Data;
using System.Linq;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Input;
using Prism.Services.Dialogs;
using Prism.Ioc;
using SWS.Commons;
using SWS.Model;
using SWS.Service;
using SWS.WPF.Views;
using Telerik.Windows.Controls;
using Telerik.Windows.Data;
using Unity;
using DialogParameters = Prism.Services.Dialogs.DialogParameters;
using DryIoc;
using ImTools;
2025-09-04 18:28:02 +08:00
using System.Timers;
using System.Windows.Threading;
2025-08-15 15:38:37 +08:00
namespace SWS.WPF.ViewModels
{
public class DialogSignalManagementViewModel : DialogBase, IDialogAware
{
#region
private ObservableCollection<SignalManagementInfo> _smInfos = new ObservableCollection<SignalManagementInfo>();
/// <summary>
/// 表格数据源
/// </summary>
public ObservableCollection<SignalManagementInfo> smInfos
{
get { return _smInfos; }
set
{
_smInfos = value;
RaisePropertyChanged(nameof(smInfos));
}
}
2025-09-04 18:28:02 +08:00
private QueryableCollectionView _smInfosView;
/// <summary>
/// 可筛选的的集合视图
/// </summary>
public QueryableCollectionView smInfosView
{
get { return _smInfosView; }
set { _smInfosView = value; RaisePropertyChanged(nameof(smInfosView)); }
}
2025-08-15 15:38:37 +08:00
private SignalManagementInfo _SelectedSmInfo;
/// <summary>
/// 选中行
/// </summary>
public SignalManagementInfo SelectedSmInfo
{
get { return _SelectedSmInfo; }
set
{
_SelectedSmInfo = value;
RaisePropertyChanged(nameof(SelectedSmInfo));
}
}
/// <summary>
/// 信号接口服务
/// </summary>
WireGroupService _wireGroupService;
private string _count;
/// <summary>
/// 表格数据数量
/// </summary>
public string count
{
get { return _count; }
set { _count = value; RaisePropertyChanged(nameof(count)); }
}
private string _pojectName;
/// <summary>
/// 表格名
/// </summary>
public string pojectName
{
get { return _pojectName; }
set { _pojectName = value; RaisePropertyChanged(nameof(pojectName)); }
}
public DialogSignalNotice SignalNoticeView { get; set; }
private string _ButtonContent = "回收站";
/// <summary>
/// 回收站按钮文本
/// </summary>
public string ButtonContent
{
get { return _ButtonContent; }
set { _ButtonContent = value; RaisePropertyChanged(nameof(ButtonContent)); }
}
private string _SearchText;
/// <summary>
/// 搜索框文本
/// </summary>
public string SearchText
{
get { return _SearchText; }
set { _SearchText = value; RaisePropertyChanged(nameof(SearchText)); }
}
private System.Windows.Visibility _IsButtonVisibility = Visibility.Hidden;
/// <summary>
/// 控制关联母线按钮显示隐藏
/// </summary>
public System.Windows.Visibility IsButtonVisibility
{
get { return _IsButtonVisibility; }
set
{
_IsButtonVisibility = value;
RaisePropertyChanged(nameof(IsButtonVisibility));
}
}
private Visibility _IsChannelButtonVisibility = Visibility.Hidden;
/// <summary>
/// 控制关联通道按钮显示隐藏
/// </summary>
public Visibility IsChannelButtonVisibility
{
get { return _IsChannelButtonVisibility; }
set
{
_IsChannelButtonVisibility = value;
RaisePropertyChanged(nameof(IsChannelButtonVisibility));
}
}
private ec_Wire_Group _IsAssociated;
/// <summary>
/// 通道是否关联信号
/// </summary>
public ec_Wire_Group IsAssociated
{
get { return _IsAssociated; }
set
{
_IsAssociated = value;
RaisePropertyChanged(nameof(IsAssociated));
}
}
2025-09-04 18:28:02 +08:00
private string[] _buttonTexts = { "全部", "输出信号", "非输出信号" };
2025-08-15 15:38:37 +08:00
2025-09-04 18:28:02 +08:00
private string _buttonText = "全部";
2025-08-15 15:38:37 +08:00
/// <summary>
/// 切换信号按钮的文本
/// </summary>
public string buttonText
{
get { return _buttonText; }
set
{
_buttonText = value;
RaisePropertyChanged(nameof(buttonText));
}
}
2025-09-04 18:28:02 +08:00
private bool _PopupButton_IsOpen;
/// <summary>
/// 导出按钮的浮框是否展开
/// </summary>
public bool PopupButton_IsOpen
{
get { return _PopupButton_IsOpen; }
set { _PopupButton_IsOpen = value;
RaisePropertyChanged(nameof(PopupButton_IsOpen));
}
}
private DateTime? _statDate;
/// <summary>
/// 开始时间
/// </summary>
public DateTime? statDate
{
get { return _statDate; }
set { _statDate = value;
RaisePropertyChanged(nameof(statDate));
}
}
private DateTime? _endDate;
/// <summary>
/// 结束时间
/// </summary>
public DateTime? endDate
{
get { return _endDate; }
set { _endDate = value;
RaisePropertyChanged(nameof(endDate));
}
}
2025-08-15 15:38:37 +08:00
#region
private List<ec_dataitemdetail> _GroupOthers;
/// <summary>
/// 绑定组别列表
/// </summary>
public List<ec_dataitemdetail> GroupOthers
{
get { return _GroupOthers; }
set { _GroupOthers = value; RaisePropertyChanged(nameof(GroupOthers)); }
}
private List<string> _BelongingMajors = new List<string> { "E", "M" };
/// <summary>
/// 绑定归属专业
/// </summary>
public List<string> BelongingMajors
{
get { return _BelongingMajors; }
set { _BelongingMajors = value; RaisePropertyChanged(nameof(BelongingMajors)); }
}
private List<string> _InOrOuts = new List<string> { "input", "output" };
/// <summary>
/// 绑定IO类型
/// </summary>
public List<string> InOrOuts
{
get { return _InOrOuts; }
set { _InOrOuts = value; RaisePropertyChanged(nameof(InOrOuts)); }
}
private List<string> _IO_Types = new List<string> { "ON/OFF", "NO", "NC", "4-20mA", "PT100", "Pulse", "N/A" };
/// <summary>
/// 绑定信号类型
/// </summary>
public List<string> IO_Types
{
get { return _IO_Types; }
set { _IO_Types = value; RaisePropertyChanged(nameof(IO_Types)); }
}
private List<string> _AL_GRPs;
/// <summary>
/// 绑定AL_GRP
/// </summary>
public List<string> AL_GRPs
{
get { return _AL_GRPs; }
set { _AL_GRPs = value; RaisePropertyChanged(nameof(AL_GRPs)); }
}
private List<string> _BL_GRPs;
/// <summary>
/// 绑定BL_GRP
/// </summary>
public List<string> BL_GRPs
{
get { return _BL_GRPs; }
set { _BL_GRPs = value; RaisePropertyChanged(nameof(BL_GRPs)); }
}
private List<ec_dataitemdetail> _Suppliers;
/// <summary>
/// 绑定供应商
/// </summary>
public List<ec_dataitemdetail> Suppliers
{
get { return _Suppliers; }
set { _Suppliers = value; RaisePropertyChanged(nameof(Suppliers)); }
}
private List<ec_dataitemdetail> _WHCPUs;
/// <summary>
/// 绑定WHCPU
/// </summary>
public List<ec_dataitemdetail> WHCPUs
{
get { return _WHCPUs; }
set
{
_WHCPUs = value;
ECRCPUs = value;
ShipOfficeCPUs = value;
RaisePropertyChanged(nameof(WHCPUs));
}
}
private List<ec_dataitemdetail> _ECRCPUs;
/// <summary>
/// 绑定ECRCPU
/// </summary>
public List<ec_dataitemdetail> ECRCPUs
{
get { return _ECRCPUs; }
set { _ECRCPUs = value; RaisePropertyChanged(nameof(ECRCPUs)); }
}
private List<ec_dataitemdetail> _ShipOfficeCPUs;
/// <summary>
/// 绑定ShipOfficeCPU
/// </summary>
public List<ec_dataitemdetail> ShipOfficeCPUs
{
get { return _ShipOfficeCPUs; }
set { _ShipOfficeCPUs = value; RaisePropertyChanged(nameof(ShipOfficeCPUs)); }
}
private WireGroups _Ent;
/// <summary>
/// 新增或修改的列表
/// </summary>
public WireGroups Ent
{
get { return _Ent; }
set { _Ent = value; }
}
#endregion
2025-09-04 18:28:02 +08:00
private CountdownModel _ReviewCountdown = new CountdownModel();
/// <summary>
/// 送审时间倒计时
/// </summary>
public CountdownModel ReviewCountdown
{
get { return _ReviewCountdown; }
set { _ReviewCountdown = value;
RaisePropertyChanged(nameof(ReviewCountdown));
}
}
private CountdownModel _ConstructionCountdown=new CountdownModel();
/// <summary>
/// 施工时间倒计时
/// </summary>
public CountdownModel ConstructionCountdown
{
get { return _ConstructionCountdown; }
set { _ConstructionCountdown = value;
RaisePropertyChanged(nameof(ConstructionCountdown));
}
}
2025-09-15 18:35:41 +08:00
private DateTime? _ReviewTime;
2025-09-04 18:28:02 +08:00
/// <summary>
/// 送审时间
/// </summary>
2025-09-15 18:35:41 +08:00
public DateTime? ReviewTime
2025-09-04 18:28:02 +08:00
{
get { return _ReviewTime; }
set { _ReviewTime = value;
RaisePropertyChanged(nameof(ReviewTime));
}
}
2025-09-15 18:35:41 +08:00
private DateTime? _ConstructionTime;
2025-09-04 18:28:02 +08:00
/// <summary>
/// 施工时间
/// </summary>
2025-09-15 18:35:41 +08:00
public DateTime? ConstructionTime
2025-09-04 18:28:02 +08:00
{
get { return _ConstructionTime; }
set { _ConstructionTime = value;
RaisePropertyChanged(nameof(ConstructionTime));
}
}
2025-08-15 15:38:37 +08:00
2025-09-15 18:35:41 +08:00
private Visibility _IsReviewTimeVisibility = Visibility.Visible;
/// <summary>
/// 控制送审时间是否可见
/// </summary>
public Visibility IsReviewTimeVisibility
{
get { return _IsReviewTimeVisibility; }
set
{
_IsReviewTimeVisibility = value;
RaisePropertyChanged(nameof(IsReviewTimeVisibility));
}
}
private Visibility _IsConstructionTimeVisibility = Visibility.Visible;
/// <summary>
/// 控制施工时间是否可见
/// </summary>
public Visibility IsConstructionTimeVisibility
{
get { return _IsConstructionTimeVisibility; }
set
{
_IsConstructionTimeVisibility = value;
RaisePropertyChanged(nameof(IsConstructionTimeVisibility));
}
}
2025-08-15 15:38:37 +08:00
2025-09-04 18:28:02 +08:00
private readonly DispatcherTimer _timer = new DispatcherTimer();
public ICommand StartReviewCommand { get; set; }
public ICommand StartConstructionCommand { get;set; }
2025-08-15 15:38:37 +08:00
#endregion
private readonly IDialogService _dialogService;
2025-09-04 18:28:02 +08:00
private DataItemService _dataItemService;
2025-08-15 15:38:37 +08:00
public DialogSignalManagementViewModel()
{
title = "信号管理";
_dialogService = GlobalObject._prismContainer.Resolve<IDialogService>();
_wireGroupService = GlobalObject.container.Resolve<WireGroupService>();
2025-09-04 18:28:02 +08:00
_dataItemService = GlobalObject.container.Resolve<DataItemService>();
2025-08-15 15:38:37 +08:00
}
public string Title => "";
public event Action<IDialogResult> RequestClose;
public bool CanCloseDialog()
{
return true;
}
public void OnDialogClosed()
{
}
2025-09-04 18:28:02 +08:00
private List<ec_Wire_Group> signals = new List<ec_Wire_Group>();
private List<ec_Wire_Group> Allsignals = new List<ec_Wire_Group>();
2025-08-15 15:38:37 +08:00
public async void OnDialogOpened(IDialogParameters parameters)
{
try
{
IsBusy = true; BusyContent = "加载中...";
2025-09-04 18:28:02 +08:00
//设置组别下拉列表
GroupOthers = Task.Run(() => _dataItemService.GetDetails("be_Signal_Group")).Result.OrderBy(s => s.DataItemCode).ToList();
Suppliers = Task.Run(() => _dataItemService.GetDetails("Maker")).Result;
WHCPUs = Task.Run(() => _dataItemService.GetDetails("Alarm")).Result;
//实例化用来修改保存的实体
Ent = new WireGroups();
Ent.Signals = new List<ec_Wire_Group>();
//DateTime startTime = DateTime.Now;
//设置信号源
2025-08-15 15:38:37 +08:00
signals = await _wireGroupService.GetSignals(GlobalObject.curProject.ProjectId, false);
2025-09-12 12:03:20 +08:00
if (signals == null)
{
signals = new List<ec_Wire_Group>();
}
2025-09-04 18:28:02 +08:00
//TimeSpan duration = DateTime.Now - startTime;
//System.Windows.MessageBox.Show($"Time taken: {duration.Seconds} milliseconds");
count = signals.Count().ToString();
2025-08-15 15:38:37 +08:00
signals = signals.Where(s => s.Status != WireGroupStatusEnum.deleted).ToList();
2025-09-04 18:28:02 +08:00
Allsignals = new List<ec_Wire_Group>(signals);
2025-08-15 15:38:37 +08:00
SetBaseData(signals);
2025-09-04 18:28:02 +08:00
count = signals.Count().ToString() + "/" + count;
2025-08-15 15:38:37 +08:00
pojectName = GlobalObject.curProject.ProjectName + " | " + GlobalObject.curProject.ShipNameCN;
2025-09-04 18:28:02 +08:00
2025-08-15 15:38:37 +08:00
//关联母线按钮是否显示
string FromWhichPage = parameters.GetValue<string>(GlobalObject.dialogPar.para1.ToString());
if (FromWhichPage != null)
{
if (FromWhichPage.Equals("关联母线"))
{
IsButtonVisibility = Visibility.Visible;
}
if (FromWhichPage.Equals("关联通道"))
{
IsChannelButtonVisibility = Visibility.Visible;
}
}
IsAssociated = parameters.GetValue<ec_Wire_Group>(GlobalObject.dialogPar.info.ToString());
2025-09-04 18:28:02 +08:00
//获取送审时间和施工时间
2025-09-15 18:35:41 +08:00
ReviewTime = GlobalObject.curProject.IO_predicted_issue;
ConstructionTime = GlobalObject.curProject.IO_predicted_issue;
if (ReviewTime == null) IsReviewTimeVisibility = Visibility.Collapsed;
if (ConstructionTime == null) IsConstructionTimeVisibility = Visibility.Collapsed;
2025-09-04 18:28:02 +08:00
// 获取当前时间
DateTime currentTime = DateTime.Now;
// 初始化倒计时时间
2025-09-15 18:35:41 +08:00
ReviewCountdown.TimeRemaining = ReviewTime==null? TimeSpan.Zero:(TimeSpan)(ReviewTime - currentTime);
ReviewCountdown.IsActive = ReviewTime == null ?false: true;
2025-09-04 18:28:02 +08:00
if (ReviewCountdown.TimeRemaining<= TimeSpan.Zero)
{
2025-09-15 18:35:41 +08:00
if (GlobalObject.curProject.IO_real_issue == null && GlobalObject.curProject.IO_predicted_issue!=null)
2025-09-09 08:58:50 +08:00
{
System.Windows.MessageBox.Show($"送审时间已过期: {ReviewCountdown.TimeRemaining:%d}天 {ReviewCountdown.TimeRemaining:hh\\:mm\\:ss}", "错误", MessageBoxButton.OK, MessageBoxImage.Error);
}
2025-09-04 18:28:02 +08:00
}
2025-09-15 18:35:41 +08:00
ConstructionCountdown.TimeRemaining = ConstructionTime==null? TimeSpan.Zero:(TimeSpan)(ConstructionTime - currentTime);
2025-08-15 15:38:37 +08:00
2025-09-15 18:35:41 +08:00
ConstructionCountdown.IsActive = ConstructionTime == null ? false: true;
2025-09-04 18:28:02 +08:00
if (ConstructionCountdown.TimeRemaining <= TimeSpan.Zero)
{
2025-09-15 18:35:41 +08:00
if (GlobalObject.curProject.IO_real_construct == null&& GlobalObject.curProject.IO_predicted_issue!=null)
2025-09-09 08:58:50 +08:00
{
System.Windows.MessageBox.Show($"施工时间已过期: {ConstructionCountdown.TimeRemaining:%d}天 {ConstructionCountdown.TimeRemaining:hh\\:mm\\:ss}", "错误", MessageBoxButton.OK, MessageBoxImage.Error);
}
2025-09-04 18:28:02 +08:00
}
// 初始化定时器
_timer.Interval = TimeSpan.FromSeconds(1);
_timer.Tick += OnTimerElapsed;
_timer.Start();
2025-08-15 15:38:37 +08:00
}
2025-09-04 18:28:02 +08:00
catch (Exception ex)
{
System.Windows.MessageBox.Show(ex.Message, "错误", MessageBoxButton.OK, MessageBoxImage.Error);
}
finally
{
IsBusy = false;
}
2025-08-15 15:38:37 +08:00
}
2025-09-04 18:28:02 +08:00
2025-08-15 15:38:37 +08:00
public override void ExecuteOKCommandAsync(object para)
{
DialogResult res = new DialogResult(ButtonResult.Yes);
RequestClose.Invoke(res);
}
public override void ExecuteCloseCommand(object parameter)
{
2025-09-04 18:28:02 +08:00
if (smInfos.Any(s => s.IsModified == true || s.ChildSignals.Any(c => c.IsModified == true)))
{
MessageBoxResult resultMessage = MessageBox.Show("修改未保存,是否取消修改", "KunHengCAD", MessageBoxButton.OKCancel, MessageBoxImage.Question);
if (resultMessage != MessageBoxResult.OK)
{
return;
}
}
2025-08-15 15:38:37 +08:00
if (parameter as string == "ClickNo")
{
DialogResult res = new DialogResult(ButtonResult.No);
RequestClose.Invoke(res);
}
else
{
DialogResult res = new DialogResult(ButtonResult.Cancel);
RequestClose.Invoke(res);
}
this.Dispose();
}
#region
public ICommand StatusButtonCmd => new DelegateCommand(StatusButton_Click);
/// <summary>
/// 显示状态按钮
/// </summary>
/// <param name="parameter"></param>
public virtual async void StatusButton_Click(object parameter)
{
2025-09-04 18:28:02 +08:00
if (smInfos.Any(s => s.IsModified == true || s.ChildSignals.Any(c => c.IsModified == true)))
{
MessageBoxResult resultMessage = MessageBox.Show("修改未保存,是否取消修改", "KunHengCAD", MessageBoxButton.OKCancel, MessageBoxImage.Question);
if (resultMessage != MessageBoxResult.OK)
{
return;
}
}
2025-08-15 15:38:37 +08:00
smInfos = new ObservableCollection<SignalManagementInfo>();
IsBusy = true; BusyContent = "查询中...";
2025-09-04 18:28:02 +08:00
//signals = await _wireGroupService.GetSignals(GlobalObject.curProject.ProjectId, false);
//IsBusy = false;
//count = signals.Count.ToString();
//signals = signals.Where(s => s.Status != WireGroupStatusEnum.deleted).ToList();
//Allsignals = new List<ec_Wire_Group>(signals);
2025-08-15 15:38:37 +08:00
if (!parameter.Equals("All"))
{
2025-09-04 18:28:02 +08:00
signals = Allsignals.Where(s => s.Status.ToString().Equals(parameter)).ToList();
SetBaseData(signals, 1);
2025-08-15 15:38:37 +08:00
}
2025-09-04 18:28:02 +08:00
else
{
int buttonTextindex = _buttonTexts.IndexOf(buttonText);
buttonText = _buttonTexts[(buttonTextindex + 1) % _buttonTexts.Length];
2025-08-15 15:38:37 +08:00
2025-09-04 18:28:02 +08:00
var InOrOut = "";
if (buttonText.Equals("输出信号"))
{
InOrOut = "output";
}
if (buttonText.Equals("非输出信号"))
{
InOrOut = "input";
}
signals = Allsignals.Where(s => s.Status != WireGroupStatusEnum.deleted).ToList();
if (!buttonText.Equals("全部"))
{
if (InOrOut.Equals("output"))
{
signals = Allsignals.Where(s => s.InOrOut.ToString().Equals(InOrOut)).ToList();
}
else if (InOrOut.Equals("input"))
{
signals = Allsignals.Where(s => !s.InOrOut.ToString().Equals("output")).ToList();
}
}
SetBaseData(signals);
}
count = smInfos.Count.ToString() + "/" + count.Split('/')[1];
IsBusy = false;
2025-08-15 15:38:37 +08:00
}
public ICommand ButtonCmd => new DelegateCommand(Button_Click);
/// <summary>
/// 页面右侧按钮
/// </summary>
/// <param name="parameter"></param>
public virtual async void Button_Click(object parameter)
{
if (!_smInfos.Any())
{
return;
}
int index = _smInfos.IndexOf(_SelectedSmInfo);//当前选中项在源数据集合中的索引
#region
if (parameter.Equals("新增信号"))
{
if (index != -1 || SelectedSmInfo.type != "虚拟点")
{
var newEntity = new SignalManagementInfo();
newEntity.BelongingMajor = "M";
newEntity.type = "信号";
newEntity.Status = "New";
newEntity.GroupOthers = GroupOthers;
newEntity.Suppliers = Suppliers;
newEntity.IsModified = true;
//订阅事件以更新数据。
newEntity.GroupOtherChanged += (sender, e) => UpdateParametersValue((SignalManagementInfo)sender);
// 添加新行到选中行下方
2025-09-04 18:28:02 +08:00
smInfos.Insert(index == -1 ? 0 : index + 1, newEntity);
2025-08-15 15:38:37 +08:00
//重新排序
int i = 0;
2025-09-04 18:28:02 +08:00
foreach (var item in smInfos)
2025-08-15 15:38:37 +08:00
{
i++;
item.serialNumber = i.ToString();
foreach (var item2 in item.ChildSignals)
{
i++;
item2.serialNumber = i.ToString();
}
}
SelectedSmInfo = newEntity;
}
else
{
// 显示消息框
MessageBox.Show("请选择信号节点!", "KunHengCAD", MessageBoxButton.OK, MessageBoxImage.Warning);
return;
}
}
#endregion
#region
if (parameter.Equals("新增虚拟点"))
{
if (index == -1 || SelectedSmInfo.type.Equals("虚拟点"))
{
MessageBox.Show("请选择信号节点!", "KunHengCAD", MessageBoxButton.OK, MessageBoxImage.Warning);
return;
}
else
{
2025-09-04 18:28:02 +08:00
if (string.IsNullOrEmpty(SelectedSmInfo.Wire_Group_ID))
{
MessageBox.Show("新增的信号,请先保存在操作!", "KunHengCAD", MessageBoxButton.OK, MessageBoxImage.Warning);
return;
}
2025-08-15 15:38:37 +08:00
var newEntity = new SignalManagementInfo();
newEntity.BelongingMajor = SelectedSmInfo.BelongingMajor;
newEntity.type = "虚拟点";
newEntity.Status = "New";
newEntity.ParentID = SelectedSmInfo.Wire_Group_ID;
newEntity.GroupOthers = GroupOthers;
2025-09-04 18:28:02 +08:00
//newEntity.GroupOther = SelectedSmInfo.GroupOther;
2025-08-15 15:38:37 +08:00
newEntity.Suppliers = Suppliers;
newEntity.IsModified = true;
//订阅事件以更新数据。
newEntity.ParametersChanged += (sender, e) => UpdateParametersValue((SignalManagementInfo)sender);
// 添加新行到选中行下方
//smInfos.Insert(index + 1, newEntity);
SelectedSmInfo.ChildSignals.Add(newEntity);
//重新排序
int i = 0;
foreach (var item in smInfos)
{
i++;
item.serialNumber = i.ToString();
foreach (var item2 in item.ChildSignals)
{
i++;
item2.serialNumber = i.ToString();
}
}
SelectedSmInfo = newEntity;
}
}
#endregion
#region
if (parameter.Equals("信号转虚拟点"))
{
if (SelectedSmInfo != null)
{
if (SelectedSmInfo.type.Equals("信号"))
{
2025-09-04 18:28:02 +08:00
//信号转虚拟点需要排除自己
var smInfols = new ObservableCollection<SignalManagementInfo>();
foreach (var signal in Allsignals)
{
SignalManagementInfo info = new SignalManagementInfo();
SetEntData(info, signal);
smInfols.Add(info);
}
smInfols.Remove(smInfols.FirstOrDefault(s => s.Wire_Group_ID.Equals(SelectedSmInfo.Wire_Group_ID)));
2025-08-15 15:38:37 +08:00
IDialogParameters para = new DialogParameters();
para.Add(GlobalObject.dialogPar.title.ToString(), "信号选择框");
para.Add(GlobalObject.dialogPar.info.ToString(), "请选择要将这个虚拟点放在哪个信号下");
2025-09-04 18:28:02 +08:00
para.Add(GlobalObject.dialogPar.para1.ToString(), smInfols);
2025-08-15 15:38:37 +08:00
_dialogService.ShowDialog(nameof(DialogSignalSelect), para, (RES) =>
{
2025-09-04 18:28:02 +08:00
if (string.IsNullOrEmpty(SelectedSmInfo.Wire_Group_ID))
{
MessageBox.Show("新增的信号,请先保存在操作!", "KunHengCAD", MessageBoxButton.OK, MessageBoxImage.Warning);
return;
}
2025-08-15 15:38:37 +08:00
if (RES.Result == ButtonResult.Yes)
{
var signal = RES.Parameters.GetValue<Signal>(GlobalObject.dialogPar.para1.ToString());
SelectedSmInfo.ParentID = signal.SignalId;
SelectedSmInfo.type = "虚拟点";
2025-09-04 18:28:02 +08:00
//如果是虚拟点转换的会带_
if (!SelectedSmInfo.Group_Name.Contains("_"))
{
SelectedSmInfo.Group_Name = SelectedSmInfo.Group_Name + (string.IsNullOrEmpty(SelectedSmInfo.Code) ? "" : "_" + SelectedSmInfo.Code);
}
2025-08-15 15:38:37 +08:00
SelectedSmInfo.IsModified = true;
var tempSmInfo = SelectedSmInfo;
smInfos.Remove(SelectedSmInfo);
//var signalindex = smInfos.IndexOf(smInfos.FirstOrDefault(s => s.Wire_Group_ID == signal.SignalId)) + 1;
//smInfos.Insert(signalindex, tempSmInfo);
smInfos.FirstOrDefault(s => s.Wire_Group_ID == signal.SignalId).ChildSignals.Add(tempSmInfo);
var i = 0;
foreach (var item in smInfos)
{
i++;
item.serialNumber = i.ToString();
foreach (var item2 in item.ChildSignals)
{
i++;
item2.serialNumber = i.ToString();
}
}
SelectedSmInfo = tempSmInfo;
}
else if (RES.Result == ButtonResult.No)
{ }
});
}
else if (SelectedSmInfo.type.Equals("虚拟点"))
{
2025-09-04 18:28:02 +08:00
if (string.IsNullOrEmpty(SelectedSmInfo.Wire_Group_ID))
{
MessageBox.Show("新增的虚拟点,请先保存在操作!", "KunHengCAD", MessageBoxButton.OK, MessageBoxImage.Warning);
return;
}
2025-08-15 15:38:37 +08:00
var parentSmif = smInfos.FirstOrDefault(s => s.Wire_Group_ID == SelectedSmInfo.ParentID);
SelectedSmInfo.type = "信号";
SelectedSmInfo.ParentID = "";
//SelectedSmInfo.Code = "";
2025-09-04 18:28:02 +08:00
//SelectedSmInfo.Group_Name = SelectedSmInfo.Group_Name.Split('_')[0];
//SelectedSmInfo.GroupOther = "";
2025-08-15 15:38:37 +08:00
SelectedSmInfo.IsModified = true;
var tempSmInfo = SelectedSmInfo;
parentSmif.ChildSignals.Remove(SelectedSmInfo);
var signalindex = smInfos.IndexOf(parentSmif);
//signalindex = smInfos.IndexOf(smInfos.Skip(signalindex).Where(s => s.type.Equals("信号")).First());
smInfos.Insert(signalindex + 1, tempSmInfo);
var i = 0;
foreach (var item in smInfos)
{
i++;
item.serialNumber = i.ToString();
foreach (var item2 in item.ChildSignals)
{
i++;
item2.serialNumber = i.ToString();
}
}
SelectedSmInfo = tempSmInfo;
}
}
}
#endregion
#region
if (parameter.Equals("删除"))
{
if (SelectedSmInfo != null)
{
2025-09-04 18:28:02 +08:00
if (SelectedSmInfo.Status.Equals("ToDelete"))
{
MessageBox.Show("已是待删除的信号,不能删除!", "KunHengCAD", MessageBoxButton.OK, MessageBoxImage.Warning);
return;
}
2025-08-15 15:38:37 +08:00
//RadWindow.Alert("Start time: " + this.StartTime + "\nEnd time: " + this.EndTime);
2025-09-04 18:28:02 +08:00
MessageBoxResult result;
if (SelectedSmInfo.ChildSignals == null || SelectedSmInfo.ChildSignals.Count == 0)
{
// 显示消息框
result = MessageBox.Show("确定准备删除选择的一行数据", "KunHengCAD", MessageBoxButton.OKCancel, MessageBoxImage.Question);
}
else
{
// 显示消息框
result = MessageBox.Show("确定准备删除信号节点及其子节点", "KunHengCAD", MessageBoxButton.OKCancel, MessageBoxImage.Question);
}
2025-08-15 15:38:37 +08:00
if (result == MessageBoxResult.OK)
{
//id为空表示新增的未保存所以直接删除不为空表示数据库已存在只修改状态
if (string.IsNullOrEmpty(SelectedSmInfo.Wire_Group_ID))
{
2025-09-04 18:28:02 +08:00
if (SelectedSmInfo.type.Equals("信号"))
{
//如过是信号直接在集合中删除
smInfos.Remove(SelectedSmInfo);
}
else if (SelectedSmInfo.type.Equals("虚拟点"))
{
//如果是虚拟点在当前选中的虚拟点的父信号里删除
smInfos.FirstOrDefault(s => !string.IsNullOrEmpty(s.Wire_Group_ID)&& s.Wire_Group_ID.Equals(SelectedSmInfo.ParentID)).ChildSignals.Remove(SelectedSmInfo);
}
//重新排序
int i = 0;
foreach (var item in smInfos)
{
i++;
item.serialNumber = i.ToString();
foreach (var item2 in item.ChildSignals)
{
i++;
item2.serialNumber = i.ToString();
}
}
smInfosView = new QueryableCollectionView(smInfos);
2025-08-15 15:38:37 +08:00
}
else
{
IDialogParameters x = new DialogParameters();
x.Add(GlobalObject.dialogPar.title.ToString(), "提示");
x.Add(GlobalObject.dialogPar.info.ToString(), "请输入删除的原因:");
_dialogService.ShowDialog(nameof(DialogInput), x, (RES) =>
{
if (RES.Result == ButtonResult.Yes)
{
var Reason = RES.Parameters.GetValue<string>(GlobalObject.dialogPar.info.ToString());
if (string.IsNullOrEmpty(Reason))
{
MessageBox.Show("您输入的信息为空!");
}
else
{
List<ActionHistory> histories = new List<ActionHistory>()
{
new ActionHistory()
{
ActionTime= DateTime.Now,
ActionType = SWS.Model.Action.,
reason = Reason
}
};
2025-09-04 18:28:02 +08:00
if (!(SelectedSmInfo.ChildSignals == null || SelectedSmInfo.ChildSignals.Count == 0))
{
foreach (var ChildSignal in SelectedSmInfo.ChildSignals)
{
if (!SelectedSmInfo.Status.Equals("ToDelete"))
{
ChildSignal.ActionHistorys = histories;
ChildSignal.Status = "ToDelete";
ChildSignal.IsModified = true;
if (ChildSignal.type.Equals("虚拟点"))
{
ChildSignal.GroupOther = "";
}
}
}
}
2025-08-15 15:38:37 +08:00
SelectedSmInfo.ActionHistorys = histories;
SelectedSmInfo.Status = "ToDelete";
SelectedSmInfo.IsModified = true;
if (SelectedSmInfo.type.Equals("虚拟点"))
{
SelectedSmInfo.GroupOther = "";
}
2025-09-04 18:28:02 +08:00
2025-08-15 15:38:37 +08:00
}
}
else if (RES.Result == ButtonResult.No)
{ }
});
}
}
}
else
{
// 显示消息框
MessageBox.Show("请选择要准备删除的信号!", "KunHengCAD", MessageBoxButton.OK, MessageBoxImage.Warning);
}
}
#endregion
#region
if (parameter.Equals("撤销删除"))
{
if (SelectedSmInfo != null && SelectedSmInfo.Status == "ToDelete")
{
List<ActionHistory> histories = new List<ActionHistory>()
2025-09-04 18:28:02 +08:00
{
new ActionHistory()
{
ActionTime= DateTime.Now,
ActionType = Model.Action.,
2025-08-15 15:38:37 +08:00
2025-09-04 18:28:02 +08:00
}
};
if (SelectedSmInfo.type.Equals("虚拟点"))
{
var ParentStatus = smInfos.Where(s => !string.IsNullOrEmpty(s.Wire_Group_ID)&& s.Wire_Group_ID.Equals(SelectedSmInfo.ParentID)).Select(s => s.Status).FirstOrDefault();
if (ParentStatus.Equals("ToDelete"))
{
MessageBox.Show("父信号节点还是“待删除”状态,无法撤销删除");
return;
}
}
//if (!(SelectedSmInfo.ChildSignals == null || SelectedSmInfo.ChildSignals.Count == 0))
//{
// foreach (var ChildSignal in SelectedSmInfo.ChildSignals)
// {
// ChildSignal.ActionHistorys = histories;
// ChildSignal.Status = "New";
// ChildSignal.IsModified = true;
// }
//}
2025-08-15 15:38:37 +08:00
SelectedSmInfo.ActionHistorys = histories;
SelectedSmInfo.Status = "New";
SelectedSmInfo.IsModified = true;
}
else
{
MessageBox.Show("只有待删除的信号才能撤销删除");
2025-09-04 18:28:02 +08:00
return;
2025-08-15 15:38:37 +08:00
}
}
#endregion
#region
if (parameter.Equals("彻底删除"))
{
if (SelectedSmInfo != null)
{
2025-09-04 18:28:02 +08:00
List<ec_Wire_Group> Signals = new List<ec_Wire_Group>();
if (!(SelectedSmInfo.ChildSignals == null || SelectedSmInfo.ChildSignals.Count == 0))
2025-08-15 15:38:37 +08:00
{
2025-09-04 18:28:02 +08:00
foreach (var ChildSignal in SelectedSmInfo.ChildSignals)
2025-08-15 15:38:37 +08:00
{
2025-09-04 18:28:02 +08:00
Signals.Add(new ec_Wire_Group()
{
Group_Name = ChildSignal.Group_Name,
Wire_Group_ID = ChildSignal.Wire_Group_ID
});
2025-08-15 15:38:37 +08:00
}
2025-09-04 18:28:02 +08:00
}
Signals.Add(new ec_Wire_Group()
{
Group_Name = SelectedSmInfo.Group_Name,
Wire_Group_ID = SelectedSmInfo.Wire_Group_ID
});
2025-08-15 15:38:37 +08:00
WireGroups ent = new WireGroups();
ent.Signals = Signals;
string message = await _wireGroupService.CanSaveSignals(ent, Model.Action.);
if (message != "OK")
{
// 显示消息框
MessageBox.Show(message, "KunHengCAD", MessageBoxButton.OK, MessageBoxImage.Warning);
return;
}
else
{
List<ActionHistory> histories = new List<ActionHistory>()
2025-09-04 18:28:02 +08:00
{
new ActionHistory()
{
ActionTime= DateTime.Now,
ActionType = Model.Action.,
reason = ""
}
};
if (!(SelectedSmInfo.ChildSignals == null || SelectedSmInfo.ChildSignals.Count == 0))
{
foreach (var ChildSignal in SelectedSmInfo.ChildSignals)
{
ChildSignal.ActionHistorys = histories;
ChildSignal.Status = "deleted";
ChildSignal.DeleteFlg = true;
ChildSignal.IsModified = true;
SignalManagementInfo tempChildsmif = new SignalManagementInfo();
tempChildsmif = ChildSignal;
if (ChildSignal.type.Equals("信号"))
2025-08-15 15:38:37 +08:00
{
2025-09-04 18:28:02 +08:00
smInfos.Remove(ChildSignal);
smInfos.Add(tempChildsmif);
}
else
{
var parentSmif = smInfos.FirstOrDefault(s => s.Wire_Group_ID == SelectedSmInfo.ParentID);
SelectedSmInfo.ChildSignals.Remove(ChildSignal);
smInfos.Add(tempChildsmif);
}
}
2025-08-15 15:38:37 +08:00
2025-09-04 18:28:02 +08:00
}
2025-08-15 15:38:37 +08:00
SelectedSmInfo.ActionHistorys = histories;
SelectedSmInfo.Status = "deleted";
SelectedSmInfo.DeleteFlg = true;
SelectedSmInfo.IsModified = true;
SignalManagementInfo tempsmif = new SignalManagementInfo();
tempsmif = SelectedSmInfo;
if (SelectedSmInfo.type.Equals("信号"))
{
smInfos.Remove(SelectedSmInfo);
smInfos.Add(tempsmif);
}
else
{
var parentSmif = smInfos.FirstOrDefault(s => s.Wire_Group_ID == SelectedSmInfo.ParentID);
parentSmif.ChildSignals.Remove(SelectedSmInfo);
smInfos.Add(tempsmif);
}
}
}
}
#endregion
#region
if (parameter.Equals("还原信号"))
{
if (SelectedSmInfo != null)
{
IDialogParameters x = new DialogParameters();
x.Add(GlobalObject.dialogPar.title.ToString(), "提示");
x.Add(GlobalObject.dialogPar.info.ToString(), "请输入还原信号的原因:");
_dialogService.ShowDialog(nameof(DialogInput), x, (RES) =>
{
if (RES.Result == ButtonResult.Yes)
{
var Reason = RES.Parameters.GetValue<string>(GlobalObject.dialogPar.info.ToString());
if (string.IsNullOrEmpty(Reason))
{
MessageBox.Show("您输入的信息为空!");
}
else
{
List<ActionHistory> histories = new List<ActionHistory>()
{
new ActionHistory()
{
ActionTime= DateTime.Now,
ActionType = Model.Action.,
reason = Reason
}
};
SelectedSmInfo.ActionHistorys = histories;
SelectedSmInfo.Status = "New";
SelectedSmInfo.DeleteFlg = false;
SelectedSmInfo.IsModified = true;
SignalManagementInfo tempsmif = new SignalManagementInfo();
tempsmif = SelectedSmInfo;
2025-09-04 18:28:02 +08:00
//if (SelectedSmInfo.type.Equals("信号"))
//{
// smInfos.Remove(SelectedSmInfo);
// smInfos.Add(tempsmif);
//}
//else
//{
// var parentSmif = smInfos.FirstOrDefault(s => s.Wire_Group_ID == SelectedSmInfo.ParentID);
// parentSmif.ChildSignals.Remove(SelectedSmInfo);
// smInfos.Add(tempsmif);
//}
smInfos.Remove(SelectedSmInfo);
smInfos.Add(tempsmif);
2025-08-15 15:38:37 +08:00
}
}
else if (RES.Result == ButtonResult.No)
{ }
});
}
}
#endregion
#region
if (parameter.Equals("审核"))
{
if (SelectedSmInfo != null)
{
List<ec_Wire_Group> Signals = new List<ec_Wire_Group>()
{
new ec_Wire_Group()
{
Group_Name = SelectedSmInfo.Group_Name,
Wire_Group_ID = SelectedSmInfo.Wire_Group_ID
}
};
WireGroups ent = new WireGroups();
ent.Signals = Signals;
string message = await _wireGroupService.CanSaveSignals(ent, Model.Action.);
if (message != "OK")
{
// 显示消息框
MessageBox.Show(message, "KunHengCAD", MessageBoxButton.OK, MessageBoxImage.Warning);
return;
}
else
{
List<ActionHistory> histories = new List<ActionHistory>()
{
new ActionHistory()
{
ActionTime= DateTime.Now,
ActionType = Model.Action.,
reason = ""
}
};
SelectedSmInfo.ActionHistorys = histories;
SelectedSmInfo.Status = "Confirmed";
SelectedSmInfo.IsModified = true;
}
}
}
#endregion
#region
if (parameter.Equals("重新打开"))
{
if (SelectedSmInfo != null)
{
var messageBoxResult = MessageBox.Show("确定重新打开选中的一行数据?", "KunHengCAD", MessageBoxButton.OKCancel, MessageBoxImage.Question);
if (messageBoxResult == MessageBoxResult.OK)
{
if (SelectedSmInfo.Status == "Confirmed")
{
IDialogParameters x = new DialogParameters();
x.Add(GlobalObject.dialogPar.title.ToString(), "提示");
x.Add(GlobalObject.dialogPar.info.ToString(), "请输入重新打开改信号的原因:");
_dialogService.ShowDialog(nameof(DialogInput), x, (RES) =>
{
if (RES.Result == ButtonResult.Yes)
{
var Reason = RES.Parameters.GetValue<string>(GlobalObject.dialogPar.info.ToString());
if (string.IsNullOrEmpty(Reason))
{
MessageBox.Show("输入的信息不能为空!");
}
else
{
List<ActionHistory> histories = new List<ActionHistory>()
{
new ActionHistory()
{
ActionTime= DateTime.Now,
ActionType = Model.Action.,
reason = Reason
}
};
SelectedSmInfo.ActionHistorys = histories;
SelectedSmInfo.Status = "Reopen";
SelectedSmInfo.IsModified = true;
}
}
else if (RES.Result == ButtonResult.No)
{ }
});
}
else
{
// 显示消息框
MessageBox.Show("只有已审核的信号才能重新打开", "KunHengCAD", MessageBoxButton.OK, MessageBoxImage.Warning);
return;
}
}
else
{
return;
}
}
}
#endregion
#region
if (parameter.Equals("关联通道"))
{
if (SelectedSmInfo == null)
{
System.Windows.MessageBox.Show("您未选择关联信号", "KunHengCAD", MessageBoxButton.OK, MessageBoxImage.Warning); return;
}
else
{
if (!SelectedSmInfo.Status.Equals("New") || SelectedSmInfo.Status.Equals("Reopen"))
{
System.Windows.MessageBox.Show("只有新增或重新打开的信号才能关联,请重新选择!", "KunHengCAD", MessageBoxButton.OK, MessageBoxImage.Warning); return;
}
else
{
if (IsAssociated != null)
{
MessageBoxResult result = System.Windows.MessageBox.Show("已关联的信号:" + IsAssociated.Group_Name + "是否确认被覆盖?", "KunHengCAD", MessageBoxButton.OKCancel, MessageBoxImage.Warning);
if (result == MessageBoxResult.OK)
{
List<ec_Wire_Group> WireGroups = new List<ec_Wire_Group>();
WireGroups.Add(SelectedSmInfo.to_ec_Wire_Group(signals));
IDialogParameters para = new DialogParameters();
para.Add(GlobalObject.dialogPar.para1.ToString(), WireGroups);
DialogResult res = new DialogResult(ButtonResult.Yes);
RequestClose.Invoke(res);
this.Dispose();
}
else
{
return;
}
}
}
}
}
#endregion
#region 线
if (parameter.Equals("关联母线"))
{
if (SelectedSmInfo == null)
{
System.Windows.MessageBox.Show("您未选择关联信号", "KunHengCAD", MessageBoxButton.OK, MessageBoxImage.Warning); return;
}
else
{
if (!SelectedSmInfo.CommunicationPoint)
{
System.Windows.MessageBox.Show("只有通讯信号才能关联,请重新选择!", "KunHengCAD", MessageBoxButton.OK, MessageBoxImage.Warning); return;
}
else
{
List<SignalManagementInfo> WireGroupIds = new List<SignalManagementInfo>();
WireGroupIds.Add(SelectedSmInfo);
IDialogParameters para = new DialogParameters();
para.Add(GlobalObject.dialogPar.para1.ToString(), WireGroupIds);
DialogResult res = new DialogResult(ButtonResult.Yes);
RequestClose.Invoke(res);
this.Dispose();
}
}
}
#endregion
#region
if (parameter.Equals("关联信号"))
{
2025-09-04 18:28:02 +08:00
//只传入非output信号和未被关联信号
var smInfols = new ObservableCollection<SignalManagementInfo>();
var tempAllsignals = Allsignals.Where(s => !s.InOrOut.Equals("output")).ToList();
foreach (var signal in tempAllsignals)
{
SignalManagementInfo info = new SignalManagementInfo();
SetEntData(info, signal);
smInfols.Add(info);
}
//查找被关联信号
var associatedId = Allsignals.Where(s => s.InOrOut.Equals("output") && !string.IsNullOrEmpty(s.LinkedID)).Select(s => s.LinkedID);
var ids = new List<string>();
if (associatedId != null)
{
foreach (var item in associatedId)
{
ids = item.Split(',').ToList();
foreach (var id in ids)
{
smInfols = new ObservableCollection<SignalManagementInfo>(smInfols.Where(s => !s.Wire_Group_ID.Equals(id)));
}
}
}
//修改完的还会保存,需要处理当前显示的表格数据
//查询修改后的output信号
var updateOutputSignal = smInfos.Where(s =>!string.IsNullOrEmpty(s.InOrOut) && s.InOrOut.Equals("output") && !string.IsNullOrEmpty(s.LinkedID)).ToList();
foreach (var Signal in updateOutputSignal)
{
//查询原始关联信号
var originalOutputSignal = Allsignals.FirstOrDefault(a => a.Wire_Group_ID.Equals(Signal.Wire_Group_ID) && !string.IsNullOrEmpty(a.LinkedID));
var originalIds = new List<string>();
if (originalOutputSignal != null)
{
originalIds = originalOutputSignal.LinkedID.Split(',').ToList();
}
var updateIds = Signal.LinkedID.Split(',').ToList();
//列表要去掉的id
var deleIds = originalIds.Except(updateIds);
foreach (var id in deleIds)
{
SignalManagementInfo info = new SignalManagementInfo();
SetEntData(info, Allsignals.FirstOrDefault(a => a.Wire_Group_ID.Equals(id)));
smInfols.Add(info);
}
var addIds = updateIds.Except(originalIds);
foreach (var id in addIds)
{
smInfols.Remove(smInfols.FirstOrDefault(a => a.Wire_Group_ID.Equals(id)));
}
}
2025-08-15 15:38:37 +08:00
IDialogParameters para = new DialogParameters();
para.Add(GlobalObject.dialogPar.title.ToString(), "信号选择框");
para.Add(GlobalObject.dialogPar.info.ToString(), "请选择要关联的信号:");
2025-09-04 18:28:02 +08:00
para.Add(GlobalObject.dialogPar.para1.ToString(), smInfols);
2025-09-15 18:35:41 +08:00
_dialogService.ShowDialog(nameof(DialogAssociatedSignal), para, (RES) =>
2025-08-15 15:38:37 +08:00
{
if (RES.Result == ButtonResult.Yes)
{
2025-09-15 18:35:41 +08:00
var signal = RES.Parameters.GetValue<SignalManagementInfo>(GlobalObject.dialogPar.para1.ToString());
2025-09-04 18:28:02 +08:00
if (!string.IsNullOrEmpty(SelectedSmInfo.LinkedID))
2025-08-15 15:38:37 +08:00
{
2025-09-04 18:28:02 +08:00
var LinkedIDs = SelectedSmInfo.LinkedID.Split(',').ToList();
LinkedIDs.RemoveAll(item => string.IsNullOrEmpty(item));
2025-09-15 18:35:41 +08:00
if (!LinkedIDs.Contains(signal.Wire_Group_ID))
2025-09-04 18:28:02 +08:00
{
2025-09-15 18:35:41 +08:00
LinkedIDs.Add(signal.Wire_Group_ID);
2025-09-04 18:28:02 +08:00
}
SelectedSmInfo.LinkedID = string.Join(",", LinkedIDs);
}
else
{
2025-09-15 18:35:41 +08:00
SelectedSmInfo.LinkedID = signal.Wire_Group_ID;
2025-08-15 15:38:37 +08:00
}
SelectedSmInfo.IsModified = true;
2025-09-04 18:28:02 +08:00
System.Windows.MessageBox.Show("关联成功", "KunHengCAD", MessageBoxButton.OK, MessageBoxImage.Warning);
2025-08-15 15:38:37 +08:00
}
else if (RES.Result == ButtonResult.No)
{ }
});
return;
}
#endregion
#region
if (parameter.Equals("查关联信号"))
{
//传入窗口的参数
ObservableCollection<SignalManagementInfo> sminfols = new ObservableCollection<SignalManagementInfo>();
var LinkedIDs = SelectedSmInfo.LinkedID.Split(',').ToList();
2025-09-04 18:28:02 +08:00
foreach (var signal in Allsignals)
2025-08-15 15:38:37 +08:00
{
2025-09-04 18:28:02 +08:00
if (LinkedIDs.Contains(signal.Wire_Group_ID))
2025-08-15 15:38:37 +08:00
{
2025-09-04 18:28:02 +08:00
SignalManagementInfo info = new SignalManagementInfo();
SetEntData(info, signal);
sminfols.Add(info);
2025-08-15 15:38:37 +08:00
}
}
//打开窗口
IDialogParameters para = new DialogParameters();
para.Add(GlobalObject.dialogPar.title.ToString(), "信号关联列表");
para.Add(GlobalObject.dialogPar.info.ToString(), "下面是信号关联列表");
para.Add(GlobalObject.dialogPar.para1.ToString(), sminfols);
2025-09-15 18:35:41 +08:00
_dialogService.ShowDialog(nameof(DialogAssociatedSignal), para, (RES) =>
2025-08-15 15:38:37 +08:00
{
if (RES.Result == ButtonResult.Yes)
{
2025-09-15 18:35:41 +08:00
var signals = RES.Parameters.GetValue<List<SignalManagementInfo>>(GlobalObject.dialogPar.para2.ToString());
2025-09-04 18:28:02 +08:00
signals.ForEach(s =>
{
2025-09-15 18:35:41 +08:00
var signalid = s.Wire_Group_ID;
2025-09-04 18:28:02 +08:00
if (LinkedIDs.Contains(signalid))
{
LinkedIDs.Remove(signalid);
}
});
SelectedSmInfo.LinkedID = string.Join(",", LinkedIDs);
SelectedSmInfo.IsModified = true;
}
else if (RES.Result == ButtonResult.No)
{ }
});
return;
}
#endregion
#region
if (parameter.Equals("输出点落实情况"))
{
//打开窗口
IDialogParameters para = new DialogParameters();
//para.Add(GlobalObject.dialogPar.title.ToString(), "信号关联列表");
_dialogService.ShowDialog(nameof(DialogAllOutputSignal), para, (RES) =>
{
2025-08-15 15:38:37 +08:00
2025-09-04 18:28:02 +08:00
if (RES.Result == ButtonResult.Yes)
{
2025-08-15 15:38:37 +08:00
}
else if (RES.Result == ButtonResult.No)
{ }
});
return;
}
#endregion
2025-09-04 18:28:02 +08:00
#region
if (parameter.Equals("导出"))
2025-08-15 15:38:37 +08:00
{
2025-09-04 18:28:02 +08:00
System.Windows.Forms.SaveFileDialog saveFileDialog = new System.Windows.Forms.SaveFileDialog();
saveFileDialog.Filter = "Excel文件 (*.xlsx)|*.xlsx|所有文件 (*.*)|*.*";
saveFileDialog.Title = "选择保存路径";
2025-08-15 15:38:37 +08:00
2025-09-04 18:28:02 +08:00
if (saveFileDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
2025-08-15 15:38:37 +08:00
{
2025-09-04 18:28:02 +08:00
string selectedPath = saveFileDialog.FileName;
if (System.IO.File.Exists(selectedPath))
{ System.IO.File.Delete(selectedPath); }
2025-08-15 15:38:37 +08:00
2025-09-04 18:28:02 +08:00
var msg = await _wireGroupService.Exportchanges(selectedPath, (DateTime)statDate, (DateTime)endDate);
if (string.IsNullOrEmpty(msg))
{
MessageBox.Show("下载文件成功!");
}
else { MessageBox.Show("下载文件异常:" + msg); }
2025-08-15 15:38:37 +08:00
}
}
#endregion
}
public ICommand HeadButtonCmd => new DelegateCommand(HeadButton_Click);
/// <summary>
2025-09-04 18:28:02 +08:00
/// 页面顶部按钮
2025-08-15 15:38:37 +08:00
/// </summary>
/// <param name="parameter"></param>
public virtual async void HeadButton_Click(object parameter)
{
#region
if (parameter.Equals("保存"))
{
//新增或者修改的集合
List<SignalManagementInfo> updatals = new List<SignalManagementInfo>();
foreach (var item in smInfos)
{
if (item.IsModified)
{
updatals.Add(item);
}
foreach (var item2 in item.ChildSignals)
{
if (item2.IsModified)
{
updatals.Add(item2);
}
}
}
2025-09-04 18:28:02 +08:00
if (updatals.Count == 0) return;
2025-08-15 15:38:37 +08:00
//updatals = smInfos.Where(s => s.IsModified == true).ToList();
foreach (var item in updatals)
{
//保存的为信号时才判断组别
if (item.type == "信号")
{
if (string.IsNullOrEmpty(item.GroupOther))
{
// 显示消息框
2025-09-04 18:28:02 +08:00
MessageBox.Show($"第{item.serialNumber}行组别不能为空", "KunHengCAD", MessageBoxButton.OK, MessageBoxImage.Warning);
2025-08-15 15:38:37 +08:00
return;
}
}
else if (item.type == "虚拟点")
{
if (string.IsNullOrEmpty(item.Code))
{
2025-09-04 18:28:02 +08:00
MessageBox.Show($"第{item.serialNumber}行Code列不能为空", "KunHengCAD", MessageBoxButton.OK, MessageBoxImage.Warning);
return;
}
//需要判断不同名的虚拟点
var ParentSignal = smInfos.FirstOrDefault(s =>!string.IsNullOrEmpty(s.Wire_Group_ID)&& s.Wire_Group_ID.Equals(item.ParentID));
var chnols= ParentSignal.ChildSignals.Where(c=>c.Group_Name.Equals(item.Group_Name)).ToList();
if (chnols!=null&& chnols.Count()>1)
{
MessageBox.Show($"第{item.serialNumber}行CH.NO列已存在", "KunHengCAD", MessageBoxButton.OK, MessageBoxImage.Warning);
2025-08-15 15:38:37 +08:00
return;
}
}
Ent.Signals.Add(item.to_ec_Wire_Group(signals));
}
//保存
2025-09-04 18:28:02 +08:00
var Res_SaveSignals = await _wireGroupService.SaveSignals(Ent) as learunHttpRes<List<ec_Wire_Group>>;
if (Res_SaveSignals.code == 200)
2025-08-15 15:38:37 +08:00
{
2025-09-04 18:28:02 +08:00
//smInfos = new ObservableCollection<SignalManagementInfo>();
IsBusy = true; BusyContent = "保存中...";
//signals = await _wireGroupService.GetSignals(GlobalObject.curProject.ProjectId, false);
//Allsignals = new List<ec_Wire_Group>(signals);
//IsBusy = false;
//count = signals.Count.ToString();
//if (ButtonContent.Equals("回收站"))
2025-08-15 15:38:37 +08:00
//{
2025-09-04 18:28:02 +08:00
// signals = signals.Where(s => s.Status != WireGroupStatusEnum.deleted).ToList();
// SetBaseData(signals);
2025-08-15 15:38:37 +08:00
//}
2025-09-04 18:28:02 +08:00
//else
//{
// signals = signals.Where(s => s.Status == WireGroupStatusEnum.deleted).ToList();
// SetBaseData(signals, 1);
//}
//count = signals.Count.ToString() + "/" + count;
var resSinals = Res_SaveSignals.data;
foreach (var Sinal in resSinals)
2025-08-15 15:38:37 +08:00
{
2025-09-04 18:28:02 +08:00
if (string.IsNullOrEmpty(Sinal.ParentID))
{
var sminfo= smInfos.FirstOrDefault(s =>!string.IsNullOrEmpty(s.Wire_Group_ID)&& s.Wire_Group_ID.Equals(Sinal.Wire_Group_ID));
//为空表示当前是新增的
if (sminfo == null)
{
sminfo = smInfos.FirstOrDefault(s => s.Group_Name.Equals(Sinal.Group_Name));
signals.Add(Sinal);
Allsignals.Add(Sinal);
}
SignalManagementInfo info = new SignalManagementInfo();
info.serialNumber = sminfo.serialNumber;
SetEntData(info, Sinal);
int indexof = smInfos.IndexOf(sminfo);
smInfos.Remove(sminfo);
smInfos.Insert(indexof,info);
}
else
{
var Parentsminfo = smInfos.FirstOrDefault(s => !string.IsNullOrEmpty(s.Wire_Group_ID) && s.Wire_Group_ID.Equals(Sinal.ParentID));
var sminfo = Parentsminfo.ChildSignals.FirstOrDefault(s => !string.IsNullOrEmpty(s.Wire_Group_ID) && s.Wire_Group_ID.Equals(Sinal.Wire_Group_ID));
if (sminfo == null)
{
sminfo = Parentsminfo.ChildSignals.FirstOrDefault(s => s.Group_Name.Equals(Sinal.Group_Name));
signals.Add(Sinal);
Allsignals.Add(Sinal);
2025-08-15 15:38:37 +08:00
2025-09-04 18:28:02 +08:00
}
SignalManagementInfo info = new SignalManagementInfo();
info.serialNumber = sminfo.serialNumber;
SetEntData(info, Sinal);
int indexof = Parentsminfo.ChildSignals.IndexOf(sminfo);
Parentsminfo.ChildSignals.Remove(sminfo);
Parentsminfo.ChildSignals.Insert(indexof, info);
}
}
//count = smInfos.Count() + "/" + signals.Count().ToString();
2025-08-15 15:38:37 +08:00
Ent.Signals.Clear();
2025-09-04 18:28:02 +08:00
IsBusy = false;
2025-08-15 15:38:37 +08:00
// 显示消息框
MessageBox.Show("保存成功", "KunHengCAD", MessageBoxButton.OK, MessageBoxImage.Information);
}
else
{
Ent.Signals.Clear();
2025-09-04 18:28:02 +08:00
MessageBox.Show($"{Res_SaveSignals.info}", "KunHengCAD", MessageBoxButton.OK, MessageBoxImage.Error);
2025-08-15 15:38:37 +08:00
}
return;
}
#endregion
2025-09-04 18:28:02 +08:00
#region
if (parameter.Equals("导出全部记录"))
2025-08-15 15:38:37 +08:00
{
2025-09-04 18:28:02 +08:00
PopupButton_IsOpen = true;
return;
2025-08-15 15:38:37 +08:00
}
#endregion
#region
if (parameter.Equals("通知信息"))
{
//RadWindow window = new RadWindow();
//window.Content = new DialogSignalNotice();
//window.WindowStartupLocation = WindowStartupLocation.CenterOwner;
//window.Header = "通知消息";
////window.CanClose = false;
//window.Show();
//打开窗体
IDialogParameters para = new DialogParameters();
_dialogService.ShowDialog(nameof(DialogSignalNotice), para, (RES) =>
{
if (RES.Result == ButtonResult.Yes)
{
}
else if (RES.Result == ButtonResult.No)
{ }
});
}
#endregion
#region
if (parameter.Equals("历史记录"))
{
if (SelectedSmInfo != null)
{
//打开窗体
IDialogParameters para = new DialogParameters();
para.Add(GlobalObject.dialogPar.para1.ToString(), SelectedSmInfo);
_dialogService.ShowDialog(nameof(DialogSignalPropertyhisAndLogs), para, (RES) =>
{
});
}
}
#endregion
#region
if (parameter.Equals("回收站"))
{
switch (ButtonContent)
{
case "回收站":
ButtonContent = "显示全部";
break;
case "显示全部":
ButtonContent = "回收站";
break;
}
smInfos = new ObservableCollection<SignalManagementInfo>();
IsBusy = true; BusyContent = "查询中...";
signals = await _wireGroupService.GetSignals(GlobalObject.curProject.ProjectId, false);
IsBusy = false;
count = signals.Count.ToString();
if (ButtonContent.Equals("回收站"))
{
signals = signals.Where(s => s.Status != WireGroupStatusEnum.deleted).ToList();
2025-09-04 18:28:02 +08:00
SetBaseData(signals);
2025-08-15 15:38:37 +08:00
}
else
{
signals = signals.Where(s => s.Status == WireGroupStatusEnum.deleted).ToList();
2025-09-04 18:28:02 +08:00
SetBaseData(signals, 1);
2025-08-15 15:38:37 +08:00
}
2025-09-04 18:28:02 +08:00
2025-08-15 15:38:37 +08:00
count = smInfos.Count.ToString() + "/" + count;
}
#endregion
#region
if (parameter.Equals("搜索框"))
{
PerformSearch();
}
#endregion
}
public ICommand EditEndCmd => new DelegateCommand(EditEnd);
/// <summary>
/// 编辑结束事件
/// </summary>
/// <param name="parameter"></param>
public virtual void EditEnd(object parameter)
{
//做个标记表示该项修改过
SelectedSmInfo.IsModified = true;
}
#endregion
#region
/// <summary>
/// 设置数据
2025-09-04 18:28:02 +08:00
/// 0是初始化数据(层次化数据)1是查询数据信号虚拟点都在一个层级
2025-08-15 15:38:37 +08:00
/// </summary>
2025-09-04 18:28:02 +08:00
public void SetBaseData(List<ec_Wire_Group> signals, int model = 0)
2025-08-15 15:38:37 +08:00
{
int index = 0;
foreach (var signal in signals)
{
2025-09-04 18:28:02 +08:00
if (model == 0)
2025-08-15 15:38:37 +08:00
{
2025-09-04 18:28:02 +08:00
if (string.IsNullOrEmpty(signal.ParentID))
2025-08-15 15:38:37 +08:00
{
2025-09-04 18:28:02 +08:00
index++;
SignalManagementInfo info = new SignalManagementInfo();
info.serialNumber = index.ToString();
SetEntData(info, signal);
smInfos.Add(info);
foreach (var signal2 in signals)
2025-08-15 15:38:37 +08:00
{
2025-09-04 18:28:02 +08:00
if (signal.Wire_Group_ID.Equals(signal2.ParentID))
2025-08-15 15:38:37 +08:00
{
2025-09-04 18:28:02 +08:00
index++;
SignalManagementInfo info2 = new SignalManagementInfo();
info2.serialNumber = index.ToString();
SetEntData(info2, signal2);
info.ChildSignals.Add(info2);
info.ChildSignalsView = new QueryableCollectionView(info.ChildSignals);
info.IsExpandable = true;
2025-08-15 15:38:37 +08:00
}
}
}
}
2025-09-04 18:28:02 +08:00
else
{
index++;
SignalManagementInfo info = new SignalManagementInfo();
info.serialNumber = index.ToString();
SetEntData(info, signal);
smInfos.Add(info);
}
}
smInfosView = new QueryableCollectionView(smInfos);
}
/// <summary>
/// 设置数据
/// </summary>
public void SetEntData(SignalManagementInfo info, ec_Wire_Group signal)
{
info.Wire_Group_ID = signal.Wire_Group_ID;
info.ParentID = signal.ParentID;
info.LinkedID = signal.LinkedID;
info.Status = signal.Status.ToString();
info.type = string.IsNullOrEmpty(signal.ParentID) ? "信号" : "虚拟点";
info.Group_Name = signal.Group_Name;
info.Group_Desc_EN = signal.Group_Desc_EN;
info.Group_Desc = signal.Group_Desc;
info.BelongingMajor = signal.ElecOnly ? "E" : "M";
info.GroupOthers = GroupOthers;
if (string.IsNullOrEmpty(GroupOthers.Where(g => g.DataItemCode == signal.Signal_Group).Select(g => g.DataItemName).FirstOrDefault()))
{
info.GroupOther = "";
}
else
{
info.GroupOther = GroupOthers.Where(g => g.DataItemCode == signal.Signal_Group).Select(g => g.DataItemName).FirstOrDefault() + "|" + GroupOthers.Where(g => g.DataItemCode == signal.Signal_Group).Select(g => g.DataItemCode).FirstOrDefault();
}
info.Signal_SeqNo = signal.Signal_SeqNo;
info.Code = signal.Code;
info.InOrOut = signal.InOrOut;
info.IO_Type = signal.IO_Type;
info.Range_Min = signal.Range_Min;
info.Range_Max = signal.Range_Max;
info.Unit = signal.Unit;
info.Alarm_LL = signal.Alarm_LL;
info.Alarm_L = signal.Alarm_L;
info.Alarm_H = signal.Alarm_H;
info.Alarm_HH = signal.Alarm_HH;
info.SENSOR_CODE = signal.SENSOR_CODE;
info.CommunicationPoint = signal.CommunicationPoint;
info.SeriousType = signal.SeriousType;
info.AL_GRP = signal.AL_GRP;
info.BL_GRP = signal.BL_GRP;
info.Time_Delay = signal.Time_Delay;
info.Suppliers = Suppliers;
info.Supplier = Suppliers.Where(g => g.DataItemCode == signal.Supplier).Select(g => g.DataItemName).FirstOrDefault();
info.EquipName = signal.EquipName;
info.VDR_Record = signal.VDR_Record;
info.WHConsole = signal.WHConsole;
//info.WHCPU = signal.WHCPU;
foreach (var item in signal.WHCPU.Split('|'))
{
info.WHCPUs.Add(WHCPUs.Where(e => e.DataItemCode.Equals(item.Trim())).FirstOrDefault());
}
info.ECRConsole = signal.ECRConsole;
//info.ECRCPU = signal.ECRCPU;
foreach (var item in signal.ECRCPU.Split('|'))
{
info.ECRCPUs.Add(ECRCPUs.Where(e => e.DataItemCode.Equals(item.Trim())).FirstOrDefault());
}
info.ShipOfficeConsole = signal.ShipOfficeConsole;
//info.ShipOfficeCPU = signal.ShipOfficeCPU;
foreach (var item in signal.ShipOfficeCPU.Split('|'))
{
info.ShipOfficeCPUs.Add(ShipOfficeCPUs.Where(e => e.DataItemCode.Equals(item.Trim())).FirstOrDefault());
2025-08-15 15:38:37 +08:00
}
2025-09-04 18:28:02 +08:00
info.SLD = signal.SLD;
info.SHD = signal.SHD;
info.SafetyDelay = signal.SafetyDelay;
info.AutoCtrl = signal.AutoCtrl;
info.AssociatedCableInfo = (string.IsNullOrEmpty(signal.CableName) ? "" : "电缆位号:" + signal.CableName) + (string.IsNullOrEmpty(signal.CableSetName) ? "" : " 电缆对:" + signal.CableSetName);
info.AssociatedChannelInfo = (string.IsNullOrEmpty(signal.PanelName) ? "" : "采集箱:" + signal.PanelName) + (string.IsNullOrEmpty(signal.StripName) ? "" : "端子排:" + signal.StripName) + (string.IsNullOrEmpty(signal.ChannelName) ? "" : " 通道:" + signal.ChannelName);
info.Remarks = signal.Remarks;
info.DeleteFlg = signal.DeleteFlg;
//订阅事件以更新数据。
info.ParametersChanged += (sender, e) => UpdateParametersValue((SignalManagementInfo)sender);
2025-08-15 15:38:37 +08:00
}
/// <summary>
/// 选择组别改变时修改Group_Name和Code()
/// </summary>
/// <param name="item"></param>
private async void UpdateParametersValue(SignalManagementInfo item)
{
if (item.type == "信号")
{
//获取当前组别的可用编码
2025-09-04 18:28:02 +08:00
if (item.tempGroupOther != null)
2025-08-15 15:38:37 +08:00
{
2025-09-04 18:28:02 +08:00
string group = item.tempGroupOther.DataItemCode;
if (string.IsNullOrEmpty(item.Signal_SeqNo))//编码列为空时才通过接口获取可用编码
2025-08-15 15:38:37 +08:00
{
2025-09-04 18:28:02 +08:00
var seq = await _wireGroupService.GetNextAvailableSeq(group);
int index = seq.Length;
int count = smInfos.Where(s => s.IsModified == true && string.IsNullOrEmpty(s.Wire_Group_ID) && !string.IsNullOrEmpty(s.GroupOther)).ToList().Count;
if (count > 1)
{
seq = (double.Parse(seq) + count - 1).ToString();
index = index - seq.Length;
for (int i = 0; i < index; i++)
{
seq = "0" + seq;
}
}
item.Signal_SeqNo = seq.ToString();
2025-08-15 15:38:37 +08:00
}
2025-09-04 18:28:02 +08:00
item.Group_Name = group + item.Signal_SeqNo;
2025-08-15 15:38:37 +08:00
}
2025-09-04 18:28:02 +08:00
2025-08-15 15:38:37 +08:00
}
else if (item.type == "虚拟点")
{
if (string.IsNullOrEmpty(item.Group_Name))
{
string Group_Name = smInfos.Where(e => e.Wire_Group_ID == item.ParentID).Select(e => e.Group_Name).FirstOrDefault();
item.Group_Name = Group_Name + "_" + item.Code;
}
else
{
item.Group_Name = item.Group_Name.Split('_')[0] + "_" + item.Code;
}
}
}
/// <summary>
/// 搜索方法
/// </summary>
private void PerformSearch()
{
2025-09-04 18:28:02 +08:00
smInfosView.FilterDescriptors.Clear();
2025-08-15 15:38:37 +08:00
if (!string.IsNullOrEmpty(SearchText))
{
var compositeFilter = new CompositeFilterDescriptor
{
LogicalOperator = FilterCompositionLogicalOperator.Or
};
foreach (var prop in typeof(SignalManagementInfo).GetProperties())
{
if (prop.PropertyType == typeof(string))
{
compositeFilter.FilterDescriptors.Add(new FilterDescriptor
{
Member = prop.Name,
Operator = FilterOperator.Contains,
Value = SearchText.ToLower(),
IsCaseSensitive = false
});
}
}
2025-09-04 18:28:02 +08:00
smInfosView.FilterDescriptors.Add(compositeFilter);
2025-08-15 15:38:37 +08:00
}
}
2025-09-04 18:28:02 +08:00
#region
/// <summary>
/// 定时器绑定方法
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void OnTimerElapsed(object sender, EventArgs e)
{
UpdateCountdown(ReviewCountdown);
UpdateCountdown(ConstructionCountdown);
}
private void UpdateCountdown(CountdownModel model)
{
if (model.IsActive)
{
model.TimeRemaining -= TimeSpan.FromSeconds(1);
}
}
#endregion
2025-08-15 15:38:37 +08:00
#endregion
}
2025-09-04 18:28:02 +08:00
public class CountdownModel:ViewModelBase
{
private TimeSpan _TimeRemaining;
public TimeSpan TimeRemaining
{
get { return _TimeRemaining; }
set { _TimeRemaining = value;
RaisePropertyChanged(nameof(TimeRemaining));
}
}
private bool _IsActive;
2025-08-15 15:38:37 +08:00
2025-09-04 18:28:02 +08:00
public bool IsActive
{
get { return _IsActive; }
set { _IsActive = value;
RaisePropertyChanged(nameof(IsActive));
}
}
}
2025-08-15 15:38:37 +08:00
}