XamGanttのカレンダーで特定の日を稼働日や非稼働日にする場合は、設定する日ごとにProjectCalendarExceptionオブジェクトを作成し、カレンダーに追加してください。
// ==== 毎年5月3日をプロジェクト開始日から2年間非稼働日にする場合 ====
ProjectCalendarException pce1 = new ProjectCalendarException();
pce1.DateRange = new DateRange(project.Start, project.Start.AddYears(2)); // 開始日: プロジェクト開始日、終了日: プロジェクト開始日の2年後
pce1.DaySettings = new DaySettings { IsWorkday = false }; // 非稼働日として設定
pce1.Recurrence = new DateRecurrence // 繰り返しの設定
{
Count = 0, // 無期限(※無期限の場合、DateRangeは開始日と終了日の両方の指定が必要)
Frequency = DateRecurrenceFrequency.Yearly // 年次
};
pce1.Recurrence.Rules.Add(new MonthOfYearRecurrenceRule(5)); // 毎年5月
pce1.Recurrence.Rules.Add(new DayOfMonthRecurrenceRule(3)); // 毎月3日(※MonthOfYearRecurrenceRuleとDayOfMonthRecurrenceRuleの両方同時にDateRecurrenceFrequencyをYearlyで追加することで、毎年5月3日を非稼働日に指定できる)
projectCalendar.Exceptions.Add(pce1); // プロジェクトのカレンダーに追加する。
// ==== 2021年1月30日(土)のみを稼働日にする場合 ====
ProjectCalendarException pce2 = new ProjectCalendarException();
pce2.DateRange = new DateRange(new DateTime(2021, 1, 30)); // 開始日を指定
pce2.DaySettings = new DaySettings { IsWorkday = true }; // 稼働日として設定
pce2.Recurrence = new DateRecurrence // 繰り返しの設定
{
Count = 1, // 1回だけ
Frequency = DateRecurrenceFrequency.Daily // 日次
};
projectCalendar.Exceptions.Add(pce2); // プロジェクトのカレンダーに追加する。
サンプル
ヘルプドキュメント、APIリファレンス
- xamGantt コード例カレンダー例外の作成 (xamGantt)
- ProjectCalendarException クラス メンバ
- DateRange 構造体 メンバ
- DaySettings クラス メンバ
- DateRecurrence クラス メンバ