[RESOLVED] Fill the data row items on listview
Hi
I need help, I would like to fill the data row items on my listview when I connect to the right server name like germany and fill the right items that connected to the right germany server.
Here it the code:
Code:
Private Sub FindServer_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles FindServer.Click
If GetHTMLPage("http://www.whatismyip.com" & ProxyAddress.Text, chkUseProxy.Checked, ProxyAddress.Text, IIf(IsNumeric(ProxyPort.Text), ProxyPort.Text, 0), UserName.Text, Password.Text) Is "" Then
TextBox1.Text = TextBox1.Text
Else
TextBox1.Text = ProxyAddress.Text
End If
End Sub
Public Function GetExternalIP() As String
Dim IP_URL As String = "http://checkip.dyndns.org"
Dim strHTML, strIP As String
Try
Dim objWebReq As System.Net.WebRequest = System.Net.WebRequest.Create(IP_URL)
Dim objWebResp As System.Net.WebResponse = objWebReq.GetResponse()
Dim strmResp As System.IO.Stream = objWebResp.GetResponseStream()
Dim srResp As System.IO.StreamReader = New System.IO.StreamReader(strmResp, System.Text.Encoding.UTF8)
strHTML = srResp.ReadToEnd()
Dim regexIP As System.Text.RegularExpressions.Regex
regexIP = New System.Text.RegularExpressions.Regex("\b\d{1,3}.\d{1,3}.\d{1,3}.\d{1,3}\b")
strIP = regexIP.Match(strHTML).Value
Return strIP
Catch ex As Exception
MessageBox.Show("Can't retrieve external IP: " & ex.Message)
Return Nothing
End Try
End Function
Public Function GetHTMLPage(ByVal URL As String, Optional ByVal UseProxy As Boolean = False, Optional ByVal ProxyAddress As String = "", Optional ByVal ProxyPort As Integer = 0, Optional ByVal UserName As String = "", Optional ByVal PassWord As String = "", Optional ByVal Domain As String = "") As String
Dim sResult As String = ""
Try
Dim objResponse As WebResponse
Dim objRequest As WebRequest = System.Net.HttpWebRequest.Create(URL)
If UseProxy Then
Dim oProxy As New WebProxy(ProxyAddress, ProxyPort)
If Domain <> "" Then
oProxy.Credentials = New NetworkCredential(UserName, PassWord, Domain)
Else
oProxy.Credentials = New NetworkCredential(UserName, PassWord)
End If
objRequest.Proxy = oProxy
End If
objRequest.Method = "GET"
objRequest.Timeout = 120000 ' 20 sec.
objResponse = objRequest.GetResponse
Dim sr As System.IO.StreamReader = New System.IO.StreamReader(objResponse.GetResponseStream(), System.Text.Encoding.UTF7)
sResult = sr.ReadToEnd()
sr.Close()
' when code-execution has reached this point without
' throwing an error, the html page is loaded which
' means all is o.k.
MessageBox.Show("You are connected success")
Catch ex As System.Exception
Debug.WriteLine(ex.Message)
MessageBox.Show("You have failed connected")
End Try
Return sResult
End Function
Private Sub frmMain_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
TextBox1.Text = GetExternalIP()
If chkUseProxy.Checked = False Then
ProxyAddress.Enabled = True
ProxyPort.Enabled = True
ElseIf chkUseProxy.Checked = True Then
ProxyAddress.Enabled = False
ProxyPort.Enabled = False
End If
End Sub
Private Sub chkUseProxy_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chkUseProxy.CheckedChanged
If chkUseProxy.Checked = False Then
ProxyPort.Enabled = True
ProxyAddress.Enabled = True
ElseIf chkUseProxy.Checked = True Then
ProxyPort.Enabled = False
ProxyAddress.Enabled = False
End If
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
' Connect to the database and retreive the data required from Table1 into a datatable object.
Dim da As New System.Data.OleDb.OleDbDataAdapter( _
"SELECT Car, Images FROM Table1 ORDER BY Car DESC", _
"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\db1_test.mdb;Persist Security Info=False;")
Dim dt As New DataTable
da.Fill(dt)
' Place a new imagelist control onto your form designer window. The following
' will assign the listview to read from this control.
With ListView1
.LargeImageList = ImageList1
.SmallImageList = ImageList1
End With
Dim img As Image
Dim intImageIndex As Integer = 0
' Loop through each row in the database.
For Each row As DataRow In dt.Rows
' First off, check we have a record value within the Car column.
If Not String.IsNullOrEmpty(row.Item("Car")) Then
' If there is an image contained within the row, retreive this into a new image object.
' Next, add this image into the imagelist control & output the car name and image to the
' listview as a newlist item. This last call references the image by index number, which
' is kept track of in the intImageIndex variable - incremented upon each loop iteration.
If Not (row.Item("Images") Is Nothing) Then
img = Image.FromStream(New IO.MemoryStream(DirectCast(row.Item("Images"), Byte())))
ImageList1.Images.Add(row.Item("Car").ToString, img)
ListView1.Items.Add(row.Item("Car").ToString, intImageIndex)
Else
' If we arrived at this point, we have a car record entry, but no image. Therefore
' we will just output the info we do have into a new listview listitem.
ListView1.Items.Add(row.Item("Car").ToString)
End If
Else
' If we arrived here at this point in the code, then no record beneath the Car column
' exists for the row. Here we check if there's an image record and output that if
' existing in the same manner as above.
If Not (row.Item("Images") Is Nothing) Then
img = Image.FromStream(New IO.MemoryStream(DirectCast(row.Item("Images"), Byte())))
ImageList1.Images.Add("{NULL Value}", img)
ListView1.Items.Add("{NULL Value}", intImageIndex)
End If
End If
intImageIndex += 1
Next
If ListView1.Items.Count = 2 Then
Me.ListView1.Items.Clear()
End If
End Sub
When I click the button that connecting to the database, the program filled the data row items without connected to the server like germany. I need the items to be separate and some items to be filled only when I connected to the server like germany???
Hope you can help!
Thanks,
Mark
Re: Fill the data row items on listview
anyone???????????????????????
Re: Fill the data row items on listview
1) You're loading CARS from C:\db1_test.mdb, not online anywhere.
2) You have code for gethtml, but don't call it.
3) Read the info from the site that checked the ip for a location.
Re: Fill the data row items on listview
I WOULD PUT ONLINE IF I GET THIS DONE FIRST!!!!!!!!
You said I have code for gethtml but don't call it. I need it because I need to access to the proxy server but I don't know how I could checked the ip for a location with proxy on gethtml statement??
Quote:
Originally Posted by dglienna
1) You're loading CARS from C:\db1_test.mdb, not online anywhere.
2) You have code for gethtml, but don't call it.
3) Read the info from the site that checked the ip for a location.
Re: Fill the data row items on listview
Are you trying to create a server (that people can access from different locations in the world), or do you want to create a client?
If you makee a client, you know where you are.
If you use a proxy, you appear to be from wherever the proxy address is
Please explain...
Re: Fill the data row items on listview
No, I am trying to make a client by connecting to the proxy server and scan ip country mapping then displaying correct data information from my own database. I got IP-country mapping database but I cant find the source code to scan ip-country mapping for proxy and input the correct ip-country information from my own database??
Hope you can help!!!!!!
Thanks,
Mark
Re: Fill the data row items on listview
Do you have the ip country mappings in your database and the user's external ip address?
Is it the database query you need help with?
Re: Fill the data row items on listview
Yes I do, I have ip country mappings database but I did not put them in my own database. I don't think I have put my external ip address in the database??
I have dynamic ip address which it is impossible to retrieve ip-country from the database. And I need source code to scan ip-country mapping, I need to get them working with the external ip address and proxy server.
Thanks,
Mark
Re: Fill the data row items on listview
It's always going to be the address of the proxy that you are using, so is that what you want to select? The proxy address from the country code table?
Why don't you post the table that you have? That might be useful to others.
Re: Fill the data row items on listview
What do you expect me to do? I won't write the code for you, if that's what you expect. I'll look at it later anyways, but I don't expect a lot, other than code copied from somewhere that you don't even understand.
If that's the case, it means you didn't get any books, and still want others to do your work for you.
Re: Fill the data row items on listview
I would like you to check and fix the code. I want to scan the country code on IPCountry database and read my database then fill the data from my database when the server retrieve as country code from IPCountry database.
It should do with Private Sub Button1_Click and Public Function GetCountyFromIP statement, it might work together but I am not sure which one is the proper way of doing in the right way....
Hope you can help!!!!!!!!!!
Thanks,
Mark