using System; using System.Web.Mvc; using System.Web.UI.WebControls; using DevExpress.Web.Mvc; using DevExpress.XtraScheduler; using DayView = DevExpress.Web.ASPxScheduler.DayView; // TODO: Ist veraltet! namespace BeWoPlanerMobil.Views.DevExpressScheduler { public static class SchedulerHelper { private static MVCxAppointmentStorage _DefaultAppointmentStorage; public static MVCxAppointmentStorage DefaultAppointmentStorage => _DefaultAppointmentStorage ?? (_DefaultAppointmentStorage = CreateDefaultAppointmentStorage()); private static MVCxAppointmentStorage CreateDefaultAppointmentStorage() { var appointmentStorage = new MVCxAppointmentStorage(); SetupMappings(appointmentStorage); appointmentStorage.CustomFieldMappings.Add("CustomFieldStorage", "CustomFieldStorage"); return appointmentStorage; } public static void SetupMappings(MVCxAppointmentStorage storage) { storage.Mappings.AppointmentId = "Oid"; storage.Mappings.Start = "StartDate"; storage.Mappings.End = "EndDate"; storage.Mappings.Subject = "Subject"; storage.Mappings.Description = "Description"; storage.Mappings.Label = "LabelId"; storage.Mappings.AllDay = "AllDay"; storage.Mappings.ResourceId = "ResourceId"; storage.Mappings.RecurrenceInfo = "RecurrenceInfo"; storage.Mappings.ReminderInfo = "ReminderInfo"; storage.Mappings.Location = "Location"; storage.Mappings.Type = "EventType"; storage.Mappings.Status = "Status"; } public static void ApplyCommonViewSettings(DayView view) { view.ResourcesPerPage = 1; ApplyWorkTime(view); } private static void ApplyWorkTime(DayView view) { view.WorkTime.Start = TimeSpan.FromHours(7); view.WorkTime.End = TimeSpan.FromHours(20); view.ShowWorkTimeOnly = true; } private static MVCxResourceStorage _DefaultResourceStorage; public static MVCxResourceStorage DefaultResourceStorage => _DefaultResourceStorage ?? (_DefaultResourceStorage = CreateDefaultResourceStorage()); private static MVCxResourceStorage CreateDefaultResourceStorage() { var resourceStorage = new MVCxResourceStorage(); resourceStorage.Mappings.ResourceId = "Id"; resourceStorage.Mappings.Caption = "Caption"; return resourceStorage; } public static SchedulerSettings GetSchedulerSettings() { return GetSchedulerSettings(null); } public static SchedulerSettings GetSchedulerSettings(this HtmlHelper customHtml) { var settings = new SchedulerSettings { Name = "scheduler", CallbackRouteValues = new { Controller = "DevExpressScheduler", Action = "SchedulerPagePartial" }, EditAppointmentRouteValues = new { Controller = "DevExpressScheduler", Action = "EditAppointment" }, }; ApplyCommonViewSettings(settings.Views.DayView); ApplyCommonViewSettings(settings.Views.WorkWeekView); ApplyCommonViewSettings(settings.Views.FullWeekView); settings.Views.FullWeekView.Enabled = true; settings.Views.WeekView.Enabled = false; settings.Views.MonthView.ResourcesPerPage = 1; settings.Views.MonthView.AppointmentDisplayOptions.StartTimeVisibility = AppointmentTimeVisibility.Never; settings.Views.MonthView.AppointmentDisplayOptions.EndTimeVisibility = AppointmentTimeVisibility.Never; settings.Views.MonthView.AppointmentDisplayOptions.StatusDisplayType = AppointmentStatusDisplayType.Bounds; settings.Views.MonthView.AppointmentDisplayOptions.ShowRecurrence = true; settings.Views.MonthView.MonthViewStyles.DateCellBody.Height = Unit.Pixel(170); settings.Views.FullWeekView.Enabled = true; settings.Views.WeekView.Enabled = false; settings.Views.MonthView.ResourcesPerPage = 1; settings.Views.MonthView.AppointmentDisplayOptions.StartTimeVisibility = AppointmentTimeVisibility.Never; settings.Views.MonthView.AppointmentDisplayOptions.EndTimeVisibility = AppointmentTimeVisibility.Never; settings.Views.MonthView.AppointmentDisplayOptions.StatusDisplayType = AppointmentStatusDisplayType.Bounds; settings.Views.MonthView.AppointmentDisplayOptions.ShowRecurrence = true; settings.Views.MonthView.MonthViewStyles.DateCellBody.Height = Unit.Pixel(170); TimeScale[] timeScales = { new TimeScaleYear { Enabled = false }, new TimeScaleQuarter { Enabled = false }, new TimeScaleMonth(), new TimeScaleFixedInterval { Enabled = false }, new TimeScaleDay(), new TimeScaleHour { Enabled = false } }; settings.Views.TimelineView.Scales.AddRange(timeScales); settings.Views.TimelineView.ResourcesPerPage = 2; settings.Storage.EnableReminders = false; settings.Storage.Resources.Assign(DefaultResourceStorage); settings.Storage.Appointments.Assign(DefaultAppointmentStorage); settings.Storage.Appointments.Assign(DefaultAppointmentStorage); settings.Storage.Resources.Assign(DefaultResourceStorage); settings.Views.DayView.Styles.ScrollAreaHeight = new Unit(500); return settings; } } }