using CommunityToolkit.Mvvm.ComponentModel; using CommunityToolkit.Mvvm.Input; using SamplePre.Models.Tables; using SamplePre.ProcessBll.BLL; using SamplePre.UIWpf.ConfigManager.chirld; using System; using System.Collections.Generic; using System.ComponentModel; using System.Linq; using System.Runtime.CompilerServices; using System.Text; using System.Threading.Tasks; using System.Windows; using System.Windows.Controls; namespace SamplePreSystem.UI.ViewModel.ConfigManager { public partial class RoleViewModel : ObservableObject { RolesBll roleBll = new RolesBll(); public RoleViewModel() { GetData(); } [ObservableProperty] private List rolesList; [ObservableProperty] private config_role configRole = new config_role(); public void GetData() { RolesList = roleBll.GetRoles(); } /// /// 保存角色 /// public bool SaveRole() { if(string.IsNullOrEmpty(ConfigRole.name.Trim())) { MessageBox.Show("角色名称不能为空!"); return false; } if (string.IsNullOrEmpty(ConfigRole.id)) { //new ConfigRole.id = Guid.NewGuid().ToString(); if (roleBll.SaveRoleData(ConfigRole) < 0) { return false; } } else { if (roleBll.UpdateRoleData(ConfigRole) < 0) { return false; } } return true; } public bool DeleteRole() { if(!string.IsNullOrEmpty( ConfigRole.id )) { if (MessageBox.Show($"确定删除:{ConfigRole.name}", "提示",MessageBoxButton.OKCancel) == MessageBoxResult.OK) { if (roleBll.DeleteRole(ConfigRole) < 0) { MessageBox.Show("用户删除失败!"); return false; } //刷新用户 GetData(); return true; } } return false; } /// /// 添加角色 /// [RelayCommand] public void BtnAddClick() { ConfigRole = new config_role(); NewRoleWindow frm = new NewRoleWindow(this); if (frm.ShowDialog() == true) { GetData(); } } /// /// 编辑角色 /// [RelayCommand] public void BtnEditClick() { NewRoleWindow frm = new NewRoleWindow(this); if (frm.ShowDialog() == true) { GetData(); } } /// /// 删除角色 /// [RelayCommand] public void BtnDeleClick() { DeleteRole(); } [RelayCommand] public void BtnPermissonClick() { if (string.IsNullOrEmpty(ConfigRole.id)) return; PermissionWindow frm = new PermissionWindow(this); frm.ShowDialog(); } } }