This is a migrated thread and some comments may be shown as answers.

[Solved] how to avoid a recurrence rule for a particular date

1 Answer 131 Views
Scheduler
This is a migrated thread and some comments may be shown as answers.
Nagesh Mynedi
Top achievements
Rank 1
Nagesh Mynedi asked on 11 Jan 2010, 12:48 PM
how to avoid a recurrence rule for a particular date for example the recurrence rule is from Jan 1st to Jan 30 but i don't want the recurrence to be visible on some days like 15th Jan and 20 Jan

1 Answer, 1 is accepted

Sort by
0
Peter
Telerik team
answered on 12 Jan 2010, 02:27 PM
Hi Nagesh,

You can store the exception dates in a custom attribute. Then you can handle AppointmentInsert to parst the custom attribute value and to overwrite the recurrence rule:

<telerik:RadScheduler ID="RadScheduler1" CustomAttributeNames="ExceptionDates(yyyy/MM/dd)" 
       EnableCustomAttributeEditing="true" runat="server" 
       onappointmentdatabound="RadScheduler1_AppointmentDataBound" 
       onappointmentinsert="RadScheduler1_AppointmentInsert" >
      </telerik:RadScheduler>

protected void RadScheduler1_AppointmentInsert(object sender, SchedulerCancelEventArgs e)
    {
        if (e.Appointment.RecurrenceRule != String.Empty)
        {
            RecurrenceRule parsedRule;
            RecurrenceRule.TryParse(e.Appointment.RecurrenceRule.ToString(), out parsedRule);
            List<DateTime> ExceptionsList = new List<DateTime>();
            if (e.Appointment.Attributes["ExceptionDates(yyyy/MM/dd)"] != null)
            {
                foreach (string exceptionDateString in e.Appointment.Attributes["ExceptionDates(yyyy/MM/dd)"].Split(';'))
                {
                    DateTime exceptionTime = DateTime.Parse(exceptionDateString);
                    exceptionTime = exceptionTime.ToLocalTime();
                    exceptionTime = exceptionTime.AddHours(e.Appointment.Start.Hour);
                    exceptionTime = exceptionTime.AddMinutes(e.Appointment.Start.Minute);
                    ExceptionsList.Add(exceptionTime);
                }
            }          
            parsedRule.Exceptions = ExceptionsList;
            e.Appointment.RecurrenceRule = parsedRule.ToString();
        }
    }

For example, for dates 15th Jan and 20 Jan, you should type in the ExceptionDates textbox the following:

"2010/01/15;2010/01/20"

If you need to create exception dates for already existing recurring appointments, simply move the above logic from AppointmentInsert to AppointmentDataBound.




All the best,
Peter
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Tags
Scheduler
Asked by
Nagesh Mynedi
Top achievements
Rank 1
Answers by
Peter
Telerik team
Share this question
or