Reschedule Project tasks and resource assignments

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 .NET.

We can recalculate dates from finish date by setting the project finish date and then invoking Project.Recalculate().

Programming Sample: Rescheduling a Project from the Finish Date The following lines of code show how to achieve this using C#.

1Project project = new Project("New Project.mpp");
2project.Set(Prj.ScheduleFromStart, false);
3project.Set(Prj.FinishDate, new DateTime(2020, 1, 1));
4
5// 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)
6project.Recalculate();
7TaskCollection criticalPath = project.CriticalPath;

Programming Sample: Rescheduling a Project from the Start Date The following lines of code shows how to achieve this using C#.

1Project project = new Project("New Project.mpp");
2project.Set(Prj.ScheduleFromStart, true);
3project.Set(Prj.StartDate, new DateTime(2014, 1, 1));
4
5// 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)
6project.Recalculate();
7TaskCollection criticalPath = project.CriticalPath;

Update Project and Reschedule Incomplete 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’s 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 Files

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// Create a new project and set start date
 2Project project = new Project();
 3project.Set(Prj.StartDate, new DateTime(2014, 1, 27, 8, 0, 0));
 4
 5// Add new tasks
 6Task task1 = project.RootTask.Children.Add("Task 1");
 7Task task2 = project.RootTask.Children.Add("Task 2");
 8task2.Set(Tsk.Duration, task2.ParentProject.GetDuration(16, TimeUnitType.Hour));
 9Task task3 = project.RootTask.Children.Add("Task 3");
10task3.Set(Tsk.Duration, task2.ParentProject.GetDuration(24, TimeUnitType.Hour));
11Task task4 = project.RootTask.Children.Add("Task 4");
12task4.Set(Tsk.Duration, task2.ParentProject.GetDuration(16, TimeUnitType.Hour));
13Task task5 = project.RootTask.Children.Add("Task 5");
14task5.Set(Tsk.Duration, task2.ParentProject.GetDuration(16, TimeUnitType.Hour));
15
16// Add links between tasks
17TaskLink link12 = project.TaskLinks.Add(task1, task2, TaskLinkType.FinishToStart);
18TaskLink link23 = project.TaskLinks.Add(task2, task3, TaskLinkType.FinishToStart);
19// One day lag
20link23.LinkLag = 4800; 
21TaskLink link34 = project.TaskLinks.Add(task3, task4, TaskLinkType.FinishToStart);
22TaskLink link45 = project.TaskLinks.Add(task4, task5, TaskLinkType.FinishToStart);
23
24// Add new tasks
25Task task6 = project.RootTask.Children.Add("Task 6");
26Task task7 = project.RootTask.Children.Add("Task 7");
27task7.Set(Tsk.Duration, task7.ParentProject.GetDuration(24, TimeUnitType.Hour));
28Task task8 = project.RootTask.Children.Add("Task 8");
29task8.Set(Tsk.Duration, task2.ParentProject.GetDuration(16, TimeUnitType.Hour));
30Task task9 = project.RootTask.Children.Add("Task 9");
31task9.Set(Tsk.Duration, task2.ParentProject.GetDuration(16, TimeUnitType.Hour));
32Task task10 = project.RootTask.Children.Add("Task 10");
33
34// Add links between tasks
35TaskLink link67 = project.TaskLinks.Add(task6, task7, TaskLinkType.FinishToStart);
36TaskLink link78 = project.TaskLinks.Add(task7, task8, TaskLinkType.FinishToStart);
37TaskLink link89 = project.TaskLinks.Add(task8, task9, TaskLinkType.FinishToStart);
38TaskLink link910 = project.TaskLinks.Add(task9, task10, TaskLinkType.FinishToStart);
39task6.Set(Tsk.IsManual, true);
40task7.Set(Tsk.IsManual, true);
41task8.Set(Tsk.IsManual, true);
42task9.Set(Tsk.IsManual, true);
43task10.Set(Tsk.IsManual, true);
44
45// Save project before and after updating work as completed 
46project.Save("RescheduleUncompletedWork_not updated_out.xml", SaveFileFormat.XML);
47project.UpdateProjectWorkAsComplete(new DateTime(2014, 1, 28, 17, 0, 0), false);
48project.Save("RescheduleUncompletedWork_updated_out.xml", SaveFileFormat.XML);
49
50// Save project after rescheduling uncompleted work
51project.RescheduleUncompletedWorkToStartAfter(new DateTime(2014, 2, 7, 8, 0, 0));
52project.Save("RescheduleUncompletedWork_rescheduled_out.xml", SaveFileFormat.XML);
Subscribe to Aspose Product Updates

Get monthly newsletters & offers directly delivered to your mailbox.