Skip to main content

SchedulerControl.QueryWorkTime Event

Occurs when the scheduler's view calculates the work time interval for the specific resource.

Namespace: DevExpress.Xpf.Scheduler

Assembly: DevExpress.Xpf.Scheduler.v14.2.dll

#Declaration

public event QueryWorkTimeEventHandler QueryWorkTime

#Event Data

The QueryWorkTime event's handler receives an argument of the QueryWorkTimeEventArgs type. The following properties provide information specific to this event:

Property Description
Interval Gets the time interval for which the working time is queried.
Resource Gets the resource for which the working time interval is queried.
WorkTime Gets or sets the working time interval.
WorkTimes Provides access to the collection of work times specified for a single day.

#Remarks

Handle the QueryWorkTime event to specify custom work time intervals. They can be set differently for distinct days and resources.

#Examples

This example demonstrates how to set a custom work time for each day and resource.

To do this, handle the SchedulerControl.QueryWorkTime event, check values of the QueryWorkTimeEventArgs.Interval and QueryWorkTimeEventArgs.Resource properties and set the QueryWorkTimeEventArgs.WorkTime property value, as required.

using DevExpress.XtraScheduler;
using DevExpress.Xpf.Scheduler;
//...

// Create a collection of different worktime intervals.
TimeOfDayInterval[] workTimes = new TimeOfDayInterval[] {
    new TimeOfDayInterval(TimeSpan.FromHours(0), TimeSpan.FromHours(16)),
    new TimeOfDayInterval(TimeSpan.FromHours(10), TimeSpan.FromHours(20)),
    null,
    new TimeOfDayInterval(TimeSpan.FromHours(7), TimeSpan.FromHours(15)),
    new TimeOfDayInterval(TimeSpan.FromHours(16), TimeSpan.FromHours(24)),
        };

private void schedulerControl1_QueryWorkTime(object sender, QueryWorkTimeEventArgs e) {

    if(schedulerControl1.Storage.ResourceStorage == null)
        return;

    int resourceIndex = schedulerControl1.Storage.ResourceStorage.Items.IndexOf(e.Resource);
    if(resourceIndex >= 0) {
        if(resourceIndex == 0) {
        // Specify alternate worktimes for odd and even days.
            if((e.Interval.Start.Day % 2) == 0)
                e.WorkTime = workTimes[resourceIndex % workTimes.Length];
            else
                e.WorkTime = TimeOfDayInterval.Empty;
        }
        else {
            // Specify worktime interval if the current date is treated as a working day.
            if (schedulerControl1.WorkDays.IsWorkDay(e.Interval.Start.Date))
                e.WorkTime = workTimes[resourceIndex % workTimes.Length];
        }
    }
}
See Also