Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Twice a key in a table
Message
Information générale
Forum:
Visual FoxPro
Catégorie:
Base de données, Tables, Vues, Index et syntaxe SQL
Divers
Thread ID:
01118041
Message ID:
01118103
Vues:
12
This message has been marked as a message which has helped to the initial question of the thread.
>>In my prev. job I had some code to check for uniqueness at the class level using Indexseek as Cetin suggested (actually, I had the code twice in valid of textbox and in save time). If you want, I'll search for that old code...
>
>it is very kind of you..
>
>bernhart
>
I am posting the code as is, I may have done it differently now:
**************************************************
*-- Class:        wguniquetext (c:\redp\appl\commonwg\classes\wgcontrols.vcx)
*-- ParentClass:  wgtextbox (c:\redp\appl\commonwg\classes\wgcontrols.vcx)
*-- BaseClass:    textbox
*-- Time Stamp:   05/16/01 04:20:14 PM
*-- Contains logic to determine if its VALUE property is unique. Can be used for checking uniqueness of a key field.
*
DEFINE CLASS wguniquetext AS wgtextbox


	*-- Holds index tag name used in the unique validation method.
	pcvalidtag = ""
	*-- User notes
	notes = ""
	*-- Holds index key expression, used for validation
	pcfields = ""
	Name = "wguniquetext"


	PROCEDURE Valid
		********************************************************************
		*  Description.......: wgUniqueText.Valid()
		*  Calling Samples...:
		*  Parameter List....:
		*  Created by........:
		*  Modified by.......: Nadya Nosonovsky 06/05/2000 12:08:49 PM
		********************************************************************
		*--- Checks to see if the value entered is unique.
		local lcvalue,llunique,lnaction, lcfield, lcAlias, lcTag, lcSavDel, lnRecno
		llunique = .t.
		lcAlias=alias()
		if empty(lcAlias)
			lcAlias=thisform.dataenvironment.InitialSelectedAlias
		endif
		lcTag = this.pcValidTag && Tag Name, used in validation
		lcField=this.pcFields && Field Name or combination of fields in validation
		lcValue = iif(type("this.value") = "C", alltrim(this.value), this.value) && Store value entered.

		*--- Make sure that it is NOT empty.
		if empty(this.value)
			lnaction=messagebox('This field can not be blank! Would you like to try again?',20,'Warning')

			if lnaction = 6			&& Return user to field.
				llunique = .f.
		*--- Do nothing , false will be returned.

			else
		*--- The user choose to cancel the edit or add.  Return them to review mode.
				llunique = .t.
				select (lcAlias)
				thisform.edit()
				thisform.navstand.navupdate()
				thisform.refresh()
				RETURN llunique 
			endif

		endif

		if llunique
		*--- Check table.
			if thisform.addmode or (not thisform.addmode and oldval(lcfield,lcAlias)<>lcvalue)
				* Note - the select only sees the values already on disk (not buffered)
		      lcSavDel=SET('DELETED')
		      SET DELETED OFF

				select * from (lcAlias) ;
					where &lcfield == lcvalue to screen noconsole
			  SET DELETED &lcSavDel.
			  
		*!*	*--- Test results of SELECT-SQL duplicate record check.

				if _tally > 0
					llunique = .f.
				endif
		      
		*!*	      if indexseek(lcValue,.f.,lcAlias, lcTag) && Field is duplicate
		*!*	           llUnique=.f.
		*!*	      endif     

				if !llunique		&&
					lnaction=messagebox('The value entered is not unique. Would you like to try again?',20,'Duplicate value')

					if lnaction = 6			&& Return user to field.
						llunique = .f.
		*--- Do nothing , false will be returned.

					else
		*--- The user choose to cancel the edit or add.  Return them to review mode.
						llunique = .t.
						select (lcAlias)
						thisform.edit()
						thisform.navstand.navupdate()
						thisform.refresh()
						RETURN llunique 
					endif
				endif
			endif
		endif
		return llunique
	ENDPROC


ENDDEFINE
*
*-- EndDefine: wguniquetext
**************************************************
If it's not broken, fix it until it is.


My Blog
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform