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.2.Core.dll
NuGet Package: DevExpress.Scheduler.Core
#Declaration
public static AppointmentBaseCollection GetAppointmentsFromSortedCollection(
AppointmentBaseCollection coll,
TimeInterval interval
)
#Parameters
Name | Type | Description |
---|---|---|
coll | Appointment |
An Appointment |
interval | Time |
A Time |
#Returns
Type | Description |
---|---|
Appointment |
An Appointment |
#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);
}