vb.net call to google api using Eircode to get full address - vb.net

I am trying to get the full address from an Irish Eircode, using the Google Geocoding API and VB.NET. I am getting the results back but the address is missing street level, not sure why?
Here is my code... I think Google can't provide the full address, is there any other way?
Private Async Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim address = ""
Try
'***** Check Eircode First ******
If Me.tbEircode.Text = "" Then
MessageBox.Show("No Eircode, please correct")
Exit Sub
End If
MessageBox.Show(Me.tbEircode.Text & " Eircode sent to Google Maps")
'*************** Get them in order with | and destination address
Dim OrgAddress As String = ""
OrgAddress = Me.tbEircode.Text
address = "https://maps.googleapis.com/maps/api/geocode/json?components=postal_code:F*****|country:IE&key=***************"
MsgBox(address)
Using client As New Net.Http.HttpClient(), result = Await client.GetAsync(address)
If result.IsSuccessStatusCode Then
Dim content = Await result.Content.ReadAsStringAsync
Dim response = Newtonsoft.Json.JsonConvert.DeserializeObject(Of Response)(content)
Me.tbAddress1.Text = response.status
Me.tbAddress2.Text = response.formatted_address.ToString
Else
Me.tbAddress1.Text = "error downloading"
End If
End Using
Catch ex As Exception
MessageBox.Show(ex.Message, "Google Distance Calculator")
End Try

Related

having a problem in autosearch of textbox in vb.net

Iam using autosearch in textbox from database its working good its searching and all the places also changing with the change in that box but problem is that i have a auto generate id box if my autosearch textbox founds nothing then the auto id box should come to its defahult value
Private Sub txtvendorname_frmvdt_TextChanged(sender As Object, e As EventArgs) Handles txtvendorname_frmvdt.TextChanged
Try
conn95.Open()
qryvi = "select * from tblvendorinfo where Vendorname='" & txtvendorname_frmvdt.Text & "'"
cmdcu = New SqlCommand(qryvi, conn95)
cmdcu.ExecuteNonQuery()
drvi = cmdcu.ExecuteReader
If drvi.Read Then
txtvendorid_frmvdt.Text = drvi("Vendorid")
txtvendoraddress_frmvdt.Text = drvi("Vendoraddress")
txtvendorstate_frmvdt.Text = drvi("Vendorstate")
txtvendorgst_frmvdt.Text = drvi("Vendorgstno")
Else
'txtvendorid_frmvdt.Text = drvi("Vendorid")
txtvendoraddress_frmvdt.Text = ""
txtvendorstate_frmvdt.Text = ""
txtvendorgst_frmvdt.Text = ""
End If
conn95.Close()
Loadvendorid1()
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub

How to get the ID from table database into link using vb.net?

