Hi everyone;
Just came across this post, and thought I should share some answers. Yes, CodeJock calendar control does work with dbfs/ adts/ xml/ mdb/ SQL/ arrays/ Objects, or just about any other type of data.
Here is a short sample on working with a tdata class based on dbfs. I'm trying to keep the code simple. The intent is show how to connect dbf data to CodeJock ExtremeCalendar Control:
- Code: Select all Expand view RUN
//create the object
::oCalex := tActiveX():New( ::oPanelCalex, "Codejock.CalendarControl.13.4.2" )
//set some properties
with object ::oCalex
:VisualTheme( xtpCalendarThemeOffice2007 )
:bOnEvent = { | event, aParms | ::xTrmCalTriggeredEvents( Event, aParms ) }
:SetDataProvider( "provider=custom" )
if !:DataProvider:open() ;:DataProvider:Create() ;endif
:ShowCaptionBar( .t. )
:ViewType( xtpCalendarDayView )
:DayView:ShowLinks( .t. )
:DayView:TimeScaleMinTime( [8:00:00 AM] )
:DayView:TimeScaleMaxTime( [6:00:00 PM] )
:DayView:TimeScale( 10 )
:DayView:ScrollToWorkDayBegin() //scroll the view to the work day starting time
:Options:DayViewTimeScaleShowMinutes( .t. )
end
//now all you have to do is create the triggered events to write/read from dbfs
- Code: Select all Expand view RUN
//-----------------------------------------------------------------------------------------------------//
METHOD xTrmCalTriggeredEvents( Event, aParms ) CLASS MpCal
if valType( Event ) == "C"
Do Case
Case Event == "DoRetrieveDayEvents"
::RetrieveDayEvents( aParms )
case Event == "EventAddedEx"
::InsertEvent( aParms[ 1 ] )
case Event == "EventChangedEx"
::UpdateEvent( aParms[ 1 ] )
case Event == "EventDeletedEx"
::DeleteAppnt( aParms[ 1 ] )
End
endif
Return nil
//-----------------------------------------------------------------------------------------------------//
METHOD InsertEvent( oEvent ) CLASS MpCal
::odbf:VarSubject := oEvent:Subject()
::odbf:VarStartTime := oEvent:StartTime()
::odbf:VarEndTime := oEvent:EndTime()
::odbf:VarMore_Info := oEvent:Body()
::odbf:Append()
::odbf:Save()
//fill in a custom property on this entry to link to unique key on dbf. Field Guid is auto-field using
//an On-Insert trigger on the dbf and it defaults to a global unique string used as primary key.
oEvent:CustomProperties:Property( "guid", ::odbf:Guid )
//every time a new appointment is added on the calendar control
//expand appntmnt details with a custom form for tel, med rec, email...
::EventDetails( oEvent )
Return oEvent
//-----------------------------------------------------------------------------------------------------//
//using SQL is less writing, but the same can be done with ISAM.
METHOD UpdateEvent( oEvent ) CLASS MpCal
local cSql := "Update appntmnts set Subject = '" + oEvent:Subject() + "', " +;
"StartTime = Convert( '" + TtoC( oEvent:StartTime() ) + "', SQL_TIMESTAMP ), " +;
"EndTime = Convert( '" + TtoC( oEvent:EndTime() ) + "', SQL_TIMESTAMP ), " +;
"More_Info = '" + oEvent:Body() + "' " + ;
"Where guid = '" + oEvent:CustomProperties:Property( "Guid" ) + "'"
ExecuteSqlScript( cSql, .f. )
::EventDetails( oEvent )
return oEvent
//-----------------------------------------------------------------------------------------------------//
METHOD DeleteAppnt( oEvent ) CLASS MpCal
local cSql := "Delete from appntmnts " + ;
"Where guid = '" + oEvent:CustomProperties:Property( "Guid" ) + "'"
ExecuteSqlScript( cSql, .f. )
return oEvent
//-----------------------------------------------------------------------------------------------------//
//CodeJock ExtremeCalender control calls this function sending a DT parameter and
//the container property that contains all the day entries. The function should fill in
//the container property with all day events (appointments)
METHOD RetrieveDayEvents( aParms ) CLASS MpCal
Local cSql := "Select mrec, Subject, Last_Name, First_Name, StartTime, EndTime, eMail, Tel, GuId, More_Info " + ;
"from appntmnts where convert( StartTime, SQL_DATE )= '" + Date2SqlString( aParms[ 1 ] ) + "'"
local arec
local aRet := ExecuteSQLScript( cSql, .f. )
local oEvents := aParms[ 2 ]
local oEvent
for each arec in aret
oEvent := ::oCalex:DataProvider:CreateEvent()
With Object oEvent
:Subject( aRec[ 2 ] ) //TokenUpper( trim( aRec[ 3 ] ) + " " + trim( arec[ 4 ] ) ) )
:StartTime( aRec[ 5 ] )
:EndTime( aRec[ 6 ] )
:body( arec[ 10 ] )
:CustomProperties:Property( "MRec", alltrim( aRec[ 1 ] ) )
:CustomProperties:Property( "Guid", aRec[ 9 ] )
:CustomProperties:Property( "Tel", aRec[ 8 ] )
:CustomProperties:Property( "eMail", aRec[ 7 ] )
End
oEvents:add( oEvent )
next
Retur Nil
It works really nice. If anyone needs help, I'll be glad to offer my help. Here is a screenshot:
Reinaldo.