|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
|
Announcements
Chapters
Services
Feature Zones
|
IntroductionThis article explains the advantages of abstracting the various layers during the time of Rapid Application Development (RAD). Everybody would have got a chance to work on ERP applications. A client who needs ERP products prefers UI of type Windows application. This is mainly because of the fact that Windows applications are quick in response and also have many sophisticated controls. ERP applications expect uniformity in UI across forms as one its key requirements. The uniformity in UI improves the productivity of the end users who use the ERP application. The major problem in an ERP application source is that the code written will become unmanageable after some time and it also becomes hard to extend. In this article, we will discuss how OOPS helps us to achieve some basic UI layering, which helps us to develop rapid ERP applications which are uniform in their look. Layering of Windows ControlsFirst and foremost step in the product development life cycle is abstracting the Windows controls which we are going to program around. As a thumb rule, we should always create a wrapper class (class inherits from the base class) of all the controls which we re going to use in the project and publish the assembly as a UI control library to all the developers in the project. This is applicable to only those controls which are inheritable. Most of the controls available are inheritable except a few like As a Proof Of Concept (POC), I would like to explain one of the key features of extending a control. In all our forms which we develop, we need to perform some basic non-business validations like email validations, mathematical calculation validations etc. Normally these types of validations will be done in the textbox validating event. In this POC, I would like to highlight the powerfulness of Regular Expressions and the layering of Windows controls. Let us re-define our problem statement. Regular Expressions are a very powerful library which helps us to perform pattern matching validations. In simple terms, we can define Regular Expressions as a formula which evaluates for a value which returns true or false. True means that the value evaluated adheres to the formula pattern. False means the value evaluated fails in the pattern match. Imports System.Text
Public Class TextBoxBase
Inherits System.Windows.Forms.TextBox
Private _RegularExpression As String = ""
Private _ErrorMessage As String = ""
Private ErrControl As New ErrorProvider
Public Property RegExToValidate() As String
Get
Return _RegularExpression
End Get
Set(ByVal Value As String)
_RegularExpression = Value
End Set
End Property
Public Property ErrorMessage() As String
Get
Return _ErrorMessage
End Get
Set(ByVal Value As String)
_ErrorMessage = Value
End Set
End Property
Private Sub TextBoxBase_Validating(ByVal sender As Object, _
ByVal e As System.ComponentModel.CancelEventArgs) _
Handles MyBase.Validating
Try
If _RegularExpression.Length > 0 Then
If RegularExpressions.Regex.IsMatch(Me.Text, _
_RegularExpression) = False Then
ErrControl.SetError(Me, _ErrorMessage) e.Cancel = True
Else
ErrControl.SetError(Me, Nothing)
End If
End If
Catch ex As Exception
' Do Exception Management Here.
End Try
End Sub
End Class
In the above example, the extension is very simple to make the article easy to understand. Ideally speaking, we will give much more configurations like, validating the textbox data based on multiple regular expressions, and also we should be able to configure the validations as AND/OR conditions. This will help us to have a very strong validation layer with various options. I don't want to cover the entire configuration, because in this, we are not trying to explain the complexity of the functionality, instead we are trying to explain the advantages of controls abstraction. Abstracting UI LayerAbstracting the Windows controls is the starting point in UI abstraction. Abstracting the controls helps us to extend the control's functionality in one place and it will be available to all the controls inheriting in the same hierarchy tree. Abstracting the UI layer is nothing but a flexible design on which the entire ERP form development happens. The main point which should be there in our mind during the design is that, the forms should be pluggable and also have a uniform look. There are various designs available to achieve this. Before getting to the design part, I would like to give some basic thumb rule which we need to keep in our mind.
In the design which we made for this article, we have used XML file as the data store to store the menu information. Each and every menu item will carry Form Development Steps
Registering Menus
Application Context ObjectWhen ever the form gets loaded, the first method which will get called is Public Interface IApplicationContext
'Connection String Configured in the exe.config.
ReadOnly Property ConnectionString() As String
ReadOnly Property SQLConnection() As SqlClient.SqlConnection
Function BeginTransaction() As SqlClient.SqlTransaction
' Holds all the instances of loaded forms.
ReadOnly Property FormsCollection() As FormCollection
Property MainUI() As Object ' Main UI object (MDI Form)
End Interface
Forms CollectionApplication Context Object has a readonly property called Public Class FormCollection ' Actual Code Excluded
Public Shared Function FindForm(ByVal FormID As String) As Form
Public Function AddForm(ByVal frm As Form, ByVal FormID As String) As Boolean
Public Function RemoveForm(ByVal FormID As String) As Boolean
End Class
Application Context Object adheres to Singleton patternApplication context object is one of the good examples of implementation of Singleton pattern. This object should be created only once and the same instance should get passed across forms. Following code snippet explains the minimal implementation of the Application Context class: Public Class WinApplicationContext
Implements IApplicationContext
Shared _MyInstance As IApplicationContext
Private Sub New() 'Private Constructor
End Sub Public
Shared Function ApplicationContext() As IApplicationContext
' Shared Property to return the instance.
If _MyInstance Is Nothing Then
_MyInstance = New WinApplicationContext
End
Return _MyInstance
End Function
End Class
Enhancements
HistoryHas only the layering for UI, which is not configurable. Only menus can get re-directed to a new component. In part II of this article, we will discuss about a design in which all the code which we write is pluggable.
|
||||||||||||||||||||||