Completed
Last Updated: 06 May 2016 14:05 by ADMIN
ADMIN
Dess | Tech Support Engineer, Sr.
Created on: 18 Mar 2016 09:09
Category: Scheduler/Reminder
Type: Bug Report
0
FIX. RadScheduler - ArgumentException when using EnableExactTimeRendering
public Form1()
{
    InitializeComponent();
    DateTime d = DateTime.Now.Date; 
    radScheduler1.Appointments.Add(new Appointment(new DateTime(d.Year, d.Month, d.Day, 1, 30, 0), new DateTime(d.Year, d.Month, d.Day, 1, 30, 0), "Appointment_Free_0", "", ""));
    radScheduler1.Appointments.Add(new Appointment(new DateTime(d.Year, d.Month, d.Day, 8, 30, 0), new DateTime(d.Year, d.Month, d.Day, 9, 0, 0), "Appointment_Free_0", "", ""));
    radScheduler1.Appointments.Add(new Appointment(new DateTime(d.Year, d.Month, d.Day, 11, 00, 0), new DateTime(d.Year, d.Month, d.Day, 11, 30, 0), "Appointment_Free_0", "", ""));

    radScheduler1.Appointments.Add(new Appointment(new DateTime(d.Year, d.Month, d.Day, 11, 0, 0), new DateTime(d.Year, d.Month, d.Day, 11, 0, 0), "Appointment_Free_0", "", ""));
    radScheduler1.Appointments.Add(new Appointment(new DateTime(d.Year, d.Month, d.Day, 10, 30, 0), new DateTime(d.Year, d.Month, d.Day, 11, 0, 0), "Appointment_Free_0", "", ""));
    radScheduler1.Appointments.Add(new Appointment(new DateTime(d.Year, d.Month, d.Day, 11, 00, 0), new DateTime(d.Year, d.Month, d.Day, 11, 30, 0), "Appointment_Free_0", "", ""));
    radScheduler1.Appointments.Add(new Appointment(new DateTime(d.Year, d.Month, d.Day, 11, 30, 0), new DateTime(d.Year, d.Month, d.Day, 12, 0, 0), "Appointment_Free_0", "", ""));
    radScheduler1.Appointments.Add(new Appointment(new DateTime(d.Year, d.Month, d.Day, 14, 0, 0), new DateTime(d.Year, d.Month, d.Day, 14, 30, 0), "Appointment_Free_0", "", ""));
    radScheduler1.Appointments.Add(new Appointment(new DateTime(d.Year, d.Month, d.Day, 15, 00, 0), new DateTime(d.Year, d.Month, d.Day, 15, 30, 0), "Appointment_Free_0", "", ""));

    radScheduler1.Appointments.Add(new Appointment(new DateTime(d.Year, d.Month, d.Day, 17, 30, 0), new DateTime(d.Year, d.Month, d.Day, 17, 30, 0), "Appointment_Free_0", "", ""));

    radScheduler1.ActiveViewType = SchedulerViewType.Day;

    radScheduler1.EnableExactTimeRendering = true;
}


Workaround: use a custom DayViewAppointmentsTable

 this.radScheduler1.ElementProvider = new MyElementProvider(this.radScheduler1);

public class MyElementProvider : SchedulerElementProvider
{
    public MyElementProvider(RadScheduler scheduler) : base(scheduler)
    {
    }

    protected override T CreateElement<T>(SchedulerView view, object context)
    {
        if (typeof(T) == typeof(DayViewAppointmentsTable))
        {
            return new CustomDayViewAppointmentsTable(view.Scheduler, view, (DayViewAppointmentsArea)context)as T;
        }

        return base.CreateElement<T>(view, context);
    }
}

public class CustomDayViewAppointmentsTable : DayViewAppointmentsTable
{
    public CustomDayViewAppointmentsTable(RadScheduler scheduler, SchedulerView view, DayViewAppointmentsArea area) : base(scheduler, view, area)
    {
    }
    
