protected void BtnSearch_Click(object sender, EventArgs e) { if (TxtGameName.Text.Trim() != "") { searchInventory = DataLayerAccess.GetGamesPlatform(TxtGameName.Text.Trim(), DdlPlatform.SelectedValue); } else { searchInventory = DataLayerAccess.GetGamesByPlatform(DdlPlatform.SelectedValue); } Session["searchList"] = (searchInventory.Count > 0) ? searchInventory : null; if (Session["searchList"] != null) { CreateSearchTable(); } // if no results found else { container.Controls.Clear(); container.Controls.AddAt(0, new Literal { Text = "No games found. <br /><br />" }); } }
protected void Page_Load(object sender, EventArgs e) { if (Request.QueryString["id"] == null) { Response.Redirect("Inventory.aspx"); } // get the id of the game object from queryString int id = Convert.ToInt32(Request.QueryString["id"]); game = DataLayerAccess.GetGameById(id); }
protected void BtnCheckout_Click(object sender, EventArgs e) { // when checkout is clicked, each item contained in the cart is saved into Invoice and InvoiceGame Invoice invoice = new Invoice { InvoiceDate = DateTime.Now, SubTotal = subTotal, Tax = tax, TotalAmount = total }; // add invoice to db DataLayerAccess.AddInvoice(invoice); // get id of invoice just added Invoice inv = DataLayerAccess.GetLastInvoice(); foreach (var item in cart) { InvoiceGame ig = new InvoiceGame { InvoiceId = inv.Id, Price = item.Item.Price, QuantitySold = item.Quantity, Item = item.Item, Invoice = inv }; DataLayerAccess.AddInvoiceGame(ig); // update stock int newStock = item.Item.InStock - item.Quantity; DataLayerAccess.UpdateStock(item.Item.Id, newStock); } // reset chart, hide buttons, erase cart display and show message cart = null; HttpContext.Current.Session["Cart"] = null; BtnCheckout.Visible = false; BtnResetCart.Visible = false; cartContainer.Controls.Clear(); LblPurchaseResult.Text = "Purchase Successful!"; }
protected void BtnSubmit_Click(object sender, EventArgs e) { // validate the platform controls first Page.Validate("ValPlatform"); if (Page.IsValid) { Game game = new Game(); game.Title = TxtTitle.Text; game.Rating = DdlRating.SelectedValue; game.ReleaseYear = Convert.ToInt32(TxtYear.Text); for (int i = 0; i < CheckBoxList1.Items.Count; i++) { ListItem chk = CheckBoxList1.Items[i]; if (chk.Selected) { GameGenre gg = new GameGenre(); gg.Genre = chk.Text; game.GameGenres.Add(gg); } } // loop through the Panel1 control to find all platform related checkboxes for (int i = 0; i < Panel1.Controls.Count; i++) { if (Panel1.Controls[i] is CheckBox) { // loop through platform names to compare input field id's. for (int j = 0; j < platformFieldIds.Count; j++) { // generate the platform based id for comparing with checkbox id string chkId = "Chk" + platformFieldIds[j]; // get the proper controls from the html CheckBox chk = (CheckBox)Panel1.Controls[i]; // if checkbox is not null AND checkbox belongs to that specific platform AND checkbox is checked // then set the values of game object. if (chk != null && chk.ID.Equals(chkId) && chk.Checked) { string txtPriceId = "TxtPrice" + platformFieldIds[j]; string txtStockId = "TxtStock" + platformFieldIds[j]; TextBox txtPrice = (TextBox)FindControlRecursive(Panel1, txtPriceId); TextBox txtStock = (TextBox)FindControlRecursive(Panel1, txtStockId); GamePlatform gp = new GamePlatform(); gp.Platform = chk.Text; gp.Price = Convert.ToDouble(txtPrice.Text); gp.InStock = Convert.ToInt32(txtStock.Text); game.GamePlatforms.Add(gp); } } } } DataLayerAccess.AddGame(game); Response.Redirect("AddGame.aspx"); } }
protected void BtbSearch_Click(object sender, EventArgs e) { searchGames = DataLayerAccess.GetGamesByTitle(TxtTitle.Text); searchResult = searchGames.Count == 0 ? "No games found." : ""; }
protected void Page_Load(object sender, EventArgs e) { LblPurchaseResult.Text = ""; cart = (List <CartItem>)HttpContext.Current.Session["Cart"]; searchInventory = (List <GamePlatform>)Session["searchList"]; // checks if there is already a cart in this user's session if (cart == null) { cart = new List <CartItem>(); BtnCheckout.Visible = false; BtnResetCart.Visible = false; } // if there are items in the cart else { CreateCartTable(); BtnCheckout.Visible = true; BtnResetCart.Visible = true; } if (searchInventory == null) { searchInventory = new List <GamePlatform>(); } else { CreateSearchTable(); } ClientScript.GetPostBackEventReference(this, string.Empty); string targetCtrl = Page.Request.Params.Get("__EVENTTARGET"); // if an "add" button was clicked if (targetCtrl != null && targetCtrl != string.Empty) { int indexAdd = targetCtrl.IndexOf("Add"); string gamePlatId = targetCtrl.Substring(indexAdd + 3, targetCtrl.Length - indexAdd - 3); GamePlatform gp = DataLayerAccess.GetGamePlatform(Convert.ToInt32(gamePlatId)); bool isItemInCart = false; // see if cart already contains item for (int j = 0; j < cart.Count; j++) { // if item was found, simply add 1 to the quantity of that item if (cart[j].Item.Id.ToString() == gamePlatId) { if (gp.InStock > cart[j].Quantity) { cart[j].Quantity++; } isItemInCart = true; } } if (!isItemInCart) { cart.Add(new CartItem { Item = gp, Quantity = 1 }); } HttpContext.Current.Session["Cart"] = cart; CreateCartTable(); BtnCheckout.Visible = true; BtnResetCart.Visible = true; } }
protected void Page_Load(object sender, EventArgs e) { // if there is no queryString then redirect to inventory page. if (Request.QueryString["id"] == null) { Response.Redirect("Inventory.aspx"); } else { // get the id of the game object from queryString id = Convert.ToInt32(Request.QueryString["id"]); } // generate the genre checkboxes List <string> genreList = DataLayerAccess.GetGenres(); if (CheckBoxList1.Items.Count == 0) { for (int i = 0; i < genreList.Count; i++) { CheckBoxList1.Items.Add(genreList[i]); } } // if postback is true (submit button has clicked) then gets the game from DB and overrides the edit activity // so we should check that first if (!IsPostBack) { Game game = DataLayerAccess.GetGameById(id); // pass all the values into proper controls on the page. TxtTitle.Text = game.Title; DdlRating.SelectedValue = game.Rating; TxtYear.Text = game.ReleaseYear.ToString(); for (int i = 0; i < game.GameGenres.Count; i++) { for (int j = 0; j < CheckBoxList1.Items.Count; j++) { if (CheckBoxList1.Items[j].Text == game.GameGenres[i].Genre) { CheckBoxList1.Items[j].Selected = true; break; } } } for (int i = 0; i < game.GamePlatforms.Count; i++) { string chkPlatformId = "Chk" + game.GamePlatforms[i].Platform.ToString().Replace(" ", ""); CheckBox chk = (CheckBox)FindControlRecursive(Panel1, chkPlatformId); chk.Checked = true; string txtPriceId = "TxtPrice" + game.GamePlatforms[i].Platform.ToString().Replace(" ", ""); TextBox txtPrice = (TextBox)FindControlRecursive(Panel1, txtPriceId); txtPrice.Text = game.GamePlatforms[i].Price.ToString(); string txtStockId = "TxtStock" + game.GamePlatforms[i].Platform.ToString().Replace(" ", ""); TextBox txtStock = (TextBox)FindControlRecursive(Panel1, txtStockId); txtStock.Text = game.GamePlatforms[i].InStock.ToString(); } } }
protected void BtnSubmit_Click(object sender, EventArgs e) { DataLayerAccess.DeleteGame(game); Response.Redirect("Inventory.aspx"); }
protected void btnSearchInvoice_Click(object sender, EventArgs e) { searchInvoice = DataLayerAccess.GetInvoice(Convert.ToInt32(txtSearchInvoice.Text)); searchInvoiceResult = searchInvoice == null ? "No invoices found." : ""; }