Hi :) I'm making a simple alt client for a game, I'm almost done and most of what I've done has been within my ability. However I need to add an item price lookup. How can I link this to a GUI, I want the price to appear in a textbox. Thanks so much in advance.
<pre>using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.Windows.Forms;
using System.Text.RegularExpressions;
namespace GELookup
{
public class GELookup
{
private ArrayList id;
private ArrayList name;
public List<string> Result;
public GELookup(string Item, bool MultiPage, int Page)
{
try
{
Result = new List<string>();
id = new ArrayList();
name = new ArrayList();
string strPage = GetFile("http://itemdb-rs.runescape.com/results.ws?query=" + Item + "&sup=All&cat=All&sub=All&page=" + Page + "&vis=1&order=1&sortby=name&price=all&members=");
string[] splitter = new string[] { "./viewitem.ws?obj=" };
string[] array;
array = strPage.Split(splitter, StringSplitOptions.None);
splitter = new string[] { "\"> " };
for (int i = 1; i < array.Length; i++)
{
id.Add(array[i].Split(splitter, StringSplitOptions.None)[0]);
name.Add(array[i].Split(splitter, StringSplitOptions.None)[1].Split(new string[] { "</a>" }, StringSplitOptions.None)[0]);
}
for (int i = 0; i < id.Count; i++)
{
Result.Add(name[i].ToString()); ;
}
if (MultiPage)
{
int Start = strPage.IndexOf("<td class=\"navmid\">\n1");
int Finish = strPage.IndexOf("</td>\n<td class=\"navright\">");
string Data = "blank";
if (Start > 0 && Finish > 0)
{
Data = strPage.Substring(Start);
Data = Data.Substring(0, Data.IndexOf("</td>\n"));
Data = Data.Substring(Data.LastIndexOf("bers=\">") + 7, 1);
string[] Data2 = Data.Split(new string[] { "\n<a href=\"./results.ws?query=" + Item + "&sup=All&cat=All&sub=All&page=2&vis=1&order=1&sortby=name&price=all&members=\">", "</a>", "<td>" }, StringSplitOptions.None);
List<object> _Results = new List<object>();
char[] number = Data.ToCharArray();
if (Char.IsNumber(number[0]))
{
int Count = Convert.ToInt32(Data);
for (int X = 2; X <= Count; X++)
{
_Results.Add(ParsePage(Item, X));
}
for (int i = 0; i < _Results.Count; i++)
{
Result.AddRange((List<string>)_Results[i]);
}
}
}
}
}
catch
{
MessageBox.Show("Error Code: 010.\r\nPlease post this Error Code in the Bug's\r\nSection of the forum.\r\nThank you.");
}
}
public GELookup()
{ }
private string GetFile(string strURL)
{
try
{
WebRequest myWebRequest = WebRequest.Create(strURL);
WebResponse myWebResponse = myWebRequest.GetResponse();
Stream ReceiveStream = myWebResponse.GetResponseStream();
Encoding encode = System.Text.Encoding.GetEncoding("utf-8");
StreamReader readStream = new StreamReader(ReceiveStream, encode);
string strResponse = readStream.ReadToEnd();
readStream.Close();
myWebResponse.Close();
return strResponse;
}
catch(Execption e)
{
MessageBox.Show(e.ToString());
return null;
}
}
private List<string> ParsePage(string Item, int Page)
{
try
{
ArrayList id1 = new ArrayList();
ArrayList name1 = new ArrayList();
List<string> Result1 = new List<string>();
string strPage = GetFile("http://itemdb-rs.runescape.com/results.ws?query=" + Item + "&sup=All&cat=All&sub=All&page=" + Page + "&vis=1&order=1&sortby=name&price=all&members=");
string[] splitter = new string[] { "./viewitem.ws?obj=" };
string[] array;
array = strPage.Split(splitter, StringSplitOptions.None);
splitter = new string[] { "\"> " };
for (int i = 1; i < array.Length; i++)
{
id.Add(array[i].Split(splitter, StringSplitOptions.None)[0]);
name1.Add(array[i].Split(splitter, StringSplitOptions.None)[1].Split(new string[] { "</a>" }, StringSplitOptions.None)[0]);
}
for (int i = 0; i < name1.Count; i++)
{
Result1.Add(name1[i].ToString()); ;
}
return Result1;
}
catch(Execption e)
{
MessageBox.Show(e.ToString());
return null;
}
}
public string[] GetPrice(int ItemIndex)
{
try
{
string[] ReturnPrices = new string[6];
int index = ItemIndex;
string[] price = new string[3];
string[] array;
string[] splitter = new string[] { "price: " };
if (index != -1)
{
string page = GetFile("http://itemdb-rs.runescape.com/viewitem.ws?obj=" + id[index]);
array = page.Split(splitter, StringSplitOptions.None);
splitter = new string[] { "</span>" };
for (int i = 0; i < 3; i++)
{
price[i] = array[i + 1].Split(splitter, StringSplitOptions.None)[0];
}
Regex Regex = new Regex("\\d{4}_obj_big.gif?");
Match match = Regex.Match(page);
string matchResult = match.Value;
string DynamicId = matchResult.Remove(4);
ReturnPrices[0] = "Name: " + Result[index];
ReturnPrices[1] = "ID: " + id[index];
ReturnPrices[2] = "Minimum Price: " + price[0];
ReturnPrices[3] = "Market Price: " + price[1];
ReturnPrices[4] = "Maximum Price: " + price[2];
ReturnPrices[5] = GetImage(Convert.ToString(id[index]), DynamicId);
}
return ReturnPrices;
}
catch(Execption e)
{
MessageBox.Show(e.ToString());
return null;
}
}
private string GetImage(string ItemID,string imageDynId)
{
try
{
DirectoryInfo Folder = new DirectoryInfo(Directory.GetCurrentDirectory() + @"\GeImages\");
if (!Folder.Exists)
{
Folder.Create();
}
if (!File.Exists(Directory.GetCurrentDirectory() + @"\GeImages\" + ItemID + ".gif"))
{
WebClient objClient = new WebClient();
objClient.DownloadFile(@"http://itemdb-rs.runescape.com/" + imageDynId + "_obj_big.gif?id=" + ItemID, Directory.GetCurrentDirectory() + @"\GeImages\" + ItemID + ".gif");
}
return Directory.GetCurrentDirectory() + @"\GeImages\" + ItemID + ".gif";
}
catch(Execption e)
{
MessageBox.Show(e.ToString());
return null;
}
}
public string[] GetGraph(string ItemID)
{
try
{
DirectoryInfo Folder = new DirectoryInfo(Directory.GetCurrentDirectory() + @"\GeImages\");
if (!Folder.Exists)
{
Folder.Create();
}
string page = GetFile("http://itemdb-rs.runescape.com/viewitem.ws?obj=" + ItemID);
Regex Regex = new Regex("\\d{4}_graphimg.gif?");
Match match = Regex.Match(page);
string matchResult = match.Value;
string graphDynId = matchResult.Remove(4);
Uri File1 = new Uri("http://itemdb-rs.runescape.com/" + graphDynId + "_scaleimg.gif?id=" + ItemID + "&scale=0&axis=0");
Uri File2 = new Uri("http://itemdb-rs.runescape.com/" + graphDynId + "_graphimg.gif?id=" + ItemID + "&scale=0");
Uri File3 = new Uri("http://itemdb-rs.runescape.com/" + graphDynId + "_scaleimg.gif?id=" + ItemID + "&scale=0&axis=2");
WebClient objClient = new WebClient();
objClient.DownloadFile(File1, Directory.GetCurrentDirectory() + @"\GeImages\" + ItemID + "Graph_Scale1.gif");
objClient.DownloadFile(File2, Directory.GetCurrentDirectory() + @"\GeImages\" + ItemID + "Graph_Graph.gif");
objClient.DownloadFile(File3, Directory.GetCurrentDirectory() + @"\GeImages\" + ItemID + "Graph_Scale2.gif");
return new string[3] {Directory.GetCurrentDirectory() + @"\GeImages\" + ItemID + "Graph_Scale1.gif", Directory.GetCurrentDirectory() + @"\GeImages\" + ItemID + "Graph_Graph.gif", Directory.GetCurrentDirectory() + @"\GeImages\" + ItemID + "Graph_Scale2.gif"};
}
catch(Exception e)
{
MessageBox.Show(e.ToString());
return null;
}
}
}
}
What I have tried:
I've spent the past 2 days searching for answers.