Code: Select all
// FiveWin - DataBase Objects Tutorial - 01
// FiveWin DataBase tools
#include "FiveWin.ch"
#include "Dbfown.ch"
static oWnd
//----------------------------------------------------------------------------//
function Main()
SET _3DLOOK ON
DEFINE WINDOW oWnd FROM 2, 2 TO 20, 70 ;
TITLE "Testing DataBase Objects" ;
MENU BuildMenu()
SET MESSAGE OF oWnd ;
TO "FiveWin - Object Oriented DataBase Management" CENTERED
oWnd:bLDblClick = { || MsgInfo( "Double Left Click" ) }
ACTIVATE WINDOW oWnd MAXIMIZED ;
VALID MsgYesNo( "Do you really want to end ?" )
return nil
//----------------------------------------------------------------------------//
function BuildMenu()
local oMenu
MENU oMenu
MENUITEM "&Clients"
MENU
MENUITEM "&Record by Record..." ACTION ClientsRec() ;
MESSAGE "Clients record by record management dialog"
MENUITEM "&Browse..." ACTION ClientsBrowse() ;
MESSAGE "Clients browse management dialog"
SEPARATOR
MENUITEM "&Exit Test..." ACTION oWnd:End() ;
MESSAGE "End doing this tutorial"
ENDMENU
ENDMENU
return oMenu
//----------------------------------------------------------------------------//
function ClientsRec()
local oDbf, oDlg
local oBtnNew:="&New", oBtnTop:="&Top", ;
oBtnPrev:="&Previous", oBtnNext:="&Next", oBtnBottom:="&bottom", oBtnEnd:="&End"
local aButtons
local lNew := .f.
USE Customer
DATABASE oDbf // We create a DBF Object based on the current Alias
// Now we can change WorkArea and the DBF Object
// automatically access its area !
oDbf:bEoF = nil // We don't want default EOF processing
DEFINE DIALOG oDlg FROM 8, 2 TO 600, 700 PIXEL ;
TITLE ("Customer" )
@ 1,2 SAY "&First" OF oDlg PIXEL
@ 1,50 SAY ":" OF oDlg PIXEL
@ 1,60 GET oDbf:First OF oDlg PIXEL
@ 15,1 SAY "&Name" OF oDlg PIXEL
@ 15,50 SAY ":" OF oDlg PIXEL
@ 15,60 GET oDbf:Last OF oDlg PIXEL
@ 280, 10 BUTTON oBtnNew OF oDlg PIXEL SIZE 30, 12 ;
ACTION New( @lNew, oDbf, aButtons, oDlg ) ;
MESSAGE "Add a new customer"
@ 280, 50 BUTTON oBtnTop OF oDlg PIXEL SIZE 30, 12 ;
ACTION Top( @lNew, oDbf, aButtons, oDlg ) ;
MESSAGE "Go to the first record of the DataBase"
@ 280, 100 BUTTON oBtnPrev OF oDlg PIXEL SIZE 30, 12 ;
ACTION ( oDbf:Skip( -1 ), oDlg:Update() ) ;
MESSAGE "Go to the previous record of the DataBase"
@ 280, 150 BUTTON oBtnNext OF oDlg PIXEL SIZE 30, 12 ;
ACTION ( oDbf:Skip(),;
If( oDbf:Eof(), ( MsgStop( "EoF" ), oDbf:GoBottom() ),;
oDlg:Update() ) ) ;
MESSAGE "Go to the next record of the DataBase"
@ 280, 200 BUTTON oBtnBottom OF oDlg PIXEL SIZE 30, 12 ;
ACTION ( oDbf:GoBottom(), oDlg:Update() ) ;
MESSAGE "Go to the last record of the DataBase"
@ 280, 250 BUTTON oBtnEnd OF oDlg PIXEL SIZE 30, 12 ;
ACTION oDlg:End() ;
MESSAGE "End this dialog"
aButtons = { oBtnNew, oBtnTop, oBtnPrev, oBtnNext, oBtnBottom, oBtnEnd }
ACTIVATE DIALOG oDlg CENTERED ;
ON INIT ( oDlg:Update() )
USE
return nil
//----------------------------------------------------------------------------//
function New( lNew, oDbf, aButtons, oDlg )
local n
if ! lNew
aButtons[ 1 ]:SetText( "&Save" )
aButtons[ 2 ]:SetText( "&Cancel" )
for n = 3 to Len( aButtons )
aButtons[ n ]:Disable()
next
oDbf:Blank() // we 'clean' the DataBase buffer
oDlg:Update() // we refresh the controls
oDlg:aControls[ 1 ]:SetFocus() // we give focus to the first GET
else
oDbf:Append() // The user selected 'save'
oDbf:Save() // we copy from the DataBase buffer into the 'real' DBF
aButtons[ 1 ]:SetText( "&New" )
aButtons[ 2 ]:SetText( "&Top" )
for n = 3 to Len( aButtons )
aButtons[ n ]:Enable()
next
endif
lNew = ! lNew // we toggle the lNew value
return nil
//----------------------------------------------------------------------------//
function Top( lNew, oDbf, aButtons, oDlg )
local n
if ! lNew // the user wants to GO TOP
oDbf:GoTop()
oDlg:Update() // we repaint the controls containts
else // the user canceled the 'New' option
oDbf:Load() // reload again fields info from the DBF
oDlg:Update() // we repaint the controls contains
aButtons[ 1 ]:SetText( "&New" )
aButtons[ 2 ]:SetText( "&Top" )
for n = 3 to Len( aButtons )
aButtons[ n ]:Enable()
next
lNew = .f.
endif
return nil
//----------------------------------------------------------------------------//
function ClientsBrowse()
local oDlg, oDbf, oBrw, oFnt
USE customer
DATABASE oDbf
DEFINE DIALOG oDlg RESOURCE "Browse"
REDEFINE LISTBOX oBrw ;
FIELDS oDbf:first, oDbf:last ;
HEADERS "first", "last" ;
SIZES 250, 300 ;
ID 110 OF oDlg
// We change the skip codeblock of the browse, to be managed
// by the DataBase object skip method, so we can directly use
// oDbf:Name and oDbf:Adress in the above FIELDS ... clause
oBrw:bSkip = { | nRecs | oDbf:Skipper( nRecs ) }
oBrw:lAutoEdit = .T.
oBrw:cToolTip = "This is a test"
ACTIVATE DIALOG oDlg CENTERED
USE
return nil
//----------------------------------------------------------------------------//
procedure AppSys // XBase++ requirement
return
//----------------------------------------------------------------------------//