Working with Recurring Appointments
RadScheduler includes support for recurring events on minutely, hourly, weekly, daily, monthly and yearly basis. Exceptions to the recurrence rules are also permitted. To support this recurrence behavior, the IEvent interface (which the Appointment class implements) includes the RecurrenceRule, MasterEvent, Occurrences and Exceptions properties. When an appointment is assigned a recurrence rule it becomes a recurring appointment.
If the user modifies an individual appointment occurrence, this creates an exception, sets its MasterEvent property to the original recurring appointment and puts it in its Exceptions collection so that no occurrence is generated for the exception occurrence. This way the exception is still linked to the original recurrence series.
The RecurrenceRule class is the engine for creating and evaluating recurrence rules. It serves as a base class to several specialized classes and cannot be instantiated directly. The specialized classes are:
MinutelyRecurrenceRule
HourlyRecurrenceRule
DailyRecurrenceRule
WeeklyRecurrenceRule
MonthlyRecurrenceRule
YearlyRecurrenceRule
Using the specialized classes makes it easier to define recurrence rules because only relevant parameters are specified in their constructors.
Recurring Appointments
One of several constructor overloads lets you set the start time, duration and number of occurences. Then the rule can be assigned to the appointments RecurrenceRule property. The snippet below defines a rule that starts "now" and recurs every two hours and stops after the tenth occurence.
RecurrenceRule Property
The Appointment Occurrences property lets you iterate a list of IEvent instances. To get only some occurrences between specific starting and stopping times, use the Appointment GetOccurrences() method.
Retrieving Occurrences
When the user changes a specific occurrence and not the entire series, an "Exception" is created. "Exceptions" in this context refer to "Exceptions to a rule", not the .NET Exception class related to error handling. You can create exceptions programmatically by adding to the IEvent MasterEvent.Exceptions collection. The snippet below changes the background and status of an IEvent instance and adds the IEvent to its own MasterEvent Exceptions collection.
Recurrence Rule Exception
Examples
Here is an example using the HourlyRecurrenceRule class:
Setting HourlyReccurrenceRule
The Occurrences property of the Appointment class returns an enumerator that can be used to retrieve all the occurrences defined by the rule. Similarly the GetOccurrences method of the Appointment class can be used to retrieve all occurrences in a given interval. The example above produces the following output:
Figure 1: Appointment Occurrences