Reprogrammation du projet

Projet de reproduction à partir de la date de début ou de fin

Ce sujet montre comment reprogrammer un projet à partir de la date de début / fin du projet à l’aide d’Aspose.Tasks pour Java.

reprogrammer un projet à partir de la date de fin

Nous pouvons recalculer les dates de la date d’arrivée en fixant la date de fin du projet, puis en invoquant la méthode Project.Recalculate (). Vous pouvez calculer les pantalons tâches en fonction de leurs dates précoces / tardives.

Échantillon de programmation

Les lignes de code suivantes montrent comment y parvenir en utilisant Java

 1// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-Java
 2// The path to the documents directory.
 3String dataDir = Utils.getDataDir(RescheduleProjectFromStartOrFinishDate.class);
 4
 5Project project = new Project(dataDir + "Project.mpp");
 6project.set(Prj.SCHEDULE_FROM_START, new NullableBool(false));
 7java.util.Calendar cal = java.util.Calendar.getInstance();
 8cal.set(2020, 1, 1, 0, 0, 0);
 9project.set(Prj.FINISH_DATE, cal.getTime());
10
11// Now all tasks dates (Start, Finish, EarlyStart, EarlyFinish,
12// LateStart,
13// LateFinish) are calculated.
14// To get the critical path we need to calculate slacks (can be invoked
15// in
16// separate thread, but only after calculation of all early/late dates)
17project.recalculate();
18TaskCollection criticalPath = project.getCriticalPath();

Rescheduling a Project from the Start Date

We can calculate dates from start date by setting the project start date and then invoke the Project.recalculate() method.

The following lines of code show how to achieve this using Java.

 1// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-Java
 2// The path to the documents directory.
 3String dataDir = Utils.getDataDir(RescheduleProjectFromStartOrFinishDate.class);
 4
 5Project project = new Project(dataDir + "Project.mpp");
 6project.set(Prj.SCHEDULE_FROM_START, new NullableBool(true));
 7java.util.Calendar cal = java.util.Calendar.getInstance();
 8cal.set(2020, 1, 1, 0, 0, 0);
 9project.set(Prj.START_DATE, cal.getTime());
10
11// Now all tasks dates (Start, Finish, EarlyStart, EarlyFinish,
12// LateStart,
13// LateFinish) are calculated.
14// To get the critical path we need to calculate slacks (can be invoked
15// in
16// separate thread, but only after calculation of all early/late dates)
17project.recalculate();
18TaskCollection criticalPath = project.getCriticalPath();

Update Project and Reschedule Uncompleted Work

Microsoft Project lets users 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 article provides a working example of both these methods as a single use case.

Update Project

This topic 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.

The following sample demonstrates how to achieve this

 1// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-Java
 2// The path to the documents directory.
 3String dataDir = Utils.getDataDir(UpdateProjectAndRescheduleuncompletedwork.class);
 4
 5long OneSec = 10000000;// microsecond * 10
 6long OneMin = 60 * OneSec;
 7long OneHour = 60 * OneMin;
 8
 9Project project = new Project();
10
11java.util.Calendar cal = java.util.Calendar.getInstance();
12cal.set(2014, 1, 27, 8, 0, 0);
13project.set(Prj.START_DATE, cal.getTime());
14
15Task task1 = project.getRootTask().getChildren().add("Task 1");
16Task task2 = project.getRootTask().getChildren().add("Task 2");
17task2.set(Tsk.DURATION, task2.getParentProject().getDuration(16, TimeUnitType.Hour));
18Task task3 = project.getRootTask().getChildren().add("Task 3");
19task3.set(Tsk.DURATION, task2.getParentProject().getDuration(24, TimeUnitType.Hour));
20Task task4 = project.getRootTask().getChildren().add("Task 4");
21task4.set(Tsk.DURATION, task2.getParentProject().getDuration(16, TimeUnitType.Hour));
22Task task5 = project.getRootTask().getChildren().add("Task 5");
23task5.set(Tsk.DURATION, task2.getParentProject().getDuration(16, TimeUnitType.Hour));
24
25TaskLink link12 = project.getTaskLinks().add(task1, task2, TaskLinkType.FinishToStart);
26TaskLink link23 = project.getTaskLinks().add(task2, task3, TaskLinkType.FinishToStart);
27link23.setLinkLag(4800); // one day lag
28TaskLink link34 = project.getTaskLinks().add(task3, task4, TaskLinkType.FinishToStart);
29TaskLink link45 = project.getTaskLinks().add(task4, task5, TaskLinkType.FinishToStart);
30
31Task task6 = project.getRootTask().getChildren().add("Task 6");
32Task task7 = project.getRootTask().getChildren().add("Task 7");
33task7.set(Tsk.DURATION, task7.getParentProject().getDuration(24, TimeUnitType.Hour));
34Task task8 = project.getRootTask().getChildren().add("Task 8");
35task8.set(Tsk.DURATION, task2.getParentProject().getDuration(16, TimeUnitType.Hour));
36Task task9 = project.getRootTask().getChildren().add("Task 9");
37task9.set(Tsk.DURATION, task2.getParentProject().getDuration(16, TimeUnitType.Hour));
38Task task10 = project.getRootTask().getChildren().add("Task 10");
39
40TaskLink link67 = project.getTaskLinks().add(task6, task7, TaskLinkType.FinishToStart);
41TaskLink link78 = project.getTaskLinks().add(task7, task8, TaskLinkType.FinishToStart);
42TaskLink link89 = project.getTaskLinks().add(task8, task9, TaskLinkType.FinishToStart);
43TaskLink link910 = project.getTaskLinks().add(task9, task10, TaskLinkType.FinishToStart);
44
45task6.set(Tsk.IS_MANUAL, new NullableBool(true));
46task7.set(Tsk.IS_MANUAL, new NullableBool(true));
47task8.set(Tsk.IS_MANUAL, new NullableBool(true));
48task9.set(Tsk.IS_MANUAL, new NullableBool(true));
49task10.set(Tsk.IS_MANUAL, new NullableBool(true));
50
51project.save(dataDir + "not updated.xml", SaveFileFormat.XML);
52
53cal.set(2014, 1, 28, 17, 0, 0);
54project.updateProjectWorkAsComplete(cal.getTime(), false);
55
56project.save(dataDir + "updated.xml", SaveFileFormat.XML);
57
58cal.set(2014, 1, 28, 17, 0, 0);
59project.rescheduleUncompletedWorkToStartAfter(cal.getTime());
60
61project.save(dataDir + "rescheduled.xml", SaveFileFormat.XML);
Subscribe to Aspose Product Updates

Get monthly newsletters & offers directly delivered to your mailbox.