Back to Devexpress

How to: Add Shifted Holidays to the Scheduler

aspnet-3814-components-scheduler-examples-miscellaneous-how-to-add-shifted-holidays-to-the-scheduler.md

latest3.7 KB
Original Source

How to: Add Shifted Holidays to the Scheduler

  • Dec 17, 2020
  • 2 minutes to read

This example demonstrates how easily holidays can be added to the Scheduler and then exchanged with working. So, the phenomenon of shifted holidays occurs.

Suppose you are approaching the Independence Day of Brazil (Dia da Independencia), September 7, which in year 2008 falls on Sunday. An urgent need requires that one shift of your employees work on that day. But, you have to provide them with two days off in the middle of the week, instead of the national holiday and a weekend. The ASPxScheduler can handle this scenario with relative ease.

To create a custom schedule, perform the following steps:

Step 1. Add a holiday

csharp
private void AddNationalHolidays() {
    WorkDaysCollection workDays = ASPxScheduler1.WorkDays;
    workDays.BeginUpdate();
    try {
        workDays.AddHoliday(new DateTime(2008, 9, 7), "Independence Day of Brazil");
    }
    finally {
        workDays.EndUpdate();
    }
}
vb
Private Sub AddNationalHolidays()
    Dim workDays As WorkDaysCollection = ASPxScheduler1.WorkDays
    workDays.BeginUpdate()
    Try
        workDays.AddHoliday(New DateTime(2008, 9, 7), "Independence Day of Brazil")
    Finally
        workDays.EndUpdate()
    End Try
End Sub

Step 2. Convert weekends to working days

The following method specifies Sunday, September 7 as a working day, thus creating an exclusion in the common holiday series of the scheduler. The ASPxDateNavigator control displays this day with black color.

csharp
private void ConvertWeekendsToWorkDays() {
    WorkDaysCollection workDays = this.ASPxScheduler1.WorkDays;
    workDays.BeginUpdate();
    try {
        DateTime workingSat = new DateTime(2008, 9, 7);
        workDays.Add(new ExactWorkDay(workingSat, "Working Sunday"));
    }
    finally {
        workDays.EndUpdate();
    }
}
vb
Private Sub ConvertWeekendsToWorkDays()
    Dim workDays As WorkDaysCollection = Me.ASPxScheduler1.WorkDays
    workDays.BeginUpdate()
    Try
        Dim workingSat As DateTime = New DateTime(2008, 9, 7)
        workDays.Add(New ExactWorkDay(workingSat, "Working Sunday"))
    Finally
        workDays.EndUpdate()
    End Try
End Sub

Step 3. Create shifted weekend days

This method creates two new holidays. They are painted red in the DateNavigator control.

csharp
private void ShiftWeekendHolidays() {
    WorkDaysCollection workDays = ASPxScheduler1.WorkDays;
    workDays.BeginUpdate();
    try {
        workDays.AddHoliday(new DateTime(2008, 9, 8), "Shifted Sunday");
        workDays.AddHoliday(new DateTime(2008, 9, 9), "Extra Non-Working Day");
    }
    finally {
        workDays.EndUpdate();
    }
}
vb
Private Sub ShiftWeekendHolidays()
    Dim workDays As WorkDaysCollection = ASPxScheduler1.WorkDays
    workDays.BeginUpdate()
    Try
        workDays.AddHoliday(New DateTime(2008, 9, 8), "Shifted Sunday")
        workDays.AddHoliday(New DateTime(2008, 9, 9), "Extra Non-Working Day")
    Finally
        workDays.EndUpdate()
    End Try
End Sub

We’ll add all-day appointments for each affected day and preview the result in the display of the ASPxDateNavigator control:

and in the scheduler’s working area: