How to: Add Shifted Holidays to the Scheduler

  • 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

private void AddNationalHolidays() {
    WorkDaysCollection workDays = ASPxScheduler1.WorkDays;
    workDays.BeginUpdate();
    try {
        workDays.AddHoliday(new DateTime(2008, 9, 7), "Independence Day of Brazil");
    }
    finally {
        workDays.EndUpdate();
    }
}

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.

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();
    }
}

Step 3. Create shifted weekend days

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

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();
    }
}

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

ShiftedHolliday_01

and in the scheduler's working area:

ShiftedHolliday_02