2016-06-27 01:45:38 +02:00
using System ;
using System.Windows.Controls ;
using DevExpress.Xpf.Scheduler ;
using DevExpress.Xpf.Scheduler.Drawing ;
using DevExpress.XtraScheduler ;
using DevExpress.Xpf.Scheduler.UI ;
using SchedulerControl = DevExpress . Xpf . Scheduler . SchedulerControl ;
using System.Globalization ;
using System.Windows ;
using System.Windows.Media ;
namespace BeWo.Scheduler.View
{
public class AbstractAppointmentEditForm : UserControl
{
2019-07-01 15:11:19 +02:00
public AbstractAppointmentEditForm ( ) { }
2016-06-27 01:45:38 +02:00
public AbstractAppointmentEditForm ( SchedulerControl schedulerControl , Appointment appointment )
{
2017-09-28 14:00:40 +02:00
Control = schedulerControl ;
Appointment = appointment ;
2016-06-27 01:45:38 +02:00
2017-09-28 14:00:40 +02:00
Controller = CreateFormController ( Control , Appointment ) ;
RecurrenceVisualController = new RecurrenceVisualController ( Controller ) ;
2016-06-27 01:45:38 +02:00
}
public virtual AppointmentFormController CreateFormController ( SchedulerControl schedulerControl , Appointment appointment )
{
return new AppointmentFormController ( schedulerControl , appointment ) ;
}
2017-09-28 14:00:40 +02:00
public SchedulerControl Control { get ; }
public Appointment Appointment { get ; }
public AppointmentFormController Controller { get ; }
2017-09-27 11:06:48 +02:00
public string TimeEditMask = > CultureInfo . CurrentCulture . DateTimeFormat . LongTimePattern ;
2017-09-28 14:00:40 +02:00
public RecurrenceVisualController RecurrenceVisualController { get ; }
2016-06-27 01:45:38 +02:00
2023-01-18 13:43:11 +01:00
protected internal bool IsNewAppointment = > Controller is null | | Controller . IsNewAppointment ;
2016-06-27 01:45:38 +02:00
2017-09-28 14:00:40 +02:00
protected bool ShouldShowRecurrence = > ! Appointment . IsOccurrence & & Controller . ShouldShowRecurrenceButton ;
2016-06-27 01:45:38 +02:00
protected virtual bool ApplyChanges ( )
{
2017-09-28 14:00:40 +02:00
if ( ! Controller . IsConflictResolved ( ) )
2016-06-27 01:45:38 +02:00
{
return false ;
}
2021-06-23 13:44:13 +02:00
// TODO: Endzeit und Startzeit werden als Dauer auf das Start-Objekt addiert
2016-06-27 01:45:38 +02:00
if ( ShouldShowRecurrence )
{
2021-06-23 13:44:13 +02:00
var rvcStart = RecurrenceVisualController . Start ;
2017-09-28 14:00:40 +02:00
RecurrenceVisualController . ApplyRecurrence ( ) ;
2016-06-27 01:45:38 +02:00
}
try
{
2017-09-28 14:00:40 +02:00
Controller . ApplyChanges ( ) ;
2016-06-27 01:45:38 +02:00
}
catch ( Exception e )
{
2017-09-27 11:06:48 +02:00
MessageBox . Show ( $"Es ist leider ein Fehler aufgetreten. Die von Ihnen getätigten Änderungen am Termin konnten leider nicht übernommen werden.\n{e.Message}\n{e.StackTrace}" , "Fehler" , MessageBoxButton . OK , MessageBoxImage . Error ) ;
2016-06-27 01:45:38 +02:00
}
2017-09-28 14:00:40 +02:00
2016-06-27 01:45:38 +02:00
SchedulerFormBehavior . Close ( this , true ) ;
return true ;
}
protected virtual void Cancel ( )
{
SchedulerFormBehavior . Close ( this , false ) ;
}
protected virtual void DeleteAppointment ( )
{
if ( IsNewAppointment )
2017-09-28 14:00:40 +02:00
{
return ;
}
2016-06-27 01:45:38 +02:00
2017-09-28 14:00:40 +02:00
Controller . DeleteAppointment ( ) ;
2016-06-27 01:45:38 +02:00
SchedulerFormBehavior . Close ( this , false ) ;
}
protected static void LocalizeVisualChild ( DependencyObject obj )
{
2017-09-28 14:00:40 +02:00
for ( var i = 0 ; i < VisualTreeHelper . GetChildrenCount ( obj ) ; i + + )
2016-06-27 01:45:38 +02:00
{
2017-09-28 14:00:40 +02:00
var child = VisualTreeHelper . GetChild ( obj , i ) ;
2019-01-05 17:03:44 -04:00
if ( child is WeekOfMonthEdit edt1 )
2016-06-27 01:45:38 +02:00
{
2019-01-05 17:03:44 -04:00
edt1 . CustomDisplayText - = EditCustomDisplayText ;
edt1 . CustomDisplayText + = EditCustomDisplayText ;
2016-06-27 01:45:38 +02:00
2019-01-05 17:03:44 -04:00
foreach ( var womEditItem in edt1 . Items )
2016-06-27 01:45:38 +02:00
{
2019-01-05 17:03:44 -04:00
if ( womEditItem is NamedElement ne )
2017-09-28 14:00:40 +02:00
{
ne . Caption = Translate ( ne . Caption ) ;
}
2016-06-27 01:45:38 +02:00
}
}
2019-01-05 17:03:44 -04:00
if ( child is WeekDaysEdit edt )
2016-06-27 01:45:38 +02:00
{
2017-09-28 14:00:40 +02:00
edt . CustomDisplayText - = EditCustomDisplayText ;
edt . CustomDisplayText + = EditCustomDisplayText ;
2016-06-27 01:45:38 +02:00
foreach ( var womEditItem in edt . Items )
{
2019-01-05 17:03:44 -04:00
if ( womEditItem is NamedElement ne )
2017-09-28 14:00:40 +02:00
{
ne . Caption = Translate ( ne . Caption ) ;
}
2016-06-27 01:45:38 +02:00
}
}
LocalizeVisualChild ( child ) ;
}
}
2017-09-28 14:00:40 +02:00
private static void EditCustomDisplayText ( object sender , DevExpress . Xpf . Editors . CustomDisplayTextEventArgs e )
2016-06-27 01:45:38 +02:00
{
e . DisplayText = Translate ( e . DisplayText ) ;
e . Handled = true ;
}
2017-09-28 14:00:40 +02:00
private static string Translate ( string text )
2016-06-27 01:45:38 +02:00
{
switch ( text )
{
case "First" :
return "Ersten" ;
case "Second" :
return "Zweiten" ;
case "Third" :
return "Dritten" ;
case "Fourth" :
return "Vierten" ;
case "Last" :
return "Letzten" ;
case "Day" :
return "Tag" ;
case "Weekday" :
return "Arbeitstag" ;
case "Weekend day" :
return "Wochenendtag" ;
2017-09-28 14:00:40 +02:00
default :
return text ;
2016-06-27 01:45:38 +02:00
}
}
}
}