タスクの制約の処理

タスクの制約は、Microsoft Project Projectのスケジュールを定義し、タスクをいつ開始または終了するかを定義するために使用されます。制約は柔軟になります - できるだけ早く、またはできるだけ早く開始または終了します - または柔軟性がありません。柔軟性のない制約は、特定の日付と結びついています。

制約の操作

制約と制約タイプのプロパティは、制約を処理するために タスククラスによって公開されます。

Microsoftプロジェクトの制約の設定

Microsoftプロジェクトで制約を設定するには:

  1. ビューメニューで、その他のビューを選択し、タスクエントリフォームを選択します。
  2. タスクエントリフォームのタスクをダブルクリックします。
  3. [アドバンス]タブを選択します。
  4. 制約タイプリストからオプションを選択し、制約日付リストの日付を選択して制約を設定します。

Microsoftプロジェクトの制約の設定

Microsoftプロジェクトのタスク制約の更新

Aspose.Tasksで制約を設定

制約タイプができるだけ早くまたはできるだけ遅くの場合、制約日はNAです。 Naに等しい日付値の場合、Aspose.Tasksは評価バージョンで値「1/1/2000」、およびライセンス製品のMinValueの値「1/1/2000」を使用します。以下の場合、ソースプロジェクトファイルを入力として使用し、それぞれの場合にさまざまなタスクにさまざまなタイプの制約を適用します。次のコードサンプルは、さまざまな制約タイプの適用と、各ケースの結果のスナップショットを伴うことを示しています。

入力ファイル

Microsoft Projectでタスク制約を備えたMPPファイルを編集します

以下のコードサンプルは、制約タイプを設定して設定されています。

 1// Create project instance
 2Project project = new Project(dataDir + "ConstraintStartNoEarlierThan.mpp");
 3            
 4// Set constraint Start No Earlier Than on task with Id 1
 5Task summary = project.getRootTask().getChildren().getById(1);
 6summary.set(Tsk.CONSTRAINT_TYPE, ConstraintType.StartNoEarlierThan);
 7        
 8java.util.Calendar cal = java.util.Calendar.getInstance();
 9cal.set(2013, 6, 3, 9, 0, 0);
10summary.set(Tsk.CONSTRAINT_DATE, cal.getTime());
11
12// Save project as pdf
13SaveOptions o = new PdfSaveOptions();
14o.setStartDate(project.get(Prj.START_DATE));
15o.setTimescale(Timescale.ThirdsOfMonths);
16project.save(dataDir + "project_StartNoEarlierThan_out.pdf", o);

Output file with Start No Earlier Than constraint

save MPP file with task constraints in Microsoft Project

The code samples below set the constraint type set to Finish No Earlier Than.

 1// Create project instance
 2Project project = new Project(dataDir + "ConstraintStartNoEarlierThan.mpp");
 3            
 4// Set constraint Start No Earlier Than on task with Id 1
 5Task summary = project.getRootTask().getChildren().getById(1);
 6summary.set(Tsk.CONSTRAINT_TYPE, ConstraintType.FinishNoEarlierThan);
 7        
 8java.util.Calendar cal = java.util.Calendar.getInstance();
 9cal.set(2013, 6, 1, 18, 0, 0);
10summary.set(Tsk.CONSTRAINT_DATE, cal.getTime());
11
12// Save project as pdf
13SaveOptions o = new PdfSaveOptions();
14o.setStartDate(project.get(Prj.START_DATE));
15o.setTimescale(Timescale.ThirdsOfMonths);
16project.save(dataDir + "project_StartNoEarlierThan_out.pdf", o);

Output file showing Finish No Earlier Than constraint

Finish No Earlier Than task constraint in Microsoft Project

The code samples below set the constraint type set to Must Start On.

 1// Create project instance
 2Project project = new Project(dataDir + "ConstraintStartNoEarlierThan.mpp");
 3        
 4// Set constraint Must Start On for task with Id 2
 5Task roof = project.getRootTask().getChildren().getById(2);
 6roof.set(Tsk.CONSTRAINT_TYPE, ConstraintType.MustFinishOn);
 7
 8java.util.Calendar cal = java.util.Calendar.getInstance();
 9cal.set(2013, 6, 1, 18, 0, 0);
10roof.set(Tsk.CONSTRAINT_DATE, cal.getTime());
11
12// Save project as pdf
13SaveOptions options = new PdfSaveOptions();
14options.setStartDate(project.get(Prj.START_DATE));
15options.setTimescale(Timescale.ThirdsOfMonths);
16project.save(dataDir + "project_MustStartOn_out.pdf", options);

Output file showing Must Start On constraint

Must Start On task constraint in Microsoft Project

The code samples below set the constraint type set to As Late As Possible.

 1// Create project instance
 2Project project = new Project(dataDir + "ConstraintStartNoEarlierThan.mpp");
 3        
 4// Set constraint As Late As Possible for task with Id 11
 5Task wallBoard = project.getRootTask().getChildren().getById(11);
 6wallBoard.set(Tsk.CONSTRAINT_TYPE, ConstraintType.AsLateAsPossible);            
 7            
 8// Save project as pdf
 9SaveOptions options = new PdfSaveOptions();
10options.setStartDate(project.get(Prj.START_DATE));
11options.setTimescale(Timescale.ThirdsOfMonths);
12project.save(dataDir + "project_AsLateAsPossible_out.pdf", options);

Output file showing As Late As Possible constraint

As Late As Possible task constraint in Microsoft Project

The code sample below shows the constraint type set to Must Finish On.

 1// Create project instance
 2Project project = new Project(dataDir + "ConstraintStartNoEarlierThan.mpp");
 3        
 4// Set constraint Must Finish On for task with Id 15
 5Task interiorFixtures = project.getRootTask().getChildren().getById(15);
 6interiorFixtures.set(Tsk.CONSTRAINT_TYPE, ConstraintType.MustFinishOn);
 7        
 8java.util.Calendar cal = java.util.Calendar.getInstance();
 9cal.set(2013, 9, 21, 18, 0, 0);
10interiorFixtures.set(Tsk.CONSTRAINT_DATE, cal.getTime());
11            
12// Save project as pdf
13SaveOptions options = new PdfSaveOptions();
14options.setStartDate(project.get(Prj.START_DATE));
15options.setTimescale(Timescale.ThirdsOfMonths);
16project.save(dataDir + "project_MustFinishOn_out.pdf", options);

Output file showing Must Finish On constraint

Must Finish On task constraint in Microsoft Project

Getting Constraints

This code sample displays any constraints found when traversing the tasks in the project to a command window.

 1Project project = new Project(dataDir + "Project2.mpp");
 2
 3// Create a ChildTasksCollector instance
 4ChildTasksCollector collector = new ChildTasksCollector();
 5
 6// Collect all the tasks from RootTask using TaskUtils
 7TaskUtils.apply(project.getRootTask(), collector, 0);
 8
 9// Parse through all the collected tasks
10for (Task tsk1 : collector.getTasks())
11{
12    if (tsk1.get(Tsk.CONSTRAINT_DATE).toString() == "1/1/2000")
13        System.out.println("NA");
14    else
15        System.out.println(tsk1.get(Tsk.CONSTRAINT_DATE).toString());
16
17    System.out.println(tsk1.get(Tsk.CONSTRAINT_TYPE).toString());
18}
Subscribe to Aspose Product Updates

Get monthly newsletters & offers directly delivered to your mailbox.