## User Defined Criteria

In a nutshell, I'm looking to know what the standard methodology is for coding user defined criteria (such as Excel's conditional formatting)

For example, let's say I have a commission system with the following code:

```if (sales < 100 && empCategory = "junior") {
commRate = 0.50;
} else if (sales < 100 && empCategory = "senior") {
commRate = 0.60;
} else if (sales >= 100 && sales <1000) {
commRate = 0.70;
} else {
commRate = 0.80;
}```

So, in this example the logic that determines the commission rate is hardcoded. However, I want to take this logic out of the hardcoded code and allow the user to add, modify and delete these criteria using boolean and comparison operators against fields in the db (again, just like Excel conditional formatting)

Note I'm using the setting of a variable as an example. Instead, I could be calling another procedure based on the criteria?

Also, please note that the above example is very simplistic. The calculations in real life will involve a much more complex formula that uses most of the boolean/comparison operators with nested statements. There will almost always be an "else" case if no condition is met. Finally, this will be applied to each row is a fairly large recordset.

Designing the GUI for this isn't a problem, but I'm unsure:
1. Where to store the user's conditions (in a db table, in an XML, etc...)?
2. How to set the commRate variable if the boolean/comparison operators and indeed the very structure of the boolean statement (i.e nested statement) isn't hardcoded

I'm stumped how to achieve this if I'm not actually using the boolean/comparison operators in my actual code, but I know it is possible. I know you can use a binary tree data structure to work with math formulae but I'm unsure if I'm on the right track.