Professional Documents
Culture Documents
NET
SkillSoft Corporation. (c) 2004. Copying Prohibited.
Table of Contents
Chapter 2: Creating the Order Processing Application...............................................................1
Architecture of the Order Processing Application..................................................................1
Creating the Database Schema.............................................................................................4
Creating the Order Processing Application............................................................................6
Creating the Customers Class.........................................................................................6
Creating the Orders Class................................................................................................7
Creating the OrderInformation Class...............................................................................9
Creating the Invoices Class...........................................................................................10
Creating the InvoiceCreditCardInfo Class......................................................................11
Creating the Shared Module..........................................................................................12
Creating the Login Manager Window.............................................................................13
Creating the Application Manager Window....................................................................14
Creating the Place Order Window..................................................................................15
Creating the View Order Status Window........................................................................18
Creating the Update Order Status Window....................................................................19
Creating the View Order Information Window................................................................21
Creating the Raise Invoice Window...............................................................................23
Creating the Invoice Window.........................................................................................25
Creating the Customer Registration Window.................................................................28
Unit Testing..........................................................................................................................30
Chapter 2: Creating the Order Processing
Application
Download CD Content
Unified Modeling Language (UML) enables you to create component diagrams that model the
physical system of an application. A component diagram consists of components, such as source
code, binary code, dynamic−link library files, or executable. The component diagram also illustrates
the dependencies between these components. You can use Visio to generate .NET skeleton code
for an application based on the UML component diagram. You can then customize this skeleton
code according to the requirements of the application.
This chapter demonstrates how you can use a UML component diagram that models the physical
system of the Order Processing application to create the .NET skeleton code and then customize it.
The Order Processing application consists of an OrderProcessing project, which utilizes the classes
that the UML component diagram creates. This project enables customers to register, select
products, and place an order.
Reprinted for milanm, Avanade SkillSoft, SkillSoft Corporation (c) 2004, Copying Prohibited
.NET InstantCode: UML with Visio and Visual Studio .NET 2
The Customer component creates the .NET skeleton code for the Customers class. The Order
component creates the .NET skeleton code for the Orders and OrderInformation classes. The
Invoice component creates the .NET skeleton code for the Invoices and InvoiceCreditCardInfo
class.
• Shared.vb: Provides the main() function that establishes a connection with the
OrderProcessing database and invokes the Login Manager window to let customers and
administrator log on to the Order Processing application.
• frmLoginManager.vb: Provides the LoginManager class that defines the Login Manager
window that customers and administrator use to log on to the Order Processing application.
Reprinted for milanm, Avanade SkillSoft, SkillSoft Corporation (c) 2004, Copying Prohibited
.NET InstantCode: UML with Visio and Visual Studio .NET 3
• Customers.vb: Provides the Customers class that registers a new customer and retrieves
information about a particular customer.
• Orders.vb: Provides the Orders class to save the orders that a customer places, in the
database. The Orders class also retrieves the status of an order, sorts information based on
the status of an order, and updates the status of an order.
• OrderInformation.vb: Provides the OrderInformation class that saves and retrieves product
information for an order.
• Invoices.vb: Provides the Invoices class that generates a new invoice and retrieves invoice
information for an order.
• frmPlaceOrder.vb: Provides the PlaceOrder class that defines the Place Order window,
where the customer can select products and place an order.
• frmViewOrderStatus.vb: Provides the ViewOrderStatus class that defines the View Order
Status window, where a customer views the status of an order after providing its order id.
• frmViewOrderInfo.vb: Provides the ViewOrderInfo class that defines the View Order
Information window, where a customer views the product information included in an order,
such as the product name and the quantity ordered.
• frmRaiseInvoice.vb: Provides the RaiseInvoice class that defines the Raise Invoice window,
where the administrator views information on completed orders and raises invoices
accordingly.
• frmInvoice.vb: Provides the Invoice class that defines the Invoice window, where the
administrator views information on the customer and order, and generates the invoice for
that order.
Figure 2−3 shows the class diagram for the Order Processing application:
Reprinted for milanm, Avanade SkillSoft, SkillSoft Corporation (c) 2004, Copying Prohibited
.NET InstantCode: UML with Visio and Visual Studio .NET 4
Figure 2−3: The Class Diagram for the Order Processing Application
Listing 2−1 shows the SQL script to generate the database on the SQL Server:
Listing 2−1: Creating the OrderProcessing Database
Reprinted for milanm, Avanade SkillSoft, SkillSoft Corporation (c) 2004, Copying Prohibited
.NET InstantCode: UML with Visio and Visual Studio .NET 5
The above listing creates the OrderProcessing database for the Order Processing application. The
above code creates the following tables in the database:
• Company: Stores information about the company that uses the Order Processing
application. It stores the company name, address, city, country, zip code, and phone.
• Customers: Stores information about the customers. It stores the customer id, user name,
password, first name, last name, address1, address2, city, country, and zip code.
Reprinted for milanm, Avanade SkillSoft, SkillSoft Corporation (c) 2004, Copying Prohibited
.NET InstantCode: UML with Visio and Visual Studio .NET 6
• InvoiceCreditCardInfo: Stores information about the credit card that a customer uses to pay
for an order when an invoice is generated. It stores the invoice id, name on the credit card,
and credit card number.
• Invoices: Stores information about the invoices that the administrator generates when an
order is completed. It stores the invoice id, order id, customer id, invoice date, subtotal,
shipping and handling cost, total amount, and payment mode.
• OrderInformation: Stores information about the products in the order that a customer places.
It stores the order id, product id, and quantity of product.
• Orders: Stores information about the orders. It stores the order id, order date, customer id,
amount, completion date, and order status.
• Products: Stores information about the products, such as product id, product name, unit
price, and quantity available.
'Static Model
Imports System.Data.SqlClient
Public Class Customers
Public customerId As Integer
Public username As String
Public password As String
Public firstName As String
Public lastName As String
Public address1 As String
Public address2 As String
Public city As String
Public country As String
Public zipCode As String
Private ds As DataSet
Private sqlCommand As sqlCommand
Private sqlda As SqlDataAdapter
'This method registers a new customer and returns the id of the newly registered
customer
Public Function addCustomerInformation() As Integer
sqlCommand = New SqlCommand("insert into customers values('" &
username & "','" & password & "','" & firstName &
"','" & lastName & "','" & address1 & "','" & address2 &
"','" & city & "','" & country & "','" & zipCode & "' )",
sqlConnection)
sqlCommand.ExecuteNonQuery()
sqlCommand = New SqlCommand("select max(customerId) from customers", sqlConnection)
sqlda = New SqlDataAdapter(sqlCommand)
ds = New DataSet
Reprinted for milanm, Avanade SkillSoft, SkillSoft Corporation (c) 2004, Copying Prohibited
.NET InstantCode: UML with Visio and Visual Studio .NET 7
sqlda.Fill(ds)
If Not ds.Tables.Count = 0 And Not ds.Tables(0).Rows.Count = 0 Then
Return ds.Tables(0).Rows(0).Item(0)
Else
Return 0
End If
End Function
'This method retrieves the information for a specified customer
Public Sub retrieveCustomerInformation(ByVal cId As Integer)
sqlCommand = New SqlCommand("select firstname,lastname,address1,address2,
city,country,zipcode from Customers where customerId='" & cId & "'",
sqlConnection)
sqlda = New SqlDataAdapter(sqlCommand)
ds = New DataSet
sqlda.Fill(ds)
If Not ds.Tables.Count = 0 And Not ds.Tables(0).Rows.Count = 0 Then
firstName = ds.Tables(0).Rows(0).Item(0)
If Not IsDBNull(ds.Tables(0).Rows(0).Item(1)) Then
lastName = ds.Tables(0).Rows(0).Item(1)
Else
lastName = ""
End If
address1 = ds.Tables(0).Rows(0).Item(2)
If Not IsDBNull(ds.Tables(0).Rows(0).Item(3)) Then
address2 = ds.Tables(0).Rows(0).Item(3)
Else
address2 = ""
End If
city = ds.Tables(0).Rows(0).Item(4)
country = ds.Tables(0).Rows(0).Item(5)
zipCode = ds.Tables(0).Rows(0).Item(6)
Else
firstName = ""
lastName = ""
address1 = ""
address2 = ""
city = ""
country = ""
zipCode = ""
End If
End Sub
End Class 'END CLASS DEFINITION Customers
'Static Model
Imports System.Data.SqlClient
Public Class Orders
Public orderDate As Date
Public customerId As Integer
Reprinted for milanm, Avanade SkillSoft, SkillSoft Corporation (c) 2004, Copying Prohibited
.NET InstantCode: UML with Visio and Visual Studio .NET 8
• SaveOrder(): Saves the order in the Orders table and returns the order id of the newly saved
order.
• RetrieveOrderByStatus(): Accepts the order id as a parameter and retrieves the order status
whether it is pending, completed, or invoiced.
• UpdateOrderStatus(): Accepts the order id and status mode as parameters and updates the
order according to the status mode. This method updates the order status as ‘C’ if the status
mode is ‘completed’ and ‘I’ if the status mode is ‘invoiced’.
'Static Model
Imports System.Data.SqlClient
Public Class OrderInformation
Public orderId As Integer
Public productId As Integer
Public quantity As Integer
Dim sqlCommand As sqlCommand
Dim sqlda As SqlDataAdapter
Dim ds As DataSet
'This method saves the product wise order information
Public Sub SaveOrderInfo()
Try
Reprinted for milanm, Avanade SkillSoft, SkillSoft Corporation (c) 2004, Copying Prohibited
.NET InstantCode: UML with Visio and Visual Studio .NET 10
• SaveOrderInfo(): Saves the product information provided in an order, such as the product id
and quantity of that product.
• RetrieveOrderInfo(): Accepts the order id and returns product information for the order
referenced by that order id.
'Static Model
Imports System.Data.SqlClient
Public Class Invoices
Public invoiceId As Integer
Public invoiceDate As Date
Public orderId As Integer
Public customerId As Integer
Public subTotal As Double
Public paymentMode As String
Public shipping_handlingCost As Double
Public totalAmount As Double
Private sqlCommand As sqlCommand
Private sqlda As SqlDataAdapter
Private ds As DataSet
'This method generates the invoice
Reprinted for milanm, Avanade SkillSoft, SkillSoft Corporation (c) 2004, Copying Prohibited
.NET InstantCode: UML with Visio and Visual Studio .NET 11
• generateInvoice(): Generates a new invoice and stores the invoice information in the
Invoices table.
'Static Model
Imports System.Data.SqlClient
Public Class InvoiceCreditCardInfo
Public invoiceId As Integer
Public nameOnCard As String
Public creditCardNumber As String
Private sqlCommand As sqlCommand
Reprinted for milanm, Avanade SkillSoft, SkillSoft Corporation (c) 2004, Copying Prohibited
.NET InstantCode: UML with Visio and Visual Studio .NET 12
Public Sub New(ByVal invoiceId As Integer, ByVal nameOnCard As String, ByVal creditCardNu
Me.invoiceId = invoiceId
Me.nameOnCard = nameOnCard
Me.creditCardNumber = creditCardNumber
End Sub
'This method saves the credit card information of the customer.
Public Sub saveCreditCardInfo()
sqlCommand = New SqlCommand("insert into InvoiceCreditCardInfo values(" & invoiceId
&
",'" & nameOnCard & "','" & creditCardNumber & "')", sqlConnection)
sqlCommand.ExecuteNonQuery()
End Sub
End Class
'END CLASS DEFINITION InvoiceCreditCardInfo
In the above listing, the saveCreditCardInfo method saves the customer’s credit card information
into the InvoiceCreditCardInfo table.
Imports System.Data.SqlClient
Imports System.IO
Module _Shared
'A variable to store the login role. The role can be of administrator or customer.
Public loginRole As String
'Stores the id of the customer
Public custId As Integer
'A boolean variable that keeps in track the success and failure of invoice generation proces
Public boolInvoiceGeneration As Boolean
Dim strSqlConnection As String
Public sqlConnection As New sqlConnection
Public Sub main()
'Try to establish connection with database OrderProcessing through SQLClient Connection o
Try
Try
'Read connection string from a text file settings,text located in /bin folder of the a
Dim sr As New StreamReader("Settings.txt")
strSqlConnection = sr.ReadLine
sr.Close()
Catch ex As Exception
'If file settings.txt not found
strSqlConnection = "SERVER=localhost;UID=sa;PWD=sa;Initial
Catalog=OrderProcessing"
End Try
sqlConnection.ConnectionString = strSqlConnection
sqlConnection.Open()
Dim objLoginManager As New LoginManager
objLoginManager.ShowDialog()
Catch ex As Exception
MsgBox("Error in establishing connection", MsgBoxStyle.OKOnly, "CONNECTION ERROR")
Exit Sub
End Try
End Sub
End Module
Reprinted for milanm, Avanade SkillSoft, SkillSoft Corporation (c) 2004, Copying Prohibited
.NET InstantCode: UML with Visio and Visual Studio .NET 13
In the above listing, the main() function establishes a connection with the OrderProcessing
database through a SqlConnection object and invokes the Login Manager window.
Listing 2−8 shows the code for the frmLoginManager.vb that defines the LoginManager class:
Listing 2−8: The frmLoginManager.vb File
Imports System.Data.SqlClient
Imports System.IO
Public Class LoginManager
Inherits System.Windows.Forms.Form
Dim strSqlConnection As String
Dim ds As DataSet
Dim sqlda As SqlDataAdapter
Dim sqlCommand As sqlCommand
Private Sub cmdGo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles
cmdGo.Click
'Verifying the login credentials
Try
sqlCommand = New SqlCommand("select customerId from Customers where username='" &
txtUserName.Text & "' and password='" & txtPassWord.Text & "'", sqlConnection)
sqlda = New SqlDataAdapter(sqlCommand)
ds = New DataSet
sqlda.Fill(ds)
Catch ex As Exception
MsgBox("Error in login.", MsgBoxStyle.OKOnly, "LOGIN ERROR")
txtUserName.Focus()
Exit Sub
End Try
'To check whether the login attempt is successful
If Not ds.Tables.Count = 0 And Not ds.Tables(0).Rows.Count = 0 Then
If txtUserName.Text = "administrator" Then
loginRole = "administrator"
Else
loginRole = "customer"
End If
custId = ds.Tables(0).Rows(0).Item(0)
'An object reference to the ApplicationManager class
Dim objApplicationManager As New ApplicationManager
objApplicationManager.ShowDialog()
txtUserName.Text = ""
txtPassWord.Text = ""
Else
MsgBox("Login Unsuccessful.", MsgBoxStyle.OKOnly, "INVALID LOGIN CREDENTIALS")
txtUserName.Focus()
Exit Sub
End If
End Sub
Private Sub cmdRegister_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles cmdRegister.Click
Dim objCustomerRegisteration As New CustomerRegistration
objCustomerRegisteration.ShowDialog()
If Not custId = 0 Then
loginRole = "customer"
txtUserName.Text = ""
txtPassWord.Text = ""
'An object reference to the ApplicationManager class
Dim objApplicationManager As New ApplicationManager
objApplicationManager.ShowDialog()
End If
End Sub
End Class
Reprinted for milanm, Avanade SkillSoft, SkillSoft Corporation (c) 2004, Copying Prohibited
.NET InstantCode: UML with Visio and Visual Studio .NET 14
• cmdGo_Click(): Executes when a customer specifies the user name and password and
clicks the Login button. This method checks for the validity of the login information and
invokes the Application Manager window if the login information is correct.
• cmdRegister_Click(): Executes when a prospective customer clicks the New User Sign In
Here button to register and obtain access to the Place Order window. This method invokes
the Customer Registration window.
Listing 2−9 shows the code for the frmApplicationManager.vb that defines the ApplicationManager
class:
Listing 2−9: The frmApplicationManager.vb File
Reprinted for milanm, Avanade SkillSoft, SkillSoft Corporation (c) 2004, Copying Prohibited
.NET InstantCode: UML with Visio and Visual Studio .NET 15
Listing 2−10 shows the code for the frmPlaceOrder.vb that defines the PlaceOrder class:
Listing 2−10: The frmPlaceOrder.vb File
Imports System.Data.SqlClient
Public Class PlaceOrder
Inherits System.Windows.Forms.Form
Dim ds As DataSet
Dim sqlda As SqlDataAdapter
Dim sqlCommand As sqlCommand
Reprinted for milanm, Avanade SkillSoft, SkillSoft Corporation (c) 2004, Copying Prohibited
.NET InstantCode: UML with Visio and Visual Studio .NET 16
tempListViewItem.SubItems.Add(Double.Parse(txtUnitPrice.Text) * Double.Parse(txtQuanti
txtQuantityAvailable.Text = Integer.Parse(txtQuantityAvailable.Text) −
Integer.Parse(txtQuantity.Text)
Dim itemCount As Integer
Dim dblTotalAmount As Double
For itemCount = 0 To listviewOrder.Items.Count − 1
dblTotalAmount = dblTotalAmount +
Double.Parse(listviewOrder.Items(itemCount).SubItems(2).Text)
Next
txtAmount.Text = dblTotalAmount
txtQuantity.Text = ""
productCombo.Focus()
End If
End Sub
Private Sub cmdPlaceOrder_Click(ByVal sender As System.Object, ByVal e As _
System.EventArgs) Handles cmdPlaceOrder.Click
If Not listviewOrder.Items.Count = 0 Then
Dim dt As System.DateTime
'Creating an object of type Orders
Dim objOrders As New Orders
objOrders.customerId = custId
objOrders.amount = Double.Parse(txtAmount.Text)
objOrders.orderDate = dt.Today
'Call the SaveOrder method of Orders class to save the order
Dim orderId As Integer = objOrders.SaveOrder
'If the order is successfully saved then
If orderId <> 0 Then
Try
Dim itemCount As Integer
For itemCount = 0 To listviewOrder.Items.Count − 1
'Save the product wise order information into the database
Dim objOrderInformation As New OrderInformation
objOrderInformation.orderId = orderId
'Retrieve the product Id of the selected product
sqlCommand = New SqlCommand("select productId from products where product='" &
listviewOrder.Items(itemCount).Text & "'", sqlConnection)
sqlda = New SqlDataAdapter(sqlCommand)
ds = New DataSet
sqlda.Fill(ds)
objOrderInformation.productId = ds.Tables(0).Rows(0).Item(0)
objOrderInformation.quantity = Integer.Parse(listviewOrder.Items(itemCount).SubI
'Call the SaveOrderInfo method of OrderInformantion class to save the product wi
of the order
objOrderInformation.SaveOrderInfo()
'Update the product quantity
sqlCommand = New SqlCommand("update products set qtyInHand=qtyInHand−" &
Integer.Parse(listviewOrder.Items(itemCount).SubItems(1).Text) & " where product
listviewOrder.Items(itemCount).Text & "'", sqlConnection)
sqlCommand.ExecuteNonQuery()
Next
Catch ex As Exception
MsgBox("Your order cannot be saved.", MsgBoxStyle.OKOnly, "Database Error")
Exit Sub
End Try
Else
MsgBox("Your order cannot be saved.", MsgBoxStyle.OKOnly, "Database Error")
Exit Sub
End If
MsgBox("Your order is saved successfully. Your ORDER ID is " & orderId & ".", MsgBoxStyle
listviewOrder.Items.Clear()
txtAmount.Text = ""
productCombo.Focus()
End If
End Sub
Private Sub cmdClose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Me.Close()
End Sub
End Class
• PlaceOrder_Load(): Retrieves the available products from the database and displays the
products in the productCombo drop−down list box.
• cmdAdd_Click(): Executes when a customer selects a product, specifies the quantity, and
clicks the Add to Order button to add the selected product in the current order. This method
adds the selected product in the listviewOrder list view control that represents the current
order.
• cmdPlaceOrder_Click(): Executes when a customer clicks the Place Order button to place
an order for the selected products. This method calls the SaveOrder() method of the Orders
class to save the order information, such as the order date, customer id, and total amount. It
then calls the SaveOrderInfo() method of the OrderInformation class to save the product
information, such as the product id and the quantity for that product in the order.
Listing 2−11 shows the code for the frmViewOrderStatus.vb that defines the ViewOrderStatus class:
Listing 2−11: The frmViewOrderStatus.vb File
Imports System.Data.SqlClient
Public Class ViewOrderStatus
Inherits System.Windows.Forms.Form
Dim ds As DataSet
Dim sqlda As SqlDataAdapter
Dim sqlCommand As sqlCommand
Private Sub txtOrderId_KeyPress(ByVal sender As Object, ByVal e As
System.Windows.Forms.KeyPressEventArgs) Handles txtOrderId.KeyPress
If Not Char.IsDigit(e.KeyChar) Then
If e.KeyChar = vbBack Then
Exit Sub
End If
e.Handled = True
End If
End Sub
Private Sub cmdViewStatus_Click(ByVal sender As Object, ByVal e As System.EventArgs) Hand
Reprinted for milanm, Avanade SkillSoft, SkillSoft Corporation (c) 2004, Copying Prohibited
.NET InstantCode: UML with Visio and Visual Studio .NET 19
In the above listing, the cmdViewStatus_Click() method executes when a customer specifies an
order id and clicks the View Status button to view the status of the order referred to by that order id.
This method calls the RetrieveOrderStatus() method of the Orders class to retrieve the status and
displays the retrieved status in the lblStatus label.
Listing 2−12 shows the code for the frmUpdateOrderStatus.vb that defines the UpdateOrderStatus
class:
Reprinted for milanm, Avanade SkillSoft, SkillSoft Corporation (c) 2004, Copying Prohibited
.NET InstantCode: UML with Visio and Visual Studio .NET 20
Listing 2−12: The frmUpdateOrderStatus.vb File
Imports System.Data.SqlClient
Public Class UpdateOrderStatus
Inherits System.Windows.Forms.Form
Dim tempListViewItem As ListViewItem
Dim sqlCommand As sqlCommand
Dim sqlda As SqlDataAdapter
Dim ds As DataSet
Private Sub cmdUpdate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _
Handles cmdUpdate.Click
If Not listviewOrders.SelectedItems.Count = 0 Then
'Update the status of the order as completed
Dim dt As System.DateTime
Try
Dim objOrders As New Orders
'Call the UpdateOrderStatus method of the class Orders to update the status of _
the selected order as completed
objOrders.UpdateOrderStatus(listviewOrders.SelectedItems(0).Text, "completed")
listviewOrders.Items.Remove(listviewOrders.SelectedItems(0))
Catch ex As Exception
MsgBox("Unable to update the status of the selected order.", MsgBoxStyle.OKOnly,
Exit Sub
End Try
End If
End Sub
Private Sub UpdateOrderStatus_Load(ByVal sender As Object, ByVal e As System.EventArgs
Handles MyBase.Load
'An arraylist object to hold the order objects passed by RetrieveOrderByStatus method
Dim arrayOrders As ArrayList
Try
Dim objOrders As New Orders
arrayOrders = objOrders.RetrieveOrderByStatus("P")
If Not arrayOrders.Count = 0 Then
Dim cnt As Integer
For cnt = 0 To arrayOrders.Count − 1
Dim tempObjOrders As Orders
tempObjOrders = arrayOrders(cnt)
tempListViewItem = listviewOrders.Items.Add(tempObjOrders.orderId)
tempListViewItem.SubItems.Add(tempObjOrders.orderDate)
'Retrieving the customer name
sqlCommand = New SqlCommand("select firstname, lastname from customers where
tempObjOrders.customerId & "", sqlConnection)
sqlda = New SqlDataAdapter(sqlCommand)
ds = New DataSet
sqlda.Fill(ds)
If Not ds.Tables.Count = 0 And Not ds.Tables(0).Rows.Count = 0 Then
tempListViewItem.SubItems.Add(ds.Tables(0).Rows(0).Item(0) & " " &
ds.Tables(0).Rows(0).Item(1))
Else
tempListViewItem.SubItems.Add("")
End If
tempListViewItem.SubItems.Add(tempObjOrders.amount)
Next
Else
MsgBox("No orders are pending.", MsgBoxStyle.OKOnly, "No orders to be completed")
Exit Sub
End If
Catch ex As Exception
MsgBox("Unable to retrieve pending orders.", MsgBoxStyle.OKOnly, "Retrieval Error")
Exit Sub
End Try
End Sub
Private Sub cmdClose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Ha
Me.Close()
End Sub
Private Sub cmdViewInformation_Click(ByVal sender As System.Object, ByVal e As _ System.E
Handles cmdViewInformation.Click
'Retrieve product wise information for the selected order.
If Not listviewOrders.SelectedItems.Count = 0 Then
Dim objViewOrderInfo As New ViewOrderInfo(listviewOrders.SelectedItems(0).Text)
objViewOrderInfo.ShowDialog()
End If
End Sub
Reprinted for milanm, Avanade SkillSoft, SkillSoft Corporation (c) 2004, Copying Prohibited
.NET InstantCode: UML with Visio and Visual Studio .NET 21
End Class
Listing 2−13 shows the code for the frmViewOrderInfo.vb that defines the ViewOrderInfo class:
Listing 2−13: The frmViewOrderInfo.vb File
In the above listing, the ViewOrderInfo_Load() method calls the RetrieveOrderInfo() method of the
Orders class to retrieve the product information for the order and displays the information in the
listviewOrders list view control.
Reprinted for milanm, Avanade SkillSoft, SkillSoft Corporation (c) 2004, Copying Prohibited
.NET InstantCode: UML with Visio and Visual Studio .NET 23
Listing 2−14 shows the code for the frmRaiseInvoice.vb that defines the RaiseInvoice class:
Listing 2−14: The frmRaiseInvoice.vb File
Imports System.Data.SqlClient
Public Class RaiseInvoice
Inherits System.Windows.Forms.Form
Dim sqlCommand As sqlCommand
Dim sqlda As SqlDataAdapter
Dim ds As DataSet
Dim tempListViewItem As ListViewItem
Private Sub cmdClose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Ha
Me.Close()
End Sub
Private Sub RaiseInvoice_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handle
'An arraylist object to hold the order objects passed by RetrieveOrderByStatus method of
Dim arrayOrders As ArrayList
Try
Dim objOrders As New Orders
'Call the RetrieveOrderByStatus method to retrieve all completed orders
arrayOrders = objOrders.RetrieveOrderByStatus("C")
If Not arrayOrders.Count = 0 Then
Dim cnt As Integer
For cnt = 0 To arrayOrders.Count − 1
Dim tempObjOrders As Orders
tempObjOrders = arrayOrders(cnt)
tempListViewItem = listviewOrders.Items.Add(tempObjOrders.orderId)
tempListViewItem.SubItems.Add(tempObjOrders.orderDate)
tempListViewItem.SubItems.Add(tempObjOrders.customerId)
'Retrieving the customer name
sqlCommand = New SqlCommand("select firstname, lastname from customers where
customerId=" & tempObjOrders.customerId & "", sqlConnection)
sqlda = New SqlDataAdapter(sqlCommand)
ds = New DataSet
sqlda.Fill(ds)
If Not ds.Tables.Count = 0 And Not ds.Tables(0).Rows.Count = 0 Then
tempListViewItem.SubItems.Add(ds.Tables(0).Rows(0).Item(0) & " "
& ds.Tables(0).Rows(0).Item(1))
Else
tempListViewItem.SubItems.Add("")
End If
tempListViewItem.SubItems.Add(tempObjOrders.completionDate)
Reprinted for milanm, Avanade SkillSoft, SkillSoft Corporation (c) 2004, Copying Prohibited
.NET InstantCode: UML with Visio and Visual Studio .NET 24
Next
Else
MsgBox("No orders are left to be invoiced.", MsgBoxStyle.OKOnly, "No orders left")
Me.Close()
End If
Catch ex As Exception
MsgBox("Unable to retrieve completed orders.", MsgBoxStyle.OKOnly, "Retrieval Error")
Me.Close()
End Try
End Sub
Private Sub cmdRaise_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Ha
If Not listviewOrders.SelectedItems.Count = 0 Then
Dim objInvoice As New Invoice(listviewOrders.SelectedItems(0).Text, _
listviewOrders.SelectedItems(0).SubItems(2).Text)
objInvoice.ShowDialog()
End If
'If invoice generation was a success
If boolInvoiceGeneration = True Then
'Update the status of the selected order to invoiced(I)
Dim objOrders As New Orders
objOrders.UpdateOrderStatus(listviewOrders.SelectedItems(0).Text, "invoiced")
listviewOrders.Items.Remove(listviewOrders.SelectedItems(0))
End If
End Sub
End Class
• cmdRaise_Click(): Executes when the administrator selects an order and clicks the Raise
button to raise an invoice for the selected order. This method invokes the Invoice window.
Reprinted for milanm, Avanade SkillSoft, SkillSoft Corporation (c) 2004, Copying Prohibited
.NET InstantCode: UML with Visio and Visual Studio .NET 25
Listing 2−15 shows the code for the frmInvoice.vb that defines the Invoice class:
Listing 2−15: The frmInvoice.vb File
Imports System.Data.SqlClient
Public Class Invoice
Inherits System.Windows.Forms.Form
Dim sqlCommand As sqlCommand
Dim sqlda As SqlDataAdapter
Dim ds As DataSet
Dim orderId As Integer
Dim customerId As Integer
Dim tempListViewItem As ListViewItem
Dim invoiceId As Integer
Public Sub New(ByVal oId As Integer, ByVal cId As Integer)
MyBase.New()
InitializeComponent()
orderId = oId
customerId = cId
End Sub
Private Sub Invoice_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) _
Handles MyBase.Load
Dim dt As System.DateTime
dtPicker.Value = dt.Today
'Retrieve the invoice id of the last invoice generated
Try
Dim objInvoices As New Invoices
invoiceId = objInvoices.retrieveInvoiceId() + 1
Catch ex As Exception
invoiceId = 1
End Try
lblInvoiceId.Text = lblInvoiceId.Text & " " & invoiceId
lblOrderId.Text = lblOrderId.Text & " " & orderId
'Retrieve company information
Try
sqlCommand = New SqlCommand("select * from Company", sqlConnection)
sqlda = New SqlDataAdapter(sqlCommand)
ds = New DataSet
sqlda.Fill(ds)
If Not ds.Tables(0).Rows.Count = 0 Then
lblCompanyName.Text = lblCompanyName.Text & " : " & _
ds.Tables(0).Rows(0).Item(0)
lblCompanyAddress.Text = lblCompanyAddress.Text & " : " & _
ds.Tables(0).Rows(0).Item(1)
& ", " & ds.Tables(0).Rows(0).Item(2) & ", " & _
ds.Tables(0).Rows(0).Item(3)
& ", " & ds.Tables(0).Rows(0).Item(4)
lblCompanyPhone.Text = lblCompanyPhone.Text & " : " & _
ds.Tables(0).Rows(0).Item(5)
End If
Catch ex As Exception
MsgBox("Unable to retrieve company information.", MsgBoxStyle.OKOnly, "Retrieval Error
Me.Close()
End Try
'Retrieve Customer Information
Try
Dim objCustomers As New Customers
objCustomers.retrieveCustomerInformation(customerId)
If objCustomers.firstName = "" Then
MsgBox("Customer information not found.", MsgBoxStyle.OKOnly, "Retrieval Error")
Me.Close()
Else
lblCustomerName.Text = lblCustomerName.Text & " : " & objCustomers.firstName & " "
& objCustomers.lastName
lblAddress.Text = lblAddress.Text & " : " & objCustomers.address1 & " " _
& objCustomers.address2
lblCity.Text = lblCity.Text & " : " & objCustomers.city
Reprinted for milanm, Avanade SkillSoft, SkillSoft Corporation (c) 2004, Copying Prohibited
.NET InstantCode: UML with Visio and Visual Studio .NET 26
Exit Sub
End If
e.Handled = True
End If
End Sub
Private Sub cashRadioButton_CheckedChanged(ByVal sender As System.Object, ByVal e As _
System.EventArgs) Handles cashRadioButton.CheckedChanged
If cashRadioButton.Checked = True Then
creditCardGroupBox.Enabled = False
Else
creditCardGroupBox.Enabled = True
End If
End Sub
Private Sub creditRadioButton_CheckedChanged(ByVal sender As System.Object, ByVal e As _
System.EventArgs) Handles creditRadioButton.CheckedChanged
If creditRadioButton.Checked = True Then
creditCardGroupBox.Enabled = True
Else
creditCardGroupBox.Enabled = False
End If
End Sub
Private Sub cmdGenerate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles cmdGenerate.Click
Dim dt As System.DateTime
If creditRadioButton.Checked = True Then
If txtNameOnCard.Text = "" Then
MsgBox("Please specify Name as on the credit card.", MsgBoxStyle.OKOnly, "Please _
specify the information")
Exit Sub
End If
If txtCreditCardNumber.Text = "" Then
MsgBox("Please specify credit card number.", MsgBoxStyle.OKOnly, "Please specify th
Exit Sub
End If
If dt.Today > dtPicker.Value Then
MsgBox("Your credit card has expired.", MsgBoxStyle.OKOnly, "Please check the infor
Exit Sub
End If
End If
Try
If txtshipping.Text = "" Then
txtshipping.Text = "0"
End If
'Create an object of the type Invoices that represent as invoice
Dim objInvoices As New Invoices
objInvoices.invoiceDate = dt.Today
objInvoices.orderId = orderId
objInvoices.shipping_handlingCost = txtshipping.Text
objInvoices.subTotal = txtSubTotal.Text
objInvoices.totalAmount = txtTotal.Text
If creditRadioButton.Checked = True Then
objInvoices.paymentMode = "credit card"
Else
objInvoices.paymentMode = "cash"
End If
'Call the generateInvoice method of the class Invoices to save the Invoice
objInvoices.generateInvoice()
If creditRadioButton.Checked = True Then
'Create an object of the type InvoiceCreditCardInfo
Dim objInvoiceCreditCardInfo As New InvoiceCreditCardInfo(invoiceId,
txtNameOnCard.Text, txtCreditCardNumber.Text)
'Call the saveCreditCardInfo method to save the credit card information
objInvoiceCreditCardInfo.saveCreditCardInfo()
End If
boolInvoiceGeneration = True
Me.Close()
Catch ex As Exception
MsgBox("Unable to generate the invoice.", MsgBoxStyle.OKOnly, "Database Error")
boolInvoiceGeneration = False
Me.Close()
End Try
End Sub
End Class
Reprinted for milanm, Avanade SkillSoft, SkillSoft Corporation (c) 2004, Copying Prohibited
.NET InstantCode: UML with Visio and Visual Studio .NET 28
• Invoice_Load(): Calls the retrieveInvoiceId() method of the Invoices class to retrieve the id of
the last invoice generated. This method also calls the retriveCustomerInformation() method
of the Customer class to retrieve the information of the customer who placed a particular
order. Then this method calls the RetrieveOrderInfo() method of the OrderInformation class
to display the product information in the listviewOrders list view control.
• cmdGenerate_Click(): Executes when the administrator specifies the shipping and handling
cost, selects the payment mode, and clicks the Generate Invoice button to generate the
invoice. This method calls the generateInvoice() method of the Invoice class that saves the
invoice information in the Invoices table.
Listing 2−16 shows the code for the frmCustomerRegistration.vb that defines the
CustomerRegistration class:
Listing 2−16: The frmCustomerRegistration.vb File
Reprinted for milanm, Avanade SkillSoft, SkillSoft Corporation (c) 2004, Copying Prohibited
.NET InstantCode: UML with Visio and Visual Studio .NET 29
In the above listing, the cmdAdd_Click() method executes when a prospective customer specifies
customer information and clicks the Save button to save the information and register. This method
checks the validity of the information and calls the addCustomerInformation() method of the
Reprinted for milanm, Avanade SkillSoft, SkillSoft Corporation (c) 2004, Copying Prohibited
.NET InstantCode: UML with Visio and Visual Studio .NET 30
Customers class that inserts the customer information in the Customers table.
Unit Testing
To execute the Order Processing application:
1. Execute the OrderProcessing.exe file. This file is located in the /bin folder of the
OrderProcessing folder. The Login Manager window appears, as shown in Figure 2−13:
2. Specify the user name and password for a customer and click the Login button. The
Application Manager window appears, as shown in Figure 2−14:
Reprinted for milanm, Avanade SkillSoft, SkillSoft Corporation (c) 2004, Copying Prohibited
.NET InstantCode: UML with Visio and Visual Studio .NET 31
3. Select Orders−>Place Order to place an order. The Place Order window appears, as shown
in Figure 2−15:
4. Select a product, specify the quantity required, and click the Add to Order button to add the
product to the Your Order list, as shown in Figure 2−16:
Reprinted for milanm, Avanade SkillSoft, SkillSoft Corporation (c) 2004, Copying Prohibited
.NET InstantCode: UML with Visio and Visual Studio .NET 32
Figure 2−16: Your Order List after the Customer Adds a Product.
6. Click the Place Order button to confirm and place the order. A confirmation message box
appears that shows the order id of the order placed, as shown in Figure 2−17:
8. Select Orders−>View Order Status to view the status of an order. The View Order Status
window appears, as shown in Figure 2−18:
9. Specify the Order id of the order and click the View Status button to view the status of that
order. The order status appears, as shown in Figure 2−19:
Reprinted for milanm, Avanade SkillSoft, SkillSoft Corporation (c) 2004, Copying Prohibited
.NET InstantCode: UML with Visio and Visual Studio .NET 33
10. Click the Close button to close the View Order Status window.
12. Specify the administrator login information in the Login Manager window and select Login.
The Application Manager window appears, as shown in Figure 2−20:
Figure 2−20: The Application Manager Window Displaying Options for Administrator
13. Select Orders−>Update Order to update the status of pending orders. The Update Order
Status window appears, as shown in Figure 2−21:
Reprinted for milanm, Avanade SkillSoft, SkillSoft Corporation (c) 2004, Copying Prohibited
.NET InstantCode: UML with Visio and Visual Studio .NET 34
14. Select an order from the Pending Orders list and click the View Information button to view
the product information for that order. The View Order Information window appears, as
shown in Figure 2−22:
15. Click the Close button to close the View Order Information window.
16. Select an order from the Pending Orders list and click the Update Order button to update the
status of that order.
Reprinted for milanm, Avanade SkillSoft, SkillSoft Corporation (c) 2004, Copying Prohibited
.NET InstantCode: UML with Visio and Visual Studio .NET 35
17. Click the Close button to close the Update Order Status window.
20. Repeat Steps 8−9 to view the status of the order that the administrator has updated. The
order status appears, as shown in Figure 2−23:
Figure 2−23: The View Order Status Window after Order Update
22. Select Invoice−>Raise Invoice to raise invoices for updated orders. The Raise Invoice
window appears, as shown in the Figure 2−24:
23. Select an order and click the Raise button. The Invoice window appears, as shown in Figure
2−25:
Reprinted for milanm, Avanade SkillSoft, SkillSoft Corporation (c) 2004, Copying Prohibited
.NET InstantCode: UML with Visio and Visual Studio .NET 36
24. Specify the shipping and handling cost and credit card information if required, and click the
Generate Invoice button to generate the invoice.
25. Click the Close button to close the Raise Invoice window.
27. Repeat the Steps 8−9 to view the status of those orders where the invoice has been
generated by the administrator. The View Order Status window displays the status of the
invoiced order, as shown in Figure 2−26:
Figure 2−26: The View Order Status Window after Invoice Generation
28. Click the Close button to close the View Order Status window.
Reprinted for milanm, Avanade SkillSoft, SkillSoft Corporation (c) 2004, Copying Prohibited
.NET InstantCode: UML with Visio and Visual Studio .NET 37
Reprinted for milanm, Avanade SkillSoft, SkillSoft Corporation (c) 2004, Copying Prohibited