2739 lines
103 KiB
C#
2739 lines
103 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Collections.ObjectModel;
|
|
using System.ComponentModel;
|
|
using System.Diagnostics;
|
|
using System.Globalization;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Text;
|
|
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.Utils;
|
|
using BeWo.Scheduler.ViewModel;
|
|
using BeWo.ServiceProxy;
|
|
using BeWo.View;
|
|
|
|
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 BS.SharedLauncher;
|
|
using DevExpress.Xpf.Bars;
|
|
using DevExpress.Xpf.Editors;
|
|
using DevExpress.Xpf.Scheduler;
|
|
using DevExpress.Xpf.Scheduler.Reporting;
|
|
using DevExpress.XtraScheduler;
|
|
using DevExpress.XtraScheduler.Compatibility;
|
|
using DevExpress.XtraScheduler.iCalendar;
|
|
using Microsoft.Win32;
|
|
using Appointment = DevExpress.XtraScheduler.Appointment;
|
|
using AppointmentViewInfoCustomizingEventArgs = DevExpress.Xpf.Scheduler.AppointmentViewInfoCustomizingEventArgs;
|
|
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));
|
|
}
|
|
}
|
|
|
|
private bool _IsTasksVisible;
|
|
|
|
public bool IsTasksVisible
|
|
{
|
|
get => _IsTasksVisible;
|
|
|
|
set
|
|
{
|
|
_IsTasksVisible = value;
|
|
OnPropertyChanged(nameof(IsTasksVisible));
|
|
}
|
|
}
|
|
|
|
public bool IsInCustomerViewMode { get; set; }
|
|
|
|
private SchedulerPrintingSettings _PrintingSettings = new SchedulerPrintingSettings();
|
|
|
|
public NewSchedulerViewModel ViewModel { get; set; }
|
|
|
|
public event PropertyChangedEventHandler PropertyChanged;
|
|
|
|
[NotifyPropertyChangedInvocator]
|
|
public void OnPropertyChanged(string propertyName)
|
|
{
|
|
var handler = PropertyChanged;
|
|
handler?.Invoke(this, new PropertyChangedEventArgs(propertyName));
|
|
}
|
|
|
|
public bool ZeigeNurMeineTermine
|
|
{
|
|
get => MainSession.AppSettings.ZeigeNurMeineTermine;
|
|
set
|
|
{
|
|
if(MainSession.AppSettings.ZeigeNurMeineTermine != value)
|
|
{
|
|
MainSession.AppSettings.ZeigeNurMeineTermine = value;
|
|
MainSession.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, ICollection<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));
|
|
|
|
AlleMitarbeiterCB.IsChecked = ListEquals(value, AllEmployees);
|
|
|
|
ZeigeNurMeineTermine = value.Count == 1 && value.Contains(MainSession.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;
|
|
|
|
AlleRessourcenCB.IsChecked = ListEquals(value, AllResources);
|
|
|
|
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 DateTime? _SelectedAppointmentStartDate;
|
|
|
|
private readonly SchedulerAppointmentDC _SelectedAppointmentFromHomePanelView;
|
|
private bool _IsComingFromHomeDragPanel;
|
|
public NewSchedulerView(DateTime pIntervalStartDate, SchedulerAppointmentDC pAppointment)
|
|
{
|
|
_IsComingFromHomeDragPanel = true;
|
|
|
|
_SelectedAppointmentFromHomePanelView = pAppointment;
|
|
|
|
_SelectedAppointmentStartDate = pIntervalStartDate;
|
|
|
|
ConstructObject();
|
|
}
|
|
|
|
private void GetCacheObjects(Action<List<CompactCustomerDC>, List<CompactEmployeeDC>, Dictionary<ValueListEntryDC, List<ResourceDC>>> callback)
|
|
{
|
|
Cache.GetInstance().GetAllActiveEmployeesCompact(allEmployees =>
|
|
{
|
|
this.Dispatch(() =>
|
|
{
|
|
Cache.GetInstance().GetAllActiveCustomersCompact(allCustomers =>
|
|
{
|
|
this.Dispatch(() =>
|
|
{
|
|
Cache.GetInstance().GetCategories2ResourcesDictionary(resourceDictionary =>
|
|
{
|
|
this.Dispatch(() =>
|
|
{
|
|
if(!MainSession.LoggedOnUser.HasRight(UserRightType.KalenderMitarbeitertermineAnsehen))
|
|
{
|
|
allEmployees = new List<CompactEmployeeDC> { MainSession.CompactLoggedOnEmployee };
|
|
}
|
|
|
|
var darfKlientenAnsichtSehen = MainSession.LoggedOnUser.HasRight(UserRightType.Customer_ViewMyCustomers) && MainSession.LoggedOnUser.HasRight(UserRightType.CustomerView_View);
|
|
var darfTermineAllerKlientenSehen = MainSession.LoggedOnUser.HasRight(UserRightType.KalenderKliententermineAlleAnsehen);
|
|
|
|
if(darfKlientenAnsichtSehen)
|
|
{
|
|
if(!darfTermineAllerKlientenSehen)
|
|
{
|
|
allCustomers = allCustomers.Where(w => w.IsRelatedToEmployee).ToList();
|
|
}
|
|
}
|
|
else
|
|
{
|
|
allCustomers.Clear();
|
|
}
|
|
|
|
if(!MainSession.LoggedOnUser.HasRight(UserRightType.KalenderRessourcentermineAnsehen))
|
|
{
|
|
resourceDictionary.Clear();
|
|
}
|
|
|
|
callback(allCustomers, allEmployees, resourceDictionary);
|
|
});
|
|
});
|
|
});
|
|
});
|
|
});
|
|
});
|
|
}
|
|
|
|
private void ConstructObject()
|
|
{
|
|
IsEmployeeBrushVisible = true;
|
|
|
|
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;
|
|
}
|
|
}
|
|
|
|
//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()
|
|
{
|
|
ViewModel = new NewSchedulerViewModel();
|
|
ViewModel.ViewModelChanged += ViewModel_ViewModelChanged;
|
|
ViewModel.ViewModelChanged += UpdateRequestStringEvent;
|
|
}
|
|
|
|
private void ViewModel_ViewModelChanged(object sender, EventArgs<ISchedulerViewModel> e)
|
|
{
|
|
this.Dispatch(() =>
|
|
{
|
|
UpdateDataSource(e.Data);
|
|
|
|
if(_IstErsterAufruf)
|
|
{
|
|
if(MainPage.HatNeueTermine && !_IsComingFromHomeDragPanel)
|
|
{
|
|
FensterOeffnen();
|
|
}
|
|
|
|
_IstErsterAufruf = false;
|
|
}
|
|
});
|
|
}
|
|
|
|
private void InitScheduler()
|
|
{
|
|
if(_IsComingFromHomeDragPanel && _SelectedAppointmentStartDate.HasValue)
|
|
{
|
|
var monday = _SelectedAppointmentStartDate.Value.FirstDateOfWeek(_SelectedAppointmentStartDate.Value.GetIso8601WeekOfYear());
|
|
|
|
Scheduler.Start = monday;
|
|
}
|
|
else
|
|
{
|
|
Scheduler.Start = DateTime.Today;
|
|
|
|
}
|
|
|
|
_TimelineDayCount = 0;
|
|
Scheduler.DayView.NavigationButtonVisibility = NavigationButtonVisibility.Always;
|
|
Scheduler.DayView.AppointmentDisplayOptions.ShowRecurrence = true;
|
|
Scheduler.DayView.AppointmentDisplayOptions.ShowReminder = true;
|
|
Scheduler.DayView.ResourcesPerPage = 1;
|
|
|
|
Scheduler.WorkWeekView.ShowFullWeek = _IsComingFromHomeDragPanel && Scheduler.Start.DayOfWeek.Equals(DayOfWeek.Saturday) || Scheduler.Start.DayOfWeek.Equals(DayOfWeek.Sunday);
|
|
Scheduler.WorkWeekView.ShowWorkTimeOnly = false;
|
|
|
|
Scheduler.WorkWeekView.NavigationButtonVisibility = NavigationButtonVisibility.Always;
|
|
Scheduler.WorkWeekView.ResourcesPerPage = 1;
|
|
|
|
Scheduler.WeekView.NavigationButtonVisibility = NavigationButtonVisibility.Always;
|
|
Scheduler.WeekView.ResourcesPerPage = 1;
|
|
|
|
Scheduler.MonthView.NavigationButtonVisibility = NavigationButtonVisibility.Always;
|
|
Scheduler.MonthView.ResourcesPerPage = 1;
|
|
|
|
Scheduler.TimelineView.NavigationButtonVisibility = NavigationButtonVisibility.Always;
|
|
Scheduler.TimelineView.ResourcesPerPage = 1;
|
|
}
|
|
|
|
private void InitRights()
|
|
{
|
|
MitarbeiterTabItem.Visibility = MainSession.LoggedOnUser.HasRight(UserRightType.KalenderMitarbeitertermineAnsehen) ? Visibility.Visible : Visibility.Collapsed;
|
|
RessourcenTabItem.Visibility = MainSession.LoggedOnUser.HasRight(UserRightType.KalenderRessourcentermineAnsehen) ? Visibility.Visible : Visibility.Collapsed;
|
|
KlientenTabItem.Visibility = MainSession.LoggedOnUser.HasRight(UserRightType.CustomerView_View) || MainSession.LoggedOnUser.HasRight(UserRightType.ViewAll) ? Visibility.Visible : Visibility.Collapsed;
|
|
|
|
MitarbeiterEbenenCheckBox.Visibility = MitarbeiterTabItem.Visibility;
|
|
RessourcenEbenenCheckBox.Visibility = RessourcenTabItem.Visibility;
|
|
KlientenEbenenCheckBox.Visibility = KlientenTabItem.Visibility;
|
|
MitarbeiterfarbenEinAusCheckBox.Visibility = MitarbeiterTabItem.Visibility;
|
|
|
|
ButtonDeleteAppointments.Visibility = MainSession.LoggedOnUser.HasRight(UserRightType.Termine_IntervalDelete) ? Visibility.Visible : Visibility.Collapsed;
|
|
}
|
|
|
|
private void UpdateDataSource(ISchedulerViewModel vm)
|
|
{
|
|
try
|
|
{
|
|
IgnoreChangeEvents = true;
|
|
|
|
Scheduler.Storage.BeginUpdate();
|
|
UpdateCustomFieldMappings(vm);
|
|
Scheduler.Storage.EndUpdate();
|
|
|
|
// DateTime.MaxValue wird nicht unterstützt, weil zu dem EndDate noch etwas draufaddiert wird und dann der MaxValue überschritten werden würde
|
|
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 IMainSessionointment;
|
|
|
|
if(item.IsRecurring)
|
|
{
|
|
var ausnahmen = item.GetExceptions();
|
|
foreach(var exc in ausnahmen)
|
|
{
|
|
var b = exc.GetSourceObject(Scheduler.GetCoreStorage()) as IMainSessionointment;
|
|
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;
|
|
}
|
|
}
|
|
|
|
private void UpdateSchedulerSettings()
|
|
{
|
|
var settings = ViewModel.GetActiveSettings();
|
|
Scheduler.Start = settings.StartDate;
|
|
var starttimeInterval = settings.StartDate.Date;
|
|
|
|
if (_SelectedAppointmentStartDate.HasValue)
|
|
{
|
|
var weekOfYear = _SelectedAppointmentStartDate.Value.GetIso8601WeekOfYear();
|
|
var monday = _SelectedAppointmentStartDate.Value.FirstDateOfWeek(weekOfYear);
|
|
|
|
settings.StartDate = monday;
|
|
|
|
Scheduler.Start = monday;
|
|
starttimeInterval = settings.StartDate;
|
|
|
|
settings.ViewType = _SelectedAppointmentStartDate.Value.DayOfWeek == DayOfWeek.Saturday || _SelectedAppointmentStartDate.Value.DayOfWeek == DayOfWeek.Sunday ? AppointmentViewType.Week : AppointmentViewType.WorkWeek;
|
|
_SelectedAppointmentStartDate = null;
|
|
}
|
|
else
|
|
{
|
|
settings.ViewType = ViewTypeConvert.ToAppointmentViewType(_CurrentViewType);
|
|
}
|
|
|
|
starttimeInterval = starttimeInterval.AddHours(Scheduler.WorkWeekView.WorkTime.Start.Hours);
|
|
|
|
|
|
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);
|
|
}
|
|
}
|
|
|
|
private void UpdateCustomFieldMappings(ISchedulerViewModel vm)
|
|
{
|
|
Scheduler.Storage.AppointmentStorage.CustomFieldMappings.Clear();
|
|
vm.AddCustomFieldsMapping(Scheduler.Storage);
|
|
}
|
|
#endregion
|
|
|
|
public CheckBoxConverter CheckBoxConverter => Resources[nameof(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;
|
|
ReloadVM(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)
|
|
{
|
|
ReloadVM(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(MainSession.CompactLoggedOnEmployee))
|
|
{
|
|
ZeigeNurMeineTermine = false;
|
|
ReloadVM(true);
|
|
}
|
|
else if (SelectedEmployees.Count == 1 && SelectedEmployees.First().Equals(MainSession.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(nameof(Enabled));
|
|
}
|
|
}
|
|
|
|
public void UpdateRequestString()
|
|
{
|
|
ServiceFacade.DoResourceServiceSync(r => _Liste = r.GetAllOpenAppointmentsForEmployee(MainSession.LoggedOnEmployee.EmployeeOid.Value));
|
|
|
|
var count = 0;
|
|
var oidList = new List<long>();
|
|
foreach (var termin in _Liste)
|
|
{
|
|
if (termin.Originator.EmployeeOid == MainSession.LoggedOnEmployee.EmployeeOid.Value)
|
|
{
|
|
foreach (var status in termin.EmployeeList.Where(w => w.Employee.EmployeeOid != MainSession.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 == MainSession.LoggedOnEmployee.EmployeeOid.Value))
|
|
{
|
|
foreach (var status in termin.EmployeeList.Where(w => w.Employee.EmployeeOid == MainSession.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 || IgnoreManualAppointmentCreation)
|
|
{
|
|
return;
|
|
}
|
|
|
|
Debug.WriteLine("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ NewSchedulerStorage_AppointmentsChanged");
|
|
|
|
var appList = e.Objects.Cast<Appointment>().ToList();
|
|
|
|
if (appList.Any(f => f.CF_IsPrivate()))
|
|
{
|
|
ShowPrivateAppointmentsCheckBox.IsChecked = true;
|
|
}
|
|
|
|
ViewModel.ActiveAppointmentViewModel.SaveAppointments(Scheduler, appList);
|
|
|
|
ReloadVM(true);
|
|
}
|
|
|
|
private void NewSchedulerStorage_AppointmentDeleting(object sender, PersistentObjectCancelEventArgs e)
|
|
{
|
|
var appointment = (Appointment) e.Object;
|
|
var sourceObj = (SchedulerAppointmentVM) appointment.GetSourceObject(Scheduler.GetCoreStorage());
|
|
|
|
if(appointment != null && sourceObj != null)
|
|
{
|
|
if(!BeWoUtils.CheckSchedulerRights(appointment, sourceObj.IsNew, SchedulerRightsCheckType.Edit))
|
|
{
|
|
e.Cancel = true;
|
|
return;
|
|
}
|
|
}
|
|
|
|
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);
|
|
}
|
|
|
|
var dcList = appList.Select(item => item.GetSourceObject(Scheduler.GetCoreStorage())).OfType<SchedulerAppointmentVM>().Select(vm => vm.CommitToDataContract()).Where(dc => dc.SchedulerAppointmentOid.HasValue).ToList();
|
|
var idList = (from item in dcList where item.SchedulerAppointmentOid.HasValue select item.SchedulerAppointmentOid.Value).ToList();
|
|
|
|
IgnoreChangeEvents = true;
|
|
|
|
ServiceFacade.DoResourceServiceAsync(s => s.GetSchedulerAppointmentsById(idList), appointments =>
|
|
{
|
|
ServiceFacade.DoResourceServiceAsync(s2 => s2.DeactivateSchedulerAppointmentsForSync(appointments.ToDictionary(dc => dc.SchedulerAppointmentOid.Value, dc => dc.NewSchedulerAppointmentVersion.Value)), updatedAppointments =>
|
|
{
|
|
ViewModel.ActiveAppointmentViewModel.UpdateViewModel(updatedAppointments);
|
|
|
|
this.Dispatch(() =>
|
|
{
|
|
Scheduler.ActiveView.LayoutChanged();
|
|
UpdateRequestString();
|
|
ReloadVM(true);
|
|
});
|
|
|
|
IgnoreChangeEvents = false;
|
|
});
|
|
});
|
|
}
|
|
}
|
|
}
|
|
|
|
private void NewSchedulerStorage_AppointmentsInserted(object sender, PersistentObjectsEventArgs e)
|
|
{
|
|
if(IgnoreManualAppointmentCreation)
|
|
{
|
|
return;
|
|
}
|
|
|
|
var appList = e.Objects.Cast<Appointment>().ToList();
|
|
|
|
if(appList.Any(f => f.CF_IsPrivate()))
|
|
{
|
|
ShowPrivateAppointmentsCheckBox.IsChecked = true;
|
|
}
|
|
|
|
ViewModel.ActiveAppointmentViewModel.InsertAppointments(Scheduler, appList);
|
|
UpdateRequestString();
|
|
ReloadVM(true);
|
|
}
|
|
|
|
private void Scheduler_EditAppointmentFormShowing(object sender, EditAppointmentFormEventArgs e)
|
|
{
|
|
var control = (SchedulerControl) sender;
|
|
|
|
IgnoreChangeEvents = true;
|
|
|
|
if (_IsNew)
|
|
{
|
|
var n = new ObservableCollection<Employee2SchedulerAppointmentDC>(SelectedEmployees.Select(item => new Employee2SchedulerAppointmentDC { Employee = item, ParticipationAnswer = ParticipationAnswer.Offen }).ToList());
|
|
e.Appointment.CF_EmployeeList(n);
|
|
e.Appointment.CF_CustomerList(new List<CompactCustomerDC>(SelectedCustomers));
|
|
e.Appointment.CF_ResourceList(new List<ResourceDC>(SelectedResources));
|
|
}
|
|
|
|
var form = ViewModel.GetEditAppointmentForm(control, e.Appointment);
|
|
if (form == null)
|
|
{
|
|
if(_IsNew)
|
|
{
|
|
_IsNew = false;
|
|
}
|
|
|
|
IgnoreChangeEvents = false;
|
|
|
|
return;
|
|
}
|
|
|
|
e.Form = form;
|
|
e.AllowResize = false;
|
|
|
|
if (_IsNew)
|
|
{
|
|
_IsNew = false;
|
|
}
|
|
|
|
IgnoreChangeEvents = false;
|
|
}
|
|
|
|
private void SchedulerControl_EditRecurrentAppointmentFormShowing(object sender, EditAppointmentFormEventArgs e) { }
|
|
|
|
private void Scheduler_PopupMenuShowing(object sender, SchedulerMenuEventArgs e)
|
|
{
|
|
if(Scheduler.SelectedAppointments?.Count == 1)
|
|
{
|
|
bool isAllowedToEdit;
|
|
var test = Scheduler.SelectedAppointments.First();
|
|
if(test.IsOccurrence)
|
|
{
|
|
var patternAppointment = test.RecurrencePattern;
|
|
var sourceObject = patternAppointment.GetSourceObject(Scheduler.GetCoreStorage());
|
|
var viewModel = (SchedulerAppointmentVM) sourceObject;
|
|
|
|
isAllowedToEdit = BeWoUtils.CheckSchedulerRights(test, viewModel.IsNew, SchedulerRightsCheckType.Edit);
|
|
}
|
|
else
|
|
{
|
|
isAllowedToEdit = Scheduler.SelectedAppointments.Any(a => BeWoUtils.CheckSchedulerRights(a, ((SchedulerAppointmentVM)a.GetSourceObject(Scheduler.GetCoreStorage())).IsNew, SchedulerRightsCheckType.Edit));
|
|
}
|
|
|
|
if(!isAllowedToEdit)
|
|
{
|
|
var menuItem = e.Menu.ItemLinks.FirstOrDefault(f => f.Name.Contains("DeleteAppointment"));
|
|
|
|
if(menuItem != null)
|
|
{
|
|
e.Menu.ItemLinks.Remove(menuItem);
|
|
}
|
|
}
|
|
}
|
|
|
|
if(!MainSession.LoggedOnUser.HasRight(UserRightType.KalenderMitarbeitertermineAnsehen) || !MainSession.LoggedOnUser.HasRight(UserRightType.Mitarbeiterstundenkonto_ViewAll))
|
|
{
|
|
var verfuegbarkeitMenue = e.Menu.ItemLinks.FirstOrDefault(f => f.GetType() == typeof(BarButtonItemLink) && (((BarButtonItemLink)f).Item?.Name.Contains("MitarbeiterVerfuegbarkeitPruefenButtonItem") ?? false));
|
|
|
|
if (verfuegbarkeitMenue != null)
|
|
{
|
|
e.Menu.ItemLinks.Remove(verfuegbarkeitMenue);
|
|
}
|
|
}
|
|
|
|
if(Scheduler.SelectedAppointments.Count == 0 || Scheduler.SelectedAppointments[0]?.Type != AppointmentType.ChangedOccurrence)
|
|
{
|
|
var restoreMenu = e.Menu.ItemLinks.FirstOrDefault(f =>
|
|
{
|
|
var type = f.GetType();
|
|
if(type == typeof(BarButtonItemLink))
|
|
{
|
|
var item = (BarButtonItemLink) f;
|
|
|
|
if(item.Name.Contains("RestoreAppointmentButtonItem"))
|
|
{
|
|
return true;
|
|
}
|
|
}
|
|
|
|
return false;
|
|
});
|
|
|
|
if(restoreMenu != null)
|
|
{
|
|
e.Menu.ItemLinks.Remove(restoreMenu);
|
|
}
|
|
}
|
|
|
|
if(!MainSession.LoggedOnUser.HasRight(UserRightType.KalenderInZeiterfassungUebernehmen))
|
|
{
|
|
BarItemLinkBase menuItem = null;
|
|
|
|
foreach(var item in e.Menu.ItemLinks)
|
|
{
|
|
if(item.GetType() == typeof(BarButtonItemLink))
|
|
{
|
|
var barButton = (BarButtonItemLink) item;
|
|
|
|
if(barButton.Name.Contains("ZeiterfassungButtonItem"))
|
|
{
|
|
menuItem = item;
|
|
}
|
|
}
|
|
}
|
|
|
|
if(menuItem != null)
|
|
{
|
|
e.Menu.ItemLinks.Remove(menuItem);
|
|
}
|
|
|
|
}
|
|
|
|
if (Scheduler.SelectedAppointments.Count > 0)
|
|
{
|
|
var zusageButton = e.Menu.ItemLinks.FirstOrDefault(f => f.GetType() == typeof(BarButtonItemLink) && ((BarButtonItemLink) f).BarItemName.Equals("ZusagenButtonItem"));
|
|
var mitVorbehaltButton = e.Menu.ItemLinks.FirstOrDefault(f => f.GetType() == typeof(BarButtonItemLink) && ((BarButtonItemLink) f).BarItemName.Equals("MitVorbehaltButtonItem"));
|
|
var absageButton = e.Menu.ItemLinks.FirstOrDefault(f => f.GetType() == typeof(BarButtonItemLink) && ((BarButtonItemLink) f).BarItemName.Equals("AbsagenButtonItem"));
|
|
var seperatorTop = e.Menu.ItemLinks.FirstOrDefault(f => f.GetType() == typeof(BarItemLinkSeparator) && ((BarItemLinkSeparator) f).BarItemName.Equals("ZusagenStackSeperatorTop"));
|
|
var seperatorBottom = e.Menu.ItemLinks.FirstOrDefault(f => f.GetType() == typeof(BarItemLinkSeparator) && ((BarItemLinkSeparator) f).BarItemName.Equals("ZusagenStackSeperatorBottom"));
|
|
|
|
if(!Scheduler.SelectedAppointments[0].CF_IsTask() && Scheduler.SelectedAppointments[0].CF_EmployeeList().Any(a => a.Employee.EmployeeOid.Equals(MainSession.LoggedOnEmployee.EmployeeOid)))
|
|
{
|
|
return;
|
|
}
|
|
|
|
if(seperatorTop != null)
|
|
{
|
|
e.Menu.ItemLinks.Remove(seperatorTop);
|
|
}
|
|
|
|
if(seperatorBottom != null)
|
|
{
|
|
e.Menu.ItemLinks.Remove(seperatorBottom);
|
|
}
|
|
|
|
if (zusageButton != null)
|
|
{
|
|
e.Menu.ItemLinks.Remove(zusageButton);
|
|
}
|
|
|
|
if (mitVorbehaltButton != null)
|
|
{
|
|
e.Menu.ItemLinks.Remove(mitVorbehaltButton);
|
|
}
|
|
|
|
if (absageButton != null)
|
|
{
|
|
e.Menu.ItemLinks.Remove(absageButton);
|
|
}
|
|
}
|
|
}
|
|
|
|
private bool _IsNew;
|
|
private void Scheduler_InitNewAppointment(object sender, AppointmentEventArgs e)
|
|
{
|
|
_IsNew = true;
|
|
ViewModel.InitNewAppointment(e.Appointment);
|
|
}
|
|
|
|
private void Scheduler_AppointmentViewInfoCustomizing(object sender, AppointmentViewInfoCustomizingEventArgs e)
|
|
{
|
|
var cf = e.ViewInfo.Appointment.CustomFields;
|
|
|
|
if(cf[nameof(CustomFieldStorage)] == null)
|
|
{
|
|
return;
|
|
}
|
|
|
|
cf.BeginUpdate();
|
|
|
|
e.ViewInfo.CustomViewInfo = cf;
|
|
|
|
cf.EndUpdate();
|
|
}
|
|
|
|
private void AllowAppointmentAenderung(object sender, AppointmentOperationEventArgs e)
|
|
{
|
|
var darfTerminDetailsSehen = true;
|
|
var appointment = e.Appointment;
|
|
|
|
if(appointment.GetCustomFieldStorage() == null)
|
|
{
|
|
e.Allow = false;
|
|
return;
|
|
}
|
|
|
|
if(appointment.CF_IsAbsenceTime())
|
|
{
|
|
e.Allow = false;
|
|
return;
|
|
}
|
|
|
|
var ersteller = appointment.CF_Originator();
|
|
var mitarbeiterliste = appointment.CF_EmployeeList();
|
|
var istErsteller = ersteller?.EmployeeOid.Equals(MainSession.LoggedOnEmployee.EmployeeOid) ?? false;
|
|
|
|
if(!istErsteller && appointment.CF_IsPrivate() && !mitarbeiterliste.Any(a => Equals(a.Employee, MainSession.CompactLoggedOnEmployee)))
|
|
{
|
|
darfTerminDetailsSehen = false;
|
|
}
|
|
|
|
e.Allow = darfTerminDetailsSehen;
|
|
}
|
|
|
|
private void AllowAppointmentCreateEvent(object sender, AppointmentOperationEventArgs e)
|
|
{
|
|
var darfAnlegen = (MainSession.LoggedOnUser.HasRight(UserRightType.KalenderKliententermineAnlegen) || MainSession.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)
|
|
{
|
|
ReloadVM(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)
|
|
{
|
|
//!MainSession.LoggedOnUser.HasRight(UserRightType.CustomerView_View) && MainSession.LoggedOnUser.HasRight(UserRightType.Customer_ViewMyCustomers) ? AllCustomers :
|
|
|
|
var relatedCustomerOids = MainSession.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 customFieldStorage = (CustomFieldStorage) app.CustomFields[nameof(CustomFieldStorage)];
|
|
|
|
var originator = customFieldStorage.Originator;
|
|
|
|
if(customFieldStorage.EmployeeList == null || originator.EmployeeOid == MainSession.LoggedOnEmployee.EmployeeOid.Value)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
var empList = customFieldStorage.EmployeeList;
|
|
|
|
return empList.Any(a => a.Employee.EmployeeOid.Equals(MainSession.LoggedOnEmployee.EmployeeOid) && a.ParticipationAnswer == ParticipationAnswer.Offen);
|
|
}).ToList();
|
|
|
|
var updates = vm.Appointments.Where(app =>
|
|
{
|
|
var customFieldStorage = (CustomFieldStorage)app.CustomFields[nameof(CustomFieldStorage)];
|
|
|
|
if(customFieldStorage.Originator == null || customFieldStorage.EmployeeList == null)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
var empList = customFieldStorage.EmployeeList;
|
|
var or = customFieldStorage.Originator;
|
|
|
|
return or.EmployeeOid.Equals(MainSession.LoggedOnEmployee.EmployeeOid) && empList.Any(a => a.IsPChanged && a.ParticipationAnswer != ParticipationAnswer.Offen && a.ParticipationAnswer != ParticipationAnswer.Verstrichen && !a.Employee.EmployeeOid.Equals(MainSession.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)
|
|
{
|
|
ReloadVM(true);
|
|
UpdateRequestString();
|
|
}
|
|
|
|
public void ShowAppointmentRequests(object sender, RequestNavigateEventArgs e)
|
|
{
|
|
FensterOeffnen();
|
|
}
|
|
|
|
private void UpdateBeiParticipationChanged(object sender, EventArgs e)
|
|
{
|
|
ReloadVM(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(nameof(SelectedCustomers));
|
|
OnPropertyChanged(nameof(SelectedEmployees));
|
|
OnPropertyChanged(nameof(SelectedResources));
|
|
OnPropertyChanged(nameof(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)
|
|
{
|
|
ReloadVM(true);
|
|
}
|
|
|
|
//private void ExportButton_OnClick(object sender, RoutedEventArgs e)
|
|
//{
|
|
// SaveFileDialog dialog = new SaveFileDialog
|
|
// {
|
|
// Filter = "iCalendar files (*.ics)|*.ics",
|
|
// FilterIndex = 1
|
|
// };
|
|
|
|
// if (dialog.ShowDialog() == true)
|
|
// {
|
|
// using (Stream stream = dialog.OpenFile())
|
|
// {
|
|
// iCalendarExporter exporter = new iCalendarExporter(Scheduler.Storage.InnerStorage);
|
|
// exporter.Export(stream);
|
|
// }
|
|
// }
|
|
//}
|
|
|
|
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 = sa.CF_EmployeeList();
|
|
var neu = new ObservableCollection<Employee2SchedulerAppointmentDC>(el.DoForEach(dfe =>
|
|
{
|
|
if(!dfe.Employee.EmployeeOid.Equals(MainSession.LoggedOnEmployee.EmployeeOid))
|
|
{
|
|
return;
|
|
}
|
|
|
|
dfe.ParticipationAnswer = antwort;
|
|
dfe.IsPC_CheckedTs = null;
|
|
}).ToList());
|
|
sa.CF_EmployeeList(neu);
|
|
|
|
var appointment = (SchedulerAppointmentVM) sa.GetSourceObject(Scheduler.GetCoreStorage());
|
|
|
|
ServiceFacade.DoResourceServiceAsync(s => s.UpdateSchedulerAppointments(new List<SchedulerAppointmentDC>{ appointment.CommitToDataContract() }), delegate { this.Dispatch(() => {ReloadVM(true);}); });
|
|
}
|
|
|
|
private void ZeiterfassungButtonItem_OnItemClick(object sender, ItemClickEventArgs e)
|
|
{
|
|
if (Scheduler.SelectedAppointments.Count <= 0)
|
|
{
|
|
return;
|
|
}
|
|
|
|
var appointment = Scheduler.SelectedAppointments.FirstOrDefault();
|
|
|
|
if(appointment == null)
|
|
{
|
|
return;
|
|
}
|
|
|
|
var employee2SchedulerAppointmentList = appointment.CF_EmployeeList();
|
|
var customerList = appointment.CF_CustomerList();
|
|
|
|
var employeeList = employee2SchedulerAppointmentList.Select(employee2SchedulerAppointment => employee2SchedulerAppointment.Employee).ToList();
|
|
|
|
BeWoUtils.CreateZeiterfassung(appointment.Start, appointment.End, customerList, employeeList, appointment.Subject, appointment, () =>
|
|
{
|
|
try
|
|
{
|
|
IgnoreManualAppointmentCreation = true;
|
|
IgnoreChangeEvents = true;
|
|
|
|
var schedulerAppointment = (SchedulerAppointmentVM) appointment.GetSourceObject(Scheduler.GetCoreStorage());
|
|
|
|
var appointmentOid = schedulerAppointment?.CommitToDataContract().SchedulerAppointmentOid;
|
|
|
|
if(appointmentOid.HasValue)
|
|
{
|
|
appointment.CF_HasServiceRecordEntry(true);
|
|
|
|
ViewModel.ActiveAppointmentViewModel.SaveAppointments(Scheduler, new List<Appointment> {appointment});
|
|
|
|
ReloadVM(true);
|
|
}
|
|
else
|
|
{
|
|
// Serientermin!
|
|
var recurrenceInfo = appointment.RecurrenceInfo;
|
|
|
|
var pattern = StaticAppointmentFactory.CreateAppointment(AppointmentType.Pattern);
|
|
pattern.RecurrenceInfo.FromXml(recurrenceInfo.ToXml());
|
|
|
|
var apt = appointment.RecurrencePattern.CreateException(AppointmentType.ChangedOccurrence, appointment.RecurrenceIndex);
|
|
|
|
apt.Duration = appointment.Duration;
|
|
apt.End = apt.Start.Add(appointment.Duration);
|
|
|
|
apt.Subject = appointment.Subject;
|
|
apt.Location = appointment.Location;
|
|
apt.Description = appointment.Description;
|
|
|
|
Scheduler.Storage.AppointmentStorage.CreateCustomFields(apt);
|
|
|
|
apt.CustomFields[nameof(CustomFieldStorage)] = appointment.CustomFields[nameof(CustomFieldStorage)];
|
|
|
|
apt.CF_HasServiceRecordEntry(true);
|
|
|
|
ViewModel.ActiveAppointmentViewModel.InsertAppointments(Scheduler, new List<Appointment> {apt});
|
|
|
|
IgnoreChangeEvents = true;
|
|
|
|
ReloadVM(true);
|
|
}
|
|
}
|
|
finally
|
|
{
|
|
IgnoreManualAppointmentCreation = false;
|
|
IgnoreChangeEvents = false;
|
|
}
|
|
});
|
|
}
|
|
|
|
private bool IgnoreManualAppointmentCreation { get; set; }
|
|
|
|
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)
|
|
{
|
|
if(_LastFetchingDateTime != null && _LastFetchingDateTime.Value < DateTime.Now.AddMilliseconds(-500d))
|
|
{
|
|
return;
|
|
}
|
|
|
|
_LastFetchingDateTime = DateTime.Now;
|
|
|
|
ReloadVM();
|
|
}
|
|
|
|
private bool _ReloadingViewModel;
|
|
private DateTime? _LastFetchingDateTime;
|
|
|
|
private void ReloadVM(bool shouldForceReload = false)
|
|
{
|
|
if (_ReloadingViewModel)
|
|
{
|
|
return;
|
|
}
|
|
|
|
_ReloadingViewModel = true;
|
|
|
|
if (ViewModel == null)
|
|
{
|
|
_ReloadingViewModel = 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(!shouldForceReload && newFetchingInterval.Equals(_LastFetchedInterval))
|
|
{
|
|
_ReloadingViewModel = false;
|
|
return;
|
|
}
|
|
|
|
_LastFetchedInterval = newFetchingInterval;
|
|
|
|
ReloadAppointmentViewModel(start, end, selectedEmployeeOids, selectedCustomerOids, selectedResourceOids, employeesOnly, customersOnly, resourcesOnly, onlyPrivateAppointments, showOnlyMyAppointments, showAbsenceTimes);
|
|
}
|
|
|
|
public void ReloadAppointmentViewModel(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 (!MainSession.LoggedOnEmployee.EmployeeOid.HasValue)
|
|
{
|
|
return;
|
|
}
|
|
|
|
var start = pIntervalStart - FetchPadding;
|
|
var end = pIntervalEnd + FetchPadding;
|
|
|
|
GetCacheObjects((c, e, r) =>
|
|
{
|
|
ServiceFacade.DoResourceServiceAsync(s2 => s2.LoadFilteredAppointmentsMitAufgaben(MainSession.HasLoggedOnUserRight(new[] {UserRightType.KalenderMitarbeitertermineAnsehen}), MainSession.LoggedOnEmployee.EmployeeOid.Value, start, end, pSelectedEmployees, pSelectedCustomer, pSelectedResources, pEmployeesOnly, pCustomersOnly, pResourcesOnly, pPrivateAppointmentsOnly, pOnlyMyAppointments, IsTasksVisible),
|
|
appointments =>
|
|
{
|
|
ServiceFacade.DoResourceServiceAsync(s3 => s3.GetAllActiveAbsenceTimesInInterval(start, end, MainSession.LoggedOnEmployee.EmployeeOid.Value, MainSession.LoggedOnUser.HasRight(UserRightType.KalenderMitarbeitertermineAnsehen)),
|
|
absenceTimes =>
|
|
{
|
|
this.Dispatch(() =>
|
|
{
|
|
var prefilteredAppointments = appointments.Where(w => (w.EmployeeList.Count == 0 && w.Originator.EmployeeOid.Equals(MainSession.LoggedOnEmployee.EmployeeOid) ||
|
|
w.EmployeeList.Count > 0 && w.EmployeeList.Any(a => a.Employee.EmployeeOid.Equals(MainSession.LoggedOnEmployee.EmployeeOid)) ||
|
|
BeWoUtils.HasRight(UserRightType.KalenderMitarbeitertermineAnsehen)) && (!w.EmployeeList.TrueForAll(e2a => e2a.ParticipationAnswer == ParticipationAnswer.Absage) || w.EmployeeList == null || w.EmployeeList.Count == 0)).ToList();
|
|
|
|
var vm = new SchedulerAppointmentListVM(prefilteredAppointments, c, e, r);
|
|
if(pShouldShowAbsenceTimes)
|
|
{
|
|
vm.Appointments.AddRange(ViewModel.ConvertAbsenceTimesToAppointments(absenceTimes.Where(w =>
|
|
{
|
|
return SelectedEmployees.Count == 0 || SelectedEmployees.Any(a => a.EmployeeOid == w.EmployeeOid);
|
|
}), end, e));
|
|
}
|
|
|
|
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;
|
|
|
|
_ReloadingViewModel = false;
|
|
|
|
Scheduler.Storage.RefreshData();
|
|
Scheduler.Storage.RefreshUI();
|
|
|
|
if (_IsComingFromHomeDragPanel && _SelectedAppointmentFromHomePanelView != null)
|
|
{
|
|
var apps = Scheduler.ActiveView.GetAppointments().ToList();
|
|
|
|
var oid = _SelectedAppointmentFromHomePanelView.SchedulerAppointmentOid;
|
|
Appointment appointmentToOpen;
|
|
|
|
if (oid != null)
|
|
{
|
|
appointmentToOpen = apps.Find(app =>
|
|
{
|
|
var oidValue = app.CF_SchedulerAppointmentOid();
|
|
|
|
return oidValue.HasValue && oidValue.Value == oid;
|
|
});
|
|
|
|
|
|
if (appointmentToOpen != null)
|
|
{
|
|
Scheduler.ShowEditAppointmentForm(appointmentToOpen);
|
|
}
|
|
}
|
|
else if (_SelectedAppointmentFromHomePanelView.RecurrenceId != null && _SelectedAppointmentFromHomePanelView.RecurrenceIndex > 0)
|
|
{
|
|
appointmentToOpen = apps.Find(appointment => appointment.RecurrenceInfo.Id.ToString().Equals(_SelectedAppointmentFromHomePanelView.RecurrenceId));
|
|
|
|
if (appointmentToOpen != null)
|
|
{
|
|
Scheduler.ShowEditAppointmentForm(appointmentToOpen);
|
|
}
|
|
}
|
|
|
|
_IsComingFromHomeDragPanel = false;
|
|
}
|
|
});
|
|
});
|
|
});
|
|
});
|
|
}
|
|
|
|
private void ExportButton_OnClick(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", MainSession.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)
|
|
{
|
|
appointmentExportingEventArgs.Cancel = !Scheduler.ActiveView.GetAppointments().Contains(appointmentExportingEventArgs.Appointment);
|
|
}
|
|
|
|
//private void OnAppointmentExporting(object sender, AppointmentExportingEventArgs appointmentExportingEventArgs)
|
|
//{
|
|
// var iCalArgs = (iCalendarAppointmentExportingEventArgs)appointmentExportingEventArgs;
|
|
// var vEvent = iCalArgs.VEvent;
|
|
|
|
// var ma = (ObservableCollection<Employee2SchedulerAppointmentDC>)appointmentExportingEventArgs.Appointment.CF_EmployeeList();
|
|
// var ca = (List<CompactCustomerDC>)appointmentExportingEventArgs.Appointment.CF_CustomerList();
|
|
// var ra = (List<ResourceDC>)appointmentExportingEventArgs.Appointment.CF_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.CF_IsAbsenceTime()).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.ToList(), 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 (tage > 31)
|
|
{
|
|
tage = 31;
|
|
}
|
|
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", MainSession.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)
|
|
{
|
|
_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))))
|
|
{
|
|
ReloadVM();
|
|
}
|
|
}
|
|
|
|
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 && MainSession.CompactLoggedOnEmployee != null)
|
|
{
|
|
if (cb.IsChecked != null && cb.IsChecked.Value)
|
|
{
|
|
SelectedEmployees = new List<CompactEmployeeDC>{MainSession.CompactLoggedOnEmployee};
|
|
CheckBoxConverter.AktuellerMitarbeiter = MainSession.CompactLoggedOnEmployee;
|
|
}
|
|
else if (cb.IsChecked != null && !cb.IsChecked.Value && SelectedEmployees.Count == 1)
|
|
{
|
|
SelectedEmployees.Remove(MainSession.CompactLoggedOnEmployee);
|
|
CheckBoxConverter.AktuellerMitarbeiter = null;
|
|
}
|
|
|
|
OnPropertyChanged(nameof(SelectedEmployees));
|
|
OnPropertyChanged(nameof(SelectedItems));
|
|
|
|
ReloadVM(true);
|
|
}
|
|
}
|
|
|
|
private void AbwesenheitenEinAusCheckBox_OnChecked(object sender, RoutedEventArgs e)
|
|
{
|
|
var cb = (CheckBox) sender;
|
|
IsAbsenceTimeVisible = cb.IsChecked ?? true;
|
|
|
|
ReloadVM(true);
|
|
}
|
|
|
|
public 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
|
|
}
|
|
|
|
public static void WriteMethodCallToLog(long pElapsedMilliseconds)
|
|
{
|
|
#if DEBUG
|
|
var callerName = new StackTrace().GetFrame(1).GetMethod().Name;
|
|
|
|
using(var logFile = new StreamWriter(Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + @"\method_calls_log.txt", true))
|
|
{
|
|
logFile.WriteLine($"{callerName} took {pElapsedMilliseconds} ms");
|
|
}
|
|
#endif
|
|
}
|
|
|
|
private void Scheduler_OnInplaceEditorShowing(object sender, InplaceEditorEventArgs e)
|
|
{
|
|
if(_IsNew)
|
|
{
|
|
var n = new ObservableCollection<Employee2SchedulerAppointmentDC>(SelectedEmployees.Select(item => new Employee2SchedulerAppointmentDC { Employee = item, ParticipationAnswer = ParticipationAnswer.Offen }).ToList());
|
|
e.Appointment.CF_EmployeeList(n);
|
|
e.Appointment.CF_CustomerList(new List<CompactCustomerDC>(SelectedCustomers));
|
|
e.Appointment.CF_ResourceList(new List<ResourceDC>(SelectedResources));
|
|
|
|
_IsNew = false;
|
|
}
|
|
}
|
|
|
|
private void ButtonDeleteAppointmentsInInterval_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
DeleteAppointmentsPopup.IsOpen = true;
|
|
}
|
|
|
|
private void AbortDeletingAppointments_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
DeleteAppointmentsPopup.IsOpen = false;
|
|
}
|
|
|
|
private void DeleteAppointmentsForGood_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
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 loggedOnUserHasRightToSeeAllAppointments = MainSession.LoggedOnUser.HasRight(UserRightType.KalenderKliententermineAlleAnsehen) || MainSession.LoggedOnUser.HasRight(UserRightType.ViewAll);
|
|
var loggedOnEmployeeOid = MainSession.LoggedOnEmployee.EmployeeOid.Value;
|
|
var date = DeleteForGoodIntervalEndDateEdit.DateTime;
|
|
|
|
var userRights = new Dictionary<UserRightType, bool>
|
|
{
|
|
{
|
|
UserRightType.KalenderKliententermineAendern, MainSession.LoggedOnUser.HasRight(UserRightType.KalenderKliententermineAendern)
|
|
},
|
|
{
|
|
UserRightType.KalenderMitarbeitertermineAendern, MainSession.LoggedOnUser.HasRight(UserRightType.KalenderMitarbeitertermineAendern)
|
|
},
|
|
{
|
|
UserRightType.KalenderRessourcentermineAendern, MainSession.LoggedOnUser.HasRight(UserRightType.KalenderRessourcentermineAendern)
|
|
},
|
|
{
|
|
UserRightType.KalenderRessourcentermineAndererAendern, MainSession.LoggedOnUser.HasRight(UserRightType.KalenderRessourcentermineAndererAendern)
|
|
}
|
|
};
|
|
|
|
var dialog = new MessageDialog(() =>
|
|
{
|
|
ServiceFacade.DoOperationsServiceAsync(s => s.DeleteAppointmentsInInterval(
|
|
loggedOnUserHasRightToSeeAllAppointments,
|
|
loggedOnEmployeeOid,
|
|
date,
|
|
SelectedEmployees.Select(employee => employee.EmployeeOid).ToList(),
|
|
SelectedCustomers.Select(customer => customer.CustomerOid).ToList(),
|
|
SelectedResources.Select(resource => resource.ResourceOid.Value).ToList(),
|
|
employeesOnly,
|
|
customersOnly,
|
|
resourcesOnly,
|
|
onlyPrivateAppointments,
|
|
showOnlyMyAppointments,
|
|
userRights), () =>
|
|
{
|
|
this.Dispatch(() =>
|
|
{
|
|
DeleteAppointmentsPopup.IsOpen = false;
|
|
ReloadVM(true);
|
|
});
|
|
});
|
|
});
|
|
|
|
ServiceFacade.DoOperationsServiceAsync(
|
|
s => s.GetMessageFromServerForDeletingAppointments(
|
|
loggedOnUserHasRightToSeeAllAppointments,
|
|
loggedOnEmployeeOid,
|
|
date,
|
|
SelectedEmployees.Select(employee => employee.EmployeeOid).ToList(),
|
|
SelectedCustomers.Select(customer => customer.CustomerOid).ToList(),
|
|
SelectedResources.Select(resource => resource.ResourceOid.Value).ToList(),
|
|
employeesOnly,
|
|
customersOnly,
|
|
resourcesOnly,
|
|
onlyPrivateAppointments,
|
|
showOnlyMyAppointments,
|
|
userRights), xaml =>
|
|
{
|
|
this.Dispatch(() =>
|
|
{
|
|
dialog.SetXaml(xaml);
|
|
dialog.ShowDialog();
|
|
});
|
|
});
|
|
}
|
|
|
|
private void RestoreAppointmentButtonItem_OnItemClick(object sender, ItemClickEventArgs e)
|
|
{
|
|
var appointmentToRestore = Scheduler.SelectedAppointments[0];
|
|
|
|
var appointmentVM = (SchedulerAppointmentVM) appointmentToRestore.GetSourceObject(Scheduler.GetCoreStorage());
|
|
|
|
var appointmentDC = appointmentVM?.CommitToDataContract();
|
|
|
|
if(appointmentDC?.SchedulerAppointmentOid == null || appointmentDC.NewSchedulerAppointmentVersion == null || appointmentToRestore.Type != AppointmentType.ChangedOccurrence)
|
|
{
|
|
return;
|
|
}
|
|
|
|
ServiceFacade.DoResourceServiceAsync(s => s.GetSchedulerAppointmentByid(appointmentDC.SchedulerAppointmentOid.Value), appointment =>
|
|
{
|
|
if(appointment.SchedulerAppointmentOid == null || appointment.NewSchedulerAppointmentVersion == null)
|
|
{
|
|
return;
|
|
}
|
|
|
|
ServiceFacade.DoResourceServiceAsync(s => s.DeleteSchedulerAppointments(new Dictionary<long, long> { { appointment.SchedulerAppointmentOid.Value, appointment.NewSchedulerAppointmentVersion.Value } }),
|
|
() =>
|
|
{
|
|
this.Dispatch(() =>
|
|
{
|
|
ReloadVM(true);
|
|
});
|
|
});
|
|
});
|
|
}
|
|
|
|
private void AufgabeAnlegen_OnItemClick(object sender, ItemClickEventArgs e)
|
|
{
|
|
var end = Scheduler.SelectedInterval.End.GetShortDateTime();
|
|
var dueDate = Scheduler.SelectedInterval.End;
|
|
var start = end.AddDays(1);
|
|
|
|
var newTask = Scheduler.Storage.CreateAppointment(AppointmentType.Normal);
|
|
|
|
newTask.Start = end;
|
|
newTask.End = start;
|
|
newTask.AllDay = true;
|
|
newTask.Subject = "Neue Aufgabe";
|
|
|
|
var employees2Appointments = SelectedEmployees.Select(item => new Employee2SchedulerAppointmentDC { Employee = item, ParticipationAnswer = ParticipationAnswer.Offen }).ToList();
|
|
|
|
ViewModel.InitNewTask(newTask, dueDate, employees2Appointments, SelectedCustomers, SelectedResources, new List<CompactSupportConceptDC>());
|
|
|
|
Scheduler.ShowEditAppointmentForm(newTask);
|
|
}
|
|
|
|
private void ShowTasksCheckBox_OnClick(object sender, RoutedEventArgs e)
|
|
{
|
|
var cb = (CheckBox) sender;
|
|
IsTasksVisible = cb.IsChecked ?? false;
|
|
|
|
ReloadVM(true);
|
|
}
|
|
|
|
private void Scheduler_OnAppointmentDrag(object sender, AppointmentDragEventArgs e)
|
|
{
|
|
var editedAppointment = e.EditedAppointment;
|
|
|
|
var editedIsTask = editedAppointment.CF_IsTask();
|
|
var editedEnd = editedAppointment.End;
|
|
var editedDueDate = editedAppointment.CF_DueDate();
|
|
|
|
|
|
var sourceAppointment = e.SourceAppointment;
|
|
|
|
var sourceIsTask = sourceAppointment.CF_IsTask();
|
|
var sourceEnd = sourceAppointment.End;
|
|
|
|
if(editedIsTask)
|
|
{
|
|
editedAppointment.AllDay = true;
|
|
}
|
|
|
|
if(editedIsTask && sourceIsTask && !Equals(editedEnd, sourceEnd) && editedDueDate.HasValue)
|
|
{
|
|
editedDueDate = editedEnd.MergeDatesByDate(editedDueDate.Value).AddDays(-1);
|
|
|
|
editedAppointment.CF_DueDate(editedDueDate);
|
|
}
|
|
}
|
|
|
|
private static void WriteToDebug(string pText)
|
|
{
|
|
Debug.WriteLine($"-----------------------> {pText}");
|
|
}
|
|
|
|
private void LogStorage()
|
|
{
|
|
var storageAppointments = Scheduler.Storage.AppointmentStorage.Items.ToList();
|
|
|
|
var sb = new StringBuilder();
|
|
sb.Append("AppointmentStorage-Inhalt:\n");
|
|
|
|
foreach (var app in storageAppointments)
|
|
{
|
|
sb.Append($"{app.Subject} {app.Start:dd.MM.yyyy HH:mm}-{app.End:dd.MM.yyyy HH:mm}\n");
|
|
}
|
|
|
|
WriteToDebug(sb.ToString());
|
|
}
|
|
}
|
|
|
|
#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;
|
|
var customFieldStorage = (CustomFieldStorage) customFields[nameof(CustomFieldStorage)];
|
|
|
|
if(customFieldStorage != null && parameter != null && parameter.Equals("AlleRessourcen"))
|
|
{
|
|
return customFieldStorage.ResourceList;
|
|
}
|
|
|
|
return null;
|
|
}
|
|
|
|
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) { throw new NotImplementedException("#4534523454"); }
|
|
}
|
|
|
|
public class AppointmentToolTipConverter : IValueConverter
|
|
{
|
|
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
|
{
|
|
try
|
|
{
|
|
var customFields = (CustomFieldCollection) value;
|
|
var customFieldStorage = (CustomFieldStorage) customFields[nameof(CustomFieldStorage)];
|
|
|
|
var mitarbeiter = customFieldStorage.EmployeeList;
|
|
var ressourcen = customFieldStorage.ResourceList;
|
|
var klienten = customFieldStorage.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 customFieldStorage = (CustomFieldStorage) customViewInfo[nameof(CustomFieldStorage)];
|
|
|
|
var isTask = customFieldStorage.IsTask;
|
|
|
|
if (isTask)
|
|
{
|
|
farbe = Color.FromRgb(153, 59, 59);
|
|
}
|
|
|
|
var aptCustomers = customFieldStorage.CustomerList;
|
|
var aptResources = customFieldStorage.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;
|
|
|
|
if(customFields == null)
|
|
{
|
|
return new SolidColorBrush(Color.FromRgb(192, 255, 208));
|
|
}
|
|
|
|
var customFieldStorage = (CustomFieldStorage) customFields[nameof(CustomFieldStorage)];
|
|
|
|
|
|
var employeeList = customFieldStorage.EmployeeList;
|
|
var isTask = customFieldStorage.IsTask;
|
|
|
|
return employeeList.Any(e => e.Employee.EmployeeOid.Equals(MainSession.LoggedOnEmployee.EmployeeOid) && e.ParticipationAnswer == ParticipationAnswer.Vorbehalt) ?
|
|
new SolidColorBrush(Color.FromRgb(185, 39, 217)) :
|
|
isTask ? new SolidColorBrush(Color.FromRgb(153, 59, 59)) : 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(!(value is Employee2SchedulerAppointmentDC))
|
|
{
|
|
return null;
|
|
}
|
|
|
|
if (parameter != null && parameter.Equals("GibName"))
|
|
{
|
|
var v = (Employee2SchedulerAppointmentDC) value;
|
|
|
|
if(v != null)
|
|
{
|
|
return v.Employee.DetailDescription;
|
|
}
|
|
}
|
|
|
|
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(); }
|
|
}
|
|
#endregion
|
|
}
|