Codejock Forums Homepage
Forum Home Forum Home > Codejock Products > ActiveX COM > Calendar
  New Posts New Posts RSS Feed - Create Event Exception
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

Create Event Exception

 Post Reply Post Reply
Author
Message
WaaZ View Drop Down
Senior Member
Senior Member


Joined: 31 January 2006
Location: United Kingdom
Status: Offline
Points: 103
Post Options Post Options   Thanks (0) Thanks(0)   Quote WaaZ Quote  Post ReplyReply Direct Link To This Post Topic: Create Event Exception
    Posted: 31 January 2006 at 8:23am

Hi,

Its the same question I posted on the wrong forum, I am using the activeX control one.

I wish to know, if I have a CalendarEvent "myEvent" with a recurrence object, and I wish to add an exception without the user clicking on the form.

Normally, if I can get hold of an event of state (CalendarEventRecurrenceState.xtpCalendarRecurrenceOccurrence), I can make it as an exception. How will I get hold of such an instance of calendarEvent, or how can I replicate my MasterEvent so that I can make another event of state (CalendarEventRecurrenceState.xtpCalendarRecurrenceException) under this particular event.

Thnx in advance for ur collaboration

WaaZ

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: 31 January 2006 at 1:48pm
Hi,

The idea is the folowing:

- You have an instance of event occurrence (you can get it by HitTest or in another way).
Recurrence state == xtpCalendarRecurrenceOccurrence      ; ;

- Call pEvent.MakeAsRException() to change recurrence state (and store original occurrence Start/End times in separate members)

- Than you may change other pEvent properties.

- To commit your changes call pCalendar.DataProvider.ChangeEvent(pEvent)

That's it.

btw, if you enable "Show hidden members" option of the Object Browser, some other class members will be visible for you. They might sometimes be useful for extended operations.

(please reply in this topic if needed)

--
WBR,
Serge
Back to Top
WaaZ View Drop Down
Senior Member
Senior Member


Joined: 31 January 2006
Location: United Kingdom
Status: Offline
Points: 103
Post Options Post Options   Thanks (0) Thanks(0)   Quote WaaZ Quote  Post ReplyReply Direct Link To This Post Posted: 01 February 2006 at 5:47am

Thank you for the reply, it is really helpful. I have some other problem with this:

What if at loading time, I am retrieving data from an external soucre (database or webservices) and that I need to create a CalendarEvent object with recurrences and exceptions. I will create an exception as follows since I have access to only the masterEvent:

CalendarEvent masterEv = CalendarControl.DataProvider.CreateEvent();

Then I will clone this event so that I can create an Exception out of it as follows:

CalendarEvent ExcepEv = masterEv.CloneEvent();

ExcepEv.MakeAsRException();

ExcepEv.Description = FromExternalSource.getField("description");

// and so on

How do I  attach ExcepEv with masterEv since it is not working. I am not having the exception displayed on the screen. I have tried :

ExcepRv.MakeAsRExceptionEx(MasterEv.Id);

which is not working either.

Note: I do not have access to HitTest and I cannot get access to any CalendarEven object of type :

Recurrence state == xtpCalendarRecurrenceOccurrence

since I do not have access to the UI. I am at the initialization stage of the calendar with events date received from an external source.

Thanks

WaaZ

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: 01 February 2006 at 8:54am
Hi,

Note that MakeAsRExceptionEx() need pattern ID -- not master event ID.

I'd also suggest you to look at some more info about Recurrences at the forum, especially http://forum.codejock.com/forum_posts.asp?TID=2929.

--
WBR,
Serge
Back to Top
WaaZ View Drop Down
Senior Member
Senior Member


Joined: 31 January 2006
Location: United Kingdom
Status: Offline
Points: 103
Post Options Post Options   Thanks (0) Thanks(0)   Quote WaaZ Quote  Post ReplyReply Direct Link To This Post Posted: 01 February 2006 at 10:52am

I have done this also and have also put ChangeEvent(), but it does not change anything..

Is there some steps (some method calls) i need to make sure to have done so that it works? for instance, i have cloned the masterEvent itself, then MakeAsRExceptionEx() with masterEv.RecurrencePattern.Id.

Thnks

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: 02 February 2006 at 6:52am
First steps:
- you have to create master event,
- Set recurrence pattern properties,
- update recurrence,
- Add master event to data provider.

Only after that exceptions could be processed.

Ordering records by a Recurrence State is useful to add master event before exceptions.


Other important step - set occurrence Start/End times before making an exception:

pEvent.StartTime = pEventRS("RExceptionStartTimeOrig");
pEvent.EndTime = pEventRS("RExceptionEndTimeOrig");
     
pEvent.MakeAsRExceptionEx(pEventRS(" RecurrencePatternID"));


Please try searching the forum for keyword 'recurrence' - you can find there a lot of useful information, not mentioned in my answer above.


Does creating recurrence without exceptions work fine?
If my advices above wouldn't help you, please send your loading procedure source code.

