Inactive Lookup Codes

Inactive Lookup Codes

Old forum URL: forums.lhotka.net/forums/t/1573.aspx


RealQuiet posted on Tuesday, October 24, 2006

I realize this problem is not specific to CSLA, but I'm trying to use CSLA objects to solve it, so here goes:

I currently have a collection of lookup objects.  These objects have 3 properties: key, value, and active flag.  I am also wrapping that collection up with a "cache" object that retrieves a set of lookup values the first time it's used and caches it.

The customer needs to be able to inactivate codes.  I think it should be easy enough to pull the active values out of the lookup collection using the FilteredBindingList, but the problem is what to do about inactive codes for historical data. 

For example, a record was entered sometime in the past with a code that was active at that time.  The code was made inactive at some point, and now the user tries to pull up the old record.  If I use the active codes to bind to a combo box, the old value isn't valid and can't be displayed.  In the combobox, I need to show the active items plus the inactive item that was previously entered.  In addition to this, this may occur in a datagrid, so there may be multiple inactive items that need to be added in with the active items.

I am hoping to find out how other people are handling the inactive code issue.

ajj3085 replied on Tuesday, October 24, 2006

Search the forum for displaying a 'blank' line in a combo box.  It sounds similar to this; the idea is that a combo should have a blank value, but the db list obviously won't contain the blank value.


You should be able to workout a similar solution, which is to create a view which is bound to the combo (which has everything + the selected value, if that value is inactive).

JoeFallon1 replied on Tuesday, October 24, 2006

I agree with Andy.

I add the "inactive" value to the list of "Active" values - but only when editing an existing record. A New record only gets the list of Actvie values.

I also have rules that check for IsNew and that the Inactive value has not changed to a different inactive value.

In other words, the user can leave the field alone and edit the rest of the record and the Save will work (even though the field is inactive.)  I do this by setting the orig_Value of the field to a private member variable and using that in my rules for ensuring the current value is either the originally loaded inactive value or is a new Active value.

Also, they can change the field if they want to one of the Active values. They just can't change it to a different inactive value.

Joe

 

mtagliaf replied on Tuesday, October 24, 2006

I agree w/ the above, with one other point - I see these as two different use cases - "All Active Codes" and "All Active Codes along with the one inactive code on the current record". Two use cases - two objects (or, at the very least, a second factory method on the same object that alters the SQL).

You might also want to rethink the caching on the second object - since the object changes frequently.

matt tag

RealQuiet replied on Tuesday, October 24, 2006

Thanks guys.  You've hit exactly what I'm looking for.  Currently, my "cache" object has a method that returns a given lookup list.  That method has an override to accept a string parameter for the first item.  So you could pass in "<Choose Something>", and the object would pass you back the list with that as the first item in the list.  In that method, I clone the cached object and add the item, so the original cached item is untouched and still available for use throughout the application.

Joe, it sounds like you have done exactly what I need to do with the object keeping the original value, etc, and that is the behavior I want.  Can I ask how you are adding the current inactive values to the active list?  Is this lookup exposed through your BO, and the BO populates the extra values for you?  -Or- Do you pass in the values to the lookup object to return you the modified list?  Or what is the cleanest way to do that?

SlyBelle replied on Tuesday, October 24, 2006

Not sure if this is the absolutely right way, but this is how I accomplished what your looking to do.  I do it through actual SQL.  Basically, you pass the Stored Procedure the current value and the stored procedure returns all the currently active records plus the original record selected.  Now you can select any currently active items or the one that was previosuly used since they will be listed in the listbox.

SELECT

   [TestId],

   [TestName],

   [ActiveStatus]

FROM [tblTest]

WHERE

([TestId] = @OldTestIdValue) or ([ActiveStatus] = 1)

 

Brian Criswell replied on Tuesday, October 24, 2006

I lob the lookup list into an ObjectListView and set its filter property to "Active = True or Id in (" + GetIdsCurrentlyInUseByObjects() + ")".  Then you get the items that are active or used by the items that you want to display.

RealQuiet replied on Tuesday, October 24, 2006

Perfect, thanks everyone!

Copyright (c) Marimer LLC