General information
Category:
Coding, syntax & commands
Title:
Is this a correct logic for AutoNumber ??
hello all
My app generates a autonumber in a form,i have this code in Savedata method of a form,let me know will this work fine in a multiuser environment and i generate the autonumber only when the user clicks save is this the correct method ??
Txs
cmdSave Click Method
---------------------
BEGIN TRANSACTION
Thisform.nAutoNumber.Value=autonumber()
SELECT BANKACCT
M_BALANCE=BANKACCT.BALANCE
SELECT LOAN
llloan=TABLEUPDATE(.T.)
SELECT CHECK
M_BALANCE = M_BALANCE - SC_AMOUNT
APPEND BLANK
REPLACE CK_NUM WITH SC_CHECK;
BANK_ID WITH 789012
llcheck=TABLEUPDATE(.T.)
SELECT BANKACCT
REPLACE BALANCE WITH M_BALANCE
llbank=TABLEUPDATE(.T.)
SELECT LOANREIM
APPEND BLANK
REPLACE CK_NUM WITH SC_CHECK
llloanreim=TABLEUPDATE(.T.)
IF llloan and llcheck and llbank and llloanreim = .t.
end transaction
ELSE
messagebox('Another User modified the record,try later',64,'Network Conflict')
rollback
ENDIF
Wait wind 'RECORD ADDED !!! ' timeout .5
RETURN
Stored Procedure Autonumber
----------------------------
FUNCTION Autonumber(tcAlias)
LOCAL lcAlias, ;
lcID, ;
lcOldReprocess, ;
lnOldArea
lnOldArea = SELECT()
IF PARAMETERS() < 1
lcAlias = UPPER(ALIAS())
ELSE
lcAlias = UPPER(tcAlias)
ENDIF
lcOldReprocess = SET('REPROCESS')
*-- Lock until user presses Esc
SET REPROCESS TO AUTOMATIC
IF !USED("COUNTER")
USE dbcTest!counter IN 0
ENDIF
SELECT counter
IF RLOCK()
lcID = counter.nextcheckno
REPLACE counter.nextCheckNo WITH ;
ALLT(STR(VAL(ALLT(lcID)) + 1, LEN(counter.nextcheckno)))
UNLOCK
ENDIF
SELECT (lnOldArea)
SET REPROCESS TO lcOldReprocess
RETURN lcID
RELEASE lcID
ENDFUNC
Next
Reply
View the map of this thread
View the map of this thread starting from this message only
View all messages of this thread
View all messages of this thread starting from this message only