Files
BeWoPlaner/BeWo/Scheduler/View/NewSchedulerView.xaml.cs

2352 lines
86 KiB
C#

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
using System.Windows.Data;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Navigation;
using BeWo.Annotations;
using BeWo.Core;
using BeWo.Core.Service;
using BeWo.Scheduler.Converter;
using BeWo.Scheduler.ViewModel;
using BeWo.ServiceProxy;
using BS.Shared;
using BS.Shared.Core;
using BS.Shared.DataContracts;
using BS.Shared.DataContracts.Compact;
using BS.Shared.Extensions;
using BS.Shared.Translation;
using DevExpress.Utils.Extensions;
using DevExpress.Xpf.Bars;
using DevExpress.Xpf.Editors;
using DevExpress.Xpf.Scheduler;
using DevExpress.Xpf.Scheduler.Reporting;
using DevExpress.XtraScheduler;
using Appointment = DevExpress.XtraScheduler.Appointment;
using ColorConverter = System.Windows.Media.ColorConverter;
using DateTime = System.DateTime;
using InplaceEditorEventArgs = DevExpress.Xpf.Scheduler.InplaceEditorEventArgs;
using SchedulerControl = DevExpress.Xpf.Scheduler.SchedulerControl;
namespace BeWo.Scheduler.View
{
public partial class NewSchedulerView : INotifyPropertyChanged
{
private bool _IsEmployeeBrushVisible;
public bool IsEmployeeBrushVisible
{
get => _IsEmployeeBrushVisible;
set
{
_IsEmployeeBrushVisible = value;
OnPropertyChanged(nameof(IsEmployeeBrushVisible));
}
}
private bool _IsAbsenceTimeVisible;
public bool IsAbsenceTimeVisible
{
get => _IsAbsenceTimeVisible;
set
{
_IsAbsenceTimeVisible = value;
OnPropertyChanged(nameof(IsAbsenceTimeVisible));
}
}
public bool IsInCustomerViewMode { get; set; }
public event PropertyChangedEventHandler PropertyChanged;
private SchedulerPrintingSettings _PrintingSettings = new SchedulerPrintingSettings();
public NewSchedulerViewModel ViewModel { get; set; }
[NotifyPropertyChangedInvocator]
protected void OnPropertyChanged(string propertyName)
{
var handler = PropertyChanged;
handler?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
public bool ZeigeNurMeineTermine
{
get => BeWoApp.AppSettings.ZeigeNurMeineTermine;
set
{
if(BeWoApp.AppSettings.ZeigeNurMeineTermine != value)
{
BeWoApp.AppSettings.ZeigeNurMeineTermine = value;
BeWoApp.SaveAppSettings();
OnPropertyChanged(nameof(ZeigeNurMeineTermine));
}
}
}
private List<CompactEmployeeDC> _AllEmployees;
public List<CompactEmployeeDC> AllEmployees
{
get => _AllEmployees ?? (_AllEmployees = new List<CompactEmployeeDC>());
set
{
if(!ListEquals(_AllEmployees, value))
{
_AllEmployees = value;
OnPropertyChanged(nameof(AllEmployees));
}
}
}
private List<CompactEmployeeDC> _GefilterteMitarbeiter;
public List<CompactEmployeeDC> GefilterteMitarbeiter
{
get => _GefilterteMitarbeiter ?? (_GefilterteMitarbeiter = new List<CompactEmployeeDC>(AllEmployees));
set
{
if(!ListEquals(_GefilterteMitarbeiter, value))
{
_GefilterteMitarbeiter = value;
_GefilterteMitarbeiter.Sort((x, y) => string.Compare(x.LastName + ", " + x.FirstName, y.LastName + ", " + y.FirstName, StringComparison.Ordinal));
OnPropertyChanged(nameof(GefilterteMitarbeiter));
}
}
}
private List<CompactCustomerDC> _GefilterteKlienten;
public List<CompactCustomerDC> GefilterteKlienten
{
get => _GefilterteKlienten ?? (_GefilterteKlienten = new List<CompactCustomerDC>(AllCustomers));
set
{
if(!ListEquals(_GefilterteKlienten, value))
{
_GefilterteKlienten = value;
_GefilterteKlienten.Sort((x, y) => string.Compare(x.LastName + ", " + x.FirstName, y.LastName + ", " + y.FirstName, StringComparison.Ordinal));
OnPropertyChanged(nameof(GefilterteKlienten));
}
}
}
private List<CompactCustomerDC> _AllCustomers;
public List<CompactCustomerDC> AllCustomers
{
get => _AllCustomers ?? (_AllCustomers = new List<CompactCustomerDC>());
set
{
if(!ListEquals(_AllCustomers, value))
{
_AllCustomers = value;
OnPropertyChanged(nameof(AllCustomers));
}
}
}
private List<ResourceDC> _AllResources;
public List<ResourceDC> AllResources
{
get => _AllResources ?? (_AllResources = new List<ResourceDC>());
set
{
if(!ListEquals(_AllResources, value))
{
_AllResources = value;
OnPropertyChanged(nameof(AllResources));
}
}
}
private List<CompactCustomerDC> _CustomerList;
public List<CompactCustomerDC> CustomerList
{
get => _CustomerList ?? (_CustomerList = new List<CompactCustomerDC>());
set
{
if(!ListEquals(_CustomerList, value))
{
_CustomerList = value;
_CustomerList.Sort((x, y) => string.Compare(x.LastName + ", " + x.FirstName, y.LastName + ", " + y.FirstName, StringComparison.Ordinal));
OnPropertyChanged(nameof(CustomerList));
}
}
}
private int _TimelineDayCount;
private SchedulerViewType _CurrentViewType;
private Dictionary<ValueListEntryDC, List<ResourceDC>> _Category2ResourcesDictionary;
public Dictionary<ValueListEntryDC, List<ResourceDC>> Category2ResourcesDictionary
{
get => _Category2ResourcesDictionary ?? (_Category2ResourcesDictionary = new Dictionary<ValueListEntryDC, List<ResourceDC>>());
set
{
if(!CheckCats2ResourcesForEqualitiy(value))
{
_Category2ResourcesDictionary = value;
AllResources = new List<ResourceDC>();
value.DoForEach(d => AllResources.AddRange(d.Value));
OnPropertyChanged(nameof(Category2ResourcesDictionary));
}
}
}
private bool CheckCats2ResourcesForEqualitiy(Dictionary<ValueListEntryDC, List<ResourceDC>> dic2)
{
if(_Category2ResourcesDictionary == null && dic2 != null || dic2 == null && _Category2ResourcesDictionary != null)
{
return false;
}
return _Category2ResourcesDictionary == null && dic2 == null || _Category2ResourcesDictionary != null && dic2 != null && _Category2ResourcesDictionary.Count == dic2.Count && _Category2ResourcesDictionary.Except(dic2).Any();
}
private static bool ListEquals<T>(IReadOnlyCollection<T> list1, List<T> list2)
{
if(list1 == null && list2 == null)
{
return true;
}
if(list1 == null && list2 != null || list1 != null && list2 == null)
{
return false;
}
return list1.Count == list2.Count && list1.All(list2.Contains);
}
private List<CompactEmployeeDC> _SelectedEmployees = new List<CompactEmployeeDC>();
private List<CompactCustomerDC> _SelectedCustomers = new List<CompactCustomerDC>();
private List<ResourceDC> _SelectedResources = new List<ResourceDC>();
public List<CompactEmployeeDC> SelectedEmployees
{
get => _SelectedEmployees;
set
{
if(!ListEquals(_SelectedEmployees, value))
{
_SelectedEmployees = value;
_SelectedEmployees.Sort((x, y) => string.Compare(x.LastName + ", " + x.FirstName, y.LastName + ", " + y.FirstName, StringComparison.Ordinal));
if (value.Equals(AllEmployees))
{
AlleMitarbeiterCB.IsChecked = true;
}
ZeigeNurMeineTermine = value.Count == 1 && value.Contains(BeWoApp.CompactLoggedOnEmployee);
OnPropertyChanged(nameof(SelectedEmployees));
OnPropertyChanged(nameof(SelectedItems));
}
}
}
public List<CompactCustomerDC> SelectedCustomers
{
get => _SelectedCustomers;
set
{
if(!ListEquals(_SelectedCustomers, value))
{
_SelectedCustomers = value;
_SelectedCustomers.Sort((x, y) => string.Compare(x.LastName + ", " + x.FirstName, y.LastName + ", " + y.FirstName, StringComparison.Ordinal));
if(NurMeineKlientenCB.IsChecked.HasValue && NurMeineKlientenCB.IsChecked.Value && value.Equals(GefilterteKlienten) || value.Equals(AllCustomers))
{
AlleKlientenCB.IsChecked = true;
}
OnPropertyChanged(nameof(SelectedCustomers));
OnPropertyChanged(nameof(SelectedItems));
}
}
}
public List<ResourceDC> SelectedResources
{
get => _SelectedResources;
set
{
if(!ListEquals(_SelectedResources, value))
{
_SelectedResources = value;
if(value.Equals(AllResources))
{
AlleRessourcenCB.IsChecked = true;
}
OnPropertyChanged(nameof(SelectedResources));
OnPropertyChanged(nameof(SelectedItems));
}
}
}
public IEnumerable<IDataContract> SelectedItems
{
get
{
var erg = new List<IDataContract>();
erg.AddRange(SelectedEmployees);
erg.AddRange(SelectedCustomers);
erg.AddRange(SelectedResources);
return erg;
}
}
public IEnumerable<IDataContract> AllItems
{
get
{
var erg = new List<IDataContract>();
erg.AddRange(GefilterteKlienten);
erg.AddRange(AllResources);
return erg;
}
}
public static bool IgnoreChangeEvents;
private List<CompactTeamDC> _EmployeesTeams = new List<CompactTeamDC>();
private string _Requests;
public string Requests
{
get => _Requests ?? (_Requests = "keine Benachrichtigungen");
set
{
_Requests = value;
OnPropertyChanged(nameof(Requests));
}
}
public static TimeSpan FetchPadding = TimeSpan.FromDays(14);
private TimeInterval _LastFetchedInterval = new TimeInterval();
public long CustomerOidToPreselect { get; set; }
//private static string[] outlookCalendarPaths;
//public static string[] OutlookCalendarPaths
//{
// get
// {
// if (outlookCalendarPaths != null)
// return outlookCalendarPaths;
// try
// {
// outlookCalendarPaths = OutlookExchangeHelper.GetOutlookCalendarPaths();
// }
// catch
// {
// outlookCalendarPaths = new string[0];
// }
// return outlookCalendarPaths;
// }
//}
// KONSTRUKTOR
public NewSchedulerView(long customerOid)
{
// Kalenderaufruf aus dem CustomerView2 heraus
CustomerOidToPreselect = customerOid;
ConstructObject();
}
public NewSchedulerView()
{
ConstructObject();
}
private void ConstructObject()
{
//WriteToDebugLog("Beginning");
IsEmployeeBrushVisible = true;
if (BeWoApp.LoggedOnUser.HasRight(UserRightType.KalenderMitarbeitertermineAnsehen))
{
Cache.GetInstance().GetAllActiveEmployeesCompact(liste => this.Dispatch(() =>
{
AllEmployees = liste;
GefilterteMitarbeiter = liste;
}));
}
else
{
CompactEmployeeDC compact = null;
ServiceFacade.DoEmployeeServiceSync(s => compact = s.LoadCompactEmployee(BeWoApp.LoggedOnEmployee.EmployeeOid.Value));
AllEmployees = new List<CompactEmployeeDC> { compact };
GefilterteMitarbeiter = new List<CompactEmployeeDC> { compact };
}
if (BeWoApp.LoggedOnUser.HasRight(UserRightType.Customer_ViewMyCustomers) && !BeWoApp.LoggedOnUser.HasRight(UserRightType.CustomerView_View))
{
var cusRels = BeWoApp.LoggedOnEmployee.RelatedCustomers;
AllCustomers = cusRels.Select(cr => cr.Customer).ToList();
CustomerList = AllCustomers;
GefilterteKlienten = AllCustomers;
}
else
{
Cache.GetInstance().GetAllActiveCustomersCompact(liste => this.Dispatch(() =>
{
var erg = (!BeWoApp.LoggedOnUser.HasRight(UserRightType.KalenderKliententermineAlleAnsehen) ? liste.Where(c => c.IsRelatedToEmployee).ToList() : liste).Where(c => c.IsArchived == false).ToList();
AllCustomers = erg;
CustomerList = AllCustomers;
GefilterteKlienten = AllCustomers;
Scheduler.UpdateLayout();
}));
}
Cache.GetInstance().GetCategories2ResourcesDictionary(dict => this.Dispatch(() =>
{
Category2ResourcesDictionary = dict;
}));
ServiceFacade.DoEmployeeServiceSync(es => _EmployeesTeams = es.GetTeamOidsByEmployee(BeWoApp.LoggedOnEmployee.EmployeeOid.Value));
InitializeComponent();
InitViewModel();
InitScheduler();
Scheduler.Storage.AppointmentStorage.ResourceSharing = false;
DataContext = this;
_CurrentViewType = Scheduler.ActiveViewType;
EditorLocalizer.Active = new GermanEditorLocalizer();
InitRights();
foreach (var item in from object item in TabControl.Items let ti = (TabItem)item where ti.Visibility.Equals(Visibility.Visible) select item)
{
TabControl.SelectedIndex = TabControl.Items.IndexOf(item);
break;
}
//WriteToDebugLog("Done");
}
//private void Synchronize()
//{
// var synchronizer = new OutlookExportSynchronizer(Scheduler.Storage.GetCoreStorage());
// if (OutlookCalendarPaths.Length <= 0) return;
// ((ISupportCalendarFolders) synchronizer).CalendarFolderName = OutlookCalendarPaths[0];
// synchronizer.ForeignIdFieldName = "OutlookEntryId";
// synchronizer.AppointmentSynchronizing += (sender, args) =>
// {
// };
// synchronizer.Synchronize();
//}
private bool _IstErsterAufruf = true;
#region InitViewModel
private void InitViewModel()
{
//WriteToDebugLog("Beginning");
ViewModel = new NewSchedulerViewModel();
ViewModel.ViewModelChanged += ViewModel_ViewModelChanged;
ViewModel.ViewModelChanged += UpdateRequestStringEvent;
//WriteToDebugLog("Done");
}
private void ViewModel_ViewModelChanged(object sender, EventArgs<ISchedulerViewModel> e)
{
this.Dispatch(() =>
{
//WriteToDebugLog("Beginning");
UpdateDataSource(e.Data);
if (_IstErsterAufruf)
{
if (MainControl.HatNeueTermine)
{
FensterOeffnen();
}
_IstErsterAufruf = false;
}
//WriteToDebugLog("Done");
});
}
private void InitScheduler()
{
//WriteToDebugLog("Beginning");
Scheduler.Start = DateTime.Now;
_TimelineDayCount = 0;
Scheduler.DayView.NavigationButtonVisibility = NavigationButtonVisibility.Always;
Scheduler.DayView.AppointmentDisplayOptions.ShowRecurrence = true;
Scheduler.DayView.AppointmentDisplayOptions.ShowReminder = true;
Scheduler.DayView.ResourcesPerPage = 3;
Scheduler.WorkWeekView.ShowFullWeek = false;
Scheduler.WorkWeekView.ShowWorkTimeOnly = false;
Scheduler.WorkWeekView.NavigationButtonVisibility = NavigationButtonVisibility.Always;
Scheduler.WorkWeekView.ResourcesPerPage = 3;
Scheduler.WeekView.NavigationButtonVisibility = NavigationButtonVisibility.Always;
Scheduler.WeekView.ResourcesPerPage = 3;
Scheduler.MonthView.NavigationButtonVisibility = NavigationButtonVisibility.Always;
Scheduler.MonthView.ResourcesPerPage = 3;
Scheduler.TimelineView.NavigationButtonVisibility = NavigationButtonVisibility.Always;
Scheduler.TimelineView.ResourcesPerPage = 0;
//WriteToDebugLog("Done");
}
private void InitRights()
{
MitarbieterTabItem.Visibility = BeWoApp.LoggedOnUser.HasRight(UserRightType.KalenderMitarbeitertermineAnsehen) ? Visibility.Visible : Visibility.Collapsed;
RessourcenTabItem.Visibility = Visibility.Visible;
MitarbeiterEbenenCheckBox.Visibility = MitarbieterTabItem.Visibility;
RessourcenEbenenCheckBox.Visibility = RessourcenTabItem.Visibility;
}
private void UpdateDataSource(ISchedulerViewModel vm)
{
try
{
//WriteToDebugLog("Beginning");
IgnoreChangeEvents = true;
Scheduler.Storage.BeginUpdate();
UpdateCustomFieldMappings(vm);
Scheduler.Storage.EndUpdate();
Scheduler.Storage.AppointmentStorage.DataSource = vm.Appointments;
Scheduler.Storage.BeginUpdate();
UpdateSchedulerSettings();
foreach (var item in Scheduler.Storage.AppointmentStorage.Items)
{
var bapp = item.GetSourceObject(Scheduler.GetCoreStorage()) as IBeWoAppointment;
if (item.IsRecurring)
{
var ausnahmen = item.GetExceptions();
foreach (var exc in ausnahmen)
{
var b = exc.GetSourceObject(Scheduler.GetCoreStorage()) as IBeWoAppointment;
if (b?.CustomFields == null)
{
continue;
}
foreach (var field in b.CustomFields)
{
exc.CustomFields[field.Key] = field.Value;
}
}
}
if (bapp?.CustomFields == null)
{
continue;
}
foreach (var field in bapp.CustomFields)
{
item.CustomFields[field.Key] = field.Value;
}
}
}
catch (Exception e)
{
throw e;
}
finally
{
Scheduler.Storage.EndUpdate();
IgnoreChangeEvents = false;
//WriteToDebugLog("Done");
}
}
private void UpdateSchedulerSettings()
{
//WriteToDebugLog("Beginning");
var settings = ViewModel.GetActiveSettings();
Scheduler.Start = settings.StartDate;
var starttimeInterval = settings.StartDate.Date;
starttimeInterval = starttimeInterval.AddHours(Scheduler.WorkWeekView.WorkTime.Start.Hours);
settings.ViewType = ViewTypeConvert.ToAppointmentViewType(_CurrentViewType);
switch (settings.ViewType)
{
case AppointmentViewType.Day:
Scheduler.ActiveViewType = SchedulerViewType.Day;
Scheduler.ActiveView.GotoTimeInterval(new TimeInterval(starttimeInterval, new TimeSpan(8, 0, 0)));
Scheduler.DayView.DayCount = settings.DayViewCount;
break;
case AppointmentViewType.Week:
Scheduler.ActiveViewType = SchedulerViewType.Week;
Scheduler.ActiveView.GotoTimeInterval(new TimeInterval(starttimeInterval, new TimeSpan(8, 0, 0)));
break;
case AppointmentViewType.Month:
Scheduler.ActiveViewType = SchedulerViewType.Month;
break;
case AppointmentViewType.WorkWeek:
Scheduler.ActiveViewType = SchedulerViewType.WorkWeek;
Scheduler.ActiveView.GotoTimeInterval(new TimeInterval(starttimeInterval, new TimeSpan(8, 0, 0)));
break;
case AppointmentViewType.Timeline:
Scheduler.ActiveViewType = SchedulerViewType.Timeline;
Scheduler.TimelineView.ResourcesPerPage = settings.TimelineResourceCount;
Scheduler.TimelineView.IntervalCount = settings.TimelineIntervalCount;
break;
}
UpdateOptionPanel();
try
{
Scheduler.GroupType = settings.GroupByResource ? SchedulerGroupType.Resource : SchedulerGroupType.None;
Scheduler.OptionsCustomization.AllowAppointmentCreate = UsedAppointmentType.Custom;
Scheduler.OptionsCustomization.AllowAppointmentDrag = UsedAppointmentType.Custom;
Scheduler.OptionsCustomization.AllowAppointmentDelete = UsedAppointmentType.Custom;
Scheduler.OptionsCustomization.AllowAppointmentEdit = UsedAppointmentType.Custom;
Scheduler.OptionsCustomization.AllowAppointmentDragBetweenResources = UsedAppointmentType.Custom;
}
catch (Exception)
{
MessageBox.Show("Ein Fehler bei der Darstellung ist aufgetreten.", "Fehler", MessageBoxButton.OK, MessageBoxImage.Error);
}
//WriteToDebugLog("Done");
}
private void UpdateCustomFieldMappings(ISchedulerViewModel vm)
{
//WriteToDebugLog("Beginning");
Scheduler.Storage.AppointmentStorage.CustomFieldMappings.Clear();
vm.AddCustomFieldsMapping(Scheduler.Storage);
//WriteToDebugLog("Done");
}
#endregion
public CheckBoxConverter CheckBoxConverter => Resources["CheckBoxConverter"] as CheckBoxConverter;
#region Filterauswahl
private void AlleMitarbeiterCB_OnClick(object sender, RoutedEventArgs e)
{
var cb = (CheckBox) sender;
if (!cb.IsChecked.HasValue)
{
return;
}
SelectedEmployees = cb.IsChecked.Value ? new List<CompactEmployeeDC>(AllEmployees) : new List<CompactEmployeeDC>();
if(SelectedEmployees.Count > 1)
{
ZeigeNurMeineTermine = false;
}
}
private void MitarbeiterListe_OnClick(object sender, RoutedEventArgs e)
{
var cb = (CheckBox) sender;
if (CheckBoxConverter != null && cb.DataContext is CompactEmployeeDC selectedEmployee)
{
CheckBoxConverter.AktuellerMitarbeiter = selectedEmployee;
}
}
private void AlleRessourcenCB_OnClick(object sender, RoutedEventArgs e)
{
var cb = (CheckBox) sender;
if (!cb.IsChecked.HasValue)
{
return;
}
SelectedResources = cb.IsChecked.Value ? new List<ResourceDC>(AllResources) : new List<ResourceDC>();
if (CheckBoxConverter != null && SelectedResources != null)
{
CheckBoxConverter.SelektierteRessourcen = SelectedResources;
UpdateVM(true);
}
}
private void RessourcenTV_OnClick(object sender, RoutedEventArgs e)
{
var cb = (CheckBox) sender;
if (CheckBoxConverter != null && cb.DataContext is ResourceDC selectedResource)
{
CheckBoxConverter.AktuelleRessource = selectedResource;
}
}
private void AlleKlientennCB_OnClick(object sender, RoutedEventArgs e)
{
var cb = (CheckBox) sender;
if (!cb.IsChecked.HasValue) return;
if (NurMeineKlientenCB.IsChecked.HasValue && NurMeineKlientenCB.IsChecked.Value)
{
SelectedCustomers = cb.IsChecked.Value ? new List<CompactCustomerDC>(GefilterteKlienten) : new List<CompactCustomerDC>();
}
else
{
SelectedCustomers = cb.IsChecked.Value ? new List<CompactCustomerDC>(AllCustomers) : new List<CompactCustomerDC>();
}
}
private void KlientenListe_OnClick(object sender, RoutedEventArgs e)
{
var cb = (CheckBox) sender;
if(CheckBoxConverter != null && cb.DataContext is CompactCustomerDC selectedCustomer)
{
CheckBoxConverter.AktuellerKlient = selectedCustomer;
}
}
private void ListItemCheckedEvent(object sender, RoutedEventArgs e)
{
UpdateVM(true);
}
private void BtnRemoveElement_Click(object sender, RoutedEventArgs e)
{
var selectedDC = ((Button) sender).Tag as IDataContract;
switch(selectedDC)
{
case CompactEmployeeDC _:
var employee = selectedDC as CompactEmployeeDC;
SelectedEmployees.Remove(employee);
OnPropertyChanged(nameof(SelectedEmployees));
if (employee != null && employee.Equals(BeWoApp.CompactLoggedOnEmployee))
{
ZeigeNurMeineTermine = false;
UpdateVM(true);
}
else if (SelectedEmployees.Count == 1 && SelectedEmployees.First().Equals(BeWoApp.CompactLoggedOnEmployee))
{
ZeigeNurMeineTermine = true;
}
break;
case CompactCustomerDC _:
var customer = selectedDC as CompactCustomerDC;
SelectedCustomers.Remove(customer);
OnPropertyChanged(nameof(SelectedCustomers));
break;
case ResourceDC _:
var resource = selectedDC as ResourceDC;
SelectedResources.Remove(resource);
OnPropertyChanged(nameof(SelectedResources));
break;
}
OnPropertyChanged(nameof(SelectedItems));
}
private void ButtonDayView_Click(object sender, RoutedEventArgs e)
{
Scheduler.ActiveViewType = SchedulerViewType.Day;
_CurrentViewType = Scheduler.ActiveViewType;
UpdateOptionPanel();
DayViewOptions.Visibility = Visibility.Visible;
TimelineViewOptions.Visibility = Visibility.Collapsed;
}
private void ButtonMonthView_Click(object sender, RoutedEventArgs e)
{
Scheduler.ActiveViewType = SchedulerViewType.Month;
_CurrentViewType = Scheduler.ActiveViewType;
var interval = Scheduler.ActiveView.GetVisibleIntervals();
Scheduler.ActiveView.SetVisibleIntervals(new TimeIntervalCollection {new TimeInterval(interval.Start, new TimeSpan(35, 0, 0, 0))});
UpdateOptionPanel();
}
private void ButtonWorkWeekView_Click(object sender, RoutedEventArgs e)
{
Scheduler.ActiveViewType = SchedulerViewType.WorkWeek;
_CurrentViewType = Scheduler.ActiveViewType;
UpdateOptionPanel();
}
private void ButtonWeekView_Click(object sender, RoutedEventArgs e)
{
Scheduler.ActiveViewType = SchedulerViewType.Week;
_CurrentViewType = Scheduler.ActiveViewType;
UpdateOptionPanel();
}
private void ButtonTimelineView_Click(object sender, RoutedEventArgs e)
{
Scheduler.ActiveViewType = SchedulerViewType.Timeline;
_CurrentViewType = Scheduler.ActiveViewType;
UpdateOptionPanel();
DayViewOptions.Visibility = Visibility.Collapsed;
TimelineViewOptions.Visibility = Visibility.Visible;
}
private void SpinEditDayViewDayCount_EditValueChanged(object sender, EditValueChangedEventArgs e)
{
if (e.NewValue != null && int.TryParse(e.NewValue.ToString(), out var count) && count > 0)
{
Scheduler.DayView.DayCount = count;
_TimelineDayCount = count;
}
}
private void SpinEditTimelineViewDayCount_EditValueChanged(object sender, EditValueChangedEventArgs e)
{
if (e.NewValue == null || !int.TryParse(e.NewValue.ToString(), out var count))
{
return;
}
if (count > 0)
{
Scheduler.TimelineView.IntervalCount = count;
_TimelineDayCount = count;
}
}
#endregion
private bool _Enabled;
public bool Enabled
{
get => _Enabled;
set
{
_Enabled = value;
OnPropertyChanged("Enabled");
}
}
private void UpdateRequestString()
{
ServiceFacade.DoResourceServiceSync(r => _Liste = r.GetAllOpenAppointmentsForEmployee(BeWoApp.LoggedOnEmployee.EmployeeOid.Value));
var count = 0;
var oidList = new List<long>();
foreach (var termin in _Liste)
{
if (termin.Originator.EmployeeOid == BeWoApp.LoggedOnEmployee.EmployeeOid.Value)
{
foreach (var status in termin.EmployeeList.Where(w => w.Employee.EmployeeOid != BeWoApp.LoggedOnEmployee.EmployeeOid.Value))
{
if (status.IsPChanged && status.ParticipationAnswer != ParticipationAnswer.Offen && status.ParticipationAnswer != ParticipationAnswer.Verstrichen && !oidList.Contains(status.Employee2SchedulerAppointmentOid.Value))
{
oidList.Add(status.Employee2SchedulerAppointmentOid.Value);
count++;
}
}
}
else
{
if (termin.EmployeeList.Any(a => a.Employee.EmployeeOid == BeWoApp.LoggedOnEmployee.EmployeeOid.Value))
{
foreach (var status in termin.EmployeeList.Where(w => w.Employee.EmployeeOid == BeWoApp.LoggedOnEmployee.EmployeeOid.Value))
{
if (!status.IsPChanged && status.ParticipationAnswer == ParticipationAnswer.Offen && status.ParticipationAnswer != ParticipationAnswer.Verstrichen && !oidList.Contains(status.Employee2SchedulerAppointmentOid.Value))
{
oidList.Add(status.Employee2SchedulerAppointmentOid.Value);
count++;
}
}
}
}
}
Enabled = count > 0;
Requests = $"{(count == 0 ? "keine" : count.ToString())} Benachrichtigung{(count == 1 ? "" : "en")}";
}
private List<SchedulerAppointmentDC> _Liste = new List<SchedulerAppointmentDC>();
private void NewSchedulerStorage_AppointmentsChanged(object sender, PersistentObjectsEventArgs e)
{
if (IgnoreChangeEvents)
{
return;
}
//WriteToDebugLog("Appointment changing...");
var appList = e.Objects.Cast<Appointment>().ToList();
if (appList.Any(f => f.CustomFields["IsPrivate"] != null && (bool)f.CustomFields["IsPrivate"]))
{
ShowPrivateAppointmentsCheckBox.IsChecked = true;
}
ViewModel.ActiveAppointmentViewModel.SaveAppointments(Scheduler, appList);
UpdateVM(true);
}
private void NewSchedulerStorage_AppointmentDeleting(object sender, PersistentObjectCancelEventArgs e)
{
//WriteToDebugLog("Appointment deleting");
if (e.Object is Appointment app && app.Type != AppointmentType.ChangedOccurrence)
{
const string msg = "Möchten Sie den gewählten Termin wirklich löschen?";
if (app.Type != AppointmentType.DeletedOccurrence && MessageBox.Show(msg, "BeWoPlaner", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.No)
{
e.Cancel = true;
}
else
{
var appList = new List<Appointment>();
if (app.Type != AppointmentType.ChangedOccurrence)
{
appList.Add(app);
}
ViewModel.ActiveAppointmentViewModel.DeleteAppointments(Scheduler, appList);
}
}
UpdateRequestString();
UpdateVM(true);
}
private void NewSchedulerStorage_AppointmentsInserted(object sender, PersistentObjectsEventArgs e)
{
//WriteToDebugLog("Appointments inserted");
var appList = e.Objects.Cast<Appointment>().ToList();
if(appList.Any(f => f.CustomFields["IsPrivate"] != null && (bool) f.CustomFields["IsPrivate"]))
{
ShowPrivateAppointmentsCheckBox.IsChecked = true;
}
ViewModel.ActiveAppointmentViewModel.InsertAppointments(Scheduler, appList);
UpdateRequestString();
UpdateVM(true);
}
private void Scheduler_EditAppointmentFormShowing(object sender, EditAppointmentFormEventArgs e)
{
var control = (SchedulerControl) sender;
if (_IsNew)
{
var n = SelectedEmployees.Select(item => new Employee2SchedulerAppointmentDC {Employee = item, ParticipationAnswer = ParticipationAnswer.Offen}).ToList();
e.Appointment.CustomFields["EmployeeList"] = n;
e.Appointment.CustomFields["CustomerList"] = new List<CompactCustomerDC>(SelectedCustomers);
e.Appointment.CustomFields["ResourceList"] = new List<ResourceDC>(SelectedResources);
}
var form = ViewModel.GetEditAppointmentForm(control, e.Appointment);
if (form == null)
{
//WriteToDebugLog("Appointment edit form is null!");
if(_IsNew)
{
_IsNew = false;
}
return;
}
e.Form = form;
e.AllowResize = false;
if (_IsNew)
{
_IsNew = false;
}
}
private void SchedulerControl_EditRecurrentAppointmentFormShowing(object sender, EditAppointmentFormEventArgs e) { }
private void Scheduler_PopupMenuShowing(object sender, SchedulerMenuEventArgs e)
{
if (!BeWoApp.LoggedOnUser.HasRight(UserRightType.KalenderMitarbeitertermineAnsehen) || !BeWoApp.LoggedOnUser.HasRight(UserRightType.Mitarbeiterstundenkonto_ViewAll))
{
var verfuegbarkeitMenue = e.Menu.ItemLinks.FirstOrDefault(f => f.GetType() == typeof(BarButtonItemLink) && ((BarButtonItemLink)f).Item.Name.Contains("MitarbeiterVerfuegbarkeitPruefenButtonItem"));
if (verfuegbarkeitMenue != null)
{
e.Menu.ItemLinks.Remove(verfuegbarkeitMenue);
}
}
//if (!BeWoApp.LoggedOnUser.HasRight(UserRightType.KalenderInZeiterfassungUebernehmen))
//{
// var menuitem = e.Menu.ItemLinks.FirstOrDefault(f => f.GetType() == typeof(BarButtonItemLink) && ((BarButtonItemLink)f).Item.Name.Contains("ZeiterfassungButtonItem"));
// if (menuitem != null)
// {
// e.Menu.ItemLinks.Remove(menuitem);
// }
//}
var zusageUntermenue = e.Menu.ItemLinks.FirstOrDefault(f=>f.GetType() == typeof(BarSubItemLink) && ((BarSubItemLink) f).Item.Name.Equals("TeilnahmeMenue"));
if (zusageUntermenue == null || ((List<Employee2SchedulerAppointmentDC>)Scheduler.SelectedAppointments[0].CustomFields["EmployeeList"]).Any(a => a.Employee.EmployeeOid.Equals(BeWoApp.LoggedOnEmployee.EmployeeOid)))
{
return;
}
e.Menu.ItemLinks.Remove(zusageUntermenue);
}
private bool _IsNew;
private void Scheduler_InitNewAppointment(object sender, AppointmentEventArgs e)
{
//WriteToDebugLog("Initiating new appointment");
_IsNew = true;
ViewModel.InitNewAppointment(e.Appointment);
}
private void Scheduler_AppointmentViewInfoCustomizing(object sender, DevExpress.Xpf.Scheduler.AppointmentViewInfoCustomizingEventArgs e)
{
var cf = e.ViewInfo.Appointment.CustomFields;
if(cf[SchedulerAppointmentListVM.CustomField_CustomerList] == null &&
cf[SchedulerAppointmentListVM.CustomField_EmployeeList] == null &&
cf[SchedulerAppointmentListVM.CustomField_IsAbsenceTime] == null &&
cf[SchedulerAppointmentListVM.CustomField_IsPrivate] == null &&
cf[SchedulerAppointmentListVM.CustomField_Originator] == null &&
cf[SchedulerAppointmentListVM.CustomField_ResourceList] == null)
{
return;
}
cf.BeginUpdate();
e.ViewInfo.CustomViewInfo = cf;
cf.EndUpdate();
}
private void AllowAppointmentAenderung(object sender, AppointmentOperationEventArgs e)
{
try
{
var darfTerminDetailsSehen = true;
var appointment = e.Appointment;
if((bool) appointment.CustomFields["IsAbsenceTime"])
{
e.Allow = false;
return;
}
var ersteller = (CompactEmployeeDC) appointment.CustomFields["Originator"];
var mitarbeiterliste = (List<Employee2SchedulerAppointmentDC>) appointment.CustomFields["EmployeeList"];
var hatNurAndereMitarbeiter = mitarbeiterliste.Count > 0 && !(mitarbeiterliste.Count == 1 && mitarbeiterliste.ElementAt(0).Employee.EmployeeOid.Equals(BeWoApp.LoggedOnEmployee.EmployeeOid));
var hatKlienten = ((List<CompactCustomerDC>) appointment.CustomFields["CustomerList"]).Count > 0;
var istErsteller = ersteller.EmployeeOid.Equals(BeWoApp.LoggedOnEmployee.EmployeeOid);
if(hatNurAndereMitarbeiter || !istErsteller)
{
darfTerminDetailsSehen = BeWoApp.LoggedOnUser.HasRight(UserRightType.KalenderMitarbeitertermineAendern);
}
if(hatKlienten)
{
darfTerminDetailsSehen = BeWoApp.LoggedOnUser.HasRight(UserRightType.KalenderKliententermineAendern);
}
if(hatNurAndereMitarbeiter && !darfTerminDetailsSehen)
{
darfTerminDetailsSehen = mitarbeiterliste.Select(ml => ml.Employee).Any(a => a.EmployeeOid.Equals(BeWoApp.LoggedOnEmployee.EmployeeOid)) || istErsteller;
}
if(!istErsteller && (bool) appointment.CustomFields["IsPrivate"] && !mitarbeiterliste.Any(em => em.Employee.EmployeeOid.Equals(BeWoApp.LoggedOnEmployee.EmployeeOid)))
{
darfTerminDetailsSehen = false;
}
e.Allow = darfTerminDetailsSehen;
}
catch(Exception exception)
{
throw exception;
}
}
private void AllowAppointmentCreateEvent(object sender, AppointmentOperationEventArgs e)
{
//WriteToDebugLog("Allowing appointment create event");
var darfAnlegen = BeWoApp.LoggedOnUser.HasRight(UserRightType.KalenderKliententermineAnlegen) || BeWoApp.LoggedOnUser.HasRight(UserRightType.KalenderMitarbeitertermineAnlegen);
e.Allow = darfAnlegen;
}
private void UpdateOptionPanel()
{
switch (ViewTypeConvert.ToAppointmentViewType(_CurrentViewType))
{
case AppointmentViewType.Day:
TimelineViewOptions.Visibility = Visibility.Collapsed;
DayViewOptions.Visibility = Visibility.Visible;
SpinEditDayViewDayCount.Value = Scheduler.DayView.DayCount;
_TimelineDayCount = 0;
break;
case AppointmentViewType.Timeline:
TimelineViewOptions.Visibility = Visibility.Visible;
DayViewOptions.Visibility = Visibility.Collapsed;
SpinEditTimelineViewDayCount.Value = _TimelineDayCount == 0 ? Scheduler.TimelineView.IntervalCount : _TimelineDayCount;
break;
default:
_TimelineDayCount = 0;
TimelineViewOptions.Visibility = Visibility.Collapsed;
DayViewOptions.Visibility = Visibility.Collapsed;
break;
}
Scheduler.WeekView.AppointmentDisplayOptions.AppointmentAutoHeight = true;
Scheduler.MonthView.AppointmentDisplayOptions.AppointmentAutoHeight = true;
Scheduler.TimelineView.AppointmentDisplayOptions.AppointmentAutoHeight = true;
}
private void ShowPrivateAppointmentsCheckBox_OnClick(object sender, RoutedEventArgs e)
{
UpdateVM(true);
}
private void LeftExpanderClick(object sender, RoutedEventArgs e)
{
if (!LeftExpanderButton.IsChecked.HasValue)
{
return;
}
AuswahlGrid.Visibility = ZeigeNurMeineTermineCheckBox.Visibility = LeftExpanderButton.IsChecked.Value ? Visibility.Collapsed : Visibility.Visible;
}
private void RightExpanderClick(object sender, RoutedEventArgs e)
{
if (!RightExpanderButton.IsChecked.HasValue)
{
return;
}
DateNavigator.Visibility = RightExpanderButton.IsChecked.Value ? Visibility.Collapsed : Visibility.Visible;
}
private void NurEigeneKlientenAnzeigen(object sender, RoutedEventArgs e)
{
//!BeWoApp.LoggedOnUser.HasRight(UserRightType.CustomerView_View) && BeWoApp.LoggedOnUser.HasRight(UserRightType.Customer_ViewMyCustomers) ? AllCustomers :
var relatedCustomerOids = BeWoApp.LoggedOnEmployee.RelatedCustomers.Select(s => s.Customer.CustomerOid);
if (NurMeineKlientenCB.IsChecked.HasValue && NurMeineKlientenCB.IsChecked.Value)
{
GefilterteKlienten = AllCustomers.Where(ac => relatedCustomerOids.Contains(ac.CustomerOid)).ToList();
}
else if (NurMeineKlientenCB.IsChecked.HasValue && !NurMeineKlientenCB.IsChecked.Value)
{
GefilterteKlienten = AllCustomers;
}
}
private void TextBoxEmployees_OnTextChanged(object sender, TextChangedEventArgs e)
{
var suchtext = ((TextBox)sender).Text;
GefilterteMitarbeiter = AllEmployees.Where(m => m.FirstName.ToLower().Contains(suchtext.ToLower()) ||
m.LastName.ToLower().Contains(suchtext.ToLower())).ToList();
}
private void TextBoxCustomers_OnTextChanged(object sender, TextChangedEventArgs e)
{
var suchtext = ((TextBox)sender).Text;
GefilterteKlienten = AllCustomers.Where(m => m.FullName.ToLower().Contains(suchtext.ToLower())).ToList();
}
private void FensterOeffnen()
{
var neueListe = new SchedulerAppointmentListVM(_Liste, AllCustomers, AllEmployees, Category2ResourcesDictionary);
var vm = neueListe;
var zuBestaetigen = vm.Appointments.Where(app =>
{
var originator = (CompactEmployeeDC) app.CustomFields["Originator"];
if (!app.CustomFields.ContainsKey("EmployeeList") || originator.EmployeeOid == BeWoApp.LoggedOnEmployee.EmployeeOid.Value)
{
return false;
}
var empList = (List<Employee2SchedulerAppointmentDC>) app.CustomFields["EmployeeList"];
return empList.Any(a => a.Employee.EmployeeOid.Equals(BeWoApp.LoggedOnEmployee.EmployeeOid) && a.ParticipationAnswer == ParticipationAnswer.Offen);
}).ToList();
var updates = vm.Appointments.Where(app =>
{
if (!app.CustomFields.ContainsKey("Originator") || !app.CustomFields.ContainsKey("EmployeeList"))
{
return false;
}
var empList = (List<Employee2SchedulerAppointmentDC>) app.CustomFields["EmployeeList"];
var or = (CompactEmployeeDC) app.CustomFields["Originator"];
return or.EmployeeOid.Equals(BeWoApp.LoggedOnEmployee.EmployeeOid) && empList.Any(a => a.IsPChanged && a.ParticipationAnswer != ParticipationAnswer.Offen && a.ParticipationAnswer != ParticipationAnswer.Verstrichen && !a.Employee.EmployeeOid.Equals(BeWoApp.LoggedOnEmployee.EmployeeOid));
}).ToList();
if (!zuBestaetigen.Any() && !updates.Any())
{
return;
}
var requestAnswerView = new RequestAnswerView(zuBestaetigen, updates);
requestAnswerView.Closed += RequestAnswerViewClosedEvent;
requestAnswerView.ParticipationChanged += UpdateRequestStringEvent;
requestAnswerView.ParticipationChanged += UpdateBeiParticipationChanged;
requestAnswerView.Show();
}
private void RequestAnswerViewClosedEvent(object sender, EventArgs e)
{
UpdateVM(true);
UpdateRequestString();
}
private void ShowAppointmentRequests(object sender, RequestNavigateEventArgs e)
{
FensterOeffnen();
}
private void UpdateBeiParticipationChanged(object sender, EventArgs e)
{
UpdateVM(true);
}
private void UpdateRequestStringEvent(object sender, EventArgs e)
{
UpdateRequestString();
}
private void AuswahlAufhebenClick(object sender, RoutedEventArgs e)
{
SelectedResources.Clear();
SelectedEmployees.Clear();
SelectedCustomers.Clear();
AlleMitarbeiterCB.IsChecked = false;
AlleKlientenCB.IsChecked = false;
AlleRessourcenCB.IsChecked = false;
OnPropertyChanged("SelectedCustomers");
OnPropertyChanged("SelectedEmployees");
OnPropertyChanged("SelectedResources");
OnPropertyChanged("SelectedItems");
}
private void Selector_OnSelectionChanged(object sender, SelectionChangedEventArgs e)
{
var tabControl = (TabControl)sender;
var selectedItem = (TabItem)tabControl.SelectedItem;
var mitarbeiterPinsel = new LinearGradientBrush(new GradientStopCollection { new GradientStop(Color.FromRgb(69, 153, 59), 0), new GradientStop(Color.FromRgb(32, 92, 25), 1) }, new Point(0.5, 0), new Point(0.5, 1));
var klientenPinsel = new LinearGradientBrush(new GradientStopCollection { new GradientStop(Color.FromRgb(59, 119, 153), 0), new GradientStop(Color.FromRgb(25, 72, 92), 1) }, new Point(0.5, 0), new Point(0.5, 1));
var ressourcenPinsel = new LinearGradientBrush(new GradientStopCollection { new GradientStop(Color.FromRgb(4, 180, 208), 0), new GradientStop(Color.FromRgb(3, 129, 149), 1) }, new Point(0.5, 0), new Point(0.5, 1));
var h = selectedItem.Header.ToString();
if (h == Translator.Translate("Mitarbeiter"))
{
tabControl.Background = mitarbeiterPinsel;
tabControl.BorderBrush = mitarbeiterPinsel;
}
else if (h == Translator.Translate("Klienten"))
{
tabControl.Background = klientenPinsel;
tabControl.BorderBrush = klientenPinsel;
}
else
{
tabControl.Background = ressourcenPinsel;
tabControl.BorderBrush = ressourcenPinsel;
}
}
private void ReloadButton_OnClick(object sender, RoutedEventArgs e)
{
UpdateVM(true);
}
private void ZusagenButtonItem_OnItemClick(object sender, ItemClickEventArgs e)
{
if (Scheduler.SelectedAppointments.Count <= 0)
{
return;
}
ZusageAendern(ParticipationAnswer.Zusage, Scheduler.SelectedAppointments[0]);
}
private void MitVorbehaltButtonItem_OnItemClick(object sender, ItemClickEventArgs e)
{
if (Scheduler.SelectedAppointments.Count <= 0)
{
return;
}
ZusageAendern(ParticipationAnswer.Vorbehalt, Scheduler.SelectedAppointments[0]);
}
private void AbsagenButtonItem_OnItemClick(object sender, ItemClickEventArgs e)
{
if (Scheduler.SelectedAppointments.Count <= 0)
{
return;
}
ZusageAendern(ParticipationAnswer.Absage, Scheduler.SelectedAppointments[0]);
}
private void ZusageAendern(ParticipationAnswer antwort, Appointment sa)
{
var el = (List<Employee2SchedulerAppointmentDC>) sa.CustomFields["EmployeeList"];
var neu = el.DoForEach(dfe =>
{
if (!dfe.Employee.EmployeeOid.Equals(BeWoApp.LoggedOnEmployee.EmployeeOid))
{
return;
}
dfe.ParticipationAnswer = antwort;
dfe.IsPC_CheckedTs = null;
}).ToList();
sa.CustomFields["EmployeeList"] = neu;
UpdateVM(true);
}
private void ZeiterfassungButtonItem_OnItemClick(object sender, ItemClickEventArgs e)
{
if (Scheduler.SelectedAppointments.Count <= 0)
{
return;
}
var app = Scheduler.SelectedAppointments[0];
var e2aList = app.CustomFields["EmployeeList"] as List<Employee2SchedulerAppointmentDC>;
var customerList = app.CustomFields["CustomerList"] as List<CompactCustomerDC>;
var empList = e2aList.Select(e2a => e2a.Employee).ToList();
BeWoUtils.CreateZeiterfassung(app.Start, app.End, customerList, empList, app.Subject);
//var employ = SelectedMitarbeiter.Items;
//var y = SelectedKlient.Items;
//if (y.Count == 0)
//{
// MessageBox.Show("Bitte wählen Sie mindestens einen Klienten aus!");
//}
//else
//{
// var startDate = StartDate.DateTime;
// var startTime = DateTime.Parse(StartTime.Text);
// var endDate = EndDate.DateTime;
// var endTime = DateTime.Parse(EndTime.Text);
// DateTime start = new DateTime(startDate.Year, startDate.Month, startDate.Day, startTime.Hour, startTime.Minute, startTime.Second);
// DateTime end = new DateTime(endDate.Year, endDate.Month, endDate.Day, endTime.Hour, endTime.Minute, endTime.Second);
// List<CompactCustomerDC> customerlist = new List<CompactCustomerDC>();
// List<CompactEmployeeDC> employeelist = new List<CompactEmployeeDC>();
// foreach (var employee in employ)
// {
// var xy = (Employee2SchedulerAppointmentDC)employee;
// employeelist.Add(xy.Employee);
// }
// foreach (var klient in y)
// {
// var s = (CompactCustomerDC)klient;
// customerlist.Add(s);
// }
// BeWoUtils.CreateZeiterfassung(start, end, customerlist, employeelist, Notice.Text);
//}
}
private void MeinTB_OnChecked(object sender, RoutedEventArgs e)
{
var tb = (ToggleButton) sender;
if (tb?.IsChecked == null)
{
return;
}
if (!tb.IsChecked.Value)
{
MitarbeiterSuchGrid.Visibility = Visibility.Collapsed;
MitarbeiterSuchTextBox.Clear();
}
else
{
MitarbeiterSuchGrid.Visibility = Visibility.Visible;
MitarbeiterSuchTextBox.Focus();
}
}
private void MeinTB2_OnChecked(object sender, RoutedEventArgs e)
{
var tb = (ToggleButton)sender;
if (tb?.IsChecked == null)
{
return;
}
if (!tb.IsChecked.Value)
{
KlientenSuchGrid.Visibility = Visibility.Collapsed;
KlientenSuchTextBox.Clear();
}
else
{
KlientenSuchGrid.Visibility = Visibility.Visible;
KlientenSuchTextBox.Focus();
}
}
private void SchedulerStorage_OnFetchAppointments(object sender, FetchAppointmentsEventArgs e)
{
UpdateVM();
}
private bool _UpdatingViewModel;
private void UpdateVM(bool shouldForceUpdate = false)
{
//WriteToDebugLog(new StackTrace().GetFrame(1).GetMethod().Name);
if (_UpdatingViewModel)
{
//WriteToDebugLog("Already updating. Aborting second try.");
return;
}
_UpdatingViewModel = true;
//WriteToDebugLog("Beginning");
if (ViewModel == null)
{
//WriteToDebugLog("Aborting");
_UpdatingViewModel = false;
return;
}
var range = Scheduler.ActiveView.GetVisibleIntervals();
var start = range.Start;
var end = range.End;
var newFetchingInterval = new TimeInterval(start - FetchPadding, end + FetchPadding);
var selectedEmployeeOids = SelectedEmployees.Select(s => s.EmployeeOid).ToList();
var selectedCustomerOids = SelectedCustomers.Select(s => s.CustomerOid).ToList();
var selectedResourceOids = SelectedResources.Where(w => w.ResourceOid.HasValue).Select(s => s.ResourceOid.Value).ToList();
var employeesOnly = MitarbeiterEbenenCheckBox.IsChecked != null && MitarbeiterEbenenCheckBox.IsChecked.Value;
var customersOnly = KlientenEbenenCheckBox.IsChecked != null && KlientenEbenenCheckBox.IsChecked.Value;
var resourcesOnly = RessourcenEbenenCheckBox.IsChecked != null && RessourcenEbenenCheckBox.IsChecked.Value;
var onlyPrivateAppointments = ShowPrivateAppointmentsCheckBox.IsChecked != null && ShowPrivateAppointmentsCheckBox.IsChecked.Value;
var showOnlyMyAppointments = ZeigeNurMeineTermine;
var showAbsenceTimes = AbwesenheitenEinAusCheckBox.IsChecked != null && AbwesenheitenEinAusCheckBox.IsChecked.Value;
if(!shouldForceUpdate && newFetchingInterval.Equals(_LastFetchedInterval))
{
_UpdatingViewModel = false;
//WriteToDebugLog("Aborting. Redundant call.");
return;
}
_LastFetchedInterval = newFetchingInterval;
UpdateAppointmentViewModel(start, end, selectedEmployeeOids, selectedCustomerOids, selectedResourceOids, employeesOnly, customersOnly, resourcesOnly, onlyPrivateAppointments, showOnlyMyAppointments, showAbsenceTimes);
}
public void UpdateAppointmentViewModel(DateTime pIntervalStart, DateTime pIntervalEnd, List<long> pSelectedEmployees, List<long> pSelectedCustomer, List<long> pSelectedResources, bool pEmployeesOnly, bool pCustomersOnly, bool pResourcesOnly, bool pPrivateAppointmentsOnly, bool pOnlyMyAppointments, bool pShouldShowAbsenceTimes)
{
if (!BeWoApp.LoggedOnEmployee.EmployeeOid.HasValue)
{
return;
}
var start = pIntervalStart - FetchPadding;
var end = pIntervalEnd + FetchPadding;
Cache.GetInstance().GetAllActiveEmployeesCompact(allEmployees =>
{
ServiceFacade.DoResourceServiceAsync(s => s.GetAllCategories2ResourcesInDictionary(), cats2Res =>
{
ServiceFacade.DoResourceServiceAsync(s2 => s2.LoadFilteredAppointments(BeWoApp.HasLoggedOnUserRight(new[] { UserRightType.KalenderMitarbeitertermineAnsehen }), BeWoApp.LoggedOnEmployee.EmployeeOid.Value, start, end, pSelectedEmployees, pSelectedCustomer, pSelectedResources, pEmployeesOnly, pCustomersOnly, pResourcesOnly, pPrivateAppointmentsOnly, pOnlyMyAppointments),
appointments =>
{
Cache.GetInstance().GetAllActiveCustomersCompact(customers =>
{
if (BeWoApp.LoggedOnUser.HasRight(UserRightType.Customer_ViewMyCustomers) && !BeWoApp.LoggedOnUser.HasRight(UserRightType.CustomerView_View))
{
customers = customers.Where(c => BeWoApp.LoggedOnEmployee.RelatedCustomers.Any(a => a.Customer.Equals(c))).ToList();
}
ServiceFacade.DoResourceServiceAsync(s3 => s3.GetAllActiveAbsenceTimesInInterval(start, end, BeWoApp.LoggedOnEmployee.EmployeeOid.Value, BeWoApp.LoggedOnUser.HasRight(UserRightType.KalenderMitarbeitertermineAnsehen)),
absenceTimes =>
{
this.Dispatch(() =>
{
var prefilteredAppointments = appointments.Where(w => (w.EmployeeList.Count == 0 && w.Originator.EmployeeOid.Equals(BeWoApp.LoggedOnEmployee.EmployeeOid) ||
w.EmployeeList.Count > 0 && w.EmployeeList.Any(a => a.Employee.EmployeeOid.Equals(BeWoApp.LoggedOnEmployee.EmployeeOid)) ||
BeWoApp.LoggedOnUser.HasRight(UserRightType.KalenderMitarbeitertermineAnsehen)) && (!w.EmployeeList.TrueForAll(e2a => e2a.ParticipationAnswer == ParticipationAnswer.Absage) || w.EmployeeList == null || w.EmployeeList.Count == 0)).ToList();
var vm = new SchedulerAppointmentListVM(prefilteredAppointments, customers, allEmployees, cats2Res);
if (pShouldShowAbsenceTimes)
{
vm.Appointments.AddRange(ViewModel.ConvertAbsenceTimesToAppointments(absenceTimes.Where(w =>
{
return SelectedEmployees.Count == 0 || SelectedEmployees.Any(a => a.EmployeeOid == w.EmployeeOid);
}), end, allEmployees));
}
ViewModel.ActiveAppointmentViewModel = vm;
ViewModel.SchedulerSettings = ViewModel.GetActiveSettings();
ViewModel.SchedulerSettings.StartDate = pIntervalStart;
GefilterteMitarbeiter = ViewModel.ActiveAppointmentViewModel.AllEmployees;
AllEmployees = ViewModel.ActiveAppointmentViewModel.AllEmployees;
GefilterteKlienten = ViewModel.ActiveAppointmentViewModel.AllCustomers;
AllCustomers = ViewModel.ActiveAppointmentViewModel.AllCustomers;
Category2ResourcesDictionary = ViewModel.ActiveAppointmentViewModel.Categories2Resources;
SelectedEmployees = AllEmployees.Where(w => SelectedEmployees.Any(a => a.EmployeeOid.Equals(w.EmployeeOid))).ToList();
SelectedCustomers = AllCustomers.Where(w => SelectedCustomers.Any(a => a.CustomerOid.Equals(w.CustomerOid))).ToList();
SelectedResources = AllResources.Where(w => SelectedResources.Any(a => a.ResourceOid.Equals(w.ResourceOid))).ToList();
var items = SelectedItems;
var testtesttest = ViewModel.ActiveAppointmentViewModel;
_UpdatingViewModel = false;
//WriteToDebugLog("Done");
});
});
});
});
});
});
}
//private void ExportAsiCal(object sender, RoutedEventArgs e)
//{
// var dialog = new SaveFileDialog {Filter = "iCalendar files (*.ics)|*.ics", FilterIndex = 1};
// if (dialog.ShowDialog() != true)
// return;
// using (var stream = dialog.OpenFile())
// {
// ExportAppointmentsAs_iCal(stream);
// }
//}
//void ExportAppointmentsAs_iCal(Stream stream)
//{
// if (stream == null)
// return;
// try
// {
// var productIdentifier = string.Format("-//{0}//DXScheduler iCalendarExchange Example//DE", BeWoApp.Mandator);
// var exporter = new iCalendarExporter(Scheduler.GetCoreStorage()) { ProductIdentifier = productIdentifier };
// //exporter.AppointmentExporting += OnAppointmentExporting;
// exporter.Export(stream);
// }
// catch (Exception e)
// {
// MessageBox.Show(string.Format("Der Kalender konnte leider nicht exportiert werden.\n{0}", e.Message), "Fehler beim Export", MessageBoxButton.OK, MessageBoxImage.Error);
// }
//}
//private void OnAppointmentExporting(object sender, AppointmentExportingEventArgs appointmentExportingEventArgs)
//{
// var iCalArgs = (iCalendarAppointmentExportingEventArgs) appointmentExportingEventArgs;
// var vEvent = iCalArgs.VEvent;
// var ma = (List<Employee2SchedulerAppointmentDC>)appointmentExportingEventArgs.Appointment.CustomFields["EmployeeList"];
// var ca = (List<CompactCustomerDC>)appointmentExportingEventArgs.Appointment.CustomFields["CustomerList"];
// var ra = (List<ResourceDC>)appointmentExportingEventArgs.Appointment.CustomFields["ResourceList"];
//}
//private void SyncWithOutlook(object sender, RoutedEventArgs e)
//{
// Synchronize();
//}
private void PrintCalendar(object sender, RequestNavigateEventArgs e)
{
if (Scheduler.ActiveView.GetAppointments().Count == 0)
{
MessageBox.Show("Das Drucken ist nicht möglich, da im ausgewählten Intervall keine Termine vorhanden sind.",
"Drucken nicht möglich",
MessageBoxButton.OK,
MessageBoxImage.Error);
return;
}
var range = Scheduler.ActiveView.GetVisibleIntervals();
var datesList = new List<DateTime>();
if (range.GetType() == typeof(WeekIntervalCollection))
{
for (var i = 0; i < range.Duration.Days; i++)
{
datesList.Add(range.Start.AddDays(i));
}
}
else
{
datesList.AddRange(range.Select(x => x.Start));
}
var apps = Scheduler.ActiveView.GetAppointments().Where(w => w.CustomFields["IsAbsenceTime"] == null || (bool) w.CustomFields["IsAbsenceTime"] == false).ToList();
var appointmentOidListe = apps.Where(w => !w.IsOccurrence && !w.IsRecurring || w.IsException).Select(app => Convert.ToInt64(((SchedulerAppointmentVM) app.GetSourceObject(Scheduler.GetCoreStorage())).Id)).Distinct().ToList();
var serienTerminOids = apps.Where(w => w.IsRecurring || w.IsOccurrence).Select(app => Convert.ToInt64(((SchedulerAppointmentVM)app.RecurrencePattern.GetSourceObject(Scheduler.GetCoreStorage())).Id)).Distinct().ToList();
var serienTermine = new List<SchedulerAppointmentDC>();
var recurringAppointments = new List<Appointment>();
foreach (var app in apps.Where(w => w.IsOccurrence || w.IsRecurring).Where(app => !recurringAppointments.Any(a => a.RecurrenceInfo.Id.Equals(app.RecurrenceInfo.Id))))
{
recurringAppointments.Add(app);
}
foreach (var serienTermin in recurringAppointments)
{
var basistermin = (SchedulerAppointmentVM) serienTermin.RecurrencePattern.GetSourceObject(Scheduler.GetCoreStorage());
var info = serienTermin.RecurrenceInfo;
var ausnahmen = apps.Where(w => w.RecurrenceInfo != null && w.RecurrenceInfo.Id.Equals(info.Id) && w.IsException).ToList();
var calc = OccurrenceCalculator.CreateInstance(info);
var ttc = new TimeInterval(range.Start, range.End + new TimeSpan(1, 0, 0));
var kollektionOhneAusnahmen = calc.CalcOccurrences(ttc, serienTermin.RecurrencePattern).Where(w => (w.RecurrenceIndex != 0 && !w.IsException)).ToList();
if (ausnahmen.Any(appointment => appointment.IsException && appointment.RecurrenceIndex == 0) && basistermin.DataContract.SchedulerAppointmentOid != null)
{
serienTerminOids.Remove(basistermin.DataContract.SchedulerAppointmentOid.Value);
}
if (ausnahmen.Count > 0)
{
kollektionOhneAusnahmen = kollektionOhneAusnahmen.Where(w => !ausnahmen.Select(s => s.RecurrenceIndex).Contains(w.RecurrenceIndex)).ToList();
}
serienTermine.AddRange(kollektionOhneAusnahmen.Select(z => new SchedulerAppointmentDC
{
AllDay = z.AllDay, CustomerList = basistermin.CustomerList, EmployeeList = basistermin.EmployeeList, ResourceList = basistermin.ResourceList, StartDate = z.Start, EndDate = z.End, Description = z.Description, IsPrivate = basistermin.IsPrivate, Location = z.Location, Subject = z.Subject, LabelId = z.LabelId, Type = (int) z.Type, Originator = basistermin.Originator, RecurrenceInfo = z.RecurrenceInfo.ToXml()
}));
}
appointmentOidListe.AddRange(serienTerminOids.Where(w => !appointmentOidListe.Contains(w)));
var mehrTaegigeTermine = apps.Where(a => !a.SameDay && !(!a.SameDay && a.AllDay && a.Duration == new TimeSpan(1,0,0,0))).Select(s => ((SchedulerAppointmentVM)s.GetSourceObject(Scheduler.GetCoreStorage())).CommitToDataContract()).ToList();
appointmentOidListe.RemoveRange(mehrTaegigeTermine.Select(s => s.SchedulerAppointmentOid.Value));
var neueTermine = new List<SchedulerAppointmentDC>();
foreach (var termin in mehrTaegigeTermine)
{
var tage = termin.StartDate.Value.GetDayNumberBetweenTwoDates(termin.EndDate.Value);
if (termin.AllDay)
{
tage -= 1;
}
if (tage > 0)
{
if (termin.AllDay)
{
for (var i = 0; i <= tage; i++)
{
neueTermine.Add(new SchedulerAppointmentDC
{
AllDay = termin.AllDay,
CustomerList = termin.CustomerList,
Description = termin.Description,
EmployeeList = termin.EmployeeList,
EndDate = new DateTime(termin.StartDate.Value.AddDays(i + 1).Year, termin.StartDate.Value.AddDays(i + 1).Month, termin.StartDate.Value.AddDays(i + 1).Day),
FormerBookingSequenceOid = termin.FormerBookingSequenceOid,
IsPrivate = termin.IsPrivate,
LabelId = termin.LabelId,
Location = termin.Location,
Originator = termin.Originator,
RecurrenceInfo = termin.RecurrenceInfo,
ReminderInfo = termin.ReminderInfo,
ResourceList = termin.ResourceList,
StartDate = new DateTime(termin.StartDate.Value.AddDays(i).Year, termin.StartDate.Value.AddDays(i).Month, termin.StartDate.Value.AddDays(i).Day),
Status = termin.Status,
Subject = termin.Subject,
Type = termin.Type
});
}
}
else
{
for (var i = 0; i <= tage; i++)
{
if (i == 0)
{
neueTermine.Add(new SchedulerAppointmentDC
{
AllDay = false,
CustomerList = termin.CustomerList,
Description = termin.Description,
EmployeeList = termin.EmployeeList,
EndDate = new DateTime(termin.StartDate.Value.AddDays(1).Year, termin.StartDate.Value.AddDays(1).Month, termin.StartDate.Value.AddDays(1).Day),
FormerBookingSequenceOid = termin.FormerBookingSequenceOid,
IsPrivate = termin.IsPrivate,
LabelId = termin.LabelId,
Location = termin.Location,
Originator = termin.Originator,
RecurrenceInfo = termin.RecurrenceInfo,
ReminderInfo = termin.ReminderInfo,
ResourceList = termin.ResourceList,
StartDate = termin.StartDate,
Status = termin.Status,
Subject = termin.Subject,
Type = termin.Type
});
}
else if (i == tage)
{
neueTermine.Add(new SchedulerAppointmentDC
{
AllDay = false,
CustomerList = termin.CustomerList,
Description = termin.Description,
EmployeeList = termin.EmployeeList,
EndDate = termin.EndDate,
FormerBookingSequenceOid = termin.FormerBookingSequenceOid,
IsPrivate = termin.IsPrivate,
LabelId = termin.LabelId,
Location = termin.Location,
Originator = termin.Originator,
RecurrenceInfo = termin.RecurrenceInfo,
ReminderInfo = termin.ReminderInfo,
ResourceList = termin.ResourceList,
StartDate = new DateTime(termin.EndDate.Value.Year, termin.EndDate.Value.Month, termin.EndDate.Value.Day),
Status = termin.Status,
Subject = termin.Subject,
Type = termin.Type
});
}
else
{
neueTermine.Add(new SchedulerAppointmentDC
{
AllDay = true,
CustomerList = termin.CustomerList,
Description = termin.Description,
EmployeeList = termin.EmployeeList,
EndDate = new DateTime(termin.StartDate.Value.AddDays(i + 1).Year, termin.StartDate.Value.AddDays(i + 1).Month, termin.StartDate.Value.AddDays(i + 1).Day),
FormerBookingSequenceOid = termin.FormerBookingSequenceOid,
IsPrivate = termin.IsPrivate,
LabelId = termin.LabelId,
Location = termin.Location,
Originator = termin.Originator,
RecurrenceInfo = termin.RecurrenceInfo,
ReminderInfo = termin.ReminderInfo,
ResourceList = termin.ResourceList,
StartDate = new DateTime(termin.StartDate.Value.AddDays(i).Year, termin.StartDate.Value.AddDays(i).Month, termin.StartDate.Value.AddDays(i).Day),
Status = termin.Status,
Subject = termin.Subject,
Type = termin.Type
});
}
}
}
}
}
var variablenDictionary = new Dictionary<String, Object>
{
{ "appointmentOidListe", appointmentOidListe },
{ "datesList", datesList },
{ "employeeOid", BeWoApp.LoggedOnEmployee.EmployeeOid },
{ "serienTermine", serienTermine },
{"mehrtaegigeTermine", neueTermine}
};
BeWoUtils.ShowReport("Kalender", variablenDictionary, ReportEnum.KalenderMonatsReportEnum);
}
public void PreselectCustomer(long pCustomerOid)
{
if (AllCustomers.Any(c => c.CustomerOid.Equals(pCustomerOid)))
{
SelectedCustomers = new List<CompactCustomerDC> {AllCustomers.Find(f => f.CustomerOid.Equals(pCustomerOid))};
OnPropertyChanged(nameof(SelectedCustomers));
OnPropertyChanged(nameof(SelectedItems));
OnPropertyChanged(nameof(GefilterteKlienten));
}
}
private void DateNavigator_OnSelectedDatesChanged(object sender, EventArgs e)
{
//WriteToDebugLog("Selected dates changed");
_CurrentViewType = Scheduler.ActiveViewType;
var navigator = (DevExpress.Xpf.Editors.DateNavigator.DateNavigator) sender;
var selectedDates = navigator.SelectedDates;
var isSelectedDateFetched = _LastFetchedInterval.ContainsEveryDateFromList(selectedDates);
if(!isSelectedDateFetched && !(_LastFetchedInterval.Start.Equals(new DateTime(1,1,1,0,0,0)) && _LastFetchedInterval.End.Equals(new DateTime(1, 1, 1, 0, 30, 0))))
{
UpdateVM();
}
}
private void MitarbeiterVerfuegbarkeitPruefenButtonItem_OnItemClick(object sender, ItemClickEventArgs e)
{
var intervall = Scheduler.ActiveView.SelectedInterval;
ServiceFacade.DoEmployeeServiceAsync(s1 => s1.GetAllActiveEmployeesCompact(),
dcs => ServiceFacade.DoReportServiceAsync(
s2 => s2.GetMitarbeiterverfuegbarkeiten(dcs, intervall.Start, intervall.End), s3 => this.Dispatch(() =>
{
var mviv = new MitarbeiterverfuegbarkeitsinfoView(s3, intervall.Start, intervall.End);
if (mviv.CommandBindings.Count == 0)
{
mviv.CommandBindings.Add(
new CommandBinding(
ApplicationCommands.Close,
(s, e2) =>
{
if (!mviv.DoSaveCheck())
{
return;
}
PopupContent.Visibility = Visibility.Hidden;
PopupContent.Child = null;
}));
}
PopupContent.Child = mviv;
PopupContent.Height = 400;
PopupContent.Width = 450;
PopupContent.Visibility = Visibility.Visible;
})));
}
private void MitarbeiterfarbenEinAusCheckBox_OnChecked(object sender, RoutedEventArgs e)
{
var cb = (CheckBox) sender;
IsEmployeeBrushVisible = cb.IsChecked ?? true;
}
private void NurMeineTermineEinAusCheckBox_OnChecked(object sender, RoutedEventArgs e)
{
var cb = (CheckBox) sender;
if (CheckBoxConverter != null && BeWoApp.CompactLoggedOnEmployee != null)
{
if (cb.IsChecked != null && cb.IsChecked.Value)
{
SelectedEmployees = new List<CompactEmployeeDC>{BeWoApp.CompactLoggedOnEmployee};
CheckBoxConverter.AktuellerMitarbeiter = BeWoApp.CompactLoggedOnEmployee;
}
else if (cb.IsChecked != null && !cb.IsChecked.Value && SelectedEmployees.Count == 1)
{
SelectedEmployees.Remove(BeWoApp.CompactLoggedOnEmployee);
CheckBoxConverter.AktuellerMitarbeiter = null;
}
OnPropertyChanged(nameof(SelectedEmployees));
OnPropertyChanged(nameof(SelectedItems));
UpdateVM(true);
}
}
private void AbwesenheitenEinAusCheckBox_OnChecked(object sender, RoutedEventArgs e)
{
var cb = (CheckBox) sender;
IsAbsenceTimeVisible = cb.IsChecked ?? true;
UpdateVM(true);
}
private static void WriteToDebugLog(string message, bool isWithoutTimestamp = false)
{
#if DEBUG
var callerName2 = new StackTrace().GetFrame(2).GetMethod().Name;
var callerName = new StackTrace().GetFrame(1).GetMethod().Name;
using(var file = new StreamWriter(Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + @"\scheduler_log.txt", true))
{
var messageToWrite = isWithoutTimestamp ? message : $"{DateTime.Now:yyyy-MM-dd HH:mm:ss:ffff} {callerName2}->{callerName}: {message}";
file.WriteLine(messageToWrite);
}
Debug.WriteLine($"{DateTime.Now:yyyy-MM-dd HH:mm:ss:ffff} {callerName}: {message}");
#endif
}
private void Scheduler_OnInplaceEditorShowing(object sender, InplaceEditorEventArgs e)
{
if(_IsNew)
{
var n = SelectedEmployees.Select(item => new Employee2SchedulerAppointmentDC { Employee = item, ParticipationAnswer = ParticipationAnswer.Offen }).ToList();
e.Appointment.CustomFields["EmployeeList"] = n;
e.Appointment.CustomFields["CustomerList"] = new List<CompactCustomerDC>(SelectedCustomers);
e.Appointment.CustomFields["ResourceList"] = new List<ResourceDC>(SelectedResources);
_IsNew = false;
}
}
}
#region Converter
public static class ViewTypeConvert
{
public static AppointmentViewType ToAppointmentViewType(SchedulerViewType svt)
{
switch (svt)
{
case SchedulerViewType.Day:
return AppointmentViewType.Day;
case SchedulerViewType.Week:
return AppointmentViewType.Week;
case SchedulerViewType.Timeline:
return AppointmentViewType.Timeline;
case SchedulerViewType.Month:
return AppointmentViewType.Month;
default:
return AppointmentViewType.WorkWeek;
}
}
}
public class TextFromIDataContractConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if(value is ResourceDC resourceDC)
{
return resourceDC.Name;
}
if (value is Employee2SchedulerAppointmentDC dc)
{
return dc.Employee.SimpleDescription;
}
var filterableDC = value as IFilterableDC;
return filterableDC?.SimpleDescription;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) { throw new NotImplementedException(); }
}
public class GermanEditorLocalizer : EditorLocalizer
{
public override string Language => "Deutsch";
public override string GetLocalizedString(EditorStringId id)
{
return id.Equals(EditorStringId.Today) ? "Heute" : base.GetLocalizedString(id);
}
}
public class ViewInfo2CustomFieldsConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
var customFields = (CustomFieldCollection) value;
if(customFields != null)
{
var ressourcen = (List<ResourceDC>) customFields["ResourceList"];
if (parameter != null && parameter.Equals("AlleRessourcen"))
{
return ressourcen;
}
}
return null;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) { throw new NotImplementedException(); }
}
public class CustomField2VisibilityConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
try
{
var customFields = (CustomFieldCollection)value;
var mitarbeiter = (List<Employee2SchedulerAppointmentDC>)customFields["EmployeeList"];
var ressourcen = (List<ResourceDC>)customFields["ResourceList"];
var klienten = (List<CompactCustomerDC>)customFields["CustomerList"];
if (parameter == null)
{
return Visibility.Collapsed;
}
switch (parameter.ToString())
{
case "Ressourcen":
return ressourcen != null && ressourcen.Count > 0 ? Visibility.Visible : Visibility.Collapsed;
case "Klienten":
return klienten != null && klienten.Count > 0 ? Visibility.Visible : Visibility.Collapsed;
case "Mitarbeiter":
return mitarbeiter != null && mitarbeiter.Count > 0 ? Visibility.Visible : Visibility.Collapsed;
case "Trennstrich":
return mitarbeiter != null && mitarbeiter.Any() || klienten != null && klienten.Any() || ressourcen != null && ressourcen.Any() ? Visibility.Visible : Visibility.Collapsed;
default:
return Visibility.Collapsed;
}
}
catch(Exception e)
{
return Visibility.Collapsed;
}
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) { throw new NotImplementedException(); }
}
public class AppointmentToolTipConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
try
{
var customfields = (CustomFieldCollection) value;
var mitarbeiter = (List<Employee2SchedulerAppointmentDC>)customfields["EmployeeList"];
var ressourcen = (List<ResourceDC>) customfields["ResourceList"];
var klienten = (List<CompactCustomerDC>) customfields["CustomerList"];
var tooltip = string.Empty;
var seperator = "; ";
if (parameter == null)
{
return tooltip;
}
var auswahl = new List<IFilterableDC>();
switch (parameter.ToString())
{
case "Ressourcen":
seperator = ", ";
if(ressourcen != null)
{
auswahl = ressourcen.Cast<IFilterableDC>().ToList();
}
break;
case "Mitarbeiter":
if (mitarbeiter != null)
{
auswahl = mitarbeiter.Select(s => s.Employee).Cast<IFilterableDC>().ToList();
}
break;
case "Klienten":
if(klienten != null)
{
auswahl = klienten.Cast<IFilterableDC>().ToList();
}
break;
}
foreach (var item in auswahl)
{
var index = auswahl.IndexOf(item);
if (index % 3 == 0 && index < auswahl.Count - 1 && index > 0)
{
tooltip += "\n";
}
tooltip += item.ToString();
if (index < auswahl.Count - 1)
{
tooltip += seperator;
}
}
return tooltip;
}
catch(Exception e)
{
return string.Empty;
}
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) { throw new NotImplementedException(); }
}
public class WidthAdditionMultiConverter : IMultiValueConverter
{
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
{
var w1 = System.Convert.ToDouble(values[0]);
var w2 = System.Convert.ToDouble(values[1]);
return w1 + w2;
}
public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture) { throw new NotImplementedException(); }
}
public class FilterBackgroundConverter : IMultiValueConverter
{
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
{
var farbe = Color.FromRgb(192, 255, 208);
try
{
if (!(values[0] is List<IDataContract> selectedItems) || !selectedItems.Any())
{
return new LinearGradientBrush(new GradientStopCollection { new GradientStop(farbe, 1) }, new Point(.5, 0), new Point(.5, 1));
}
if (!(values[1] is CustomFieldCollection customViewInfo))
{
return new LinearGradientBrush(new GradientStopCollection { new GradientStop(farbe, 1) }, new Point(.5, 0), new Point(.5, 1));
}
var aptCustomers = (List<CompactCustomerDC>) customViewInfo["CustomerList"];
var aptResources = (List<ResourceDC>) customViewInfo["ResourceList"];
var gradientCollection = new GradientStopCollection();
var farbKollektion = new List<Color>();
if (selectedItems.Any(aptCustomers.Contains))
{
farbKollektion.Add(Color.FromRgb(59, 119, 153));
}
if (selectedItems.Any(aptResources.Contains))
{
farbKollektion.Add(Color.FromRgb(4, 180, 208));
}
switch (farbKollektion.Count)
{
case 1:
var first = aptResources.FirstOrDefault();
gradientCollection.Add(first != null ? new GradientStop((Color) (ColorConverter.ConvertFromString(first.Color) ?? Color.FromRgb(4, 180, 208)), 1) : new GradientStop(farbKollektion[0], 1));
break;
case 2:
gradientCollection.Add(new GradientStop(farbKollektion[0], 0.5));
var first2 = aptResources.FirstOrDefault();
if (first2 != null)
{
gradientCollection.Add(new GradientStop((Color) (ColorConverter.ConvertFromString(first2.Color) ?? Color.FromRgb(4, 180, 208)), 0.5));
}
break;
default:
gradientCollection.Add(new GradientStop(farbe, 1));
break;
}
return new LinearGradientBrush(gradientCollection, new Point(.5, 0), new Point(.5, 1));
}
catch (Exception)
{
return new LinearGradientBrush(new GradientStopCollection { new GradientStop(farbe, 1) }, new Point(.5, 0), new Point(.5, 1));
}
}
public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture) { throw new NotImplementedException(); }
}
public class AppointmentBorderZusageConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
try
{
var customFields = (CustomFieldCollection)value;
var employeeList = (List<Employee2SchedulerAppointmentDC>) customFields["EmployeeList"];
return employeeList.Any(e => e.Employee.EmployeeOid.Equals(BeWoApp.LoggedOnEmployee.EmployeeOid) && e.ParticipationAnswer == ParticipationAnswer.Vorbehalt) ?
new SolidColorBrush(Color.FromRgb(185, 39, 217)) :
new SolidColorBrush(Color.FromRgb(192, 255, 208));
}
catch(Exception e)
{
Console.WriteLine(e);
return new SolidColorBrush(Color.FromRgb(192, 255, 208));
}
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) { throw new NotImplementedException(); }
}
public class NichtNochEinConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (parameter != null && parameter.Equals("GibName"))
{
var v = (Employee2SchedulerAppointmentDC) value;
if(v != null)
{
return v.Employee.DetailDescription;
}
}
if (parameter != null && parameter.Equals("ListenQuelle"))
{
var customFields = (CustomFieldCollection) value;
var employeeList = (List<Employee2SchedulerAppointmentDC>) customFields["EmployeeList"];
return employeeList;
}
var val = (Employee2SchedulerAppointmentDC)value;
var c = Color.FromRgb(255, 255, 255);
if(val != null)
{
switch(val.ParticipationAnswer)
{
case ParticipationAnswer.Vorbehalt:
c = Color.FromRgb(185, 39, 217);
break;
case ParticipationAnswer.Zusage:
c = Color.FromRgb(72, 212, 78);
break;
case ParticipationAnswer.Absage:
c = Color.FromRgb(171, 0, 48);
break;
}
}
return new SolidColorBrush(c);
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) { throw new NotImplementedException(); }
}
public class ToolTipTimeVisibilityConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
var customFields = (CustomFieldCollection) value;
if(customFields == null || customFields.ToArray().ToList().Any(a => a == null))
{
return Visibility.Visible;
}
var isParsingSuccessful = bool.TryParse(customFields[SchedulerAppointmentListVM.CustomField_IsAbsenceTime].ToString(), out var isAbsenceTime);
return isParsingSuccessful && isAbsenceTime ? Visibility.Collapsed : Visibility.Visible;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
#endregion
}