--
WBR,
Serge
Back to Top
WaaZ View Drop Down
Senior Member
Senior Member


Joined: 31 January 2006
Location: United Kingdom
Status: Offline
Points: 103
Post Options Post Options   Thanks (0) Thanks(0)   Quote WaaZ Quote  Post ReplyReply Direct Link To This Post Posted: 02 February 2006 at 9:24am

Hi serge,

I've tried this in my code and the result is that it is having an exception and its not overwriting the one that occurs that same day and same time. How do I make it overwrite a recurrence?

CalendarEvent masterEv = CalendarControl.DataProvider.CreateEvent();

//DateTime tempdate = DateTime.Now;

masterEv = CalendarControl.DataProvider.CreateEvent();

masterEv.Subject = "Master Ev";

masterEv.Location = "Master Loca";

CalendarRecurrencePattern RecurEv = masterEv.CreateRecurrence();

DateTime dtStart = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 13, 8, 0);

DateTime dtRecurencePattern_Start = new DateTime(DateTime.Now.Ticks);

// duration

RecurEv.StartTime = DateTime.Now;

RecurEv.DurationMinutes = 60;

// period

dtRecurencePattern_Start = DateTime.Now.AddDays(-4);

RecurEv.StartDate = dtRecurencePattern_Start;

dtRecurencePattern_Start = DateTime.Now.AddDays(10);

RecurEv.EndDate = dtRecurencePattern_Start;

RecurEv.Options.RecurrenceType = CalendarRecurrenceType.xtpCalendarRecurrenceDaily;

RecurEv.Options.DailyEveryWeekDayOnly = false;

RecurEv.Options.DailyIntervalDays = 1;

masterEv.UpdateRecurrence(RecurEv);

CalendarControl.DataProvider.AddEvent(masterEv);

/************/

/************/

CalendarEvent excepEv = CalendarControl.DataProvider.CreateEventEx(masterEv.Id);

excepEv.StartTime = DateTime.Now;

excepEv.EndTime = DateTime.Now.AddMinutes(60);

excepEv.Subject = "Excep Ev";

excepEv.MakeAsRExceptionEx(RecurEv.Id);

CalendarControl.DataProvider.AddEvent(excepEv);

CalendarControl.DataProvider.ChangeEvent(masterEv);

isNewEventfromUi = false;

 

.............

Thnx

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: 03 February 2006 at 11:47am
Hi,

Some notes below:

1.
You don't need CreateEventEx here.
    CalendarEvent excepEv = CalendarControl.DataProvider.CreateEventEx(masterEv.Id);
Better to use CreateEvent.

2.
This call adds exception.
CalendarControl.DataProvider.AddEvent(excepEv);

But this call kills all your exceptions:
CalendarControl.DataProvider.ChangeEvent(masterEv);

Are you sure you need this call???

-----
Master event contains recurrence pattern object.
Pattern contains a collection of exceptions (which is empty in the beginning).

After call AddEvent(masterEv) data provider store a copy of master event object (with Pattern).

When you call AddEvent(excepEv) - data provider finds master event and adds exception to it's pattern collection of exceptions.

After call ChangeEvent(masterEv) - data provider updates it's copy of master event. But your masterEv object instance has no exceptions in it's collection.

3.
Using DateTime.Now does not let you debug this peace of code.
I mean it will return different values for different lines.


--
WBR,
Serge
Back to Top
WaaZ View Drop Down
Senior Member
Senior Member


Joined: 31 January 2006
Location: United Kingdom
Status: Offline
Points: 103
Post Options Post Options   Thanks (0) Thanks(0)   Quote WaaZ Quote  Post ReplyReply Direct Link To This Post Posted: 10 February 2006 at 6:14am

Please, can I have a sample that demonstrates how this can be achieved.

Thanks

WaaZ

Back to Top
WaaZ View Drop Down
Senior Member
Senior Member


Joined: 31 January 2006
Location: United Kingdom
Status: Offline
Points: 103
Post Options Post Options   Thanks (0) Thanks(0)   Quote WaaZ Quote  Post ReplyReply Direct Link To This Post Posted: 12 February 2006 at 6:08am

The problem with the code is actually not to do with the time, since I've had a temporary DateTime variable to make sure that the same time is used for the recurrencePattern and the exception event.

The actual problem in the code is that MakeAsRExceptionEx does not put the event in the collection in masterEv.RecurrencePattern.Exceptions. This means that the provided code result in masterEv not having an instance of EventEx in the collection of its exceptions.

the code: *******************************

 

CalendarEvent masterEv = CalendarControl.DataProvider.CreateEvent();

//DateTime tempdate = DateTime.Now;

masterEv = CalendarControl.DataProvider.CreateEvent();

masterEv.Subject = "Master Ev";

masterEv.Location = "Master Loca";

CalendarRecurrencePattern RecurEv = masterEv.CreateRecurrence();

DateTime dtStart = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 13, 8, 0);

