终端一体化运控平台
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.
 
 
 

60 řádky
2.1 KiB

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