To create the Information Retrieval Visio XML application, you need to create the Connect and EventSink classes, the Services, Locations, Companies, Company Location, Company Services, Service Information, and Near by Locations windows , as well as the Shared module.
The InformationRetrievalCOMAddIn project uses the Connect class to define the COM add-in to connect to Microsoft Visio. The Connect class implements the IDTExtensibility2 interface to connect to Microsoft Visio as a COM add-in.
Listing 7-2 shows the code for the Connect.vb file:
![]() |
Imports Microsoft.Office.Core Imports Extensibility Imports System.Runtime.InteropServices Imports Microsoft.Office.Interop.Visio <GuidAttribute("a199ffea-fcb3-4ba6-a2ae-f3d9275f20a8"), ProgIdAttribute("InformationRetrievalCOMAddIn.Connect")> _ Public Class Connect 'Abstract - This class implements the IDTExtensibility2 interface 'in order to connect to Microsoft Visio as a COM add-in. Implements Extensibility.IDTExtensibility2 Public WithEvents vsoApplication As Microsoft.Office.Interop.Visio.Application Dim resultEvent As Microsoft.Office.Interop.Visio.Event Dim eventSink As IVisEventProc Dim addInInstance As Object 'This procedure is the class constructor. Public Sub New() 'No initialization required. End Sub 'This procedure implements the OnAddInsUpdate method of the 'IDTExtensibility2 interface. It receives notification that the 'collection of add-ins has changed. '<param name="custom">Array of parameters that are host application 'specific</param> Public Sub OnAddInsUpdate(ByRef custom As System.Array) _ Implements Extensibility.IDTExtensibility2.OnAddInsUpdate End Sub 'This procedure implements the OnBeginShutdown method of the 'IDTExtensibility2 interface. It receives notification that the host 'application is being unloaded. '<param name="custom">Array of parameters that are host application specific</param> Public Sub OnBeginShutdown(ByRef custom As System.Array) _ Implements Extensibility.IDTExtensibility2.OnBeginShutdown End Sub 'This method implements the OnConnection method of the 'IDTExtensibility2 interface. It receives notification when the add-in loads. '<param name="application">Root object of the host application '</param> '<param name="connectMode">Describes how the add-in is being loaded '</param> '<param name="addInInst">Object representing this add-in</param> '<param name="custom">Array of parameters that are host application 'specific.</param> Public Sub OnConnection(ByVal application As Object, _ ByVal connectMode As Extensibility.ext_ConnectMode, _ ByVal addInInst As Object, ByRef custom As System.Array) _ Implements Extensibility.IDTExtensibility2.OnConnection vsoApplication = CType(application, Microsoft.Office.Interop.Visio.Application) addInInstance = addInInst MsgBox("Information Retrieval connected.", MsgBoxStyle.OKOnly, "InformationRetrieval COM add-in") Dim eventlist As EventList = vsoApplication.EventList Dim visioEventSink As New EventSink 'Adding the visEvtDocCreate event to the eventlist collection of the visio document resultEvent = eventlist.AddAdvise(VisEventCodes.visEvtCodeDocCreate, visioEventSink, "", "") End Sub 'This procedure is called when the add-in is about to be unloaded. 'The add-in will be unloaded when Microsoft Visio is shutting down or 'when a user has removed or deselected the add-in from the "COM add-ins" dialog. '<param name="removeMode">Indicator telling the add-in why Visio is 'disconnecting </param> '<param name="custom">Array of additional parameters for the add-in, 'not used in this case</param> Public Sub OnDisconnection(ByVal RemoveMode As _ Extensibility.ext_DisconnectMode, _ ByRef custom As System.Array) _ Implements Extensibility.IDTExtensibility2.OnDisconnection End Sub 'This procedure implements the OnStartupComplete method of the IDTExtensibility2 interface. 'It receives notification that the host application has completed loading. '<param name="custom">Array of parameters that are host 'application specific</param> Public Sub OnStartupComplete(ByRef custom As System.Array) _ Implements Extensibility.IDTExtensibility2.OnStartupComplete End Sub 'This procedure is called when the Visio document is created. Private Sub vsoApplication_DocumentCreated(ByVal doc As _ Microsoft.Office.Interop.Visio.Document) Handles vsoApplication.DocumentCreated Dim objServices As New Services Try If doc.DocumentSheet.SectionExists(VisSectionIndices.visSectionUser, 0) Then objServices.ShowDialog() Else objServices.ShowDialog() End If Catch ex As Exception MsgBox("Unable to open the Information Retrieval Template", MsgBoxStyle.OKOnly, "Loading Error") End Try End Sub End Class
![]() |
Download this Listing .
The above listing defines the following methods :
onConnection() : Executes when an end user invokes Microsoft Visio. This method receives a notification when the COM add-in loads with Visio. It adds the visEvtCodeDocCreate event to the event list of the Visio application to trap this event when the end user creates a Visio document.
vsoApplication_DocumentCreated() : Executes when an end user creates a Visio document. This method loads the Services window to enable the end user to access service categories.
The EventSink.vb file defines the EventSink class that implements the IVisEventProc interface. The EventSink class provides the VisEventProc() method that executes when an end user performs an action in Visio that generates an event, which maps to an event in the EventList collection of a Visio application.
Listing 7-3 shows the code for the EventSink.vb file:
![]() |
Imports Microsoft.Office.Interop.Visio Imports System.Runtime.InteropServices Public Class EventSink Implements IVisEventProc 'The IVisEventProc.VisEventProc function is called by Visio when 'an event which has been added to an events list collection has been raised. Public Function VisEventProc(ByVal nEventCode As Short, ByVal pSourceObj As Object, _ ByVal nEventID As Integer, ByVal nEventSeqNum As Integer, ByVal pSubjectObj As _ Object, ByVal vMoreInfo As Object) As Object Implements _ Microsoft.Office.Interop.Visio.IVisEventProc.VisEventProc Dim visioDocument As Document 'If the Visio document created event is raised If nEventCode = CShort(VisEventCodes.visEvtCodeDocCreate) Then 'If the object that has initiated this function is a document. If TypeOf pSubjectObj Is Document Then visioDocument = pSubjectObj End If 'Extract the XML data from the XMLds dataset in the SolutionXMLElement element of the visio document If Not XMLds.Tables.Count = 0 And Not XMLds.Tables(0).Rows.Count = 0 Then Try Dim rowcount As Integer Dim XMLElementString As String For rowcount = 0 To XMLds.Tables(0).Rows.Count - 1 XMLElementString = "InformationRetrieval" & rowcount + 1 visioDocument.SolutionXMLElement(XMLElementString) = _ "<SolutionXML Name='" & XMLElementString & "'><Service>" & _ XMLds.Tables(0).Rows(rowcount).Item(0) & " </Service><Company>" & _ XMLds.Tables(0).Rows(rowcount).Item(2) & "</Company><Location>" & _ XMLds.Tables(0).Rows(rowcount).Item(1) & "</Location><Address>" & _ XMLds.Tables(0).Rows(rowcount).Item(3) & "</Address><Phone>" & _ XMLds.Tables(0).Rows(rowcount).Item(4) & "</Phone></SolutionXML>" Next Catch ex As Exception MsgBox("Unable to write XML data to the visio drawing", MsgBoxStyle.OKOnly, "XML Error") Exit Function End Try MsgBox("The XML data has been successfully extracted", MsgBoxStyle.OKOnly, "SUCCESS") End If End If End Function End Class
![]() |
Download this Listing .
In the above listing, the VisEventProc method executes when an end user creates a Visio document. This method stores the XML data that an end user extracts from the Service Information window, in the SolutionXMLElement element of the Visio document. This method then displays a confirmation message if it successfully extracts the XML data.
The Services class defines the Services window. The Services class displays the service categories available in the database to the end user.
Listing 7-4 shows the code for the frmServices.vb that defines the Services class:
![]() |
'This class displays the available service categories in the database to the end user Imports System.Windows.Forms Public Class Services Inherits System.Windows.Forms.Form Private Sub Services_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load Try Dim informationRetrievalService As New localhost.InformationRetrievalService Dim ds As DataSet 'Calling the GetServiceCategory method from the Web service to retrieve the service categories ds = informationRetrievalService.GetServiceCategory If Not ds.Tables.Count = 0 And Not ds.Tables(0).Rows.Count = 0 Then Dim rowcount As Integer 'Retrieving service categories from data set returned by GetServiceCategory method For rowcount = 0 To ds.Tables(0).Rows.Count - 1 'Adding to the list view the service category listviewServices.Items.Add(ds.Tables(0).Rows(rowcount).Item(1)) Next 'This item is added to allow the end user to browse through the 'locations instead of selecting a service category listviewServices.Items.Add("No particular service") Else MsgBox("No service categories found", MsgBoxStyle.OKOnly, "No Service Categories") Exit Sub End If Catch ex As Exception MsgBox("Unable to retrieve service categories", MsgBoxStyle.OKOnly, "Retrieval Error") End Try End Sub Private Sub cmdNext_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmdNext.Click If Not listviewServices.SelectedItems.Count = 0 Then If listviewServices.SelectedItems(0).Text = "No particular service" Then 'Creating an instance of Locations class that represents the window 'displaying all available locations in the database Dim objLocations As New Locations objLocations.Left = Me.Left objLocations.Top = Me.Top objLocations.ShowDialog() Else 'Creating an instance of CompanyLocation class that represents the window 'displaying all available companies and their locations providing services 'for the selected service category Dim objCompanyLocation As New CompanyLocation(listviewServices.SelectedItems(0).Text) objCompanyLocation.Left = Me.Left objCompanyLocation.Top = Me.Top objCompanyLocation.ShowDialog() End If End If End Sub End Class
![]() |
Download this Listing .
The above listing defines the following methods:
Services_Load() : Calls the GetServiceCategory() method from the InformationRetrievalService Web service to retrieve the service categories available and displays the retrieved service categories in the listviewServices list view control.
cmdNext_Click() : Executes when an end user selects a service category and clicks the Next button. This method invokes the Company Location window if the end user selects a service category, and invokes the Locations window if the end user selects the No particular service option.
Figure 7-3 shows the output of Listing 7-4:
The Locations class defines the Locations window. The Locations class displays the locations available in the Locations table within the database to the end user.
Listing 7-5 shows the code for the frmLocations.vb that defines the Location class:
![]() |
'This class displays the available locations in the database to the end user so that 'the end user can browse through the locations and choose one to see the services 'located in that location Imports System.Data Public Class Locations Inherits System.Windows.Forms.Form Private Sub frmLocations_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load Try 'Creating an instance of InformationRetrievalService Web service Dim informationRetrievalService As New localhost.InformationRetrievalService Dim ds As DataSet 'Retrieving the available locations by calling GetLocations method from the web service ds = informationRetrievalService.GetLocations If Not ds.Tables.Count = 0 And Not ds.Tables(0).Rows.Count = 0 Then Dim rowcount As Integer For rowcount = 0 To ds.Tables(0).Rows.Count - 1 listviewLocations.Items.Add(ds.Tables(0).Rows(rowcount).Item(1)) Next 'This item is added to allow the end user to browse through the companies 'instead of selecting a particular location listviewLocations.Items.Add("No particular location") Else MsgBox("No locations found", MsgBoxStyle.OKOnly, "No Locations") Exit Sub End If Catch ex As Exception MsgBox("Unable to retrieve locations", MsgBoxStyle.OKOnly, "Retrieval Error") End Try End Sub 'To view the near by locations for a particular location listed in listviewLocations 'the end user is required to double-click the location in the listviewLocations Private Sub listviewLocations_DoubleClick(ByVal sender As Object, ByVal e As _ System.EventArgs) Handles listviewLocations.DoubleClick If Not listviewLocations.SelectedItems.Count = 0 And Not _ listviewLocations.SelectedItems(0).Text = "No particular location" Then 'Creating an instance of NearbyLocations and passing the selected location name 'as a parameter in the NearbyLocations constructor Dim objNearByLocations As New NearbyLocations(listviewLocations.SelectedItems(0).Text) objNearByLocations.ShowDialog() End If End Sub 'To view the services located in a particular location the end user is 'required to select the desired location and click next button Private Sub cmdNext_Click(ByVal sender As System.Object, ByVal e As _ System.EventArgs) Handles cmdNext.Click If Not listviewLocations.SelectedItems.Count = 0 Then If listviewLocations.SelectedItems(0).Text = "No particular location" Then 'Creating an instance of Companies to show the available companies in the database Dim objCompanies As New Companies objCompanies.Left = Me.Left objCompanies.Top = Me.Top objCompanies.ShowDialog() Else 'Creating an instance of CompanyServices and passing the selected 'location name as a parameter in the Services constructor Dim objCompanyServices As New CompanyServices(listviewLocations.SelectedItems(0).Text) objCompanyServices.Left = Me.Left objCompanyServices.Top = Me.Top objCompanyServices.ShowDialog() End If End If End Sub End Class
![]() |
Download this Listing .
The above listing defines the following methods:
Locations_Load() : Calls the GetLocations() method from the InformationRetrievalService Web service to retrieve the available locations and displays the retrieved locations in the listviewLocations list view control.
cmdNext_Click() : Executes when an end user selects a location and clicks the Next button to view the companies and the services provided in the location selected. This method invokes the Company Services window if the end user selects a location, and invokes the Companies window if the end user selects the No particular location option.
listviewLocations_DoubleClick() : Executes when an end user selects a location to get information on locations close to a selected location. This method invokes the Near by Locations window.
Figure 7-4 shows the output of Listing 7-5:
The NearbyLocations class defines the Near by Locations window. The NearbyLocations class displays the locations that are close to a selected location in the Locations window.
Listing 7-6 shows the code for the frmNearbyLocations.vb that defines the NearbyLocation class:
![]() |
'This class displays the near by locations for the location selected by the end user Imports System.Windows.Forms Public Class NearbyLocations Inherits System.Windows.Forms.Form Dim locationName As String Public Sub New(ByVal strLocationName As String) MyBase.New() 'This call is required by the Windows Form Designer. InitializeComponent() 'Add any initialization after the InitializeComponent() call locationName = strLocationName End Sub Private Sub NearbyLocations_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load Try Dim informationRetrievalService As New localhost.InformationRetrievalService Dim ds As DataSet 'Calling the GetNearByLocations method from the web service to retrieve the near by locations ds = informationRetrievalService.GetNearByLocations(locationName) If Not ds.Tables.Count = 0 And Not ds.Tables(0).Rows.Count = 0 Then Dim rowcount As Integer Dim tempListViewItem As ListViewItem 'Retrieving near by locations from data set returned by GetNearByLocations method For rowcount = 0 To ds.Tables(0).Rows.Count - 1 'Adding to the list view the name of the near by location tempListViewItem = listviewNearbyLocations.Items.Add(ds.Tables(0).Rows(rowcount).Item(1)) 'Adding to the list view the distance in kilometers from the selected location tempListViewItem.SubItems.Add(ds.Tables(0).Rows(rowcount).Item(2)) Next Else MsgBox("No near by locations found", MsgBoxStyle.OKOnly, "No Near by Locations") Exit Sub End If Catch ex As Exception MsgBox("Unable to retrieve near by locations", MsgBoxStyle.OKOnly, "Retrieval Error") End Try End Sub Private Sub cmdBack_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdBack.Click Me.Close() End Sub Private Sub cmdNext_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmdNext.Click If Not listviewNearbyLocations.SelectedItems.Count = 0 Then 'Creating an instance of CompanyServices and passing the selected 'location name as a parameter in the Services constructor Dim objCompanyServices As New CompanyServices(listviewNearbyLocations.SelectedItems(0).Text) objCompanyServices.Left = Me.Left objCompanyServices.Top = Me.Top objCompanyServices.ShowDialog() End If End Sub End Class
![]() |
Download this Listing .
The above listing defines the following methods:
NearbyLocations_Load() : Calls the GetNearByLocations() method from the InformationRetrievalService Web service to retrieve the locations that are close to the selected location and their distance from the selected location.
cmdNext_Click() : Executes when an end user selects a location and clicks the Next button to view the companies and the services provided in a selected location. This method invokes the Company Services window.
cmdBack_Click() : Executes when an end user clicks the Back button to go to the Locations window. This method closes the Near by Locations window.
Figure 7-5 shows the output of Listing 7-6:
The Companies class defines the Companies window. The Companies class displays the company names in the database.
Listing 7-7 shows the code for the frmCompanies.vb that defines the Companies class:
![]() |
'This class is instantiated when the end user selects "No particular service" from the Services Window Public Class Companies Inherits System.Windows.Forms.Form Private Sub frmCompanies_Load(ByVal sender As System.Object, ByVal e As _ System.EventArgs) Handles MyBase.Load Try Dim informationRetrievalService As New localhost.InformationRetrievalService Dim ds As DataSet 'Calling the GetCompany method from the Web service to retrieve the company names ds = informationRetrievalService.GetCompany If Not ds.Tables.Count = 0 And Not ds.Tables(0).Rows.Count = 0 Then Dim rowcount As Integer 'Retrieving company names from data set returned by GetCompany method For rowcount = 0 To ds.Tables(0).Rows.Count - 1 'Adding to the list view the company name listviewCompanies.Items.Add(ds.Tables(0).Rows(rowcount).Item(0)) Next Else MsgBox("No companies found", MsgBoxStyle.OKOnly, "No Companies") Exit Sub End If Catch ex As Exception MsgBox("Unable to retrieve company names", MsgBoxStyle.OKOnly, "Retrieval Error") End Try End Sub Private Sub cmdNext_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdNext.Click 'Creating an instance of ServiceDetails to view the details of the services 'provided by the selected company If Not listviewCompanies.SelectedItems.Count = 0 Then Dim objServiceDetails As New ServiceDetails("", listviewCompanies.SelectedItems(0).Text, _ "", "GetServicesBycompany") objServiceDetails.Left = Me.Left objServiceDetails.Top = Me.Top objServiceDetails.ShowDialog() End If End Sub End Class
![]() |
Download this Listing .
The above listing defines the following methods:
frmCompanies_Load() : Calls the GetCompany() method from the InformationRetrievalService Web service to retrieve company names.
cmdNext_Click() : Executes when an end user selects a company and clicks the Next button to view the contact information and services provided by a selected company. This method invokes the Service Information window.
Figure 7-6 shows the output of Listing 7-7:
The CompanyLocation class defines the Company Location window. The CompanyLocation class displays the company names and the location for the selected service category in the Services window.
Listing 7-8 shows the code for the frmCompanyLocation.vb that defines the CompanyLocation class:
![]() |
'This class displays the list of companies providing the services and their location for the selected service category Imports System.Windows.Forms Public Class CompanyLocation Inherits System.Windows.Forms.Form Dim ServiceName As String Public Sub New(ByVal strServiceName As String) MyBase.New() 'This call is required by the Windows Form Designer. InitializeComponent() 'Add any initialization after the InitializeComponent() call ServiceName = strServiceName End Sub Private Sub frmCompanyLocation_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load Try Dim informationRetrievalService As New localhost.InformationRetrievalService Dim ds As DataSet 'Calling the GetCompLocByService method from the web service to retrieve 'the company and location name of all the services available for selected service category ds = informationRetrievalService.GetCompLocByService(ServiceName) If Not ds.Tables.Count = 0 And Not ds.Tables(0).Rows.Count = 0 Then Dim rowcount As Integer Dim tempListViewItem As ListViewItem 'Retrieving company name and location name from data set returned by GetCompLocByService method For rowcount = 0 To ds.Tables(0).Rows.Count - 1 'Adding to the list view the company name tempListViewItem = listviewCompanyLocation.Items.Add(ds.Tables(0).Rows(rowcount).Item(1)) 'Adding to the list view the location name tempListViewItem.SubItems.Add(ds.Tables(0).Rows(rowcount).Item(0)) Next Else MsgBox("No services found", MsgBoxStyle.OKOnly, "No services for the selected category") Exit Sub End If Catch ex As Exception MsgBox("Unable to retrieve services", MsgBoxStyle.OKOnly, "Retrieval Error") End Try End Sub Private Sub cmdNext_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmdNext.Click 'Creating an instance of ServiceDetails to view the details of the selected 'service provided by the selected company in a specified location If Not listviewCompanyLocation.SelectedItems.Count = 0 Then Dim objServiceDetails As New _ ServiceDetails(listviewCompanyLocation.SelectedItems(0).SubItems(1).Text, _ listviewCompanyLocation.SelectedItems(0).Text, ServiceName, "GetSpecServiceByCompLoc") objServiceDetails.Left = Me.Left objServiceDetails.Top = Me.Top objServiceDetails.ShowDialog() End If End Sub End Class
![]() |
Download this Listing .
The above listing defines the following methods:
frmCompanyLocation_Load() : Calls the GetCompLocByService() method from the InformationRetrievalService Web service to retrieve the company names and the locations of all the services that belong to the selected service category.
cmdNext_Click() : Executes when an end user selects a combination of a company name and its location and clicks the Next button to view the information about the services provided by the selected company in a particular location. This method invokes the Service Information window.
Figure 7-7 shows the output of Listing 7-8:
The CompanyServices class defines the Company Services window. The CompanyServices class displays the company names and the services provided by these companies in the location that the end user selects in the Locations window.
Listing 7-9 shows the code for the frmCompanyServices.vb that defines the CompanyServices class:
![]() |
'This class displays the services located in the location selected by the end user in Locations window Imports System.Windows.Forms Public Class CompanyServices Inherits System.Windows.Forms.Form Dim LocationName As String Public Sub New(ByVal strLocationName As String) MyBase.New() 'This call is required by the Windows Form Designer. InitializeComponent() 'Add any initialization after the InitializeComponent() call LocationName = strLocationName End Sub Private Sub frmCompanyServices_Load(ByVal sender As Object, ByVal e As _ System.EventArgs) Handles MyBase.Load Try Dim informationRetrievalService As New localhost.InformationRetrievalService Dim ds As DataSet 'Calling the GetServicesByLocation method from the web service to 'retrieve the services located in the selected location ds = informationRetrievalService.GetServicesByLocation(LocationName) If Not ds.Tables.Count = 0 And Not ds.Tables(0).Rows.Count = 0 Then Dim rowcount As Integer Dim tempListViewItem As ListViewItem 'Retrieving company name and location name from data set returned by 'GetCompLocByService method For rowcount = 0 To ds.Tables(0).Rows.Count - 1 'Adding to the listview the company name tempListViewItem = listviewCompanyService.Items.Add(ds.Tables(0).Rows(rowcount).Item(2)) 'Adding to the list view the service category tempListViewItem.SubItems.Add(ds.Tables(0).Rows(rowcount).Item(1)) Next Else MsgBox("No services found", MsgBoxStyle.OKOnly, "No services for the selected location") Exit Sub End If Catch ex As Exception MsgBox("Unable to retrieve services", MsgBoxStyle.OKOnly, "Retrieval Error") End Try End Sub Private Sub cmdNext_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdNext.Click 'Creating an instance of ServiceDetails to view the details of the 'selected service provided by the selected company in a specified location Dim objServiceDetails As New ServiceDetails(LocationName, _ listviewCompanyService.SelectedItems(0).Text, _ listviewCompanyService.SelectedItems(0).SubItems(1).Text, "GetSpecServiceByCompLoc") objServiceDetails.Left = Me.Left objServiceDetails.Top = Me.Top objServiceDetails.ShowDialog() End Sub End Class
![]() |
Download this Listing .
The above listing defines the following methods:
frmCompanyServices_Load() : Calls the GetServicesByLocation() method from the InformationRetrievalService Web service to retrieve the companies and the services provided by these companies in selected locations.
cmdNext_Click() : Executes when an end user selects a combination of a company and the service it provides and clicks the Next button to view the information about the selected combination of companies and services in a particular location. This method invokes the Service Information window.
Figure 7-8 shows the output of Listing 7-9:
The ServiceDetails class defines the Service Information window. The ServiceDetails class displays information, such as company names, service categories, locations, addresses, and phone numbers for a particular service.
Listing 7-10 shows the code for the frmServiceDetails.vb that defines the ServiceDetails class:
![]() |
'This class displays the details for the selected service, such as address and phone number. Imports System.Windows.Forms Public Class ServiceDetails Inherits System.Windows.Forms.Form Dim LocationName As String Dim Company As String Dim ServiceCategory As String Dim Mode As String Dim ds As New DataSet Dim extractds As New DataSet Public Sub New(ByVal strLocation As String, ByVal strCompany As String, _ ByVal strService As String, ByVal strMode As String) MyBase.New() 'This call is required by the Windows Form Designer. InitializeComponent() 'Add any initialization after the InitializeComponent() call LocationName = strLocation Company = strCompany ServiceCategory = strService Mode = strMode 'Creating a new dataset that will contain the extracted information Dim extractTable As New DataTable("InformationRetrieval") Dim serviceColumn As New DataColumn("service") Dim locationColumn As New DataColumn("location") Dim companyColumn As New DataColumn("company") Dim addressColumn As New DataColumn("address") Dim phoneColumn As New DataColumn("phone") extractTable.Columns.Add(serviceColumn) extractTable.Columns.Add(locationColumn) extractTable.Columns.Add(companyColumn) extractTable.Columns.Add(addressColumn) extractTable.Columns.Add(phoneColumn) extractds.Tables.Add(extractTable) End Sub Private Sub cmdExtract_Click(ByVal sender As System.Object, ByVal e As _ System.EventArgs) Handles cmdExtract.Click 'Extracting the returned dataset by the web service into a shared 'data set provided in the shared.vb module XMLds = extractds Me.Close() End Sub Private Sub ServiceDetails_Load(ByVal sender As Object, ByVal e As _ System.EventArgs) Handles MyBase.Load 'Creating an instance of InformationRetrievalService Web service Dim informationRetrievalService As New localhost.InformationRetrievalService Try If Mode = "GetSpecServiceByCompLoc" Then 'Retrieving the details of the selected service provided by 'a specific company located at a specific location ds = informationRetrievalService.GetSpecServiceByCompLoc _ (ServiceCategory, LocationName, Company) If Not ds.Tables.Count = 0 And Not ds.Tables(0).Rows.Count = 0 Then Dim rowcount As Integer Dim tempListViewItem As ListViewItem For rowcount = 0 To ds.Tables(0).Rows.Count - 1 Dim datarow As DataRow = extractds.Tables(0).NewRow 'Adding service category tempListViewItem = listviewServiceDetails.Items.Add(ServiceCategory) DataRow(0) = ServiceCategory 'Adding company name tempListViewItem.SubItems.Add(Company) DataRow(2) = Company 'Adding location tempListViewItem.SubItems.Add(LocationName) DataRow(1) = LocationName 'Adding address tempListViewItem.SubItems.Add(ds.Tables(0).Rows(rowcount).Item(0)) DataRow(3) = ds.Tables(0).Rows(rowcount).Item(0) 'Adding phone numbers tempListViewItem.SubItems.Add(ds.Tables(0).Rows(rowcount).Item(1)) DataRow(4) = ds.Tables(0).Rows(rowcount).Item(1) extractds.Tables(0).Rows.Add(DataRow) Next Else MsgBox("No details found", MsgBoxStyle.OKOnly, "No Details") Exit Sub End If End If Catch ex As Exception MsgBox("Unable to retrieve details for the selected service", MsgBoxStyle.OKOnly, "WAIT HERE") End Try Try If Mode = "GetServicesBycompany" Then 'Retrieving the details of the services provided by a specific company ds = informationRetrievalService.GetServicesBycompany(Company) If Not ds.Tables.Count = 0 And Not ds.Tables(0).Rows.Count = 0 Then Dim rowcount As Integer Dim tempListViewItem As ListViewItem For rowcount = 0 To ds.Tables(0).Rows.Count - 1 Dim datarow As DataRow = extractds.Tables(0).NewRow tempListViewItem = listviewServiceDetails.Items.Add(ds.Tables(0).Rows(rowcount).Item(0)) datarow(0) = ds.Tables(0).Rows(rowcount).Item(0) tempListViewItem.SubItems.Add("") datarow(1) = "" tempListViewItem.SubItems.Add("") datarow(2) = "" tempListViewItem.SubItems.Add(ds.Tables(0).Rows(rowcount).Item(1)) datarow(3) = ds.Tables(0).Rows(rowcount).Item(1) tempListViewItem.SubItems.Add(ds.Tables(0).Rows(rowcount).Item(2)) datarow(4) = ds.Tables(0).Rows(rowcount).Item(2) extractds.Tables(0).Rows.Add(datarow) Next Else MsgBox("No details found", MsgBoxStyle.OKOnly, "No Details") Exit Sub End If End If Catch ex As Exception MsgBox("Unable to retrieve the services provided by the selected company", _ MsgBoxStyle.OKOnly, "WAIT HERE") End Try End Sub 'If the mode is GetServicesByCompany then in order to see the complete details 'of the listed services the end user is required to double-click 'that service in the listviewServiceDetails Private Sub listviewServiceDetails_DoubleClick(ByVal sender As Object, _ ByVal e As System.EventArgs) Handles listviewServiceDetails.DoubleClick Try If Mode = "GetServicesBycompany" Then Dim InformationRetrievalService As New localhost.InformationRetrievalService 'Retrieving the details of the specific service listed in the 'listviewServiceDetails provided by a company selected by the user 'in the Companies window ds = informationRetrievalService.GetSpecServiceByComp _ (listviewServiceDetails.SelectedItems(0).Text, Company) If Not ds.Tables.Count = 0 And Not ds.Tables(0).Rows.Count = 0 Then Dim rowcount As Integer Dim tempListViewItem As ListViewItem 'Clearing existing contents in the listviewServiceDetails listviewServiceDetails.Items.Clear() For rowcount = 0 To ds.Tables(0).Rows.Count - 1 tempListViewItem = listviewServiceDetails.Items.Add(ds.Tables(0).Rows(rowcount).Item(0)) tempListViewItem.SubItems.Add("") tempListViewItem.SubItems.Add("") tempListViewItem.SubItems.Add(ds.Tables(0).Rows(rowcount).Item(1)) tempListViewItem.SubItems.Add(ds.Tables(0).Rows(rowcount).Item(2)) Next Else MsgBox("No details found", MsgBoxStyle.OKOnly, "No Details") Exit Sub End If End If Catch ex As Exception MsgBox("Unable to retrieve the selected service details", MsgBoxStyle.OKOnly, "WAIT HERE") End Try End Sub End Class
![]() |
Download this Listing .
The above listing defines the following methods:
ServiceDetails_Load() : Calls the GetSpecServiceByCompLoc() method if the Company Location window invokes the Service Information window and calls the GetServiceBycompany() method if the Company Services window invokes the Service Information window. This method then populates the listviewServiceDetails list view control with the retrieved information.
cmdExtract_Click() : Executes when an end user clicks the Extract button to extract the data retrieved by the Web service methods. This method copies the data retrieved in a temporary XMLds dataset.
Figure 7-9 shows the output of Listing 7-10: