|
- using BPASmartClient.CustomResource.Pages.Model;
- using BPA.Helper;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
-
- namespace BPASmartClient.CustomResource.Pages.ViewModel
- {
- public class AddNewUserViewModel : NotifyBase
- {
- 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 BPARelayCommand ExitCommand { get; set; }
-
- public BPARelayCommand 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 BPARelayCommand(Confirm);
-
- ExitCommand = new BPARelayCommand(() =>
- {
- ActionManage.GetInstance.Send("AddNewUserViewCancel");
-
- });
- }
- }
- }
|