2025-09-04 18:28:02 +08:00

168 lines
5.8 KiB
C#

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<propertyModel> _listPro = new ObservableCollection<propertyModel>();
/// <summary>
/// 属性列表
/// </summary>
public ObservableCollection<propertyModel> listPro
{
get { return _listPro; }
set
{
_listPro = value;
RaisePropertyChanged(nameof(listPro));
}
}
private string _SelectionChanged;
/// <summary>
/// 用来监听下拉选择的值为“新增电缆位号”时弹出窗口
/// </summary>
public string SelectionChanged
{
get { return _SelectionChanged; }
set { _SelectionChanged = value;
RaisePropertyChanged(nameof(SelectionChanged));
}
}
#endregion
IEventAggregator eventAggregator;
public DialogNewPositionalViewModel()
{
eventAggregator = GlobalObject.container.Resolve<IEventAggregator>();
//订阅事件
eventAggregator.GetEvent<NewPositional_SelectChangeEvent>().Subscribe(SelectChannelInfos, ThreadOption.UIThread, true);
}
public string Title => "";
public event Action<IDialogResult> RequestClose;
public bool CanCloseDialog()
{
return true;
}
public void OnDialogClosed()
{
}
private List<string> handles = new List<string>();
private ec_drawing_file objDwg;
public async void OnDialogOpened(IDialogParameters parameters)
{
title = parameters.GetValue<string>(GlobalObject.dialogPar.title.ToString());
#region
var propertyModels = parameters.GetValue<List<propertyModel>>(GlobalObject.dialogPar.para1.ToString());
ObservableCollection<propertyModel> listPropertys = new ObservableCollection<propertyModel>();
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;
/// <summary>
/// 下拉列表选择改变时调用
/// </summary>
///
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<IDialogService>();
_dialogService.ShowDialog(nameof(DialogNewComponent), para, async (RES) =>
{
if (RES.Result == ButtonResult.Yes)
{
var reslistPro = RES.Parameters.GetValue<ObservableCollection<propertyModel>>(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
}
}