终端一体化运控平台
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

62 lines
2.2 KiB

  1. using BPASmartClient.CustomResource.Pages.Model;
  2. using BPASmartClient.Helper;
  3. using Microsoft.Toolkit.Mvvm.ComponentModel;
  4. using Microsoft.Toolkit.Mvvm.Input;
  5. using System;
  6. using System.Collections.Generic;
  7. using System.Linq;
  8. using System.Text;
  9. using System.Threading.Tasks;
  10. namespace BPASmartClient.CustomResource.Pages.ViewModel
  11. {
  12. public class AddNewUserViewModel:ObservableObject
  13. {
  14. public string ErrorInfo { get { return _mErrorInfo; } set { _mErrorInfo = value; OnPropertyChanged(); } }
  15. private string _mErrorInfo;
  16. public string UserName { get { return _userName; } set { _userName = value; OnPropertyChanged(); } }
  17. private string _userName;
  18. public string NewPassword1 { get { return _mNewPassword1; } set { _mNewPassword1 = value; OnPropertyChanged(); } }
  19. private string _mNewPassword1;
  20. public string NewPassword2 { get { return _mNewPassword2; } set { _mNewPassword2 = value; OnPropertyChanged(); } }
  21. private string _mNewPassword2;
  22. public RelayCommand ExitCommand { get; set; }
  23. public RelayCommand ConfirmCommand { get; set; }
  24. private void Confirm()
  25. {
  26. if (UserName == null) { ErrorInfo = "用户名不能为空"; return; }
  27. if (NewPassword1 == null) { ErrorInfo = "请输入密码"; return; }
  28. if (NewPassword2 != NewPassword1) { ErrorInfo = "两次密码不一致"; return; }
  29. var res = Global.userManager.userInfos.FirstOrDefault(p => p.UserName == UserName);
  30. if (res != null) { ErrorInfo = "用户名已存在";return; }
  31. Global.userManager.userInfos.Add(new UserInfo
  32. {
  33. UserName = UserName,
  34. Password = NewPassword1,
  35. userTreeViewModels = new List<UserTreeViewModel>()
  36. });
  37. Config.GetInstance.SaveUser();
  38. ActionManage.GetInstance.Send("AddNewUserViewConfirm");
  39. }
  40. public AddNewUserViewModel()
  41. {
  42. ConfirmCommand = new RelayCommand(Confirm);
  43. ExitCommand = new RelayCommand(() =>
  44. {
  45. ActionManage.GetInstance.Send("AddNewUserViewCancel");
  46. });
  47. }
  48. }
  49. }