I made a function Create_Data() to create the dbf
Then I insert a button to append a row into xbrowse and I wish edit each column
the user must insert a new Item ( he can edit a new product , he can edit the tax column from edit_listbox, insert the unit price and the Qty and the procedure must make the total of row into total field )
or
press the button on the second column to select an product ( he can select a product from products archive, then he can edit the tax column and the qty and the unit price)
How I can make it easy ?
Please can you create a small test or correct this to understand it ?
The Dialog test
- Code: Select all Expand view
#Include "Fivewin.ch"
#include "xbrowse.ch"
#include "constant.ch"
REQUEST DBFCDX
REQUEST DBFFPT
external ordkeyno, ordkeycount,ordcreate,ordkeygoto
Function Test()
Local oFrmInvoice
Local oBrw
Local oFld1,oFld2,oFld3
Local nBottom := 30
Local nRight := 81.2
Local nWidth := Max( nRight * DLG_CHARPIX_W, 180 )
Local nHeight := nBottom * DLG_CHARPIX_H
RddSetDefault( "DBFCDX" )
nInvoice:="001"
if ! Db_OpenNoIndex("Parts","PA")
return nil
endif
DEFINE DIALOG oFrmInvoice TITLE "Invoice" ;
SIZE nWidth, nHeight PIXEL
@ 6, 0.8 XBROWSE oBrw SIZE 312,60 ;
OF oFrmInvoice ALIAS "PA";
COLUMNS 'PA->PAQTY','PA->PAITEM','PA->PADESC',' PA->PAUNIT','PA->PATAX','PA->PATOTAL' ;
COLSIZES 50,80,250,80,40,90 ;
HEADERS "Qty","Item","Description","Unit Price","Tax","Total" ;
PICTURES '@ 9999',,,'@ €99,999.99','99%','@ €99,999.99' ;
CELL LINES FOOTERS FASTEDIT
WITH OBJECT oBrw
WITH OBJECT oBrw:aCols[2]
:nBtnBmp := 1
:nEditType := EDIT_BUTTON
:bEditBlock :={||MsgInfo("selezione articolo")}
END
WITH OBJECT oBrw:aCols[5]
:nBtnBmp := 1
:nEditType := EDIT_LISTBOX
:aEditListTxt:={"21","20","12","8","4" }
END
:nStretchCol := STRETCHCOL_WIDEST
:lHscroll:=.f.
:lRecordSelector := .f.
:CreateFromCode()
end
FOR i := 1 TO LEN( oBrw:aCols)
oCol := oBrw:aCols[ i ]
* oCol:bLDClickData := {|| }
oCol:oDataFont := oFontGrid
oCol:bOnPostEdit := {|o, v, n| iif( n != VK_ESCAPE, ( DBRLOCK(), FieldPut( o:nCreationOrder, v ), DBUNLOCK() ), ) }
* oCol:bOnChange := { || oBrw:MakeTotals(), oBrw:RefreshFooters() }
NEXT
@ oBrw:nbottom+3, 5 BUTTON oBtn[1] PROMPT "&New Item" ;
SIZE 40,10 PIXEL OF oFrmInvoice ACTION NewItem(oBrw,nInvoice)
ACTIVATE DIALOG oFrmInvoice CENTER
RETURN NIL
Function NewItem(oBrw,nInvoice)
PA->(DbAppend())
replace PA->PAINVOICE With nInvoice
replace PA->PAQTY With 1
PA->(DbCommit())
FOR i := 1 TO LEN( oBrw:aCols)
oCol := oBrw:aCols[ i ]
oCol:nEditType := 1
oCol:bOnPostEdit := {|o, v, n| iif( n != VK_ESCAPE, ( DBRLOCK(), FieldPut( o:nCreationOrder, v ), DBUNLOCK() ), ) }
NEXT
oBrw:refresh()
oBrw:setfocus()
Return NIL
//---------------------------------------------------------------------------//
Function Create_Data()
cDir:=cFilePath(GetModuleFileName(GetInstance()))
DbCreate(cDir+'PA', { {'PAINVOICE' ,'C',004,000},; // number of Invoice
{'PAITEM' ,'C',010,000},; // Item
{'PADESC' ,'C',030,000},; //Desc
{'PAQTY' ,'N',004,000},; // Qty
{'PAUNIT' ,'C',010,002},; // Unit Price
{'PATOTAL','N',010,002},; // Total
{'PATAX' ,'N',005,002} }, 'DBFCDX') Tax of Item
close all
use &(cDir+'PA') new
select PA
if FILE(cDir+'Parts.DBF')
delete file &(cdir+'Parts.cdx')
append from &(cdir+'Parts')
dbcommitall()
close all
delete file &(cdir+'Parts.dbf')
endif
close all
rename &(cdir+'PA.dbf') to &(cdir+'Parts.dbf')
return nil
function Db_OpenNoIndex(cDbf,cAlias)
if file( cDbf + ".dbf" )
USE &(cDbf+".dbf") ;
ALIAS &(cAlias) NEW
else
MsgStop( i18n( "Non si è trovato l'archivio dei dati." ) + CRLF + ;
i18N( "Per favore controlla la configurazone") + CRLF + ;
i18N( "e indicizza gli archivi dell'applicazione." ) )
return .f.
return .f.
END if
if NetErr()
msgStop( i18n( "Errore nell'aprire un archivio" ) + CRLF + ;
i18n( "Per favore caricare di nuovo l'applicazione." ) )
DbCloseAll()
return .f.
endif
return .t.