添加项目文件。
This commit is contained in:
113
SamplePreSystem.UI/ViewModel/Login/LoginViewModel.cs
Normal file
113
SamplePreSystem.UI/ViewModel/Login/LoginViewModel.cs
Normal file
@@ -0,0 +1,113 @@
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using CommunityToolkit.Mvvm.Input;
|
||||
using SamplePre.ProcessBll.BLL;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Security.Principal;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using System.Windows.Input;
|
||||
|
||||
namespace SamplePreSystem.UI.ViewModel.Login
|
||||
{
|
||||
public partial class LoginViewModel : ObservableObject
|
||||
{
|
||||
|
||||
|
||||
UsersBll usersBll = new UsersBll();
|
||||
|
||||
/// <summary>
|
||||
/// 关闭委托
|
||||
/// </summary>
|
||||
public Action<bool> ColseAction;
|
||||
|
||||
//保持用户名
|
||||
public Action<string> SaveUserAction;
|
||||
|
||||
public LoginViewModel()
|
||||
{
|
||||
;
|
||||
}
|
||||
|
||||
[ObservableProperty]
|
||||
public string errInfo = "";
|
||||
|
||||
[ObservableProperty]
|
||||
public bool isSaveUser = false;
|
||||
|
||||
[ObservableProperty]
|
||||
public string userName = "";
|
||||
|
||||
|
||||
[ObservableProperty]
|
||||
public string userPwd = "";
|
||||
|
||||
|
||||
|
||||
public bool UserChecked()
|
||||
{
|
||||
|
||||
if (usersBll.CheckUser(UserName, UserPwd) == false)
|
||||
{
|
||||
|
||||
ErrInfo = "登录账号或密码错误!";
|
||||
return false;
|
||||
}
|
||||
|
||||
if (IsSaveUser == true)
|
||||
{
|
||||
SaveUserAction?.Invoke(UserName);
|
||||
|
||||
}
|
||||
|
||||
ColseAction?.Invoke(true);
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 登录
|
||||
/// </summary>
|
||||
[RelayCommand]
|
||||
public void LoginButtonClick()
|
||||
{
|
||||
UserChecked();
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 回车登录
|
||||
/// </summary>
|
||||
/// <param name="e"></param>
|
||||
[RelayCommand]
|
||||
public void PwdKeyDown(KeyEventArgs e)
|
||||
{
|
||||
if (e.Key == Key.Enter)
|
||||
{
|
||||
UserChecked();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 退出
|
||||
/// </summary>
|
||||
[RelayCommand]
|
||||
public void CancelClick()
|
||||
{
|
||||
ColseAction?.Invoke(false);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user