Files
BeWoPlaner/BeWo/View/Master/AdministrationView.xaml.cs
2020-08-17 15:50:00 +02:00

396 lines
18 KiB
C#

using System;
using System.Collections.Generic;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media;
using BeWo.SchulbegleitenderDienst.View;
using BS.Shared;
using BS.Shared.Extensions;
using BeWo.ServiceProxy;
using BeWo.View.Detail;
using BeWo.ViewModel;
using BeWo.ViewModel.ListViewModel;
using DevExpress.Xpf.Accordion;
namespace BeWo.View.Master
{
public partial class AdministrationView
{
#region Fields
private readonly Dictionary<String, BeWoView> _OpenViews = new Dictionary<String, BeWoView>();
private BeWoView _SelectedView;
#endregion
#region Konstruktor
public AdministrationView()
{
InitializeComponent();
//GenerateNewView(TabitemMandator);
Root.SelectedItem = TabitemMandator;
this.Loaded += AdministrationView_Loaded;
MouseMove += (s, e) =>
{
var p = e.GetPosition(btnSave);
if (p.X >= 0 && p.X < btnSave.ActualWidth && p.Y >= 0 && p.Y < btnSave.ActualHeight)
{
Root.Focus();
}
};
#region Rechte
if (!BeWoApp.LoggedOnUser.HasRight(UserRightType.AssessmentSheet_View))
{
TabitemAssessmentSheetValues.Visibility = Visibility.Collapsed;
TabitemAssessmentSheetCategories.Visibility = Visibility.Collapsed;
}
if (!BeWoApp.LoggedOnUser.HasRight(UserRightType.AdditionalService_View))
{
TabitemAdditionalServices.Visibility = Visibility.Collapsed;
TabitemAdditionalServiceRegions.Visibility = Visibility.Collapsed;
}
TabitemAuszahlungsarten.Visibility = BeWoApp.LoggedOnUser.HasRight(UserRightType.OvertimeView)
? Visibility.Visible
: Visibility.Collapsed;
if (!BeWoApp.AppSettings.IsMedicationAllowed)
{
TabitemMedikamentenarten.Visibility = Visibility.Collapsed;
}
if (!BeWoApp.LoggedOnUser.HasRight(UserRightType.TextbausteineAlleAnsehen) &&
!BeWoApp.LoggedOnUser.HasRight(UserRightType.TextbausteineAlleBearbeiten))
{
TabitemTextbausteine.Visibility = Visibility.Collapsed;
}
if (BeWoApp.Mandator != null && BeWoApp.Mandator.AllowSbd)
{
TabitemSbd.Visibility = Visibility.Visible;
}
else
{
TabitemSbd.Visibility = Visibility.Collapsed;
}
#endregion
}
private void AdministrationView_Loaded(object sender, RoutedEventArgs e)
{
ExpandItems();
}
private void ExpandItems()
{
if (!String.IsNullOrEmpty(BeWoApp.AppSettings.ExpandedAdministrationItems))
{
foreach (AccordionItem item in Root.Items)
{
item.IsExpanded = false;
if (BeWoApp.AppSettings.ExpandedAdministrationItems.Contains(":" + item.Header))
{
item.ExpandSubtree();
item.IsExpanded = true;
}
}
}
else
{
//foreach (AccordionItem item in Root.Items)
//{
// item.IsExpanded = true;
//}
}
}
#endregion
#region Events
private void Tabitem_Selected(object sender, RoutedEventArgs e)
{
if (!(sender is AccordionItem selectedAccordionItem))
return;
if (_OpenViews.ContainsKey(selectedAccordionItem.Header.ToString()))
SetView(_OpenViews[selectedAccordionItem.Header.ToString()]);
else
GenerateNewView(selectedAccordionItem);
}
#endregion
#region Propeties
public override bool IsDirty => SelectedView != null &&
SelectedView.IsDirty;
public BeWoView SelectedView
{
get => _SelectedView;
set
{
if (value == null) return;
_SelectedView = value;
ContentBorder.Child = value;
}
}
internal override DependencyObject ValidationOnSaveRootElement =>
SelectedView.ValidationOnSaveRootElement;
#endregion
#region Methoden
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;
if (ActualHeight > 120 && !(pView is MandatorView))
{
pView.MaxHeight = ActualHeight - 120;
}
_OpenViews.Add(pTabItem.Header.ToString(), pView);
SetView(pView);
}
private void SetView(BeWoView newView)
{
if (newView == null || Equals(newView, SelectedView)) return;
newView.Margin = new Thickness(0);
if (ContentBorder.Child == null)
SelectedView = newView;
else if (DoSaveCheck())
SelectedView = newView;
}
private void GenerateNewView(AccordionItem accordionItem)
{
if (accordionItem == null)
return;
switch (accordionItem.Name)
{
case nameof(TabitemMandator):
ServiceFacade.DoAccountingServiceAsync(s => s.LoadInvoiceNumber(),
iv => ServiceFacade.DoOperationsServiceAsync(
s => s.GetMandator(),
m =>
this.Dispatch(() => AddView(TabitemMandator,
new MandatorView(new MandatorVM(new InvoiceNumberVM(iv), m))))));
return;
case nameof(TabitemQualificationTypes):
VMFactory.CreateValueListVMAsync(ValueListEntryType.StaffQualificationsType,
r => this.Dispatch(() => AddView(TabitemQualificationTypes, new ValueListView(r))));
return;
case nameof(TabitemQualifikationsbedarf):
VMFactory.CreateValueListVMAsync(ValueListEntryType.QualifikationsBedarf,
r => this.Dispatch(() => AddView(TabitemQualifikationsbedarf, new ValueListView(r))));
return;
case nameof(TabitemAbsenceCategories):
VMFactory.CreateAbsenceReasonListVMAsync(r =>
this.Dispatch(() => AddView(TabitemAbsenceCategories, new AbsenceReasonView(r))));
return;
case nameof(TabitemDisablityTypes):
VMFactory.CreateValueListVMAsync(ValueListEntryType.DisabilityType,
r => this.Dispatch(() => AddView(TabitemDisablityTypes, new ValueListView(r))));
return;
case nameof(TabitemEmploymentTypes):
VMFactory.CreateEmploymentTypeListVMAsync(r =>
this.Dispatch(() => AddView(TabitemEmploymentTypes, new EmploymentTypeView(r))));
return;
case nameof(TabitemCustomerCareTypes):
VMFactory.CreateValueListVMAsync(ValueListEntryType.CustomerCareType,
r => this.Dispatch(() => AddView(TabitemCustomerCareTypes, new ValueListView(r))));
return;
case nameof(TabitemTerminationReasons):
VMFactory.CreateValueListVMAsync(ValueListEntryType.TerminationReasonType,
r => this.Dispatch(() => AddView(TabitemTerminationReasons, new ValueListView(r))));
return;
case nameof(TabitemPlacementObjectives):
VMFactory.CreateValueListVMAsync(ValueListEntryType.PlacementObjectiveType,
r => this.Dispatch(() => AddView(TabitemPlacementObjectives, new ValueListView(r))));
return;
case nameof(TabitemTitles):
VMFactory.CreateValueListVMAsync(ValueListEntryType.TitleType,
r => this.Dispatch(() => AddView(TabitemTitles, new ValueListView(r))));
return;
case nameof(TabitemFunctions):
VMFactory.CreateValueListVMAsync(ValueListEntryType.FunctionType,
personFunctionList => VMFactory.CreateValueListVMAsync(
ValueListEntryType.OrganisationFunctionType,
orgFunctionList =>
this.Dispatch(() => AddView(TabitemFunctions,
new EnvironmentRoleView(personFunctionList, orgFunctionList)))));
return;
case nameof(TabitemNationality):
VMFactory.CreateValueListVMAsync(ValueListEntryType.Nationality,
natList =>
this.Dispatch(() => AddView(TabitemNationality, new NationalityView(natList))));
return;
case nameof(TabitemAufenthaltsstatus):
VMFactory.CreateValueListVMAsync(ValueListEntryType.Aufenthaltsstatus,
orgList =>
this.Dispatch(() => AddView(TabitemAufenthaltsstatus, new AufenthaltsView(orgList))));
return;
case nameof(TabitemFinazCategories):
VMFactory.CreateValueListVMAsync(ValueListEntryType.AccountingTransactionType,
r => this.Dispatch(() => AddView(TabitemFinazCategories, new ValueListView(r))));
return;
case nameof(TabitemServiceCategories):
VMFactory.CreateServiceCategoryListVMAsync(r =>
this.Dispatch(() => AddView(TabitemServiceCategories, new ServiceCategoryView(r))));
return;
case nameof(TabitemServiceDescriptions):
VMFactory.CreateServiceDescriptionListVMAsync(r =>
this.Dispatch(() => AddView(TabitemServiceDescriptions, new ServiceDescriptionView(r))));
return;
case nameof(TabitemTextbausteine):
VMFactory.CreateTextModuleListVMAsync(
r => this.Dispatch(() => AddView(TabitemTextbausteine, new TextbausteinView(r, true))), true,
true);
return;
case nameof(TabitemMedikamentenarten):
VMFactory.CreateMedArtListVMAsync(r =>
this.Dispatch(() => AddView(TabitemMedikamentenarten, new MedikamentenartenView(r))));
return;
case nameof(TabitemRoles):
VMFactory.CreateValueListVMAsync(ValueListEntryType.StaffRoleType,
r => this.Dispatch(() => AddView(TabitemRoles, new ValueListView(r))));
return;
case nameof(TabitemEnvironmentRoles):
VMFactory.CreateValueListVMAsync(ValueListEntryType.EnvironmentPersonType,
personList => VMFactory.CreateValueListVMAsync(ValueListEntryType.RoleInOrganisationType,
roleInOrgList => VMFactory.CreateValueListVMAsync(
ValueListEntryType.EnvironmentOrganisationType,
orgList => VMFactory.CreateValueListVMAsync(ValueListEntryType.RoleInFamily,
roleInFamily => this.Dispatch(() => AddView(TabitemEnvironmentRoles,
new EnvironmentRoleView(personList, orgList, roleInOrgList, roleInFamily)))))));
return;
case nameof(TabitemActivityFocus):
VMFactory.CreateValueListVMAsync(ValueListEntryType.StaffActivityFocusType,
r => this.Dispatch(() => AddView(TabitemActivityFocus, new ValueListView(r))));
return;
case nameof(TabitemResourceCategories):
VMFactory.CreateValueListVMAsync(ValueListEntryType.ResourceCategory,
r => this.Dispatch(() => AddView(TabitemResourceCategories, new ValueListView(r))));
return;
case nameof(TabitemResources):
VMFactory.CreateResourceListVMAsync(r =>
this.Dispatch(() => AddView(TabitemResources, new RessourceView(r))));
return;
case nameof(TabitemGoalcategories):
VMFactory.CreateGoalCategoryVMAsync(r =>
this.Dispatch(() => AddView(TabitemGoalcategories, new MassnahmenTreeViewView(r))));
return;
case nameof(TabitemNews):
ServiceFacade.DoEmployeeServiceAsync(s => s.GetAllNewsItems(),
cb => this.Dispatch(() => AddView(TabitemNews, new NewsItemView(new NewsItemListVM(cb)))));
return;
case nameof(TabitemAssessmentSheetValues):
VMFactory.CreateAssessmentSheetValueListVM(m =>
this.Dispatch(() => AddView(TabitemAssessmentSheetValues, new AssessmentSheetValueView(m))));
return;
case nameof(TabitemAssessmentSheetCategories):
VMFactory.CreateAssessmentSheetCategoryListVM(m => this.Dispatch(() =>
AddView(TabitemAssessmentSheetCategories, new AssessmentSheetCategoryView(m))));
return;
case nameof(TabitemAdditionalServices):
VMFactory.CreateAdditionalServiceListVMAsync(r =>
this.Dispatch(() => AddView(TabitemAdditionalServices, new AdditionalServiceAddView(r))));
return;
case nameof(TabitemAdditionalServiceRegions):
VMFactory.CreateAdditionalServiceRegionListVMAsync(r =>
this.Dispatch(
() => AddView(TabitemAdditionalServiceRegions, new AdditionalServiceRegionView(r))));
return;
case nameof(TabitemAuszahlungsarten):
VMFactory.CreateAuszahlungsartenListVMAsync(r =>
this.Dispatch(() => AddView(TabitemAuszahlungsarten, new AuszahlungsartenAddView(r))));
return;
case nameof(TabitemDokumenttype):
VMFactory.CreateValueListVMAsync(ValueListEntryType.DocumentType,
r => this.Dispatch(() => AddView(TabitemDokumenttype, new DokumentationstypView(r))));
return;
case nameof(TabitemSbd):
VMFactory.CreateSbdAdminVMAsync(r => this.Dispatch(() => AddView(TabitemSbd, new SbdAdminView(r))));
return;
case nameof(TabitemContracttypes):
VMFactory.CreateValueListVMAsync(ValueListEntryType.ContractType,
r => this.Dispatch(() => AddView(TabitemContracttypes, new ValueListView(r))));
return;
case nameof(TabitemBudgets):
VMFactory.CreateBudgetListVMAsync(r =>
this.Dispatch(() => AddView(TabitemBudgets, new BudgetView(r))));
return;
case nameof(TabitemDienste):
VMFactory.CreateDienstListVMAsync(r =>
this.Dispatch(() => AddView(TabitemDienste, new DienstView(r))));
return;
case nameof(TabitemNotizenkategorie):
VMFactory.CreateValueListVMAsync(ValueListEntryType.NotizenKategorieEmployee,
notizEmpList => VMFactory.CreateValueListVMAsync(ValueListEntryType.NotizenKategorieCustomer,
notizCosList => this.Dispatch(() => AddView(TabitemNotizenkategorie, new NotizenKategorieView(notizEmpList, notizCosList)))));
return;
case nameof(TabitemRatingTypes):
VMFactory.CreateRatingTypeListVMAsync(r =>
this.Dispatch(() => AddView(TabitemRatingTypes, new RatingTypeView(r))));
return;
}
throw new ArgumentOutOfRangeException(nameof(accordionItem));
}
#endregion
}
}