using System;
using System.Data;
using System.Drawing;
using System.IO;
using System.Net;
using System.Text;
using System.Windows.Forms;
using MySql.Data.MySqlClient;
namespace WindowsFormsApplication5
{
public partial class Form1 : Form
{
Hero[,] heroes = new Hero[5,4];
public Form1()
{
InitializeComponent();
InitializeHeroGrid();
}
private void InitializeHeroGrid()
{
for (int i = 0; i <= 4; i++)
{
for (int k = 0; k < 3; k++)
{
heroes[i,k] = new Hero(2);
heroes[i,k].Location = new Point(i * 81, k * 46);
heroes[i, k].Click += new EventHandler(heroes[i, k].HeroClick);
Controls.Add(heroes[i,k]);
}
}
}
public class NetWRKN
{
IDbConnection conn;
IDbCommand cmd;
IDataReader reader;
public NetWRKN()
{
conn = new MySqlConnection("Server=10.40.4.250; " + "user=samuel; password=6195");
conn.Open();
cmd = conn.CreateCommand();
cmd.CommandText = "use samuel";
cmd.ExecuteNonQuery();
}
public String getData(String what, int heroID, int spellNR)
{
String data = "";
if (spellNR == 0)
{
cmd.CommandText = "SELECT " + what + " FROM Hjaltar where hID=" + heroID;
reader = cmd.ExecuteReader();
reader.Read();
data = reader.GetString(0);
reader.Close();
}
else
{
cmd.CommandText = "SELECT " + what + " FROM Formagor where hID=" + heroID + " and aID=" + spellNR;
reader = cmd.ExecuteReader();
reader.Read();
data = reader.GetString(0);
reader.Close();
}
return data;
}
public Image fetchImage(String URI)
{
WebRequest requestPic = WebRequest.Create("http://i.imgur.com/" + URI + ".jpg");
requestPic.Proxy = null;
WebResponse responsePic = requestPic.GetResponse();
return Image.FromStream(responsePic.GetResponseStream());
}
}
public class Hero : PictureBox
{
Spell[] spells;
int[] natstatestik;
String name;
String attr;
ToolTip popup;
public Hero(int heroID)
{
NetWRKN connection = new NetWRKN();
name = connection.getData("namn", heroID, 0);
attr = connection.getData("attribut", heroID, 0);
this.Image = connection.fetchImage(connection.getData("ikon", heroID, 0));
spells = new Spell[4];
for (int i = 0; i <= 3; i++)
{
spells[i] = new Spell(heroID, i + 1);
}
this.Size = new Size(80, 45);
}
public void HeroClick(object sender, EventArgs e)
{
ToggleTooltip();
}
public void ToggleTooltip()
{
new ToolTip(
}
}
public class Spell : PictureBox
{
String name;
String desc;
public Spell(int heroID, int spellNR)
{
NetWRKN connection = new NetWRKN();
name = connection.getData("namn", heroID, spellNR);
desc = connection.getData("descr", heroID, spellNR);
this.Image = connection.fetchImage(connection.getData("ikon", heroID, spellNR));
this.Size = new Size(32, 32);
}
}
}
}