I have a system where when user click button submit it will insert the data into the table database and also send an email to the user. My problem is I want to put a link into the email.Body so that the user can click the link to the Approval page. But when I click the link it says the sites can't be reached and the id=0. Every Functions work well, I just have a problem with the link.
Here is my sendMessage() code :
Private Sub SendMessage()
Dim mail As MailMessage = New MailMessage
mail.From = New MailAddress("notice#example.com")
mail.To.Add(New MailAddress("user1#example.com"))
mail.Subject = "Test Approval"
Dim link As String
Dim intID As Integer
link = "Click here"
mail.Body = "<br/><br/>Employee No : " & lblEmpNO.Text.Trim(Environment.NewLine, "<br />") & "<br/><br/>Employee Name : " & lblemployeename.Text.Trim & link
mail.IsBodyHtml = True
Dim client As New SmtpClient()
client.EnableSsl = True
Try
client.Send(mail)
'MsgBox("Sending Email succeeded")
Catch ex As Exception
'MsgBox("Sending Email failed. Please try again")
End Try
End Sub
Here is LoadEmployeeDetailsById(intID) :
Private Function LoadEmployeeDetailsById(ByVal intid As Integer) As String
Using GetdutyDetails As New clsExternalWorkDuty_func
Dim dt As New DataTable
Dim result As String = ""
dt = GetdutyDetails.GetAllDataTableExternalWorkdutyDetailsByID(intid) 'Call the Function from AppCode
If dt.Rows.Count > 0 Then
pnlApproval.Visible = True
End If
Return result
End Using
End Function
Here is btnSubmit() :
Protected Sub btnSubmit_Click(sender As Object, e As EventArgs) Handles btnSubmit.Click
If InsertData(lblhdddnuserid.Text, lblhddnEmployeedeptid.Text) = 1 Then
DisplayMessage("success", "Done", "Data succesfully inserted!")
SendMessage()
LoadEmployeeByuserid(Membership.GetUser.ProviderUserKey)
End If
End Sub
Your SQL must be modified to return a scalar value of the Id. If the ID is an IDENTITY column then you can call SELECT SCOPE_IDENTIY() at the end of your statement. Or you can use the OUTPUT directive, as below:
INSERT INTO [YourTable] ([Field1], [Field2], [Field3])
OUTPUT INSERTED.ID VALUES (#Value1, #Value2, #Value3)
The adjust your InsertData function to return an object as the result
Public Class InsertDataResult
Public Property Success As Boolean
Public Property InsertedId As Integer
End Class

Process.Start() with "manage-bde.exe" crashing in VB.NET

I'm trying to start manage-bde.exe as a new process in VB.net but when it tries to start the proc, Bitlocker crashes. Could anyone please tell me what I'm doing wrong here? This code was converted from C# where it works all day long....
Code:
Private Sub btnLock_Click(sender As Object, e As EventArgs) Handles btnLock.Click
Dim drvSelected As String = cmbDriveSelect.SelectedValue.ToString()
Dim sysDirWithBDE As String = Environment.SystemDirectory + "\manage-bde.exe"
Dim lockStatus As String = String.Empty
' This is the code for the base process
Dim myProcess As New Process()
' Start a new instance of this program
Dim myProcessStartInfo As New ProcessStartInfo(sysDirWithBDE, " -lock " + drvSelected.Remove(2))
'Set Use Shell to false so as to redirect process run info to application
myProcessStartInfo.UseShellExecute = False
myProcessStartInfo.RedirectStandardOutput = True
myProcess.StartInfo = myProcessStartInfo
Try
myProcess.Start()
lblDriveLockMsg.Show()
Catch err As Exception
lblDriveLockMsg.Text = err.Message
End Try
'Read the standard output of the process.
lockStatus = myProcess.StandardOutput.ReadToEnd()
If lockStatus.Contains("code 0x80070057") Then
lblDriveLockMsg.Text = "Drive selected is not Bit Locker encrypted"
ElseIf lockStatus.Contains("code 0x80070005") Then
lblDriveLockMsg.Text = "Drive selected is in use by an application on your machine, force dismounting might result in data loss, please check and close any applications using the drive"
Else
lblDriveLockMsg.Text = lockStatus
End If
myProcess.WaitForExit()
myProcess.Close()
End Sub

Query in VB.net sometimes doesn't work

I have a functionality which saves the information from a webform to the database, which is working fine.
This is my code for save functionality in Onspec.aspx.vb page
Public Sub SaveClick(ByVal sender As Object, ByVal e As System.EventArgs)
If Not Page.IsValid Then
litMessage.Text = ""
Exit Sub
End If
Try
Dim sName As String = ""
With EmployerCandidate
.employerid = Master.Employer.ID
.employeruserid = 0
Try
.CVID = DocId
Catch
End Try
.Name = uxName.Text
.SurName = uxSurname.Text
Try
.PostCode = uxPostcode.Text
Catch ex As Exception
End Try
.Email = uxEmail.Text
Try
.MobileNo = uxMobileNo.Text
Catch ex As Exception
End Try
.OnSpec = True
.OnSpecType = uxOnSpecCategory.SelectedItem.Text
.Source = uxSourceID.SelectedItem.Text
.LastEmployer = uxEmployer.Text
.LastJobTitle = uxJobtitle.Text
.Profile = uxProfile.Text.Trim
End With
' email()
ResetForm()
panForm.Visible = False
panUpload.Visible = True
uxSubmit.Visible = False
uxUpload.Visible = True
litMessage.Text = "Thank you for submitting your details! We'll be in touch when appropriate vacancy arises. <a href='#' onclick='parent.$.colorbox.close()'>Close</a>"
UploadPanel.Visible = False
Response.Redirect("onspec-complete.aspx?e=" & Master.Employer.ID)
Catch ex As Exception
litMessage.Text = Core.Helper.FancyMessage("Error as occurred - " & ex.Message.ToString, "ERROR")
End Try
End Sub
Now, I want to send emails along with saving the data in the database so I added the following lines of code before ResetForm().
Dim specmatch As DataRow = DB.GetRow("SELECT TOP 1 name,email,password FROM [user] usr JOIN employeruser empUsr ON usr.id = empUsr.userid WHERE empUsr.empusertype = 1 AND empUsr.employerid = #eid ", DB.SIP("eid", LocalHelper.UserEmployerID))
If my query returns a value then I want to send email by calling the email function.
If specmatch IsNot Nothing Then
email()
End If
But in this line of code the employerid value is sometimes empty. It can't pick the id therefore it is returning an empty row. And therefore it's not calling the email function.
This id is the same as
.employerid = Master.Employer.ID
But if I replace the LocalHelper.UserEmployerID with Master.Employer.ID the form gives an error:
Object reference not set to an instance of an object.
employerid is an integer value.
I have also tried to add the following lines of code in this page(Onspec.aspx.vb)
Public ReadOnly Property EmployerId() As Integer
Get
Return Master.Employer.ID
End Get
End Property
But I get the same error:
Object reference not set to an instance of an object.
The above lines of code does not make any difference.
So I replaced Master.Employer.ID with LocalHelper.UserEmployerID
Where in localhelper.vb file (under appcode folder) it is determining employerid from the website with following lines of code.
Public Shared Function UserEmployerID() As Integer
If HttpContext.Current.Items("lh_useremployerid") Is Nothing Then
If LocalHelper.UserTypeCode = "e" Then
HttpContext.Current.Items("lh_useremployerid") = Core.DB.GetInteger("SELECT employerid FROM employeruser WHERE userid = " & LocalHelper.UserID)
Else
HttpContext.Current.Items("lh_useremployerid") = 0
End If
End If
Return HttpContext.Current.Items("lh_useremployerid")
End Function
These lines of code has been used in many places and works perfectly fine. In this case as well, it was working fine last Friday and now it's not. There was no changes made.
This is my email function
Private Sub email()
Dim strCandidateName As String = uxName.Text.Trim & " " & uxSurname.Text.Trim
Dim strCandidateSurname As String = uxSurname.Text
Dim strCandidateEmail As String = uxEmail.Text.Trim
Dim strCandidatePhone As String = uxMobileNo.Text.Trim
Dim strCPass As String = "mpb123"
Dim strContactType As String = "Speculative Application has been submited on the category of " & uxOnSpecCategory.SelectedItem.Text
Dim strContactMessage As String = uxProfile.Text.Trim
'''''''''''''''''''variable
Dim qq As String = String.Format("Select top 1 name, email, password FROM [user] WHERE id in (Select userid FROM employeruser WHERE empusertype=1 and employerid= " & LocalHelper.UserEmployerID & ")")
Dim drow As DataRow = Core.DB.GetRow(qq)
Dim semail As String = drow.Item("email").ToString
Dim sname As String = drow.Item("name").ToString
Dim spass As String = drow.Item("password").ToString
'''''''''''''''''''variable
Dim Email As Core.Email
'New Onspec Candidate Email sent to EmployerUser who is assigned to receive onspec email
Email = New Core.Email
With Email
.ContentID = 99
.Replacement("ContactName", strCandidateName)
.Replacement("ContactEmail", strCandidateEmail)
.Replacement("ContactTelephone", strCandidatePhone)
.Replacement("ContactType", strContactType)
.Replacement("ContactMessage", strContactMessage)
.Replacement("AdminContactName", sname)
.Replacement("AdminContactEmail", semail)
.Replacement("SiteName", LocalHelper.AppSetting("sitename"))
Dim attachments As New Generic.List(Of String)
If EmployerCandidate.CVID > 0 Then
Dim doc As New Document(EmployerCandidate.CVID)
attachments.Add(doc.PathOnDisc)
End If
.Attachments = Join(attachments.ToArray(), ";")
.Send()
End With
End Sub
GetRow function is defined in my database.vb page like following which is also used in many other places.
Shared Function GetRow(ByVal selectQueryText As String, ByVal ParamArray params As SqlParameter()) As DataRow
Return GetRowFromDB(selectQueryText, CommandType.Text, params)
End Function
And
Shared Function GetRowFromDB(ByVal selectCommandText As String, ByVal selectCommandType As CommandType, ByVal ParamArray params As SqlParameter()) As DataRow
Dim conn As SqlConnection = Nothing
Try
conn = GetOpenSqlConnection()
Return GetRowFromDB(conn, selectCommandText, selectCommandType, params)
Finally
If conn IsNot Nothing Then conn.Dispose()
End Try
End Function
Please suggest ways on how I can organize my code so that it works all the time.

Custom search from textbox switch/parameter

I think I am over engineering this a bit. Any assistance is greatly appreciated on how I can fix this little problem. I have an app that searches multiple sites. But if a user types a custom parameter of g=, then it will search google. The problem is I have right now is it strips the G from the first word of my search term. For example, If I type g=golf game, google pops up with olf game. With the other searches, the = character is getting stripped. Should I use contains instead of this custom firstChars function?
Here is my code:
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
If TextBox1.Text = "" Then
MsgBox("Enter text to search on." & vbCrLf & Err.Description, MsgBoxStyle.Information, "Need search term to search on.")
TextBox1.Focus()
End If
Try
'CHECK FOR GOOGLE.COM SEARCHING
Dim MyString As String = TextBox1.Text
Dim MyChar() As Char = {"g", "G", "="}
Dim NewString As String = MyString.TrimStart(MyChar)
Dim myUri As New Uri("http://google.com/search?hl=en&q=" & NewString)
Dim first2Chars As String
Dim first3Chars As String
Dim first4Chars As String
first2Chars = TextBox1.Text.Substring(0, 2)
first3Chars = TextBox1.Text.Substring(0, 3)
first4Chars = TextBox1.Text.Substring(0, 4)
MsgBox(first2Chars)
If first2Chars = "G=" Or first2Chars = "g=" Then
System.Diagnostics.Process.Start(myUri.AbsoluteUri)
ElseIf first3Chars = "TS=" Or first3Chars = "ts=" Then
System.Diagnostics.Process.Start("https://localhost/search.do?query=" & Net.WebUtility.UrlEncode(TextBox1.Text))
ElseIf first4Chars = "PIC=" Or first4Chars = "pic=" Then
System.Diagnostics.Process.Start("https://localhost/search.do?query_pic=" & Net.WebUtility.UrlEncode(TextBox1.Text))
End If
Catch ex As Exception
MsgBox("Error running search. The error was: " & vbCrLf & Err.Description, MsgBoxStyle.Exclamation, "Error")
End Try
End Sub