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

105 rivejä
3.0 KiB

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