using Prism.Commands;
using Prism.Mvvm;
using Prism.Services.Dialogs;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Data;
namespace WorkStation.Client.ViewModels.Dialogs
{
public class LoginViewModel : BindableBase, IDialogAware
{
///
/// 弹窗标题
///
public string Title => "登录界面";
///
/// 账户
///
private string _account = string.Empty;
public string Account
{
get => _account;
set => SetProperty(ref _account, value);
}
///
/// 密码
///
private string _password = string.Empty;
public string Password
{
get => _password;
set => SetProperty(ref _password, value);
}
///
/// 用于关闭窗口时,判断是否登录成功。
/// 如果登录失败就终止当前应用。
///
private bool _isSuccess = false;
///
/// 登录命令
///
public DelegateCommand LoginCommand { get; set; }
///
/// 请求关闭委托
///
public event Action RequestClose;
///
/// Determines whether the dialog can be closed.
///
/// if the dialog can be closed; otherwise, .
public bool CanCloseDialog()
{
return true;
}
public void OnDialogClosed()
{
if (_isSuccess == false)
{
Application.Current.Shutdown();
}
}
public void OnDialogOpened(IDialogParameters parameters)
{
}
public LoginViewModel()
{
LoginCommand = new DelegateCommand(() =>
{
if (Account == "11" && Password == "22")
{
_isSuccess = true;
RequestClose(new DialogResult(ButtonResult.OK));
}
});
}
}
}