Codejock Forums Homepage
Forum Home Forum Home > Codejock Products > ActiveX COM > Calendar
  New Posts New Posts RSS Feed - Moving the calendar back and forward through dates
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

Moving the calendar back and forward through dates

 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: Moving the calendar back and forward through dates
    Posted: 01 November 2006 at 7:16am

Using 9.81 ActiveX

I keep getting the following error when the user press the forward or back button below is the error and below that is the code which produces the error. This problem does not show on my computer but only on some computers.

Exception:
 
System.Exception: TargetInvocationException in Navigate_Cal_Back_And_Forward()., CalendarControl.ViewType = xtpCalendarDayView, CalendarControl.ActiveView.DaysCount = 1, date range = 2006-11-02 00:00:00.000 to 2006-11-02 00:00:00.000
 
Stack Trace:
 
JotmeApp.Calendar.CalendarBoardControl.Navigate_Cal_Back_And_Forward
   at JotmeApp.Calendar.CalendarBoardControl.Navigate_Cal_Back_And_Forward(Boolean forward)
   at JotmeApp.Calendar.CalendarBoardControl.Cal_Move_Forward_Click(Object sender, EventArgs e)
   at System.Windows.Forms.Control.OnClick(EventArgs e)
   at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
   at System.Windows.Forms.Control.WndProc(Message& m)
   at System.Windows.Forms.Label.WndProc(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
   at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
 
Now the code which produces the error:
 

private void Navigate_Cal_Back_And_Forward(bool forward)

{

DateTime DateBegin = DateTime.Today;

DateTime DateEnd = DateTime.Today;

AxXtremeCalendarControl.AxDatePicker datePicker = this.mainFromRef.DatePicker;

if (datePicker.Selection.BlocksCount > 0)

{

DateBegin = datePicker.Selection[0].DateBegin;

DateEnd = datePicker.Selection[0].DateEnd;

}

switch (CalendarControl.ViewType)

{

case CalendarViewType.xtpCalendarDayView:

case CalendarViewType.xtpCalendarWorkWeekView:

//************ DEBUG VERSION ******************************************

int daysCount = CalendarControl.ActiveView.DaysCount;

DateTime rangeStart = DateBegin.AddDays(forward

? daysCount

: -daysCount

);

DateTime rangeEnd = DateEnd.AddDays(forward

? daysCount

: -daysCount

);

Application.DoEvents();

try

{

if (!CalendarControl.IsDisposed)

{

CalendarControl.DayView.ShowDays(rangeStart, rangeEnd);

}

}

catch (Exception ex)

{

throw new Exception(ex.GetType().Name + " in Navigate_Cal_Back_And_Forward()."

+ ", CalendarControl.ViewType = " + CalendarControl.ViewType.ToString()

+ ", CalendarControl.ActiveView.DaysCount = " + daysCount

+ ", date range = " + rangeStart.ToString("yyyy-MM-dd HH:mm:ss.fff")

+ " to " + rangeEnd.ToString("yyyy-MM-dd HH:mm:ss.fff")

);

}

//************ DEBUG VERSION ******************************************

break;

case CalendarViewType.xtpCalendarMonthView:

if (forward)

{

CalendarControl.ViewChanged -= new System.EventHandler(this.CalendarControl_ViewChanged);

CalendarControl.ActiveView.ShowDay(DateEnd.AddDays(5), true);

CalendarControl.ViewChanged += new System.EventHandler(this.CalendarControl_ViewChanged);

CalendarControl.ViewType = XtremeCalendarControl.CalendarViewType.xtpCalendarMonthView;

}

else

{

CalendarControl.ViewChanged -= new System.EventHandler(this.CalendarControl_ViewChanged);

CalendarControl.ActiveView.ShowDay(DateBegin.AddDays(-5), true);

CalendarControl.ViewChanged += new System.EventHandler(this.CalendarControl_ViewChanged);

CalendarControl.ViewType = XtremeCalendarControl.CalendarViewType.xtpCalendarMonthView;

}

break;

case CalendarViewType.xtpCalendarWeekView:

if (forward)

{

CalendarControl.ActiveView.ShowDay(DateEnd.AddDays(1), false);

}

else

{

CalendarControl.ActiveView.ShowDay(DateBegin.AddDays(-1), false);

}

break;

}

}

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: 03 November 2006 at 5:22am
CodeJock people, I have a new patch comming out this weekend and I would really appreciate a reply.
 
Thanks
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 November 2006 at 11:50am
Hi,

I think I see the problem. It might happen because Dates are represented in OLE by Double values. And 2 equal Dates could be represented by not exactly same Doubles. The defference is small, but we have to keep in mind this when compare Dates. This is not implemented in ShowDays and as a result sometimes it removes all days and do not adds one.
 
To avoid that use ShowDay method to show only one day.

--
WBR,
Serge
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 November 2006 at 11:51am
Another possible easy solution would be to add some amount of time to rangeEnd (1 minute for example). In this case Doubles should be compared fine...

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