Codejock Forums Homepage
Forum Home Forum Home > Codejock Products > Visual C++ MFC > Calendar
  New Posts New Posts RSS Feed - Binding data and exceptions
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

Binding data and exceptions

 Post Reply Post Reply
Author
Message
JohnCrenshaw View Drop Down
Groupie
Groupie
Avatar

Joined: 08 September 2006
Status: Offline
Points: 65
Post Options Post Options   Thanks (0) Thanks(0)   Quote JohnCrenshaw Quote  Post ReplyReply Direct Link To This Post Topic: Binding data and exceptions
    Posted: 10 November 2006 at 10:57am
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.

Back to Top
JohnCrenshaw View Drop Down
Groupie
Groupie
Avatar

Joined: 08 September 2006
Status: Offline
Points: 65
Post Options Post Options   Thanks (0) Thanks(0)   Quote JohnCrenshaw Quote  Post ReplyReply Direct Link To This Post Posted: 16 November 2006 at 4:59pm
I found a solution to this, sort of. I can't delay the retrieval of exceptions until they are needed. I have to load them ALL when the recurrence pattern gets loaded.
 
Is there any chance of this changing in the future?
Back to Top
sserge View Drop Down
Moderator Group
Moderator Group


Joined: 01 December 2004
Status: Offline
Points: 1297
Post Options Post Options   Thanks (0) Thanks(0)   Quote sserge Quote  Post ReplyReply Direct Link To This Post Posted: 17 November 2006 at 7:45am
Yes, you are on the right way.
 
The recurrence event structure is following:
    <Master Event object>
        <Recurrence pattern object>
            <Recurrence exceptions collection>
 
They are linked and master event must be provided completly.
This is a basic idea and when you return completed master event it can be cached.
 
I think this is easy to understand and implement.

May be add some notifications to process recurrence exceptions, but if you have 1 - 100 exceptions for single recurrence event I think this is not a problem or using other more complex way will not give you a big advantage.
 
Microsoft Outlook (MAPI) also use the same completed recurrence structure. The difference only that in MAPI exceptions are saved not as completed event object, but only changed properties and times of master event saved.
 
We also may go in this way, but it's more complex and looks to be not needed for now.
 
--
WBR,
Serge
Back to Top
 Post Reply Post Reply
  Share Topic   

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.04
Copyright ©2001-2021 Web Wiz Ltd.

This page was generated in 0.172 seconds.