#include "FiveWin.Ch"
#include "ord.ch"
#include "xbrowse.ch"
//----------------------------------------------------------------------------//
REQUEST DBFCDX
static cFwhPath := "c:\work\fwh\"
//----------------------------------------------------------------------------//
function Main()
BrowseTree( MakeTree() )
return (0)
//----------------------------------------------------------------------------//
init procedure PrgInit
SET DATE ITALIAN
SET CENTURY ON
SET TIME FORMAT TO "HH:MM:SS"
SET EPOCH TO YEAR(DATE())-50
SET DELETED ON
SET EXCLUSIVE OFF
RDDSETDEFAULT( "DBFCDX" )
XbrNumFormat( 'E', .t. )
SetKinetic( .f. )
SetGetColorFocus()
SetBalloon( .t. )
return
//----------------------------------------------------------------------------//
static function MakeTree()
field STATE,CODE,CITY
local cPath := cFwhPath + "samples\\"
local oTree, oState, oCity
USE ( cPath + "STATES" ) NEW SHARED
INDEX ON CODE TAG CODE TO STMP MEMORY
USE ( cPath + "CUSTOMER" ) NEW ALIAS CUST SHARED
INDEX ON STATE+CITY TAG STATE TO CTMP MEMORY
SET RELATION TO STATE INTO STATES
GO TOP
TREE oTree
oTree:Cargo := { "", 0, 0.00, 0 }
do while ! CUST->( eof() )
TREEITEM oState PROMPT STATES->NAME CARGO { CTOD( "" ), 0, 0.00, 0 }
TREE
do while STATES->NAME == oState:cPrompt .and. ! CUST->( eof() )
TREEITEM oCity PROMPT CUST->CITY ;
CARGO { CUST->HIREDATE, CUST->AGE, CUST->SALARY, CUST->( RECNO() ) }
oState:Cargo[ 2 ] += oCity:Cargo[ 2 ]
oState:Cargo[ 3 ] += oCity:Cargo[ 3 ]
CUST->( DbSkip( 1 ) )
enddo
TREEITEM "Sub-Total" CARGO oState:Cargo
oTree:Cargo[ 2 ] += oState:Cargo[ 2 ]
oTree:Cargo[ 3 ] += oState:Cargo[ 3 ]
ENDTREE
enddo
ENDTREE
return oTree
//----------------------------------------------------------------------------//
static function BrowseTree( oTree )
local oDlg, oBrw, oFont
local nGrpClr := RGB(255,250,220)
local nTotClr := RGB(200,255,200)
DEFINE FONT oFont NAME "TAHOMA" SIZE 0,-14
DEFINE DIALOG oDlg SIZE 620,700 PIXEL FONT oFont ;
TITLE "EDITABLE TREE BROWSE WITH SUBTOTALS"
@ 20,10 XBROWSE oBrw SIZE -10,-10 PIXEL OF oDlg DATASOURCE oTree ;
COLUMNS 1, 2, 3 ;
HEADERS "State/City", "HireDate", "Number", "Salary" ;
PICTURES nil, nil, nil, NumPict ( 12, 2 ) ;
CELL LINES FOOTERS FASTEDIT NOBORDER
WITH OBJECT oBrw
:nStretchCol := 1
:lDisplayZeros := .f.
:bChange := { || CUST->( DBGOTO( oBrw:oTreeItem:Cargo[ 4 ] ) ) }
:bLock := { || CUST->( RLOCK() ) }
:bUnLock := { || CUST->( DBUNLOCK() ) }
:bClrStd := { || { CLR_BLACK, If( oBrw:oTreeItem:nLevel == 1, nGrpClr, ;
If( oBrw:oTreeItem:cPrompt == "Sub-Total", nTotClr, ;
CLR_WHITE ) ) } }
// Bitmaps
WITH OBJECT :aCols[ 1 ]
:AddBitmap( { FWRArrow(), FWDArrow(), cFwhPath + "bitmaps\16x16\reset.bmp" } )
:cFooter := "GRAND TOTAL"
END
// When Group is closed show totals. When open show totals at bottom
// Allow edit of columns and save data to DBF, update group and grand totals
WITH OBJECT :aCols[ 3 ]
:bEditValue := { |x| If( oBrw:oTreeItem:lOpened, 0, ;
If( x == nil, oBrw:oTreeItem:Cargo[ 2 ], ;
CUST->AGE := oBrw:oTreeItem:Cargo[ 2 ] := x ) ) }
:nTotal := oTree:Cargo[ 2 ]
//
:nEditType := EDIT_GET
:bEditWhen := { || oBrw:oTreeItem:nLevel > 1 .and. oBrw:oTreeItem:cPrompt != "Sub-Total" }
:bOnChange := { |o,nOld| oBrw:oTreeItem:Parent():Cargo[ 2 ] += ( o:Value - nOld ), oBrw:Refresh() }
END
WITH OBJECT :aCols[ 4 ]
:bEditValue := { |x| If( oBrw:oTreeItem:lOpened, 0, ;
If( x == nil, oBrw:oTreeItem:Cargo[ 3 ], ;
CUST->SALARY := oBrw:oTreeItem:Cargo[ 3 ] := x ) ) }
:nTotal := oTree:Cargo[ 3 ]
//
:nEditType := EDIT_GET
:bEditWhen := { || oBrw:oTreeItem:nLevel > 1 .and. oBrw:oTreeItem:cPrompt != "Sub-Total" }
:bOnChange := { |o,nOld| oBrw:oTreeItem:Parent():Cargo[ 3 ] += ( o:Value - nOld ), oBrw:Refresh() }
END
//
:CreateFromCode()
END
Eval( oBrw:bChange )
ACTIVATE DIALOG oDlg CENTERED
RELEASE FONT oFont
return nil
//----------------------------------------------------------------------------//
Return to FiveWin for Harbour/xHarbour
Users browsing this forum: No registered users and 53 guests