    protected override IEnumerable<AppointmentElement> CreateAppointmentElements()
    {
        if (this.View != null)
        {
            IList<IEvent> appointmentsInView = new List<IEvent>(this.View.Appointments);
            List<AppointmentElement> elements = DivideAppointmentToElements(appointmentsInView);
            elements.Sort(0, elements.Count, new DateTimeComparer(this.Scheduler));

            foreach (AppointmentElement currentAppointment in elements)
            {
                currentAppointment.RelatedAppointments.Clear();
                currentAppointment.DesiredBounds = new RectangleF();
            }

            foreach (AppointmentElement appointment in elements)
            {
                List<AppointmentElement> intersectingAppointments = this.GetAllAppointmentsInDay(appointment.Start.Day, elements);
                intersectingAppointments.Remove(appointment);
                appointment.RelatedAppointments = intersectingAppointments;
            }

            return elements;
        }
        else
        {
            return new List<AppointmentElement>();
        }
    }

    private List<AppointmentElement> GetAllAppointmentsInDay(int day, List<AppointmentElement> elements)
    {
        List<AppointmentElement> result = new List<AppointmentElement>();
        foreach (AppointmentElement appointment in elements)
        {
            if (appointment.Start.Day == day)
            {
                result.Add(appointment);
            }
        }

        return result;
    }

