SchedulerControl.QueryWorkTime Event

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

Namespace: DevExpress.XtraScheduler

Assembly: DevExpress.XtraScheduler.v20.2.dll

Declaration

public event QueryWorkTimeEventHandler QueryWorkTime
Public Event QueryWorkTime As QueryWorkTimeEventHandler

Event Data

The QueryWorkTime event's data class is QueryWorkTimeEventArgs. 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 this event to specify custom work time intervals. They can be set differently for distinct days and resources.

NOTE

When different work time intervals are specified in the SchedulerControl.QueryWorkTime event handler, the DayView.ShowWorkTimeOnly option has no effect.

Examples

The following code illustrates how to set a custom work time for each day and resource. Check the QueryWorkTimeEventArgs.Interval and QueryWorkTimeEventArgs.Resource values, and set the QueryWorkTimeEventArgs.WorkTime as required.

QueryWorkTime

private void SchedulerControl1_QueryWorkTime(object sender, QueryWorkTimeEventArgs e)
{
    if (e.Resource.Id.Equals(1))
    {
        if (e.Interval.Start.Day % 2 == 0)
        {
            List<TimeOfDayInterval> workTimes = new List<TimeOfDayInterval>();
            workTimes.Add(new TimeOfDayInterval(TimeSpan.FromHours(0), TimeSpan.FromHours(3)));
            workTimes.Add(new TimeOfDayInterval(TimeSpan.FromHours(5), TimeSpan.FromHours(8)));
            workTimes.Add(new TimeOfDayInterval(TimeSpan.FromHours(10), TimeSpan.FromHours(11)));
            e.WorkTimes.AddRange(workTimes);
        }
        else
            e.WorkTime = new TimeOfDayInterval(TimeSpan.FromHours(8), TimeSpan.FromHours(20));
    }
    if (e.Resource.Id.Equals(2))
    {
        if (e.Interval.Start.Day % 2 == 0)
            e.WorkTime = new TimeOfDayInterval(TimeSpan.FromHours(14), TimeSpan.FromHours(18));
        else
            e.WorkTime = new TimeOfDayInterval(TimeSpan.FromHours(8), TimeSpan.FromHours(12));
    }
    if (e.Resource.Id.Equals(3))
        e.WorkTime = new TimeOfDayInterval(TimeSpan.FromHours(14), TimeSpan.FromHours(21));
    if (e.Resource.Id.Equals(4))
    {
        List<TimeOfDayInterval> workTimes = new List<TimeOfDayInterval>();
        workTimes.Add(new TimeOfDayInterval(TimeSpan.FromHours(8), TimeSpan.FromHours(11)));
        workTimes.Add(new TimeOfDayInterval(TimeSpan.FromHours(13), TimeSpan.FromHours(17)));
        e.WorkTimes.AddRange(workTimes);
    }
}
See Also