终端一体化运控平台
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.

ChangeUserViewModel.cs 3.0 KiB

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