Skip to main content

FreeTimeCalculator.IntervalFound Event

This event is raised for each interval before it is added to the collection. It enables you to change a free interval after it is found.

Namespace: DevExpress.XtraScheduler.Tools

Assembly: DevExpress.XtraScheduler.v24.1.Core.Desktop.dll

NuGet Package: DevExpress.Scheduler.CoreDesktop

Declaration

public event IntervalFoundEventHandler IntervalFound

Event Data

The IntervalFound event's data class is IntervalFoundEventArgs. The following properties provide information specific to this event:

Property Description
FreeIntervals Gets or sets a collection, containing the discovered free interval.
Resource Gets or sets a resource for appointments which are taken into account when a search for a free time is performed.

Remarks

This event gives you the flexibility to decide whether a particular free time slot satisfies your requirements.

The FreeIntervals property of IntervalFoundEventArgs object provides access to a TimeIntervalCollectionEx collection, which contains a single element - the located time interval. You can edit this interval by modifying its start, end and duration.

Example

The following example illustrates how the FreeTimeCalculator.IntervalFound event can be used to find the spare time periods in work time only within the work week.

To accomplish this, subscribe to the event and then call the FreeTimeCalculator.FindFreeTimeInterval method.

using DevExpress.XtraScheduler;
using DevExpress.XtraScheduler.Tools;
// ...
private TimeInterval FindInterval(TimeInterval interval, TimeSpan duration) {            
    FreeTimeCalculator calculator = 
        new FreeTimeCalculator(schedulerControl1.Storage);
    // Set a handler for the IntervalFound event.
    calculator.IntervalFound += new IntervalFoundEventHandler(OnIntervalFound);            
    // Call the method which raises the event.
    TimeInterval freeInterval = calculator.FindFreeTimeInterval(interval, 
        duration, true);
    return freeInterval;
}
private void OnIntervalFound(object sender, IntervalFoundEventArgs args)
{   TimeIntervalCollectionEx freeIntervals = args.FreeIntervals;
    DateTime start = freeIntervals.Start.Date.AddDays(-1);
    DateTime end = freeIntervals.End;
    while (start < end) {
        RemoveSpareTime(freeIntervals, start);
        RemoveNonworkingDays(freeIntervals, start);
        start += TimeSpan.FromDays(1);
    }
}        
private void RemoveSpareTime(TimeIntervalCollectionEx freeIntervals, DateTime date) {
    TimeInterval spareTime = new TimeInterval(date.AddHours(18), 
        TimeSpan.FromHours(15));            
    freeIntervals.Remove(spareTime);
}
private void RemoveNonworkingDays(TimeIntervalCollectionEx freeIntervals, 
DateTime date) {
    bool isWorkDay = schedulerControl1.WorkDays.IsWorkDay(date);
    if (!isWorkDay)
        freeIntervals.Remove(new TimeInterval(date, TimeSpan.FromDays(1)));            
}

The following code snippet (auto-collected from DevExpress Examples) contains a reference to the IntervalFound event.

Note

The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

See Also