Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 9th, 2012  |  syntax: C#  |  size: 4.05 KB  |  hits: 13  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. using System;
  2. using System.Data;
  3. using System.Drawing;
  4. using System.IO;
  5. using System.Net;
  6. using System.Text;
  7. using System.Windows.Forms;
  8. using MySql.Data.MySqlClient;
  9.  
  10. namespace WindowsFormsApplication5
  11. {
  12.     public partial class Form1 : Form
  13.     {
  14.         Hero[,] heroes = new Hero[5,4];
  15.         public Form1()
  16.         {
  17.             InitializeComponent();
  18.             InitializeHeroGrid();
  19.         }
  20.         private void InitializeHeroGrid()
  21.         {
  22.             for (int i = 0; i <= 4; i++)
  23.             {
  24.                 for (int k = 0; k < 3; k++)
  25.                 {
  26.                     heroes[i,k] = new Hero(2);
  27.                     heroes[i,k].Location = new Point(i * 81, k * 46);
  28.                     heroes[i, k].Click += new EventHandler(heroes[i, k].HeroClick);
  29.                     Controls.Add(heroes[i,k]);
  30.  
  31.                 }
  32.             }
  33.         }
  34.  
  35.         public class NetWRKN
  36.         {
  37.             IDbConnection conn;
  38.             IDbCommand cmd;
  39.             IDataReader reader;
  40.             public NetWRKN()
  41.             {
  42.                 conn = new MySqlConnection("Server=10.40.4.250; " + "user=samuel; password=6195");
  43.                 conn.Open();
  44.                 cmd = conn.CreateCommand();
  45.                 cmd.CommandText = "use samuel";
  46.                 cmd.ExecuteNonQuery();
  47.             }
  48.             public String getData(String what, int heroID, int spellNR)
  49.             {
  50.                 String data = "";
  51.                 if (spellNR == 0)
  52.                 {
  53.                     cmd.CommandText = "SELECT " + what + " FROM Hjaltar where hID=" + heroID;
  54.                     reader = cmd.ExecuteReader();
  55.                     reader.Read();
  56.                     data = reader.GetString(0);
  57.                     reader.Close();
  58.                 }
  59.                 else
  60.                 {
  61.                     cmd.CommandText = "SELECT " + what + " FROM Formagor where hID=" + heroID + " and aID=" + spellNR;
  62.                     reader = cmd.ExecuteReader();
  63.                     reader.Read();
  64.                     data = reader.GetString(0);
  65.                     reader.Close();
  66.                 }
  67.                 return data;
  68.             }
  69.             public Image fetchImage(String URI)
  70.             {
  71.                 WebRequest requestPic = WebRequest.Create("http://i.imgur.com/" + URI + ".jpg");
  72.                 requestPic.Proxy = null;
  73.                 WebResponse responsePic = requestPic.GetResponse();
  74.                 return Image.FromStream(responsePic.GetResponseStream());
  75.             }
  76.         }
  77.         public class Hero : PictureBox
  78.         {
  79.             Spell[] spells;
  80.             int[] natstatestik;
  81.             String name;
  82.             String attr;
  83.             ToolTip popup;
  84.             public Hero(int heroID)
  85.             {
  86.                 NetWRKN connection = new NetWRKN();
  87.                 name = connection.getData("namn", heroID, 0);
  88.                 attr = connection.getData("attribut", heroID, 0);
  89.                 this.Image = connection.fetchImage(connection.getData("ikon", heroID, 0));
  90.                 spells = new Spell[4];
  91.                 for (int i = 0; i <= 3; i++)
  92.                 {
  93.                     spells[i] = new Spell(heroID, i + 1);
  94.  
  95.                 }
  96.  
  97.                 this.Size = new Size(80, 45);
  98.             }
  99.             public void HeroClick(object sender, EventArgs e)
  100.             {
  101.                 ToggleTooltip();
  102.             }
  103.             public void ToggleTooltip()
  104.             {
  105.                 new ToolTip(
  106.             }
  107.         }
  108.  
  109.         public class Spell : PictureBox
  110.         {
  111.             String name;
  112.             String desc;
  113.             public Spell(int heroID, int spellNR)
  114.             {
  115.                 NetWRKN connection = new NetWRKN();
  116.                 name = connection.getData("namn", heroID, spellNR);
  117.                 desc = connection.getData("descr", heroID, spellNR);
  118.                 this.Image = connection.fetchImage(connection.getData("ikon", heroID, spellNR));
  119.                 this.Size = new Size(32, 32);
  120.             }
  121.         }
  122.     }
  123. }