Skip to main content

OccurrenceCalculator Class

Enables you to calculate the occurrences for a given recurrent appointment.

Namespace: DevExpress.XtraScheduler

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

#Declaration

public abstract class OccurrenceCalculator

#Returned By

The OccurrenceCalculator.CreateInstance(RecurrenceInfo) method returns an instance of OccurrenceCalculator.

#Remarks

Use the OccurrenceCalculator object to calculate occurrences for a predefined time interval, as illustrated in the code sample below.

#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);
}

#Inheritance

Object
OccurrenceCalculator
See Also