public bool AddToCartPice(CartRow cartRow) { CartExists(); if (cart.Pica.Where(x => x.Id == cartRow.Id).SingleOrDefault() != null) { var staraKolicina = cart.Pica.SingleOrDefault(x => x.Id == cartRow.Id).Kolicina; cart.Pica.SingleOrDefault(x => x.Id == cartRow.Id).Kolicina = cartRow.Kolicina; cart.Pica.SingleOrDefault(x => x.Id == cartRow.Id).TotalRowPrice = cartRow.Cijena * cartRow.Kolicina; cart.TotalPrice += cartRow.Cijena * cartRow.Kolicina; cart.TotalPrice -= cartRow.Cijena * staraKolicina; label4.Text = Math.Round(cart.TotalPrice, 2).ToString() + " KM"; } else { CartRow pice = new CartRow(); pice.Id = cartRow.Id; pice.Kolicina = cartRow.Kolicina; pice.Naziv = cartRow.Naziv; pice.Cijena = cartRow.Cijena; pice.TotalRowPrice = cartRow.Cijena * cartRow.Kolicina; cart.Pica.Add(pice); pice.Kategorija = cartRow.Kategorija; pice.StanjeKolicina = cartRow.StanjeKolicina; pice.Imageurl = cartRow.Imageurl; cart.TotalPrice += pice.TotalRowPrice; label4.Text = Math.Round(cart.TotalPrice, 2).ToString() + " KM"; } SetBtnOdaberiStoVisibility(); return(true); //fali dio sa stanjem,da li ima stavke na stanju , treba uraditi poziv prema API }
public bool DodajUKorpu() { if (ViewModel.Id != null) { var stavkaKorpe = new CartRow { Naziv = ViewModel.Naziv, Cijena = ViewModel.Cijena, Kolicina = kolicina, Id = ViewModel.Id ?? 0, Kategorija = ViewModel.Kategorija, StanjeKolicina = ViewModel.Kolicina, Imageurl = ViewModel.imageUrl }; if (ViewModel.Kategorija == "Jela") { ((Form1)this.ParentForm).AddToCartJelo(stavkaKorpe); return(true); } else { ((Form1)this.ParentForm).AddToCartPice(stavkaKorpe); return(true); } } return(false); }
public bool AddToCartJelo(CartRow cartRow) { if (cart.Jela.Where(x => x.Id == cartRow.Id).SingleOrDefault() != null) { var staraKolicina = cart.Jela.SingleOrDefault(x => x.Id == cartRow.Id).Kolicina; cart.Jela.SingleOrDefault(x => x.Id == cartRow.Id).Kolicina = cartRow.Kolicina; cart.Jela.SingleOrDefault(x => x.Id == cartRow.Id).TotalRowPrice = cartRow.Cijena * cartRow.Kolicina; cart.TotalPrice += cartRow.Cijena * cartRow.Kolicina; cart.TotalPrice -= cartRow.Cijena * staraKolicina; label4.Text = Math.Round(cart.TotalPrice, 2).ToString() + " KM"; } else { CartRow jelo = new CartRow(); jelo.Id = cartRow.Id; jelo.Kolicina = cartRow.Kolicina; jelo.Naziv = cartRow.Naziv; jelo.Kategorija = cartRow.Kategorija; jelo.Imageurl = cartRow.Imageurl; jelo.Cijena = cartRow.Cijena; jelo.StanjeKolicina = 0; jelo.TotalRowPrice = cartRow.Cijena * cartRow.Kolicina; cart.Jela.Add(jelo); cart.TotalPrice += jelo.TotalRowPrice; label4.Text = Math.Round(cart.TotalPrice, 2).ToString() + " KM"; } SetBtnOdaberiStoVisibility(); return(true); }
Cart myCart = new Cart(); // shopping cart #endregion Fields #region Methods protected void btnAddToCart_Click(object sender, EventArgs e) { string pid = (string)Session["PRODUCTID"]; string pname = (string)Session["PRODDESC"]; //short description string price = (string)Session["PRICE"]; CartRow row = new CartRow(); CartRow testrow = new CartRow(); row.PID = pid; row.PName = pname; row.Price = price; row.Qty = txtQuantity.Text; // count of how many to buy // if item exists in shopping cart, remove first, then add // with an updated total count int nTotalItem = myCart.list.Count; for (int nItem = 0; nItem < nTotalItem; nItem++) { testrow = (CartRow)myCart.list[nItem]; if (testrow.PID == pid) { int qty = Int32.Parse(testrow.Qty); qty += 1; testrow.Qty = qty.ToString(); myCart.list.RemoveAt(nItem); row = testrow; break; } } myCart.list.Add(row); //Cart.ShowCartTable(myCart, Table1, LabelTotal); lblAddToCart.Text = row.Qty + " items of " + row.PName + " added to your Shopping Cart"; }
public void AddtoCart() { CartRow row = new CartRow(); //CartRow testrow = new CartRow(); //row.id = id; //row.name = name; //row.price = price; //row.items = "1"; //int nTotalItem = myCart.list.Count; //double dTotal = 0.0; //double dPrice = 0.0; //for (int nItem = 0; nItem < nTotalItem; nItem++) //{ // testrow = (CartRow)myCart.list[nItem]; // if (testrow.id == id) // { // int nItems = Int32.Parse(testrow.items); // nItems += 1; // testrow.items = nItems.ToString(); // myCart.list.RemoveAt(nItem); // row = testrow; // break; // } //} //myCart.list.Add(row); //nTotalItem = myCart.list.Count; }
private void btnEmpty_Click(object sender, System.EventArgs e) { myCart.list.Clear(); int nTotalItem = myCart.list.Count; double dTotal = 0.0; double dPrice = 0.0; for (int nItem = 0; nItem < nTotalItem; nItem++) { TableRow trow = new TableRow(); CartRow row = new CartRow(); row = (CartRow)myCart.list[nItem]; TableCell c1 = new TableCell(); TableCell c2 = new TableCell(); TableCell c3 = new TableCell(); TableCell c4 = new TableCell(); c1.Text = row.id; c2.Text = row.name; c3.Text = row.price; c4.Text = row.items; trow.Cells.Add(c1); trow.Cells.Add(c2); trow.Cells.Add(c3); trow.Cells.Add(c4); Table1.Rows.Add(trow); dPrice = Double.Parse(row.price); dTotal += dPrice; } LabelTotal.Text = dTotal.ToString(); }
protected void btnUpdate_Click(object sender, EventArgs e) { //Session["MYCARTOLD"] = myCart; // will not work // as we are clearing myCart in the following line. // To make it work properly, the above call should // use a clone object of myCart. For this, we have // to provide a clone method in the Cart class. Session["MYCARTOLD"] = myCart.Clone(); // clone is important here myCart.list.Clear(); // first row is heading, last row is total for (int i = 1; i < tblCart.Rows.Count - 1; i++) { CartRow cr = new CartRow(); cr.PID = tblCart.Rows[i].Cells[0].Text; if (cr.PID != "") // not shipping/handling price { if (int.Parse(((TextBox)(tblCart.Rows[i].Cells[2].Controls[0])).Text) > 0) { // if Qty is greater than 0 cr.PName = tblCart.Rows[i].Cells[1].Text; cr.Qty = ((TextBox)(tblCart.Rows[i].Cells[2].Controls[0])).Text; cr.Price = tblCart.Rows[i].Cells[3].Text.Substring(1, tblCart.Rows[i].Cells[3].Text.Length - 1); // exclude $ from price myCart.list.Add(cr); } } else { cr.PName = "Shipping/Handling"; cr.Price = tblCart.Rows[i].Cells[4].Text.Substring(1, tblCart.Rows[i].Cells[4].Text.Length - 1); // price without $ myCart.list.Add(cr); } } Session["MYCART"] = myCart; //Cart.ShowCartTable(myCart,Table2); // uncomment above line and comment the Response.Redirect // line to see interesting bug in updating cart quantity //Response.Redirect("ViewCart.aspx"); // The above line should be the actual page in which the // shopping cart user control resides, as given below string reqPage = Request["SCRIPT_NAME"]; Response.Redirect(reqPage); }
private void Page_Load(object sender, System.EventArgs e) { lblEmptyCart.Visible = false; if ((Session["cart"] == null)) { Session["cart"] = myCart; } else { myCart = (Cart)(Session["cart"]); } sqlDataAdapter1.Fill(dsProduct1); DataGridProduct.DataBind(); if (!IsPostBack) { int nTotalItem = myCart.list.Count; double dTotal = 0.0; double dPrice = 0.0; for (int nItem = 0; nItem < nTotalItem; nItem++) { TableRow trow = new TableRow(); CartRow row = new CartRow(); row = (CartRow)myCart.list[nItem]; TableCell c1 = new TableCell(); TableCell c2 = new TableCell(); TableCell c3 = new TableCell(); TableCell c4 = new TableCell(); c1.Text = row.id; c2.Text = row.name; c3.Text = row.price; c4.Text = row.items; trow.Cells.Add(c1); trow.Cells.Add(c2); trow.Cells.Add(c3); trow.Cells.Add(c4); Table1.Rows.Add(trow); dPrice = Double.Parse(row.price); dTotal += dPrice; } LabelTotal.Text = dTotal.ToString(); } }
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { string uid = ""; if (Session["CUSTOMERUSERID"] != null) { uid = (string)Session["CUSTOMERUSERID"]; try { string sql = "SELECT * FROM CustomerInfos WHERE UserID=" + uid; DataSet ds = DBFunctions.GetDataSetDB(sql); lblFirstName.Text = ds.Tables[0].Rows[0]["FirstName"].ToString(); lblLastName.Text = ds.Tables[0].Rows[0]["LastName"].ToString(); txtAddress.Text = ds.Tables[0].Rows[0]["Address"].ToString(); txtCity.Text = ds.Tables[0].Rows[0]["City"].ToString(); txtState.Text = ds.Tables[0].Rows[0]["State"].ToString(); txtZipcode.Text = ds.Tables[0].Rows[0]["Zipcode"].ToString(); txtCCNumber.Text = ds.Tables[0].Rows[0]["CCNumber"].ToString(); string cctype = ds.Tables[0].Rows[0]["CCType"].ToString(); switch (cctype) { case "Visa": ddlCCType.Items[0].Selected = true; break; case "MasterCard": ddlCCType.Items[1].Selected = true; break; case "AmericanExpress": ddlCCType.Items[2].Selected = true; break; case "Discover": ddlCCType.Items[3].Selected = true; break; } txtExpiration.Text = ds.Tables[0].Rows[0]["CCExpiration"].ToString(); txtEmail.Text = ds.Tables[0].Rows[0]["Email"].ToString(); } catch (Exception ex) { lblStatus.Text = ex.Message; } } try { // add shipping and handling info to shopping cart if (Session["MYCART"] != null) { Cart myCart = (Cart)Session["MYCART"]; CartRow row = new CartRow(); row.PID = ""; // shipping/handling has blank row id row.PName = "Shipping/Handling"; row.Price = "8.75"; // later on get the price from database // based on products and shipping address row.Qty = ""; // count of how many to buy // for shipping/handling row, it is blank // if shipping/handling exists in shopping cart, remove first, then add // with an updated total count int cartRowCount = myCart.list.Count; CartRow crow; for (int i = 0; i < cartRowCount; i++) { crow = (CartRow)myCart.list[i]; if (crow.PID == row.PID) { myCart.list.RemoveAt(i); break; } } myCart.list.Add(row); // add it at the end of shopping cart //Cart.ShowCartTable(myCart, Table1, LabelTotal); } MyCCValidator.AcceptedCreditCardTypes = ddlCCType.SelectedValue; } catch (Exception ex) { lblStatus.Text = ex.Message; } } }
public CartItem(CartRow viewModel) : this() { ViewModel = viewModel; }
public CartRowChangeEvent(CartRow row, global::System.Data.DataRowAction action) { this.eventRow = row; this.eventAction = action; }
private void DataGridProduct_SelectedIndexChanged(object sender, System.EventArgs e) { int nIdx = DataGridProduct.SelectedIndex; string id = dsProduct1.Tables["Products"].Rows[nIdx][0].ToString(); string name = dsProduct1.Tables["Products"].Rows[nIdx][1].ToString(); string price = dsProduct1.Tables["Products"].Rows[nIdx][5].ToString(); CartRow row = new CartRow(); CartRow testrow = new CartRow(); row.id = id; row.name = name; row.price = price; row.items = "1"; int nTotalItem = myCart.list.Count; double dTotal = 0.0; double dPrice = 0.0; for (int nItem = 0; nItem < nTotalItem; nItem++) { testrow = (CartRow)myCart.list[nItem]; if (testrow.id == id) { int nItems = Int32.Parse(testrow.items); nItems += 1; testrow.items = nItems.ToString(); myCart.list.RemoveAt(nItem); row = testrow; break; } } myCart.list.Add(row); nTotalItem = myCart.list.Count; for (int nItem = 0; nItem < nTotalItem; nItem++) { TableRow trow = new TableRow(); //CartRow row = new CartRow(); row = (CartRow)myCart.list[nItem]; TableCell c1 = new TableCell(); TableCell c2 = new TableCell(); TableCell c3 = new TableCell(); TableCell c4 = new TableCell(); c1.Text = row.id; c2.Text = row.name; c3.Text = row.price; c4.Text = row.items; trow.Cells.Add(c1); trow.Cells.Add(c2); trow.Cells.Add(c3); trow.Cells.Add(c4); Table1.Rows.Add(trow); dPrice = Double.Parse(row.price); int nNum = Int32.Parse(row.items); dPrice *= nNum; dTotal += dPrice; } LabelTotal.Text = dTotal.ToString(); }