캘린더 생성
달력 만들기
캘린더 및 기타 정보는 Microsoft Project에서 프로젝트 일정을 구축하는 데 사용됩니다. C ++의 경우 Aspose.Tasks 를 사용하면 프로젝트에 달력을 추가하는 것이 쉽습니다. 캘린더 클래스 생성자를 사용하면 캘린더에 ID 또는 캘린더 이름을 할당하거나 기본 생성자를 사용할 수 있습니다. 옵션은 아래에 설명되어 있습니다.
Aspose.Tasks에서 캘린더를 만드는 세 가지 방법이 있습니다. 캘린더 클래스는 다음 세 가지 생성자를 노출시킵니다.
- Calendar () - 기본 생성자.
- 캘린더 (int id) - ID로 캘린더를 만듭니다.
- 캘린더 (문자열 이름) - 이름의 캘린더를 만듭니다.
다음 코드는 각 생성자를 사용하는 세 가지 캘린더를 만듭니다. Microsoft Project에서 출력 파일을 열고 프로젝트 메뉴에서 프로젝트 정보를 선택하여 캘린더에 액세스하십시오.
달력 정보를 보여주는 프로젝트 정보
1// Create a project instance
2System::SharedPtr<Project> project = System::MakeObject<Project>();
3
4// New calendar can be added to a project's calendar collection using the collection's Add method.
5System::SharedPtr<Aspose::Tasks::Calendar> cal1 = project->get_Calendars()->Add(u"New Info");
6System::SharedPtr<Aspose::Tasks::Calendar> cal2 = project->get_Calendars()->Add(u"no name");
7System::SharedPtr<Aspose::Tasks::Calendar> cal3 = project->get_Calendars()->Add(u"cal3");
8
9// Save the Project
10System::String dataDir = Examples::CPP::RunExamples::GetDataDir(System::Reflection::MethodBase::GetCurrentMethod(ASPOSE_CURRENT_FUNCTION)->get_DeclaringType().get_FullName());
11project->Save(dataDir + u"CreatingCalendar_out.Xml", Aspose::Tasks::Saving::SaveFileFormat::XML);
Defining Weekdays for Calendar
Microsoft Project keeps track of which days are considered weekdays in a calendar so that it can calculate project end dates and so on. Aspose.Tasks for C++ API allows developers to define weekdays for a calendar associated with a project.
The Days collection exposed by the Calendar class is used to define the weekdays for a calendar. The Days collection represents an array list of WeekDay objects.
The CreateDefaultWorkingDay method exposed by the WeekDay class can further be implemented to define the default day timings, while the FromTime and ToTime properties exposed by the WorkingTime class is used to define the specific timing for a day. FromTime and ToTime support the DateTime datatype.
The code samples below set weekdays for a project. After running the code, open the output file in Microsoft Project and, on the Tools menu, select Change Work Timing to establish that the changes have been applied.
Defining weekdays in Microsoft Project
The code sample given below defines Monday through Thursday as weekdays with default timings, whereas Friday as a weekday with special timings.
1// This example shows how Aspose.Tasks API can be used to define a new Calendar, add week days to it and define working times for days
2// Create a project instance
3System::SharedPtr<Project> project = System::MakeObject<Project>();
4
5// Define Calendar
6System::SharedPtr<Aspose::Tasks::Calendar> cal = project->get_Calendars()->Add(u"Calendar1");
7
8// Add working days monday through thursday with default timings
9cal->get_WeekDays()->Add(WeekDay::CreateDefaultWorkingDay(Aspose::Tasks::DayType::Monday));
10cal->get_WeekDays()->Add(WeekDay::CreateDefaultWorkingDay(Aspose::Tasks::DayType::Tuesday));
11cal->get_WeekDays()->Add(WeekDay::CreateDefaultWorkingDay(Aspose::Tasks::DayType::Wednesday));
12cal->get_WeekDays()->Add(WeekDay::CreateDefaultWorkingDay(Aspose::Tasks::DayType::Thursday));
13cal->get_WeekDays()->Add(System::MakeObject<WeekDay>(Aspose::Tasks::DayType::Saturday));
14cal->get_WeekDays()->Add(System::MakeObject<WeekDay>(Aspose::Tasks::DayType::Sunday));
15
16// Set friday as short working day
17System::SharedPtr<WeekDay> myWeekDay = System::MakeObject<WeekDay>(Aspose::Tasks::DayType::Friday);
18
19// Sets working time. Only time part of DateTime is important
20System::SharedPtr<WorkingTime> wt1 = System::MakeObject<WorkingTime>();
21wt1->set_FromTime(System::DateTime(1, 1, 1, 9, 0, 0, 0));
22wt1->set_ToTime(System::DateTime(1, 1, 1, 12, 0, 0, 0));
23System::SharedPtr<WorkingTime> wt2 = System::MakeObject<WorkingTime>();
24wt2->set_FromTime(System::DateTime(1, 1, 1, 13, 0, 0, 0));
25wt2->set_ToTime(System::DateTime(1, 1, 1, 16, 0, 0, 0));
26myWeekDay->get_WorkingTimes()->Add(wt1);
27myWeekDay->get_WorkingTimes()->Add(wt2);
28myWeekDay->set_DayWorking(true);
29cal->get_WeekDays()->Add(myWeekDay);
30
31// Save the Project
32System::String dataDir = Examples::CPP::RunExamples::GetDataDir(System::Reflection::MethodBase::GetCurrentMethod(ASPOSE_CURRENT_FUNCTION)->get_DeclaringType().get_FullName());
33project->Save(u"Project_DefineCalendarWeekdays_out.xml", Aspose::Tasks::Saving::SaveFileFormat::XML);
Making a Standard Calendar
A standard calendar provides the most common work days, work hours and holidays. By default, a standard calendar is added whenever a project is created using Microsoft Project. Aspose.Tasks for C++ API has features for defining a standard calendar for a project.
The Calendar class exposes the following two static overloaded methods for creating a standard calendar:
- MakeStandardCalendar() – Creates a new standard calendar.
- MakeStandardCalendar(Calendar cal) – Makes a calendar as standard.
In Microsoft Project, open the file output by the code below and, on the Tools menu, select Change Working Times Information, to see the standard calendar.
The Change Working Times Information dialogue shows the standard calendar used by the project
The following lines of code create a standard calendar using both methods.
1// Create a project instance
2System::SharedPtr<Project> project = System::MakeObject<Project>();
3
4// Define Calendar and make it standard
5System::SharedPtr<Aspose::Tasks::Calendar> cal1 = project->get_Calendars()->Add(u"My Cal");
6Aspose::Tasks::Calendar::MakeStandardCalendar(cal1);
7
8// Save the Project
9System::String dataDir = Examples::CPP::RunExamples::GetDataDir(System::Reflection::MethodBase::GetCurrentMethod(ASPOSE_CURRENT_FUNCTION)->get_DeclaringType().get_FullName());
10project->Save(dataDir + u"Project_MakeStandardCalendar_out.xml", Aspose::Tasks::Saving::SaveFileFormat::XML);