OccurrenceCalculator Class
Enables you to calculate the occurrences for a given recurrent appointment.
Namespace: DevExpress.XtraScheduler
Assembly: DevExpress.XtraScheduler.v24.2.Core.dll
NuGet Package: DevExpress.Scheduler.Core
#Declaration
#Related API Members
The following members return OccurrenceCalculator objects:
#Remarks
Use the OccurrenceCalculator
object to calculate occurrences for a predefined time interval, as illustrated in the code sample below.
Note
The calculated appointments do not contain custom fields. This behavior is by design; it increases performance.
If you need to construct the actual recurrence appointment series with both standard and custom appointment fields, then you have to use the Appointment
#Example
The following code sample retrieves the recurrence pattern of the first appointment in the scheduler’s collection and replaces all occurrences with appointments of AppointmentType.Normal type. It utilizes the OccurrenceCalculator.CalcOccurrences method to calculate items in the recurrent series.
Note
A complete sample project is available at https://github.
// Calculate occurrences for the first recurrent series.
Appointment pattern = schedulerStorage1.Appointments.Items.FirstOrDefault(item => item.Type == AppointmentType.Pattern);
if (pattern == null) return;
OccurrenceCalculator calc = OccurrenceCalculator.CreateInstance(pattern.RecurrenceInfo);
TimeInterval processedInterval = new TimeInterval(DateTime.Today, DateTime.Today.AddDays(7));
AppointmentBaseCollection calculatedOccurrences = calc.CalcOccurrences(processedInterval, pattern);
// Create normal appointments in place of occurrences.
schedulerStorage1.BeginUpdate();
for (int i = 0; i < calculatedOccurrences.Count; i++) {
Appointment resultAppointment = schedulerStorage1.CreateAppointment(AppointmentType.Normal);
resultAppointment.Subject = String.Format("Occurrence {0} - {1}", calculatedOccurrences[i].Subject, i);
resultAppointment.Description = calculatedOccurrences[i].Description;
resultAppointment.Start = calculatedOccurrences[i].Start;
resultAppointment.End = calculatedOccurrences[i].End;
schedulerStorage1.Appointments.Add(resultAppointment);
}
schedulerStorage1.EndUpdate();
// Remove the pattern and occurrences.
schedulerStorage1.Appointments.Remove(pattern);