protected void Page_Load(object sender, EventArgs e) { acc.UserName = Session["AccountUserName"].ToString(); if (!IsPostBack) { Account userAccountSessionTracker = new Account(); userAccountSessionTracker = (Account)HttpContext.Current.Session["User"]; lblUserNameNav.Text = acc.UserName; loadCategoriesFromDatabase(); toggleImagePanel(false); } else if (IsPostBack) { bookItemList = CartItemList.GetCart(); if ((ddlBookName.SelectedIndex <= 0 || ddlBookCategory.SelectedIndex <= 0) || (ddlBookName.SelectedIndex <= 0 && ddlBookCategory.SelectedIndex <= 0)) { toggleImagePanel(false); } else { toggleImagePanel(true); } } }
protected void Button1_Click(object sender, EventArgs e) { var closeLink = (Control)sender; GridViewRow row = (GridViewRow)closeLink.NamingContainer; string firstCellText = row.Cells[2].Text; Items item = new Items(); string output = firstCellText.ToLower().Replace(" desert", "_desert"); for (int i = 0; i < desertList.Count; i++) { if (desertList[i].item_name.ToLower().Replace(" desert", "_desert") == output) { item.item_id = desertList[i].item_id; item.item_name = desertList[i].item_name; item.item_price = desertList[i].item_price; item.item_description = desertList[i].item_description; item.image = desertList[i].image; } } CartItemList cart = CartItemList.GetCart(); ItemList cartItem = cart[item.item_name]; int quantity = 1; if (cartItem == null) { cart.AddItem(item, quantity); } else { cartItem.AddQuantity(quantity); } Response.Redirect("~/cart.aspx"); }
protected void btnRemove_Click(object sender, EventArgs e) { cart = CartItemList.GetCart(); if (cart.Count > 0) { List <int> list = lstCart.GetSelectedIndices().ToList <int>(); // Redundant but the only method that worked for us for some reason if (list.Count > 0) { for (int i = 0; i < lstCart.Items.Count; i++) { if (lstCart.Items[i].Selected == true) { cart.RemoveAt(i); lstCart.Items.Remove(lstCart.Items[i]); break; } } } else { lblMessage.Text = "Please select the item you want to remove."; } } Session["sessionCart"] = cart; this.DisplayCart(); resetCartSize(); }
/* private Product GetSelectedProduct() * { * //get row from SqlDataSource based on value in dropdownlist * DataView productsTable = (DataView) * SqlDataSource.Select(DataSourceSelectArguments.Empty); * productsTable.RowFilter = string.Format("ProductID = '{0}'", * ddlProducts.SelectedValue); * DataRowView row = (DataRowView)productsTable[0]; * * //create a new product object and load with data from row * Product p = new Product(); * p.ProductID = row["ProductID"].ToString(); * p.Name = row["Name"].ToString(); * p.ShortDescription = row["ShortDescription"].ToString(); * p.LongDescription = row["LongDescription"].ToString(); * p.UnitPrice = (decimal)row["UnitPrice"]; * p.ImageFile = row["ImageFile"].ToString(); * return p; * }*/ protected void btnAdd_Click(object sender, EventArgs e) { if (Page.IsValid) { string itemID; Button clickedButton = (Button)sender; itemID = clickedButton.Attributes["ItemID"]; //get cart from session and selected item from cart CartItemList cart = CartItemList.GetCart(); CartItem cartItem = cart[itemID]; //if item isn’t in cart, add it; otherwise, increase its quantity if (cartItem == null) { SqlConnection conn = new SqlConnection(connstring); conn.Open(); int id = Convert.ToInt32(itemID); SqlCommand sqlcmd = new SqlCommand("SELECT * FROM MenuItem where Id =" + id, conn); SqlDataReader theReader = sqlcmd.ExecuteReader(); theReader.Read(); MenuItem m = readerToMenuItem(theReader); cart.AddItem(m, 1); } else { cartItem.AddQuantity(1); } Response.Redirect("Cart.aspx"); } }
protected void Page_Load(object sender, EventArgs e) { //retrieve cart object from session state on every post back cart = CartItemList.GetCart(); //on initial page load, add cart items to list control if (!IsPostBack) { this.DisplayCart(); } // if user is signed in, populate address on file in check out page for easier check out -lg if (User.Identity.IsAuthenticated) { var userId = User.Identity.GetUserId(); UserManager <IdentityUser> userManager = new UserManager <IdentityUser>(new UserStore <IdentityUser>()); string firstName = UserDA.getFirstname(userId); string lastName = UserDA.getLastname(userId); string fullname = firstName + " " + lastName; txtShipTo.Text = fullname; string address = UserDA.getAddress(userId); txtShipAddr1.Text = address; string city = UserDA.getCity(userId); txtShipCity.Text = city; string state = UserDA.getState(userId); txtShipState.Text = state; string zip = UserDA.getZip(userId); txtShipZip.Text = zip; } }
protected void GridView1_SelectedIndexChanged(object sender, EventArgs e) { string id = GridView1.SelectedRow.Cells[1].Text; selectedPackage = PackagesDB.GetPackage(Convert.ToInt16(id)); Page.Validate(); // Next add them to the cart which is a session variable and thus global to // all the web forms if (Page.IsValid) { CartItemList cart = CartItemList.GetCart(); CartItem cartItem = cart[selectedPackage.PackageId]; //if item isn’t in cart, add it; otherwise, increase its quantity if (cartItem == null) { cart.AddItem(selectedPackage, 1); } else { cartItem.AddQuantity(1); } } }
protected void Page_Load(object sender, EventArgs e) { cart = CartItemList.GetCart(); decimal totalPrice = Convert.ToDecimal(Session["TotalPrice"]); lblTotalPrice.Text = "Total Price: " + Convert.ToString(totalPrice); }
protected void Page_Load(object sender, EventArgs e) { cart = CartItemList.GetCart(); if (!IsPostBack) { this.DisplayCart(); } }
protected void Page_Load(object sender, EventArgs e) { cart = CartItemList.GetCart(); // get on all postbacks if (!IsPostBack) // do on initial load { this.DisplayCart(); } ; }
protected void Page_Load(object sender, EventArgs e) { Master.HeaderText = "Your Shopping Cart"; cart = CartItemList.GetCart(); if (!IsPostBack) { this.DisplayCart(); } }
protected void Page_Load(object sender, EventArgs e) { // retrieve cart object from session state on every post-back cart = CartItemList.GetCart(); // on initial page load, add cart items to list control if (!IsPostBack) { this.DisplayCart(); } }
private void AddToBasket(int ProductId) { CartItemList cart = CartItemList.GetCart(); //Create Product From Id // create a new product object and load with data from row Product p = new Product(); Session["Basket"] = true; //Read Info From DB For Product SqlConnection conn = new SqlConnection(); conn.ConnectionString = "Data Source = (LocalDB)\\MSSQLLocalDB;" + "AttachDbFilename = C:\\Users\\Matte\\Downloads\\Ex09Cart\\Ex09Cart\\App_Data\\MyRestaurant.mdf;" + "Integrated Security = True"; SqlCommand command = new SqlCommand("SELECT* FROM [Product] Where Id = @Id"); command.Parameters.AddWithValue("@Id", ProductId); command.Connection = conn; conn.Open(); DataSet ds = new DataSet(); SqlDataAdapter da = new SqlDataAdapter(command); da.Fill(ds); conn.Close(); if (ds.Tables.Count > 0) { p.ProductID = ds.Tables[0].Rows[0].Field <int>("Id").ToString(); p.Name = ds.Tables[0].Rows[0].Field <string>("name"); p.UnitPrice = ds.Tables[0].Rows[0].Field <decimal>("cost"); p.ImageFile = "Images/Products/" + ds.Tables[0].Rows[0].Field <string>("image"); //if item isn’t in cart, add it; otherwise, increase its quantity cart = CartItemList.GetCart(); CartItem cartItem = cart[p.ProductID]; if (cartItem == null) { cart.AddItem(p, 1); } else { cartItem.AddQuantity(1); } Response.Redirect("Cart.aspx"); } //Response.Redirect("login.aspx"); }
protected void Page_Load(object sender, EventArgs e) { cart = CartItemList.GetCart(); this.DisplayCart(); decimal grandTotal = Convert.ToDecimal(Session["Total"]); Label1.Text = "Total: " + grandTotal.ToString("c"); firstLabel.Text = "First Name: " + Convert.ToString(Session["First"]); lastLabel.Text = "Last Name: " + Convert.ToString(Session["Last"]); dateLabel.Text = "Date Ordered: " + Convert.ToString(Session["Date"]); shipLabel.Text = "Shipping Method: " + Convert.ToString(Session["Ship"]); }
protected void btnEmpty_Click(object sender, EventArgs e) { cart = CartItemList.GetCart(); if (cart.Count > 0) { cart.Clear(); lstCart.Items.Clear(); } Session["sessionCart"] = cart; this.DisplayCart(); resetCartSize(); }
protected void Page_Load(object sender, EventArgs e) { //retrieve cart object from session on every post back cart = CartItemList.GetCart(); //on initial page load, add cart items to list control //and set master page logo image tool tip if (!IsPostBack) { this.DisplayCart(); } }
protected void Page_Load(object sender, EventArgs e) { cart = CartItemList.GetCart(); // get on all postbacks if (!IsPostBack) // do on initial load { Master.AddBreadcrumbLink("/Order.aspx", "Home"); Master.AddCurrentPage("Cart"); this.DisplayCart(); } ; }
protected void btnAdd_Click(object sender, EventArgs e) { if (IsValid) { Product selectedProduct = GetSelectedProduct(); CartItemList cart = CartItemList.GetCart(); CartItem cartItem = cart[selectedProduct.productID]; if (cartItem == null) { cart.AddItem(selectedProduct, Convert.ToInt32(txtQuantity.Text)); } ; } }
protected void Page_Load(object sender, EventArgs e) { //retrieve cart object from session on every post back cart = CartItemList.GetCart(); orderTotal = GetCartTotal(cart); //on initial page load, add cart items to list control //and set master page logo image tool tip if (!IsPostBack) { this.DisplayCart(); // this.Master.PageH1Text = "Your Shopping Cart"; } }
protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { lblTotal.Text = "Total = $0.00"; if (Session["SelectedRest"] != null) { ddlRestaurants.SelectedValue = Session["SelectedRest"].ToString(); Session["SelectedRest"] = null; } lblMessage.Text = ""; resetCartSize(); cart = CartItemList.GetCart(); this.DisplayCart(); } }
protected void btnAdd_Click(object sender, EventArgs e) { if (Page.IsValid) { CartItemList cart = CartItemList.GetCart(); CartItem cartItem = cart[selectedProduct.Name]; if (cartItem == null) { cart.AddItem(selectedProduct, Convert.ToInt32(txtQuantity.Text)); } else { cartItem.AddQuantity(Convert.ToInt32(txtQuantity.Text)); } Response.Redirect("Cart.aspx"); } }
protected void Page_Load(object sender, EventArgs e) { //takes the user to the login page if they're not logged in if ((Session["loggedIn"] == null) || (bool)Session["loggedIn"] == false) { Response.Redirect("LoginPage.aspx"); } //retrieve cart object from session on every post back cart = CartItemList.GetCart(); //on initial page load, add cart items to list control //and set master page logo image tool tip if (!IsPostBack) { this.DisplayCart(); } }
protected void Page_Load(object sender, EventArgs e) { userAccountSessionTracker = (Account)HttpContext.Current.Session["User"]; bookItemList = CartItemList.GetCart(); lblTotalPrice.Text = HttpContext.Current.Session["OrderTotalAmount"].ToString(); order.TotalAmount = Convert.ToDecimal(lblTotalPrice.Text); if (!IsPostBack) { order.TotalAmount = Convert.ToDecimal(lblTotalPrice.Text); displayList(); } else { } }
protected void addButton_Click(object sender, EventArgs e) { if (Page.IsValid) { CartItemList cart = CartItemList.GetCart(); CartItem cartItem = cart[selectedProduct.ProductID]; if (cartItem == null) { cart.AddItem(selectedProduct, Convert.ToInt32(quantityTextBox.Text)); } else { cartItem.AddQuantity(Convert.ToInt32(quantityTextBox.Text)); } Response.Redirect("~/ShoppingPages/Cart.aspx"); } }
protected void Page_Load(object sender, EventArgs e) { lblCardData.Visible = false; txtCardNumber.Visible = false; toggleImagePanel(false); bookItemList = CartItemList.GetCart(); if (!IsPostBack) { lblProfileName.Text = Session["AccountUserName"].ToString().Trim(); loadCategoriesFromDatabase(); toggleImagePanel(true); } imgBookImage.ImageUrl = "images/book5-c.jpg"; }
protected void AddToCart(int itemID) { Item selectedProduct = this.GetSelectedProduct(itemID); CartItemList cart = CartItemList.GetCart(); CartItem cartItem = cart[selectedProduct.ItemID]; if (cartItem == null) { cart.AddItem(selectedProduct, 1); Console.WriteLine(selectedProduct.ItemName); } else { cartItem.AddQuantity(1); } resetCartSize(); Session["sessionCart"] = cart; }
private void DisplayCart() { cart = CartItemList.GetCart(); lstCart.Items.Clear(); CartItem item; for (int i = 0; i < cart.Count; i++) { item = cart[i]; lstCart.Items.Add(item.Display()); lblTotal.Text = "Total = " + String.Format("{0:C2}", cart.GetCartTotal()); } if (lstCart.Items.Count <= 0) { lstCart.Items.Add("Empty Cart"); } }
protected void btnAdd_Click1(object sender, EventArgs e) { if (Page.IsValid) { selectedProduct = this.GetSelectedProduct(); CartItemList cart = CartItemList.GetCart(); CartItem cartItem = cart[selectedProduct.ProductID]; if (cartItem.Product != selectedProduct) { cart.AddItem(selectedProduct, 1); } else { cartItem.AddQuantity(1); } Console.WriteLine("PageLoad"); Response.Redirect("Cart.aspx", false); } }
protected void Page_Load(object sender, EventArgs e) { lblCardData.Visible = false; txtCardNumber.Visible = false; userAccountSessionTracker = (Account)HttpContext.Current.Session["User"]; order.TotalAmount = Convert.ToDecimal(HttpContext.Current.Session["OrderTotalAmount"]); bookItemList = CartItemList.GetCart(); lblTotalAmount.Text = order.TotalAmount.ToString(); if (!IsPostBack) { displayList(); } else { } }
protected void btnAdd_Click(object sender, EventArgs e) { if (Page.IsValid) { //get cart from session state and selected item from cart CartItemList cart = CartItemList.GetCart(); CartItem cartItem = cart[selectedProduct.ProductID]; //if item is nt in cart, add it; else increase its quantity if (cartItem == null) { cart.AddItem(selectedProduct, Convert.ToInt32(txtQuantity.Text)); } else { cartItem.AddQuantity(Convert.ToInt32(txtQuantity.Text)); } Response.Redirect("Cart.aspx"); } }
protected void btnAddToCart_Click(object sender, EventArgs e) { Product redpepper = new Product(); redpepper.name = "Redpepper"; redpepper.description = "These cases are great quality protective cases. They have ip68 water and dust resistance which means you can drop them in the pool and not worry!"; redpepper.unitPrice = 70; redpepper.type = dropPhone.Text; CartItemList cart = CartItemList.GetCart(); CartItem cartItem = cart[0]; if (cartItem == null) { cart.AddItem(redpepper, Convert.ToInt32(dropQuantity.Text)); } Response.Redirect("~/Cart.aspx"); }