Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
File Locking
Message
 
À
21/01/2001 23:46:47
Agnes Cheng
DynamicTech Consultants Ltd.
Hong Kong, Hong Kong
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Titre:
Divers
Thread ID:
00466456
Message ID:
00466502
Vues:
7
>My case : I got an invoice form, invheader,invdetail ,invnumber (3
>tables).
>
> I want to lock the 'Invnumber' table , Get the newest number , then update
> that tables, There are over 20 users to use this forms.
>
> so What syntax / alog. should I write ??
>
> Thanks in advnace.
>From Agnes

Here is the function I cut and pasted from Codebook framework. It uses Id table instead of InvNumber...Hope that helps.

*========================
FUNCTION NewID( tcAlias )
*========================
LOCAL lcAlias, ;
luID, ;
lnOldReprocess, ;
lnOldArea

lnOldArea = SELECT()

*--------------------------------------------------
*-- If no alias was provided, use the current alias
*--------------------------------------------------
IF PARAMETERS() < 1
lcAlias = ALIAS()
IF CURSORGETPROP("SOURCETYPE") = DB_SRCLOCALVIEW
*----------------------------
*-- Attempt to get base table
*----------------------------
lcAlias = UPPER(CURSORGETPROP("TABLES"))

*------------------------------------------------------------------------
*-- Modified 10/18/1997 21:34 - CTB:
*-- A view returned an lcBaseTable of "Emloyee!EmpRight,Employee!Section"
*-- Therefore, if a "," comma exists in the lcBaseTable variable,
*-- parse out the first DATABASE!TABLE name and use that as the
*-- base table information. This change also had to be made in all
*-- NewID() functions in all databases.
*------------------------------------------------------------------------
IF OCCURS( ",", lcAlias ) > 0
lcAlias = SUBSTR( lcAlias, 1, AT( ",", lcAlias ) - 1)
ENDIF

lcAlias = SUBSTR(lcAlias, AT("!", lcAlias) + 1)
ENDIF
ELSE
lcAlias = UPPER(tcAlias)
ENDIF

luID = ""
lnOldReprocess = SET('REPROCESS')

*------------------------------
*-- Lock until user presses Esc
*------------------------------
SET REPROCESS TO AUTOMATIC

*--------------------------------------------------
*-- IF an ID table is already in use, close it down
*-- and force this procedure to use its database
*-- ID table
*--------------------------------------------------
IF USED('id')
USE IN id
ENDIF

*----------------------------------------------------------
*-- The following situations must be taken into account.
*-- 1) Default Codebook setup has been implemented and the
*-- .EXE or .APP is located one subdirectory above
*-- the database directory (which is defined in the
*-- DATABASE_DIR defined constant)
*-- 2) The .EXE resides on a client machine and the
*-- data resides on the server (local or remote). In
*-- this case, the first IF statement fails and the
*-- second one uses the DBPaths.DBF to locate the
*-- database.
*----------------------------------------------------------

*---------------------------------------
*-- Situation #1: Codebook Default Setup
*---------------------------------------
IF FILE( DATABASE_DIR + "ID.DBF" )
USE ( DATABASE_DIR + "ID.DBF" ) IN 0 ALIAS id
ELSE
*-----------------------------------------------
*-- Situation #2: .EXE Is Located Somewhere Else
*-----------------------------------------------
LOCAL lcIDTablePath
=GetTablePath( DATABASE_NAME, @lcIDTablePath )
IF FILE( lcIDTablePath + "ID.DBF" )
USE (lcIDTablePath + "ID.DBF" ) IN 0 ALIAS id
ENDIF
ENDIF

IF .NOT. USED('ID')
=MESSAGEBOX( "The ID table for this database could not be " + ;
"found. The new record you just tried to add " + ;
"does not have a system generated key. Please " + ;
"Cancel this new record and contact your " + ;
"developer for maintenance." , ;
0, DATABASE_NAME + " Database Error" )
ELSE
SELECT id

*-------------------------------------
*-- Generate the ID for the new record
*-------------------------------------
IF SEEK(lcAlias, "id", "keyname")
IF RLOCK()
luID = IIF(id.Type = 'C', id.Value, VAL(id.Value))
REPLACE id.value WITH EVAL(id.incrementprocedure)
UNLOCK
ENDIF
ELSE
*------------------------------------------------
*-- If the new ID could not be generated, message
*-- the developer.
*------------------------------------------------
=MESSAGEBOX( "The alias " + lcAlias + " could not be found " + ;
"in the ID Table, as a result, the primary key " + ;
"could not be generated!!! Please Cancel the " + ;
"newly added record and contact your developer for " + ;
"maintenance." , ;
0, DATABASE_NAME + " Database Error" )
ENDIF

*--------------------------------------------------------------
*-- Trim trailing blanks only if the generated key is character
*--------------------------------------------------------------
IF TYPE('luID') == "C"
luID = RTRIM(luID)
=AttachPrefix( @luID )
ENDIF
ENDIF

SET REPROCESS TO lnOldReprocess
SELECT (lnOldArea)

RETURN luID

ENDFUNC
- Jayesh
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform