1510 lines
61 KiB
C#
1510 lines
61 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;
|
||
|
||
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;
|
||
dataView = new QueryableCollectionView(value);
|
||
RaisePropertyChanged(nameof(smInfos));
|
||
}
|
||
}
|
||
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 QueryableCollectionView _dataView;
|
||
|
||
public QueryableCollectionView dataView
|
||
{
|
||
get { return _dataView; }
|
||
set { _dataView = value; RaisePropertyChanged(nameof(dataView)); }
|
||
}
|
||
|
||
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));
|
||
}
|
||
}
|
||
|
||
#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
|
||
|
||
|
||
#endregion
|
||
|
||
private readonly IDialogService _dialogService;
|
||
public DialogSignalManagementViewModel()
|
||
{
|
||
title = "信号管理";
|
||
_dialogService = GlobalObject._prismContainer.Resolve<IDialogService>();
|
||
_wireGroupService = GlobalObject.container.Resolve<WireGroupService>();
|
||
var serv = GlobalObject.container.Resolve<DataItemService>();
|
||
GroupOthers = Task.Run(() => serv.GetDetails("be_Signal_Group")).Result;
|
||
Suppliers = Task.Run(() => serv.GetDetails("Maker")).Result;
|
||
WHCPUs = Task.Run(() => serv.GetDetails("Alarm")).Result;
|
||
|
||
Ent = new WireGroups();
|
||
Ent.Signals = new List<ec_Wire_Group>();
|
||
|
||
var screen = System.Windows.Forms.Screen.PrimaryScreen;
|
||
var workArea = screen.WorkingArea;
|
||
|
||
}
|
||
|
||
public string Title => "";
|
||
|
||
public event Action<IDialogResult> RequestClose;
|
||
|
||
public bool CanCloseDialog()
|
||
{
|
||
return true;
|
||
}
|
||
|
||
public void OnDialogClosed()
|
||
{
|
||
|
||
}
|
||
|
||
private List<ec_Wire_Group> signals;
|
||
public async void OnDialogOpened(IDialogParameters parameters)
|
||
{
|
||
|
||
try
|
||
{
|
||
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();
|
||
SetBaseData(signals);
|
||
dataView = new QueryableCollectionView(smInfos);
|
||
count = smInfos.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());
|
||
|
||
}
|
||
catch (Exception)
|
||
{
|
||
|
||
|
||
}
|
||
|
||
}
|
||
public override void ExecuteOKCommandAsync(object para)
|
||
{
|
||
DialogResult res = new DialogResult(ButtonResult.Yes);
|
||
RequestClose.Invoke(res);
|
||
}
|
||
public override void ExecuteCloseCommand(object parameter)
|
||
{
|
||
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)
|
||
{
|
||
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();
|
||
if (!parameter.Equals("All"))
|
||
{
|
||
signals = signals.Where(s => s.Status.ToString().Equals(parameter)).ToList();
|
||
}
|
||
SetBaseData(signals);
|
||
count = smInfos.Count.ToString() + "/" + count;
|
||
|
||
}
|
||
|
||
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
|
||
{
|
||
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("信号"))
|
||
{
|
||
IDialogParameters para = new DialogParameters();
|
||
para.Add(GlobalObject.dialogPar.title.ToString(), "信号选择框");
|
||
para.Add(GlobalObject.dialogPar.info.ToString(), "请选择要将这个虚拟点放在哪个信号下");
|
||
para.Add(GlobalObject.dialogPar.para1.ToString(), smInfos);
|
||
_dialogService.ShowDialog(nameof(DialogSignalSelect), para, (RES) =>
|
||
{
|
||
|
||
if (RES.Result == ButtonResult.Yes)
|
||
{
|
||
var signal = RES.Parameters.GetValue<Signal>(GlobalObject.dialogPar.para1.ToString());
|
||
SelectedSmInfo.ParentID = signal.SignalId;
|
||
SelectedSmInfo.type = "虚拟点";
|
||
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("虚拟点"))
|
||
{
|
||
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.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)
|
||
{
|
||
//RadWindow.Alert("Start time: " + this.StartTime + "\nEnd time: " + this.EndTime);
|
||
// 显示消息框
|
||
MessageBoxResult result = MessageBox.Show("确定准备删除选择的一行数据", "KunHengCAD", MessageBoxButton.OKCancel, MessageBoxImage.Question);
|
||
if (result == MessageBoxResult.OK)
|
||
{
|
||
|
||
//id为空表示新增的未保存所以直接删除,不为空表示数据库已存在只修改状态
|
||
if (string.IsNullOrEmpty(SelectedSmInfo.Wire_Group_ID))
|
||
{
|
||
smInfos.Remove(SelectedSmInfo);
|
||
}
|
||
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
|
||
|
||
}
|
||
};
|
||
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.撤销删除,
|
||
|
||
}
|
||
};
|
||
SelectedSmInfo.ActionHistorys = histories;
|
||
SelectedSmInfo.Status = "New";
|
||
SelectedSmInfo.IsModified = true;
|
||
}
|
||
else
|
||
{
|
||
MessageBox.Show("只有待删除的信号才能撤销删除");
|
||
}
|
||
|
||
}
|
||
#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 = "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.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);
|
||
}
|
||
|
||
}
|
||
}
|
||
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("关联信号"))
|
||
{
|
||
IDialogParameters para = new DialogParameters();
|
||
para.Add(GlobalObject.dialogPar.title.ToString(), "信号选择框");
|
||
para.Add(GlobalObject.dialogPar.info.ToString(), "请选择要关联的信号:");
|
||
para.Add(GlobalObject.dialogPar.para1.ToString(), smInfos);
|
||
_dialogService.ShowDialog(nameof(DialogSignalSelect), para, (RES) =>
|
||
{
|
||
|
||
if (RES.Result == ButtonResult.Yes)
|
||
{
|
||
var signal = RES.Parameters.GetValue<Signal>(GlobalObject.dialogPar.para1.ToString());
|
||
var LinkedIDs = SelectedSmInfo.LinkedID.Split(',').ToList();
|
||
LinkedIDs.RemoveAll(item=>string.IsNullOrEmpty(item));
|
||
if (!LinkedIDs.Contains(signal.SignalId))
|
||
{
|
||
LinkedIDs.Add(signal.SignalId);
|
||
}
|
||
SelectedSmInfo.LinkedID = string.Join(",", LinkedIDs);
|
||
SelectedSmInfo.IsModified = true;
|
||
|
||
}
|
||
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 smInfoitem in smInfos)
|
||
{
|
||
if (LinkedIDs.Contains(smInfoitem.Wire_Group_ID))
|
||
{
|
||
sminfols.Add(smInfoitem);
|
||
}
|
||
foreach (var item in smInfoitem.ChildSignals)
|
||
{
|
||
if (LinkedIDs.Contains(item.Wire_Group_ID))
|
||
{
|
||
sminfols.Add(item);
|
||
}
|
||
}
|
||
}
|
||
//打开窗口
|
||
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 (RES.Result == ButtonResult.Yes)
|
||
{
|
||
|
||
}
|
||
else if (RES.Result == ButtonResult.No)
|
||
{ }
|
||
});
|
||
return;
|
||
}
|
||
#endregion
|
||
|
||
#region 切换信号
|
||
if (parameter.Equals("切换信号"))
|
||
{
|
||
int buttonTextindex = _buttonTexts.IndexOf(buttonText);
|
||
buttonText = _buttonTexts[(buttonTextindex + 1) % _buttonTexts.Length];
|
||
|
||
var InOrOut = "";
|
||
if (buttonText.Equals("输出信号"))
|
||
{
|
||
InOrOut = "output";
|
||
}
|
||
if (buttonText.Equals("输入信号"))
|
||
{
|
||
InOrOut = "input";
|
||
}
|
||
|
||
|
||
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();
|
||
if (!buttonText.Equals("所有信号"))
|
||
{
|
||
signals = signals.Where(s => s.InOrOut.ToString().Equals(InOrOut)).ToList();
|
||
}
|
||
SetBaseData(signals);
|
||
count = smInfos.Count.ToString() + "/" + count;
|
||
|
||
}
|
||
#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);
|
||
}
|
||
}
|
||
}
|
||
//updatals = smInfos.Where(s => s.IsModified == true).ToList();
|
||
foreach (var item in updatals)
|
||
{
|
||
//保存的为信号时才判断组别
|
||
if (item.type == "信号")
|
||
{
|
||
if (string.IsNullOrEmpty(item.GroupOther))
|
||
{
|
||
// 显示消息框
|
||
MessageBox.Show("组别不能为空", "KunHengCAD", MessageBoxButton.OK, MessageBoxImage.Warning);
|
||
return;
|
||
}
|
||
}
|
||
else if (item.type == "虚拟点")
|
||
{
|
||
if (string.IsNullOrEmpty(item.Code))
|
||
{
|
||
MessageBox.Show("Code列不能为空", "KunHengCAD", MessageBoxButton.OK, MessageBoxImage.Warning);
|
||
return;
|
||
}
|
||
}
|
||
|
||
Ent.Signals.Add(item.to_ec_Wire_Group(signals));
|
||
}
|
||
//保存
|
||
var data = await _wireGroupService.SaveSignals(Ent);
|
||
if (data != null && data.Count != 0)
|
||
{
|
||
|
||
//foreach (var item in data)
|
||
//{
|
||
|
||
//}
|
||
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();
|
||
}
|
||
else
|
||
{
|
||
signals = signals.Where(s => s.Status == WireGroupStatusEnum.deleted).ToList();
|
||
}
|
||
|
||
SetBaseData(signals);
|
||
count = smInfos.Count.ToString() + "/" + count;
|
||
Ent.Signals.Clear();
|
||
// 显示消息框
|
||
MessageBox.Show("保存成功", "KunHengCAD", MessageBoxButton.OK, MessageBoxImage.Information);
|
||
}
|
||
else
|
||
{
|
||
Ent.Signals.Clear();
|
||
MessageBox.Show("保存失败", "KunHengCAD", MessageBoxButton.OK, MessageBoxImage.Error);
|
||
}
|
||
return;
|
||
}
|
||
#endregion
|
||
|
||
#region 退出按钮
|
||
if (parameter.Equals("退出"))
|
||
{
|
||
DialogResult result = new DialogResult(ButtonResult.Cancel);
|
||
RequestClose.Invoke(result);
|
||
this.Dispose();
|
||
}
|
||
#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();
|
||
}
|
||
else
|
||
{
|
||
signals = signals.Where(s => s.Status == WireGroupStatusEnum.deleted).ToList();
|
||
|
||
}
|
||
SetBaseData(signals);
|
||
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>
|
||
/// 设置数据
|
||
/// </summary>
|
||
public void SetBaseData(List<ec_Wire_Group> signals)
|
||
{
|
||
|
||
int index = 0;
|
||
foreach (var signal in signals)
|
||
{
|
||
|
||
//if (signal.ParentID.Equals(""))
|
||
if (string.IsNullOrEmpty(signal.ParentID))
|
||
{
|
||
SignalManagementInfo info = new SignalManagementInfo();
|
||
|
||
index++;
|
||
info.Wire_Group_ID = signal.Wire_Group_ID;
|
||
info.ParentID = signal.ParentID;
|
||
info.LinkedID = signal.LinkedID;
|
||
info.Status = signal.Status.ToString();
|
||
info.serialNumber = index.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;
|
||
info.GroupOther = GroupOthers.Where(g => g.DataItemCode == signal.Signal_Group).Select(g => g.DataItemName).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 = (signal.CableName == "" || signal.CableName == null ? "" : "电缆位号:" + signal.CableName) + (signal.CableSetName == null ? "" : " 电缆对:" + signal.CableSetName);
|
||
info.AssociatedChannelInfo = (signal.PanelName == null ? "" : "采集箱:" + signal.PanelName) + (signal.StripName == null ? "" : "端子排:" + signal.StripName) + (signal.ChannelName == null ? "" : " 通道:" + signal.ChannelName);
|
||
info.Remarks = signal.Remarks;
|
||
info.DeleteFlg = signal.DeleteFlg;
|
||
//订阅事件以更新数据。
|
||
info.ParametersChanged += (sender, e) => UpdateParametersValue((SignalManagementInfo)sender);
|
||
smInfos.Add(info);
|
||
foreach (var signal2 in signals)
|
||
{
|
||
if (signal.Wire_Group_ID.Equals(signal2.ParentID))
|
||
{
|
||
SignalManagementInfo info2 = new SignalManagementInfo();
|
||
|
||
index++;
|
||
info2.Wire_Group_ID = signal2.Wire_Group_ID;
|
||
info2.ParentID = signal2.ParentID;
|
||
info2.LinkedID = signal2.LinkedID;
|
||
info2.Status = signal2.Status.ToString();
|
||
info2.serialNumber = index.ToString();
|
||
info2.type = signal2.ParentID.Equals("") ? "信号" : "虚拟点";
|
||
info2.Group_Name = signal2.Group_Name;
|
||
info2.Group_Desc_EN = signal2.Group_Desc_EN;
|
||
info2.Group_Desc = signal2.Group_Desc;
|
||
info2.BelongingMajor = signal.ElecOnly ? "E" : "M";
|
||
|
||
info2.GroupOthers = GroupOthers;
|
||
info2.GroupOther = GroupOthers.Where(g => g.DataItemCode == signal2.Signal_Group).Select(g => g.DataItemName).FirstOrDefault();
|
||
|
||
info2.Signal_SeqNo = signal2.Signal_SeqNo;
|
||
info2.Code = signal2.Code;
|
||
info2.InOrOut = signal2.InOrOut;
|
||
info2.IO_Type = signal2.IO_Type;
|
||
info2.Range_Min = signal2.Range_Min;
|
||
info2.Range_Max = signal2.Range_Max;
|
||
info2.Unit = signal2.Unit;
|
||
info2.Alarm_LL = signal2.Alarm_LL;
|
||
info2.Alarm_L = signal2.Alarm_L;
|
||
info2.Alarm_H = signal2.Alarm_H;
|
||
info2.Alarm_HH = signal2.Alarm_HH;
|
||
info2.SENSOR_CODE = signal2.SENSOR_CODE;
|
||
info2.CommunicationPoint = signal2.CommunicationPoint;
|
||
info2.SeriousType = signal2.SeriousType;
|
||
info2.AL_GRP = signal2.AL_GRP;
|
||
info2.BL_GRP = signal2.BL_GRP;
|
||
info2.Time_Delay = signal2.Time_Delay;
|
||
info2.Suppliers = Suppliers;
|
||
info2.Supplier = Suppliers.Where(g => g.DataItemCode == signal2.Supplier).Select(g => g.DataItemName).FirstOrDefault();
|
||
info2.EquipName = signal2.EquipName;
|
||
info2.VDR_Record = signal2.VDR_Record;
|
||
info2.WHConsole = signal2.WHConsole;
|
||
//info2.WHCPU = signal2.WHCPU;
|
||
foreach (var item in signal2.WHCPU.Split('|'))
|
||
{
|
||
info2.WHCPUs.Add(WHCPUs.Where(e => e.DataItemCode.Equals(item.Trim())).FirstOrDefault());
|
||
}
|
||
info2.ECRConsole = signal2.ECRConsole;
|
||
//info2.ECRCPU = signal2.ECRCPU;
|
||
foreach (var item in signal2.ECRCPU.Split('|'))
|
||
{
|
||
info2.ECRCPUs.Add(ECRCPUs.Where(e => e.DataItemCode.Equals(item.Trim())).FirstOrDefault());
|
||
}
|
||
info2.ShipOfficeConsole = signal2.ShipOfficeConsole;
|
||
//info2.ShipOfficeCPU = signal2.ShipOfficeCPU;
|
||
foreach (var item in signal2.ShipOfficeCPU.Split('|'))
|
||
{
|
||
info2.ShipOfficeCPUs.Add(ShipOfficeCPUs.Where(e => e.DataItemCode.Equals(item.Trim())).FirstOrDefault());
|
||
}
|
||
info2.SLD = signal2.SLD;
|
||
info2.SHD = signal2.SHD;
|
||
info2.SafetyDelay = signal2.SafetyDelay;
|
||
info2.AutoCtrl = signal2.AutoCtrl;
|
||
info2.AssociatedCableInfo = (signal2.CableName == "" || signal2.CableName == null ? "" : "电缆位号:" + signal2.CableName) + (signal2.CableSetName == null ? "" : " 电缆对:" + signal2.CableSetName);
|
||
info2.AssociatedChannelInfo = (signal2.PanelName == null ? "" : "采集箱:" + signal2.PanelName) + (signal2.StripName == null ? "" : "端子排:" + signal2.StripName) + (signal2.ChannelName == null ? "" : " 通道:" + signal2.ChannelName);
|
||
info2.Remarks = signal2.Remarks;
|
||
info2.DeleteFlg = signal2.DeleteFlg;
|
||
//订阅事件以更新数据。
|
||
info2.ParametersChanged += (sender, e) => UpdateParametersValue((SignalManagementInfo)sender);
|
||
//smInfos.Add(info2);
|
||
info.ChildSignals.Add(info2);
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
|
||
/// <summary>
|
||
/// 选择组别改变时修改Group_Name和Code()
|
||
/// </summary>
|
||
/// <param name="item"></param>
|
||
private async void UpdateParametersValue(SignalManagementInfo item)
|
||
{
|
||
if (item.type == "信号")
|
||
{
|
||
//获取当前组别的可用编码
|
||
string group = GroupOthers.Where(e => e.DataItemName.Equals(item.GroupOther)).Select(e => e.DataItemCode).FirstOrDefault();
|
||
if (string.IsNullOrEmpty(item.Signal_SeqNo))//编码列为空时才通过接口获取可用编码
|
||
{
|
||
var seq = await _wireGroupService.GetNextAvailableSeq(group);
|
||
int count = smInfos.Where(s => s.IsModified == true && string.IsNullOrEmpty(s.Wire_Group_ID)).ToList().Count;
|
||
if (count > 1)
|
||
{
|
||
seq = (double.Parse(seq) + count - 1).ToString();
|
||
}
|
||
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()
|
||
{
|
||
dataView.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
|
||
});
|
||
}
|
||
}
|
||
|
||
dataView.FilterDescriptors.Add(compositeFilter);
|
||
}
|
||
|
||
|
||
}
|
||
|
||
#endregion
|
||
|
||
}
|
||
|
||
|
||
|
||
|
||
|
||
}
|