#include "fivewin.ch"
#include "calendar.ch"
#include "calex.ch"
#include "tselex.ch"
#include "ord.ch"
#include "tdolphin.ch"
REQUEST DBFCDX
function Main()
SET DATE FORMAT "MM/DD/YYYY"
SET DELETE ON
SampleCalex():New()
return nil
//---------------------------------------------------//
CLASS SampleCalex
DATA dDateStart, dDateEnd
DATA oServer
DATA lOnPreNext
DATA oCalex
DATA oDtPick
DATA oExBar
DATA oPanelExplorer
DATA oPanelCalex
DATA oWnd
DATA oSelex
METHOD New()
METHOD AddDates()
METHOD connectMySql()
METHOD BuildCalex()
METHOD BuildDialog()
METHOD BuildExplorer()
METHOD BuildPanels()
METHOD BuildPop( oView, dDateFrom, dDateTo, nTimeFrom, nTimeTo )
METHOD ChangeSelex()
METHOD ChangeDate()
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.
::connectMySql()
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
local oQry
// compat with xharbour
DEFAULT dStart := CToD( " / / " )
DEFAULT dEnd := CToD( " / / " )
oQry = ::oServer:Query( "SELECT * FROM citas WHERE concat( dstart + '', start + '' ) >= '" + DToS( dStart ) + Str( nStart * 100, 4 ) +;
"' AND concat( dstart + '', start + '' ) <= '" + DToS( dEnd ) + Str( nEnd * 100, 4 ) + "'" )
::oCalex:Reset()
DO WHILE ! oQry:Eof()
::oCalex:LoadDates( oQry:start,;
oQry:endi, ;
oQry:dstart, ;
oQry:dstart, ;
oQry:texto, ;
oQry:subject,;
oQry:idx )
oQry:Skip()
ENDDO
oQry:End()
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 0 ;
END HOUR 25;
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 connectMysql() CLASS SampleCalex
local cHost:="dolphintest.sitasoft.net"
local cUser:="test_dolphin"
local cPsw:="123456"
local nFlags:=0x20000
local nPort:=3306
local cDBName:="dolphin_man"
CONNECT ::oServer HOST chost ;
USER cUser ;
PASSWORD cpsw ;
PORT nPort ;
FLAGS nFlags;
DATABASE cDBName
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
local aMod
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
if lNew
::oServer:hInsert( "citas", { "start" => nTimeFrom, "endi" => nTimeTo, "dstart" => dDateFrom, "subject" => cSubject, "texto" => cText } )
else
::oServer:hUpdate( "citas", { "start" => nTimeFrom, "endi" => nTimeTo, "dstart" => dDateFrom, "subject" => cSubject, "texto" => cText },;
"idx = " + ClipValue2Sql( o:nIdx ) )
endif
::AddDates( oView:dStart, oView:dEnd, oView:nStartHour, oView:nEndHour )
oView:BuildDates()
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 | ::ChangeDate( o ) }
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
::oServer:Execute( "DELETE FROM citas WHERE idx = " + ClipValue2Sql( nIdx ) )
RETURN NIL
//---------------------------------------------------//
METHOD ChangeDate( oDatePick ) CLASS SampleCalex
::oCalex:oView:SetDate( oDatePick:GetDate() )
if ::oCalex:oView:IsKindOf( "TMONTHVIEW" )
::oCalex:SetMonthView()
elseif ::oCalex:oView:IsKindOf( "TWEEKVIEW" )
::oCalex:SetWeekView()
else
::oCalex:SetDayView()
endif
RETURN NIL
//---------------------------------------------------//