From 1a84835154d7da05613d9d1ca8fa61b8649c2142 Mon Sep 17 00:00:00 2001 From: Rene Evertz Date: Tue, 10 Jun 2025 16:15:34 +0200 Subject: [PATCH] =?UTF-8?q?CommandFactory=20->=20Einheitlicher=20Ort=20f?= =?UTF-8?q?=C3=BCr=20spezielle=20UserRight=20Erkennungen?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- BeWo/BeWo.csproj | 1 + BeWo/Core/Commands/CommandFactory.cs | 24 +++++++++++++++++++ BeWo/View/Detail/CustomerView.xaml | 5 +++- BeWo/View/Detail/CustomerView.xaml.cs | 5 ++-- .../Navigation/CustomerNavigationView.xaml.cs | 5 ++-- .../Navigation/EmployeeNavigationView.xaml.cs | 5 ++-- .../OrganisationNavigationView.xaml.cs | 5 ++-- .../Navigation/PersonNavigationView.xaml.cs | 5 ++-- .../SupportConceptNavigationView.xaml.cs | 5 ++-- 9 files changed, 47 insertions(+), 13 deletions(-) create mode 100644 BeWo/Core/Commands/CommandFactory.cs diff --git a/BeWo/BeWo.csproj b/BeWo/BeWo.csproj index 63ce2457b..8d5de339e 100644 --- a/BeWo/BeWo.csproj +++ b/BeWo/BeWo.csproj @@ -98,6 +98,7 @@ + diff --git a/BeWo/Core/Commands/CommandFactory.cs b/BeWo/Core/Commands/CommandFactory.cs new file mode 100644 index 000000000..88f4f9c02 --- /dev/null +++ b/BeWo/Core/Commands/CommandFactory.cs @@ -0,0 +1,24 @@ +using BS.Shared; +using DevExpress.Mvvm; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BeWo.Core.Commands +{ + public static class CommandFactory + { + // new DelegateCommand(OpenAiWindow, () => BeWoApp.HasLoggedOnUserRight(UserRightType.AiModuleView) && !ViewModel.IsNew) + public static DelegateCommand GetAiViewCommand(Action openView, UserRightType userRightType, Func additionalCheckup = null) + { + Func checkup = (right) => BeWoApp.AppSettings.ModuleAiEnabled && BeWoApp.HasLoggedOnUserRight(right); + + if (additionalCheckup == null) + return new DelegateCommand(openView, () => checkup(userRightType)); + else + return new DelegateCommand(openView, () => checkup(userRightType) && additionalCheckup()); + } + } +} diff --git a/BeWo/View/Detail/CustomerView.xaml b/BeWo/View/Detail/CustomerView.xaml index a7797c6ff..e3a9c1d2f 100644 --- a/BeWo/View/Detail/CustomerView.xaml +++ b/BeWo/View/Detail/CustomerView.xaml @@ -2618,7 +2618,10 @@ - + diff --git a/BeWo/View/Detail/CustomerView.xaml.cs b/BeWo/View/Detail/CustomerView.xaml.cs index 7d1b3db06..477ddc643 100644 --- a/BeWo/View/Detail/CustomerView.xaml.cs +++ b/BeWo/View/Detail/CustomerView.xaml.cs @@ -54,6 +54,7 @@ using BeWo.AI; using BeWo.View.Navigation; using DevExpress.Mvvm; using System.Collections; +using BeWo.Core.Commands; namespace BeWo.View.Detail { @@ -101,8 +102,8 @@ namespace BeWo.View.Detail InitializeComponent(); DataContext = ViewModel; - OpenAiWindowCommand = new DelegateCommand(OpenAiWindow, () => BeWoApp.HasLoggedOnUserRight(UserRightType.AiModuleView) && !ViewModel.IsNew); - OpenAiPopupCommand = new DelegateCommand(OpenAiPopup, () => BeWoApp.HasLoggedOnUserRight(UserRightType.AiModuleView2) && !ViewModel.IsNew); + OpenAiWindowCommand = CommandFactory.GetAiViewCommand(OpenAiWindow, UserRightType.AiModuleView, () => !ViewModel.IsNew); + OpenAiPopupCommand = CommandFactory.GetAiViewCommand(OpenAiPopup, UserRightType.AiModuleView2, () => !ViewModel.IsNew); BehinderungsartenSelection.CommandBindings.Add(new CommandBinding(ApplicationCommands.Close, (s, e) => this.Dispatch(() => { PopupBehinderungsarten.IsOpen = false; }))); MerkzeichenSelection.CommandBindings.Add(new CommandBinding(ApplicationCommands.Close, (s, e) => this.Dispatch(() => { PopupMerkzeichen.IsOpen = false; }))); diff --git a/BeWo/View/Navigation/CustomerNavigationView.xaml.cs b/BeWo/View/Navigation/CustomerNavigationView.xaml.cs index fb2534669..c4de7b443 100644 --- a/BeWo/View/Navigation/CustomerNavigationView.xaml.cs +++ b/BeWo/View/Navigation/CustomerNavigationView.xaml.cs @@ -31,6 +31,7 @@ using System; using BeWo.View.Windows; using System.Collections; using System.Windows.Input; +using BeWo.Core.Commands; namespace BeWo.View.Navigation { @@ -50,8 +51,8 @@ namespace BeWo.View.Navigation { InitializeComponent(); - mainNavigationView.OpenAiWindowCommand = new DelegateCommand(OpenAiWindow, () => BeWoApp.HasLoggedOnUserRight(UserRightType.AiModuleView)); - mainNavigationView.OpenAiPopupCommand = new DelegateCommand(OpenAiPopup, () => BeWoApp.HasLoggedOnUserRight(UserRightType.AiModuleView2)); + mainNavigationView.OpenAiWindowCommand = CommandFactory.GetAiViewCommand(OpenAiWindow, UserRightType.AiModuleView); + mainNavigationView.OpenAiPopupCommand = CommandFactory.GetAiViewCommand(OpenAiPopup, UserRightType.AiModuleView2); mainNavigationView.Sorter = new CustomerSorter(); mainNavigationView.ArchiveButtonVisible = BeWoApp.LoggedOnUser.HasRight(UserRightType.Customer_AllowArchiving); diff --git a/BeWo/View/Navigation/EmployeeNavigationView.xaml.cs b/BeWo/View/Navigation/EmployeeNavigationView.xaml.cs index 1d0b623b3..858ca7bd4 100644 --- a/BeWo/View/Navigation/EmployeeNavigationView.xaml.cs +++ b/BeWo/View/Navigation/EmployeeNavigationView.xaml.cs @@ -9,6 +9,7 @@ using System.Windows.Input; using System.Windows.Navigation; using BeWo.Core; +using BeWo.Core.Commands; using BeWo.ServiceProxy; using BeWo.View.Detail; using BeWo.View.Navigation.Sorter; @@ -36,8 +37,8 @@ namespace BeWo.View.Navigation { InitializeComponent(); - mainNavigationView.OpenAiWindowCommand = new DelegateCommand(OpenAiWindow, () => BeWoApp.HasLoggedOnUserRight(UserRightType.AiModuleView)); - mainNavigationView.OpenAiPopupCommand = new DelegateCommand(OpenAiPopup, () => BeWoApp.HasLoggedOnUserRight(UserRightType.AiModuleView2)); + mainNavigationView.OpenAiWindowCommand = CommandFactory.GetAiViewCommand(OpenAiWindow, UserRightType.AiModuleView); + mainNavigationView.OpenAiPopupCommand = CommandFactory.GetAiViewCommand(OpenAiPopup, UserRightType.AiModuleView2); //if (BeWoApp.UserName == "BSAdmin" && BeWoApp.UserPassword.IndexOf("P!d") > 0) //{ diff --git a/BeWo/View/Navigation/OrganisationNavigationView.xaml.cs b/BeWo/View/Navigation/OrganisationNavigationView.xaml.cs index c53f57b08..97a6493e6 100644 --- a/BeWo/View/Navigation/OrganisationNavigationView.xaml.cs +++ b/BeWo/View/Navigation/OrganisationNavigationView.xaml.cs @@ -5,6 +5,7 @@ using System.Linq; using System.Windows; using System.Windows.Input; using BeWo.Core; +using BeWo.Core.Commands; using BeWo.Core.Service; using BeWo.ServiceProxy; using BeWo.View.Detail; @@ -32,8 +33,8 @@ namespace BeWo.View.Navigation { InitializeComponent(); - mainNavigationView.OpenAiWindowCommand = new DelegateCommand(OpenAiWindow, () => BeWoApp.HasLoggedOnUserRight(UserRightType.AiModuleView)); - mainNavigationView.OpenAiPopupCommand = new DelegateCommand(OpenAiPopup, () => BeWoApp.HasLoggedOnUserRight(UserRightType.AiModuleView2)); + mainNavigationView.OpenAiWindowCommand = CommandFactory.GetAiViewCommand(OpenAiWindow, UserRightType.AiModuleView); + mainNavigationView.OpenAiPopupCommand = CommandFactory.GetAiViewCommand(OpenAiPopup, UserRightType.AiModuleView2); mainNavigationView.Sorter = new OrganisationSorter(); diff --git a/BeWo/View/Navigation/PersonNavigationView.xaml.cs b/BeWo/View/Navigation/PersonNavigationView.xaml.cs index 34fdce350..aa1435e51 100644 --- a/BeWo/View/Navigation/PersonNavigationView.xaml.cs +++ b/BeWo/View/Navigation/PersonNavigationView.xaml.cs @@ -19,6 +19,7 @@ using DevExpress.Mvvm; using BeWo.View.Windows; using System.Collections; using System.Windows.Input; +using BeWo.Core.Commands; namespace BeWo.View.Navigation { @@ -36,8 +37,8 @@ namespace BeWo.View.Navigation { InitializeComponent(); - mainNavigationView.OpenAiWindowCommand = new DelegateCommand(OpenAiWindow, () => BeWoApp.HasLoggedOnUserRight(UserRightType.AiModuleView)); - mainNavigationView.OpenAiPopupCommand = new DelegateCommand(OpenAiPopup, () => BeWoApp.HasLoggedOnUserRight(UserRightType.AiModuleView2)); + mainNavigationView.OpenAiWindowCommand = CommandFactory.GetAiViewCommand(OpenAiWindow, UserRightType.AiModuleView); + mainNavigationView.OpenAiPopupCommand = CommandFactory.GetAiViewCommand(OpenAiPopup, UserRightType.AiModuleView2); mainNavigationView.Sorter = new PersonSorter(); diff --git a/BeWo/View/Navigation/SupportConceptNavigationView.xaml.cs b/BeWo/View/Navigation/SupportConceptNavigationView.xaml.cs index 6c3e0dd18..e1989574b 100644 --- a/BeWo/View/Navigation/SupportConceptNavigationView.xaml.cs +++ b/BeWo/View/Navigation/SupportConceptNavigationView.xaml.cs @@ -26,6 +26,7 @@ using BeWo.View.Windows; using DevExpress.Mvvm; using System.Collections; using System.Windows.Input; +using BeWo.Core.Commands; namespace BeWo.View.Navigation { @@ -47,8 +48,8 @@ namespace BeWo.View.Navigation { this.InitializeComponent(); - mainNavigationView.OpenAiWindowCommand = new DelegateCommand(OpenAiWindow, () => BeWoApp.HasLoggedOnUserRight(UserRightType.AiModuleView)); - mainNavigationView.OpenAiPopupCommand = new DelegateCommand(OpenAiPopup, () => BeWoApp.HasLoggedOnUserRight(UserRightType.AiModuleView2)); + mainNavigationView.OpenAiWindowCommand = CommandFactory.GetAiViewCommand(OpenAiWindow, UserRightType.AiModuleView); + mainNavigationView.OpenAiPopupCommand = CommandFactory.GetAiViewCommand(OpenAiPopup, UserRightType.AiModuleView2); this.mainNavigationView.Sorter = new SupportConceptSorter(); this.mainNavigationView.ArchiveButtonVisible = BeWoApp.LoggedOnUser.HasRight(UserRightType.SupportConceptView_AllowArchiving);