Skip to main content

MonthlyExceptionRule Class

Represents a rule that specifies an exception that reoccurs every month on a particular day of the month.

Namespace: DevExpress.XtraGantt.Exceptions

Assembly: DevExpress.XtraGantt.v23.2.dll

NuGet Package: DevExpress.Win.Gantt

Declaration

public class MonthlyExceptionRule :
    WorkTimesExceptionRule

Examples

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

The code below shows how to specify holidays.

using DevExpress.XtraGantt.Base.Scheduling;
using DevExpress.XtraGantt.Exceptions;

ganttControl1.Exceptions.AddRange(CreateExceptionRules());

ExceptionRule[] CreateExceptionRules() {
    YearlyExceptionRule NewYearDay = new YearlyExceptionRule() {
        DayOfMonth = 1,
        Month = Scheduling.Month.January
    };
    YearlyDayOfWeekExceptionRule MartinLutherDay = new YearlyDayOfWeekExceptionRule() {
        DayOfWeek = System.DayOfWeek.Monday,
        Month = Scheduling.Month.January,
        WeekOfMonth = Scheduling.WeekOfMonth.Third
    };
    YearlyDayOfWeekExceptionRule PresidentDay = new YearlyDayOfWeekExceptionRule() {
        DayOfWeek = System.DayOfWeek.Monday,
        Month = Scheduling.Month.February,
        WeekOfMonth = Scheduling.WeekOfMonth.Third
    };
    YearlyDayOfWeekExceptionRule MemorialDay = new YearlyDayOfWeekExceptionRule() {
        DayOfWeek = System.DayOfWeek.Monday,
        Month = Scheduling.Month.May,
        WeekOfMonth = Scheduling.WeekOfMonth.Last
    };
    YearlyExceptionRule IndependenceDay = new YearlyExceptionRule() {
        DayOfMonth = 4,
        Month = Scheduling.Month.July
    };
    YearlyDayOfWeekExceptionRule LaborDay = new YearlyDayOfWeekExceptionRule() {
        DayOfWeek = System.DayOfWeek.Monday,
        Month = Scheduling.Month.September,
        WeekOfMonth = Scheduling.WeekOfMonth.First
    };
    YearlyDayOfWeekExceptionRule ColumbusDay = new YearlyDayOfWeekExceptionRule() {
        DayOfWeek = System.DayOfWeek.Monday,
        Month = Scheduling.Month.October,
        WeekOfMonth = Scheduling.WeekOfMonth.Second
    };
    YearlyExceptionRule VeteransDay = new YearlyExceptionRule() {
        DayOfMonth = 11,
        Month = Scheduling.Month.November
    };
    YearlyDayOfWeekExceptionRule ThanksgivingDay = new YearlyDayOfWeekExceptionRule() {
        DayOfWeek = System.DayOfWeek.Thursday,
        Month = Scheduling.Month.November,
        WeekOfMonth = Scheduling.WeekOfMonth.Forth
    };
    YearlyExceptionRule ChristmasDay = new YearlyExceptionRule() {
        DayOfMonth = 25,
        Month = Scheduling.Month.December
    };
    return new ExceptionRule[] {
        NewYearDay,
        MartinLutherDay,
        PresidentDay,
        MemorialDay,
        IndependenceDay,
        LaborDay,
        ColumbusDay,
        VeteransDay,
        ThanksgivingDay,
        ChristmasDay
    };
}

Note

Run the XtraGantt demo to see the complete example. Click Open Solution in the ribbon for source codes.

Inheritance

See Also