Project Rescheduling

Reschedule Project From Start or Finish Date

This topic shows how to reschedule a project from the project start/finish date using Aspose.Tasks for C++.

We can recalculate dates from finish date by setting the project finish date and then invoking Task.Recalculate(). Rescheduling is made faster by the public method Project.CalcSlacks(). You can calculate tasks slacks based on their early/late dates.

Programming Sample: Rescheduling a Project from the Finish Date The following lines of code demonstrate how to achieve rescheduling of a project from the finish date.

 1// The path to the documents directory.
 2System::String dataDir = RunExamples::GetDataDir(System::Reflection::MethodBase::GetCurrentMethod(ASPOSE_CURRENT_FUNCTION)->get_DeclaringType().get_FullName());
 3    
 4System::SharedPtr<Project> project = System::MakeObject<Project>(dataDir + u"Project2.mpp");
 5project->Set<NullableBool>(Prj::ScheduleFromStart(), NullableBool::to_NullableBool(false));
 6project->Set(Prj::FinishDate(), System::DateTime(2020, 1, 1));
 7    
 8// Now all tasks dates (Start, Finish, EarlyStart, EarlyFinish, LateStart, LateFinish) are calculated. To get the critical path we need to calculate slacks (can be invoked in separate thread, but only after calculation of all early/late dates)
 9project->Recalculate();
10System::SharedPtr<TaskCollection> criticalPath = project->get_CriticalPath();

Programming Sample: Rescheduling a Project from the Start Date The following lines of code demonstrate how to achieve rescheduling of a project from the start date.

 1// The path to the documents directory.
 2System::String dataDir = RunExamples::GetDataDir(System::Reflection::MethodBase::GetCurrentMethod(ASPOSE_CURRENT_FUNCTION)->get_DeclaringType().get_FullName());
 3    
 4System::SharedPtr<Project> project = System::MakeObject<Project>(dataDir + u"Project2.mpp");
 5project->Set<NullableBool>(Prj::ScheduleFromStart(), NullableBool::to_NullableBool(true));
 6project->Set(Prj::StartDate(), System::DateTime(2014, 1, 1));
 7    
 8// Now all tasks dates (Start, Finish, EarlyStart, EarlyFinish, LateStart, LateFinish) are calculated. To get the critical path we need to calculate slacks (can be invoked in separate thread, but only after calculation of all early/late dates)
 9project->Recalculate();
10System::SharedPtr<TaskCollection> criticalPath = project->get_CriticalPath();

Update Project and Reschedule Uncomplete Work

Microsoft Project provides the facility to update and reschedule work through a defined date. This helps identify work completed up to the specified date as well as reschedule any uncompleted work from a specified date. Aspose.Tasks’ Project API provides the same functionality by exposing the UpdateProjectWorkAsComplete and RescheduleUncompletedWorkToStartAfter methods. This topic provides a working example of both these methods as a single-use case.

Update Project

The example below demonstrates how to update a project through a specified date. The UpdateProjectWorkAsComplete method updates all the work as complete through a specified date for an entire project.

  1. If the Boolean input parameter is set to true, the method updates only those tasks to 100% complete that have finish dates before the specified completed-through date.
  2. If the Boolean input parameter is set to false, the method calculates a percentage complete value based on the scheduled state and complete-through dates.
  3. If a list of task is specified, the method updates all work as complete through the specified date for the list of tasks.
 1// The path to the documents directory.
 2System::String dataDir = RunExamples::GetDataDir(System::Reflection::MethodBase::GetCurrentMethod(ASPOSE_CURRENT_FUNCTION)->get_DeclaringType().get_FullName());
 3    
 4// Create a new project and set start date
 5System::SharedPtr<Project> project = System::MakeObject<Project>();
 6project->Set(Prj::StartDate(), System::DateTime(2014, 1, 27, 8, 0, 0));
 7    
 8// Add new tasks
 9System::SharedPtr<Task> task1 = project->get_RootTask()->get_Children()->Add(u"Task 1");
