I am binding my database to the calendar and have encountered a huge problem with exceptions to recurrence patterns. For some reason, they don't take. I have implemented my own version of the DoRetrieveDayEvents() function and everything else is working.
Here is what I am doing:
1. I look for recurrence patterns in my database that recur across the day and add them to the return list.
2. I look for calendar blocks in the database that include this day.
2.1 Since recurrence exceptions are implemented via the calendar blocks, they are read in at this point.
3. If a calendar block represents an exception, we use the following code:
// We have a recurrence ID. This event is actually an
// exception to a pattern that may well be recurring
// here. Grab the pattern first
CXTPCalendarRecurrencePatternPtr pRecurPtr = LookupPatternFromDBID(pEv->m_pCal->GetRecurInstanceID(), true, true);
if (!(CXTPCalendarRecurrencePattern*)pRecurPtr)
{
// The pattern hadn't already been read in.
// Read it in now.
pRecurPtr = CreateNewRecurrencePattern(XTP_CALENDAR_UNKNOWN_RECURRENCE_PATTERN_ID);
// Grab our special data from the pointer
CEARecurrencePattern* pRecur = (CEARecurrencePattern*)(CXTPCalendarRecurrencePattern*)pRecurPtr;
// stuff the info from the database into this record
pRecur->m_pRecur->Select(m_pDB, pEv->m_pCal->GetRecurInstanceID(), 0xFFFFFFFFFFFFFFFF);
pRecur->SyncFromRecords(); // make the calendar aware of everything
// since we have a pattern, we need a master event
CXTPCalendarEventPtr pEvPtr2 = CreateNewEvent(XTP_CALENDAR_UNKNOWN_EVENT_ID);
// Grab our special data from the pointer
CEACalendarEvent* pEvMaster = (CEACalendarEvent*)(CXTPCalendarEvent*)pEvPtr2;
pEvMaster->SetScheduleID(m_pEventSch->GetID());
// read in the info for the event
if (pEvMaster->m_pItem->SelectRecurrenceMaster(m_pDB, pRecur->m_pRecur->GetID(), 0xFFFFFFFFFFFFFFFF))
{
pEvMaster->SyncFromRecords(); // make the calendar aware of everything
// link the recurrence pattern to the event
pRecurPtr->SetMasterEventID(pEvMaster->GetEventID());
pEvMaster->SetRecurrenceState_Master(pRecurPtr);
// Add the master event so it doesn't get lost
p->Add(pEvMaster);
}
// save this for later
RememberPatternFromDBID(pRecur->m_pRecur->GetID(), CXTPCalendarRecurrencePatternPtr(pEvMaster->GetRPatternRef(), true));
}
// make sure we have the pointer that the master event is using
CXTPCalendarEventPtr pEvMaster = pRecurPtr->GetMasterEvent();
CXTPCalendarRecurrencePattern* pRecur = ((CEACalendarEvent*)(CXTPCalendarEvent*)pEvMaster)->GetRPatternRef();
if (pRecur != pRecurPtr)
{
// somehow this pointer got changed, update it
RememberPatternFromDBID(((CEARecurrencePattern*)pRecur)->m_pRecur->GetID(), CXTPCalendarRecurrencePatternPtr(pRecur, true));
}
// send what we have so far to the record to prevent clobbering
// it when we finish making this an exception
pEv->SyncFromRecords();
// We have the pointer to the recurrence pattern now. Set the necessary
// information to treat this instance like an exception.
pEv->MakeAsRException(pRecur->GetPatternID());
pRecur->SetException(pEv);
// Add the master event
p->Add(pEvMaster); // shouldn't have to do this. The master should already be in the array
// but if we don't call this, our pointer for the master and the one for
// the pattern itself get deallocated when they go out of scope. This
// seems to be a source of our problem with the exceptions not taking.
|
|