protected void loadButton_Click(object sender, EventArgs e) { Int32.TryParse(shopDropDownList.SelectedValue, out int shopID); //use this to make an encounter and save to session variable MagicsTable magicTable = new MagicsTable(new DatabaseConnection()); shop = magicTable.getMagicShop(shopID); List <MagicItem> shopItems = magicTable.getMagicShopItems(shopID); shop.Items = new Dictionary <MagicItem, Color>(); //Add to items dictionary foreach (MagicItem item in shopItems) { //Color color; //if (monster.IsFriendly) color = Color.LightGreen; //else color = Color.LightSalmon; shop.Items.Add(item, Color.White); } //Save to savedContent Session["savedContent"] = shop; Session["message"] = new Message("Magic Shop Loaded!", System.Drawing.Color.Green); //Reload page to clear any nonsense before loading Response.Redirect("MagicShopTool"); }
//Populates the dropdown list with the encounters private void populateEncounterDropdown() { MagicsTable magicTable = new MagicsTable(new DatabaseConnection()); DataSet data = magicTable.getMagicShops(game.GameID); //Call to database shopDropDownList.DataSource = data; shopDropDownList.DataTextField = "shopName"; shopDropDownList.DataValueField = "shopID"; shopDropDownList.DataBind(); shopDropDownList.Items.Insert(0, new ListItem("<Select Shop>", "0")); }
//Clears the server information, removes encounter and its monsters from the db, Response.Redirect back to same page to clear postback changes protected void deleteButton_Click(object sender, EventArgs e) { if (shop.ShopID != 0) { //Delete encounter information from database MagicsTable magicTable = new MagicsTable(new DatabaseConnection()); magicTable.deleteMagicShopItems(shop.ShopID); magicTable.deleteMagicShop(shop.ShopID); //Clear Content from Session Variable Session.Remove("savedContent"); } Session["message"] = new Message("Magic Shop Deleted!", System.Drawing.Color.Green); //Reload page to clear any nonsense before loading Response.Redirect("MagicShopTool"); }
//Saves entities to the db protected void saveButton_Click(object sender, EventArgs e) { if (shopQualityDropDownList.SelectedIndex == 0) { angryLabel.Text = "You must select a quality level for the shop."; return; } shop.ShopQuality = shopQualityDropDownList.SelectedValue; MagicsTable magicTable = new MagicsTable(new DatabaseConnection()); itemTable.saveContentChanges(); shop.Items = itemTable.getContent(); Session["savedContent"] = shop; //Fresh Shop, needs creation first if (shop.ShopID == 0) { shop.ShopName = hiddenShopName.Value; //Get name from js prompt. int shopID = magicTable.insertMagicShop(shop); //Make encounter in db and return id if (shopID > 0) { shop.ShopID = shopID; //If valid id, set shopID } Session["savedContent"] = shop; } else { magicTable.updateMagicShop(shop); } //Foreach tableRow do the applicable database command (update/insert/delete) to mirror what the user has done in the table. foreach (ObjectTableRow objRow in itemTable.ObjectRows) { MagicItem item = (MagicItem)objRow.Obj; if (objRow.Visible == false) { if (item.MagicItemID != 0) { magicTable.deleteShopMagicItem(item); //delete magic item } shop.Items.Remove(item); } else if (objRow.Visible == true && item.MagicItemID != 0) { magicTable.updateMagicItem(item); //update monster } else if (objRow.Visible == true && item.MagicItemID == 0) //create monster { if (item.Shop.ShopID == 0) { item.Shop = shop; } int itemID = magicTable.insertMagicItem(item); if (itemID > 0) { item.MagicItemID = itemID; } } } //Save to savedContent w/ new IDs Session["savedContent"] = shop; Session["message"] = new Message("Magic Shop Saved!", System.Drawing.Color.Green); //Reload page to clear any nonsense before loading Response.Redirect("MagicShopTool"); }