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
{
///
/// 用户名
///
[ObservableProperty]
private string? _userName;
///
/// 原始密码
///
[ObservableProperty]
private string? _lastPassword;
///
/// 用户密码
///
[ObservableProperty]
private string? _userPassword;
///
/// 确认密码
///
[ObservableProperty]
private string? _confirmPassword;
///
/// 提示消息
///
[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.Data.UserManagers.FirstOrDefault(x => x.UserID == GlobleData.ChangeUser.UserID);
if (res != null)
{
res.Password = AESHelper.Encrypt(UserPassword);
}
else
{
ErrorVisibility = Visibility.Visible;
ErrorMessage = "该员工不存在";
return;
}
Json.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;
}
}
}
}