From 03ea11fefa278e5eaab4caeabffd9c2b738ce79c Mon Sep 17 00:00:00 2001 From: Rene Evertz Date: Fri, 29 Nov 2024 14:46:19 +0100 Subject: [PATCH] Reihenfolge --- BeWo/ServiceProxy/ServiceFacade.cs | 29 +- BeWo/View/BeWoView.cs | 318 ++++++++++---------- BeWo/View/Detail/MandatorView.xaml.cs | 6 +- BeWo/View/Master/AdministrationView.xaml | 3 +- BeWo/View/Master/AdministrationView.xaml.cs | 182 ++++++----- 5 files changed, 265 insertions(+), 273 deletions(-) diff --git a/BeWo/ServiceProxy/ServiceFacade.cs b/BeWo/ServiceProxy/ServiceFacade.cs index 688e95432..75cce83a5 100644 --- a/BeWo/ServiceProxy/ServiceFacade.cs +++ b/BeWo/ServiceProxy/ServiceFacade.cs @@ -75,17 +75,14 @@ namespace BeWo.ServiceProxy { DoAsync(pFunc, pCallBack, true); } - public static void DoAccountingServiceAsync(Action pAction) { DoAsync(pAction, true); } - public static void DoAccountingServiceAsync(Action pAction, Action callback) { DoAsync(pAction, callback, true); } - public static T DoAccountingServiceSync(Func pFunc) { try @@ -99,19 +96,16 @@ namespace BeWo.ServiceProxy return default(T); } - public static void DoAnalysisServiceAsync(Func pFunc, Action pCallBack) { DoAsync(pFunc, pCallBack, true); } - public static void DoAnalysisServiceAsync(Func pFunc, Action pCallBack, bool showWaitDialog) { DoAsync(pFunc, pCallBack, showWaitDialog); } - public static void DoAccountingServiceSync(Action pAction) { pAction.Invoke(GetInstance()); @@ -806,17 +800,6 @@ namespace BeWo.ServiceProxy } } - private static void EndWaiting() - { - Monitor.Enter(_Lock); - if ((--_RunningAsyncs) == 0 && BeWoApp.MainControl != null) - { - BeWoApp.MainControl.EndWaiting(); - } - - Monitor.Exit(_Lock); - } - private static TInterface GetInstance() where TClient : ClientBase, TInterface, new() where TInterface : class @@ -878,7 +861,7 @@ namespace BeWo.ServiceProxy BeWoApp.ShowErrorMessage(e); } - private static void StartWaiting() + private static void StartWaiting() { Monitor.Enter(_Lock); if ((++_RunningAsyncs) == 1 && BeWoApp.MainControl != null) @@ -889,5 +872,15 @@ namespace BeWo.ServiceProxy Monitor.Exit(_Lock); } + private static void EndWaiting() + { + Monitor.Enter(_Lock); + if ((--_RunningAsyncs) == 0 && BeWoApp.MainControl != null) + { + BeWoApp.MainControl.EndWaiting(); + } + + Monitor.Exit(_Lock); + } } } \ No newline at end of file diff --git a/BeWo/View/BeWoView.cs b/BeWo/View/BeWoView.cs index 38375b469..03117785b 100644 --- a/BeWo/View/BeWoView.cs +++ b/BeWo/View/BeWoView.cs @@ -10,194 +10,198 @@ using BS.Shared; namespace BeWo.View { - public class BeWoView : UserControl - { - public Action ModalEditViewUpdateCallback; + public class BeWoView : UserControl + { + public Action ModalEditViewUpdateCallback; - public virtual bool IsDoneWithInsertOrUpdate { get; set; } + public virtual bool IsDoneWithInsertOrUpdate { get; set; } - public event EventHandler BlendOutComplete; + public event EventHandler BlendOutComplete; - public virtual bool CanDelete - { - get - { - return false; - } - } + public virtual bool CanDelete + { + get + { + return false; + } + } - public virtual bool CanExcelExport - { - get - { - return false; - } - } + public virtual bool CanExcelExport + { + get + { + return false; + } + } - public virtual bool CanWordExport - { - get - { - return false; - } - } + public virtual bool CanWordExport + { + get + { + return false; + } + } - public virtual bool IsDirty - { - get - { - return false; - } - } + public virtual bool IsDirty + { + get + { + return false; + } + } - public virtual BeWoView ParentView { get; set; } + public virtual BeWoView ParentView { get; set; } - public virtual string SaveObjectName - { - get - { - return this.Title; - } - } + public virtual string SaveObjectName + { + get + { + return this.Title; + } + } - public virtual string Title - { - get - { - return string.Empty; - } - } + public virtual string Title + { + get + { + return string.Empty; + } + } - public virtual bool IsInWindow { get; set; } + public virtual bool IsInWindow { get; set; } - internal virtual DependencyObject ValidationOnSaveRootElement - { - get - { - return this; - } - } + internal virtual DependencyObject ValidationOnSaveRootElement + { + get + { + return this; + } + } - protected MainControl MainControl - { - get - { - return BeWoApp.MainControl; - } - } + protected MainControl MainControl + { + get + { + return BeWoApp.MainControl; + } + } - public void BlendIn() - { - DoubleAnimation lAnim = new DoubleAnimation(1, new Duration(TimeSpan.FromSeconds(0.3))); - this.BeginAnimation(OpacityProperty, lAnim); - } + public void BlendIn() + { + DoubleAnimation lAnim = new DoubleAnimation(1, new Duration(TimeSpan.FromSeconds(0.3))); + this.BeginAnimation(OpacityProperty, lAnim); + } - public void BlendOut() - { - DoubleAnimation lAnim = new DoubleAnimation(0, new Duration(TimeSpan.FromSeconds(0.3))); - lAnim.Completed += (s, e) => - { - if (this.BlendOutComplete != null) - { - this.BlendOutComplete(this, e); - } - }; - this.BeginAnimation(OpacityProperty, lAnim); - } + public void BlendOut() + { + DoubleAnimation lAnim = new DoubleAnimation(0, new Duration(TimeSpan.FromSeconds(0.3))); + lAnim.Completed += (s, e) => + { + if (this.BlendOutComplete != null) + { + this.BlendOutComplete(this, e); + } + }; + this.BeginAnimation(OpacityProperty, lAnim); + } - public virtual void Delete() - { - } + public virtual void Delete() + { + } - public virtual void ExportToExcel(string pFileID) - { - } + public virtual void ExportToExcel(string pFileID) + { + } - public virtual void ExportToWord(string pFileID) - { - } + public virtual void ExportToWord(string pFileID) + { + } - public virtual void ModalPopUpCloseInvoked() - { - } + public virtual void ModalPopUpCloseInvoked() + { + } - public virtual void ModalPopUpSaveInvoked() - { - } + public virtual void ModalPopUpSaveInvoked() + { + } - public virtual void ChildViewClosed() - { - } + public virtual void ChildViewClosed() + { + } - public bool SaveData() - { - if (!BeWoApp.HasLoggedOnUserRight(this.GetSaveDemands())) - { - MessageBox.Show("Sie besitzen nicht die nötigen Rechte um zu speichern. Bitte wenden Sie sich an den Administrator!", "Autorisierung fehlgeschlagen", MessageBoxButton.OK, MessageBoxImage.Warning); - return false; - } + public bool SaveData() + { + if (!BeWoApp.HasLoggedOnUserRight(this.GetSaveDemands())) + { + MessageBox.Show("Sie besitzen nicht die nötigen Rechte um zu speichern. Bitte wenden Sie sich an den Administrator!", "Autorisierung fehlgeschlagen", MessageBoxButton.OK, MessageBoxImage.Warning); + return false; + } - var lValid = ValidationTrigger.Validate(this.ValidationOnSaveRootElement); - if (lValid) - { - Save(); - } - else - { - MessageBox.Show("Bitte füllen Sie alle Pflichtfelder aus!", "Speichern nicht möglich", MessageBoxButton.OK, MessageBoxImage.Warning); - } + var lValid = ValidationTrigger.Validate(this.ValidationOnSaveRootElement); + if (lValid) + { + Save(); + } + else + { + MessageBox.Show("Bitte füllen Sie alle Pflichtfelder aus!", "Speichern nicht möglich", MessageBoxButton.OK, MessageBoxImage.Warning); + } - return lValid; - } + return lValid; + } - public virtual MessageBoxResult ShowSaveQuestion() - { - return string.IsNullOrEmpty(this.SaveObjectName) ? MessageBox.Show("Wollen Sie die Änderungen speichern?", "Änderungen speichern", MessageBoxButton.YesNoCancel, MessageBoxImage.Question) : MessageBox.Show("Wollen Sie die Änderungen an " + this.SaveObjectName + " speichern?", "Änderungen speichern", MessageBoxButton.YesNoCancel, MessageBoxImage.Question); - } + public virtual MessageBoxResult ShowSaveQuestion() + { + return string.IsNullOrEmpty(this.SaveObjectName) ? MessageBox.Show("Wollen Sie die Änderungen speichern?", "Änderungen speichern", MessageBoxButton.YesNoCancel, MessageBoxImage.Question) : MessageBox.Show("Wollen Sie die Änderungen an " + this.SaveObjectName + " speichern?", "Änderungen speichern", MessageBoxButton.YesNoCancel, MessageBoxImage.Question); + } - internal virtual bool DoSaveCheck() - { - if (this.IsDirty) - { - MessageBoxResult lResult = this.ShowSaveQuestion(); - if (lResult == MessageBoxResult.Cancel) - { - this.Focus(); - return false; - } + /// + /// Gibt false zurück, wenn Speicherfrage abgelehnt wird, sonst true + /// + /// + internal virtual bool DoSaveCheck() + { + if (!IsDirty) + return true; - if (lResult == MessageBoxResult.Yes) - { - this.SaveData(); - } - } + MessageBoxResult lResult = this.ShowSaveQuestion(); + if (lResult == MessageBoxResult.Cancel) + { + this.Focus(); + return false; + } - return true; - } + if (lResult == MessageBoxResult.Yes) + { + this.SaveData(); + } - protected virtual UserRightType[] GetSaveDemands() - { - return null; - } + return true; + } + + protected virtual UserRightType[] GetSaveDemands() + { + return null; + } - protected virtual void Save() - { - } + protected virtual void Save() + { + } - protected bool Validate(DependencyObject lElement) - { - return ValidationTrigger.Validate(lElement); - } + protected bool Validate(DependencyObject lElement) + { + return ValidationTrigger.Validate(lElement); + } - protected virtual void popup_Closed(object sender, EventArgs e) - { - this.MainControl.AnimateOpacity(1, 100); - } + protected virtual void popup_Closed(object sender, EventArgs e) + { + this.MainControl.AnimateOpacity(1, 100); + } - protected virtual void popup_Opened(object sender, EventArgs e) - { - this.MainControl.AnimateOpacity(0.5, 200); - } - } + protected virtual void popup_Opened(object sender, EventArgs e) + { + this.MainControl.AnimateOpacity(0.5, 200); + } + } } \ No newline at end of file diff --git a/BeWo/View/Detail/MandatorView.xaml.cs b/BeWo/View/Detail/MandatorView.xaml.cs index 17175e08c..ce5dd1d9b 100644 --- a/BeWo/View/Detail/MandatorView.xaml.cs +++ b/BeWo/View/Detail/MandatorView.xaml.cs @@ -111,10 +111,11 @@ namespace BeWo.View.Detail { invoiceNumberList.Add(ivm.CommitToDataContract()); } + ServiceFacade.DoAccountingServiceAsync( s => s.UpdateInvoiceNumberList(invoiceNumberList), inl => ServiceFacade.DoOperationsServiceAsync( - s => s.UpdateMandator(this.ViewModel.CommitToDataContract()), + s => s.UpdateMandator(ViewModel.CommitToDataContract()), m => this.Dispatch( delegate { @@ -147,8 +148,7 @@ namespace BeWo.View.Detail else { ViewModel.EinheitZeiterfassung = "0"; - } - + } } } } \ No newline at end of file diff --git a/BeWo/View/Master/AdministrationView.xaml b/BeWo/View/Master/AdministrationView.xaml index 74620617f..fceeb325f 100644 --- a/BeWo/View/Master/AdministrationView.xaml +++ b/BeWo/View/Master/AdministrationView.xaml @@ -13,7 +13,8 @@ Height="Auto" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" - Focusable="True"> + Focusable="True" + Loaded="AdministrationView_Loaded"> diff --git a/BeWo/View/Master/AdministrationView.xaml.cs b/BeWo/View/Master/AdministrationView.xaml.cs index f2b75926d..24ebbb727 100644 --- a/BeWo/View/Master/AdministrationView.xaml.cs +++ b/BeWo/View/Master/AdministrationView.xaml.cs @@ -31,11 +31,6 @@ namespace BeWo.View.Master InitializeComponent(); //GenerateNewView(TabitemMandator); - this.Loaded += AdministrationView_Loaded; - - - - MouseMove += (s, e) => { var p = e.GetPosition(btnSave); @@ -110,11 +105,99 @@ namespace BeWo.View.Master } + + public override bool IsDirty => SelectedView != null && + SelectedView.IsDirty; + public BeWoView SelectedView + { + get => _SelectedView; + set + { + if (value == null) return; + + _SelectedView = value; + ContentBorder.Child = value; + } + } + public MandatorVM MandatorVM + { + get => _MandatorVM; + set + { + _MandatorVM = value; + + if (_OpenViews.TryGetValue(TabitemMandator.Header.ToString(), out var cachedView) && cachedView is MandatorView mandatorView) + { + mandatorView.ViewModel = value; + } + + if (_OpenViews.TryGetValue(TabitemSozioTherapie.Header.ToString(), out var cachedView2) && cachedView2 is SoziotherapieSettingsView soziotherapieSettingsView) + { + soziotherapieSettingsView.ViewModel = value; + } + } + } + internal override DependencyObject ValidationOnSaveRootElement => + SelectedView.ValidationOnSaveRootElement; + private void AdministrationView_Loaded(object sender, RoutedEventArgs e) { ExpandItems(); } + private void Tabitem_Selected(object sender, RoutedEventArgs e) + { + if (!(sender is AccordionItem selectedAccordionItem)) + return; + var header = selectedAccordionItem.Header.ToString(); + if (_OpenViews.TryGetValue(header, out var view)) + { + if(view is object) + SetView(_OpenViews[header]); + } + else + GenerateNewView(selectedAccordionItem); + + BeWoApp.AppSettings.SelectedAdministrationItem = header; + } + + internal override bool DoSaveCheck() + { + BeWoApp.AppSettings.ExpandedAdministrationItems = ""; + + if (Root != null) + { + foreach (AccordionItem ai in Root.Items) + { + if (ai.IsExpanded) + { + BeWoApp.AppSettings.ExpandedAdministrationItems += ":" + ai.Header; + } + } + } + + if (SelectedView is null) + return true; + + var lDoSave = SelectedView.DoSaveCheck(); + + // Speicheranfrage abgelehnt + if (!lDoSave) + return false; + + // Synchron gespeichert + if (!IsDirty) + return true; + + // Keine Änderungen, asynchron gespeichert oder verworfen + _OpenViews.Remove(((AccordionItem)Root.SelectedItem).Header.ToString()); + + return true; + } + protected override void Save() + { + SelectedView.SaveData(); + } private void ExpandItems() { if (!String.IsNullOrEmpty(BeWoApp.AppSettings.ExpandedAdministrationItems)) @@ -147,91 +230,6 @@ namespace BeWo.View.Master } } - private void Tabitem_Selected(object sender, RoutedEventArgs e) - { - if (!(sender is AccordionItem selectedAccordionItem)) - return; - - var header = selectedAccordionItem.Header.ToString(); - if (_OpenViews.TryGetValue(header, out var view)) - { - if(view is object) - SetView(_OpenViews[header]); - } - else - GenerateNewView(selectedAccordionItem); - - BeWoApp.AppSettings.SelectedAdministrationItem = header; - } - - public override bool IsDirty => SelectedView != null && - SelectedView.IsDirty; - - public BeWoView SelectedView - { - get => _SelectedView; - set - { - if (value == null) return; - - _SelectedView = value; - ContentBorder.Child = value; - } - } - - public MandatorVM MandatorVM - { - get => _MandatorVM; - set - { - _MandatorVM = value; - - if (_OpenViews.TryGetValue(TabitemMandator.Header.ToString(), out var cachedView) && cachedView is MandatorView mandatorView) - { - mandatorView.ViewModel = value; - } - - if (_OpenViews.TryGetValue(TabitemSozioTherapie.Header.ToString(), out var cachedView2) && cachedView2 is SoziotherapieSettingsView soziotherapieSettingsView) - { - soziotherapieSettingsView.ViewModel = value; - } - } - } - - internal override DependencyObject ValidationOnSaveRootElement => - SelectedView.ValidationOnSaveRootElement; - - internal override bool DoSaveCheck() - { - BeWoApp.AppSettings.ExpandedAdministrationItems = ""; - - if (Root != null) - { - foreach (AccordionItem ai in Root.Items) - { - if (ai.IsExpanded) - { - BeWoApp.AppSettings.ExpandedAdministrationItems += ":" + ai.Header; - } - } - } - - if (!(Root.SelectedItem is AccordionItem item) || !_OpenViews.ContainsKey(item.Header.ToString())) return true; - - var lDoSave = SelectedView.DoSaveCheck(); - - if (!lDoSave || !IsDirty) return lDoSave; - - _OpenViews.Remove(((AccordionItem)Root.SelectedItem).Header.ToString()); - - return true; - } - - protected override void Save() - { - SelectedView.SaveData(); - } - private void AddView(AccordionItem pTabItem, BeWoView pView) { pView.VerticalAlignment = VerticalAlignment.Top; @@ -244,7 +242,6 @@ namespace BeWo.View.Master _OpenViews[pTabItem.Header.ToString()] = pView; SetView(pView); } - private void SetView(BeWoView newView) { if (newView == null || Equals(newView, SelectedView)) return; @@ -256,7 +253,6 @@ namespace BeWo.View.Master SelectedView = newView; } } - private void GenerateNewView(AccordionItem accordionItem) { if (accordionItem == null) @@ -458,7 +454,6 @@ namespace BeWo.View.Master throw new ArgumentOutOfRangeException(nameof(accordionItem)); } - private void CheckMandatorVM(Action callbackAddView) { if (MandatorVM is object) @@ -496,7 +491,6 @@ namespace BeWo.View.Master return null; } - private AccordionItem searchAccordionItem(AccordionItem accordion, string header) { if (accordion is null)