2008 lines
82 KiB
C#
2008 lines
82 KiB
C#
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;
|
||
using System.Timers;
|
||
using System.Windows.Threading;
|
||
|
||
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));
|
||
}
|
||
}
|
||
|
||
private QueryableCollectionView _smInfosView;
|
||
/// <summary>
|
||
/// 可筛选的的集合视图
|
||
/// </summary>
|
||
public QueryableCollectionView smInfosView
|
||
{
|
||
get { return _smInfosView; }
|
||
set { _smInfosView = value; RaisePropertyChanged(nameof(smInfosView)); }
|
||
}
|
||
|
||
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));
|
||
}
|
||
}
|
||
|
||
private string[] _buttonTexts = { "全部", "输出信号", "非输出信号" };
|
||
|
||
private string _buttonText = "全部";
|
||
/// <summary>
|
||
/// 切换信号按钮的文本
|
||
/// </summary>
|
||
public string buttonText
|
||
{
|
||
get { return _buttonText; }
|
||
set
|
||
{
|
||
_buttonText = value;
|
||
RaisePropertyChanged(nameof(buttonText));
|
||
}
|
||
}
|
||
|
||
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));
|
||
}
|
||
}
|
||
|
||
|
||
#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
|
||
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));
|
||
}
|
||
}
|
||
|
||
private DateTime? _ReviewTime;
|
||
/// <summary>
|
||
/// 送审时间
|
||
/// </summary>
|
||
public DateTime? ReviewTime
|
||
{
|
||
get { return _ReviewTime; }
|
||
set { _ReviewTime = value;
|
||
RaisePropertyChanged(nameof(ReviewTime));
|
||
}
|
||
}
|
||
|
||
private DateTime? _ConstructionTime;
|
||
/// <summary>
|
||
/// 施工时间
|
||
/// </summary>
|
||
public DateTime? ConstructionTime
|
||
{
|
||
get { return _ConstructionTime; }
|
||
set { _ConstructionTime = value;
|
||
RaisePropertyChanged(nameof(ConstructionTime));
|
||
}
|
||
}
|
||
|
||
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));
|
||
}
|
||
}
|
||
|
||
private readonly DispatcherTimer _timer = new DispatcherTimer();
|
||
|
||
public ICommand StartReviewCommand { get; set; }
|
||
public ICommand StartConstructionCommand { get;set; }
|
||
#endregion
|
||
|
||
private readonly IDialogService _dialogService;
|
||
private DataItemService _dataItemService;
|
||
public DialogSignalManagementViewModel()
|
||
{
|
||
title = "信号管理";
|
||
_dialogService = GlobalObject._prismContainer.Resolve<IDialogService>();
|
||
_wireGroupService = GlobalObject.container.Resolve<WireGroupService>();
|
||
_dataItemService = GlobalObject.container.Resolve<DataItemService>();
|
||
}
|
||
|
||
public string Title => "";
|
||
|
||
public event Action<IDialogResult> RequestClose;
|
||
|
||
public bool CanCloseDialog()
|
||
{
|
||
return true;
|
||
}
|
||
|
||
public void OnDialogClosed()
|
||
{
|
||
|
||
}
|
||
|
||
private List<ec_Wire_Group> signals = new List<ec_Wire_Group>();
|
||
private List<ec_Wire_Group> Allsignals = new List<ec_Wire_Group>();
|
||
public async void OnDialogOpened(IDialogParameters parameters)
|
||
{
|
||
|
||
try
|
||
{
|
||
IsBusy = true; BusyContent = "加载中...";
|
||
|
||
//设置组别下拉列表
|
||
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;
|
||
//设置信号源
|
||
signals = await _wireGroupService.GetSignals(GlobalObject.curProject.ProjectId, false);
|
||
if (signals == null)
|
||
{
|
||
signals = new List<ec_Wire_Group>();
|
||
}
|
||
//TimeSpan duration = DateTime.Now - startTime;
|
||
//System.Windows.MessageBox.Show($"Time taken: {duration.Seconds} milliseconds");
|
||
count = signals.Count().ToString();
|
||
signals = signals.Where(s => s.Status != WireGroupStatusEnum.deleted).ToList();
|
||
Allsignals = new List<ec_Wire_Group>(signals);
|
||
SetBaseData(signals);
|
||
count = signals.Count().ToString() + "/" + count;
|
||
pojectName = GlobalObject.curProject.ProjectName + " | " + GlobalObject.curProject.ShipNameCN;
|
||
|
||
//关联母线按钮是否显示
|
||
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());
|
||
|
||
//获取送审时间和施工时间
|
||
ReviewTime = GlobalObject.curProject.IO_predicted_issue;
|
||
ConstructionTime = GlobalObject.curProject.IO_predicted_issue;
|
||
if (ReviewTime == null) IsReviewTimeVisibility = Visibility.Collapsed;
|
||
if (ConstructionTime == null) IsConstructionTimeVisibility = Visibility.Collapsed;
|
||
// 获取当前时间
|
||
DateTime currentTime = DateTime.Now;
|
||
// 初始化倒计时时间
|
||
ReviewCountdown.TimeRemaining = ReviewTime==null? TimeSpan.Zero:(TimeSpan)(ReviewTime - currentTime);
|
||
ReviewCountdown.IsActive = ReviewTime == null ?false: true;
|
||
if (ReviewCountdown.TimeRemaining<= TimeSpan.Zero)
|
||
{
|
||
if (GlobalObject.curProject.IO_real_issue == null && GlobalObject.curProject.IO_predicted_issue!=null)
|
||
{
|
||
System.Windows.MessageBox.Show($"送审时间已过期: {ReviewCountdown.TimeRemaining:%d}天 {ReviewCountdown.TimeRemaining:hh\\:mm\\:ss}", "错误", MessageBoxButton.OK, MessageBoxImage.Error);
|
||
|
||
}
|
||
}
|
||
ConstructionCountdown.TimeRemaining = ConstructionTime==null? TimeSpan.Zero:(TimeSpan)(ConstructionTime - currentTime);
|
||
|
||
ConstructionCountdown.IsActive = ConstructionTime == null ? false: true;
|
||
if (ConstructionCountdown.TimeRemaining <= TimeSpan.Zero)
|
||
{
|
||
if (GlobalObject.curProject.IO_real_construct == null&& GlobalObject.curProject.IO_predicted_issue!=null)
|
||
{
|
||
System.Windows.MessageBox.Show($"施工时间已过期: {ConstructionCountdown.TimeRemaining:%d}天 {ConstructionCountdown.TimeRemaining:hh\\:mm\\:ss}", "错误", MessageBoxButton.OK, MessageBoxImage.Error);
|
||
|
||
}
|
||
}
|
||
|
||
// 初始化定时器
|
||
_timer.Interval = TimeSpan.FromSeconds(1);
|
||
_timer.Tick += OnTimerElapsed;
|
||
_timer.Start();
|
||
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
System.Windows.MessageBox.Show(ex.Message, "错误", MessageBoxButton.OK, MessageBoxImage.Error);
|
||
}
|
||
finally
|
||
{
|
||
IsBusy = false;
|
||
}
|
||
|
||
}
|
||
|
||
|
||
public override void ExecuteOKCommandAsync(object para)
|
||
{
|
||
DialogResult res = new DialogResult(ButtonResult.Yes);
|
||
RequestClose.Invoke(res);
|
||
}
|
||
public override void ExecuteCloseCommand(object parameter)
|
||
{
|
||
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;
|
||
}
|
||
}
|
||
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)
|
||
{
|
||
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;
|
||
}
|
||
}
|
||
smInfos = new ObservableCollection<SignalManagementInfo>();
|
||
IsBusy = true; BusyContent = "查询中...";
|
||
//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);
|
||
if (!parameter.Equals("All"))
|
||
{
|
||
signals = Allsignals.Where(s => s.Status.ToString().Equals(parameter)).ToList();
|
||
SetBaseData(signals, 1);
|
||
}
|
||
else
|
||
{
|
||
int buttonTextindex = _buttonTexts.IndexOf(buttonText);
|
||
buttonText = _buttonTexts[(buttonTextindex + 1) % _buttonTexts.Length];
|
||
|
||
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;
|
||
}
|
||
|
||
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);
|
||
// 添加新行到选中行下方
|
||
smInfos.Insert(index == -1 ? 0 : index + 1, 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;
|
||
}
|
||
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
|
||
{
|
||
if (string.IsNullOrEmpty(SelectedSmInfo.Wire_Group_ID))
|
||
{
|
||
MessageBox.Show("新增的信号,请先保存在操作!", "KunHengCAD", MessageBoxButton.OK, MessageBoxImage.Warning);
|
||
return;
|
||
}
|
||
var newEntity = new SignalManagementInfo();
|
||
newEntity.BelongingMajor = SelectedSmInfo.BelongingMajor;
|
||
newEntity.type = "虚拟点";
|
||
newEntity.Status = "New";
|
||
newEntity.ParentID = SelectedSmInfo.Wire_Group_ID;
|
||
newEntity.GroupOthers = GroupOthers;
|
||
//newEntity.GroupOther = SelectedSmInfo.GroupOther;
|
||
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("信号"))
|
||
{
|
||
//信号转虚拟点需要排除自己
|
||
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)));
|
||
IDialogParameters para = new DialogParameters();
|
||
para.Add(GlobalObject.dialogPar.title.ToString(), "信号选择框");
|
||
para.Add(GlobalObject.dialogPar.info.ToString(), "请选择要将这个虚拟点放在哪个信号下");
|
||
para.Add(GlobalObject.dialogPar.para1.ToString(), smInfols);
|
||
_dialogService.ShowDialog(nameof(DialogSignalSelect), para, (RES) =>
|
||
{
|
||
if (string.IsNullOrEmpty(SelectedSmInfo.Wire_Group_ID))
|
||
{
|
||
MessageBox.Show("新增的信号,请先保存在操作!", "KunHengCAD", MessageBoxButton.OK, MessageBoxImage.Warning);
|
||
return;
|
||
}
|
||
if (RES.Result == ButtonResult.Yes)
|
||
{
|
||
var signal = RES.Parameters.GetValue<Signal>(GlobalObject.dialogPar.para1.ToString());
|
||
SelectedSmInfo.ParentID = signal.SignalId;
|
||
SelectedSmInfo.type = "虚拟点";
|
||
//如果是虚拟点转换的会带‘_’
|
||
if (!SelectedSmInfo.Group_Name.Contains("_"))
|
||
{
|
||
SelectedSmInfo.Group_Name = SelectedSmInfo.Group_Name + (string.IsNullOrEmpty(SelectedSmInfo.Code) ? "" : "_" + SelectedSmInfo.Code);
|
||
}
|
||
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("虚拟点"))
|
||
{
|
||
if (string.IsNullOrEmpty(SelectedSmInfo.Wire_Group_ID))
|
||
{
|
||
MessageBox.Show("新增的虚拟点,请先保存在操作!", "KunHengCAD", MessageBoxButton.OK, MessageBoxImage.Warning);
|
||
return;
|
||
}
|
||
var parentSmif = smInfos.FirstOrDefault(s => s.Wire_Group_ID == SelectedSmInfo.ParentID);
|
||
SelectedSmInfo.type = "信号";
|
||
SelectedSmInfo.ParentID = "";
|
||
//SelectedSmInfo.Code = "";
|
||
//SelectedSmInfo.Group_Name = SelectedSmInfo.Group_Name.Split('_')[0];
|
||
//SelectedSmInfo.GroupOther = "";
|
||
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)
|
||
{
|
||
if (SelectedSmInfo.Status.Equals("ToDelete"))
|
||
{
|
||
MessageBox.Show("已是待删除的信号,不能删除!", "KunHengCAD", MessageBoxButton.OK, MessageBoxImage.Warning);
|
||
return;
|
||
}
|
||
//RadWindow.Alert("Start time: " + this.StartTime + "\nEnd time: " + this.EndTime);
|
||
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);
|
||
}
|
||
if (result == MessageBoxResult.OK)
|
||
{
|
||
|
||
//id为空表示新增的未保存所以直接删除,不为空表示数据库已存在只修改状态
|
||
if (string.IsNullOrEmpty(SelectedSmInfo.Wire_Group_ID))
|
||
{
|
||
|
||
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);
|
||
}
|
||
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
|
||
|
||
}
|
||
};
|
||
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 = "";
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
SelectedSmInfo.ActionHistorys = histories;
|
||
SelectedSmInfo.Status = "ToDelete";
|
||
SelectedSmInfo.IsModified = true;
|
||
if (SelectedSmInfo.type.Equals("虚拟点"))
|
||
{
|
||
SelectedSmInfo.GroupOther = "";
|
||
}
|
||
|
||
}
|
||
}
|
||
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>()
|
||
{
|
||
new ActionHistory()
|
||
{
|
||
ActionTime= DateTime.Now,
|
||
ActionType = Model.Action.撤销删除,
|
||
|
||
}
|
||
};
|
||
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;
|
||
// }
|
||
//}
|
||
SelectedSmInfo.ActionHistorys = histories;
|
||
SelectedSmInfo.Status = "New";
|
||
SelectedSmInfo.IsModified = true;
|
||
}
|
||
else
|
||
{
|
||
MessageBox.Show("只有待删除的信号才能撤销删除");
|
||
return;
|
||
}
|
||
|
||
}
|
||
#endregion
|
||
|
||
#region 彻底删除
|
||
if (parameter.Equals("彻底删除"))
|
||
{
|
||
if (SelectedSmInfo != null)
|
||
{
|
||
List<ec_Wire_Group> Signals = new List<ec_Wire_Group>();
|
||
if (!(SelectedSmInfo.ChildSignals == null || SelectedSmInfo.ChildSignals.Count == 0))
|
||
{
|
||
foreach (var ChildSignal in SelectedSmInfo.ChildSignals)
|
||
{
|
||
Signals.Add(new ec_Wire_Group()
|
||
{
|
||
Group_Name = ChildSignal.Group_Name,
|
||
Wire_Group_ID = ChildSignal.Wire_Group_ID
|
||
});
|
||
}
|
||
|
||
}
|
||
Signals.Add(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 = ""
|
||
|
||
}
|
||
};
|
||
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("信号"))
|
||
{
|
||
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);
|
||
}
|
||
}
|
||
|
||
}
|
||
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;
|
||
|
||
//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);
|
||
}
|
||
}
|
||
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("关联信号"))
|
||
{
|
||
//只传入非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)));
|
||
}
|
||
}
|
||
IDialogParameters para = new DialogParameters();
|
||
para.Add(GlobalObject.dialogPar.title.ToString(), "信号选择框");
|
||
para.Add(GlobalObject.dialogPar.info.ToString(), "请选择要关联的信号:");
|
||
para.Add(GlobalObject.dialogPar.para1.ToString(), smInfols);
|
||
_dialogService.ShowDialog(nameof(DialogAssociatedSignal), para, (RES) =>
|
||
{
|
||
|
||
if (RES.Result == ButtonResult.Yes)
|
||
{
|
||
var signal = RES.Parameters.GetValue<SignalManagementInfo>(GlobalObject.dialogPar.para1.ToString());
|
||
if (!string.IsNullOrEmpty(SelectedSmInfo.LinkedID))
|
||
{
|
||
var LinkedIDs = SelectedSmInfo.LinkedID.Split(',').ToList();
|
||
LinkedIDs.RemoveAll(item => string.IsNullOrEmpty(item));
|
||
if (!LinkedIDs.Contains(signal.Wire_Group_ID))
|
||
{
|
||
LinkedIDs.Add(signal.Wire_Group_ID);
|
||
}
|
||
SelectedSmInfo.LinkedID = string.Join(",", LinkedIDs);
|
||
}
|
||
else
|
||
{
|
||
SelectedSmInfo.LinkedID = signal.Wire_Group_ID;
|
||
}
|
||
SelectedSmInfo.IsModified = true;
|
||
System.Windows.MessageBox.Show("关联成功", "KunHengCAD", MessageBoxButton.OK, MessageBoxImage.Warning);
|
||
|
||
}
|
||
else if (RES.Result == ButtonResult.No)
|
||
{ }
|
||
});
|
||
return;
|
||
}
|
||
#endregion
|
||
|
||
#region 查关联信号
|
||
if (parameter.Equals("查关联信号"))
|
||
{
|
||
//传入窗口的参数
|
||
ObservableCollection<SignalManagementInfo> sminfols = new ObservableCollection<SignalManagementInfo>();
|
||
var LinkedIDs = SelectedSmInfo.LinkedID.Split(',').ToList();
|
||
foreach (var signal in Allsignals)
|
||
{
|
||
if (LinkedIDs.Contains(signal.Wire_Group_ID))
|
||
{
|
||
SignalManagementInfo info = new SignalManagementInfo();
|
||
SetEntData(info, signal);
|
||
sminfols.Add(info);
|
||
}
|
||
}
|
||
//打开窗口
|
||
IDialogParameters para = new DialogParameters();
|
||
para.Add(GlobalObject.dialogPar.title.ToString(), "信号关联列表");
|
||
para.Add(GlobalObject.dialogPar.info.ToString(), "下面是信号关联列表");
|
||
para.Add(GlobalObject.dialogPar.para1.ToString(), sminfols);
|
||
_dialogService.ShowDialog(nameof(DialogAssociatedSignal), para, (RES) =>
|
||
{
|
||
|
||
if (RES.Result == ButtonResult.Yes)
|
||
{
|
||
var signals = RES.Parameters.GetValue<List<SignalManagementInfo>>(GlobalObject.dialogPar.para2.ToString());
|
||
signals.ForEach(s =>
|
||
{
|
||
var signalid = s.Wire_Group_ID;
|
||
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) =>
|
||
{
|
||
|
||
if (RES.Result == ButtonResult.Yes)
|
||
{
|
||
|
||
}
|
||
else if (RES.Result == ButtonResult.No)
|
||
{ }
|
||
});
|
||
return;
|
||
}
|
||
#endregion
|
||
|
||
#region 导出
|
||
if (parameter.Equals("导出"))
|
||
{
|
||
System.Windows.Forms.SaveFileDialog saveFileDialog = new System.Windows.Forms.SaveFileDialog();
|
||
saveFileDialog.Filter = "Excel文件 (*.xlsx)|*.xlsx|所有文件 (*.*)|*.*";
|
||
saveFileDialog.Title = "选择保存路径";
|
||
|
||
if (saveFileDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
|
||
{
|
||
string selectedPath = saveFileDialog.FileName;
|
||
if (System.IO.File.Exists(selectedPath))
|
||
{ System.IO.File.Delete(selectedPath); }
|
||
|
||
var msg = await _wireGroupService.Exportchanges(selectedPath, (DateTime)statDate, (DateTime)endDate);
|
||
if (string.IsNullOrEmpty(msg))
|
||
{
|
||
MessageBox.Show("下载文件成功!");
|
||
}
|
||
else { MessageBox.Show("下载文件异常:" + msg); }
|
||
}
|
||
}
|
||
#endregion
|
||
}
|
||
|
||
|
||
|
||
public ICommand HeadButtonCmd => new DelegateCommand(HeadButton_Click);
|
||
/// <summary>
|
||
/// 页面顶部按钮
|
||
/// </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);
|
||
}
|
||
}
|
||
}
|
||
if (updatals.Count == 0) return;
|
||
//updatals = smInfos.Where(s => s.IsModified == true).ToList();
|
||
foreach (var item in updatals)
|
||
{
|
||
//保存的为信号时才判断组别
|
||
if (item.type == "信号")
|
||
{
|
||
if (string.IsNullOrEmpty(item.GroupOther))
|
||
{
|
||
// 显示消息框
|
||
MessageBox.Show($"第{item.serialNumber}行组别不能为空", "KunHengCAD", MessageBoxButton.OK, MessageBoxImage.Warning);
|
||
return;
|
||
}
|
||
}
|
||
else if (item.type == "虚拟点")
|
||
{
|
||
if (string.IsNullOrEmpty(item.Code))
|
||
{
|
||
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);
|
||
return;
|
||
}
|
||
}
|
||
Ent.Signals.Add(item.to_ec_Wire_Group(signals));
|
||
}
|
||
//保存
|
||
var Res_SaveSignals = await _wireGroupService.SaveSignals(Ent) as learunHttpRes<List<ec_Wire_Group>>;
|
||
if (Res_SaveSignals.code == 200)
|
||
{
|
||
//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("回收站"))
|
||
//{
|
||
// signals = signals.Where(s => s.Status != WireGroupStatusEnum.deleted).ToList();
|
||
// SetBaseData(signals);
|
||
//}
|
||
//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)
|
||
{
|
||
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);
|
||
|
||
}
|
||
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();
|
||
Ent.Signals.Clear();
|
||
IsBusy = false;
|
||
// 显示消息框
|
||
MessageBox.Show("保存成功", "KunHengCAD", MessageBoxButton.OK, MessageBoxImage.Information);
|
||
}
|
||
else
|
||
{
|
||
Ent.Signals.Clear();
|
||
MessageBox.Show($"{Res_SaveSignals.info}", "KunHengCAD", MessageBoxButton.OK, MessageBoxImage.Error);
|
||
}
|
||
return;
|
||
}
|
||
#endregion
|
||
|
||
#region 导出全部记录
|
||
if (parameter.Equals("导出全部记录"))
|
||
{
|
||
PopupButton_IsOpen = true;
|
||
return;
|
||
}
|
||
#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();
|
||
SetBaseData(signals);
|
||
}
|
||
else
|
||
{
|
||
signals = signals.Where(s => s.Status == WireGroupStatusEnum.deleted).ToList();
|
||
SetBaseData(signals, 1);
|
||
|
||
}
|
||
|
||
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>
|
||
/// 设置数据
|
||
/// 0是初始化数据(层次化数据),1是查询数据(信号虚拟点都在一个层级)
|
||
/// </summary>
|
||
public void SetBaseData(List<ec_Wire_Group> signals, int model = 0)
|
||
{
|
||
|
||
int index = 0;
|
||
foreach (var signal in signals)
|
||
{
|
||
if (model == 0)
|
||
{
|
||
if (string.IsNullOrEmpty(signal.ParentID))
|
||
{
|
||
index++;
|
||
SignalManagementInfo info = new SignalManagementInfo();
|
||
info.serialNumber = index.ToString();
|
||
SetEntData(info, signal);
|
||
smInfos.Add(info);
|
||
foreach (var signal2 in signals)
|
||
{
|
||
if (signal.Wire_Group_ID.Equals(signal2.ParentID))
|
||
{
|
||
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;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
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());
|
||
}
|
||
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);
|
||
}
|
||
|
||
|
||
/// <summary>
|
||
/// 选择组别改变时修改Group_Name和Code()
|
||
/// </summary>
|
||
/// <param name="item"></param>
|
||
private async void UpdateParametersValue(SignalManagementInfo item)
|
||
{
|
||
if (item.type == "信号")
|
||
{
|
||
//获取当前组别的可用编码
|
||
if (item.tempGroupOther != null)
|
||
{
|
||
string group = item.tempGroupOther.DataItemCode;
|
||
if (string.IsNullOrEmpty(item.Signal_SeqNo))//编码列为空时才通过接口获取可用编码
|
||
{
|
||
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();
|
||
}
|
||
item.Group_Name = group + item.Signal_SeqNo;
|
||
}
|
||
|
||
}
|
||
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()
|
||
{
|
||
smInfosView.FilterDescriptors.Clear();
|
||
|
||
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
|
||
});
|
||
}
|
||
}
|
||
|
||
smInfosView.FilterDescriptors.Add(compositeFilter);
|
||
}
|
||
|
||
|
||
}
|
||
|
||
#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
|
||
|
||
#endregion
|
||
|
||
}
|
||
|
||
public class CountdownModel:ViewModelBase
|
||
{
|
||
private TimeSpan _TimeRemaining;
|
||
|
||
public TimeSpan TimeRemaining
|
||
{
|
||
get { return _TimeRemaining; }
|
||
set { _TimeRemaining = value;
|
||
RaisePropertyChanged(nameof(TimeRemaining));
|
||
}
|
||
}
|
||
|
||
private bool _IsActive;
|
||
|
||
public bool IsActive
|
||
{
|
||
get { return _IsActive; }
|
||
set { _IsActive = value;
|
||
RaisePropertyChanged(nameof(IsActive));
|
||
}
|
||
}
|
||
}
|
||
|
||
|
||
|
||
}
|