Hi, we'd like to add a dateRecurrence on a ProjectCalendarException that for example will reoccur every week on Thursday. Unfortunately we're unable to find a working solution, regardless of what combination of count, interval and frequency we're trying.
Based on the documentation we tried:
ProjectCalendarException pce = new ProjectCalendarException()
{
DateRange = new DateRange(DateTime.Today),
DaySettings = new DaySettings { IsWorkday = false },
Recurrence = new DateRecurrence { Count = 0, Frequency = DateRecurrenceFrequency.Weekly },
};
Now I would expect that this exception reoccurs every week for an unlimited time, but that's not the case in v17.1. In addition, if we set the count to 2, the next 2 weeks are now none-working-days instead of one none-working day reoccurring for 2 weeks.
Any help appreciated.
Stefan Spies said: Hi, this now looks really promising and finally works like expected. Thanks very much. One thing I've noticed now, is that the integrated function ToExceptionsXml doesn't take the rules added to an exception into account, so they can't be easily stored.I will circumvent now around this in my project, but can you have a look at this as well or should I open a new forum entry for this (possibly not desired) behaviour? Thanks,Stefan
Hi,
this now looks really promising and finally works like expected. Thanks very much.
One thing I've noticed now, is that the integrated function ToExceptionsXml doesn't take the rules added to an exception into account, so they can't be easily stored.I will circumvent now around this in my project, but can you have a look at this as well or should I open a new forum entry for this (possibly not desired) behaviour?
Thanks,Stefan
Hi Stefan,
I am glad my suggestions were helpful. In regards to your question about ToExceptionsXml() method, I believe it's an issue in the control itself so I created a separate forum thread. This way the communication would be easier and there would be no confusion about the different issues. Also other community members that have similar issues would be able to benefit from the threads too.
For specifying bank holidays when dealing with a long period of time I would suggest using a combination of DayOfMonthRecurrenceRule and MonthOfYearRecurrenceRule for that specific ProjectCalendarException. For example, If I would like to specify the 3 March as a bank holiday, I would need the following ProjectCalendarException:
DayOfMonthRecurrenceRule rule2 = new DayOfMonthRecurrenceRule(3); MonthOfYearRecurrenceRule rule3 = new MonthOfYearRecurrenceRule(3); ProjectCalendarException pceBankHoliday = new ProjectCalendarException() { DateRange = new DateRange(new DateTime(2018, 3, 3), DateTime.Today.AddYears(10)), DaySettings = new DaySettings { IsWorkday = false }, Recurrence = new DateRecurrence { Frequency = DateRecurrenceFrequency.Yearly, Count = 0 }, }; pceBankHoliday.Recurrence.Rules.Add(rule2); pceBankHoliday.Recurrence.Rules.Add(rule3); project.CalendarResolved.Exceptions.Add(pceBankHoliday); gantt.Project = project;
DayOfMonthRecurrenceRule rule2 = new DayOfMonthRecurrenceRule(3);
MonthOfYearRecurrenceRule rule3 = new MonthOfYearRecurrenceRule(3);
ProjectCalendarException pceBankHoliday = new ProjectCalendarException()
DateRange = new DateRange(new DateTime(2018, 3, 3), DateTime.Today.AddYears(10)),
Recurrence = new DateRecurrence { Frequency = DateRecurrenceFrequency.Yearly, Count = 0 },
pceBankHoliday.Recurrence.Rules.Add(rule2);
pceBankHoliday.Recurrence.Rules.Add(rule3);
project.CalendarResolved.Exceptions.Add(pceBankHoliday);
gantt.Project = project;
Please, review this approach and let me know if you need further assistance.
Hi Galina,
thanks for your support, you're right I missed the recurrence rules and now I almost got what I need. One question left though:
What we want to achieve with the exceptions is to create a holiday management inside our gantt planning module.For this we only want to add the fixed holidays once and set the recurrence to yearly. But I can't get that to work with the recurrence rules:
How would you implement that kind of recurrence?
Thanks a lot,
Stefan
Hello Stefan,
In order to achieve a recurrence pattern where a certain day of every week has different DaySettings, you will need to make use of the recurrence rules. For instance, in order to make every Tuesday a non-working day, you should create a DayOfWeekRecurrenceRule as follows:
DayOfWeekRecurrenceRule rule = new DayOfWeekRecurrenceRule(DayOfWeek.Tuesday);
This rule then needs to be added to the Rules collection of the ProjectCalendarException's Recurrence object. In addition, when using Count = 0, the date range for the ProjectCalendarException should be defined with its start and end date as opposed to start only. The code for achieving non-working Tuesdays for a year should look similar to:
DateRange = new DateRange(DateTime.Today.AddDays(-1), DateTime.Today.AddDays(366)),
Recurrence = new DateRecurrence { Frequency = DateRecurrenceFrequency.Daily, Count = 0 },
pce.Recurrence.Rules.Add(rule);
project.CalendarResolved.Exceptions.Add(pce);
I implemented this approach in the sample application I am attaching for your reference. Please, review it and let me know if you need further assistance.