aspnet-3814-components-scheduler-examples-miscellaneous-how-to-add-shifted-holidays-to-the-scheduler.md
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:
private void AddNationalHolidays() {
WorkDaysCollection workDays = ASPxScheduler1.WorkDays;
workDays.BeginUpdate();
try {
workDays.AddHoliday(new DateTime(2008, 9, 7), "Independence Day of Brazil");
}
finally {
workDays.EndUpdate();
}
}
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
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();
}
}
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
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();
}
}
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: