プロジェクトの再スケジュール
開始日または終了日からプロジェクトを再スケジュールする
このトピックは、C ++のAspose.Tasksを使用して、プロジェクトの開始/終了日からプロジェクトを再スケジュールする方法を示しています。
プロジェクトの終了日を設定し、task.recalculate()を呼び出すことにより、終了日から日付を再計算できます。再スケジュールは、public Method Project.calcslacks()によってより速く作成されます。タスクのスラックを早期/遅い日付に基づいて計算できます。
プログラミングサンプル:終了日からプロジェクトの再スケジュール 次のコード行は、終了日からプロジェクトの再スケジュールを達成する方法を示しています。
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.
- 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.
- 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.
- 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);