Reporting Business Rule Violations


So how do you capture these rules? If you have written business objects in Visual Basic (VB) 6, you will remember that the way errors were reported to the user was with the Err.Raise statement. Typically, you would have a list of constants that defined error numbers and another list of constants that defined error messages. Catching the error meant putting an error handler in the routine, checking the number of the error (and do not forget subtracting the vbObjectError value!), and using a message box to display the error to the user. Some developers became clever and added icons to the left or right of a label or textbox in their own custom control that they could use to display error messages to the user in the form of a tooltip. Microsoft has been good at listening to the desires of the development community. And it really listened during the development of .NET. Microsoft now provides the error provider control that you can use to display error information to the user. There are no more errors in message boxes. However, the error provider control is only a tool, which means it can be used in both an efficient and inefficient manner. Consider the following situation:

Your user John is sitting at your application and working on a form with a combination of 30 textboxes and/or combo boxes that he needs to fill out. He finishes filling out the form and clicks the OK button. The form comes back with a message telling John that he made an error in textbox 3. He fixes it and clicks the OK button again. The form comes back with a message telling John he made an error in combo box number 6. He fixes it and clicks the OK button again. It comes back with an error, again and again and again until he fixes all of the errors.

Over the years, many developers have been on the receiving end of an irate user who has been in this situation. In this chapter you will fix this problem the right way, with a reusable set of routines.

Caution

If you trap a business rule in the user interface, you must also trap it in the data-centric business objects. Not doing so may pose some security issues, but another issue is that other applications may use your objects and they will not be going through your interface!




Building Client/Server Applications with VB. NET(c) An Example-Driven Approach
Building Client/Server Applications Under VB .NET: An Example-Driven Approach
ISBN: 1590590708
EAN: 2147483647
Year: 2005
Pages: 148
Authors: Jeff Levinson

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net