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 { public AbstractAppointmentEditForm() { } public AbstractAppointmentEditForm(SchedulerControl schedulerControl, Appointment appointment) { Control = schedulerControl; Appointment = appointment; Controller = CreateFormController(Control, Appointment); RecurrenceVisualController = new RecurrenceVisualController(Controller); } public virtual AppointmentFormController CreateFormController(SchedulerControl schedulerControl, Appointment appointment) { return new AppointmentFormController(schedulerControl, appointment); } public SchedulerControl Control { get; } public Appointment Appointment { get; } public AppointmentFormController Controller { get; } public string TimeEditMask => CultureInfo.CurrentCulture.DateTimeFormat.LongTimePattern; public RecurrenceVisualController RecurrenceVisualController { get; } protected internal bool IsNewAppointment => Controller is null || Controller.IsNewAppointment; protected bool ShouldShowRecurrence => !Appointment.IsOccurrence && Controller.ShouldShowRecurrenceButton; protected virtual bool ApplyChanges() { if (!Controller.IsConflictResolved()) { return false; } // TODO: Endzeit und Startzeit werden als Dauer auf das Start-Objekt addiert if (ShouldShowRecurrence) { var rvcStart = RecurrenceVisualController.Start; RecurrenceVisualController.ApplyRecurrence(); } try { Controller.ApplyChanges(); } catch (Exception e) { 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); } SchedulerFormBehavior.Close(this, true); return true; } protected virtual void Cancel() { SchedulerFormBehavior.Close(this, false); } protected virtual void DeleteAppointment() { if (IsNewAppointment) { return; } Controller.DeleteAppointment(); SchedulerFormBehavior.Close(this, false); } protected static void LocalizeVisualChild(DependencyObject obj) { for (var i = 0; i < VisualTreeHelper.GetChildrenCount(obj); i++) { var child = VisualTreeHelper.GetChild(obj, i); if (child is WeekOfMonthEdit edt1) { edt1.CustomDisplayText -= EditCustomDisplayText; edt1.CustomDisplayText += EditCustomDisplayText; foreach (var womEditItem in edt1.Items) { if (womEditItem is NamedElement ne) { ne.Caption = Translate(ne.Caption); } } } if (child is WeekDaysEdit edt) { edt.CustomDisplayText -= EditCustomDisplayText; edt.CustomDisplayText += EditCustomDisplayText; foreach (var womEditItem in edt.Items) { if (womEditItem is NamedElement ne) { ne.Caption = Translate(ne.Caption); } } } LocalizeVisualChild(child); } } private static void EditCustomDisplayText(object sender, DevExpress.Xpf.Editors.CustomDisplayTextEventArgs e) { e.DisplayText = Translate(e.DisplayText); e.Handled = true; } private static string Translate(string text) { 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"; default: return text; } } } }