|
- 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
- {
- /// <summary>
- /// 用户名
- /// </summary>
- [ObservableProperty]
- private string? _userName;
- /// <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 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<LocalUser>.Data.UserManagers!= null)
- {
- var res = Json<LocalUser>.Data.UserManagers.FirstOrDefault(p => p.UserName == UserName);
- {
- if(res != null)
- {
- ErrorVisibility = Visibility.Visible;
- ErrorMessage = "用户名已存在";
- return;
- }
- else
- {
- Json<LocalUser>.Data.UserManagers.Add(new UserManager
- {
- UserID = Guid.NewGuid().ToString(),
- UserName = UserName,
- Password = AESHelper.Encrypt(UserPassword),
- });
- }
- }
-
- }
- else
- {
- Json<LocalUser>.Data.UserManagers.Add(new UserManager
- {
- UserID = Guid.NewGuid().ToString(),
- UserName = UserName,
- Password = AESHelper.Encrypt(UserPassword)
- });
- }
- Json<LocalUser>.Save();
- UserName = String.Empty;
- UserPassword = String.Empty;
- ConfirmPassword = String.Empty;
- MessageBox.ShowDialog("注册成功");
-
- }
-
- [RelayCommand]
- private void Exit()
- {
- ActionManage.GetInstance.Send("ChangeMianContent",string.Empty);
- }
-
-
- }
- }
|