XBrowse & Edit Dialogs: Writing Portable code (Recommended)

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

Postby ukoenig » Sun Mar 31, 2019 2:36 pm

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
Since 1995 ( the first release of FW 1.9 )
i work with FW.
If you have any questions about special functions, maybe i can help.
User avatar
ukoenig
 
Posts: 4043
Joined: Wed Dec 19, 2007 6:40 pm
Location: Germany

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

Postby Silvio.Falconi » Sun Mar 31, 2019 4:24 pm

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?
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)
I use : FiveWin for Harbour November 2023 - January 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
User avatar
Silvio.Falconi
 
Posts: 6865
Joined: Thu Oct 18, 2012 7:17 pm

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

Postby Silvio.Falconi » Fri Apr 05, 2019 9:12 am

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)
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)
I use : FiveWin for Harbour November 2023 - January 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
User avatar
Silvio.Falconi
 
Posts: 6865
Joined: Thu Oct 18, 2012 7:17 pm

Previous

Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 41 guests