Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Checking some field for uniqueness
Message
General information
Forum:
Visual FoxPro
Category:
Forms & Form designer
Miscellaneous
Thread ID:
00518556
Message ID:
00519620
Views:
18
>Nadya
>
>>>We had indexseek before, but it didn't work.
>>>Here is how our classes work: If you hit Add, it uses APPEND BLANK command, so the empty record is already added in the database. Now, on the field, which requires validation, we should check for uniqueness, and if it fails, user has option to revert.
>
>And the problems you're running into now illustrate why its a bad idea to do an APPEND BLANK before you've got the data to put into the new recod.

Yes, we already figured this out. It's our own small framework, which I don't know, who invented first. It's buggy, single-tier, etc., but we have to live with it.

>
>>As a further step, you might consider writing a primary key validation class as part of a business tier. Keep the business code out of the interface layer and all that.
>>>That's a good idea, but I'm not sure, how to implement it. Can you show an example?
>
>
>
>Damn girl... not asking for much!

Next time I'll figure it by myself, ok? :)

>
>OK. The enclosed code is for illustration purposes only. I'm expressly saying that it will not work as supplied.
>The idea behind a business tier is to make a hard division between the business-rule code and the interface code.
>If you decide to go with another COM compatible language for the interface (i.e. VB) your business code doesn't have to be rewritten.
>Even if you stay with VFP, a major change in the interface paradigm has no impact on the business-tier code.
>
>Also, I wasn't aware that you were working with a framework. Multi-tier code IS a type of framework and
>your current framework doesn't appear to support multiple tiers. What you may want to do is start small.
>Write a class for the AllFunctions table that supports any business rules you need applied to that table.
>
>BTW, for all you eagle eyes out there, don't bust my chops about small stuff. If I were writing this
>for a real application, there's a number of things in this example I wouldn't do either.
>The intent is to show the type of functionality typically found in a business tier and the
>kind of code used to enforce encapsulation.
>
>Regards,
>Thom C.
>
>
>**************************************************
>*-- Class:        allfct_busytier (d:\playvfp\arbwork.vcx)
>*-- ParentClass:  custom
>*-- BaseClass:    custom
>*-- Time Stamp:   06/14/01 01:49:10 PM
>*
>DEFINE CLASS allfct_busytier AS custom
>
>	*** properties that express the table and important indexes
>	pctable = "AllFunctions"
>	pctag = "Fun_Key"
>	*-- Index tag for the primekey.
>	pc_pkeytag = "AllF_PKey"
>	
>	*** buffer properties for the field values
>	*-- Old value of AllFunctions.FunName
>	pcfunname_old = ""
>	*-- New value of Allfunctions.FunName
>	pcfunname_new = ""
>	*-- Old value of some numeric field in AllFunctions
>	pnallfun_1_old = 0
>	*-- New value of some numeric field in AllFunctions
>	pnallfun_1_new = 0
>	*-- Old value of some date field in AllFunctions
>	pdallfun_1_old = ""
>	*-- New value of some date field in AllFunctions
>	pdallfun_1_new = ""
>	*-- Value of the AllFunctions primary key.
>	pn_allf_pkey = 0
>	
>	Name = "allfct_busytier"
>
>
>	*-- Find a given AllFunctions record and load THIS's properties.
>	PROCEDURE load_funct
>		LPARAMETER tnKeyVal
>		WITH THIS
>			IF NOT USED(.pcTable)
>				USE (.pcTable) IN 0
>			ENDIF
>
>			IF INDEXSEEK((m.tnKeyVal), .F., (.pcTable), (.pc_PKeyTag))
>				.pnAllF_PKey = AllFunctions.PrimeKey
>				.pcFunName_Old = AllFunctions.FunName
>				.pc_pnAllFun_1_Old = AllFunctions.NumbField
>				.pd_pnAllFun_1_Old = AllFunctions.DateField
>			ENDIF
>		ENDWITH
>	ENDPROC
>
>
>	*-- Test for possible duplication of the primary key.
>	PROCEDURE fun_uniq
>		LPARAMETER tcKeyVal
>
>		WITH THIS
>			IF NOT USED(.pcTable)
>				USE (.pcTable) IN 0
>			ENDIF
>
>			m.lRetVal = INDEXSEEK(m.tcKey, .F., (.pcTable), (.pcTag))
>		ENDWITH
>
>		RETURN(m.lRetVal)
>	ENDPROC
>
>
>	*-- Add a new function
>	PROCEDURE add_newfunct
>		LOCAL ARRAY laInsVals[4]
>
>		WITH THIS
>			IF NOT USED(.pcTable)
>				USE (.pcTable) IN 0
>			ENDIF
>
>			IF .Fun_Uniq(.pcFunName_New)
>				laInsVals[2] = .pcFunName_New
>				laInsVals[3] = IIF(EMPTY(.pnAllFun_1_New), .pc_pnAllFun_1_Old, .pcAllFun_1_New)
>				laInsVals[4] = IIF(EMPTY(.pdAllFun_1_New), .pd_pnAllFun_1_Old, .pdAllFun_1_New)
>				laInsVals[1] = .New_PKey()
>
>				INSERT INTO AllFunctions ;
>					FROM ARRAY laInsVals
>			ENDIF
>		ENDWITH
>	ENDPROC
>
>
>	*-- Apply changes to a record in AllFunctions
>	PROCEDURE upd_funct
>		LOCAL ARRAY laUpdVals[4]
>
>		WITH THIS
>			IF NOT USED(.pcTable)
>				USE (.pcTable) IN 0
>			ENDIF
>
>			IF INDEXSEEK((.pnAllF_PKey), .T., (.pcTable), (.pc_PKeyTag))
>				laUpdVals[1] = .pnAllF_PKey
>				laUpdVals[2] = IIF(EMPTY(.pcFunName_New), .pcFunName_Old, .pcFunName_New)
>				laUpdVals[3] = IIF(EMPTY(.pnAllFun_1_New), .pn_pnAllFun_1_Old, .pnAllFun_1_New)
>				laUpdVals[4] = IIF(EMPTY(.pdAllFun_1_New), .pd_AllFun_1_Old, .pdAllFun_1_New)
>
>				SELECT (.pcTable)
>				GATHER FROM laUpdVals
>			ENDIF
>		ENDWITH
>	ENDPROC
>
>
>	*-- Delete a function.
>	PROCEDURE del_funct
>		WITH THIS
>			IF NOT USED(.pcTable)
>				USE (.pcTable) IN 0
>			ENDIF
>
>			IF INDEXSEEK(.pn_AllF_PKey, .T., (.pcTable), (.pc_Pkeytag))
>				DELETE IN (.pcTable)
>			ENDIF
>		ENDWITH
>	ENDPROC
>
>
>	*-- Validate the date field value.
>	PROCEDURE valid_pdfunct
>		LPARAMETER tdValue
>
>		[Code to verify the validity of m.tdValue]
>
>		IF m.tdValue = Valid
>			THIS.pd_AllFun_1_New = m.tdValue
>		ENDIF
>	ENDPROC
>
>
>	*-- Validate the numeric field value.
>	PROCEDURE valid_pnfunct
>		LPARAMETER tnValue
>
>		[Code to verify the validity of m.tnValue]
>
>		IF m.tnValue = Valid
>			THIS.pn_AllFun_1_New = m.tnValue
>		ENDIF
>	ENDPROC
>
>
>	*-- Test for a unique prime key.
>	PROCEDURE uniq_pkey
>		LOCAL lRetVal
>		WITH THIS
>			m.lRetVal = INDEXSEEK((.pnAllF_PKey), .F., (.pcTable), (.pc_PKeyTag))
>		ENDWITH
>		RETURN(m.lRetVal)
>	ENDPROC
>
>
>	*-- Get the next primekey.
>	PROCEDURE new_pkey
>		LOCAL lnRetVal
>
>		WITH THIS
>			IF NOT USED(.pcTable)
>				USE (.pcTable) IN 0
>			ENDIF
>			SELECT (.pcTable)
>			SET ORDER TO (.pc_PKeyTag)
>
>			GO BOTT
>
>			m.lnRetVal = AllFunctions.Primekey + 1
>		ENDWITH
>
>		RETURN(m.lnRetVal)
>	ENDPROC
>
>
>ENDDEFINE
>*
>*-- EndDefine: allfct_busytier
>**************************************************
>
Ok, I think, I got the basis, but have to work on it more.

Thanks again for your detailed help.
If it's not broken, fix it until it is.


My Blog
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform