Page 2 of 2

Re: XBrowse & Edit Dialogs: Writing Portable code (Recommended)

PostPosted: Sun Mar 31, 2019 2:36 pm
by ukoenig
cCli is the account number of customer

IF nMode == 1
oClienti:gobottom()
cCodeCliente:=StrZero(val(oClienti:numcli)+1,4)
Endif


In one of my programs I need customer-numbers as well.

There is a index on customer-number with the text-format "00000".
As soon I save the data of a new customer,
the index of customer-number is used and adds +1 to the number from the bottom.
The new number is added with saving the new data.
Next using index customer-last again.

Because I still need the data of old customers I don*t delete them
instead I move the data to the bottom
adding "Z_" to the customer lastname ( index ) and "Z" to the
customer number ( index ) like name : "Z_Maier" and number "Z0035"
I can activate the customer again removing the "Z"
both activate and deactivate works on button-action.

Image

regards
Uwe :D

Re: XBrowse & Edit Dialogs: Writing Portable code (Recommended)

PostPosted: Sun Mar 31, 2019 4:24 pm
by Silvio.Falconi
Uwe,
seem this function is not right with tdatabase as sad James and Nages

FUNC CreaCodiceClienti(oDbf)
LOCAL nLast := 0
local nArea := Select()
oDbf:OrdSetFocus(0)
oDbf:GoBottom()
nLast := Val(oDbf:NumCli) + 1
Select (nArea)
RETURN StrZero(nLast,4)

I have always done it this way and besides I have many dbf that have this type of code "0001"

Please see editrecord function on my test

on add New i made

IF nMode == 1
cCodeCliente:=CreaCodiceClienti(oClienti)
Endif
cCli:=If(nMode==1,cCodeCliente,oRec:Numcli)

on dialog I made
@ 12, 5 SAY "Codice:" OF oDlg SIZE 19, 8 PIXEL FONT oBold
@ 10, 36 GET aGet[1] VAR cCli OF oDlg SIZE 25, 10 PIXEL READONLY

then when I must save I check if cCli is the same of the last code

IF oDlg:nresult == IDOK
IF nMode == 1
cCodeCliente:=CreaCodiceClienti(oClienti)
If cCodeCliente==cCli
Else
Msginfo("The customer was saved with the account number "+ltrim(cCodeCliente)+"instead of "+ltrim(cCli),"Attention!!!" )
endif
oRec:numcli:=cCodeCliente

Endif

oRec:Save()

Endif


what's wrong?

Re: XBrowse & Edit Dialogs: Writing Portable code (Recommended)

PostPosted: Fri Apr 05, 2019 9:12 am
by Silvio.Falconi
Mr Nages,
my idea could be this to avoid entering double codes or searching at the time of saving

Function EditCustomer(....)

IF ladd
cCustCode := CreateCode( "CUSTOMERS" )

ELSE
IF oCustomer:Lastrec()==0
RETURN NIL
ENDIF

oCustomer:Load()

cTitle := "Modify Customer"
ENDIF

define dialog ...

REDEFINE GET oGet[1] VAR oCustomer:custNo ID 101 OF oDlg UPDATE WHEN .F.






sample

Code: Select all  Expand view
FUNCTION CreateCode( cDoc )
   LOCAL oControl
   LOCAL cDoc

 oControl := tdatabase().....

DO CASE
      CASE ALLTRIM( cTDoc ) == "CUSTOMERS"      ; oControl:GoTo( 1 )
ENDCASE

   oControl:Load()

IF oControl:RecLock()
      cDoc := PADL( ( VAL( oControl:documento ) + 1 ), oControl:largo, "0" )
      oControl:documento := cDoc
      oControl:Save()
   ELSE
      MsgStop( " I cannot create the code", cTDoc )
      QUIT
   ENDIF

   oControl:Close()
RETURN cDoc





in this case each time a customer is entered the procedure creates a new code without having to go each time to search if the customer code exists or has been inserted by other operators (for example in the save)