From eae6d92837cc170130d06efb38620358f5a58db5 Mon Sep 17 00:00:00 2001 From: maqiao <625215135@qq.com> Date: Mon, 13 Nov 2023 17:23:15 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A7=92=E8=89=B2=E7=AE=A1=E7=90=86=E9=A1=B5?= =?UTF-8?q?=E9=9D=A21)=E4=BF=AE=E5=A4=8Dbug,=E5=85=88=E4=B8=AD=E8=A7=92?= =?UTF-8?q?=E8=89=B2=E4=B8=AD=E5=85=A8=E9=83=A8=E8=8F=9C=E5=8D=95=E8=8F=9C?= =?UTF-8?q?=E5=8D=95=E4=B8=AD=E4=BC=9A=E5=8C=85=E5=90=AB=E5=B7=B2=E9=80=89?= =?UTF-8?q?=E8=BF=87=E7=9A=84=E8=8F=9C=E5=8D=95=E7=9A=84=E5=AD=90=E8=8F=9C?= =?UTF-8?q?=E5=8D=95=E7=9A=84=E7=AC=AC=E4=B8=80=E4=B8=AA=E9=A1=B5=E9=9D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 2)添加不可重复添加同角色名的角色校验 --- .../ViewModels/RoleManagerWindowViewModel.cs | 25 ++++++++++++++++++- DM_Weight/Views/RoleManagerWindow.xaml | 3 +++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/DM_Weight/ViewModels/RoleManagerWindowViewModel.cs b/DM_Weight/ViewModels/RoleManagerWindowViewModel.cs index fff27e7..0ec972d 100644 --- a/DM_Weight/ViewModels/RoleManagerWindowViewModel.cs +++ b/DM_Weight/ViewModels/RoleManagerWindowViewModel.cs @@ -16,6 +16,8 @@ using DM_Weight.Models; using DM_Weight.util; using System.Data; using System.Configuration; +using MaterialDesignThemes.Wpf; +using System.Windows.Media; namespace DM_Weight.ViewModels { @@ -83,7 +85,7 @@ namespace DM_Weight.ViewModels { int i = p.Children.ToList().FindIndex(it4 => it4.Id == it3.Id); //if (i > 0 && AllPremissions.ElementAt(index).Children.Count > i) - if (p.Children[i]!=null) + if (p.Children.Count > 0 && i >= 0 && p.Children[i] != null) { AllPremissions.ElementAt(index).Children.RemoveAt(i); } @@ -598,6 +600,20 @@ namespace DM_Weight.ViewModels }); } + private ISnackbarMessageQueue _snackbarMessageQueue = new SnackbarMessageQueue(TimeSpan.FromSeconds(3)); + public ISnackbarMessageQueue SnackbarMessageQueue + { + get => _snackbarMessageQueue; + set => SetProperty(ref _snackbarMessageQueue, value); + } + private SolidColorBrush _colorBrush; + + public SolidColorBrush SnackbarBackground + { + get => _colorBrush; + set => SetProperty(ref _colorBrush, value); + } + public DelegateCommand AddRole { get => new DelegateCommand(() => @@ -605,6 +621,13 @@ namespace DM_Weight.ViewModels Role.Id = 0; Role.MachineId = ConfigurationManager.AppSettings["machineId"] ?? "DM1"; Role.Permissions = RightPremissions.ToList(); + List roleList = SqlSugarHelper.Db.Queryable().Where(r => r.RoleName == Role.RoleName).ToList(); + if (roleList.Count > 0) + { + SnackbarBackground = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#b71c1c")); + SnackbarMessageQueue.Enqueue("该角色已存在!"); + return; + } SqlSugarHelper.Db.Insertable(Role).ExecuteCommand(); RequestData(); }); diff --git a/DM_Weight/Views/RoleManagerWindow.xaml b/DM_Weight/Views/RoleManagerWindow.xaml index dc606c7..766fa2e 100644 --- a/DM_Weight/Views/RoleManagerWindow.xaml +++ b/DM_Weight/Views/RoleManagerWindow.xaml @@ -189,5 +189,8 @@ +