Completed
Last Updated: 31 Jul 2018 11:05 by Dimitar
ADMIN
Hristo
Created on: 18 Jul 2018 10:33
Category: Scheduler/Reminder
Type: Bug Report
0
FIX. RadScheduler - the month view element is incorrectly scrolled to DateTime.Now if there is an AccessibleInterval set to the control
How to rerproduce:
this.radScheduler1.AccessibleInterval.Start = new DateTime(2018, 7, 18, 00, 00, 00).AddMonths(-2);
            this.radScheduler1.AccessibleInterval.End = new DateTime(2018, 7, 18, 00, 00, 00).AddMonths(2);
            this.radScheduler1.ActiveViewType = Telerik.WinControls.UI.SchedulerViewType.Month;

Workaround:
public class CustomRadScheduler : RadScheduler
{
    private FieldInfo schedulerFi;
    private FieldInfo activeViewsFi;
    private MethodInfo onPropertyChangedMi;
    private MethodInfo setActiveViewMi;

    protected override void CreateChildItems(RadElement parent)
    {
        base.CreateChildItems(parent);

        this.activeViewsFi = typeof(RadScheduler).GetField("activeViews", BindingFlags.Instance | BindingFlags.NonPublic);
        this.schedulerFi = typeof(SchedulerView).GetField("scheduler", BindingFlags.Instance | BindingFlags.NonPublic);
        this.onPropertyChangedMi = typeof(SchedulerView).GetMethod("OnPropertyChanged", BindingFlags.Instance | BindingFlags.NonPublic);
        this.setActiveViewMi = typeof(RadScheduler).GetMethod("SetActiveView", BindingFlags.Instance | BindingFlags.NonPublic);
    }

    public override string ThemeClassName
    {
        get
        {
            return typeof(RadScheduler).FullName;
        }
    }

    /// <summary>
    /// Gets or sets the type of the active view.
    /// </summary>
    /// <value>The type of the active view.</value>
    [DefaultValue(SchedulerViewType.Day)]
    [NotifyParentProperty(true)]
    public override SchedulerViewType ActiveViewType
    {
        get
        {
            return base.ActiveViewType;
        }
        set
        {
            if (this.ActiveViewType != value && value == SchedulerViewType.Month)
            {
                SchedulerView newView;
                Dictionary<SchedulerViewType, SchedulerView> activeViews = this.activeViewsFi.GetValue(this) as Dictionary<SchedulerViewType, SchedulerView>;
                if (activeViews.ContainsKey(value))
                {
                    newView = activeViews[value];
                }
                else
                {
                    SchedulerView view = new CustomSchedulerMonthView();
                    this.schedulerFi.SetValue(view, this);
                    this.onPropertyChangedMi.Invoke(view, new object[] { new string[] { "Scheduler" } });
                    newView = view;
                }

                if (this.ActiveView != newView && newView != null)
                {
                    this.setActiveViewMi.Invoke(this, new object[] { newView, true });
                }
            }
            else
            {
                base.ActiveViewType = value;
            }
        }
    }
}

public class CustomSchedulerMonthView : SchedulerMonthView
{
    public override SchedulerView OffsetView(int offset)
    {
        if (this.ShowFullMonth)
        {
            DateTime dtStart = DateHelper.GetStartOfMonth(this.StartDate);
            if (this.StartDate.Day > 1)
            {
                dtStart = dtStart.AddMonths(1);
            }

            dtStart = dtStart.AddMonths(offset);
            return this.CreateViewWithStartDate(dtStart);
        }
        else
        {
            DateTime startDate = this.StartDate.Add(new TimeSpan(offset * this.OffsetTimeSpan.Ticks));
            DateTimeInterval interval = new DateTimeInterval(startDate, this.GetEndDate(startDate));

            if (this.Scheduler.AccessibleInterval.Contains(interval))
            {
                return this.CreateViewWithStartDate(startDate);
            }

            if (true)
            {

            }

            return this.CreateViewWithStartDate(startDate);
        }
    }

    protected override SchedulerView CreateViewWithStartDate(DateTime startDate)
    {
        SchedulerMonthView monthView = new SchedulerMonthView();
        this.CopyPropertiesToView(monthView);
        DateTimeInterval interval = new DateTimeInterval(startDate, this.GetEndDate(startDate));
        if (interval.End > this.Scheduler.AccessibleInterval.End)
        {
            startDate = startDate.Add(new TimeSpan(-1 * this.OffsetTimeSpan.Ticks));
        }

        if (interval.Start < this.Scheduler.AccessibleInterval.Start)
        {
            startDate = startDate.Add(new TimeSpan(1 * this.OffsetTimeSpan.Ticks));
        }


        monthView.StartDate = startDate;

        if (this.ShowFullMonth)
        {
            monthView.WeekCount = DateHelper.GetMonthDisplayWeeks(startDate, this.CurrentCulture.DateTimeFormat);
        }

        return monthView;
    }
}
(Total attached files size should be smaller than 20mb. Allowed extensions: .zip, .rar, .jpg, .png, .gif)
0 comments