|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109 |
- 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);
- }
-
-
- }
- }
|