To Nages : Explain me how I must make this tdatabase
Posted: Fri Mar 01, 2019 10:57 am
I have a clienti.dbf with these fields
I open the Dbf with fwh Tdatabase ( no tdata ofJames)
Then created Xbrowse with DATASOURCE oClienti
I insert also
on Function EditClienti( oRec,oBrw )
I wish add a new record and modify the record selected
I need oRec := oClienti:record() or not ?
When I add a new record I wish add a new" Idcliente" but I need to show it on a get ( readonly)
to calc a new Idclienti I made
or I use this function
then I can show the variable cId
Duplicate function
using the Duplicate () function in insertion works well but in the change tells me that the code is already duplicated and therefore does not allow me to make the change as I solve?
or this is all wrong ?
How I must make it ?
wich is the correct procedure ?
Another problem ...When I make the procedure of save I made
but here could be a problem because when I go to save it is possible that some other inline user has saved a customer with the same IDCLIENTI then how can I do to avoid this inconvenience?
I thinked to make
what is the correct procedure?
Code: Select all | Expand
DbCreate(cDir+'CL', { {'idcliente','C',4,0},;
{'Cognome','C',30,0},;
{'Nome','C',30,0},;
{'Indirizzo','C',50,0},;
{'Citta','C',30,0},;
{'Provincia','C',2,0},;
{'Cap','C',5,0},;
{'Email','C',50,0},;
{'Codfiscale','C',16,0},;
{'Partiva','C',11,0},;
{'Appunti','C',200,0},;
{'Cellulare','C',20,0},;
{ "Islock" , "L", 1, 0 }}, 'DBFCDX')
I open the Dbf with fwh Tdatabase ( no tdata ofJames)
Code: Select all | Expand
oClienti := TDatabase():Open( , "CLIENTI", "DBFCDX", .T. )
oClienti:SetOrder( 1 )
oClienti:GoTop()
Then created Xbrowse with DATASOURCE oClienti
I insert also
Code: Select all | Expand
oBrw:bEdit := { |oRec| EditClienti( oRec,oBrw ) }
on Function EditClienti( oRec,oBrw )
I wish add a new record and modify the record selected
I need oRec := oClienti:record() or not ?
When I add a new record I wish add a new" Idcliente" but I need to show it on a get ( readonly)
to calc a new Idclienti I made
Code: Select all | Expand
If lAdd
oBrw:oDbf:clearFilter() // ( I can have a filter on oBrw)
oRec:gobottom()
cId:= strzero(oRec:RecNo+1,4)
oBrw:oDbf:setFilter( cFilter1)
oBrw:oDbf:GoTop()
oRec:Load(.t.)
else
cId := strzero(oRec:RecNo,4)
Endif
or I use this function
Code: Select all | Expand
Function NewId(oDbf,cFilter)
Local cId
Local nRecno:= oDbf:recno()
Local nOrder:= oDbf:OrdNumber()
local nArea := Select()
If !empty(cFilter)
oDbf:clearFilter()
Endif
oDbf:setorder(1)
oDbf:gobottom()
cId := strzero(oDbf:RecNo+1,4)
If !empty(cFilter)
oDbf:setFilter( cFilter)
oDbf:GoTop()
Endif
oDbf:SetOrder( nOrder )
oDbf:GoTo( nRecno )
Select (nArea)
return cId
then I can show the variable cId
Code: Select all | Expand
@ 12, 10 SAY "Code:" OF oDlg SIZE 19, 8 PIXEL
@ 10, 46 GET aGet[1] VAR cId OF oDlg SIZE 25, 12 PIXEL ;
VALID If( Empty( cId ), ( MsgInfo( NO_EMPTY ), .f. ), ;
If( Duplicate( cId, "IDCLIENTE", oRec:RecNo,oClienti,aGet[1] ), ( MsgInfo( YES_DUPLICATE ), .f. ), ;
.t. ) )
Duplicate function
Code: Select all | Expand
static function Duplicate( uVal, cOrder, nThisRec, oDbf, oGet )
local nSaveRec := oDbf:RECNO()
local cSaveOrd := oDbf:OrdSetFocus()
local lExists := .f.
DEFAULT nThisRec := nSaveRec
oDbf:OrdSetFocus( cOrder )
lExists := oDbf:DBSEEK( uVal ) .and. oDbf:RECNO() != nThisRec
if lExists
oGet:cText( space(4) )
endif
if ! Empty( cSaveOrd )
oDbf:OrdSetFocus( cSaveOrd )
endif
oDbf:DBGOTO( nSaveRec )
return lExists
using the Duplicate () function in insertion works well but in the change tells me that the code is already duplicated and therefore does not allow me to make the change as I solve?
or this is all wrong ?
How I must make it ?
wich is the correct procedure ?
Another problem ...When I make the procedure of save I made
Code: Select all | Expand
@ 144, 121 BTNBMP oBtnSave PROMPT "Save" OF oDlg SIZE 42, 14 PIXEL FLAT ACTION (oDlg:End(), lSave := .T.)
...
IF lSave
oRec:id:=cId
oRec:Save( .T. )
ENDIF
but here could be a problem because when I go to save it is possible that some other inline user has saved a customer with the same IDCLIENTI then how can I do to avoid this inconvenience?
I thinked to make
Code: Select all | Expand
IF lSave
cId:=NewId(oClienti,cFilter1)
oRec:id:=cId
oRec:Save( .T. )
Endif
what is the correct procedure?