using BPASmartClient.CustomResource.Pages.Model; using BPASmartClient.CustomResource.Pages.View; using Microsoft.Toolkit.Mvvm.Input; using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Linq; using System.Text; using System.Threading.Tasks; namespace BPASmartClient.CustomResource.Pages.ViewModel { public class UserManagerViewModel { /// /// datagrid绑定 /// public ObservableCollection userManager { get; set; } = Global.userManager.userInfos; public RelayCommand ChangePasswardCommand { get; set; } public RelayCommand AddNewUserCommand { get; set; } public RelayCommand DeleteUserCommand { get; set; } public RelayCommand EditUserConfigCommand { get; set; } private void ChangePassward(object o) { if (o != null && o is UserInfo infos) { Global.changeUserInfo = infos; PasswordChangeView passwordChangeView = new PasswordChangeView(); passwordChangeView.ShowDialog(); } } private void DeleteUser(object o) { if (o != null && o is UserInfo infos) { var res = Global.userManager.userInfos.FirstOrDefault(p => p.UserName == infos.UserName); if (res != null) Global.userManager.userInfos.Remove(res); Config.GetInstance.SaveUser(); } } private void EditUserConfig(object o) { if (o != null && o is UserInfo infos) { Global.changeUserInfo = null; Global.changeUserInfo = infos; UserConfigView userConfigView = new UserConfigView(); userConfigView.ShowDialog(); } } public UserManagerViewModel() { ChangePasswardCommand = new RelayCommand(ChangePassward); AddNewUserCommand = new RelayCommand(() => { AddNewUser addNewUser = new AddNewUser(); addNewUser.ShowDialog(); }); DeleteUserCommand = new RelayCommand(DeleteUser); EditUserConfigCommand = new RelayCommand(EditUserConfig); } } }