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 | Time |
A DevExpress. |
pattern | Appointment | An Appointment object which specifies the pattern for occurrences. |
#Returns
Type | Description |
---|---|
Appointment |
A DevExpress. |
#Remarks
Use the CalcOccurrences method to generate a sequence of appointments of the AppointmentType.Occurrence type for further investigation or comparison.
NOTE
The Occurrence
#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);
}