XTPCalendarEvent.cpp
上传用户:szled88
上传日期:2015-04-09
资源大小:43957k
文件大小:25k
源码类别:

对话框与窗口

开发平台:

Visual C++

  1. // XTPCalendarEvent.cpp: implementation of the CXTPCalendarEvent class.
  2. //
  3. // This file is a part of the XTREME CALENDAR MFC class library.
  4. // (c)1998-2008 Codejock Software, All Rights Reserved.
  5. //
  6. // THIS SOURCE FILE IS THE PROPERTY OF CODEJOCK SOFTWARE AND IS NOT TO BE
  7. // RE-DISTRIBUTED BY ANY MEANS WHATSOEVER WITHOUT THE EXPRESSED WRITTEN
  8. // CONSENT OF CODEJOCK SOFTWARE.
  9. //
  10. // THIS SOURCE CODE CAN ONLY BE USED UNDER THE TERMS AND CONDITIONS OUTLINED
  11. // IN THE XTREME TOOLKIT PRO LICENSE AGREEMENT. CODEJOCK SOFTWARE GRANTS TO
  12. // YOU (ONE SOFTWARE DEVELOPER) THE LIMITED RIGHT TO USE THIS SOFTWARE ON A
  13. // SINGLE COMPUTER.
  14. //
  15. // CONTACT INFORMATION:
  16. // support@codejock.com
  17. // http://www.codejock.com
  18. //
  19. /////////////////////////////////////////////////////////////////////////////
  20. #include "stdafx.h"
  21. #include "Common/XTPPropExchange.h"
  22. #include "XTPCalendarEvent.h"
  23. #include "XTPCalendarRecurrencePattern.h"
  24. #include "XTPCalendarUtils.h"
  25. #include "XTPCalendarData.h"
  26. #include "XTPCalendarEventLabel.h"
  27. #include "XTPCalendarCustomProperties.h"
  28. #ifdef _DEBUG
  29. #define new DEBUG_NEW
  30. #undef THIS_FILE
  31. static char THIS_FILE[] = __FILE__;
  32. #endif
  33. static LPCTSTR cszEventProp_EventID = _T("EventID");
  34. static LPCTSTR cszEventProp_ScheduleID= _T("ScheduleID");
  35. static LPCTSTR cszEventProp_StartTime = _T("StartTime");
  36. static LPCTSTR cszEventProp_EndTime = _T("EndTime");
  37. static LPCTSTR cszEventProp_Subject = _T("Subject");
  38. static LPCTSTR cszEventProp_Location = _T("Location");
  39. static LPCTSTR cszEventProp_Body                    = _T("Body");
  40. // OLD. used to read old data files
  41. static LPCTSTR cszEventPropOld_Description          = _T("Description");
  42. static LPCTSTR cszEventProp_AllDayEvent = _T("AllDayEvent");
  43. static LPCTSTR cszEventProp_LabelID = _T("LabelID");
  44. static LPCTSTR cszEventProp_BusyStatus = _T("BusyStatus");
  45. static LPCTSTR cszEventProp_Importance = _T("Importance");
  46. static LPCTSTR cszEventProp_ReminderMinutesBeforeStart = _T("ReminderMinutesBeforeStart");
  47. static LPCTSTR cszEventProp_ReminderSoundFile = _T("ReminderSoundFile");
  48. static LPCTSTR cszEventProp_CreationTime = _T("CreationTime");
  49. static LPCTSTR cszEventProp_LastModificationTime = _T("LastModificationTime");
  50. static LPCTSTR cszEventProp_RecurrenceState = _T("RecurrenceState");
  51. static LPCTSTR cszEventProp_IsMeeting = _T("IsMeeting");
  52. static LPCTSTR cszEventProp_IsPrivate = _T("IsPrivate");
  53. static LPCTSTR cszEventProp_IsReminder              = _T("IsReminder");
  54. //## Recurrence Event properties
  55. static LPCTSTR cszEventProp_RecurrencePatternID = _T("RecurrencePatternID");
  56. //## Recurrence Event Exception properties
  57. static LPCTSTR cszEventProp_RExceptionDeleted = _T("RExceptionDeleted");
  58. static LPCTSTR cszEventProp_RException_StartTimeOrig= _T("RException_StartTimeOrig");
  59. static LPCTSTR cszEventProp_RException_EndTimeOrig = _T("RException_EndTimeOrig");
  60. /////////////////////////////////////////////////////////////////////////////
  61. #define XTP_EVENT_PROP_SET_DATA_VER_1 1
  62. #define XTP_EVENT_PROP_SET_DATA_VER_2 2
  63. #define XTP_EVENT_PROP_SET_DATA_VER 3
  64. IMPLEMENT_DYNAMIC(CXTPCalendarEvent, CCmdTarget)
  65. /////////////////////////////////////////////////////////////////////////////
  66. /////////////////////////////////////////////////////////////////////////////
  67. CXTPCalendarEvent::CXTPCalendarEvent(CXTPCalendarData* pDataProvider)
  68. {
  69. ASSERT(pDataProvider);
  70. m_pDataProvider = pDataProvider;
  71. if (m_pDataProvider)
  72. {
  73. m_pDataProvider->InternalAddRef();
  74. }
  75. m_dwEventID = XTP_CALENDAR_UNKNOWN_EVENT_ID;
  76. m_nLabelID = XTP_CALENDAR_DEFAULT_LABEL_ID;
  77. m_uScheduleID = XTP_CALENDAR_UNKNOWN_SCHEDULE_ID;
  78. m_nBusyStatus = xtpCalendarBusyStatusFree;
  79. m_nImportance = xtpCalendarImportanceNormal;
  80. m_dwRecurrencePatternID = XTP_CALENDAR_UNKNOWN_RECURRENCE_PATTERN_ID;
  81. m_nRecurrenceState = xtpCalendarRecurrenceNotRecurring;
  82. m_bRExceptionDeleted = FALSE;
  83. m_bAllDayEvent = FALSE;
  84. m_dtStartTime = (DATE)0; //.SetStatus(COleDateTime::null);
  85. m_dtEndTime = (DATE)0; //.SetStatus(COleDateTime::null);
  86. m_dtCreationTime = m_dtLastModificationTime = CXTPCalendarUtils::GetCurrentTime();
  87. m_bReminder = FALSE;
  88. m_nReminderMinutesBeforeStart = XTP_CALENDAR_DEFAULT_REMINDER_MINUTES;
  89. m_dtRException_StartTimeOrig = (DATE)0; // .SetStatus(COleDateTime::null);
  90. m_dtRException_EndTimeOrig = (DATE)0; // .SetStatus(COleDateTime::null);
  91. m_bMeeting = FALSE;
  92. m_bPrivate = FALSE;
  93. m_dwRecurrencePatternID_ToUse = XTP_CALENDAR_UNKNOWN_RECURRENCE_PATTERN_ID;
  94. m_pCustomProperties = new CXTPCalendarCustomProperties;
  95. m_pCustomIconsIDs = new CXTPCalendarCustomIconIDs;
  96. m_pEventCategoryIDs = new CXTPCalendarEventCategoryIDs;
  97. }
  98. CXTPCalendarEvent::~CXTPCalendarEvent()
  99. {
  100. CMDTARGET_RELEASE(m_pDataProvider);
  101. CMDTARGET_RELEASE(m_pCustomProperties);
  102. CMDTARGET_RELEASE(m_pCustomIconsIDs);
  103. CMDTARGET_RELEASE(m_pEventCategoryIDs);
  104. }
  105. CXTPCalendarEventLabel* CXTPCalendarEvent::GetLabel() const
  106. {
  107. CXTPCalendarEventLabel* pResultLab = NULL;
  108. if (m_pDataProvider && m_pDataProvider->GetLabelList())
  109. {
  110. pResultLab = m_pDataProvider->GetLabelList()->Find(m_nLabelID);
  111. }
  112. return pResultLab;
  113. }
  114. void CXTPCalendarEvent::SetStartTime(COleDateTime dtStart)
  115. {
  116. if (m_nRecurrenceState == xtpCalendarRecurrenceOccurrence ||
  117. m_nRecurrenceState == xtpCalendarRecurrenceMaster)
  118. {
  119. ASSERT(FALSE);
  120. return;
  121. }
  122. m_dtStartTime = dtStart;
  123. if (m_dtStartTime.GetStatus() == COleDateTime::valid &&
  124. m_dtEndTime.GetStatus() == COleDateTime::valid &&
  125. (m_dtStartTime > m_dtEndTime ||
  126.  CXTPCalendarUtils::IsEqual(m_dtEndTime, m_dtStartTime)))
  127. {
  128. m_dtEndTime = m_dtStartTime;
  129. }
  130. }
  131. void CXTPCalendarEvent::SetEndTime(COleDateTime dtEnd)
  132. {
  133. if (m_nRecurrenceState == xtpCalendarRecurrenceOccurrence ||
  134. m_nRecurrenceState == xtpCalendarRecurrenceMaster)
  135. {
  136. ASSERT(FALSE);
  137. return;
  138. }
  139. m_dtEndTime = dtEnd;
  140. if (m_dtStartTime.GetStatus() == COleDateTime::valid &&
  141. m_dtEndTime.GetStatus() == COleDateTime::valid &&
  142. (m_dtEndTime < m_dtStartTime ||
  143.  CXTPCalendarUtils::IsEqual(m_dtEndTime, m_dtStartTime)))
  144. {
  145. m_dtStartTime = m_dtEndTime;
  146. }
  147. }
  148. void CXTPCalendarEvent::SetDuration(COleDateTimeSpan spDuration, BOOL bKeepStart)
  149. {
  150. if (bKeepStart)
  151. {
  152. SetEndTime(m_dtStartTime + spDuration);
  153. }
  154. else
  155. {
  156. SetStartTime(m_dtEndTime - spDuration);
  157. }
  158. }
  159. void CXTPCalendarEvent::MoveEvent(COleDateTime dtNewStartTime)
  160. {
  161. COleDateTimeSpan spDuration = m_dtEndTime - m_dtStartTime;
  162. SetStartTime(dtNewStartTime);
  163. SetEndTime(dtNewStartTime + spDuration);
  164. }
  165. int CXTPCalendarEvent::GetDurationMinutes() const
  166. {
  167. return CXTPCalendarUtils::GetDurationMinutes(m_dtStartTime, m_dtEndTime, m_bAllDayEvent);
  168. }
  169. COleDateTimeSpan CXTPCalendarEvent::GetDuration() const
  170. {
  171. COleDateTimeSpan spDuration;
  172. if (m_bAllDayEvent)
  173. {
  174. spDuration = CXTPCalendarUtils::ResetTime(m_dtEndTime) -
  175.  CXTPCalendarUtils::ResetTime(m_dtStartTime);
  176. }
  177. else
  178. {
  179. spDuration = m_dtEndTime - m_dtStartTime;
  180. }
  181. return spDuration;
  182. }
  183. CXTPCalendarRecurrencePatternPtr CXTPCalendarEvent::GetRecurrencePattern() const
  184. {
  185. if (m_ptrRPattern)
  186. {
  187. ASSERT(m_nRecurrenceState == xtpCalendarRecurrenceMaster);
  188. CXTPCalendarRecurrencePatternPtr ptrPattern = m_ptrRPattern->ClonePattern();
  189. return ptrPattern;
  190. }
  191. if (!m_pDataProvider)
  192. {
  193. ASSERT(FALSE);
  194. return NULL;
  195. }
  196. CXTPCalendarRecurrencePatternPtr ptrPattern = m_pDataProvider->GetRecurrencePattern(m_dwRecurrencePatternID);
  197. return ptrPattern;
  198. }
  199. BOOL CXTPCalendarEvent::SetRecurrenceState_Master(CXTPCalendarRecurrencePattern* pPattern)
  200. {
  201. if (!pPattern || m_nRecurrenceState != xtpCalendarRecurrenceNotRecurring)
  202. {
  203. ASSERT(FALSE);
  204. return FALSE;
  205. }
  206. ASSERT(!m_ptrRPattern);
  207. m_nRecurrenceState = xtpCalendarRecurrenceMaster;
  208. m_ptrRPattern = pPattern;
  209. m_ptrRPattern->InternalAddRef();
  210. m_dwRecurrencePatternID = m_ptrRPattern->GetPatternID();
  211. m_ptrRPattern->SetMasterEventID(m_dwEventID);
  212. BOOL bRes = CalcStartEndDatesFromPattern();
  213. ASSERT(bRes);
  214. return bRes;
  215. }
  216. BOOL CXTPCalendarEvent::SetRecurrenceState_ExceptionOccurrence(XTPCalendarEventRecurrenceState nState, DWORD dwNewPatternID)
  217. {
  218. ASSERT(nState == xtpCalendarRecurrenceOccurrence || nState == xtpCalendarRecurrenceException);
  219. if (m_ptrRPattern || m_nRecurrenceState == xtpCalendarRecurrenceMaster)
  220. {
  221. ASSERT(FALSE); //set new recur. state to master event. strange! why ???
  222. return FALSE;
  223. }
  224. // update original Start/End times for exception event
  225. if (nState == xtpCalendarRecurrenceException)
  226. {
  227. // You should change state to exception only for occurrence or new event (event copy).
  228. // !!! Otherwise this may not work correctly !!!
  229. //ASSERT(m_nRecurrenceState == xtpCalendarRecurrenceOccurrence);
  230. ASSERT(m_nRecurrenceState == xtpCalendarRecurrenceNotRecurring ||
  231.    m_nRecurrenceState == xtpCalendarRecurrenceOccurrence ||
  232.    m_nRecurrenceState == xtpCalendarRecurrenceException);
  233. COleDateTime dtTmpOrig = GetStartTime();
  234. SetRException_StartTimeOrig(dtTmpOrig);
  235. dtTmpOrig = GetEndTime();
  236. SetRException_EndTimeOrig(dtTmpOrig);
  237. }
  238. m_nRecurrenceState = nState;
  239. if (dwNewPatternID != XTP_CALENDAR_UNKNOWN_RECURRENCE_PATTERN_ID)
  240. {
  241. m_dwRecurrencePatternID = dwNewPatternID;
  242. }
  243. //ASSERT(m_dwRecurrencePatternID != XTP_CALENDAR_UNKNOWN_RECURRENCE_PATTERN_ID);
  244. return TRUE;
  245. }
  246. BOOL CXTPCalendarEvent::SetRecurrenceState_NotRecurring()
  247. {
  248. if (m_ptrRPattern)
  249. {
  250. m_ptrRPattern->SetMasterEventID(XTP_CALENDAR_UNKNOWN_EVENT_ID);
  251. }
  252. m_dwRecurrencePatternID_ToUse = m_dwRecurrencePatternID;
  253. m_nRecurrenceState = xtpCalendarRecurrenceNotRecurring;
  254. m_ptrRPattern = NULL;
  255. m_dwRecurrencePatternID = XTP_CALENDAR_UNKNOWN_RECURRENCE_PATTERN_ID;
  256. return TRUE;
  257. }
  258. BOOL CXTPCalendarEvent::CalcStartEndDatesFromPattern()
  259. {
  260. if (m_nRecurrenceState != xtpCalendarRecurrenceMaster || !m_ptrRPattern)
  261. {
  262. ASSERT(FALSE);
  263. return FALSE;
  264. }
  265. COleDateTime dtS = m_ptrRPattern->GetPatternStartDate();
  266. COleDateTime dtE(9999, 1, 1, 0, 0, 0);
  267. if (m_ptrRPattern->GetUseEndMethod() == xtpCalendarPatternEndDate ||
  268. m_ptrRPattern->GetUseEndMethod() == xtpCalendarPatternEndAfterOccurrences &&
  269. m_ptrRPattern->GetEndAfterOccurrences() < 4000)
  270. {
  271. CXTPCalendarDatesArray arDates;
  272. m_ptrRPattern->GetOccurrencesDates(arDates, dtS, dtE);
  273. int nCount = (int)arDates.GetSize();
  274. if (nCount)
  275. {
  276. dtS = arDates[0];
  277. dtE = arDates[nCount-1];
  278. //SetStartTime(m_ptrRPattern->GetStartOccurrenceTime(dtS));
  279. //SetEndTime(m_ptrRPattern->GetEndOccurrenceTime(dtS));
  280. m_dtStartTime = m_ptrRPattern->GetStartOccurrenceTime(dtS);
  281. m_dtEndTime = m_ptrRPattern->GetEndOccurrenceTime(dtS);
  282. ASSERT(GetEventPeriodDays() > 0);
  283. int nDays = max(1, GetEventPeriodDays());
  284. dtE += COleDateTimeSpan(nDays-1, 0, 0, 0);
  285. }
  286. else
  287. {
  288. dtE = dtS;
  289. }
  290. }
  291. //SetStartTime(dtS);
  292. //SetEndTime(dtE);
  293. m_dtStartTime = dtS;
  294. m_dtEndTime = dtE;
  295. UpdateStartEndDatesFromPatternExceptions();
  296. return TRUE;
  297. }
  298. BOOL CXTPCalendarEvent::UpdateStartEndDatesFromPatternExceptions()
  299. {
  300. COleDateTime dtS = GetStartTime();
  301. COleDateTime dtE = GetEndTime();
  302. BOOL bRes = FALSE;
  303. //---------------------------------------------------------------------------
  304. CXTPCalendarEventsPtr ptrExceptions = m_ptrRPattern->GetExceptions();
  305. int nCount = ptrExceptions ? ptrExceptions->GetCount() : 0;
  306. for (int i = 0; i < nCount; i++)
  307. {
  308. CXTPCalendarEvent* pExcept = ptrExceptions->GetAt(i);
  309. if (pExcept->GetStartTime() < dtS)
  310. {
  311. dtS = pExcept->GetStartTime();
  312. bRes = TRUE;
  313. }
  314. if (pExcept->GetEndTime() > dtE)
  315. {
  316. dtE = pExcept->GetEndTime();
  317. bRes = TRUE;
  318. }
  319. }
  320. //---------------------------------------------------------------------------
  321. if (bRes)
  322. {
  323. //SetStartTime(dtS);
  324. //SetEndTime(dtE);
  325. m_dtStartTime = dtS;
  326. m_dtEndTime = dtE;
  327. }
  328. return bRes;
  329. }
  330. CXTPCalendarEventPtr CXTPCalendarEvent::CloneEvent()
  331. {
  332. if (!m_pDataProvider)
  333. {
  334. ASSERT(FALSE);
  335. return NULL;
  336. }
  337. CXTPCalendarEventPtr ptrNewEvent = m_pDataProvider->CreateNewEvent(GetEventID());
  338. if (!ptrNewEvent)
  339. {
  340. ASSERT(FALSE);
  341. return NULL;
  342. }
  343. if (CloneEventTo(ptrNewEvent))
  344. {
  345. return ptrNewEvent;
  346. }
  347. ASSERT(FALSE);
  348. return NULL;
  349. }
  350. BOOL CXTPCalendarEvent::CloneEventTo(CXTPCalendarEvent* pEventDest)
  351. {
  352. if (!m_pDataProvider || !pEventDest)
  353. {
  354. ASSERT(FALSE);
  355. return FALSE;
  356. }
  357. pEventDest->Clear();
  358. BOOL bRes = pEventDest->Update(this);
  359. if (!bRes)
  360. {
  361. ASSERT(FALSE);
  362. return FALSE;
  363. }
  364. XTPCalendarEventRecurrenceState nRState = GetRecurrenceState();
  365. if (nRState == xtpCalendarRecurrenceMaster)
  366. {
  367. CXTPCalendarRecurrencePatternPtr ptrRPattern = GetRecurrencePattern();
  368. bRes = pEventDest->SetRecurrenceState_Master(ptrRPattern);
  369. }
  370. else
  371. if (nRState != xtpCalendarRecurrenceNotRecurring)
  372. {
  373. ASSERT(nRState == xtpCalendarRecurrenceException || nRState == xtpCalendarRecurrenceOccurrence);
  374. DWORD dwPatternID = GetRecurrencePatternID();
  375. bRes = pEventDest->SetRecurrenceState_ExceptionOccurrence(nRState, dwPatternID);
  376. }
  377. if (nRState == xtpCalendarRecurrenceException)
  378. {
  379. COleDateTime dtTmpOrig = GetRException_StartTimeOrig();
  380. pEventDest->SetRException_StartTimeOrig(dtTmpOrig);
  381. dtTmpOrig = GetRException_EndTimeOrig();
  382. pEventDest->SetRException_EndTimeOrig(dtTmpOrig);
  383. }
  384. pEventDest->m_dwRecurrencePatternID_ToUse = m_dwRecurrencePatternID_ToUse;
  385. ASSERT(bRes);
  386. return bRes;
  387. }
  388. BOOL CXTPCalendarEvent::Update(CXTPCalendarEvent* pNewData)
  389. {
  390. if (pNewData == this)
  391. {
  392. return TRUE;
  393. }
  394. UINT uScheduleID = pNewData->GetScheduleID();
  395. SetScheduleID(uScheduleID);
  396. CString strTmp = pNewData->GetSubject();
  397. SetSubject(strTmp);
  398. strTmp = pNewData->GetLocation();
  399. SetLocation(strTmp);
  400. int nTmp = pNewData->GetLabelID();
  401. SetLabelID(nTmp);
  402. BOOL bTmp = pNewData->IsAllDayEvent();
  403. SetAllDayEvent(bTmp);
  404. COleDateTime dtTmp = pNewData->GetStartTime();
  405. m_dtStartTime = dtTmp;
  406. dtTmp = pNewData->GetEndTime();
  407. m_dtEndTime = dtTmp;
  408. bTmp = pNewData->IsReminder();
  409. SetReminder(bTmp);
  410. nTmp = pNewData->GetReminderMinutesBeforeStart();
  411. SetReminderMinutesBeforeStart(nTmp);
  412. strTmp = pNewData->GetReminderSoundFile();
  413. SetReminderSoundFile(strTmp);
  414. strTmp = pNewData->GetBody();
  415. SetBody(strTmp);
  416. nTmp = pNewData->GetBusyStatus();
  417. SetBusyStatus(nTmp);
  418. nTmp = pNewData->GetImportance();
  419. SetImportance(nTmp);
  420. dtTmp = pNewData->GetCreationTime();
  421. SetCreationTime(dtTmp);
  422. dtTmp = pNewData->GetLastModificationTime();
  423. SetLastModificationTime(dtTmp);
  424. nTmp = pNewData->IsMeeting();
  425. SetMeeting(nTmp);
  426. nTmp = pNewData->IsPrivate();
  427. SetPrivate(nTmp);
  428. bTmp = pNewData->IsRExceptionDeleted();
  429. SetRExceptionDeleted(bTmp);
  430. dtTmp = pNewData->GetRException_StartTimeOrig();
  431. SetRException_StartTimeOrig(dtTmp);
  432. dtTmp = pNewData->GetRException_EndTimeOrig();
  433. SetRException_EndTimeOrig(dtTmp);
  434. // Custom properties
  435. ASSERT(pNewData->GetCustomProperties());
  436. if (pNewData->GetCustomProperties())
  437. {
  438. pNewData->GetCustomProperties()->CopyTo(m_pCustomProperties);
  439. }
  440. // Custom Icons
  441. if (GetCustomIcons() && pNewData->GetCustomIcons())
  442. {
  443. GetCustomIcons()->Copy(*pNewData->GetCustomIcons());
  444. }
  445. else
  446. {
  447. XTP_SAFE_CALL1(GetCustomIcons(), RemoveAll());
  448. }
  449. // Event categories
  450. if (GetCategories() && pNewData->GetCategories())
  451. {
  452. GetCategories()->Copy(*pNewData->GetCategories());
  453. }
  454. else
  455. {
  456. XTP_SAFE_CALL1(GetCategories(), RemoveAll());
  457. }
  458. return TRUE;
  459. }
  460. CXTPCalendarEventPtr CXTPCalendarEvent::CloneForOccurrence(COleDateTime dtStart,
  461. COleDateTime dtEnd, DWORD dwNewEventID)
  462. {
  463. int eRecurrenceState = GetRecurrenceState();
  464. if (eRecurrenceState != xtpCalendarRecurrenceMaster || !m_pDataProvider)
  465. {
  466. ASSERT(FALSE);
  467. return NULL;
  468. }
  469. CXTPCalendarEventPtr ptrNewEvent = m_pDataProvider->CreateNewEvent(dwNewEventID);
  470. if (!ptrNewEvent)
  471. {
  472. ASSERT(FALSE);
  473. return FALSE;
  474. }
  475. BOOL bRes = ptrNewEvent->Update(this);
  476. if (!bRes)
  477. {
  478. ASSERT(FALSE);
  479. return NULL;
  480. }
  481. ptrNewEvent->SetStartTime(dtStart);
  482. ptrNewEvent->SetEndTime(dtEnd);
  483. ptrNewEvent->SetRecurrenceState_ExceptionOccurrence(xtpCalendarRecurrenceOccurrence, m_dwRecurrencePatternID);
  484. ptrNewEvent->SetRExceptionDeleted(FALSE);
  485. return ptrNewEvent;
  486. }
  487. BOOL CXTPCalendarEvent::MakeEventAsRecurrence()
  488. {
  489. if (m_nRecurrenceState != xtpCalendarRecurrenceNotRecurring || !m_pDataProvider)
  490. {
  491. ASSERT(FALSE);
  492. return FALSE;
  493. }
  494. ASSERT(m_ptrRPattern == NULL);
  495. CXTPCalendarRecurrencePatternPtr ptrPattern;
  496. ptrPattern = m_pDataProvider->CreateNewRecurrencePattern(m_dwRecurrencePatternID_ToUse);
  497. if (!SetRecurrenceState_Master(ptrPattern))
  498. {
  499. ASSERT(FALSE);
  500. return FALSE;
  501. }
  502. return TRUE;
  503. }
  504. BOOL CXTPCalendarEvent::UpdateRecurrence(CXTPCalendarRecurrencePattern* pRPattern)
  505. {
  506. if (m_nRecurrenceState != xtpCalendarRecurrenceMaster ||
  507. !m_pDataProvider || !m_ptrRPattern || !pRPattern)
  508. {
  509. ASSERT(FALSE);
  510. return FALSE;
  511. }
  512. //ASSERT(m_dwRecurrencePatternID == m_ptrRPattern->GetPatternID());
  513. //ASSERT(m_dwEventID == m_ptrRPattern->GetMasterEventID());
  514. //DWORD dwPatternID2 = pRPattern->GetPatternID();
  515. //DWORD dwMasterID2 = pRPattern->GetMasterEventID();
  516. //if (m_dwRecurrencePatternID != dwPatternID2 || m_dwEventID != dwMasterID2)
  517. //{
  518. //  ASSERT(FALSE);
  519. //  return FALSE;
  520. //}
  521. //------------------------------------------------
  522. BOOL bRes = m_ptrRPattern->Update(pRPattern);
  523. if (!bRes)
  524. {
  525. ASSERT(FALSE);
  526. return FALSE;
  527. }
  528. m_dwRecurrencePatternID = m_ptrRPattern->GetPatternID();
  529. m_ptrRPattern->SetMasterEventID(m_dwEventID);
  530. bRes = CalcStartEndDatesFromPattern();
  531. ASSERT(bRes);
  532. return bRes;
  533. }
  534. BOOL CXTPCalendarEvent::RemoveRecurrence()
  535. {
  536. COleDateTime dtStart, dtEnd;
  537. BOOL bIsMaster = GetRecurrenceState() == xtpCalendarRecurrenceMaster;
  538. if (bIsMaster && m_ptrRPattern)
  539. {
  540. dtStart = CXTPCalendarUtils::UpdateTime(m_ptrRPattern->GetPatternStartDate(),
  541. m_ptrRPattern->GetStartTime());
  542. dtEnd = dtStart + m_ptrRPattern->GetDuration();
  543. }
  544. else
  545. {
  546. bIsMaster = FALSE;
  547. }
  548. if (!SetRecurrenceState_NotRecurring())
  549. {
  550. ASSERT(FALSE);
  551. return FALSE;
  552. }
  553. if (bIsMaster)
  554. {
  555. SetStartTime(dtStart);
  556. SetEndTime(dtEnd);
  557. }
  558. return TRUE;
  559. }
  560. CXTPCalendarRecurrencePattern* CXTPCalendarEvent::GetRPatternRef()
  561. {
  562. ASSERT(GetRecurrenceState() == xtpCalendarRecurrenceMaster);
  563. return m_ptrRPattern;
  564. }
  565. int CXTPCalendarEvent::GetEventPeriodDays() const
  566. {
  567. return CXTPCalendarUtils::GetEventPeriodDays(GetStartTime(), GetEndTime());
  568. }
  569. BOOL CXTPCalendarEvent::IsEqualStartEnd(CXTPCalendarEvent* pEvent) const
  570. {
  571. COleDateTime dtStart2 = pEvent->GetStartTime();
  572. COleDateTime dtEnd2 = pEvent->GetEndTime();
  573. BOOL bRes = CXTPCalendarUtils::IsEqual(m_dtStartTime, dtStart2, TRUE) &&
  574. CXTPCalendarUtils::IsEqual(m_dtEndTime, dtEnd2, TRUE);
  575. return bRes;
  576. }
  577. BOOL CXTPCalendarEvent::IsEqualIDs(CXTPCalendarEvent* pEvent) const
  578. {
  579. if (!pEvent)
  580. {
  581. ASSERT(FALSE);
  582. return FALSE;
  583. }
  584. int nRState2 = pEvent->GetRecurrenceState();
  585. BOOL bRes = FALSE;
  586. if (m_nRecurrenceState == xtpCalendarRecurrenceNotRecurring &&
  587. nRState2 == xtpCalendarRecurrenceNotRecurring)
  588. {
  589. DWORD dwEventID2 = pEvent->GetEventID();
  590. bRes = (m_dwEventID == dwEventID2);
  591. }
  592. else
  593. {
  594. DWORD dwPatternID2 = pEvent->GetRecurrencePatternID();
  595. // for xtpCalendarRecurrenceMaster & xtpCalendarRecurrenceOccurrence
  596. COleDateTime dtStart = m_dtStartTime;
  597. COleDateTime dtEnd = m_dtEndTime;
  598. COleDateTime dtStart2 = pEvent->GetStartTime();
  599. COleDateTime dtEnd2 = pEvent->GetEndTime();
  600. if (m_nRecurrenceState == xtpCalendarRecurrenceException)
  601. {
  602. dtStart = GetRException_StartTimeOrig();
  603. dtEnd = GetRException_EndTimeOrig();
  604. }
  605. if (pEvent->GetRecurrenceState() == xtpCalendarRecurrenceException)
  606. {
  607. dtStart2 = pEvent->GetRException_StartTimeOrig();
  608. dtEnd2 = pEvent->GetRException_EndTimeOrig();
  609. }
  610. bRes = m_dwRecurrencePatternID == dwPatternID2 &&
  611.    CXTPCalendarUtils::IsEqual(dtStart, dtStart2, TRUE) &&
  612.    CXTPCalendarUtils::IsEqual(dtEnd, dtEnd2, TRUE);
  613. }
  614. return bRes;
  615. }
  616. void CXTPCalendarEvent::Clear()
  617. {
  618. CXTPCalendarEventPtr ptrEmptyEvent = m_pDataProvider->CreateNewEvent(GetEventID());
  619. if (!ptrEmptyEvent)
  620. {
  621. ASSERT(FALSE);
  622. return;
  623. }
  624. SetRecurrenceState_NotRecurring();
  625. Update(ptrEmptyEvent);
  626. }
  627. void CXTPCalendarEvent::DoPropExchange(CXTPPropExchange* pPX)
  628. {
  629. long nVersion = XTP_EVENT_PROP_SET_DATA_VER;
  630. PX_Long(pPX, _T("Version"), nVersion, XTP_EVENT_PROP_SET_DATA_VER);
  631. // TODO:
  632. PX_DWord(pPX, cszEventProp_ScheduleID, (DWORD&)m_uScheduleID, 0);
  633. PX_DWord(pPX, cszEventProp_EventID, m_dwEventID, XTP_CALENDAR_UNKNOWN_EVENT_ID);
  634. PX_DateTime(pPX, cszEventProp_StartTime, m_dtStartTime);
  635. PX_DateTime(pPX, cszEventProp_EndTime, m_dtEndTime);
  636. PX_String(pPX, cszEventProp_Subject, m_strSubject, _T(""));
  637. PX_String(pPX, cszEventProp_Location, m_strLocation, _T(""));
  638. if (nVersion > XTP_EVENT_PROP_SET_DATA_VER_1)
  639. {
  640. PX_String(pPX, cszEventProp_Body, m_strBody, _T(""));
  641. }
  642. else
  643. {
  644. PX_String(pPX, cszEventPropOld_Description, m_strBody, _T(""));
  645. }
  646. PX_Bool(pPX, cszEventProp_AllDayEvent, m_bAllDayEvent, FALSE);
  647. PX_Int(pPX, cszEventProp_LabelID, m_nLabelID, XTP_CALENDAR_DEFAULT_LABEL_ID);
  648. PX_Int(pPX, cszEventProp_BusyStatus, m_nBusyStatus, xtpCalendarBusyStatusFree);
  649. PX_Int(pPX, cszEventProp_Importance, m_nImportance, xtpCalendarImportanceNormal);
  650. if (nVersion > XTP_EVENT_PROP_SET_DATA_VER_1)
  651. {
  652. PX_Bool(pPX, cszEventProp_IsReminder, m_bReminder, FALSE);
  653. }
  654. PX_Int(pPX, cszEventProp_ReminderMinutesBeforeStart, m_nReminderMinutesBeforeStart, 15);
  655. PX_String(pPX, cszEventProp_ReminderSoundFile, m_strReminderSoundFile, _T(""));
  656. PX_DateTime(pPX, cszEventProp_CreationTime, m_dtCreationTime);
  657. PX_DateTime(pPX, cszEventProp_LastModificationTime, m_dtLastModificationTime);
  658. PX_Bool(pPX, cszEventProp_IsMeeting, m_bMeeting, FALSE);
  659. PX_Bool(pPX, cszEventProp_IsPrivate, m_bPrivate, FALSE);
  660. if (pPX->IsStoring())
  661. {
  662. PX_Enum(pPX, cszEventProp_RecurrenceState, m_nRecurrenceState, xtpCalendarRecurrenceNotRecurring);
  663. PX_DWord(pPX, cszEventProp_RecurrencePatternID, m_dwRecurrencePatternID, XTP_CALENDAR_UNKNOWN_RECURRENCE_PATTERN_ID);
  664. if (m_nRecurrenceState == xtpCalendarRecurrenceException)
  665. {
  666. PX_Bool(pPX, cszEventProp_RExceptionDeleted, m_bRExceptionDeleted, FALSE);
  667. PX_DateTime(pPX, cszEventProp_RException_StartTimeOrig, m_dtRException_StartTimeOrig);
  668. PX_DateTime(pPX, cszEventProp_RException_EndTimeOrig, m_dtRException_EndTimeOrig);
  669. }
  670. }
  671. else
  672. {
  673. //===========================================================================
  674. XTPCalendarEventRecurrenceState nRecurrenceState = m_nRecurrenceState = xtpCalendarRecurrenceNotRecurring;
  675. PX_Enum(pPX, cszEventProp_RecurrenceState, nRecurrenceState, xtpCalendarRecurrenceNotRecurring);
  676. DWORD dwRecurrencePatternID = XTP_CALENDAR_UNKNOWN_RECURRENCE_PATTERN_ID;
  677. PX_DWord(pPX, cszEventProp_RecurrencePatternID, dwRecurrencePatternID, XTP_CALENDAR_UNKNOWN_RECURRENCE_PATTERN_ID);
  678. if (nRecurrenceState == xtpCalendarRecurrenceMaster)
  679. {
  680. if (!MakeEventAsRecurrence())
  681. {
  682. ASSERT(FALSE);
  683. return;
  684. }
  685. }
  686. else if (nRecurrenceState == xtpCalendarRecurrenceException || nRecurrenceState == xtpCalendarRecurrenceOccurrence)
  687. {
  688. SetRecurrenceState_ExceptionOccurrence(nRecurrenceState, dwRecurrencePatternID);
  689. if (nRecurrenceState == xtpCalendarRecurrenceException)
  690. {
  691. PX_Bool(pPX, cszEventProp_RExceptionDeleted, m_bRExceptionDeleted, FALSE);
  692. PX_DateTime(pPX, cszEventProp_RException_StartTimeOrig, m_dtRException_StartTimeOrig);
  693. PX_DateTime(pPX, cszEventProp_RException_EndTimeOrig, m_dtRException_EndTimeOrig);
  694. }
  695. }
  696. }
  697. //------------------------------------------------------------------------
  698. if (m_pCustomProperties)
  699. m_pCustomProperties->DoPropExchange(pPX);
  700. if (m_pCustomIconsIDs)
  701. m_pCustomIconsIDs->DoPropExchange(pPX);
  702. if (m_pEventCategoryIDs && nVersion > XTP_EVENT_PROP_SET_DATA_VER_2)
  703. m_pEventCategoryIDs->DoPropExchange(pPX);
  704. }
  705. void CXTPCalendarEvent::ClearIntermediateData()
  706. {
  707. m_dwRecurrencePatternID_ToUse = XTP_CALENDAR_UNKNOWN_RECURRENCE_PATTERN_ID;
  708. if (!IsReminder() && m_pCustomProperties)
  709. {
  710. // clear this property if reminder disabled
  711. m_pCustomProperties->RemoveProperty(cszEventCustProp_NextReminderTime_Snoozed);
  712. }
  713. if (!IsReminder() && m_ptrRPattern)
  714. {
  715. ASSERT(m_nRecurrenceState == xtpCalendarRecurrenceMaster);
  716. // clear reminders info for occurrences
  717. // if reminder disabled for whole series.
  718. m_ptrRPattern->GetOccReminders()->RemoveAll();
  719. }
  720. }
  721. void CXTPCalendarEvent::SetRecurrencePatternID(DWORD dwRecurrencePatternID)
  722. {
  723. m_dwRecurrencePatternID = dwRecurrencePatternID;
  724. if (m_ptrRPattern)
  725. {
  726. ASSERT(m_nRecurrenceState == xtpCalendarRecurrenceMaster);
  727. m_ptrRPattern->SetPatternID(dwRecurrencePatternID);
  728. }
  729. }
  730. void CXTPCalendarEvent::SetEventID(DWORD dwEventID)
  731. {
  732. m_dwEventID = dwEventID;
  733. if (m_nRecurrenceState == xtpCalendarRecurrenceMaster)
  734. {
  735. ASSERT(m_ptrRPattern);
  736. if (m_ptrRPattern)
  737. {
  738. m_ptrRPattern->SetMasterEventID(m_dwEventID);
  739. }
  740. }
  741. }
  742. ////////////////////////////////////////////////////////////////////////////
  743. ////////////////////////////////////////////////////////////////////////////