|
- using BPASmartClient.CustomResource.Pages.Model;
- using BPASmartClient.Helper;
- using Microsoft.Toolkit.Mvvm.ComponentModel;
- using Microsoft.Toolkit.Mvvm.Input;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
-
- namespace BPASmartClient.CustomResource.Pages.ViewModel
- {
- public class AddNewUserViewModel:ObservableObject
- {
- public string ErrorInfo { get { return _mErrorInfo; } set { _mErrorInfo = value; OnPropertyChanged(); } }
- private string _mErrorInfo;
-
- public string UserName { get { return _userName; } set { _userName = value; OnPropertyChanged(); } }
- private string _userName;
-
-
- public string NewPassword1 { get { return _mNewPassword1; } set { _mNewPassword1 = value; OnPropertyChanged(); } }
- private string _mNewPassword1;
-
-
- public string NewPassword2 { get { return _mNewPassword2; } set { _mNewPassword2 = value; OnPropertyChanged(); } }
- private string _mNewPassword2;
-
- public RelayCommand ExitCommand { get; set; }
-
- public RelayCommand ConfirmCommand { get; set; }
-
- private void Confirm()
- {
- if (UserName == null) { ErrorInfo = "用户名不能为空"; return; }
- if (NewPassword1 == null) { ErrorInfo = "请输入密码"; return; }
- if (NewPassword2 != NewPassword1) { ErrorInfo = "两次密码不一致"; return; }
- var res = Global.userManager.userInfos.FirstOrDefault(p => p.UserName == UserName);
- if (res != null) { ErrorInfo = "用户名已存在";return; }
- Global.userManager.userInfos.Add(new UserInfo
- {
- UserName = UserName,
- Password = NewPassword1,
- userTreeViewModels = new List<UserTreeViewModel>()
- });
- Config.GetInstance.SaveUser();
- ActionManage.GetInstance.Send("AddNewUserViewConfirm");
- }
-
- public AddNewUserViewModel()
- {
- ConfirmCommand = new RelayCommand(Confirm);
-
- ExitCommand = new RelayCommand(() =>
- {
- ActionManage.GetInstance.Send("AddNewUserViewCancel");
-
- });
- }
- }
- }
|