Tâches mobiles

Microsoft Project permet de déplacer une tâche sous une autre tâche. Dans ce cas, les tâches enfants des tâches sélectionnées sont également déplacées avec elle. Aspose.Tasks pour l’API C ++ fournit la même fonctionnalité en déplaçant une tâche sous une autre tâche. Cela peut être réalisé en ajoutant la tâche sélectionnée aux enfants du nouveau parent comme indiqué dans cet article. La tâche peut être déplacée sous un parent différent ou le même parent.

Déplacer la tâche sous un autre parent

Veuillez noter que l’utilisation * calculmode.none * peut améliorer les performances lorsque vous ajoutez plusieurs tâches et appelez * Recalculer * la méthode une seule fois.

 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);
Subscribe to Aspose Product Updates

Get monthly newsletters & offers directly delivered to your mailbox.