174 lines
5.3 KiB
C#
Raw Normal View History

2025-08-15 16:34:31 +08:00
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;
2025-09-04 18:28:02 +08:00
using Prism.Services.Dialogs;
using SWS.Commons;
using SWS.Service;
using SWS.Model;
2025-08-15 16:34:31 +08:00
namespace SWS.CAD.ViewModels
{
public class DialogChannelMigrationViewModel : DialogBase, IDialogAware
{
#region
2025-09-04 18:28:02 +08:00
private ObservableCollection<Model.TreeModel> _PanelTreels = new ObservableCollection<Model.TreeModel>();
2025-08-15 16:34:31 +08:00
/// <summary>
/// 页面左侧树形结构数据
/// </summary>
2025-09-04 18:28:02 +08:00
public ObservableCollection<Model.TreeModel> PanelTreels
2025-08-15 16:34:31 +08:00
{
get { return _PanelTreels; }
set { _PanelTreels = value; RaisePropertyChanged(nameof(PanelTreels)); }
}
2025-09-04 18:28:02 +08:00
private Model.TreeModel _SelectedTreeNode;
2025-08-15 16:34:31 +08:00
/// <summary>
/// 当前选中的树形节点
/// </summary>
2025-09-04 18:28:02 +08:00
public Model.TreeModel SelectedTreeNode
2025-08-15 16:34:31 +08:00
{
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>();
}
2025-09-04 18:28:02 +08:00
public string Title => "";
public event Action<IDialogResult> RequestClose;
2025-08-15 16:34:31 +08:00
public bool CanCloseDialog()
{
return true;
}
public void OnDialogClosed()
{
}
public async void OnDialogOpened(IDialogParameters parameters)
{
//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
{
2025-09-04 18:28:02 +08:00
IDialogParameters res = new Prism.Services.Dialogs.DialogParameters();
2025-08-15 16:34:31 +08:00
res.Add(GlobalObject.dialogPar.para1.ToString(), SelectedChannel);
res.Add(GlobalObject.dialogPar.para2.ToString(), panelStrip);
2025-09-04 18:28:02 +08:00
RequestClose.Invoke(new DialogResult(ButtonResult.Yes, res));
2025-08-15 16:34:31 +08:00
}
}
public override void ExecuteCloseCommand(object parameter)
{
if (parameter as string == "ClickNo")
{
2025-09-04 18:28:02 +08:00
DialogResult res = new DialogResult(ButtonResult.No);
RequestClose.Invoke(res);
2025-08-15 16:34:31 +08:00
}
else
{
2025-09-04 18:28:02 +08:00
RequestClose.Invoke(new DialogResult(ButtonResult.Cancel));
2025-08-15 16:34:31 +08:00
}
this.Dispose();
}
#region
#region
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
}
}