Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

String Conditional

Status
Not open for further replies.

link9

Programmer
Nov 28, 2000
3,387
US
Hello all --

I have what I hope is an interesting question that I further hope someone here has conquered in the past.

A little bit of background:
We are attempting to architect a reusable menu system for web applications. We have tackled all obstacles but one: special business rules.

Our goal is to set up a system whereby anyone could setup a web application. To this end, we have devised a standard database setup that covers everything but the inevitable whacko client business rule. i.e. when this strange condition exists, then do this.

We have always handled this situation by deriving a class from the base class and manually coding up the rule. That's what I'm trying to avoid, which would create less work for me (the true goal ;-)).

Specific case:
The app: Statistical reporting site that delivers results based on some number of user selected filters.

The problem: When a user has selected filterA, then I don't want them to be able to select filterB.

FilterA & filterB have no other logical connection, other than this rule that's been thrust upon us by the client. The only way to tell if filterA has been selected is to evaluate Session["filterA"].ToString()

The Question
If there was some way that I could put a 'Condition' field in the database for this filter (I have a table containing all filters), then I might make that field say:

if(Session["filterA"].ToString() != -1)

and in this case, no values would be pulled for filterB, since -1 is the value that equates to "All".

So, in code, I could simply code up that statement, and the world is rosy. But, what I'm looking for is a way to read in that condition from some source (preferably a database, but I'm not completely opposed to XML) and then apply it to the logic that creates the menu.

In this way, when a new application is launched, I simply write in the business rules to the database, and the standard menu creator takes those rules into account when it renders the menu.

So... has anyone any words of wisdom for me? I'm basically looking for some Eval() statement or something. Eval() is from javascript, and it performs things like this. I know that there's no specific Eval() statement in C#, so I'm looking for alternatives here.

I'm not even locked into the specific method I've posted, it was basically just a brain dump of what I'm looking for. If anyone has any ideas for me, that would be grand.

Thanks alot, folks! :)
paul

penny.gif
penny.gif

The answer to getting answered -- faq855-2992
 
Paul,

I don't have any help for you in terms of coding styles (since I'm only in the learning stages of C#). But I have dealt with a similar logical problem.

We created a child table to the main table. Something like:

Main table columns: <Filter_id> <Filter>

Child table: <Id> <Filter_id> <Id_to_Exclude>

So the list of available filters was itself filtered once you made selections. These list was comprised of filters not already selected and not having their Ids in the ID_To_Exclude columns.

HTH,

Perry
 
Yes, I have worked this out, as well. This is a hierarchical data structure, which is pretty standard.

What I'm looking for is help working out a non-hierarchical, non-standard business rule type constraint.

To clarify, your situation says if marketA is selected, then only show facilities which are located in marketA. What I need is if any market is selected, then don't display any specialties, or something like that, where there would be no relationship between the two w/in the database, and no logical way to work it out from filters picked other than a special conditional which I'm looking to import into the class. A special case, if you will.

But thanks. :)
paul

penny.gif
penny.gif

The answer to getting answered -- faq855-2992
 
Paul -

What about storing SQL in a column in the database?

When deciding to display a menu (or not) you could run a bit of stored SQL that would tell you thumbs-up or thumbs-down.

No extra coding involved, and can be updated via a simple script.

Chip H.
 
I've given that some thought, but I have one problem...

The value that I need to evaluate will be on the coding side (usually stored in the Session object), rather than a value in the database.

And so I'm having a hard time figuring out how to overcome that.

Hmmm... now that I'm thinking about it, I suppose I could create a temp table that would hold those values, then fire the sproc, which would promptly drop the table when it was finished reading the values.

I think that would work... I would rather not do that, but unless anyone has another idea, it looks like the answer.

penny.gif
penny.gif

The answer to getting answered -- faq855-2992
 
We wound up adding two columns to the existing schema:

conditionName & conditionValue (on the main filters table)

Both are | separated strings that contain the special rules for creating (or not creating) the menus. | separated to allow for more than one set of rules per row.

Currently,

//filters being the in-memory object of user choices
if(filters[conditionName] == conditionValue)
{
//create the menu
}

is more or less how we've solved it. Not exactly as elegant as I would have liked, but it's doing the trick.

I can see why we don't have Eval(), but boy, wouldn't that be nice? :)

thx for the contributions, folks!
-paul

penny.gif
penny.gif

The answer to getting answered -- faq855-2992
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top