タスクの制約の処理
タスクの制約は、Microsoft Project Projectのスケジュールを定義し、タスクをいつ開始または終了するかを定義するために使用されます。制約は柔軟になります - できるだけ早く、またはできるだけ早く開始または終了します - または柔軟性がありません。柔軟性のない制約は、特定の日付と結びついています。
制約の操作
constraintdateおよび constraintTypeプロパティは、制約を処理するための静的クラス TSKクラスによって公開されます。
- ConstraintDateは、DateTimeデータ型を受け入れて返します。
- ConstraintTypeは、ConstraintType Enumerationの値の1つを受け入れて返します。
Microsoftプロジェクトの制約の設定
Microsoftプロジェクトで制約を設定するには:
- ビューメニューで、その他のビューを選択し、タスクエントリフォームを選択します。
- タスクエントリフォームのタスクをダブルクリックします。
- [詳細]タブを選択します。
- 制約タイプリストからオプションを選択し、制約日付リストの日付を選択して制約を設定します。
Aspose.Tasksで制約を設定
制約タイプができるだけ早くまたはできるだけ遅くの場合、制約日はNAです。 Naに等しい日付値の場合、Aspose.Tasksは評価バージョンで値「1/1/2000」、およびライセンス製品のMinValueの値「1/1/2000」を使用します。以下の場合、ソースプロジェクトファイルを入力として使用し、それぞれの場合にさまざまなタスクにさまざまなタイプの制約を適用します。次のコードサンプルは、さまざまな制約タイプの適用を示しています。
以下のコードサンプルは、制約タイプを設定して設定されています。
1Project project = new Project("New Project.mpp");
2
3// Set constraint Start No Earlier Than on task with Id 1
4Task summary = project.RootTask.Children.GetById(1);
5summary.Set(Tsk.ConstraintType, ConstraintType.StartNoEarlierThan);
6summary.Set(Tsk.ConstraintDate, new DateTime(2016, 12, 1, 9, 0, 0));
7
8SaveOptions o = new PdfSaveOptions();
9o.StartDate = project.Get(Prj.StartDate);
10o.Timescale = Timescale.ThirdsOfMonths;
11project.Save("StartNoEarlierThan_out.pdf", o);
The code samples below set the constraint type set to Finish No Earlier Than.
1// Set constraint Finish No Earlier Than on task with Id 2
2Task first = project.RootTask.Children.GetById(2);
3first.Set(Tsk.ConstraintType, ConstraintType.FinishNoEarlierThan);
4first.Set(Tsk.ConstraintDate, new DateTime(2016, 12, 1, 18, 0, 0));
5SaveOptions options = new PdfSaveOptions();
6options.StartDate = project.Get(Prj.StartDate);
7options.Timescale = Timescale.ThirdsOfMonths;
8project.Save("FinishNoEarlierThan_out.pdf", options);
The code samples below set the constraint type set to Must Start On.
1// Set constraint Must Start On for task with Id 5
2Task roof = project.RootTask.Children.GetById(5);
3roof.Set(Tsk.ConstraintType, ConstraintType.MustStartOn);
4roof.Set(Tsk.ConstraintDate, new DateTime(2017, 1, 1, 9, 0, 0));
5
6SaveOptions options = new PdfSaveOptions();
7options.StartDate = project.Get(Prj.StartDate);
8options.Timescale = Timescale.ThirdsOfMonths;
9project.Save("MustStartOn_out.pdf", options);
The code samples below set the constraint type set to As Late As Possible.
1// Set constraint As Late As Possible for task with Id 11
2Task wallBoard = project.RootTask.Children.GetById(11);
3wallBoard.Set(Tsk.ConstraintType, ConstraintType.AsLateAsPossible);
4
5SaveOptions options = new PdfSaveOptions();
6options.StartDate = project.Get(Prj.StartDate);
7options.Timescale = Timescale.ThirdsOfMonths;
8project.Save("AsLateAsPossible_out.pdf", options);
The code sample below shows the constraint type set to Must Finish On.
1// Set constraint Must Finish On for task with Id 15
2Task task = project.RootTask.Children.GetById(15);
3task.Set(Tsk.ConstraintType, ConstraintType.MustFinishOn);
4task.Set(Tsk.ConstraintDate, new DateTime(2017, 3, 1, 18, 0, 0));
5
6SaveOptions options = new PdfSaveOptions();
7options.StartDate = project.Get(Prj.StartDate);
8options.Timescale = Timescale.ThirdsOfMonths;
9project.Save("MustFinishOn_out.pdf", options);
Getting Constraints
This code sample displays any constraints found when traversing the tasks in the project to a command window.
1Project project = new Project("New Project.mpp");
2
3// Create a ChildTasksCollector instance
4ChildTasksCollector collector = new ChildTasksCollector();
5
6// Collect all the tasks from RootTask using TaskUtils
7TaskUtils.Apply(project.RootTask, collector, 0);
8
9// Parse through all the collected tasks
10foreach (Task task in collector.Tasks)
11{
12 if (task.Get(Tsk.ConstraintDate).ToShortDateString() == "1/1/2000")
13 Console.WriteLine("NA");
14 else
15 Console.WriteLine(task.Get(Tsk.ConstraintDate).ToShortDateString());
16
17 Console.WriteLine(task.Get(Tsk.ConstraintType).ToString());
18}