Print Page | Close Window

Moving the calendar back and forward through dates

Printed From: Codejock Forums
Category: Codejock Products
Forum Name: Calendar
Forum Description: Topics Related to Codejock Calendar
URL: http://forum.codejock.com/forum_posts.asp?TID=5398
Printed Date: 22 November 2024 at 9:06pm
Software Version: Web Wiz Forums 12.04 - http://www.webwizforums.com


Topic: Moving the calendar back and forward through dates
Posted By: WaaZ
Subject: Moving the calendar back and forward through dates
Date 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;

}

}




Replies:
Posted By: WaaZ
Date 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


Posted By: sserge
Date 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


Posted By: sserge
Date 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



Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.04 - http://www.webwizforums.com
Copyright ©2001-2021 Web Wiz Ltd. - https://www.webwiz.net