Ajout et supprimer des exceptions de calendrier
Contents
[
Hide
Show
]Travailler avec des exceptions du calendrier
Aspose.Tasks pour l’API C ++ vous aide à gérer les exceptions de calendrier. La propriété Exceptions exposée par la classe de calendrier qui représente une liste d’objets Calendarexception et est utilisée pour ajouter ou supprimer les exceptions du calendrier.
L’exemple de code suivant montre comment ajouter, supprimer et afficher des exceptions.
1System::String dataDir = RunExamples::GetDataDir(System::Reflection::MethodBase::GetCurrentMethod(ASPOSE_CURRENT_FUNCTION)->get_DeclaringType().get_FullName());
2
3{
4 System::SharedPtr<System::IO::FileStream> fs = System::MakeObject<System::IO::FileStream>(dataDir + u"project_test.mpp", System::IO::FileMode::Open);
5 // Clearing resources under 'using' statement
6 System::Details::DisposeGuard<1> __dispose_guard_0({ fs});
7 // ------------------------------------------
8
9 try
10 {
11 // Create project instance
12 System::SharedPtr<Project> prj = System::MakeObject<Project>(fs);
13
14 // Remove an exception
15 System::SharedPtr<Aspose::Tasks::Calendar> cal = prj->get_Calendars()->ToList()->idx_get(0);
16 if (cal->get_Exceptions()->get_Count() > 1)
17 {
18 System::SharedPtr<CalendarException> exc = cal->get_Exceptions()->ToList()->idx_get(0);
19 cal->get_Exceptions()->Remove(exc);
20 }
21
22 // Add an exception
23 System::SharedPtr<CalendarException> calExc = System::MakeObject<CalendarException>();
24 calExc->set_FromDate(System::DateTime(2009, 1, 1));
25 calExc->set_ToDate(System::DateTime(2009, 1, 3));
26 cal->get_Exceptions()->Add(calExc);
27
28 // Display exceptions
29
30 {
31 auto calExc1_enumerator = (cal->get_Exceptions())->GetEnumerator();
32 decltype(calExc1_enumerator->get_Current()) calExc1;
33 while (calExc1_enumerator->MoveNext() && (calExc1 = calExc1_enumerator->get_Current(), true))
34 {
35 System::Console::WriteLine(System::String(u"From") + calExc1->get_FromDate().ToShortDateString());
36 System::Console::WriteLine(System::String(u"To") + calExc1->get_ToDate().ToShortDateString());
37 }
38 }
39 }
40 catch(...)
41 {
42 __dispose_guard_0.SetCurrentException(std::current_exception());
43 }
44}