Skip to main content

OccurrenceCalculator.CalcOccurrences(TimeInterval, Appointment) Method

Creates a sequence of appointments for the specified pattern within the specified time interval.

Namespace: DevExpress.XtraScheduler

Assembly: DevExpress.XtraScheduler.v14.2.Core.dll

#Declaration

public AppointmentBaseCollection CalcOccurrences(
    TimeInterval interval,
    Appointment pattern
)

#Parameters

Name Type Description
interval TimeInterval

A DevExpress.XtraScheduler.TimeInterval object which specifies the interval in which the occurrences are created.

pattern Appointment

An Appointment object which specifies the pattern for occurrences.

#Returns

Type Description
AppointmentBaseCollection

A DevExpress.XtraScheduler.AppointmentBaseCollection object which specifies a collection of occurrences.

#Remarks

Use the CalcOccurrences method to generate a sequence of appointments of the AppointmentType.Occurrence type for further investigation or comparison.

NOTE

The OccurrenceCalculator creates a collection of occurrences based on the recurrence pattern only. It is not aware of any exceptions (deleted and changed occurrences). When appointment pattern evolves in the scheduler, the recurrence chain created by the OccurrenceCalculator is merged with data on deleted and changed occurrences.

#Examples

The following code sample adds the pattern for recurring appointments to the scheduler's storage and replaces all occurrences with appointments of the AppointmentType.Normal type. It uses the OccurrenceCalculator.CalcOccurrences method to calculate the recurrent series.

using DevExpress.XtraScheduler;
// ...

private void Button_Click(object sender, RoutedEventArgs e) {

    // Add new appointment pattern
    Appointment apt = schedulerControl1.Storage.CreateAppointment(AppointmentType.Pattern);
    apt.Subject = "MyTestAppointment";
    apt.RecurrenceInfo.Type = RecurrenceType.Daily;
    apt.RecurrenceInfo.Start = DateTime.Now;
    apt.RecurrenceInfo.End = apt.RecurrenceInfo.Start.AddDays(15);
    apt.RecurrenceInfo.Range = RecurrenceRange.EndByDate;
    schedulerControl1.Storage.AppointmentStorage.Add(apt);

    // Calculate occurrences
    Appointment pattern = schedulerControl1.Storage.AppointmentStorage.Items.Find(
        delegate(Appointment item) { return item.Subject == "MyTestAppointment"; });
    OccurrenceCalculator calc =
        OccurrenceCalculator.CreateInstance(pattern.RecurrenceInfo);
    TimeInterval ttc = new TimeInterval(pattern.RecurrenceInfo.Start,
        pattern.RecurrenceInfo.End + new TimeSpan(1, 0, 0));
    AppointmentBaseCollection apts = calc.CalcOccurrences(ttc, pattern);
    Appointment occurrence = null;

    // Create normal appointments
    schedulerControl1.Storage.BeginUpdate();
    for (int i = 0; i < apts.Count; i++) {
        occurrence = schedulerControl1.Storage.CreateAppointment(AppointmentType.Normal);
        occurrence.Subject = apts[i].Subject;
        occurrence.Description = apts[i].Description;
        occurrence.Start = apts[i].Start;
        occurrence.End = apts[i].End;
        schedulerControl1.Storage.AppointmentStorage.Add(occurrence);
    }
    schedulerControl1.Storage.EndUpdate();

    // Remove the pattern and occurrences
    schedulerControl1.Storage.AppointmentStorage.Remove(pattern);
}
See Also