Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Check for uniqueness
Message
From
27/12/2001 13:21:07
Gil Munk
The Scarborough Group, Inc.
Baltimore, Maryland, United States
 
 
To
26/12/2001 21:54:24
General information
Forum:
Visual FoxPro
Category:
The Mere Mortals Framework
Miscellaneous
Thread ID:
00598341
Message ID:
00598513
Views:
16
>My form has a combobox control that can use lunique. The table I want to check uniqueness against has an index on the concatenation of 2 fields (regular index). I want to choose a value in the combo box, and check to make sure this value is not in another table for the customer I am on (i.e. the key is the customer id I am on and the value I am entering). Another way of putting it: The table I am adding to has a field for customer id and one for code. I want to make sure there are no dupe records.
>
>I set lunique to .t. on the combo box control, set cView to a view I am creating. Not sure what to use for the filter (must use both fields) and what to use for cViewParameter for the control.
>
>Anyone done this before?
>
>Thanks.

Sally,

The Framework's Uniqueness setting is well suited to checking if one value has been used before. Here you only need one view parameter. I ran into a problem that allowed an account to have multiple records in a child table and the username in the child table did not have to be unique for the customer being edited but did have to be unique to this customer alone. I subclassed the control and added 2 properties: cViewParameter2 and cViewParameter2Value

The view for checking uniqueness should have 2 view parameters, assuming something like this in the properties of the control:
lUnique = .t.
cViewParameter = vp_cUserName
cViewParameter2 = vp_iCustomerId
cViewParameter2Value = ParentView.iCustomerId &&the parent's view current key value

I then modified the UniqueValue method, (calling the default method code if the 2nd view parameter is empty) loading the the 2nd view parameter and then essentially duplicating the original code from that point out:

*------------------------------------------------------
*--- If there is no second view parameter, do the
*--- default code.
*------------------------------------------------------
IF EMPTY(This.cViewParameter2)
IF NOT DODEFAULT()
RETURN .F.
ELSE
RETURN .T.
ENDIF
ENDIF

LOCAL llUnique

*-------------------------------------------------------------
*-- Save the current alias, and select the User ID Search view
*-------------------------------------------------------------
loSelect = CREATEOBJECT("CSelect",This.cView)

*-------------------------------------------------------------
*-- Create a local view parameters for the v_UserIDSearch view
*-------------------------------------------------------------
STORE This.oControl.Value TO (This.cViewParameter)
lcViewParm = (this.cViewParameter2Value)
STORE &lcViewParm TO (This.cViewParameter2)

*---------------------------------------------------
*-- Requery the view to search for the specified ID
*---------------------------------------------------
lnRetVal = REQUERY(This.cView)

*--------------------------------------------
*--- If no records found, the entry is unique
*--------------------------------------------
llUnique = (RECCOUNT(This.cView) = 0)

*---------------------------------
*-- If the entry is not unique ...
*---------------------------------
IF NOT llUnique

*------------------------------------------------------------
*-- Create a context sensitive message to display to the user
*------------------------------------------------------------
IF TYPE('This.oControl.Value') = 'C'
lcSuffix = "'" + ALLTRIM(This.TextBox.Value) + "'"
ELSE
lcSuffix = 'This'
ENDIF

*----------------------
*-- Display the message
*----------------------
=MsgSvc('NotUniqueValue', lcSuffix + '~')

*------------------------------------------*
*--- Restore the field's original value ---*
*------------------------------------------*
This.oControl.Value = This.uOriginalValue
ENDIF

RETURN llUnique
Gil Munk


"If a nation expects to be ignorant and free, it expects what never was and never will be." - Thomas Jefferson
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform