Tareas en movimiento
Microsoft Project permite mover una tarea en otra tarea. En este caso, las tareas infantiles de las tareas seleccionadas también se mueven con ella. Aspose.Tasks for C ++ API proporciona la misma característica al mover una tarea en otra tarea. Esto se puede lograr agregando la tarea seleccionada a los hijos del nuevo padre como se muestra en este artículo. La tarea se puede mover bajo un padre diferente o el mismo padre.
Mueve la tarea bajo otro padre
Tenga en cuenta que usar * cálculoMode.None * puede mejorar el rendimiento cuando agrega varias tareas y llama * recalcular * el método una vez.
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// Loading project file
5System::SharedPtr<Project> project = System::MakeObject<Project>(dataDir + u"MoveTask.mpp");
6
7// Set CalculationMode
8project->set_CalculationMode(Aspose::Tasks::CalculationMode::Automatic);
9
10// Get Tasks by Ids
11System::SharedPtr<Task> t6 = project->get_RootTask()->get_Children()->GetByUid(6);
12System::SharedPtr<Task> t3 = project->get_RootTask()->get_Children()->GetByUid(3);
13
14// Adding Task 6 to another parent
15t3->get_Children()->Add(t6);
16
17// Saving File To Disk
18project->Save(dataDir + u"MoveTaskUnderAnotherParent_out.mpp", Aspose::Tasks::Saving::SaveFileFormat::MPP);
Moving Task Under the Same Parent
The MoveToSibling method allows moving a task under the same parent to a specific position.
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// Loading project file
5System::SharedPtr<Project> project = System::MakeObject<Project>(dataDir + u"MoveTask.mpp");
6
7// Move tasks with id 5 before task with id 3
8System::SharedPtr<Task> task = project->get_RootTask()->get_Children()->GetById(5);
9task->MoveToSibling(3);
10
11// Saving File To Disk
12project->Save(dataDir + u"MoveTaskUnderSameParent_out.mpp", Aspose::Tasks::Saving::SaveFileFormat::MPP);
Add Task To The End
To add a task to the end of the collection use -1.
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// Loading project file
5System::SharedPtr<Project> project = System::MakeObject<Project>(dataDir + u"MoveTask.mpp");
6
7// Move tasks with id 2 to the end of the collection
8System::SharedPtr<Task> task = project->get_RootTask()->get_Children()->GetById(2);
9task->MoveToSibling(-1);
10
11// Saving File To Disk
12project->Save(dataDir + u"MoveTaskAtTheEnd_out.mpp", Aspose::Tasks::Saving::SaveFileFormat::MPP);
Setting a Task to a SubProject
1// Create project instance
2System::String dataDir = RunExamples::GetDataDir(System::Reflection::MethodBase::GetCurrentMethod(ASPOSE_CURRENT_FUNCTION)->get_DeclaringType().get_FullName());
3System::SharedPtr<Project> project = System::MakeObject<Project>(dataDir + u"SubProjectTask.mpp");
4
5// Add task
6System::SharedPtr<Task> task = project->get_RootTask()->get_Children()->Add(u"Task 1");
7
8// Setting new subproject link
9task->Set<System::String>(Tsk::SubprojectName(), dataDir + u"subProject.mpp");
10
11// Save project
12project->Save(dataDir + u"SubProjectTask_out.mpp", Aspose::Tasks::Saving::SaveFileFormat::MPP);