Skip to main content

QueryWorkTimeEventArgs.Resource Property

Gets the resource for which the working time interval is queried.

Namespace: DevExpress.XtraScheduler

Assembly: DevExpress.XtraScheduler.v14.2.Core.dll

#Declaration

public Resource Resource { get; }

#Property Value

Type Description
Resource

A Resource object instance.

#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