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 @@ +