캘린더 업데이트 및 제거
Contents
[
Hide
Show
]달력 교체
캘린더는 리소스 사용 가능한지 및 작업이 예정된시기를 확인하는 데 사용됩니다. 달력에는 여러 가지 유형이 있습니다. 이 기사는 기본 캘린더, 즉 프로젝트 및 작업에 사용되는 캘린더를 다른 일정으로 바꾸는 방법을 살펴 봅니다.
기본 달력은 다른 형태로 제공됩니다.
- 표준 : 기본 캘린더에는 월요일부터 금요일까지 일주일이 있으며 하루는 08:00에서 17:00입니다.
- 24 시간 : 24 시간 내내 작동하거나 24 시간 내내 실행되는 자원에 사용됩니다.
- 야간 교대 : 표준 달력과 마찬가지로 야간 시프트 캘린더에는 월요일부터 토요일 아침 근무 주와 23:00에서 08:00의 날이 있습니다.
달력 교체 새 캘린더 교체
모든 캘린더 목록은 프로젝트 클래스를 사용하여 캘린더 컬렉션으로 검색 할 수 있습니다. 그런 다음 캘린더 컬렉션을 사용하여 다음 코드 샘플과 같이 새 캘린더를 제거하거나 추가 할 수 있습니다.
아래에 주어진 코드 예제는 기존 캘린더를 새로운 표준 캘린더로 바꾸는 방법을 보여줍니다.
1// Create project
2System::SharedPtr<Project> project = System::MakeObject<Project>(dataDir + u"Project5.mpp");
3
4// Access project calendars
5System::SharedPtr<CalendarCollection> calColl = project->get_Calendars();
6calColl->Remove(calColl->GetByName(u"TestCalendar"));
7
8// Add new calendar
9System::SharedPtr<Calendar> newCalendar = calColl->Add(u"TestCalendar");
10project->Save(dataDir + u"ReplaceCalendar_out.mpp", Aspose::Tasks::Saving::SaveFileFormat::MPP);
Writing Updated Calendar Data to MPP
With Aspose.Tasks for C++, you can update calendar data in a Microsoft Project MPP file and save it back.
The following code shows how to update the calendar data of a project by adding a new calendar and saving it back to the original MPP file. The steps involved in this activity are:
- Read the source MPP file.
- Add the calendar data to the project.
- Save the updated project data back to the MPP file.
1System::String resultFile = u"result_WriteUpdatedCalendarDataToMPP_out.mpp";
2System::String newFile = u"project_update_test.mpp";
3System::String dataDir = Examples::CPP::RunExamples::GetDataDir(System::Reflection::MethodBase::GetCurrentMethod(ASPOSE_CURRENT_FUNCTION)->get_DeclaringType().get_FullName());
4
5try
6{
7 // Create project instance and access calendar
8 System::SharedPtr<Project> project = System::MakeObject<Project>(dataDir + newFile);
9 System::SharedPtr<Calendar> cal = project->get_Calendars()->GetByUid(3);
10
11 // Update the calendar information
12 Calendar::MakeStandardCalendar(cal);
13 cal->set_Name(u"Test calendar");
14 System::SharedPtr<CalendarException> exc = System::MakeObject<CalendarException>();
15 exc->set_FromDate(System::DateTime::get_Now());
16 exc->set_ToDate(System::DateTime::get_Now().AddDays(2));
17 exc->set_DayWorking(true);
18
19 System::SharedPtr<WorkingTime> wt1 = System::MakeObject<WorkingTime>();
20 wt1->set_FromTime(System::DateTime(10, 1, 1, 9, 0, 0));
21 wt1->set_ToTime(System::DateTime(10, 1, 1, 13, 0, 0));
22
23 System::SharedPtr<WorkingTime> wt2 = System::MakeObject<WorkingTime>();
24 wt2->set_FromTime(System::DateTime(10, 1, 1, 14, 0, 0));
25 wt2->set_ToTime(System::DateTime(10, 1, 1, 19, 0, 0));
26
27 System::SharedPtr<WorkingTime> wt3 = System::MakeObject<WorkingTime>();
28 wt3->set_FromTime(System::DateTime(10, 1, 1, 20, 0, 0));
29 wt3->set_ToTime(System::DateTime(10, 1, 1, 21, 0, 0));
30
31 exc->get_WorkingTimes()->Add(wt1);
32 exc->get_WorkingTimes()->Add(wt2);
33 exc->get_WorkingTimes()->Add(wt3);
34 cal->get_Exceptions()->Add(exc);
35
36 System::SharedPtr<CalendarException> exc2 = System::MakeObject<CalendarException>();
37 exc2->set_FromDate(System::DateTime::get_Now().AddDays(7));
38 exc2->set_ToDate(exc2->get_FromDate());
39 exc2->set_DayWorking(false);
40 cal->get_Exceptions()->Add(exc2);
41
42 project->Set<System::SharedPtr<Calendar>>(Prj::Calendar(), cal);
43
44 // Save project
45 project->Save(dataDir + resultFile, Aspose::Tasks::Saving::SaveFileFormat::MPP);
46}
47catch (System::Exception& ex)
48{
49 System::Console::WriteLine(ex->get_Message() + u"\nThis example will only work if you apply a valid Aspose License. You can purchase full license or get 30 day temporary license from http:// Www.aspose.com/purchase/default.aspx.");
50}
51