#include "fivewin.ch"
#include "calendar.ch"
#include "calex.ch"
#include "tselex.ch"
#include "ord.ch"
REQUEST DBFCDX
function Main()
SET DATE FORMAT "MM/DD/YYYY"
SET DELETE ON
SampleCalex():New()
return nil
//---------------------------------------------------//
CLASS SampleCalex
DATA dDateStart, dDateEnd
DATA cAlias
DATA lOnPreNext
DATA oCalex
DATA oDtPick
DATA oExBar
DATA oPanelExplorer
DATA oPanelCalex
DATA oWnd
DATA oSelex
METHOD New()
METHOD AddDates()
METHOD BuildCalex()
METHOD BuildDbf()
METHOD BuildDialog()
METHOD BuildExplorer()
METHOD BuildPanels()
METHOD BuildPop( oView, dDateFrom, dDateTo, nTimeFrom, nTimeTo )
METHOD ChangeSelex()
METHOD DeleteInfo( oView, nIdx )
METHOD SetSize( nType, nWidth, nHeight )
ENDCLASS
//---------------------------------------------------//
METHOD New() CLASS SampleCalex
local oMenu
local oSelf := Self
MENU oMenu
ENDMENU
::dDateStart = Date()
::dDateEnd = Date()
::lOnPreNext = .F.
::cAlias = "citas"
::BuildDbf()
DEFINE WINDOW ::oWnd MDI MENU oMenu
::BuildPanels()
::BuildExplorer()
::BuildCalex()
// ::Adddates()
ACTIVATE WINDOW ::oWnd MAXIMIZED;
ON RESIZE oSelf:SetSize( nSizeType, nWidth, nHeight )
RETURN Self
//---------------------------------------------------//
METHOD AddDates( dStart, dEnd, nStart, nEnd ) CLASS SampleCalex
local dDate
// compat with xharbour
DEFAULT dStart := CToD( " / / " )
DEFAULT dEnd := CToD( " / / " )
//Clear scopes
( ::cAlias )->( OrdSetFocus( "fecha" ) )
( ::cAlias )->( OrdScope( TOPSCOPE, NIL ) )
( ::cAlias )->( OrdScope( BOTTOMSCOPE, NIL ) )
//Set New scopes
( ::cAlias )->( DBGoTop() )
( ::cAlias )->( OrdScope( TOPSCOPE, DToS( dStart ) + Str( nStart * 100, 4 ) ) )
( ::cAlias )->( OrdScope( BOTTOMSCOPE, DToS( dEnd ) + Str( nEnd * 100, 4 ) ) )
( ::cAlias )->( DBGoTop() )
::oCalex:Reset()
DO WHILE ! ( ::cAlias )->( Eof() )
::oCalex:LoadDates( ( ::cAlias )->START,;
( ::cAlias )->END, ;
( ::cAlias )->DSTART, ;
( ::cAlias )->DSTART, ;
( ::cAlias )->TEXT, ;
( ::cAlias )->SUBJECT,;
( ::cAlias )->IDX )
( ::cAlias )->( DBSkip() )
ENDDO
RETURN nil
//---------------------------------------------------//
METHOD BuildCalex() CLASS SampleCalex
local oSelf := Self
DEFINE CALEX ::oCalex OF ::oPanelCalex;
FIRST_DATE 2
DEFINE MONTH VIEW OF ::oCalex;
ON SELECT VIEW ( oSelf:AddDates( ::dStart, ::dEnd, ::nStartHour, ::nEndHour ), ;
oSelf:oDtPick:SetDate( ::dDateSelected ) ) ;
ON SELECT DAY oSelf:oDtPick:SetDate( dDate ) ;
ON SELECT WEEK oSelf:oDtPick:SetDate( dDate ) ;
ON NEXT ( oSelf:oDtPick:SetDate( dDate ), ;
oSelf:AddDates( ::dStart, ::dEnd, ::nStartHour, ::nEndHour ) );
ON PREV ( oSelf:oDtPick:SetDate( dDate ), ;
oSelf:AddDates( ::dStart, ::dEnd, ::nStartHour, ::nEndHour ) );
ACTIVATE
//Day
DEFINE DAY VIEW OF ::oCalex ;
INTERVAL 30 ;
START HOUR 2 ;
END HOUR 19;
ON SELECT VIEW ( oSelf:AddDates( ::dStart, ::dEnd, ::nStartHour, ::nEndHour ), ;
oSelf:oDtPick:SetDate( ::dDateSelected ) ) ;
ON NEXT ( oSelf:oDtPick:SetDate( dDate ), ;
oSelf:AddDates( ::dStart, ::dEnd, ::nStartHour, ::nEndHour ) );
ON PREV ( oSelf:oDtPick:SetDate( dDate ), ;
oSelf:AddDates( ::dStart, ::dEnd, ::nStartHour, ::nEndHour ) );
ON RIGHT CLICK ( oSelf:BuildPop( nRow, nCol, Self, dDateFrom, dDateTo, nTimeFrom, nTimeTo ) );
ON DELETE ( oSelf:DeleteInfo( Self, nIdx ) )
//Week
DEFINE WEEK VIEW OF ::oCalex ;
INTERVAL 30 ;
START HOUR 2 ;
END HOUR 19;
ON SELECT VIEW ( oSelf:oDtPick:SetDate( oLast:dDateSelected - DoW( oLast:dDateSelected ) + 1 ),;
oSelf:AddDates( ::dStart, ::dEnd, ::nStartHour, ::nEndHour ) ) ;
ON RIGHT CLICK ( oSelf:BuildPop( nRow, nCol, Self, dDateFrom, dDateTo, nTimeFrom, nTimeTo ) ) ;
ON NEXT ( oSelf:oDtPick:SetDate( dDate ), ;
oSelf:AddDates( ::dStart, ::dEnd, ::nStartHour, ::nEndHour ) );
ON PREV ( oSelf:oDtPick:SetDate( dDate ), ;
oSelf:AddDates( ::dStart, ::dEnd, ::nStartHour, ::nEndHour ) );
ON DELETE ( oSelf:DeleteInfo( Self, nIdx ) )
RETURN nil
//---------------------------------------------------//
METHOD BuildDbf() CLASS SampleCalex
local aStructure
if ! File( "citas.dbf" )
aStructure = { { "start" , "N", 4, 0 },;
{ "end" , "N", 4, 0 },;
{ "dstart" , "D", 8, 0 },;
{ "subject", "C", 100, 0 },;
{ "text" , "M", 10, 0 },;
{ "idx" , "N", 10, 0 } }
DBCreate( ::cAlias, aStructure, "DBFCDX" )
ENDIF
USE ( ::cAlias ) ALIAS ( ::cAlias ) VIA "DBFCDX"
INDEX ON DToS( citas->DSTART ) + StrZero( citas->START, 4 ) TAG fecha TO ( ::cAlias )
INDEX ON citas->IDX TAG idx TO ( ::cAlias )
RETURN nil
//---------------------------------------------------//
METHOD BuildDialog( oView, dDateFrom, dDateTo, nTimeFrom, nTimeTo ) CLASS SampleCalex
local oDlg
local cSubject := Space( 100 )
local cText
local lSave := .F.
local lNew := oView:oCalex:oCalInfoSelected == NIL
local o, nID, cLastOrd
DEFINE DIALOG oDlg TITLE "Adding Data" SIZE 300, 370
if ! lNew
o = oView:oCalex:oCalInfoSelected
cSubject = o:cSubject
cText = o:cText
endif
@ 10, 10 SAY "Date: " + DToC( dDateFrom ) OF oDlg PIXEL
@ 25, 10 SAY "Time Start: [" + oView:ConvertTime( nTimeFrom, oView:lAmPm ) +;
"] -- Time End: [" + oView:ConvertTime( nTimeTo, oView:lAmPm ) + "]" OF oDlg PIXEL
@ 40, 10 SAY "Subject" OF oDlg PIXEL
@ 40, 30 GET cSubject OF oDlg PIXEL SIZE 100, 10
@ 55, 10 SAY "Text" OF oDlg PIXEL
@ 70, 10 GET cText MEMO OF oDlg PIXEL SIZE 130, 95
@ 170, 10 BUTTON "OK" PIXEL ACTION ( lSave := .T., oDlg:End() )
@ 170, 100 BUTTON "CANCEL" PIXEL ACTION ( oDlg:End() )
ACTIVATE DIALOG oDlg CENTERED
IF lSave
cLastOrd = ( ::cAlias )->( OrdSetFocus( "idx" ) )
if lNew
nID = ( ::cAlias )->( DBGoBottom() )
nID = ( ::cAlias )->IDX + 1
( ::cAlias )->( DBAppend() )
REPLACE ( ::cAlias )->IDX WITH nID
else
( ::cAlias )->( DBSeek( o:nIdx ) )
o:cSubject = cSubject
o:cText = cText
endif
REPLACE ( ::cAlias )->start WITH nTimeFrom
REPLACE ( ::cAlias )->end WITH nTimeTo
REPLACE ( ::cAlias )->dstart WITH dDateFrom
REPLACE ( ::cAlias )->subject WITH cSubject
REPLACE ( ::cAlias )->text WITH cText
( ::cAlias )->( DBCommitAll() )
::AddDates( oView:dStart, oView:dEnd, oView:nStartHour, oView:nEndHour )
oView:BuildDates()
( ::cAlias )->( OrdSetFocus( cLastOrd ) )
ENDIF
RETURN nil
//---------------------------------------------------//
METHOD BuildExplorer() CLASS SampleCalex
local oPanel
local oSelf := Self
local nOption := 5
::oExBar := TExplorerBar():New( 0, 0, 250, 300, ::oPanelExplorer )
oPanel := ::oExBar:AddPanel( "Jump To Date", "c:\fwh\bitmaps\32x32\people.bmp", 200 )
@ 40, 15 CALENDAR ::oDtPick VAR ::dDateStart OF oPanel PIXEL;
SIZE 220, 157;
::oDtPick:bChange = { | o | ::oCalex:SetDate( o:GetDate() ), oSelf:oCalex:Refresh(), SysRefresh() }
oPanel := ::oExBar:AddPanel( "View", "c:\fwh\bitmaps\32x32\people.bmp", 130 )
oPanel:AddLink( "Daily" , { || ::oCalex:SetDayView(), ::ChangeSelex() }, "c:\fwh\bitmaps\16x16\additem.bmp" )
oPanel:AddLink( "Weekly" , { || ::oCalex:SetWeekView(), ::ChangeSelex() }, "c:\fwh\bitmaps\16x16\additem.bmp" )
oPanel:AddLink( "Monthly", { || ::oCalex:SetMonthView() }, "c:\fwh\bitmaps\16x16\additem.bmp" )
@ 100, 10 SELEX ::oSelex VAR nOption of oPanel PIXEL size 220, 45;
ITEMS "5", "10", "15", "20", "30", "60" ;
GRADIENT OUTTRACK { { 1/2, nRGB( 219, 230, 244 ), nRGB( 207-50, 221-25, 255 ) }, ;
{ 1/2, nRGB( 201-50, 217-25, 255 ), nRGB( 231, 242, 255 ) } };
LINECOLORS nRGB( 237, 242, 248 ), nRGB( 141, 178, 227 );
COLORTEXT CLR_BLACK, CLR_GREEN ;
ACTION (::oCalex:oView:SetInterval( Val( ::oSelex:aOptions[ nOption ] ) ), ::oCalex:refresh() )
::oPanelExplorer:oClient = ::oExBar
::oPanelExplorer:oClient:bMouseWheel = {|| MsgInfo( "ok" ) }
RETURN nil
//---------------------------------------------------//
METHOD BuildPanels() CLASS SampleCalex
local oBrush
::oPanelExplorer = TPanel():New( 0, 0, ::oWnd:nHeight, 280, ::oWnd:oWndClient )
::oPanelCalex = TPanel():New( 0, 281, ::oWnd:nHeight, ::oWnd:nWidth, ::oWnd:oWndClient )
DEFINE BRUSH oBrush COLOR CLR_WHITE
::oPanelCalex:SetBrush( oBrush )
oBrush:End()
RETURN nil
//---------------------------------------------------//
METHOD ChangeSelex() CLASS SampleCalex
local cInterval := AllTrim( Str( ::oCalex:oView:nInterval * 60, 2 ) )
local nAt := AScan( ::oSelex:aOptions, cInterval )
if nAt != 0 .and. ::oSelex:nOption != nAt
::oSelex:SetOption( nAt )
::oSelex:Refresh()
endif
RETURN nil
//---------------------------------------------------//
METHOD SetSize( nType, nWidth, nHeight ) CLASS SampleCalex
if nWidth != nil
::oPanelExplorer:Move( , , , nHeight )
::oPanelCalex:Move( , , nWidth - ::oPanelExplorer:nRight, nHeight )
endif
RETURN nil
//---------------------------------------------------//
METHOD BuildPop( nRow, nCol, oView, dDateFrom, dDateTo, nTimeFrom, nTimeTo ) CLASS SampleCalex
local oMenu
local oSelf := Self
local lNew := oView:oCalex:oCalInfoSelected == NIL
MENU oMenu POPUP
MENUITEM If( lNew, "New appointment",;
"Modify appointment" ) ACTION oSelf:BuildDialog( oView, dDateFrom, dDateTo, nTimeFrom, nTimeTo )
if ! lNew
MENUITEM "Delete appointment" ACTION If( MsgYesNo( "Are you sure?" ), oView:oCalex:DelCalInfo(), )
endif
MENUITEM "Today" ACTION ( oView:SetDate( date() ), If( oView:IsKindOf( "TWEEKVIEW" ),;
oView:oCalex:SetWeekView(),;
oView:oCalex:SetDayView() ) )
ENDMENU
ACTIVATE POPUP oMenu OF oView:oCalex AT nRow, nCol
RETURN nil
//---------------------------------------------------//
METHOD DeleteInfo( oView, nIdx ) CLASS SampleCalex
local cLastOrd
cLastOrd = ( ::cAlias )->( OrdSetFocus( "idx" ) )
( ::cAlias )->( DBSeek( nIdx ) )
( ::cAlias )->( DBDelete() )
( ::cAlias )->( OrdSetFocus( cLastOrd ) )
RETURN NIL
//---------------------------------------------------//