diff --git a/DM_Weight/ViewModels/RoleManagerWindowViewModel.cs b/DM_Weight/ViewModels/RoleManagerWindowViewModel.cs index 27cd444..0220b86 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 { @@ -59,6 +61,39 @@ namespace DM_Weight.ViewModels private void CompareList(RoleDm Role) { + //AllPremissions = Clone(defaultAll); + //RightPremissions.Clear(); + //if (Role != null && Role.Permissions != null) + //{ + // List Permissions = Role.Permissions; + // Permissions.ForEach(it => + // { + // // 父菜单 + // PremissionDm p = AllPremissions.ToList().Find(it2 => it2.Id == it.Id); + // int index = AllPremissions.ToList().FindIndex(it2 => it2.Id == it.Id); + // if (p.Id != 6) + // { + // it.Children.ToList().ForEach(it3 => + // { + // int i =p.Children.ToList().FindIndex(it4 => it4.Id == it3.Id); + // if (i > 0 && AllPremissions.ElementAt(index).Children.Count > i) + // { + // AllPremissions.ElementAt(index).Children.RemoveAt(i); + // } + // }); + // if (p.Children.Count == 0) + // { + // AllPremissions.RemoveAt(index); + // } + // } else + // { + // AllPremissions.RemoveAt(index); + // } + + // }); + // RightPremissions = new ObservableCollection(Permissions); + //} + AllPremissions = Clone(defaultAll); RightPremissions.Clear(); if (Role != null && Role.Permissions != null) @@ -69,25 +104,35 @@ namespace DM_Weight.ViewModels // 父菜单 PremissionDm p = AllPremissions.ToList().Find(it2 => it2.Id == it.Id); int index = AllPremissions.ToList().FindIndex(it2 => it2.Id == it.Id); - if (p.Id != 6) - { - it.Children.ToList().ForEach(it3 => - { - int i =p.Children.ToList().FindIndex(it4 => it4.Id == it3.Id); - if (i > 0 && AllPremissions.ElementAt(index).Children.Count > i) - { - AllPremissions.ElementAt(index).Children.RemoveAt(i); - } - }); - if (p.Children.Count == 0) - { - AllPremissions.RemoveAt(index); - } - } else + + if (p != null && p.Children != null && it != null && it.Children != null && p.Children.Count == it.Children.Count) { AllPremissions.RemoveAt(index); } - + else + { + + if (p.Id != 6) + { + it.Children.ToList().ForEach(it3 => + { + int i = p.Children.ToList().FindIndex(it4 => it4.Id == it3.Id); + //if (i > 0 && AllPremissions.ElementAt(index).Children.Count > i) + if (p.Children.Count>0&&i >= 0 && p.Children[i] != null) + { + AllPremissions.ElementAt(index).Children.RemoveAt(i); + } + }); + if (p.Children.Count == 0) + { + AllPremissions.RemoveAt(index); + } + } + else + { + AllPremissions.RemoveAt(index); + } + } }); RightPremissions = new ObservableCollection(Permissions); } @@ -149,6 +194,7 @@ namespace DM_Weight.ViewModels PremissionName = "取药记录", PremissionPath = "TakeRecordWindow", }; + quyaoChild.Add(quyao1); quyaoChild.Add(quyao2); quyaoChild.Add(quyao3); @@ -594,6 +640,19 @@ namespace DM_Weight.ViewModels RightPremissions.Clear(); }); } + 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 { @@ -602,6 +661,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..aaf0010 100644 --- a/DM_Weight/Views/RoleManagerWindow.xaml +++ b/DM_Weight/Views/RoleManagerWindow.xaml @@ -185,8 +185,11 @@ + - +