using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Linq; using System.Windows; using SWS.CAD.ViewModels.myViewModelBase; using Prism.Ioc; using SWS.CAD.Views.Dialog; using Prism.Events; using Unity; using SWS.CAD.Event; using Prism.Services.Dialogs; using SWS.Commons; using SWS.Model; namespace SWS.CAD.ViewModels { public class DialogNewPositionalViewModel: DialogBase, IDialogAware { #region 字段 private ObservableCollection _listPro = new ObservableCollection(); /// /// 属性列表 /// public ObservableCollection listPro { get { return _listPro; } set { _listPro = value; RaisePropertyChanged(nameof(listPro)); } } private string _SelectionChanged; /// /// 用来监听下拉选择的值为“新增电缆位号”时弹出窗口 /// public string SelectionChanged { get { return _SelectionChanged; } set { _SelectionChanged = value; RaisePropertyChanged(nameof(SelectionChanged)); } } #endregion IEventAggregator eventAggregator; public DialogNewPositionalViewModel() { eventAggregator = GlobalObject.container.Resolve(); //订阅事件 eventAggregator.GetEvent().Subscribe(SelectChannelInfos, ThreadOption.UIThread, true); } public string Title => ""; public event Action RequestClose; public bool CanCloseDialog() { return true; } public void OnDialogClosed() { } private List handles = new List(); private ec_drawing_file objDwg; public async void OnDialogOpened(IDialogParameters parameters) { title = parameters.GetValue(GlobalObject.dialogPar.title.ToString()); #region 添加属性 var propertyModels = parameters.GetValue>(GlobalObject.dialogPar.para1.ToString()); ObservableCollection listPropertys = new ObservableCollection(); foreach (var item in propertyModels) { listPropertys.Add(item); } listPro = listPropertys; #endregion } public override void ExecuteOKCommandAsync(object para) { foreach (var p in listPro) { if(p.DisplayText.Equals("位置名称")){ if (string.IsNullOrEmpty(p.PropertyValue)) { // 显示消息框 MessageBox.Show("属性项“位置名称”不能为空!", "KunHengCAD", MessageBoxButton.OK, MessageBoxImage.Warning);return; } } if (p.DisplayText.Equals("电缆位号")) { if (p.PropertyValue.Equals("新增电缆位号")) { return; } } } IDialogParameters res = new DialogParameters(); res.Add(GlobalObject.dialogPar.para1.ToString(), listPro); RequestClose.Invoke(new DialogResult(ButtonResult.Yes, res)); } public override void ExecuteCloseCommand(object parameter) { //if (smInfos.Any(s => s.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 { RequestClose.Invoke(new DialogResult(ButtonResult.Cancel)); } this.Dispose(); } #region 下拉列表选择改变时 private ec_PanelStrip panelStrip; /// /// 下拉列表选择改变时调用 /// /// private async void SelectChannelInfos(propertyModel model) { if (model.PropertyValue.Equals("新增电缆位号")) { //打开窗体 IDialogParameters para = new DialogParameters(); para.Add(GlobalObject.dialogPar.info.ToString(), true); var _dialogService = GlobalObject._prismContainer.Resolve(); _dialogService.ShowDialog(nameof(DialogNewComponent), para, async (RES) => { if (RES.Result == ButtonResult.Yes) { var reslistPro = RES.Parameters.GetValue>(GlobalObject.dialogPar.para1.ToString()); var selectTagNumber = reslistPro.Where(p => p.DisplayText.Equals("位号")).Select(p => p.PropertyValue).FirstOrDefault(); listPro.Where(e=>e.DisplayText.Equals("电缆位号")).FirstOrDefault().PropertyValue = selectTagNumber; //listPro.FirstOrDefault().Item } else if (RES.Result == ButtonResult.No) { } }); } } #endregion } }