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)
oClienti := TDatabase():Open( , "CLIENTI", "DBFCDX", .T. )
oClienti:SetOrder( 1 )
oClienti:GoTop()Then created Xbrowse with DATASOURCE oClienti
I insert also
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
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)
Endifor I use this function
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 cIdthen I can show the variable cId
@ 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
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 lExistsusing 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
@ 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. )
ENDIFbut 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
IF lSave
cId:=NewId(oClienti,cFilter1)
oRec:id:=cId
oRec:Save( .T. )
Endifwhat is the correct procedure?
I use : FiveWin for Harbour March-April 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
