Professional Documents
Culture Documents
NET
SkillSoft Corporation. (c) 2004. Copying Prohibited.
Table of Contents
Chapter 4: Creating the UML Static Model Diagram from the Query Tracker Application.......1
Architecture of the Query Tracker Application.......................................................................1
Creating the Database Schema.............................................................................................3
Creating the QueryTrackerAdministrator Application.............................................................5
Creating the Application Manager Window......................................................................5
Creating the Login Manager Window...............................................................................6
Creating the Executive Manager Window........................................................................7
Creating the Query Manager Window............................................................................10
Creating the Forward Pending Query to Executive Window..........................................12
Creating the View Query Status Window.......................................................................15
Creating the QueryTrackerRemotingObject Project............................................................22
Creating the QueryTrackerServerListener Project...............................................................24
Creating the QueryTrackerClient Application.......................................................................25
Creating the Executive Login Window...........................................................................25
Creating the Query Tracker Client Window....................................................................25
Creating the InitializeQueryProvider Module..................................................................27
Unit Testing..........................................................................................................................28
Downloads...........................................................................................................................34
Chapter 4: Creating the UML Static Model Diagram
from the Query Tracker Application
Download CD Content
Reverse engineering in Visual Studio .NET 2003 enables you to generate Unified Modeling
language (UML) static model diagram from code in .NET applications. Reverse engineering maps
the classes, namespaces, and methods in the .NET application code to the UML static model
diagram and generates classes in the UML Model Explorer window of Visio.
This chapter explains how to create a QueryTracker UML static model diagram by reverse
engineering the code of the Query Tracker application, which is a Visual Studio.NET application.
• QueryTrackerAdministrator
• QueryTrackerRemotingObject
• QueryTrackerServerListener
• QueryTrackerClient
The QueryTrackerAdministrator project enables the administrator to enter customer queries in the
database and assign them later to customer support executives to resolve queries. The
QueryTrackerAdministrator application connects to the SQL Server, retrieves a list of existing
executives and their departments, and provides the status of registered queries.
The QueryTrackerRemotingObject project provides the remoting object that retrieves the queries
meant for a particular customer support executive from the QueryTracker database and updates the
status of the queries when customer service executives have resolved these queries.
The QueryTrackerClient project enables executives to access queries provided by the remoting
object and to mark the queries as attended to when the executives have dealt with the queries.
Reprinted for milanm, Avanade SkillSoft, SkillSoft Corporation (c) 2004, Copying Prohibited
.NET InstantCode: UML with Visio and Visual Studio .NET 2
• frmLoginManager.vb: Provides the LoginManager class that defines the Login Manager
window, which enables the administrator to log on to the application.
• frmQueryManager.vb: Provides the QueryManager class that defines the Query Manager
window, where the administrator can register customer queries into the database.
• frmViewStatus.vb: Provides the ViewStatus class that defines the View Query Status
window, which enables the administrator to view the status of the queries.
The QueryTrackerRemotingObject project consists of one file, QueryProvider.vb that provides the
QueryProvider class, which defines the remoting object. When the executive logs on to the
QueryTrackerClient application, the remoting object retrieves the queries meant for that executive.
Reprinted for milanm, Avanade SkillSoft, SkillSoft Corporation (c) 2004, Copying Prohibited
.NET InstantCode: UML with Visio and Visual Studio .NET 3
When the executive marks the query as attended to, the remoting object updates the database
information for that query.
The QueryTrackerServerListener project consists of one file, Server.vb that provides the Server
class, which defines the server that registers the remoting object and listens for the request to
activate remoting object from the QueryTrackerClient application. The administrator runs the server
before the executives access the QueryTrackerClient application.
• frmExecutiveLogin.vb: Provides the ExecutiveLogin class that defines the Executive Login
window, which enables the executives to log on to the application.
Figure 4−2 shows the class diagram for the Query Tracker application:
Figure 4−2: The Class Diagram for the Query Tracker Application
Listing 4−1 shows the SQL script to generate the database on the SQL Server:
Listing 4−1: Creating the QueryTracker Database
The above listing creates the QueryTracker database for the Query Tracker application. The above
code creates the following tables in the database:
• CustSupportExecutives: Stores information about the executives, such as the executive id,
name, contact details, and the password assigned to the executive.
Reprinted for milanm, Avanade SkillSoft, SkillSoft Corporation (c) 2004, Copying Prohibited
.NET InstantCode: UML with Visio and Visual Studio .NET 5
• Departments: Stores information about the departments in the organization, such as the
dept ID and department name.
• Queries: Stores information about customer queries, such as the query ID, title, description
of the query, date of the query, status of the query, and date on which the customer support
executives attended the query.
• LoginAdministrator: Stores the user name and password for the administrator.
Listing 4−2 shows the code for the frmApplicationManager.vb file that defines the
frmApplicationManager class:
Listing 4−2: The frmApplicationManager.vb File
Reprinted for milanm, Avanade SkillSoft, SkillSoft Corporation (c) 2004, Copying Prohibited
.NET InstantCode: UML with Visio and Visual Studio .NET 6
Listing 4−3 shows the code for the frmLoginManager.vb file that defines the LoginManager class:
Listing 4−3: The frmLoginManager.vb File
Imports System.Data.SqlClient
Imports System.IO
Imports System.Collections
Public Class LoginManager
Inherits System.Windows.Forms.Form
Dim strSqlConnection As String
Dim SqlConn As New SqlConnection
Dim dataReader As SqlDataReader
Dim SqlCom As New SqlCommand
Private Sub LoginManager_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles M
'Try to establish connection with database QueryTracker through SQLClient Connection obje
Try
Try
'Read the connection string from a text file settings.txt located in
'/bin folder of the application.
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=QueryTracker"
End Try
SqlConn.ConnectionString = strSqlConnection
SqlConn.Open()
Catch ex As Exception
MsgBox("Error in establishing connection", MsgBoxStyle.OKOnly, "CONNECTION ERROR")
Exit Sub
End Try
End Sub
Private Sub cmdGo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles
Try
Reprinted for milanm, Avanade SkillSoft, SkillSoft Corporation (c) 2004, Copying Prohibited
.NET InstantCode: UML with Visio and Visual Studio .NET 7
• cmdGo_Click(): Executes when the administrator specifies the login credentials and clicks
the Login button. This method verifies the login credentials and enables the administrator to
log on to the application.
Listing 4−4 shows the code for the frmExecutiveManager.vb file that defines the ExecutiveManager
class:
Listing 4−4: The frmExecutiveManager.vb File
Imports System.Data.SqlClient
Imports System.IO
Imports System.Collections
Public Class ExecutiveManager
Inherits System.Windows.Forms.Form
Dim sqlCon As New SqlConnection
Reprinted for milanm, Avanade SkillSoft, SkillSoft Corporation (c) 2004, Copying Prohibited
.NET InstantCode: UML with Visio and Visual Studio .NET 8
While dataReader.Read
ExecId = dataReader.GetValue(0)
End While
End If
dataReader.Close()
Catch ex As Exception
Exit Sub
End Try
'Inserting information of executive's department
Try
sqlCom.CommandText = "insert into ExecDept values(" & ExecId & "," & DeptId & ")"
sqlCom.ExecuteNonQuery()
Catch ex As Exception
MsgBox("Error in inserting executive's department information", MsgBoxStyle.OKOnly, "I
Exit Sub
End Try
'Clear the fields
txtFirstName.Text = ""
txtLastName.Text = ""
txtAddress.Text = ""
txtJobTitle.Text = ""
txtPassWord.Text = ""
txtFirstName.Focus()
End Sub
Private Sub ExecutiveManager_Load(ByVal sender As System.Object, ByVal e As System.EventArgs
'Try to establish SQL connection to database QueryTracker through SQL Connection object
Try
Try
'Read connectionstring from a text file settings.txt located in /bin folder of the
Dim sr As New StreamReader("Settings.txt")
strSQLConnection = sr.ReadLine
sr.Close()
Catch ex As Exception
strSQLConnection = "SERVER=localhost;UID=sa;PWD=sa;Initial Catalog=QueryTracker"
End Try
sqlCon.ConnectionString = strSQLConnection
sqlCon.Open()
Catch ex As Exception
MsgBox("Error in establishing connection", MsgBoxStyle.OKOnly, "CONNECTION ERROR")
cmdAdd.Enabled = False
Exit Sub
End Try
Try
'Retrieving departments from the database
sqlCom.CommandText = "select * from departments"
sqlCom.Connection = sqlCon
dataReader = sqlCom.ExecuteReader
If dataReader.HasRows Then
'Populating ListDept with departments fetched by the datareader
While dataReader.Read
ListDept.Items.Add(dataReader.GetValue(1))
End While
Else
MsgBox("First enter the department details in the database table departments", _
MsgBoxStyle.OKOnly, "NO DEPARTMENT FOUND")
cmdAdd.Enabled = False
Exit Sub
End If
dataReader.Close()
Catch ex As Exception
MsgBox("Error in retrieving departments", MsgBoxStyle.OKOnly, "RETRIEVAL ERROR")
cmdAdd.Enabled = False
Exit Sub
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 10
• cmdAdd_Click(): Executes when the administrator specifies the information for the executive
and clicks the Add New Executive button. This method checks for the validity of the specified
information and if the information is valid, the code adds information about the new
executive into the CustSupportExecutives table.
Listing 4−5 shows the code for the frmQueryManager.vb file that defines the QueryManager class:
Listing 4−5: The frmQueryManager.vb File
Imports System.Data.SqlClient
Imports System.IO
Public Class QueryManager
Inherits System.Windows.Forms.Form
Dim sqlCon As New SqlConnection
Dim sqlCom As New SqlCommand
Dim dataReader As SqlDataReader
Dim strSQLConnection As String
Private Sub cmdAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles
'Verifying whether the required parameters are specified by the end user
'Checking for the Query Title
If txtCompTitle.Text = "" Then
MsgBox("Please enter title of the Query", MsgBoxStyle.OKOnly, "ENTER QUERY TITLE")
txtCompTitle.Focus()
Reprinted for milanm, Avanade SkillSoft, SkillSoft Corporation (c) 2004, Copying Prohibited
.NET InstantCode: UML with Visio and Visual Studio .NET 11
Exit Sub
End If
'Checking for the Query Description
If txtCompDesc.Text = "" Then
MsgBox("Please enter description of the Query", MsgBoxStyle.OKOnly, "ENTER QUERY DESCR
txtCompDesc.Focus()
Exit Sub
End If
'Checking for the Customer Information who registered the query
If txtCustInfo.Text = "" Then
MsgBox("Please enter customer information", MsgBoxStyle.OKOnly, "ENTER CUSTOMER INFORM
txtCustInfo.Focus()
Exit Sub
End If
'Inserting query information into database
Try
sqlCom.CommandText = "insert into Queries values('" & txtCompTitle.Text & _
"','" & txtCompDesc.Text & "','" & _
selQueryDate.Value.ToShortDateString & "','" & txtCustInfo.Text & "','pending',NULL)"
sqlCom.Connection = sqlCon
sqlCom.ExecuteNonQuery()
Catch ex As Exception
MsgBox("Error in inserting query information", MsgBoxStyle.OKOnly, "INSERTION ERROR")
Exit Sub
End Try
'Clear the fields
txtCompTitle.Text = ""
txtCompDesc.Text = ""
txtCustInfo.Text = ""
txtCompTitle.Focus()
End Sub
Private Sub QueryManager_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles M
'Try to establish SQL connection to database QueryTracker through SQL Connection object
Try
Try
'Read connection string from a text file settings.txt located in /bin folder of the
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=QueryTracker"
End Try
sqlCon.ConnectionString = strSQLConnection
sqlCon.Open()
Catch ex As Exception
MsgBox("Error in establishing connection", MsgBoxStyle.OKOnly, "CONNECTION ERROR")
cmdAdd.Enabled = False
Exit Sub
End Try
End Sub
Private Sub cmdClose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handl
Me.Close()
End Sub
End Class
• cmdAdd_Click(): Executes when the administrator specifies the information for the query
such as the query description, query title, and customer name, and clicks the Add Query
button. This method checks for the validity of the specified information and if the information
is valid, the code adds the query information into the Queries table.
Reprinted for milanm, Avanade SkillSoft, SkillSoft Corporation (c) 2004, Copying Prohibited
.NET InstantCode: UML with Visio and Visual Studio .NET 12
Listing 4−6 shows the code for the frmForwardQueryToExecutive.vb file that defines the
ForwardQueryToExecutive class:
Listing 4−6: The frmForwardQueryToExecutive.vb File
Imports System.Data.SqlClient
Imports System.IO
Imports System.Collections
Public Class ForwardQueryToExecutive
Inherits System.Windows.Forms.Form
Dim sqlCon As New SqlConnection
Dim sqlCom As New SqlCommand
Dim dataReader As SqlDataReader
Dim tempListViewItem As ListViewItem
Dim strSQLConnection As String
Private Sub ForwardQueryToExecutive_Load(ByVal sender As Object, ByVal e As System.EventArgs
'Try to establish SQL connection to database QueryTracker through SQL Connection object
Try
Try
'Read the connection string from a text file settings.txt located in /bin folder of
Dim sr As New StreamReader("Settings.txt")
strSQLConnection = sr.ReadLine
sr.Close()
Catch ex As Exception
strSQLConnection = "SERVER=localhost;UID=sa;PWD=sa;Initial Catalog=QueryTracker"
End Try
sqlCon.ConnectionString = strSQLConnection
sqlCon.Open()
Catch ex As Exception
MsgBox("Error in establishing connection", MsgBoxStyle.OKOnly, "CONNECTION ERROR")
cmdForward.Enabled = False
Exit Sub
End Try
Try
'Retrieving pending Queries information
sqlCom.CommandText = "select QueryId, QueryTitle, QueryDesc, QueryDate from Queries wh
sqlCom.Connection = sqlCon
Reprinted for milanm, Avanade SkillSoft, SkillSoft Corporation (c) 2004, Copying Prohibited
.NET InstantCode: UML with Visio and Visual Studio .NET 13
dataReader = sqlCom.ExecuteReader
If dataReader.HasRows Then
While dataReader.Read
'Populating ListViewQuery with Query information fetched by the datareader
tempListViewItem = ListViewQuery.Items.Add(dataReader.GetValue(0))
tempListViewItem.SubItems.Add(dataReader.GetValue(1))
tempListViewItem.SubItems.Add(dataReader.GetValue(2))
tempListViewItem.SubItems.Add(dataReader.GetValue(3))
End While
Else
'No queries found pending
cmdForward.Enabled = False
Exit Sub
End If
dataReader.Close()
Catch ex As Exception
MsgBox("Error in retrieving queries", MsgBoxStyle.OKOnly, "RETRIEVAL ERROR")
cmdForward.Enabled = False
Exit Sub
End Try
Try
'Retrieving executives from database
sqlCom.CommandText = "select EId, FirstName, LastName, Title from CustSupportExecutive
Dim adapter As New SqlDataAdapter(sqlCom)
Dim ds As New DataSet
'Filling dataset with the retrieved executives
adapter.Fill(ds)
'A variable to iterate through the data set
Dim cnt As Integer
Dim deptds As New DataSet
If ds.Tables(0).Rows.Count > 0 Then
For cnt = 0 To ds.Tables(0).Rows.Count − 1
'Populating ListViewExec with Executives related information fetched by the dat
tempListViewItem = ListViewExec.Items.Add(ds.Tables(0).Rows(cnt).Item(0))
tempListViewItem.SubItems.Add(ds.Tables(0).Rows(cnt).Item(1))
tempListViewItem.SubItems.Add(ds.Tables(0).Rows(cnt).Item(2))
sqlCom.CommandText = "Select Name from departments where DId= _
(select DId from ExecDept where EId=" & ds.Tables(0).Rows(cnt).Item(0) & ")"
adapter.SelectCommand = sqlCom
adapter.Fill(deptds)
tempListViewItem.SubItems.Add(deptds.Tables(0).Rows(0).Item(0))
tempListViewItem.SubItems.Add(ds.Tables(0).Rows(cnt).Item(3))
Next
Else
'No Executives found
cmdForward.Enabled = False
Exit Sub
End If
Catch ex As Exception
MsgBox("Error in retrieving executives", MsgBoxStyle.OKOnly, "RETRIEVAL ERROR")
cmdForward.Enabled = False
Exit Sub
End Try
End Sub
Private Sub cmdForward_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Han
'Checking whether the end user has selected any pending Query to be forwarded
If ListViewQuery.SelectedItems.Count = 0 Then
MsgBox("Please select the query to be forwarded", MsgBoxStyle.OKOnly, "SELECT QUERY")
Exit Sub
End If
'Checking whether the end user has selected an Executive to whom the selected Query is to
If ListViewExec.SelectedItems.Count = 0 Then
MsgBox("Please select the executive whom the query is to be forwarded", _
MsgBoxStyle.OKOnly, "SELECT EXECUTIVE")
Exit Sub
End If
Try
'Inserting the Executive−Query related information
sqlCom.CommandText = "insert into ExecQuery values(" & _
ListViewExec.SelectedItems(0).Text & " , " & _
ListViewQuery.SelectedItems(0).Text & ")"
sqlCom.ExecuteNonQuery()
'Updating the status of the selected Query
sqlCom.CommandText = "update Queries set status='forwarded' where QueryId=" & _
ListViewQuery.SelectedItems(0).Text & ""
Reprinted for milanm, Avanade SkillSoft, SkillSoft Corporation (c) 2004, Copying Prohibited
.NET InstantCode: UML with Visio and Visual Studio .NET 14
sqlCom.ExecuteNonQuery()
'Removing the forwarded Query from the ListViewQuery
ListViewQuery.Items.RemoveAt(ListViewQuery.SelectedItems(0).Index)
Catch ex As Exception
MsgBox("Error in forwarding query to executive", MsgBoxStyle.OKOnly, "INSERTION ERROR"
End Try
End Sub
Private Sub cmdClose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handl
Me.Close()
End Sub
End Class
• cmdForward_Click(): Executes when the administrator selects a pending query from the
pending queries list, selects a particular executive to resolve the query, and clicks the
Forward button. This method forwards the query to the selected executive, updates the
status of the query, and removes the query from the pending queries list.
Reprinted for milanm, Avanade SkillSoft, SkillSoft Corporation (c) 2004, Copying Prohibited
.NET InstantCode: UML with Visio and Visual Studio .NET 15
Listing 4−7 shows the code for the frmViewStatus.vb file that defines the ViewStatus class:
Listing 4−7: The frmViewStatus.vb File
Imports System.IO
Imports System.Data.SqlClient
Public Class ViewStatus
Inherits System.Windows.Forms.Form
Dim sqlCon As New SqlConnection
Dim sqlCom As New SqlCommand
Dim dataReader As SqlDataReader
Dim strSQLConnection As String
Dim tempListViewItem As ListViewItem
Dim boolPending As Boolean
Dim boolForwarded As Boolean
Dim boolAttended As Boolean
Private Sub ViewStatus_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyB
Try
Try
'Read the connection string from a text file settings.txt located in
'/bin folder of the application
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=QueryTracker"
End Try
sqlCon.ConnectionString = strSQLConnection
sqlCon.Open()
Catch ex As Exception
MsgBox("Error in establishing connection", MsgBoxStyle.OKOnly, "CONNECTION ERROR")
Exit Sub
End Try
showPending()
boolPending = True
End Sub
'This method is used to show pending Queries which are not assigned to any Executive yet.
Public Sub showPending()
Try
'Retrieving Information of the pending Queries
sqlCom.CommandText = _
"select QueryId, QueryTitle, QueryDate, CompDate from Queries where status='pending'"
sqlCom.Connection = sqlCon
Dim ds As New DataSet
Dim execds As New DataSet
Dim adapter As New SqlDataAdapter(sqlCom)
'Filling dataset with the Query Information
adapter.Fill(ds)
Dim cnt As Integer
ListViewQuery.Items.Clear()
If ds.Tables(0).Rows.Count > 0 Then
For cnt = 0 To ds.Tables(0).Rows.Count − 1
'Population ListViewQuery with the information fetched by the dataset
tempListViewItem = ListViewQuery.Items.Add(ds.Tables(0).Rows(cnt).Item(0))
tempListViewItem.SubItems.Add(ds.Tables(0).Rows(cnt).Item(1))
tempListViewItem.SubItems.Add(ds.Tables(0).Rows(cnt).Item(2))
tempListViewItem.SubItems.Add("pending")
Next
End If
Catch ex As Exception
MsgBox("Error in retrieving pending queries", MsgBoxStyle.OKOnly, "RETRIEVAL ERROR")
Exit Sub
End Try
End Sub
'This method is used to show Queries which forwarded to Executives.
Public Sub showForwarded()
Reprinted for milanm, Avanade SkillSoft, SkillSoft Corporation (c) 2004, Copying Prohibited
.NET InstantCode: UML with Visio and Visual Studio .NET 16
Try
'Retrieving Information of the forwarded Queries
sqlCom.CommandText = _
"select QueryId,QueryTitle,QueryDate,CompDate from Queries where status='forwarded'"
Dim ds As New DataSet
Dim execds As New DataSet
Dim adapter As New SqlDataAdapter(sqlCom)
adapter.Fill(ds)
Dim cnt As Integer
ListViewQuery.Items.Clear()
If ds.Tables(0).Rows.Count > 0 Then
For cnt = 0 To ds.Tables(0).Rows.Count − 1
'Population ListViewQuery with the information fetched by the dataset
tempListViewItem = ListViewQuery.Items.Add(ds.Tables(0).Rows(cnt).Item(0))
tempListViewItem.SubItems.Add(ds.Tables(0).Rows(cnt).Item(1))
tempListViewItem.SubItems.Add(ds.Tables(0).Rows(cnt).Item(2))
tempListViewItem.SubItems.Add("forwarded")
'Fetching the Executive Name to whom the Query is forwared
sqlCom.CommandText = _
"Select FirstName,LastName from CustSupportExecutives where EId= _
(Select EId from ExecQuery where QueryId=" & ds.Tables(0).Rows(cnt).Item(0) & ")
adapter.SelectCommand = sqlCom
adapter.Fill(execds)
'Adding Executive Name
tempListViewItem.SubItems.Add(execds.Tables(0).Rows(0).Item(0) & _
" " & execds.Tables(0).Rows(0).Item(1))
execds.Clear()
Next
End If
Catch ex As Exception
MsgBox("Error in retrieving forwarded queries", MsgBoxStyle.OKOnly, "RETRIEVAL ERROR")
Exit Sub
End Try
End Sub
'This method is used to show Queries which attended by the respective Executives.
Public Sub showAttended()
Try
'Retrieving Information of the attended Queries
sqlCom.CommandText = "select QueryId,QueryTitle,QueryDate,CompDate from Queries where
Dim ds As New DataSet
Dim execds As New DataSet
Dim adapter As New SqlDataAdapter(sqlCom)
adapter.Fill(ds)
Dim cnt As Integer
ListViewQuery.Items.Clear()
If ds.Tables(0).Rows.Count > 0 Then
For cnt = 0 To ds.Tables(0).Rows.Count − 1
tempListViewItem = ListViewQuery.Items.Add(ds.Tables(0).Rows(cnt).Item(0))
tempListViewItem.SubItems.Add(ds.Tables(0).Rows(cnt).Item(1))
tempListViewItem.SubItems.Add(ds.Tables(0).Rows(cnt).Item(2))
tempListViewItem.SubItems.Add("attended")
sqlCom.CommandText = _
"Select FirstName,LastName from CustSupportExecutives where EId= _
(Select EId from ExecQuery where QueryId=" & ds.Tables(0).Rows(cnt).Item(0) & ")
adapter.SelectCommand = sqlCom
adapter.Fill(execds)
tempListViewItem.SubItems.Add(execds.Tables(0).Rows(0).Item(0) & _
" " & execds.Tables(0).Rows(0).Item(1))
If ds.Tables(0).Rows(cnt).IsNull(3) = True Then
tempListViewItem.SubItems.Add("")
Else
'Adding Query Attended On Date
tempListViewItem.SubItems.Add(ds.Tables(0).Rows(cnt).Item(3))
End If
execds.Clear()
Next
End If
Catch ex As Exception
MsgBox("Error in retrieving attended queries", MsgBoxStyle.OKOnly, "RETRIEVAL ERROR")
Exit Sub
End Try
End Sub
Private Sub MenuItem2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Hand
boolPending = True
boolForwarded = False
Reprinted for milanm, Avanade SkillSoft, SkillSoft Corporation (c) 2004, Copying Prohibited
.NET InstantCode: UML with Visio and Visual Studio .NET 17
boolAttended = False
showPending()
End Sub
Private Sub MenuItem3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Hand
boolPending = False
boolForwarded = True
boolAttended = False
showForwarded()
End Sub
Private Sub MenuItem4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Hand
boolPending = False
boolForwarded = False
boolAttended = True
showAttended()
End Sub
Private Sub ViewNoFilter_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles
Label1.Visible = False
ListFilter.Visible = False
cmdShow.Visible = False
End Sub
Private Sub ViewFilterExec_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handle
Label1.Visible = True
Label1.Text = "Select Executive"
ListFilter.Visible = True
cmdShow.Visible = True
showExec()
End Sub
'This method is used to retrieve Executives for filtering purpose
Public Sub showExec()
Try
sqlCom.CommandText = "select FirstName,LastName from CustSupportExecutives"
sqlCom.Connection = sqlCon
dataReader = sqlCom.ExecuteReader
ListFilter.Items.Clear()
If dataReader.HasRows Then
While dataReader.Read
ListFilter.Items.Add(dataReader.GetValue(0) & " " & dataReader.GetValue(1))
End While
End If
dataReader.Close()
Catch ex As Exception
MsgBox("Error in retrieving executives", MsgBoxStyle.OKOnly, "RETRIEVAL ERROR")
Label1.Visible = False
ListFilter.Visible = False
cmdShow.Visible = False
Exit Sub
End Try
End Sub
'This method is used to retrieve Departments for filtering purpose
Public Sub ShowDept()
Try
sqlCom.CommandText = "select * from departments"
dataReader = sqlCom.ExecuteReader
ListFilter.Items.Clear()
If dataReader.HasRows Then
While dataReader.Read
ListFilter.Items.Add(dataReader.GetValue(1))
End While
End If
dataReader.Close()
Catch ex As Exception
MsgBox("Error in retrieving departments", MsgBoxStyle.OKOnly, "RETRIEVAL ERROR")
Label1.Visible = False
ListFilter.Visible = False
cmdShow.Visible = False
End Try
End Sub
'This method is used to retrieve Dates for filtering purpose
Public Sub ShowDate()
Try
sqlCom.CommandText = "select distinct QueryDate from Queries"
dataReader = sqlCom.ExecuteReader
ListFilter.Items.Clear()
If dataReader.HasRows Then
While dataReader.Read
Reprinted for milanm, Avanade SkillSoft, SkillSoft Corporation (c) 2004, Copying Prohibited
.NET InstantCode: UML with Visio and Visual Studio .NET 18
ListFilter.Items.Add(dataReader.GetValue(0))
End While
End If
dataReader.Close()
Catch ex As Exception
MsgBox("Error in retrieving query dates", MsgBoxStyle.OKOnly, "RETRIEVAL ERROR")
Label1.Visible = False
ListFilter.Visible = False
cmdShow.Visible = False
End Try
End Sub
Private Sub ViewFilterDept_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handle
Label1.Visible = True
Label1.Text = "Select Department"
ListFilter.Visible = True
cmdShow.Visible = True
ShowDept()
End Sub
Private Sub ViewFilterDate_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handle
Label1.Visible = True
Label1.Text = "Select Date"
ListFilter.Visible = True
cmdShow.Visible = True
ShowDate()
End Sub
Private Sub cmdShow_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmdSh
'Check whether there are Queries for filtering
If ListViewQuery.Items.Count = 0 Then
MsgBox("No queries to be filter", MsgBoxStyle.OKOnly)
Exit Sub
End If
Dim adapter As New SqlDataAdapter
Dim ds As New DataSet
Dim cnt As Integer
Dim execds As New DataSet
Dim count As Integer
'If the end user chooses Filter by Department
If Label1.Text = "Select Department" Then
'If pending Queries Information is displayed in the ListViewQuery
If boolPending = True Then
MsgBox("Pending queries are not assigned to any executive", MsgBoxStyle.OKOnly, "PL
Exit Sub
End If
'If any department is selected
If ListFilter.SelectedItems.Count > 0 Then
Dim DeptId As Integer
Dim ExecId As Integer
Try
'Retrieve the Dept Id of the department selected
sqlCom.CommandText = "select DId from departments where name='" & _
ListFilter.SelectedItem & "'"
adapter.SelectCommand = sqlCom
adapter.Fill(ds)
If ds.Tables(0).Rows.Count > 0 Then
DeptId = ds.Tables(0).Rows(0).Item(0)
End If
ds.Clear()
Catch ex As Exception
MsgBox("Error retrieving department information", MsgBoxStyle.OKOnly, "RETRIEVAL ER
Exit Sub
End Try
Try
'Retrieve information of all the Executives of the selected Department
sqlCom.CommandText = _
"select EId,FirstName,LastName from CustSupportExecutives where EId in _
(select EId from ExecDept where DId=" & DeptId & ")"
adapter.SelectCommand = sqlCom
adapter.Fill(ds)
Catch ex As Exception
MsgBox("Error retrieving executives information", MsgBoxStyle.OKOnly, "RETRIEVAL ER
Exit Sub
End Try
ListViewQuery.Items.Clear()
For cnt = 0 To ds.Tables(0).Rows.Count − 1
'If forward Queries Information is displayed
Reprinted for milanm, Avanade SkillSoft, SkillSoft Corporation (c) 2004, Copying Prohibited
.NET InstantCode: UML with Visio and Visual Studio .NET 19
Listing 4−8 shows the code for the QueryProvider.vb file that defines the QueryProvider class:
Listing 4−8: The QueryProvider.vb File
Imports System
Imports System.Data
Reprinted for milanm, Avanade SkillSoft, SkillSoft Corporation (c) 2004, Copying Prohibited
.NET InstantCode: UML with Visio and Visual Studio .NET 23
Imports System.Data.SqlClient
'The QueryProvider class that defines the remoting object
Public Class QueryProvider
Inherits MarshalByRefObject
Dim ds As New DataSet
Dim sqlcon As New SqlClient.SqlConnection
Sub New()
'Establishing a connection with QueryTracker Database
Try
sqlcon.ConnectionString = "SERVER=192.168.0.12;UID=sa;PWD=sa;Initial Catalog=QueryTrac
sqlcon.Open()
Catch ex As Exception
MsgBox("Connection Error", MsgBoxStyle.OKOnly, "Attempt to connection to data source f
End Try
End Sub
'This function returns the queries meant for a particular executive in form of a dataset
Public Function getQuery(ByVal id As Integer) As DataSet
Try
Dim sqlcmd As New SqlClient.SqlCommand("select * from queries where QueryId in _
(select QueryId from execquery where eid=" & id & ") and status='forwarded'", sqlcon)
Dim sqlda As New SqlClient.SqlDataAdapter(sqlcmd)
'Filling the data set
sqlda.Fill(ds)
'returning the data set
Return ds
Catch ex As Exception
'In case any exception occurs then returning a blank data set
Return ds
End Try
End Function
'This function allows the executive to log on and returns the executive id
Public Function login(ByVal strUserName As String, ByVal strpwd As String) As Integer
Try
'Verifying the specified information for Executive Login
Dim sqlcom As New SqlClient.SqlCommand("select * from CustSupportExecutives where Firs
& strUserName & "' and Pwd='" & strpwd & "'", sqlcon)
Dim sqldr As SqlClient.SqlDataReader
sqldr = sqlcom.ExecuteReader
'To check whether the login attempt is successful
If sqldr.HasRows Then
'return the executive id
sqldr.Read()
Return sqldr.GetInt32(0)
Else
'in case the login is unsuccessful return 0
MsgBox("Login Unsuccessful", MsgBoxStyle.OKOnly, "INVALID LOGIN")
Return 0
End If
Catch ex As Exception
MsgBox("Error in executive login", MsgBoxStyle.OKOnly, "LOGIN ERROR")
Return 0
End Try
End Function
'This function accepts a dataset containing the queries to be marked as
'attended for a particular executive
Public Function updateQuery(ByVal ds As DataSet)
Try
'Updating the dataset ds contents back to database QueryTracker
Dim sqlcmd As New SqlCommand("Update Queries set status='attended' where QueryId=@Quer
sqlcmd.Parameters.Add(New SqlParameter("@QueryID", SqlDbType.Int))
Dim rowcount As Integer
If ds.Tables.Count <> 0 Then
If ds.Tables(0).Rows.Count <> 0 Then
For rowcount = 0 To ds.Tables(0).Rows.Count – 1
sqlcmd.Parameters("@QueryID").Value = ds.Tables(0).Rows(rowcount).Item(0)
sqlcmd.ExecuteNonQuery()
Next
End If
End If
Catch ex As Exception
MsgBox("Unable to update", MsgBoxStyle.OKOnly, "Update Error")
End Try
End Function
End Class
Reprinted for milanm, Avanade SkillSoft, SkillSoft Corporation (c) 2004, Copying Prohibited
.NET InstantCode: UML with Visio and Visual Studio .NET 24
Listing 4−9 shows the code for the Server.vb that defines the Server class:
Listing 4−9: The Server.vb File
Imports System.Runtime.Remoting
Imports System.Runtime.Remoting.Channels
Imports System.Runtime.Remoting.Channels.Tcp
'This class defines the server listener that registers the remoting object on a TCP channel
Public Class Server
Dim tcp As TcpChannel
Dim cs As ChannelServices
Public Sub RegisterObject()
'Creating a new TcpChannel
tcp = New TcpChannel(8080)
'Registering the new TcpChannel
cs.RegisterChannel(tcp)
Dim objQueryProvider As New QueryTrackerRemotingObject.QueryProvider
'Registering the service provided by QueryProvider Remoting Business object
RemotingConfiguration.RegisterWellKnownServiceType(objQueryProvider.GetType, _
"QueryProvider", WellKnownObjectMode.SingleCall)
'This message box confirms that the server listener is running
MsgBox("Server Running")
End Sub
End Class
Public Class start
Public Shared Sub Main()
Dim server As New Server
server.RegisterObject()
End Sub
End Class
In the above listing, the RegisterObject() method creates a TCP channel and listens for the request
for the QueryProvider remoting object at port 8080. The server starts before any executive requests
the remoting object to retrieve and update queries into the database.
Reprinted for milanm, Avanade SkillSoft, SkillSoft Corporation (c) 2004, Copying Prohibited
.NET InstantCode: UML with Visio and Visual Studio .NET 25
Listing 4−10 shows the code for the frmExecutiveLogin.vb file that defines the ExecutiveLogin class:
Listing 4−10: The frmExecutiveLogin.vb File
Imports System.Data.SqlClient
Imports System.IO
Imports System.Collections
Imports System.Runtime.Remoting.Channels
Public Class ExecutiveLogin
Inherits System.Windows.Forms.Form
Private Sub cmdGo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles
'Calling the Login function
executiveId = objQueryProvider.login(txtUserName.Text, txtPassWord.Text)
'Checking whether the login is succesful
If executiveId <> 0 Then
boolLoginConfirmaion = True
strUserName = txtUserName.Text
Dim objQueryTrackerClient As New QueryTrackerClient
objQueryTrackerClient.ShowDialog()
End If
Me.Close()
End Sub
End Class
Listing 4−11 shows the code for the frmQueryTrackerClient.vb file that defines the
QueryTrackerClient class:
Listing 4−11: The frmQueryTrackerClient.vb File
'This class provides methods to allow the executives to view the queries meant
'for them and mark them as attended when they have attended the query
Public Class QueryTrackerClient
Inherits System.Windows.Forms.Form
'Dataset variable to receive the dataset from queryprovider getQuery method
Dim ds As DataSet
'Dataset variable to return the dataset containing the queries that
'has to be marked as attended in the QueryTracker database
Dim updateds As New DataSet
'A datatable to store the QueryId of the queries that has been marked as attended by the exe
Dim queryTable As New DataTable("Queries")
Private Sub QueryTrackerClient_Closing(ByVal sender As Object, ByVal e As _
System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
If queryTable.Rows.Count = 0 Then
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
'Assigning the queryTable datatable to updateds dataset
updateds.Tables.Add(queryTable)
objQueryProvider.updateQuery(updateds)
End Sub
Private Sub cmdAttended_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _
Handles cmdAttended.Click
'Check whether a query has been selected from the list view ListViewQuery
If ListViewQuery.SelectedItems.Count = 0 Then
MsgBox("Please select a query first", MsgBoxStyle.OKOnly, "WAIT HERE")
ListViewQuery.Focus()
Exit Sub
End If
'Marking the selected query as attended
ListViewQuery.SelectedItems.Item(0).SubItems(6).Text = "A"
Try
If queryTable.Rows.Count = 0 Then
'Creating the queryTable DataTable to contain the QueryId of the
'queries to be marked as attended
Dim queryDataColumn As New DataColumn
queryDataColumn.DataType = System.Type.GetType("System.Int32")
queryDataColumn.ColumnName = "QueryId"
queryTable.Columns.Add(queryDataColumn)
Dim querydataRow As DataRow = queryTable.NewRow
querydataRow.Item(0) = ListViewQuery.SelectedItems.Item(0).Text
queryTable.Rows.Add(querydataRow)
Else
'Adding new row to queryTable DataTable
Dim querydataRow As DataRow = queryTable.NewRow
querydataRow.Item(0) = ListViewQuery.SelectedItems.Item(0).Text
queryTable.Rows.Add(querydataRow)
End If
Catch ex As Exception
End Try
End Sub
Private Sub QueryTrackerClient_Load(ByVal sender As Object, ByVal e As System.EventArgs) Han
If boolLoginConfirmaion = True Then
'Splashing a welcome message to the executive
lblWelcome.Text = "Welcome " & InitializeQueryProvider.strUserName
'Retrieving the queries for the executive
ds = objQueryProvider.getQuery(executiveId)
Try
If ds.Tables(0).Rows.Count = 0 Then
lblWelcome.Text = lblWelcome.Text & " : " & "No Queries For You."
ElseIf ds.Tables(0).Rows.Count = 1 Then
lblWelcome.Text = lblWelcome.Text & " : " & _
ds.Tables(0).Rows.Count & " Query For You."
Else
lblWelcome.Text = lblWelcome.Text & " : " & _
ds.Tables(0).Rows.Count & " Queries For You."
End If
'Enabling the cmdAttended command button
cmdAttended.Enabled = True
Dim rowcount As Integer
Dim tempListViewItem As ListViewItem
'Populating ListViewQuery with Query information retrieved by the dataset
For rowcount = 0 To ds.Tables(0).Rows.Count − 1
tempListViewItem = ListViewQuery.Items.Add(ds.Tables(0).Rows(rowcount).Item(0))
tempListViewItem.SubItems.Add(rowcount + 1)
tempListViewItem.SubItems.Add(ds.Tables(0).Rows(rowcount).Item(1))
tempListViewItem.SubItems.Add(ds.Tables(0).Rows(rowcount).Item(2))
tempListViewItem.SubItems.Add(ds.Tables(0).Rows(rowcount).Item(4))
tempListViewItem.SubItems.Add(ds.Tables(0).Rows(rowcount).Item(3))
'marking the query as unattended
tempListViewItem.SubItems.Add("U")
Next
Catch ex As Exception
MsgBox("Unable to retrieve queries", MsgBoxStyle.OKOnly, "Retrieval Error")
End Try
Else
Me.Close()
End If
End Sub
Reprinted for milanm, Avanade SkillSoft, SkillSoft Corporation (c) 2004, Copying Prohibited
.NET InstantCode: UML with Visio and Visual Studio .NET 27
• QueryTrackerClient_Load(): Retrieves and loads the queries specified for the executive in
the ListViewQuery list view control.
• cmdAttended_Click(): Executes when an executive selects a query from the list and clicks
on the Mark as Attended button to mark that query as attended to. This method updates the
query status in the list as ‘A’.
Imports System.Runtime.Remoting.Channels
Imports System.Runtime.Remoting.Channels.Tcp
Module InitializeQueryProvider
'A boolean variable to store the login status of the executive
Public boolLoginConfirmaion As Boolean
'A string variable to store the user name of the executive
Public strUserName As String
'A channelservices variable to register the tcp channel
Public cs As ChannelServices
Reprinted for milanm, Avanade SkillSoft, SkillSoft Corporation (c) 2004, Copying Prohibited
.NET InstantCode: UML with Visio and Visual Studio .NET 28
In the above listing, the main() function creates a TCP channel as well as an instance of the
remoting object, and invokes the Executive Login window.
Unit Testing
To execute the QueryTrackerAdministrator application:
1. Execute the QueryTrackerAdministrator.exe file. This file is located in the /bin folder of the
QueryTrackerAdministrator project. The Login Manager window appears, as shown in Figure
4−11:
2. Enter the user name and password, and click the Login button. If the login information is
correct, the Application Manager window appears, as shown in Figure 4−12:
3. Select Executive Manager−>Add Executive to add information about a new executive. The
Executive Manager window appears, as shown in Figure 4−13:
Reprinted for milanm, Avanade SkillSoft, SkillSoft Corporation (c) 2004, Copying Prohibited
.NET InstantCode: UML with Visio and Visual Studio .NET 29
4. Specify the executive information and click the Add New Executive button to add the
information about the executive, as shown in Figure 4−14:
Reprinted for milanm, Avanade SkillSoft, SkillSoft Corporation (c) 2004, Copying Prohibited
.NET InstantCode: UML with Visio and Visual Studio .NET 30
5. Select Query Manager−>Add Query in the Application Manager window to add a query into
the database. The Query Manager window appears, as shown in Figure 4−15:
6. Specify the query information and click the Add Query button to save the information about
the query in the database, as shown in Figure 4−16:
Reprinted for milanm, Avanade SkillSoft, SkillSoft Corporation (c) 2004, Copying Prohibited
.NET InstantCode: UML with Visio and Visual Studio .NET 31
Figure 4−17: The Forward Pending Query to Executive Window with Query List
8. Select a pending query from the pending queries list, select an executive, and click the
Forward button to forward the selected query to a selected executive.
1. Execute the QueryTrackerServerListener.exe file. This file is located in the /bin folder of the
QueryTrackerServerListener project. A confirmation message box appears, as shown in
Figure 4−18:
2. Execute the QueryTrackerClient.exe file. This file is located in the /bin folder of the
QueryTrackerClient project. The Executive Login window appears, as shown in Figure 4−19:
Reprinted for milanm, Avanade SkillSoft, SkillSoft Corporation (c) 2004, Copying Prohibited
.NET InstantCode: UML with Visio and Visual Studio .NET 32
3. Enter the user name and password and click Login to access the queries. If the login is
correct, the Query Tracker Client window appears, as shown in Figure 4−20:
4. Select a query and click the Mark as Attended button to mark that query as attended. The
query status changes to ‘A’, as shown in Figure 4−21:
5. Click the Close button to update the status of the queries marked as attended to into the
database.
Reprinted for milanm, Avanade SkillSoft, SkillSoft Corporation (c) 2004, Copying Prohibited
.NET InstantCode: UML with Visio and Visual Studio .NET 33
To create a UML static model diagram from the Query Tracker application:
2. Select View−>Solution Explorer to view the Solution Explorer for the QueryTracker
application. The Solution Explorer appears, as shown in Figure 4−22:
Reprinted for milanm, Avanade SkillSoft, SkillSoft Corporation (c) 2004, Copying Prohibited
.NET InstantCode: UML with Visio and Visual Studio .NET 34
5. Specify the file name as QueryTrackerClient.vsd and click the Save button. Microsoft Visio
opens up automatically and displays the UML static model in the Model Explorer, as shown
in Figure 4−24:
Downloads
To download the code files, click here.
Reprinted for milanm, Avanade SkillSoft, SkillSoft Corporation (c) 2004, Copying Prohibited