작업 제약 조건 처리
작업 제약은 Microsoft Project Project의 일정을 정의하고 작업을 시작하거나 완료 해야하는시기를 정의하는 데 사용됩니다. 제약 조건은 융통성이있을 수 있습니다. 가능한 빨리 또는 가능한 빨리 또는 융통성이 없거나 융통성이 없습니다. 융통성없는 제약은 특정 날짜와 관련이 있습니다.
제약 조건으로 작업
제한도 및 제약 타자 속성은 제약 조건을 처리하기 위해 정적 클래스 TSK 클래스에 의해 노출됩니다.
- 제한가 DateTime 데이터 유형을 수락하고 반환합니다.
- 제한자 유형은 제한자 유형 열거의 값 중 하나를 받아들이고 반환합니다.
Microsoft Project에서 제약 조건 설정
Microsoft Project에서 제약을 설정하려면 :
- 보기 메뉴에서 더 많은보기를 선택한 다음 작업 입력 양식을 선택하십시오.
- 작업 입력 양식에서 작업을 두 번 클릭하십시오.
- 고급 탭을 선택하십시오.
- 제약 조건 유형 목록에서 옵션을 선택하여 제약 조건을 설정하고 제약 조건 날짜 목록의 날짜를 설정하십시오.
Aspose.Tasks로 제약 조건 설정
제약 조건 날짜는 제약 유형이 가능한 한 빨리 또는 가능한 한 늦게 인 경우 NA입니다. 날짜 값의 경우 na와 동일한 날짜 값, Aspose.Tasks 는 평가 버전에서 “1/1/2000"값을 사용하고 라이센스가 부여 된 제품의 DateTime.minValue를 사용합니다. 아래의 경우 소스 프로젝트 파일을 입력으로 가져 와서 각 경우 각각의 다양한 작업에 다른 유형의 제약 조건을 적용합니다. 다음 코드 샘플은 다른 제약 유형의 적용을 보여줍니다.
아래 코드 샘플은 세트가 시작되도록 설정된 제약 조건 유형을 설정합니다.
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}