    private List<AppointmentElement> DivideAppointmentToElements(IList<IEvent> appointmentsInView)
    {
        List<AppointmentElement> childAppointments = new List<AppointmentElement>();
        TimeSpan startTime = TimeSpan.FromMinutes(this.GetDayViewBase().RulerStartScale * 60 + this.GetDayViewBase().RulerStartScaleMinutes);
        TimeSpan endTime = TimeSpan.FromMinutes(this.GetDayViewBase().RulerEndScale * 60 + this.GetDayViewBase().RulerEndScaleMinutes);

        foreach (IEvent app in appointmentsInView)
        {
            SchedulerDayViewBase dayView = this.GetDayViewBase();
            bool allDay = (dayView != null) ? dayView.IsAllDayEvent(app) : false;

            DateTime appStart = this.View.DefaultTimeZone.OffsetTime(app.Start, this.Scheduler.SystemTimeZone);
            DateTime appEnd = this.View.DefaultTimeZone.OffsetTime(app.End, this.Scheduler.SystemTimeZone);

            if (!allDay)
            {
                // Handle > 1 day appointments
                if (appStart.Day != appEnd.Day && !(appEnd.Day - appStart.Day == 1 && appEnd.TimeOfDay == TimeSpan.Zero))
                {
                    AppointmentElement appointment1 = this.CreateAppointmentElement(this.Scheduler, this.View, app);
                    appointment1.Start = appStart;
                    appointment1.End = DateHelper.GetEndOfDay(appStart);

                    if (appointment1.Start.TimeOfDay >= endTime)
                    {
                        appointment1.Start = new DateTime(appStart.Year, appStart.Month, 
                            appStart.Day, 0, 0, 0).Add(endTime).AddMinutes(-(int)this.GetDayViewBase().RangeFactor);
                    }

                    AppointmentElement appointment2 = this.CreateAppointmentElement(this.Scheduler, this.View, app);
                    appointment2.Start = appEnd.Date;
                    appointment2.End = appEnd;

                    if (appointment1.Start >= this.View.StartDate)
                    {
                        childAppointments.Add(appointment1);
                    }

                    if (appointment2.Start >= this.View.StartDate)
                    {
                        childAppointments.Add(appointment2);
                    }
                }
                else
                {
                    AppointmentElement appointment1 = this.CreateAppointmentElement(this.Scheduler, this.View, app);
                    appointment1.Start = appStart;
                    appointment1.End = appEnd;

                    if (appointment1.Start.TimeOfDay < startTime)
                    {
                        appointment1.Start = new DateTime(appStart.Year, appStart.Month, appStart.Day, 0, 0, 0).Add(startTime);
                    }

                    if (appointment1.Start.TimeOfDay >= endTime)
                    {
                        appointment1.Start = new DateTime(appStart.Year, appStart.Month, appStart.Day, 0,
                            0, 0).Add(endTime).AddMinutes(-(int)this.GetDayViewBase().RangeFactor);
                    }

                    if (appointment1.End.TimeOfDay > endTime)
                    {
                        appointment1.End = new DateTime(appEnd.Year, appEnd.Month, appEnd.Day, 0, 0, 0).Add(endTime);
                    }

                    if (appointment1.End.TimeOfDay <= startTime)
                    {
                        appointment1.End = new DateTime(appEnd.Year, appEnd.Month, appEnd.Day, 0, 0,
                            0).Add(startTime).AddMinutes((int)this.GetDayViewBase().RangeFactor);
                    }

                    childAppointments.Add(appointment1);
                }
            }
            else if (!dayView.ShowAllDayArea)
            {
                DateTimeInterval viewInterval = new DateTimeInterval(this.View.StartDate, DateHelper.GetEndOfDay(this.View.EndDate));

                AppointmentElement appointment1 = this.CreateAppointmentElement(this.Scheduler, this.View, app);
                appointment1.Start = appStart;
                appointment1.End = DateHelper.GetEndOfDay(appStart);

                DateTimeInterval interval = new DateTimeInterval(appStart, appointment1.End);
                if (interval.IntersectsWith(viewInterval))
                {
                    if (appointment1.Start.TimeOfDay < startTime)
                    {
                        appointment1.Start = new DateTime(appStart.Year, appStart.Month, appStart.Day, 0, 0, 0).Add(startTime);
                    }

                    if (appointment1.Start.TimeOfDay >= endTime)
                    {
                        appointment1.Start = new DateTime(appStart.Year, appStart.Month, appStart.Day, 0, 0,
                            0).Add(endTime).AddMinutes(-(int)this.GetDayViewBase().RangeFactor);
                    }

                    if (appointment1.End.TimeOfDay > endTime)
                    {
                        appointment1.End = new DateTime(appEnd.Year, appEnd.Month, appEnd.Day, 0, 0, 0).Add(endTime);
                    }

                    if (appointment1.End.TimeOfDay <= startTime)
                    {
                        appointment1.End = new DateTime(appEnd.Year, appEnd.Month, appEnd.Day, 0, 0,
                            0).Add(startTime).AddMinutes((int)this.GetDayViewBase().RangeFactor);
                    }

                    childAppointments.Add(appointment1);
                }

                DateTime startDate = appStart.AddDays(1).Date;
                AppointmentElement appointment2 = null;

                while (startDate <= appEnd.Date.AddDays(-1))
                {
                    appointment2 = this.CreateAppointmentElement(this.Scheduler, this.View, app);
                    appointment2.Start = startDate;
                    appointment2.End = DateHelper.GetEndOfDay(startDate);
                    interval = new DateTimeInterval(appointment2.Start, appointment2.End);
                    if (interval.IntersectsWith(viewInterval))
                    {
                        childAppointments.Add(appointment2);
                    }
                    startDate = startDate.AddDays(1);
                }

                DateTime endDate = appEnd.Date;
                DateTime endAppointmentDate = appEnd;
                appointment2 = this.CreateAppointmentElement(this.Scheduler, this.View, app);
                appointment2.Start = endDate;
                appointment2.End = endAppointmentDate;

                interval = new DateTimeInterval(endDate, endAppointmentDate);
                if (interval.IntersectsWith(viewInterval) && interval.Start != appStart)
                {
                    childAppointments.Add(appointment2);
                }
            }
        }

        return childAppointments;
    }

    private AppointmentElement CreateAppointmentElement(RadScheduler scheduler, SchedulerView view, IEvent appointment)
    {
        AppointmentElement appointmentElement = null;
        if (scheduler.AppointmentElementFactory != null)
        {
            appointmentElement = scheduler.AppointmentElementFactory.CreateAppointmentElement(scheduler, view, appointment);
        }
        else
        {
            appointmentElement = scheduler.ElementProvider.GetElement<AppointmentElement>(view, appointment);
        }
        return appointmentElement;
    }
}
(Total attached files size should be smaller than 20mb. Allowed extensions: .zip, .rar, .jpg, .png, .gif)
0 comments