In this section, I will connect Business Logic Layer (BLL) to Data Access Layer and then User Interface Layer (UIL) to Business Logic Layer (BLL).
Note: If you are developing an enterprise application please see my next article on “Understanding 3-Tier vs. 3-Layer Architecture”.
Business Logic Layer Code
Namespace: Vishwa.Example.Business
Customer.vb : This class will communicate with previously designed Data Access Layer (DAL) in Part -2.
' Author : Vishwa@VishwaMohan.com
' Date : 10/15/2006
' Class : Customer Business Object
' Design Pattern: Domain Model and Identity Field
' Purpose: This class will act as Business Object and Business Logic Layer
Imports Vishwa.Example.Data
Namespace Vishwa.Example.Business
Public Class Customer
Private _custID As Integer = 0
Private _custName As String = String.Empty
Private _custDOB As DateTime = DateTime.MinValue
Private _custAddress As String = String.Empty
Private _dateCreated As DateTime = DateTime.Now
Private _dateModified As DateTime = DateTime.Now
#Region "Constructor"
Public Sub New()
End Sub
#End Region
#Region "Properties"
Public Property CustID() As Integer
Get
Return _custID
End Get
Set(ByVal value As Int32)
_custID = value
End Set
End Property
Public Property CustName() As String
Get
Return _custName
End Get
Set(ByVal value As String)
_custName = value
End Set
End Property
Public Property CustDOB() As DateTime
Get
Return _custDOB
End Get
Set(ByVal value As DateTime)
_custDOB = value
End Set
End Property
Public Property CustAddress() As String
Get
Return _custAddress
End Get
Set(ByVal value As String)
_custAddress = value
End Set
End Property
Public Property DateCreated() As DateTime
Get
Return _dateCreated
End Get
Set(ByVal value As DateTime)
_dateCreated = value
End Set
End Property
Public Property DateModified() As DateTime
Get
Return _dateModified
End Get
Set(ByVal value As DateTime)
_dateModified = value
End Set
End Property
#End Region
#Region "--Customer Object Functions--- "
Public Shared Function GetCustomer(ByVal custID As Integer) As Customer
Return DataAccess.GetCustomers(custID)
End Function
Public Shared Function GetAllCustomer() As Generic.List(Of Customer)
Return DataAccess.GetAllCustomers()
End Function
Public Shared Function AddCustomer() As Integer
Dim custInfo As New Customer
custInfo.CustID = 0
custInfo.CustName = "unknown"
custInfo.CustDOB = #1/1/1900#
custInfo.CustAddress = "unknown"
Return DataAccess.InsertCustomer(custInfo)
End Function
Public Shared Function AddCustomer(ByVal custInfo As Customer) As Integer
Return DataAccess.InsertCustomer(custInfo)
End Function
Public Shared Function UpdateCustomer(ByVal custInfo As Customer) As Integer
Return DataAccess.UpdateCustomer(custInfo)
End Function
Public Shared Function DeleteCustomer(ByVal custInfo As Customer) As Integer
Return DataAccess.DeleteCustomer(custInfo)
End Function
#End Region
End Class
End Namespace
Now, we have Database, Data Access Layer(DAL) and Business Logic Layer (BLL) ready for last step - User Interface Layer (UIL).
User Interface Layer (UIL)
Namespace: Vishwa.Example.WebSite1
Let's add a Web Form in the Project and drop a GridView Control and Object Data Source Control on this page and make sure that you have following code in the Source.
Customer.Aspx
-----------------------------------------------------------------
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Customer.aspx.vb" Inherits="Vishwa.Example.WebSite1.Customer" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server" >
<title>Customer</title>
</head>
<body>
<form id="frmCustomer" runat="server">
<div style="text-align:center">
<h2 >Customer Maintenance</h2>
<asp:LinkButton ID="lnkAddNew" runat="server" Text="Add New" OnClick="InsertBlankRecord" EnableViewState="false" />
<asp:GridView ID="gdvCustomer" DataKeyNames="CustID" runat="server" AllowPaging="True" DataSourceID="odsCustomer" >
<Columns>
<asp:CommandField ShowDeleteButton="True" ShowEditButton="True" />
</Columns>
<EmptyDataTemplate>
No Customer Record Found.
</EmptyDataTemplate>
</asp:GridView>
</div>
<asp:ObjectDataSource ID="odsCustomer" runat="server" DataObjectTypeName="Vishwa.Example.Business.Customer"
DeleteMethod="DeleteCustomer" SelectMethod="GetAllCustomer"
TypeName="Vishwa.Example.Business.Customer" UpdateMethod="UpdateCustomer">
</asp:ObjectDataSource>
</form>
</body>
</html>
--------------------------------------------------------------------------
Code File: Customer.Aspx.vb
--------------------------------------------------------------------------
Option Explicit On
Option Strict On
' Date : 10/15/2006
' Class : Customer
' Purpose: To Get,Insert, Update and Delete Customer Record
Namespace Vishwa.Example.WebSite1
Partial Class Customer
Inherits System.Web.UI.Page
Public Sub InsertBlankRecord(ByVal sender As Object, ByVal e As System.EventArgs)
Vishwa.Example.Business.Customer.AddCustomer()
gdvCustomer.DataBind()
End Sub
End Class
End Namespace
Code is complete now. Select Customer.aspx page in Project and Press F5 button (run). You will see the customer page as :
Case 1 : No Record.

Case 2: Click on Add New Link and a Blank new record with default value will be added
Case 3: Click on Edit link and enter a desired value for customer name and address and then click on Update link to update the record.
Case 4: Updated record is shown below. You can delete this record by clicking on Delete link. The record will be deleted and you will see the same screen presented in Case 1.

I hope this simple example helped you to understand and implement a 3 tier architecture using Visual Studio.NET 2005. If you have any questions or comments, please feel free to post and I will try to answer them.
Once you are able to understand these layer now, let's review the real information in next post.