DateTime dtRecurencePattern_Start = new DateTime(DateTime.Now.Ticks);

// duration

// RecurEv.StartTime = DateTime.Now;

RecurEv.DurationMinutes = 60;

// period

dtRecurencePattern_Start = DateTime.Now.AddDays(-4);

RecurEv.StartDate = dtRecurencePattern_Start;

dtRecurencePattern_Start = DateTime.Now.AddDays(10);

RecurEv.StartTime = dtRecurencePattern_Start;

RecurEv.EndDate = dtRecurencePattern_Start;

RecurEv.Options.RecurrenceType = CalendarRecurrenceType.xtpCalendarRecurrenceDaily;

RecurEv.Options.DailyEveryWeekDayOnly = false;

RecurEv.Options.DailyIntervalDays = 1;

masterEv.UpdateRecurrence(RecurEv);

CalendarControl.DataProvider.AddEvent(masterEv);

/************/

/************/

CalendarEvent excepEv = CalendarControl.DataProvider.CreateEventEx(masterEv.Id);

excepEv.StartTime = dtRecurencePattern_Start.AddDays(-10);

excepEv.EndTime = dtRecurencePattern_Start.AddDays(-10).AddMinutes(60);

excepEv.Subject = "Excep Ev";

excepEv.MakeAsRExceptionEx(RecurEv.Id);

CalendarControl.DataProvider.AddEvent(excepEv);

CalendarControl.DataProvider.ChangeEvent(masterEv);

 

*******************************************

I've also tried playing around with the ChangeEvent, AddEvent and CreateEventEx and the above code is the one that works to the closest.

Thnks

WaaZ

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: 12 February 2006 at 11:45am
Hi WaaZ,

Some notes about your code.
 
// Better to use CreateEvent here
//CalendarEvent excepEv = CalendarControl.DataProvider.CreateEventEx(masterEv.Id);
CalendarEvent excepEv = CalendarControl.DataProvider.CreateEvent();
 
// change status and copy dates only
excepEv.MakeAsRExceptionEx(RecurEv.Id);
 
// use ChangeEvent instead of AddEvent.
//CalendarControl.DataProvider.AddEvent(excepEv);
 
// This call add the event in the collection in
// masterEv.RecurrencePattern.Exceptions.
// (I mean DataProvider internal copy of masterEv)
CalendarControl.DataProvider.ChangeEvent(excepEv);
 
!!!
// comment this line please;
// this call kill your exception!
// CalendarControl.DataProvider.ChangeEvent(masterEv);
 
// update your instance
masterEv = CalendarControl.DataProvider.GetEvent(masterEv.Id);
//and check there.

_________________

Below is a sample for you. Add these lines to standard Calendar VB sample application to the end of Form_Load() handler for frmMain.
 
    '---------------------------------------------
    Dim dtTooday As Date
    dtTooday = Date
   
    Dim masterEv As CalendarEvent
    Dim recPattern As CalendarRecurrencePattern
   
    Set masterEv = CalendarControl.DataProvider.CreateEvent
    Set recPattern = masterEv.CreateRecurrence
   
    masterEv.Subject = "Recurrence for WaaZ"
       
    recPattern.StartTime = #3:00:00 PM#
    recPattern.DurationMinutes = 60
    recPattern.StartDate = dtTooday
    recPattern.EndAfterOccurrences = 10
       
    recPattern.Options.RecurrenceType = xtpCalendarRecurrenceDaily
    recPattern.Options.DailyIntervalDays = 1
    recPattern.Options.DailyEveryWeekDayOnly = False
       
    masterEv.UpdateRecurrence recPattern
       
    CalendarControl.DataProvider.AddEvent masterEv
   
    '**************************
    Dim excepEv As CalendarEvent
    Set excepEv = CalendarControl.DataProvider.CreateEvent()
   
    ' original times
    excepEv.StartTime = DateAdd("d", 1, dtTooday) + #3:00:00 PM#
    excepEv.EndTime = DateAdd("n", 60, excepEv.StartTime)
   
    excepEv.MakeAsRExceptionEx recPattern.Id
    ' new times   
    excepEv.StartTime = DateAdd("d", 1, dtTooday) + #2:00:00 PM#
    excepEv.EndTime = DateAdd("n", 260, excepEv.StartTime)
   
    excepEv.Subject = "Excep Ev (for WaaZ)"
 
    CalendarControl.DataProvider.ChangeEvent excepEv
   
    CalendarControl.Populate
    CalendarControl.RedrawControl

_______________

--
WBR,
Serge
Back to Top
WaaZ View Drop Down
Senior Member
Senior Member


Joined: 31 January 2006
Location: United Kingdom
Status: Offline
Points: 103
Post Options Post Options   Thanks (0) Thanks(0)   Quote WaaZ Quote  Post ReplyReply Direct Link To This Post Posted: 12 February 2006 at 12:02pm

Thnks. it works now.

We are all looking foward for version 10.

Thnks

WaaZ

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.125 seconds.