Hi,
I’m editing an empty mpp file and adding tasks to it. Our standard day has 2x12 hour shifts: one from 6 AM to 6 PM, and the other from 6 PM to 6 AM. This is the only calendar the project needs.
I create the calendar with the following code:
CalendarCollection calColl = _project.Calendars;
foreach (Calendar c in calColl)
{
if (c.Name == "24hourCal")
{
calColl.Remove(c);
break;
}
}
WorkingTime wt1 = new WorkingTime();
wt1.FromTime = new DateTime(1, 1, 1, 6, 0, 0, 0);
wt1.ToTime = new DateTime(1, 1, 1, 18, 0, 0, 0);
WorkingTime wt2 = new WorkingTime();
wt2.FromTime = new DateTime(1, 1, 1, 18, 0, 0, 0);
wt2.ToTime = new DateTime(1, 1, 2, 6, 0, 0, 0);
var asposeCalendar = _project.Calendars.Add("24hourCal");
Calendar.Make24HourCalendar(asposeCalendar);
foreach (var weekDay in asposeCalendar.WeekDays)
{
List<WorkingTime> asposeWorkingTimesRemove = weekDay.WorkingTimes.ToList();
foreach (var workingTime in asposeWorkingTimesRemove)
{
weekDay.WorkingTimes.Remove(workingTime);
}
//Add worktimes
weekDay.WorkingTimes.Add(wt1);
weekDay.WorkingTimes.Add(wt2);
weekDay.DayWorking = true;
}
_project.Set(Prj.Calendar, asposeCalendar);
When I open the mpp file in MS-Project, my Gantt chart bars that lye on a standard calendar’s non-work time are not plotting. When I check the definition of my new calendar “24hourCal”, my work times do not exist, and only the standard calendar’s work times are shown. What am I doing wrong?
Cheers
Ian