windowsforms-devexpress-dot-xtragantt-dot-exceptions-f4c81263.md
Represents a rule that specifies an exception that reoccurs by days.
Namespace : DevExpress.XtraGantt.Exceptions
Assembly : DevExpress.XtraGantt.v25.2.dll
NuGet Package : DevExpress.Win.Gantt
public class DaysExceptionRule :
ExceptionRule,
INotifyCollectionChanged<ExceptionDay>
Public Class DaysExceptionRule
Inherits ExceptionRule
Implements INotifyCollectionChanged(Of ExceptionDay)
This code shows how to how to alternate two full work days and two short work days.
using DevExpress.XtraGantt.Exceptions;
DaysExceptionRule rule = new DaysExceptionRule() {
StartDate = new DateTime(2019, 9, 12),
Interval = 2
};
WorkTime morningWorkTime = new WorkTime(9, 12);
WorkTime afternoonWorkTime = new WorkTime(13, 18);
rule.Days.Add(new ExceptionDay(morningWorkTime));
rule.Days.Add(new ExceptionDay(afternoonWorkTime));
Imports DevExpress.XtraGantt.Exceptions
Dim rule As New DaysExceptionRule() With {
.StartDate = New Date(2019, 9, 12),
.Interval = 2
}
Dim morningWorkTime As New WorkTime(9, 12)
Dim afternoonWorkTime As New WorkTime(13, 18)
rule.Days.Add(New ExceptionDay(morningWorkTime))
rule.Days.Add(New ExceptionDay(afternoonWorkTime))
The code below shows how to specify custom exception rules.
using DevExpress.XtraGantt;
using DevExpress.XtraGantt.Base.Scheduling;
using DevExpress.XtraGantt.Exceptions;
using DevExpress.XtraGantt.Scheduling;
private ExceptionRule[] CreateCustomRules() {
DailyExceptionRule dailyException = new DailyExceptionRule() {
StartDate = new DateTime(2019, 8, 19),
Occurrences = 7
};
dailyException.WorkTimes.Add(new WorkTime(9, 12));
DaysExceptionRule daysException = new DaysExceptionRule() {
StartDate = new System.DateTime(2023, 9, 27, 0, 0, 0, 0),
Occurrences = 1
};
// The rule applies to the first day of each month (January, 1; February, 1; etc.)
MonthlyExceptionRule FirstDayInMonth = new MonthlyExceptionRule() {
DayOfMonth = 1
};
FirstDayInMonth.Add(new WorkTime(10, 12));
// The rule applies to the second Friday of each month.
MonthlyDayOfWeekExceptionRule SecondFridayInMonth = new MonthlyDayOfWeekExceptionRule() {
DayOfWeek = DayOfWeek.Friday,
WeekOfMonth = WeekOfMonth.Second
};
SecondFridayInMonth.Add(new WorkTime(9, 12));
// The rule applies to 31st December 5 times
// each two years starting from 12/31/2019.
YearlyExceptionRule December31 = new YearlyExceptionRule() {
DayOfMonth = 31,
Month = Month.December,
StartDate = new DateTime(2019, 12, 31),
Interval = 2,
Occurrences = 5
};
December31.Add(new WorkTime(9, 11));
//The rule applies to the 256th day each year.
YearlyDayOfYearExceptionRule Day256 = new YearlyDayOfYearExceptionRule() {
DayOfYear = 256,
};
// Specify work hours for the 256th day.
Day256.WorkTimes.Add(new WorkTime(9, 12));
return new ExceptionRule[] { SecondFridayInMonth, FirstDayInMonth, dailyException, daysException, Day256, December31 };
}
ganttControl1.Exceptions.AddRange(CreateCustomRules());
Imports DevExpress.XtraGantt
Imports DevExpress.XtraGantt.Base.Scheduling
Imports DevExpress.XtraGantt.Exceptions
Imports DevExpress.XtraGantt.Scheduling
Private Function CreateCustomRules() As ExceptionRule()
Dim dailyException As New DailyExceptionRule() With {
.StartDate = New Date(2019, 8, 19),
.Occurrences = 7
}
dailyException.WorkTimes.Add(New WorkTime(9, 12))
Dim daysException As New DaysExceptionRule() With {
.StartDate = New Date(2023, 9, 27, 0, 0, 0, 0),
.Occurrences = 1
}
' The rule applies to the first day of each month (January, 1; February, 1; etc.)
Dim FirstDayInMonth As New MonthlyExceptionRule() With {.DayOfMonth = 1}
FirstDayInMonth.Add(New WorkTime(10, 12))
' The rule applies to the second Friday of each month.
Dim SecondFridayInMonth As New MonthlyDayOfWeekExceptionRule() With {
.DayOfWeek = DayOfWeek.Friday,
.WeekOfMonth = WeekOfMonth.Second
}
SecondFridayInMonth.Add(New WorkTime(9, 12))
' The rule applies to 31st December 5 times
' each two years starting from 12/31/2019.
Dim December31 As New YearlyExceptionRule() With {
.DayOfMonth = 31,
.Month = Month.December,
.StartDate = New Date(2019, 12, 31),
.Interval = 2,
.Occurrences = 5
}
December31.Add(New WorkTime(9, 11))
'The rule applies to the 256th day each year.
Dim Day256 As New YearlyDayOfYearExceptionRule() With {.DayOfYear = 256}
' Specify work hours for the 256th day.
Day256.WorkTimes.Add(New WorkTime(9, 12))
Return New ExceptionRule() { SecondFridayInMonth, FirstDayInMonth, dailyException, daysException, Day256, December31 }
End Function
ganttControl1.Exceptions.AddRange(CreateCustomRules())
Object BaseRule ExceptionRule DaysExceptionRule
See Also