174 lines
5.3 KiB
C#
174 lines
5.3 KiB
C#
using System;
|
||
using System.Collections.ObjectModel;
|
||
using System.Linq;
|
||
using System.Windows;
|
||
using SWS.CAD.ViewModels.myViewModelBase;
|
||
using System.Windows.Input;
|
||
using Telerik.Windows.Controls;
|
||
using Unity;
|
||
using Prism.Services.Dialogs;
|
||
using SWS.Commons;
|
||
using SWS.Service;
|
||
using SWS.Model;
|
||
|
||
namespace SWS.CAD.ViewModels
|
||
{
|
||
public class DialogChannelMigrationViewModel : DialogBase, IDialogAware
|
||
{
|
||
#region 字段
|
||
private ObservableCollection<Model.TreeModel> _PanelTreels = new ObservableCollection<Model.TreeModel>();
|
||
/// <summary>
|
||
/// 页面左侧树形结构数据
|
||
/// </summary>
|
||
public ObservableCollection<Model.TreeModel> PanelTreels
|
||
{
|
||
get { return _PanelTreels; }
|
||
set { _PanelTreels = value; RaisePropertyChanged(nameof(PanelTreels)); }
|
||
}
|
||
|
||
private Model.TreeModel _SelectedTreeNode;
|
||
/// <summary>
|
||
/// 当前选中的树形节点
|
||
/// </summary>
|
||
public Model.TreeModel SelectedTreeNode
|
||
{
|
||
get { return _SelectedTreeNode; }
|
||
set
|
||
{
|
||
_SelectedTreeNode = value;
|
||
|
||
RaisePropertyChanged(nameof(SelectedTreeNode));
|
||
UpdateChannelInfos();
|
||
}
|
||
}
|
||
|
||
private ObservableCollection<ec_PanelChannel> _Channels = new ObservableCollection<ec_PanelChannel>();
|
||
/// <summary>
|
||
/// 通道集合
|
||
/// </summary>
|
||
public ObservableCollection<ec_PanelChannel> Channels
|
||
{
|
||
get { return _Channels; }
|
||
set { _Channels = value;
|
||
RaisePropertyChanged(nameof(Channels));
|
||
}
|
||
}
|
||
|
||
private ec_PanelChannel _SelectedChannel;
|
||
/// <summary>
|
||
/// 当前选择的通道
|
||
/// </summary>
|
||
public ec_PanelChannel SelectedChannel
|
||
{
|
||
get { return _SelectedChannel; }
|
||
set { _SelectedChannel = value;
|
||
RaisePropertyChanged(nameof(SelectedChannel));
|
||
}
|
||
}
|
||
|
||
#endregion
|
||
/// <summary>
|
||
/// 接口服务
|
||
/// </summary>
|
||
IOModuleService _iOModuleService;
|
||
public DialogChannelMigrationViewModel()
|
||
{
|
||
_iOModuleService = GlobalObject.container.Resolve<IOModuleService>();
|
||
}
|
||
public string Title => "";
|
||
|
||
public event Action<IDialogResult> RequestClose;
|
||
public bool CanCloseDialog()
|
||
{
|
||
return true;
|
||
}
|
||
|
||
public void OnDialogClosed()
|
||
{
|
||
|
||
}
|
||
|
||
|
||
public async void OnDialogOpened(IDialogParameters parameters)
|
||
{
|
||
//title = parameters.GetValue<string>(GlobalObject.dialogPar.title.ToString());
|
||
title = "通用迁移";
|
||
IsBusy = true; BusyContent = "加载中...";
|
||
PanelTreels.AddRange(await _iOModuleService.GetPanelTree());
|
||
IsBusy = false;
|
||
|
||
}
|
||
|
||
public override void ExecuteOKCommandAsync(object para)
|
||
{
|
||
if (SelectedChannel==null)
|
||
{
|
||
System.Windows.MessageBox.Show("通道未选择", "KunHengCAD", MessageBoxButton.OK, MessageBoxImage.Warning); return;
|
||
|
||
}
|
||
else
|
||
{
|
||
IDialogParameters res = new Prism.Services.Dialogs.DialogParameters();
|
||
res.Add(GlobalObject.dialogPar.para1.ToString(), SelectedChannel);
|
||
res.Add(GlobalObject.dialogPar.para2.ToString(), panelStrip);
|
||
RequestClose.Invoke(new DialogResult(ButtonResult.Yes, res));
|
||
}
|
||
|
||
}
|
||
public override void ExecuteCloseCommand(object parameter)
|
||
{
|
||
if (parameter as string == "ClickNo")
|
||
{
|
||
DialogResult res = new DialogResult(ButtonResult.No);
|
||
RequestClose.Invoke(res);
|
||
}
|
||
else
|
||
{
|
||
RequestClose.Invoke(new DialogResult(ButtonResult.Cancel));
|
||
}
|
||
this.Dispose();
|
||
}
|
||
|
||
#region 方法
|
||
#region 节点改变时,更新通信消息信息表
|
||
private ec_PanelStrip panelStrip;
|
||
/// <summary>
|
||
/// 选择节点改变时,更新通道信息列表
|
||
/// </summary>
|
||
///
|
||
private async void UpdateChannelInfos()
|
||
{
|
||
|
||
if (SelectedTreeNode == null) return;
|
||
Channels.Clear();
|
||
if (SelectedTreeNode.parentId == "" || SelectedTreeNode.parentId == "1") return;
|
||
panelStrip = await _iOModuleService.GetPanelStrip(SelectedTreeNode.ID);
|
||
if (panelStrip != null && panelStrip.Channels.Count > 0)
|
||
{
|
||
foreach (var child in panelStrip.Channels.OrderBy(p => p.Channel_Seq).ToList())
|
||
{
|
||
if (child.Terms.Where(t => t.Connection != null).Count() == 0)
|
||
{
|
||
Channels.Add(child);
|
||
}
|
||
}
|
||
}
|
||
|
||
}
|
||
#endregion
|
||
public ICommand EditEndCmd => new DelegateCommand(EditEnd);
|
||
/// <summary>
|
||
/// 编辑结束事件
|
||
/// </summary>
|
||
/// <param name="parameter"></param>
|
||
public virtual void EditEnd(object parameter)
|
||
{
|
||
//做个标记表示该项修改过
|
||
|
||
}
|
||
#endregion
|
||
}
|
||
|
||
|
||
}
|