NameValueList that changes over time

NameValueList that changes over time

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


odie posted on Thursday, June 22, 2006

This might seem basic to some but I keep running into it and can't seem to get my head around the best way to deal with it.

e.g. Classes
Product (BusinessBase)
ProductCategoryList (NameValueList) fairly static but will change over time

When a user enters a new product they select among other things the product category it belongs to from a dropdown list which is populated via ProductCategoryList, which returns the current list of active product categories

The problem I am having has to do with time and viewing the a product record at some unknown time in the future when the product category selected for a given product has expired. If you populate the ProductCategoryList with active product categories the list will no longer contain the item for this product and thus will not be able to be displayed to the user.

What is the best way to get around this problem ,as some of my selection lists allow for items to be expired.

My solution is to have two GetList functions
GetList() - return list of active (non-expired) items (cached)
GetList(ByVal ID as guid) - same as above except include the specified ID regardless if expired (not cached)

When a new product is added I use the cached GetList() to display categories to the user. When editing/viewing an existing record I use the GetList(ID) using the ID of the selected record. This would allow expired records to be displayed as required.

Granted in many cases I would ideally only load the one record specified by the ID as I would not want that value changed. My example may not be the best but lets say over time this particular records product category can be changed and at the point in time it is changed the currently product category is expired, the ProductCategoryList would have to contain currently active list plus the expired value selected.

So basically I would like some input on if this approach is the best way to deal with this situation? or is there a better way?

Thanks in advance for your input.

RockfordLhotka replied on Thursday, June 22, 2006

What you are saying (I think) is that a category can expire and become invalid, but it doesn't go away. And existing products that are in that (now expired) category remain in that category. But the products are still valid and useful even though they are no longer in a valid category.

While this sounds somewhat odd, I can certainly believe that it is the case. Users come up with some really strange requirements...

It seems clear, then, that your Product class can't rely on a NV list to get the name of the current category - it must get that directly, because Product.Category and Product.CategoryName could be "invalid" values. But your overall problem isn't that complex, because a user can never _set_ Product.Category to one of these invalid values. So Product.DataPortal_Fetch() can just directly load the category name into a field within Product.

So then the issue becomes a UI one - in that you can't just use a simple combobox to display the category, because the category can be a value that isn't "valid" and thus isn't in the NV list of valid options.

My guess is that the easiest solution for this is to write a custom combobox control. People do this all the time to support the "(none)" or "(default)" concepts you see in many comboboxes. those values aren't real, and thus aren't in the NVL, but are still in the combobox. This is done by creating a custom combobox control that artificially inserts this extra item at the top of the list, and abstracts the concept away from data binding. You can do the same thing here - but with teh CategoryName value from Product being that artificially inserted value in the control.

odie replied on Thursday, June 22, 2006

Let me change my example to a better one and see if I understand correctly.

Drafters are assigned to Projects by selecting from a current DraftersList. Eventually the project is closed and the drafter quits. 6 months later someone remembers some comment need to be added to the project. Now when the record is pulled up the current DraftersList will not contain the drafter selected for that project as they are no longer with the company, but their name needs to be displayed none-the-less for reference.

Another situation also arises, lets say the Drafter originally selected only worked a short time on the project then quit and another drafter takes over, becuase the drafter is no longer active the project manager needs assign a new drafter to the project. The originally assigned, but now inactive, drafter needs to be displayed, because of the first case, but also a current DraftersList needs to be available for the project manager to select the new drafter from.

So if I follow your comments correctly, I would load the Drafters name in the Project when it is loaded. Then on the UI my custom combobox would bind to the current DraftersList (NV) along with a custom set of properties for setting the currently selected DrafterID and DrafterName. This would allow the current selection (expired value) to be displayed along with a current DraftersList to select from should a change be required.

RockfordLhotka replied on Thursday, June 22, 2006

Basically, yes. I would think that your custom combobox would work just like the normal one, but with one extra property - which is the "default text" to be displayed. That text would be displayed any time an an invalid DrafterId value comes from the data source (your object).

david.wendelken replied on Thursday, June 29, 2006

 

It seems to me you have several different purposes for the list of drafters:

  1. List of currently assigned drafters on a project.
  2. List of drafters ever assigned to the project.
  3. Combo of the above two purposes.
  4. List of currently employed (and presumably available) drafters for assignment to a project.
  5. List of drafters ever employed.
  6. and maybe more...

Seems to me each program that wants a list of drafters needs to understand what kind of list it wants, and the NewDrafterList function needs to accept parameters that populate the list accordingly.  To me, that would be one object.

Hope that helps.

Copyright (c) Marimer LLC