|
-
- using BPASmart.UserManagement.Globle;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows;
-
- namespace BPASmart.UserManagement.ViewModel
- {
- [INotifyPropertyChanged]
- partial class ChangeUserViewModel
- {
- /// <summary>
- /// 用户名
- /// </summary>
- [ObservableProperty]
- private string? _userName;
- /// <summary>
- /// 原始密码
- /// </summary>
- [ObservableProperty]
- private string? _lastPassword;
- /// <summary>
- /// 用户密码
- /// </summary>
- [ObservableProperty]
- private string? _userPassword;
- /// <summary>
- /// 确认密码
- /// </summary>
- [ObservableProperty]
- private string? _confirmPassword;
-
- /// <summary>
- /// 提示消息
- /// </summary>
- [ObservableProperty]
- private string? _errorMessage;
-
- [ObservableProperty]
- private Visibility _errorVisibility = Visibility.Collapsed;
-
- [RelayCommand]
- private void SaveUser()
- {
- if (LastPassword == null|| LastPassword == string.Empty)
- {
- ErrorVisibility = Visibility.Visible;
- ErrorMessage = "请输入原始密码";
- return;
- }
- if (UserPassword == null || UserPassword == string.Empty)
- {
- ErrorVisibility = Visibility.Visible;
- ErrorMessage = "请输入密码";
- return;
- }
- if (UserPassword != ConfirmPassword)
- {
- ErrorVisibility = Visibility.Visible;
- ErrorMessage = "两次密码不一致";
- return;
- }
- if(AESHelper.Decrypt(GlobleData.ChangeUser.Password) != LastPassword)
- {
- ErrorVisibility = Visibility.Visible;
- ErrorMessage = "原始密码错误";
- return;
- }
- var res = Json<LocalUser>.Data.UserManagers.FirstOrDefault(x => x.UserID == GlobleData.ChangeUser.UserID);
- if (res != null)
- {
- res.Password = AESHelper.Encrypt(UserPassword);
- }
- else
- {
- ErrorVisibility = Visibility.Visible;
- ErrorMessage = "该员工不存在";
- return;
- }
- Json<LocalUser>.Save();
- GlobleData.ChangeUser = null;
- ActionManage.GetInstance.Send("ChangeMianContent", string.Empty);
- MessageBox.ShowDialog("修改成功");
- }
-
- [RelayCommand]
- private void Exit()
- {
- ActionManage.GetInstance.Send("ChangeMianContent", string.Empty);
- }
-
- public ChangeUserViewModel()
- {
- if (GlobleData.ChangeUser != null)
- {
- UserName = GlobleData.ChangeUser.UserName;
- }
- }
-
- }
- }
|