mark103
July 16th, 2008, 10:50 AM
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:
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
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:
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