Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Primary Key with one to many Form
Message
De
13/07/2001 12:57:09
Nancy Folsom
Pixel Dust Industries
Washington, États-Unis
 
Information générale
Forum:
Visual FoxPro
Catégorie:
Gestionnaire d'écran & Écrans
Divers
Thread ID:
00530359
Message ID:
00530374
Vues:
16
This message has been marked as a message which has helped to the initial question of the thread.
Hi, Leroy-

>Should I not use the wizard and write the form from scratch?
>Should I modify the Form that the wizard made?

Correct. At least, that is my opinion. I used the wizards when I first started with VFP (because I had 8 hours to convert a 2.x app to 3.0 never having seen 3.0 before) and then modified the resulting form. I learned a lot about OOP and VFP but it was the most painful and haphazard way to gain knowledge. There are better tools for it. Such as books (www.hentzenwerke.com), training (Jim Duffy, Jim Booth, Chuck Urwiler--Micro Endeavors, Inc.), as well as commericial frameworks--see fox.wikis.com for discussion.

>And finally, Is there a way for me to generate a Primay key programmaticly or does anyone know of a download that does this?

Yes, you can, but you have to write the function yourself, and then, if you table belongs to a DBC, which I recommend, declare the function as your default value.

Here is an example of one (the ideas is to use a table of IDs).
FUNCTION GetID( tcTable, tcIDField, tcIDIndexExp )


	IF VARTYPE( tcTable ) <> "C" .OR. !USED( tcTable )
		RETURN 0
	ENDIF

	LOCAL lcTable, lcIDField, lcIDIndexExp, lnSelect, lnBuffering, llCloseIDs, lnID, lnI, lnLoops

	IF VARTYPE( tcIDField ) <> "C"
		lcIDField = "ID"
	ENDIF

	IF VARTYPE( tcIDIndexExp ) <> "C"
		lcIDIndexExp = lcIDField
	ENDIF

	lcTable = UPPER( TRIM( tcTable ) )

	*!* Note where we came from
	lnSelect = SELECT()

	*!* Open the table of IDs table
	IF !USED( 'ids' )
		USE IDTable IN 0
		llCloseIDs = USED( 'IDs' )
	ENDIF

	*!* We want the table to update immediately.
	LOCAL lnBuffering
	lnBuffering = CURSORGETPROP('buffering','IDs')
	IF lnBuffering # 1
		CURSORSETPROP('buffering','IDs',1)
	ENDIF

	IF !INDEXSEEK(lcTable, .F., 'IDs', "TableName" )

		IF FLOCK('IDs')
			INSERT INTO IDs ( 'TableName', 'ID' ) VALUES (lcTable, MINKEY)
			UNLOCK
		ELSE
			*!* TODO: reset environment before returning.
			RETURN 0
		ENDIF

	ELSE

		lnID = IIF( BETWEEN( IDs.ID, MINKEY, MAXKEY ), MINKEY, IDs.ID )

	ENDIF

	lnLoops = MAXKEY - MINKEY + 1

	RLOCK( 'IDs' )
	llOK = !INDEXSEEK(lnID, .F., lcTable, lcIDIndexExp )
	lni = 1
	DO WHILE !llOK
		*!* Increment and Keep hunting for an unused ID
		UNLOCK
		lnI = lnI + 1
		lnID = lnID + 1
		RLOCK( "IDs" )
		llOK = !INDEXSEEK(lnID, .F., lcTable, lcIDIndexExp ) .AND. lnID < MAXKEY && lnLoops
	ENDDO

	IF llOK
		*!* We have a good ID
		
		REPLACE ID WITH lnID + 1 IN IDs
		UNLOCK IN 'IDs'
	ELSE
		UNLOCK
		lnID = MINKEY
		DO WHILE SEEK( lcTable, lnID, lcIDIndexExp ) .AND. lnI < lnLoops
			*!* Keep hunting for an unused ID
			lnI = lnI + 1
			lnID = lnID + 1
			RLOCK( 'IDs' )
			llOK = !INDEXSEEK( lnID, .F., lcTable, lcIDIndexExp ) .AND. lnID < lnLoops
		ENDDO
		IF llOK
			*!* We have a good ID
			REPLACE ID WITH lnID + 1 IN IDs
		ENDIF

		UNLOCK
	ENDIF

	IF llCloseIDs
		USE IN IDs
	ELSE
		CURSORSETPROP( 'buffering', lnBuffering, 'IDs' )
	ENDIF

	RETURN lnID

ENDFUNC
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform