95 lines
2.9 KiB
C#
95 lines
2.9 KiB
C#
using System;
|
|
using System.Collections.ObjectModel;
|
|
using System.Linq;
|
|
using System.Windows;
|
|
using Prism.Services.Dialogs;
|
|
using SWS.CAD.ViewModels.myViewModelBase;
|
|
using SWS.Commons;
|
|
using SWS.Model;
|
|
|
|
namespace SWS.CAD.ViewModels
|
|
{
|
|
public class DialogUnitSelectViewModel : DialogBase, IDialogAware
|
|
{
|
|
|
|
public DialogUnitSelectViewModel()
|
|
{
|
|
title = "设计单位选择框";
|
|
}
|
|
|
|
public string Title => "";
|
|
|
|
public event Action<IDialogResult> RequestClose;
|
|
|
|
public bool CanCloseDialog()
|
|
{
|
|
return true;
|
|
}
|
|
|
|
public void OnDialogClosed()
|
|
{
|
|
|
|
}
|
|
private ObservableCollection<Unit> _listUnit;
|
|
/// <summary>
|
|
/// 单位列表
|
|
/// </summary>
|
|
public ObservableCollection<Unit> listUnit
|
|
{
|
|
get { return _listUnit; }
|
|
set { _listUnit = value; RaisePropertyChanged(nameof(listUnit)); }
|
|
}
|
|
private Unit _SelectedUnit;
|
|
/// <summary>
|
|
/// 选中的单位
|
|
/// </summary>
|
|
public Unit SelectedUnit
|
|
{
|
|
get { return _SelectedUnit; }
|
|
set { _SelectedUnit = value; RaisePropertyChanged(nameof(SelectedUnit)); }
|
|
}
|
|
|
|
public void OnDialogOpened(IDialogParameters parameters)
|
|
{
|
|
var unitTypeId = parameters.GetValue<string>(GlobalObject.dialogPar.unitTypeId.ToString());
|
|
var selectUnit = parameters.GetValue<string>(GlobalObject.dialogPar.textYes.ToString());
|
|
var list = GlobalObject.Units.Where(a => a.MeasuringUnitTypeID == unitTypeId).ToList();
|
|
listUnit = new ObservableCollection<Unit>();
|
|
foreach (var item in list)
|
|
{
|
|
listUnit.Add(new Unit() { UnitId=item.MeasuringUnitID, UnitName = item.MeasuringUnitName });
|
|
}
|
|
SelectedUnit = listUnit.FirstOrDefault(a => a.UnitName == selectUnit);
|
|
}
|
|
public override void ExecuteOKCommandAsync(object para)
|
|
{
|
|
if (SelectedUnit == null)
|
|
{
|
|
MessageBox.Show("请选择一个单位!");
|
|
return;
|
|
}
|
|
IDialogParameters res = new DialogParameters();
|
|
res.Add(GlobalObject.dialogPar.unit.ToString(), SelectedUnit);
|
|
DialogResult result = new DialogResult(ButtonResult.Yes, res);
|
|
RequestClose.Invoke(result);
|
|
}
|
|
public override void ExecuteCloseCommand(object parameter)
|
|
{
|
|
if (parameter as string == "ClickNo")
|
|
{
|
|
DialogResult res = new DialogResult(ButtonResult.No);
|
|
RequestClose.Invoke(res);
|
|
}
|
|
else
|
|
{
|
|
DialogResult res = new DialogResult(ButtonResult.Cancel);
|
|
RequestClose.Invoke(res);
|
|
}
|
|
this.Dispose();
|
|
}
|
|
|
|
}
|
|
|
|
|
|
}
|