Sub ButtonSaveEventHandler_Click
Dim dataSavedOk As Boolean
TabHostPeople.CurrentTab = 0 ' Go to tab page 1.
' Perform validation first.
'--------------------------
If EditTextFirstName.Text = "" Then
ToastMessageShow("Please enter the first name.", True)
EditTextFirstName.RequestFocus
Else
' Set up variable used prior to a Geocoding attempt.
'---------------------------------------------------
blnAddressGeocodedOk = False
blnParserCalledForThisStreet = False
strStreetNameToGeocode = EditTextAddressStreetName.Text
strStreetNameFromTheInternet = ""
' Try to Geocode the address.
'----------------------------
ReverseGeocodeAddress (EditTextAddressStreetName.Text, _
EditTextCity.Text, _
EditTextState.Text, _
EditTextZip.Text)
' If the Geocoding is successful, use the street name found from Geocoding.
'--------------------------------------------------------------------------
If strStreetNameFromTheInternet <> "" Then
EditTextAddressStreetName.Text = strStreetNameFromTheInternet
ToastMessageShow(strStreetNameFromTheInternet,True)
End If
' Insert or Edit the data into the database.
'-------------------------------------------
If tableMode = "New" Then
' It's in New mode so insert the data.
'-------------------------------------
' Put in a default date if the user missed it.
'---------------------------------------------
If EditTextDateOfLastVisit.Text = "" Then
EditTextDateOfLastVisit.Text = DateTime.Date(DateTime.Now)
End If
SQL.ExecNonQuery2("INSERT INTO PeopleToVisit " & _
"(Id, FirstName, LastName, AddressHouseNumber, AddressStreetName, City, State, Zip, DateOfLastVisit, " & _
"PrimaryPhone, SecondaryPhone, Email, LastVisitNote) " & _
"VALUES " & _
"(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", _
Array As Object(Null, _
EditTextFirstName.Text, _
EditTextLastName.Text, _
EditTextAddressHouseNumber.Text, _
EditTextAddressStreetName.Text, _
EditTextCity.Text, _
EditTextState.Text, _
EditTextZip.Text, _
EditTextDateOfLastVisit.Text, _
EditTextPrimaryPhone.Text, _
EditTextSecondaryPhone.Text, _
EditTextEmail.Text, _
EditTextLastVisitNote.Text _
))
ToastMessageShow(EditTextFirstName.Text & " has been ADDED to the database.", True)
ClearDetails
Else
' It's in Edit mode so just update the data.
'-------------------------------------------
SQL.ExecNonQuery2("UPDATE PeopleToVisit " & _
"SET FirstName = ?, " & _
"LastName = ?, " & _
"AddressHouseNumber = ?, " & _
"AddressStreetName = ?, " & _
"City = ?, " & _
"State = ?, " & _
"Zip = ?, " & _
"DateOfLastVisit = ?, " & _
"PrimaryPhone = ?, " & _
"SecondaryPhone = ?, " & _
"Email = ?, " & _
"LastVisitNote = ? " & _
"WHERE Id = ?", Array As Object(EditTextFirstName.Text, _
EditTextLastName.Text, _
EditTextAddressHouseNumber.Text, _
EditTextAddressStreetName.Text, _
EditTextCity.Text, _
EditTextState.Text, _
EditTextZip.Text, _
EditTextDateOfLastVisit.Text, _
EditTextPrimaryPhone.Text, _
EditTextSecondaryPhone.Text, _
EditTextEmail.Text, _
EditTextLastVisitNote.Text, _
intCurrentId))
ToastMessageShow(EditTextFirstName.Text & " has been MODIFIED in the database.", True)
Activity.Title = "Maintenance - People To Visit *** EDIT *** " & _
EditTextLastName.Text.Trim & ", " & EditTextFirstName.Text
End If
End If
PopulateTheListView
End Sub
Sub ReverseGeocodeAddress (AddressStreetName As String, _
City As String, _
State As String, _
Zip As String)
strUrlToCall = "http://where.yahooapis.com/geocode?q=" & _
AddressStreetName & " " & _
City & " " & _
State & " " & _
Zip & " "
strUrlToCall = strUrlToCall.Replace(" ", "%20")
HttpUtils.CallbackActivity = "People" 'Current activity name.
HttpUtils.CallbackJobDoneSub = "JobDone"
HttpUtils.Download("ReverseGeocode", strUrlToCall)
End Sub
Sub JobDone (Job As String)
Dim strStringFromWebSite As String
Dim in As InputStream
' Proceed when the internet site with the XML was found.
'-------------------------------------------------------
If HttpUtils.IsSuccess(strUrlToCall) Then
' Parse the input stream from the web site.
'------------------------------------------
in = HttpUtils.GetInputStream(strUrlToCall)
XmlParser.Parse(in, "XmlParser")
in.Close
Else
ToastMessageShow("PLEASE MAKE SURE YOU HAVE AN INTERNET CONNECTION.", True)
End If
End Sub
Sub XmlParser_EndElement (Uri As String, Name As String, Text As StringBuilder)
' Grab the latitude and longitude from the XML.
'----------------------------------------------
If Name = "latitude" Then
fltLatitude = Text.ToString
Else If Name = "longitude" Then
fltLongitude = Text.ToString
Else If Name = "street" Then
' Only allow 1 street per address to be parsed.
'----------------------------------------------
If blnParserCalledForThisStreet = False Then
blnParserCalledForThisStreet = True
If Text.ToString <> "" Then
fltGeocode = fltLatitude + fltLongitude
strStreetNameFromTheInternet = Text.ToString
ToastMessageShow("This address has been GEOCODED as " & fltGeocode, True)
blnAddressGeocodedOk = True ' Confirms address was found.
Else
Msgbox("Sorry, I can't geocode this address. " & CRLF & CRLF & _
"Please correct the address.", _
"GEOCODING ERROR")
blnAddressGeocodedOk = False ' Exact match not found.
End If
End If
Else If Name = "Error" Then
If Text.ToString <> "0" Then
ToastMessageShow("CAN'T GEOCODE. PLEASE CORRECT ADDRESS.", True)
End If
End If
End Sub