AppointmentBaseCollection.GetAppointmentsFromSortedCollection(AppointmentBaseCollection, TimeInterval) Method
Retrieves the collection of appointments that are in the specified time interval from the specified collection of appointments sorted by start dates.
Namespace: DevExpress.XtraScheduler
Assembly: DevExpress.XtraScheduler.v24.1.Core.dll
NuGet Package: DevExpress.Scheduler.Core
Declaration
public static AppointmentBaseCollection GetAppointmentsFromSortedCollection(
AppointmentBaseCollection coll,
TimeInterval interval
)
Parameters
Name | Type | Description |
---|---|---|
coll | AppointmentBaseCollection | An AppointmentBaseCollection object specifying the collection of appointments sorted by their Appointment.Start dates. |
interval | TimeInterval | A TimeInterval object specifying the required time interval. |
Returns
Type | Description |
---|---|
AppointmentBaseCollection | An AppointmentBaseCollection object representing the collection of appointments which belong to the specified time interval. Note, that time intervals bounds are excluded in this case. |
Remarks
The GetAppointmentsFromSortedCollection method can only be used when the AppointmentBaseCollection is sorted by the Start dates of the appointments; otherwise, the result returned by this method will be incorrect. Use this method to improve the performance for sorted AppointmentBaseCollection objects instead of the AppointmentBaseCollection.GetAppointments method.
If an appointment’s time interval partially overlaps the specified interval, this appointment is also included in the collection returned.
Example
This example demonstrates how to use the AppointmentBaseCollection.GetAppointmentsFromSortedCollection
method. This method will give a significant performance benefit when retrieving multiple appointments from the same collection. As retrieving all the appointments in a year using the SchedulerStorageBase.GetAppointments method for each day in the year to get the appointments is extremely time consuming. So as demonstrated in this example it is much quicker to get an appointment collection for the entire year, then sort it by start date, and then use the GetAppointmentsFromSortedCollection method.
using DevExpress.XtraScheduler;
// ...
// Start date.
DateTime curDate = new DateTime(2010, 1, 1);
// Get all appointments for this year.
AppointmentBaseCollection apts = schedulerStorage1.GetAppointments(curDate, curDate.AddYears(1));
// Sort them by their Start dates.
apts.Sort(new AppointmentStartDateComparer());
// Count number of days for this year.
int count = DateTime.IsLeapYear(curDate.Year) ? 366 : 365;
// Time interval for one day.
TimeInterval interval = new TimeInterval(new DateTime(curDate.Year, 1, 1), TimeSpan.FromDays(1));
// Iterate through all the days in the year.
for (int i = 0; i < count; i++) {
AppointmentBaseCollection dayApts =
AppointmentBaseCollection.GetAppointmentsFromSortedCollection(apts, interval);
// My custom action with dayApts.
// ...
interval.Start = interval.Start.AddDays(1);
}