I'm creating a web form, where in there are around 12-15 Input Fields...
You can have a look at the screen here http://img9.imageshack.us/img9/2951/image001um.jpg and here http://www.freeimagehosting.net/uploads/f9f4491598.jpg
The request is such that depending on the data the user selects in the Gridview and the DropDown list, the appropriate Textboxes and CheckBoxes needs to be displayed.
Some times the conditio开发者_如何学Cns are very direct, like when the DDL value is "ABC", get only paid amount from the user.
Sometime they are so complex like... IF DDL is "DEF" and Selected GPMS value is between 1000-2000, calculate the values of allowed, paid etc (using some formula) and the focus should be directed to Page No Field, leaving the other fields open incase user wants to edit... There are around 10-15 conditions like this.
As this was done through agile, conditions were being added as and when, and wherever it feels appropriate (DDL on change Event, GridView on selecting change event etc... etc..) After completion, now I see the code has become a big chuck, is growing unmanageably...
Now, I'm planning to clear this... From you experience, what you think is the best way to handle this. There is a possibility to add more conditions like this in future...
Please let me know, incase you need more information. I'm currently developing this app in C# .Net WindowsForms
Edit: Currently there are only three items (The Datagrid, the DDL, the OverrideAmt CheckBox) that change the way other fields behave...
Almost all of the conditions will fall between the two situations I mentioned... Mostly they belong to "Enabling/Disabling".. "Setting of Values"... and "Changing Focus" or any combination of these.
Minimal overhead
Write a single-procedure that contains all the evaluation logic.
i.e. evaluate all the individual states and show/hide the appropriate controls from within the procedure.
Now call this procedure whenever there is any change event
that requires you to re-evaluate whether to show/hide any controls.
Do NOT show/hide any controls from outside this procedure.
Any additional validation-checks in future can always be easily incorporated
by adding the additional checks inside this procedure.
To improve upon the performance of this procedure:
[1] Add a parameter (int/string) to the procedure.
[2] Pass a different value in this parameter when calling from different events of different objects.
[3] In the procedure, from on the value of the parameter, you can determine what object(& what event) has triggered this re-evaluation.
Thus You can evaluate only those conditions that could possibly depend on this particular change in this particular object. This way the re-evaluation overhead is reduced to the bare-minimum.
精彩评论