views:

48

answers:

2

I feel like I am fighting against the current when I develop ASP.NET Webform apps. I frequently run into the same problems, and while I eventually find some kind of workaround i'm never fully satisfied with the results.

Here is an example of a typical problem:

The design requires a grid or grid-like result set. This result set is pulled from a database, however, there are additional controls on each row that are not data bound, but their contents are used to insert data into other records.

A good example of this would be displaying a list of products, then adding selected products to a shopping cart based on values entered into quantity fields, and options selected per product. Throw into the mix that you have to allow multiple lines to be added to the cart at the same time, and it starts to get more complex.

Let's add to that mix that you can't select certain products together (mutually exclusive), that you can only select a certain number of one product, but not another, that prices may change while the user is selecting their items, that you you get an overall discount per item based on quantity purchased (both per item and overall order), that you are using a line of credit and cannot exceed the line of credit, nor can you buy more of a given item than an arbitrary amount set in your account or in the product by your account representitive (think certain over the counter medications that the government limits how many you can buy), etc.. etc.. etc..

What starts out as a simple grid with an add to cart becomes a hopeless mess of business logic, which then of course requires validation and notification to the user of various errors in their choices.

How does one deal with very complex data entry schemes in asp.net? How do you even begin to design a piece of software to do all this?

EDIT:

Please don't suggest changing the interface, as the interface is not the problem. Users are fine with it, and they demand that it function the way it does. I'm looking for help on how to design and solve the problem of implementing it.

+1  A: 

Some options to consider:

  • Separate out your validation logic so you can call it from both client-side and server-side code (enables next point).
  • Use AJAX to perform server-side validation and provide immediate feedback as the user performs various tasks, ie increases quantity.
  • Provide abundant and clear instructions/feedback to the user both before and after any actions are performed. Before: warn that product X can't be bought with product Y (especially if Y is already in the cart). After: explain the problem exactly and suggest ways to correct, eg "why don't you remove product Y?")
  • Fail gracefully, ie if only one product fails validation then ensure all other products are added.
  • Simplify the entry process, eg only allow one product to be added to the cart at a time.

The last point is important. A complicated data entry process can confuse users before they start, and makes trying to understand the numerous validation errors difficult. And this is even before you start coding the validation logic.

AUSteve
I'm sorry if I wasn't clear. I wasn't asking how to simplify the process, I was asking how to implement it. I cannot change the requirements, they are fixed and set in stone. The user is not confused by the interface because it's expected and normal for the industry it's in. I used a shopping cart as an example so you might be more familiar with the concepts.
Mystere Man
@Mystere Man - I think the first two points should suffice. If you have your validation logic existing on the server, then you can make JS calls (via AJAX) to perform the actual validation. So, the logic is in one place, and has two callers.
StingyJack
@StingyJack - I didn't ask about client side validation. It's not needed or required. I'm asking about how, in asp.net to implement validation of this kind of complexity.
Mystere Man
@Mystere Man - That is going to depend on all of the individual rules that need to be implemented. Unless you post all of the individual rules, there is no way anyone can reasonably answer *that* question.
StingyJack
I'm not asking you to implement my specific rules. I am asking about methods, patterns, techniques, etc.. that can be used for these situations. Please don't say "there's no way anyone can answer" when in fact people can. Jason offered some interesting advice. Don't be so literal.
Mystere Man
+1  A: 

Don't put anything other than the basic validation in your code behind. The code behind should just take what the user entered, build a business object (or collection of business objects) and let those business objects validate themselves.

Each business rule should be a single function call on the business object that deals with just the one rule and nothing else. You then simply call them one after another and keep track of which ones pass and which ones fail.

When a validation fails, the business objects can provide the code behind enough information that it can display the correct errors and highlight the fields that have errors.

Jason Berkan
I'm not sure you really read my requirements. Validation cannot be done on a line by line basis because some lines exclude other lines. If I go from beginning to end, then I have issues where line items i processed earlier are valid then, but invalid later in the list.
Mystere Man
I did not say line by line - I said rule by rule. Some rules can be implemented on a specific line (or business object). Other rules can only be implemented on the entire order (or the collection of business objects). What is important is that each rule is self contained, which aids in readability of the code.
Jason Berkan
Interesting perspective. I usually think of things in terms of operations that have to be performed on data rather than rules and the data they work with. However, the rules in this case are both global and data driven. But this gives me ideas.
Mystere Man