using BPASmart.Model; using BPASmart.Model; using BPASmartClient.Helper; 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 AddNewUserViewModel { /// /// 用户名 /// [ObservableProperty] private string? _userName; /// /// 用户密码 /// [ObservableProperty] private string? _userPassword; /// /// 确认密码 /// [ObservableProperty] private string? _confirmPassword; /// /// 提示消息 /// [ObservableProperty] private string? _errorMessage; [ObservableProperty] private Visibility _errorVisibility = Visibility.Collapsed; [RelayCommand] private void ResgisterUser() { if(UserName == null || UserName == 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(Json.Data.UserManagers!= null) { var res = Json.Data.UserManagers.FirstOrDefault(p => p.UserName == UserName); { if(res != null) { ErrorVisibility = Visibility.Visible; ErrorMessage = "用户名已存在"; return; } else { Json.Data.UserManagers.Add(new UserManager { UserID = Guid.NewGuid().ToString(), UserName = UserName, Password = AESHelper.Encrypt(UserPassword), }); } } } else { Json.Data.UserManagers.Add(new UserManager { UserID = Guid.NewGuid().ToString(), UserName = UserName, Password = AESHelper.Encrypt(UserPassword) }); } Json.Save(); UserName = String.Empty; UserPassword = String.Empty; ConfirmPassword = String.Empty; MessageBox.ShowDialog("注册成功"); } [RelayCommand] private void Exit() { ActionManage.GetInstance.Send("ChangeMianContent",string.Empty); } } }