Touring the Completed ApplicationAt this point, you re ready to take a tour of the application. When you run the program, as you can bypressing F5, the screen opens and displays the first contact in the database. The records are sorted alpha- betically by Last Name and First Name. The Contact ID is shown for display purposes, but gets auto- matically assigned by the database. An example of the starting screen is shown in Figure 11-18. Figure 11-18Notice how the Google box has been populated with records mentioning Microsoft, which is the com- pany that the fictitious John Doe works for. These records were retrieved using the Google API. You canclick on any of the hyperlinks in the Google box to review the actual Web site in more detail. When youdo so, a separate browser window is opened. The idea behind having this Google box is to provide your user with quick information about his cus- tomer or contact before he gives that contact a call. For example, the user might see that the customerhas recently been in the news, or he might just want to look at the Web site of that company for moreinformation. In either case, it is possible that one of the top-five ranking results from Google will haveuseful information about the customer. Next, if you want to test out the MapPoint features, click the Get Map button on the form. The MicrosoftMapPoint API is then called and a map of the city and state/region of the contact is displayed. This isillustrated in Figure 11-19. The user also can obtain driving directions to this customer s location. When the user clicks the GetDirections button on the form, he or she is prompted to specify a street address, city, state/region, and260Chapter
Note: If you are looking for good and high quality web space to host and run your application check Lunarwebhost Clan Web Hosting services
postal code of the starting location for the directions. An example of one of the prompts a user sees in Figure 11-20. Figure 11-19Figure 11-20261Case
Note: If you are looking for good and high quality web space to host and run your application check Lunarwebhost Clan Web Hosting services
Dim Address As New AddressAddress.AddressLine = txtAddress1.TextAddress.PrimaryCity = txtCity.TextAddress.Subdivision = txtRegion.TextAddress.PostalCode = txtPostalCode.Text set up the FindAddressSpecificationDim findAddressSpec As New FindAddressSpecificationfindAddressSpec.InputAddress = AddressfindAddressSpec.DataSourceName = MapPoint.NA call the FindAddress method to look up the addressDim foundResults As FindResultsfoundResults = findService.FindAddress(findAddressSpec) set the values for the destination addressIf (foundResults.NumberFound = 1) ThendblLatitudeEnd = foundResults.Results(0).FoundLocation.LatLong.LatitudedblLongitudeEnd = _ foundResults.Results(0).FoundLocation.LatLong.LongitudeElsedblLatitudeEnd = 0dblLongitudeEnd = 0End If ***NOW, FOR STARTING ADDRESS COORDINATES**** now, set up the starting AddressAddress.AddressLine = strAddressAddress.PrimaryCity = strCityAddress.Subdivision = strRegionAddress.PostalCode = strPostalCode call the FindAddress method to look up the addressfoundResults = findService.FindAddress(findAddressSpec) set the values for the starting addressIf (foundResults.NumberFound = 1) ThendblLatitudeStart = _ foundResults.Results(0).FoundLocation.LatLong.LatitudedblLongitudeStart = _ foundResults.Results(0).FoundLocation.LatLong.LongitudeElsedblLatitudeStart = 0dblLongitudeStart = 0End IfExit Subhandleerror: MsgBox( An error occurred in GetCoordinates: & Err.Number & - & _ Err.Description) Exit SubEnd Sub258Chapter
Note: If you are looking for good and high quality web space to host and run your application check Lunarwebhost Adult Web Hosting services
33.Add the following GetDrivingDirectionsprocedure to the form. This procedure uses theMapPoint API to retrieve driving directions for the starting and ending coordinates. Again, replace YOURUSERIDand YOURPASSWORDwhere indicated with those for your MapPointaccount. Function GetDrivingDirections(ByVal dblLatitudeStart As Double, ByVal _ dblLatitudeEnd As Double, ByVal dblLongitudeStart As Double, ByVal _ dblLongitudeEnd As Double) As StringOn Error GoTo handleerror Calculate driving directions between two latitude and longitude coordinates Dim latLongs(1) As LatLonglatLongs(0) = New LatLonglatLongs(0).Latitude = dblLatitudeStartlatLongs(0).Longitude = dblLongitudeStartlatLongs(1) = New LatLonglatLongs(1).Latitude = dblLatitudeEndlatLongs(1).Longitude = dblLongitudeEndDim routeService As New RouteServiceSoaprouteService.Credentials = New _ System.Net.NetworkCredential( YOUR USER ID , YOUR PASSWORD ) routeService.PreAuthenticate = TrueDim findRoute As RoutefindRoute = routeService.CalculateSimpleRoute(latLongs, _ MapPoint.NA , SegmentPreference.Quickest) Dim intCounter As IntegerDim strDirections As String output the directions into a stringFor intCounter = 0 To findRoute.Itinerary.Segments(0).Directions.Length = strDirections & _ findRoute.Itinerary.Segments(0).Directions(intCounter).Instruction & vbCrLfNext intCounterGetDrivingDirections = strDirectionsExit Functionhandleerror: MsgBox( An error occured in GetDrivingDirections: & Err.Number & - Err.Description) Exit FunctionEnd FunctionCongratulations! You ve now added all the code needed to make the CRM Application work. At thispoint, if you have not been doing so periodically anyway, you should save your changes to the project. You should also compile the program and make sure there are no compiler errors.
Note: If you are looking for good and high quality web space to host and run your application check Lunarwebhost Adult Web Hosting services
strPostalCode = InputBox( Please enter postal code, if known (ex: 46204) ) retrieve the coordinates for the starting and ending addressesGetCoordinates(dblLatitudeStart, dblLatitudeEnd, dblLongitudeStart, _ dblLongitudeEnd, strAddress, strCity, strRegion, strPostalCode) Dim strOutput As StringstrOutput = GetDrivingDirections(dblLatitudeStart, dblLatitudeEnd, _ dblLongitudeStart, dblLongitudeEnd) Dim frmresults As New frmMap display driving directions on other formfrmresults.lblTitle.Text = Driving directions from & strAddress & , & strCity & , & strRegion & , & strPostalCode & To & _ txtAddress1.Text & , & txtCity.Text & , & txtRegion.Text & _ , & txtPostalCode.Text show directions in text boxfrmresults.txtDirections.Text = strOutput make sure directions not selectedfrmresults.txtDirections.Select(0, 0) frmresults.picMap.Visible = False show the formfrmresults.Show() frmresults.TopMost = TrueExit Subhandleerror: MsgBox( An error occured in btnGetDirections_Click: & Err.Number & - & Err.Description) Exit SubEnd Sub32.Add the following GetCoordinatesprocedure to the form. This procedure uses the MapPointAPI to retrieve the coordinates of the starting and ending addresses to be used in the point-point directions. Again, replace YOURUSERIDand YOURPASSWORDwhere indicated with thosefor your MapPoint account. Sub GetCoordinates(ByRef dblLatitudeStart As Double, ByRef dblLatitudeEnd _ As Double, ByRef dblLongitudeStart As Double, ByRef dblLongitudeEnd _ As Double, ByVal strAddress As String, ByVal strCity As String, ByVal _ strRegion As String, ByVal strPostalCode As String) On Error GoTo handleerror Specify the credentials for the find service Use the customer id and password you were providedDim findService As New FindServiceSoapfindService.Credentials = New _ System.Net.NetworkCredential( YOUR USER ID , YOUR PASSWORD ) findService.PreAuthenticate = True set up the destination Address257Case
Note: If you are looking for good and high quality web space to host and run your application check Lunarwebhost Clan Web Hosting services
as a bitmap on the formDim streamImage As System.IO.StreamstreamImage = New System.IO.MemoryStream(mapImages(0).MimeData.Bits) Dim bitmapImage As BitmapbitmapImage = New Bitmap(streamImage) Dim frmResults As New frmMap show the map in a different formfrmResults.picMap.Image = bitmapImagefrmResults.txtDirections.Visible = FalsefrmResults.lblTitle.Text = txtCity.Text & , & txtRegion.TextfrmResults.Show() frmResults.TopMost = TrueExit Subhandleerror: MsgBox( An error occurred in btnGetMap_Click: & Err.Number & - & _ Err.Description) Exit SubEnd Sub31.Add the following btnDirections_Clickevent procedure to the form. This procedure runswhen the user clicks on the Get Directions button and uses the MapPoint API to retrieve point- to-point directions to the contact s location from a location specified by the user whenprompted. Private Sub btnGetDirections_Click(ByVal sender As System.Object, ByVal e As _ System.EventArgs) Handles btnGetDirections.Click NOTE: Make sure to include imports statement for MapPoint Web service for abbreviated declarations below to work Purpose: perform a Geocode lookup to lookup latitude and longitude based on a specified address, and then get point to point directions based on those coordinatesDim dblLatitudeStart As DoubleDim dblLongitudeStart As DoubleDim dblLatitudeEnd As DoubleDim dblLongitudeEnd As DoubleDim strAddress As StringDim strCity As StringDim strRegion As StringDim strPostalCode As String prompt the user to specify a starting addressstrAddress = InputBox( Please enter starting street address, if known (ex: 1 Monument Circle) ) strCity = InputBox( Please enter starting city (ex: Indianapolis) ) strRegion = InputBox( Please enter starting region (ex: IN) ) 256Chapter
Note: If you are looking for good and high quality web space to host and run your application check Lunarwebhost Clan Web Hosting services