Skip to main content

OccurrenceCalculator.CreateInstance(RecurrenceInfo) Method

Creates an instance of the OccurrenceCalculator inheritor according to the specified recurrence type.

Namespace: DevExpress.XtraScheduler

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

#Declaration

public static OccurrenceCalculator CreateInstance(
    RecurrenceInfo info
)

#Parameters

Name Type Description
info RecurrenceInfo

A RecurrenceInfo class instance specifying the type of calculator being created.

#Returns

Type Description
OccurrenceCalculator

An OccurrenceCalculator inheritor instance.

#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