Sample:
Code:
- Code: Select all Expand view
- function XbUserDraw()
local oDlg, oBrw, oFont, oBold, oLarge, oSmall
local oHeadBrush
local aData := {}
local nOpgBal := 25000.00
FWNumFormat( 'A', .T. )
aData := GetData()
DEFINE FONT oLarge NAME "TAHOMA" SIZE 0,-26
DEFINE FONT oFont NAME "TAHOMA" SIZE 0,-14
DEFINE FONT oBold NAME "TAHOMA" SIZE 0,-16 BOLD
DEFINE BRUSH oHeadBrush FILE "..\bitmaps\backgrnd\stone.bmp"
DEFINE DIALOG oDlg SIZE 800,650 PIXEL TRUEPIXEL FONT oFont
@ 20,20 XBROWSE oBrw SIZE -20,-20 PIXEL OF oDlg ;
DATASOURCE aData ;
COLUMNS 2,3,4,5,6, 7 ;
HEADERS "DATE", "DETAILS", "QUANTITY", "RATE", "AMOUNT", Transform( nOpgBal, NumPict( 10, 2 ) ) ;
PICTURES nil, nil, "9999.999", "$ 999.99", '$ ' + NumPict( 7, 2 ), '$ ' + NumPict( 7, 2 ) ;
CELL FOOTERS NOBORDER STYLE FLAT
WITH OBJECT oBrw
:AddVar( "oFntLarge", oLarge )
:AddVar( "oHeadBrush", oHeadBrush )
:lRecordSelector := .f.
:lHScroll := .f.
:nRowDividerStyle := LINESTYLE_BLACK
:nHeaderHeight := 90
:nFooterHeight := 90
:nRowHeight := 25
:nStretchCol := 2
:nHeadStrAligns := { AL_RIGHT, AL_LEFT, AL_RIGHT, AL_RIGHT, AL_RIGHT, AL_RIGHT }
:nFootStrAligns := { AL_RIGHT, AL_LEFT, AL_RIGHT, AL_RIGHT, AL_RIGHT, AL_RIGHT }
:lDisplayZeros := .f.
:lAllowColSwapping := .f.
:oHeaderFonts := oBold
:oFooterFonts := oBold
:aCols[ 3 ]:bClrStd := { || { CLR_BLACK, RGB( 240, 240, 240 ) } }
:aCols[ 5 ]:bClrStd := :aCols[ 3 ]:bClrStd
:aCols[ 3 ]:nFooterType := AGGR_SUM
:aCols[ 5 ]:nFooterType := AGGR_SUM
:aCols[ 6 ]:nFooterType := AGGR_SUM
:aCols[ 6 ]:bFooter := { || oBrw:aCols[ 6 ]:nTotal + nOpgBal }
:bPaintRow := { | brw, nRow, nCol, nHeight, lHighLite, lSelect, nRowPos, nColSel, oColSel | PaintRow ;
( brw, nRow, nCol, nHeight, lHighLite, lSelect, nRowPos, nColSel, oColSel ) }
:bPaintHeader := { | brw, hDC, aCols, nLast, hWhitePen, hGrayPen, hColPen | BrwHeader ;
( brw, hDC, aCols, nLast, hWhitePen, hGrayPen, hColPen ) }
:bPaintFooter := { | brw, hDC, aCols, nLast, nGridWidth, nBrwHeight, hWhitePen, hGrayPen | BrwFooter ;
( brw, hDC, aCols, nLast, nGridWidth, nBrwHeight, hWhitePen, hGrayPen ) }
:lDrawBorder := .t.
//
:MakeTotals()
//
:CreateFromCode()
END
ACTIVATE DIALOG oDlg CENTERED
RELEASE FONT oFont, oLarge, oBold
RELEASE BRUSH oHeadBrush
return nil
//----------------------------------------------------------------------------//
function BrwHeader( Self, hDC, aCols, nLast, hWhitePen, hGrayPen, hColPen )
local aRect := { 1, 1, ::nHeaderHeight, ::BrwWidth() }
local hPen
local nRow, n, aBmp
local cHeader := "Painted using oBrw:bPaintHeader"
local oBrush
FillRect( hDC, aRect, ::oHeadBrush:hBrush )
hPen := createPen( PS_SOLID, 1, CLR_BLACK )
DrawHorz( hDC, 1, 0, ::BrwWidth(), hPen )
nRow := ::SayText( cHeader, aRect, "T", ::oFntLarge, CLR_HRED )
aBmp := ::ReadPalBmpEx( "..\bitmaps\pngs\image7.png" )
::SayPalBmp( aBmp, { 1, 1, ::nHeaderHeight - 24, 64 } )
PalBmpFree( aBmp )
for n := 1 to Len( ::aCols )
::aCols[ n ]:PaintHeader( ::nHeaderHeight - 30, nil, 26, .f., hDC )
next
::SayText( "Opening" + CRLF + "Balance", ;
{ 2, 1, ::nHeaderHeight - 23, ::BrwWidth() - 8 }, "R", ::aCols[ 6 ]:oHeaderFont, CLR_HRED )
DrawHorz( hDC, ::nHeaderHeight - 3, 0, ::BrwWidth(), hPen )
DrawHorz( hDC, ::nHeaderHeight - 1, 0, ::BrwWidth(), hPen )
DeleteObject( hPen )
return nil
//----------------------------------------------------------------------------//
static function BrwFooter( Self, hDC, aCols, nLast, nGridWidth, nBrwHeight, hWhitePen, hGrayPen )
local nRow := nBrwHeight - ::nFooterHeight + 1
local aRect := { nRow, 1, nBrwHeight - 1, nGridWidth }
local hPen := CreatePen( PS_SOLID, 1, CLR_BLACK )
local n, aBmp, nTotal, nTax
FillRect( hDC, aRect, ::oHeadBrush:hBrush )
DrawHorz( hDC, nRow, aRect[ 2 ], aRect[ 4 ], hPen )
aBmp := ::ReadPalBmpEx( "..\bitmaps\alphabmp\visa.bmp" )
::SayPalBmp( aBmp, { nRow, 1, nBrwHeight - 1, 96 } )
PalBmpFree( aBmp )
for n := 3 to 6
::aCols[ n ]:PaintFooter( nRow + 2, nil, 25 )
next
nRow += 25
::SayText( "Tax calculated @ 20% :", { nRow, 1, nRow + 25, ::aCols[ 6 ]:nDisplayCol - 6 }, ;
"R", ::aCols[ 1 ]:oFooterFont, CLR_HRED )
nTotal := Eval( ::aCols[ 6 ]:bFooter )
nTax := Round( nTotal * 0.2, 2 )
::SayText( Transform( nTax, ::aCols[ 6 ]:cEditPicture ), { nRow, ::aCols[ 6 ]:nDisplayCol, nRow + 25, ::BrwWidth() - 6 }, ;
"R", ::aCols[ 1 ]:oFooterFont, CLR_GREEN )
nRow += 25
::SayText( "GRAND TOTAL :", { nRow, 1, nRow + 25, ::aCols[ 6 ]:nDisplayCol - 6 }, ;
"R", ::aCols[ 1 ]:oFooterFont, CLR_HRED )
nTotal += nTax
::SayText( Transform( nTotal, ::aCols[ 6 ]:cEditPicture ), { nRow, ::aCols[ 6 ]:nDisplayCol, nRow + 25, ::BrwWidth() - 6 }, ;
"R", ::aCols[ 1 ]:oFooterFont, CLR_HRED )
return nil
//----------------------------------------------------------------------------//
static function PaintRow( Self, nRow, nCol, nHeight, lHighLite, lSelect, nRowPos, nColSel, oColSel )
local lPainted := .f.
local hDC, aColors
if Empty( ::aRow[ 1 ] )
return .t.
endif
if oColSel != nil .and. oColSel:nCreationOrder == 6
return .t.
endif
hDC := ::GetDC()
if lSelect .and. ::nColSel < 6
aColors := Eval( ::bClrSelFocus )
else
aColors := { CLR_BLACK, RGB( 255, 200, 160 ) }
endif
FillRectEx( hDC, { nRow, nCol, nRow + nHeight, ::aCols[ 6 ]:nDisplayCol }, aColors[ 2 ] )
::SayText( ::aRow[ 3 ] + " : Using bPaintRow", ;
{ nRow, nCol, nRow + nHeight, ::aCols[ 6 ]:nDisplayCol }, nil, ;
::aCols[ 1 ]:oHeaderFont )
::aCols[ 6 ]:PaintData( nRow, nil, nHeight, lHighLite, lSelect, 6, nRowPos )
::ReleaseDC()
return .f.
//----------------------------------------------------------------------------//
static function GetData()
local aData := {}
local a, n
local nTot := 0
for n := 1 to 15
if n % 5 == 0
a := { 1, nil, RandomText( 20, 30 ), 0, 0, 0, nTot }
nTot := 0
else
a := { 0, Date() - 20 + n, RandomText( 10, 30 ), HB_RandomInt( 100, 300 ), ;
{ 10,20,30 }[ HB_RandomInt( 1, 3 ) ], 0, 0 }
a[ 6 ] := a[ 4 ] * a[ 5 ]
nTot += a[ 6 ]
endif
AAdd( aData, a )
next
return aData
//----------------------------------------------------------------------------//