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 _PanelTreels = new ObservableCollection(); /// /// 页面左侧树形结构数据 /// public ObservableCollection PanelTreels { get { return _PanelTreels; } set { _PanelTreels = value; RaisePropertyChanged(nameof(PanelTreels)); } } private Model.TreeModel _SelectedTreeNode; /// /// 当前选中的树形节点 /// public Model.TreeModel SelectedTreeNode { get { return _SelectedTreeNode; } set { _SelectedTreeNode = value; RaisePropertyChanged(nameof(SelectedTreeNode)); UpdateChannelInfos(); } } private ObservableCollection _Channels = new ObservableCollection(); /// /// 通道集合 /// public ObservableCollection Channels { get { return _Channels; } set { _Channels = value; RaisePropertyChanged(nameof(Channels)); } } private ec_PanelChannel _SelectedChannel; /// /// 当前选择的通道 /// public ec_PanelChannel SelectedChannel { get { return _SelectedChannel; } set { _SelectedChannel = value; RaisePropertyChanged(nameof(SelectedChannel)); } } #endregion /// /// 接口服务 /// IOModuleService _iOModuleService; public DialogChannelMigrationViewModel() { _iOModuleService = GlobalObject.container.Resolve(); } public string Title => ""; public event Action RequestClose; public bool CanCloseDialog() { return true; } public void OnDialogClosed() { } public async void OnDialogOpened(IDialogParameters parameters) { //title = parameters.GetValue(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; /// /// 选择节点改变时,更新通道信息列表 /// /// 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); /// /// 编辑结束事件 /// /// public virtual void EditEnd(object parameter) { //做个标记表示该项修改过 } #endregion } }