#include "FiveWin.Ch"
#include "ord.ch"
#include "xbrowse.ch"
REQUEST DBFCDX
//----------------------------------------------------------------------------//
function Main()
CreateTestDBF()
USE PRODUCTS NEW SHARED ALIAS PRD
SET ORDER TO TAG PRODUCTID
GO TOP
do while NewSale()
enddo
CLOSE DATA
return (0)
//----------------------------------------------------------------------------//
static function NewSale()
local oDlg, oBrw, oFont
local nNewRec := 0
local lNext := .f.
if SELECT( "SALE" ) > 0
SELECT SALE
ZAP
else
CreateSaleDbf()
endif
DEFINE FONT oFont NAME "TAHOMA" SIZE 0,-14
DEFINE DIALOG oDlg SIZE 900,450 PIXEL FONT oFont
@ 10,10 XBROWSE oBrw SIZE -10,-30 PIXEL OF oDlg ;
DATASOURCE "SALE" ;
COLUMNS "ProductID", "ProductNam", "Price", "Quantity", "TaxCd", "Amount" ;
HEADERS "ProdID", "ProductName" ;
CELL LINES NOBORDER FOOTERS FASTEDIT
WITH OBJECT oBrw
WITH OBJECT :oCol( 1 )
:nEditType := EDIT_GET_BUTTON
:bEditValid := { |oGet| ValidProdID( oGet, oBrw:oCol( 1 ) ) }
:bEditBlock := { |r,c,oCol| ProductSelect( oCol:Value ) }
:bOnChange := { |oCol,uOldVal| ;
PRD->( DBSEEK( oCol:Value ) ), ;
oBrw:ProductName:VarPut( PRD->PRODUCTNAM ), ;
oBrw:Price:VarPut( PRD->PRICE ), ;
oBrw:TaxCd:VarPut( PRD->TAXCD ), ;
CalcRow( oBrw ) }
ENDWITH
WITH OBJECT :Quantity
:nEditType := EDIT_GET
:bEditValid := { |oGet| oGet:VarGet() > 0 }
:bOnChange := { |oCol| CalcRow( oBrw ) }
END
WITH OBJECT :Amount
:nFooterType := AGGR_SUM
:bOnChange := { |oCol| If( oCol:Value > 0, nNewRec := 0, nil ) }
END
:bPastEof := { || If( nNewRec == 0, SALE->( DBAPPEND(), nNewRec := RECNO(), oBrw:Refresh() ), nil ) }
:bKeyDown := { |nKey| If( nkey == VK_DELETE, ;
( If( SALE->(RECNO()) == nNewRec, nNewRec := 0, nil ) , ;
SALE->( DBDELETE() ), ;
oBrw:Refresh(), ;
oBrw:MakeTotals(), ;
oBrw:RefreshFooters() ), nil ) }
:bChange := { || If( nNewRec > 0, ( SALE->( DBGOTO( nNewRec ), ;
DBDELETE(), ;
DBGOBOTTOM() ), ;
oBrw:Refresh(), ;
nNewRec := 0 ) , nil ) }
//
:nStretchCol := 2
:MakeTotals()
:CreateFromCode()
END
@ 205,350 BUTTON "Close" SIZE 40,14 PIXEL OF oDlg ACTION oDlg:End()
@ 205,400 BUTTON "NextSale" SIZE 40,14 PIXEL OF oDlg ACTION ( lNext := .t., oDlg:End() )
ACTIVATE DIALOG oDlg CENTERED ON INIT ( oBrw:GoDown() )
RELEASE FONT oFont
if nNewRec > 0
SALE->( DBGOTO( nNewRec ), DBDELETE() )
endif
XBROWSER "SALE"
return lNext
//----------------------------------------------------------------------------//
static function CalcRow( oBrw )
oBrw:Amount:VarPut( oBrw:Quantity:Value * oBrw:Price:Value )
return nil
//----------------------------------------------------------------------------//
static function ValidProdID( oGet, oCol )
local nVal := oGet:VarGet()
if .not. PRD->( DBSEEK( nVal ) )
PRD->( DBSEEK( nVal, .t. ) )
oGet:cText := oCol:Value
oCol:lRunBtnAction := .t.
endif
return .t.
//----------------------------------------------------------------------------//
static function ProductSelect( nCode )
local nSelect
local oDlg, oBrw, oFont
DEFINE FONT oFont NAME "TAHOMA" SIZE 0,-14
DEFINE DIALOG oDlg SIZE 400,500 PIXEL FONT oFont TITLE "PRODUCTS"
@ 30,10 XBROWSE oBrw SIZE -10,-30 PIXEL OF oDlg ;
DATASOURCE "PRD" ;
COLUMNS "ProductID", "ProductNam" ;
CELL LINES NOBORDER AUTOSORT
WITH OBJECT oBrw
:bLDblClick := { || nSelect := PRD->PRODUCTID, oDlg:End() }
:bKeyChar := { |nKey| If( nKey == VK_RETURN, ;
( nSelect := PRD->PRODUCTID, oDlg:End() ), nil ) }
//
:CreateFromCode()
END
@ 10,10 SAY oBrw:oSeek PROMPT oBrw:cseek SIZE 180,10 PIXEL ;
OF oDlg COLOR CLR_HRED,CLR_YELLOW
@ 230,150 BUTTON "Select" SIZE 40,14 PIXEL OF oDlg ;
ACTION ( nSelect := PRD->PRODUCTID, oDlg:End() )
ACTIVATE DIALOG oDlg CENTERED
RELEASE FONT oFont
PRD->( OrdSetFocus( "PRODUCTID" ) )
return nSelect
//----------------------------------------------------------------------------//
static function CreateSaleDbf()
DBCREATE( "SALE.DBF", { ;
{ "PRODUCTID", 'N', 7, 0 }, ;
{ "PRODUCTNAM", 'C', 25, 0 }, ;
{ "PRICE", 'N', 11, 3 }, ;
{ "QUANTITY", 'N', 11, 3 }, ;
{ "TAXCD", 'C', 1, 0 }, ;
{ "AMOUNT", 'N', 12, 2 } }, ;
"DBFCDX", .t., "SALE" )
SET FILTER TO !DELETED()
return nil
//----------------------------------------------------------------------------//
static function CreateTestDbf()
field PRODUCTID, PRODUCTNAM
USE CUSTOMER NEW SHARED ALIAS CUST
DBCREATE( "PRODUCTS.DBF", { ;
{ "PRODUCTID", 'N', 7, 0 }, ;
{ "PRODUCTNAM", 'C', 25, 0 }, ;
{ "PRICE", 'N', 11, 3 }, ;
{ "TAXCD", 'C', 1, 0 } }, ;
"DBFCDX", .t., "PROD" )
do while ! cust->( eof() )
APPEND BLANK
PROD->PRODUCTID := RECNO() * 7 + 3000
PROD->PRODUCTNAM := CUST->FIRST-CUST->LAST
PROD->PRICE := HB_Random( 100, 900 )
PROD->TAXCD := CHR( 64 + HB_RandomInt( 1, 3 ) )
cust->( dbskip( 1 ) )
enddo
INDEX ON PRODUCTID TAG PRODUCTID
INDEX ON UPPER(PRODUCTNAM) TAG PRODUCTNAM
CLOSE DATA
return nil
//----------------------------------------------------------------------------//
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( 'A', .t. )
SetKinetic( .f. )
SetGetColorFocus()
SetBalloon( .t. )
return
//----------------------------------------------------------------------------//