public static void ExecuteKit(Kit kit, string username, string admin) { try { foreach (KitItem item in kit.Items) { if (String.IsNullOrEmpty(username)) { ExecuteGive(item.Id, item.Amount.ToString(), admin); } else { ExecuteGive(item.Id, item.Amount.ToString(), username); } } } catch (Exception ex) { Console.WriteLine(ex); } }
//public static Kit GetKitFromName(String file, String filter) //{ // try // { // Kit kit = new Kit(); // XmlDocument doc = new XmlDocument(); // doc.Load(file); // XmlNode root = doc["root"]; // XmlNode kits = root["kits"]; // foreach (XmlNode n in kits) // { // int level = 0; // string name = null; // bool fixedGroup = false; // try // { // name = n.Attributes["name"].Value; // } // catch{ } // try // { // string value = n.Attributes["level"].Value; // level = Convert.ToInt32(value); // } // catch { } // try // { // fixedGroup = Convert.ToBoolean(n.Attributes["fixedgroup"].Value); // } // catch { } // if (String.IsNullOrEmpty(name) || filter != name) // continue; // kit.Name = name; // kit.Level = level; // kit.FixedGroup = fixedGroup; // foreach (XmlNode i in n) // { // string id = null; // int amount = 1; // try // { // id = i.Attributes["id"].Value; // } // catch // { // continue; // } // try // { // amount = int.Parse(i.Attributes["amount"].Value); // } // catch // { // } // KitItem item = new KitItem(id, amount); // kit.Items.Add(item); // } // return kit; // } // return null; // } // catch (Exception) // { // throw; // } //} public static List<Kit> GetKitlist(String file) { List<Kit> kitlist = new List<Kit>(); try { XmlDocument doc = new XmlDocument(); doc.Load(file); XmlNode root = doc["root"]; XmlNode kits = root["kits"]; foreach (XmlNode n in kits) { int level = 0; string name = null; bool fixedGroup = false; try { name = n.Attributes["name"].Value; } catch { } try { string value = n.Attributes["level"].Value; level = int.Parse(value); } catch { } try { fixedGroup = Convert.ToBoolean(n.Attributes["fixedgroup"].Value); } catch { } Kit kit = new Kit(); kit.Name = name; kit.Level = level; kit.FixedGroup = fixedGroup; foreach (XmlNode i in n) { string id = null; int amount = 1; try { id = i.Attributes["id"].Value; } catch { continue; } try { amount = int.Parse(i.Attributes["amount"].Value); } catch { } KitItem item = new KitItem(id, amount); kit.Items.Add(item); } kitlist.Add(kit); } } catch (Exception ex) { throw ex; } return kitlist; }
private void btAddKit_Click(object sender, EventArgs e) { Kit kit = new Kit(); kit.Name = "rename"; kitlist.Add(kit); RefreshList(); KitReader.SaveKitlist(kitlist, Config.ConfigFolder + KitReader.File); RefreshKitlist(); }
//public static Kit GetKitFromName(String file, String filter) //{ // try // { // Kit kit = new Kit(); // XmlDocument doc = new XmlDocument(); // doc.Load(file); // XmlNode root = doc["root"]; // XmlNode kits = root["kits"]; // foreach (XmlNode n in kits) // { // int level = 0; // string name = null; // bool fixedGroup = false; // try // { // name = n.Attributes["name"].Value; // } // catch{ } // try // { // string value = n.Attributes["level"].Value; // level = Convert.ToInt32(value); // } // catch { } // try // { // fixedGroup = Convert.ToBoolean(n.Attributes["fixedgroup"].Value); // } // catch { } // if (String.IsNullOrEmpty(name) || filter != name) // continue; // kit.Name = name; // kit.Level = level; // kit.FixedGroup = fixedGroup; // foreach (XmlNode i in n) // { // string id = null; // int amount = 1; // try // { // id = i.Attributes["id"].Value; // } // catch // { // continue; // } // try // { // amount = int.Parse(i.Attributes["amount"].Value); // } // catch // { // } // KitItem item = new KitItem(id, amount); // kit.Items.Add(item); // } // return kit; // } // return null; // } // catch (Exception) // { // throw; // } //} public static List <Kit> GetKitlist(String file) { List <Kit> kitlist = new List <Kit>(); try { XmlDocument doc = new XmlDocument(); doc.Load(file); XmlNode root = doc["root"]; XmlNode kits = root["kits"]; foreach (XmlNode n in kits) { int level = 0; string name = null; bool fixedGroup = false; try { name = n.Attributes["name"].Value; } catch { } try { string value = n.Attributes["level"].Value; level = int.Parse(value); } catch { } try { fixedGroup = Convert.ToBoolean(n.Attributes["fixedgroup"].Value); } catch { } Kit kit = new Kit(); kit.Name = name; kit.Level = level; kit.FixedGroup = fixedGroup; foreach (XmlNode i in n) { string id = null; int amount = 1; try { id = i.Attributes["id"].Value; } catch { continue; } try { amount = int.Parse(i.Attributes["amount"].Value); } catch { } KitItem item = new KitItem(id, amount); kit.Items.Add(item); } kitlist.Add(kit); } } catch (Exception ex) { throw ex; } return(kitlist); }