终端一体化运控平台
Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.
 
 
 

110 рядки
3.2 KiB

  1. using BPASmart.Model;
  2. using BPASmart.Model;
  3. using BPASmartClient.Helper;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows;
  10. namespace BPASmart.UserManagement.ViewModel
  11. {
  12. [INotifyPropertyChanged]
  13. partial class AddNewUserViewModel
  14. {
  15. /// <summary>
  16. /// 用户名
  17. /// </summary>
  18. [ObservableProperty]
  19. private string? _userName;
  20. /// <summary>
  21. /// 用户密码
  22. /// </summary>
  23. [ObservableProperty]
  24. private string? _userPassword;
  25. /// <summary>
  26. /// 确认密码
  27. /// </summary>
  28. [ObservableProperty]
  29. private string? _confirmPassword;
  30. /// <summary>
  31. /// 提示消息
  32. /// </summary>
  33. [ObservableProperty]
  34. private string? _errorMessage;
  35. [ObservableProperty]
  36. private Visibility _errorVisibility = Visibility.Collapsed;
  37. [RelayCommand]
  38. private void ResgisterUser()
  39. {
  40. if(UserName == null || UserName == string.Empty)
  41. {
  42. ErrorVisibility = Visibility.Visible;
  43. ErrorMessage = "请输入用户名";
  44. return;
  45. }
  46. if(UserPassword == null || UserPassword == string.Empty)
  47. {
  48. ErrorVisibility = Visibility.Visible;
  49. ErrorMessage = "请输入密码";
  50. return;
  51. }
  52. if (UserPassword != ConfirmPassword)
  53. {
  54. ErrorVisibility = Visibility.Visible;
  55. ErrorMessage = "两次密码不一致";
  56. return;
  57. }
  58. if(Json<LocalUser>.Data.UserManagers!= null)
  59. {
  60. var res = Json<LocalUser>.Data.UserManagers.FirstOrDefault(p => p.UserName == UserName);
  61. {
  62. if(res != null)
  63. {
  64. ErrorVisibility = Visibility.Visible;
  65. ErrorMessage = "用户名已存在";
  66. return;
  67. }
  68. else
  69. {
  70. Json<LocalUser>.Data.UserManagers.Add(new UserManager
  71. {
  72. UserID = Guid.NewGuid().ToString(),
  73. UserName = UserName,
  74. Password = AESHelper.Encrypt(UserPassword),
  75. });
  76. }
  77. }
  78. }
  79. else
  80. {
  81. Json<LocalUser>.Data.UserManagers.Add(new UserManager
  82. {
  83. UserID = Guid.NewGuid().ToString(),
  84. UserName = UserName,
  85. Password = AESHelper.Encrypt(UserPassword)
  86. });
  87. }
  88. Json<LocalUser>.Save();
  89. UserName = String.Empty;
  90. UserPassword = String.Empty;
  91. ConfirmPassword = String.Empty;
  92. MessageBox.ShowDialog("注册成功");
  93. }
  94. [RelayCommand]
  95. private void Exit()
  96. {
  97. ActionManage.GetInstance.Send("ChangeMianContent",string.Empty);
  98. }
  99. }
  100. }