终端一体化运控平台
Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.
 
 
 

81 wiersze
2.6 KiB

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using BPASmartClient.CustomResource.Pages.Model;
  7. using BPASmartClient.Helper;
  8. using Microsoft.Toolkit.Mvvm.ComponentModel;
  9. using Microsoft.Toolkit.Mvvm.Input;
  10. namespace BPASmartClient.CustomResource.Pages.ViewModel
  11. {
  12. public class PasswordChangeViewModel : ObservableObject
  13. {
  14. private void CheckPassword(UserInfo userInfo)
  15. {
  16. if (userInfo.Password == OldPassword)
  17. {
  18. if (NewPassword1 == NewPassword2)
  19. {
  20. userInfo.Password = NewPassword2;
  21. int index = Array.FindIndex(Global.userManager.userInfos.ToArray(), p => p.UserName == userInfo.UserName);
  22. if (index >= 0 && index < Global.userManager.userInfos.Count)
  23. Global.userManager.userInfos.ElementAt(index).Password = NewPassword1;
  24. Config.GetInstance.SaveUser();
  25. ActionManage.GetInstance.Send("PasswordChangeViewconfirm");
  26. Global.changeUserInfo = null;
  27. }
  28. else
  29. {
  30. ErrorInfo = "新密码不匹配";
  31. }
  32. }
  33. else
  34. {
  35. ErrorInfo = "原密码错误";
  36. }
  37. }
  38. public PasswordChangeViewModel( )
  39. {
  40. LoginCommand = new RelayCommand(() =>
  41. {
  42. if (Global.changeUserInfo == null) CheckPassword(Global.userInfo);
  43. else { CheckPassword(Global.changeUserInfo); }
  44. });
  45. ExitCommand = new RelayCommand(() =>
  46. {
  47. ActionManage.GetInstance.Send("PasswordChangeViewCancel");
  48. Global.changeUserInfo = null;
  49. });
  50. }
  51. public RelayCommand LoginCommand { get; set; }
  52. public RelayCommand ExitCommand { get; set; }
  53. public string ErrorInfo { get { return _mErrorInfo; } set { _mErrorInfo = value; OnPropertyChanged(); } }
  54. private string _mErrorInfo;
  55. public string OldPassword { get { return _mOldPassword; } set { _mOldPassword = value; OnPropertyChanged(); } }
  56. private string _mOldPassword;
  57. public string NewPassword1 { get { return _mNewPassword1; } set { _mNewPassword1 = value; OnPropertyChanged(); } }
  58. private string _mNewPassword1;
  59. public string NewPassword2 { get { return _mNewPassword2; } set { _mNewPassword2 = value; OnPropertyChanged(); } }
  60. private string _mNewPassword2;
  61. }
  62. }