CS 432

Lab 1

Building N-Tier Applications

 

Open Visual Studio 2005 and create a new solution: Ntier. We are interested in creating an application using the Northwind database – you can download this from the class homepage. When the application loads, we want to display all the orders, and then calculate the total price of the order and the shipping charges according to the following rules:

a.       If the order contains three or more items, a discount of 10% is offered over the total price.

b.      If the order contains five or more items, a discount of 15% of the total price as well and free shipping is offered.

c.       For orders with less than five items the shipping is 10% of the total price.

 

Part 1:

For this part, we will create a poorly designed solution where the user interface and business logic is placed together. Call this project ntier1 and create an appropriate front end to display the orders (dropdown box with order id’s displayed). Supply a button which when clicked will compute the discount, shipping, and the total price for the order. Here is the code to connect to an access database (assuming Northwind.mdb is on the C drive):

Dim ConnStr As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data

 Source=C:\Northwind.mdb"

Dim ObjConn As New OleDb.OleDbConnection(ConnStr)

Dim dt As New DataTable

Dim SqlStr As String = "select OrderID from Orders"

Dim ObjCmmd As New OleDb.OleDbCommand(SqlStr, ObjConn)

Dim ObjDA As New OleDb.OleDbDataAdapter(ObjCmmd)

ObjDA.Fill(dt)

 

Here is the code to populate a combo box called combobox1.

            Dim i As Integer

For i = 0 To dt.Rows.Count – 1

ComboBox1.Items.Add(dt.Rows(i)(0))

Next

 

Another way to do the same thing:

Dim irow As DataRow

For Each irow In dt.Rows

ComboBox1.Items.Add(irow("OrderID"))

Next

 

Part 2:

For this part, create a new project under Ntier and name it ntier2. In the solution explorer select ntier2 and from the project menu select ‘set as startup project’. Let’s use an OO design:

  1. Rename the form UI. Copy the form objects from the form of ntier1.
  2. Create a class called Order (where you will place the details of that order) in Order.vb. The code is given on the class homepage.
  3. Add a new class BL in BL.vb and create a method called getOrders(). The code for the class is given on the class homepage.

 

  1. When UI is loaded call the getOrders() function.
  2. When the calculate button is clicked fill in the labels.
  3. Can you implement a 3-tier system by adding another layer (DB) that will talk to the database?