Imports System.IO
Imports System.Net
Imports System.Drawing
Imports System.Drawing.Imaging
Public Class GrandExchangeForm
Private ItemName As String
Private ItemId As Integer
Private Description As String
Private Price As String
Public Sub New(ByVal ItemName As String, ByVal ItemId As String)
InitializeComponent()
lbl_ItemName.Text = ItemName
lbl_Description.Visible = False
Me.ItemName = ItemName
Me.ItemId = ItemId
bgw_Statistics.RunWorkerAsync()
End Sub
Private Sub GrandExchangeForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.Text = "RuneScape - GrandExchange - " & ItemName
End Sub
Private Function ParseWebsite() As Boolean
Dim URLStream As Stream = Nothing
Dim URLStreamReader As StreamReader = Nothing
Try
Dim Request As WebRequest = WebRequest.Create("http://services.runescape.com/m=itemdb_rs/viewitem.ws?obj=" & ItemId)
Dim Response As WebResponse = Request.GetResponse
URLStream = Response.GetResponseStream
URLStreamReader = New StreamReader(URLStream)
Dim Line As String = URLStreamReader.ReadLine
Dim Lines As String() = New String(3) {}
Do While (Not Line Is Nothing)
If Line.Contains("<meta name=""description"" content=""") Then
Line = Line.Replace("<meta name=""description"" content=""", "")
Line = Line.Replace(""">", "")
Description = Line
End If
If Line.Contains("<b>Current guide price:</b>") Then
Line = Line.Replace("<b>Current guide price:</b>", "")
Line = Line.Replace(" ", "")
Price = Line
End If
If Line.Contains("item_image") Then
Line = Line.Replace("<img id=""item_image"" src=""", "")
Line = Line.Replace(""" alt=""" & ItemName & """>", "")
pic_SnapShot.ImageLocation = Line
End If
If Line.Contains("item_graph_image") Then
URLStreamReader.ReadLine()
Lines(0) = URLStreamReader.ReadLine
Lines(1) = URLStreamReader.ReadLine
Lines(2) = URLStreamReader.ReadLine
Exit Do
End If
Line = URLStreamReader.ReadLine
Loop
If Not String.IsNullOrEmpty(Lines(0)) Then
Dim yAxis As String = Lines(0)
yAxis = yAxis.Replace("<td><img name=""object"" src=""", "")
yAxis = yAxis.Replace(""" alt=""""></td>", "")
yAxis = yAxis.Replace("&", "&")
pic_Axis1.ImageLocation = yAxis
Dim Graph As String = Lines(1)
Graph = Graph.Replace("<td><img src=""", "")
Graph = Graph.Replace(""" alt=""""></td>", "")
Graph = Graph.Replace("&", "&")
pic_Graph.ImageLocation = Graph
Dim xAxis As String = Lines(2)
xAxis = xAxis.Replace("<tr><td colspan=2><img src=""", "")
xAxis = xAxis.Replace(""" width=""499"" alt=""""></td>", "")
xAxis = xAxis.Replace("&", "&")
pic_Axis2.ImageLocation = xAxis
If URLStreamReader IsNot Nothing Then
URLStreamReader.Close()
End If
If URLStream IsNot Nothing Then
URLStream.Close()
End If
Return True
End If
Catch ex As Exception
Finally
If URLStreamReader IsNot Nothing Then
URLStreamReader.Close()
End If
If URLStream IsNot Nothing Then
URLStream.Close()
End If
End Try
Return False
End Function
Private Sub bgw_Statistics_DoWork(ByVal sender As System.Object, ByVal e As System.ComponentModel.DoWorkEventArgs) Handles bgw_Statistics.DoWork
If Not ParseWebsite() Then
e.Result = False
Else
e.Result = True
End If
End Sub
Private Sub bgw_Statistics_RunWorkerCompleted(ByVal sender As System.Object, ByVal e As System.ComponentModel.RunWorkerCompletedEventArgs) Handles bgw_Statistics.RunWorkerCompleted
lbl_PleaseWait.Visible = False
If e.Result = True Then
pic_Axis1.Visible = True
pic_Axis2.Visible = True
pic_Graph.Visible = True
pic_SnapShot.Visible = True
lbl_Description.Visible = True
lbl_Price.Visible = True
lbl_Price.Text = Price
lbl_Description.Text = Description
Else
lbl_Error.Visible = True
End If
End Sub
End Class