Files
CapMachine/CapMachine.Wpf/ViewModels/DialogCreateProViewModel.cs
2024-07-04 17:42:03 +08:00

110 lines
2.7 KiB
C#

using CapMachine.Core;
using Prism.Commands;
using Prism.Services.Dialogs;
using System.Windows;
namespace CapMachine.Wpf.ViewModels
{
/// <summary>
/// 创建弹窗的服务数据
/// </summary>
public class DialogCreateProViewModel : DialogViewModel
{
/// <summary>
/// 实例化函数
/// </summary>
public DialogCreateProViewModel()
{
this.Title = "新增工况";
}
private string name;
/// <summary>
/// 名称
/// </summary>
public string Name
{
get { return name; }
set { name = value; RaisePropertyChanged(); }
}
private DelegateCommand saveCmd;
/// <summary>
/// 保存命令
/// </summary>
public DelegateCommand SaveCmd
{
set
{
saveCmd = value;
}
get
{
if (saveCmd == null)
{
saveCmd = new DelegateCommand(() => SaveCmdMethod());
}
return saveCmd;
}
}
/// <summary>
/// 保存命令方法
/// </summary>
/// <exception cref="NotImplementedException"></exception>
private void SaveCmdMethod()
{
if (string.IsNullOrEmpty(Name))
{
MessageBox.Show("请输入正确的名称!");
return;
}
DialogParameters pars = new DialogParameters
{
{ "Name", Name }
};
RaiseRequestClose(new DialogResult(ButtonResult.OK, pars));
}
private DelegateCommand cancelCmd;
/// <summary>
/// 保存命令
/// </summary>
public DelegateCommand CancelCmd
{
set
{
cancelCmd = value;
}
get
{
if (cancelCmd == null)
{
cancelCmd = new DelegateCommand(() => CancelCmdMethod());
}
return cancelCmd;
}
}
/// <summary>
/// 取消命令方法
/// </summary>
/// <exception cref="NotImplementedException"></exception>
private void CancelCmdMethod()
{
RaiseRequestClose(new DialogResult(ButtonResult.Cancel));
}
/// <summary>
/// 窗口打开时的传递的参数
/// </summary>
/// <param name="parameters"></param>
public override void OnDialogOpened(IDialogParameters parameters)
{
var info = parameters.GetValue<string>("par");
}
}
}