public static ArmoryCharacterSheet getFreshCharacterSheet(string name, string server, string url, out XmlDocument rawSheet)
        {
            ArmoryCharacterSheet output = null;
            //Request the new character sheet xml
            XmlDocument sheet = RequestXml.RequestCharacterSheetXML(url);
            BaseStats baseStats = null;
            Spell spellData = null;
            int MaxHP;

            XmlNodeList xList, xList2;
            #region BaseStats
            xList = sheet.GetElementsByTagName("health");
            if (xList.Count > 0)
            {
                MaxHP = Convert.ToInt32(sheet.GetElementsByTagName("health")[0].Attributes["effective"].Value);
            }
            else MaxHP = 0;
            xList = sheet.GetElementsByTagName("baseStats");
            xList2 = sheet.GetElementsByTagName("secondBar");
            if (xList.Count > 0 && xList2.Count > 0)
            {
                baseStats = new BaseStats(xList[0], MaxHP, xList2[0]);
            }
            #endregion
            if (baseStats != null)
            {
                output = new ArmoryCharacterSheet(baseStats, name, server, url);
                //We got new data, so save it to the DB.
                SaveBaseStats(name, server, baseStats);
            }

            #region Spell data
            xList = sheet.GetElementsByTagName("spell");
            if (xList.Count > 0)
            {
                spellData = new Spell(xList[0]);
            }
            #endregion
            if (spellData != null)
            {
                SaveSpellData(name,server,spellData);
                if (output != null)
                    output.SetSpell(spellData);
            }

            //For their records
            rawSheet = sheet;
            return output;
        }
        public static void SaveSpellData(string name, string server, Spell spell)
        {
            if (spell == null) return;
            bool exists = false;

            checkSqlConnections();
            #region See if we already have a DB entry
            lock (cReaderLock)
            {
                using (SqlCommand cmd = cSqlReader.CreateCommand())
                {
                    cmd.Parameters.Add("@NAME", SqlDbType.VarChar, 512).Value = name;
                    cmd.Parameters.Add("@SERVER", SqlDbType.VarChar, 128).Value = server;

                    cmd.CommandText = "Select * From armory_CharacterSpell Where name = @NAME and server = @SERVER";

                    using (SqlDataReader rd = cmd.ExecuteReader())
                    {
                        if (rd.HasRows)
                            exists = true;
                    }
                }
            }
            #endregion
            #region Insert or update this record
            lock (cWriterLock)
            {
                using (SqlCommand cmd = cSqlWriter.CreateCommand())
                {
                    //Set our paramaters
                    #region Paramaters
                    cmd.Parameters.Add("@NAME", SqlDbType.VarChar, 512).Value = name;
                    cmd.Parameters.Add("@SERVER", SqlDbType.VarChar, 128).Value = server;
                    //Spell DMG
                    cmd.Parameters.Add("@ARD", SqlDbType.Int).Value = spell.arcane.dmg;
                    cmd.Parameters.Add("@FID", SqlDbType.Int).Value = spell.fire.dmg;
                    cmd.Parameters.Add("@FRD", SqlDbType.Int).Value = spell.frost.dmg;
                    cmd.Parameters.Add("@HOD", SqlDbType.Int).Value = spell.holy.dmg;
                    cmd.Parameters.Add("@NAD", SqlDbType.Int).Value = spell.nature.dmg;
                    cmd.Parameters.Add("@SHD", SqlDbType.Int).Value = spell.shadow.dmg;
                    //Healing
                    cmd.Parameters.Add("@HEAL", SqlDbType.Int).Value = spell.healing;
                    //hit
                    cmd.Parameters.Add("@HITP", SqlDbType.Float).Value = spell.stats.hitPct;
                    cmd.Parameters.Add("@HITR", SqlDbType.Int).Value = spell.stats.hitRating;
                    //Pen
                    cmd.Parameters.Add("@PEN", SqlDbType.Int).Value = spell.stats.penetration;
                    //-Resist
                    cmd.Parameters.Add("@RRES", SqlDbType.Int).Value = spell.stats.reducedResist;
                    //Crit
                    cmd.Parameters.Add("@ARC", SqlDbType.Float).Value = spell.arcane.crit;
                    cmd.Parameters.Add("@FIC", SqlDbType.Float).Value = spell.fire.crit;
                    cmd.Parameters.Add("@FRC", SqlDbType.Float).Value = spell.frost.crit;
                    cmd.Parameters.Add("@HOC", SqlDbType.Float).Value = spell.holy.crit;
                    cmd.Parameters.Add("@NAC", SqlDbType.Float).Value = spell.nature.crit;
                    cmd.Parameters.Add("@SHC", SqlDbType.Float).Value = spell.shadow.crit;
                    //Mana
                    cmd.Parameters.Add("@MANAC", SqlDbType.Float).Value = spell.stats.manaCasting;
                    cmd.Parameters.Add("@MANANC", SqlDbType.Float).Value = spell.stats.manaNotCasting;
                    //haste
                    cmd.Parameters.Add("@HASTEP", SqlDbType.Float).Value = spell.stats.haste;
                    cmd.Parameters.Add("@HASTER", SqlDbType.Int).Value = spell.stats.hasteRating;

                    #endregion
                    if (exists)
                    {
                        cmd.CommandText = "UPDATE armory_CharacterSpell  "
                            + "SET arcaneDmg = @ARD, fireDmg = @FID, frostDmg = @FRD, holyDmg = @HOD, natureDmg = @NAD, shadowDmg = @SHD, "
                            + "bonusHealing = @HEAL, hitPct = @HITP, penetration = @PEN, reducedResist = @RRES, hitRating = @HITR, "
                            + "arcaneCrit = @ARC, fireCrit = @FIC, frostCrit = @FRC, holyCrit = @HOC, natureCrit = @NAC, shadowCrit = @SHC, "
                            + "manaCasting = @MANAC, manaNotCasting = @MANANC, hastePct = @HASTEP, hasteRating = @HASTER, "
                            + "lastUpdate = getDate() "
                            + " WHERE name = @NAME and server = @SERVER";
                    }
                    else
                    {
                        cmd.CommandText = "INSERT INTO armory_CharacterSpell  "
                            + "(name, server, arcaneDmg, fireDmg, frostDmg, holyDmg, natureDmg, "
                            + "shadowDmg, bonusHealing, hitPct, penetration, reducedResist, "
                            + "hitRating, arcaneCrit, fireCrit, frostCrit, "
                            + "holyCrit, natureCrit, shadowCrit, manaCasting, manaNotCasting, "
                            + "hastePct, hasteRating, lastUpdate) "
                            + "VALUES (@NAME, @SERVER, @ARD, @FID, @FRD, @HOD, @NAD, "
                            + "@SHD, @HEAL, @HITP, @PEN, @RRES, "
                            + "@HITR, @ARC, @FIC, @FRC, "
                            + "@HOC, @NAC, @SHC, @MANAC, @MANANC, "
                            + "@HASTEP, @HASTER, getDate())";
                    }

                    //try
                    //{
                    cmd.ExecuteNonQuery();
                    //}//If there is some error inserting this in to the DB d/w about it
                    //catch { }

                    //Delete this record from the request queue if it exists
                    PurgeRequestQueue(ReqType.CHARACTER_SHEET, "r=" + server + "&cn=" + name);
                }
            }
            #endregion
        }
 public void SetSpell(Spell spell)
 {
     this.spell = spell;
 }