10System::SharedPtr<Task> task2 = project->get_RootTask()->get_Children()->Add(u"Task 2");
11task2->Set<Duration>(Tsk::Duration(), task2->get_ParentProject()->GetDuration(16, Aspose::Tasks::TimeUnitType::Hour));
12System::SharedPtr<Task> task3 = project->get_RootTask()->get_Children()->Add(u"Task 3");
13task3->Set<Duration>(Tsk::Duration(), task2->get_ParentProject()->GetDuration(24, Aspose::Tasks::TimeUnitType::Hour));
14System::SharedPtr<Task> task4 = project->get_RootTask()->get_Children()->Add(u"Task 4");
15task4->Set<Duration>(Tsk::Duration(), task2->get_ParentProject()->GetDuration(16, Aspose::Tasks::TimeUnitType::Hour));
16System::SharedPtr<Task> task5 = project->get_RootTask()->get_Children()->Add(u"Task 5");
17task5->Set<Duration>(Tsk::Duration(), task2->get_ParentProject()->GetDuration(16, Aspose::Tasks::TimeUnitType::Hour));
18    
19// Add links between tasks
20System::SharedPtr<TaskLink> link12 = project->get_TaskLinks()->Add(task1, task2, Aspose::Tasks::TaskLinkType::FinishToStart);
21System::SharedPtr<TaskLink> link23 = project->get_TaskLinks()->Add(task2, task3, Aspose::Tasks::TaskLinkType::FinishToStart);
22// One day lag
23link23->set_LinkLag(4800);
24System::SharedPtr<TaskLink> link34 = project->get_TaskLinks()->Add(task3, task4, Aspose::Tasks::TaskLinkType::FinishToStart);
25System::SharedPtr<TaskLink> link45 = project->get_TaskLinks()->Add(task4, task5, Aspose::Tasks::TaskLinkType::FinishToStart);
26    
27// Add new tasks
28System::SharedPtr<Task> task6 = project->get_RootTask()->get_Children()->Add(u"Task 6");
29System::SharedPtr<Task> task7 = project->get_RootTask()->get_Children()->Add(u"Task 7");
30task7->Set<Duration>(Tsk::Duration(), task7->get_ParentProject()->GetDuration(24, Aspose::Tasks::TimeUnitType::Hour));
31System::SharedPtr<Task> task8 = project->get_RootTask()->get_Children()->Add(u"Task 8");
32task8->Set<Duration>(Tsk::Duration(), task2->get_ParentProject()->GetDuration(16, Aspose::Tasks::TimeUnitType::Hour));
33System::SharedPtr<Task> task9 = project->get_RootTask()->get_Children()->Add(u"Task 9");
34task9->Set<Duration>(Tsk::Duration(), task2->get_ParentProject()->GetDuration(16, Aspose::Tasks::TimeUnitType::Hour));
35System::SharedPtr<Task> task10 = project->get_RootTask()->get_Children()->Add(u"Task 10");
36    
37// Add links between tasks
38System::SharedPtr<TaskLink> link67 = project->get_TaskLinks()->Add(task6, task7, Aspose::Tasks::TaskLinkType::FinishToStart);
39System::SharedPtr<TaskLink> link78 = project->get_TaskLinks()->Add(task7, task8, Aspose::Tasks::TaskLinkType::FinishToStart);
40System::SharedPtr<TaskLink> link89 = project->get_TaskLinks()->Add(task8, task9, Aspose::Tasks::TaskLinkType::FinishToStart);
41System::SharedPtr<TaskLink> link910 = project->get_TaskLinks()->Add(task9, task10, Aspose::Tasks::TaskLinkType::FinishToStart);
42task6->Set<NullableBool>(Tsk::IsManual(), NullableBool::to_NullableBool(true));
43task7->Set<NullableBool>(Tsk::IsManual(), NullableBool::to_NullableBool(true));
44task8->Set<NullableBool>(Tsk::IsManual(), NullableBool::to_NullableBool(true));
45task9->Set<NullableBool>(Tsk::IsManual(), NullableBool::to_NullableBool(true));
46task10->Set<NullableBool>(Tsk::IsManual(), NullableBool::to_NullableBool(true));
47    
48// Save project before and after updating work as completed 
49project->Save(dataDir + u"RescheduleUncompletedWork_not updated_out.xml", Aspose::Tasks::Saving::SaveFileFormat::XML);
50project->UpdateProjectWorkAsComplete(System::DateTime(2014, 1, 28, 17, 0, 0), false);
51project->Save(dataDir + u"RescheduleUncompletedWork_updated_out.xml", Aspose::Tasks::Saving::SaveFileFormat::XML);
52    
53// Save project after rescheduling uncompleted work
54project->RescheduleUncompletedWorkToStartAfter(System::DateTime(2014, 2, 7, 8, 0, 0));
55project->Save(dataDir + u"RescheduleUncompletedWork_rescheduled_out.xml", Aspose::Tasks::Saving::SaveFileFormat::XML);
Subscribe to Aspose Product Updates

Get monthly newsletters & offers directly delivered to your mailbox.