示例#1
0
 protected void dgvCart_RowCommand(object sender, GridViewCommandEventArgs e)
 {
     switch (e.CommandName)
     {
         case "UpdateQuantity":
             {
                 GridViewRow row = (GridViewRow)(((LinkButton)e.CommandSource).NamingContainer);
                 int productID = int.Parse(((Label)row.Cells[0].FindControl("lblProductID")).Text);
                 double productPrice = double.Parse(((Label)row.Cells[0].FindControl("lblProductPrice")).Text);
                 double userPrice = double.Parse(((Label)row.Cells[0].FindControl("lblUserPrice")).Text);
                 int quantity;
                 if (!int.TryParse(((TextBox)row.Cells[0].FindControl("txtQuantity")).Text, out quantity))
                 {
                     Response.Write("<SCRIPT LANGUAGE='JavaScript'>alert('wrong')</SCRIPT>");
                     break;
                 }
                 else
                 {
                     CartBL cartBL = new CartBL();
                     cartBL.UpdateCartProduct(Session["cartID"].ToString(), productID, quantity, productPrice, userPrice);
                     calculateItem(row.RowIndex, userPrice * quantity);
                     calculateTotal();
                 }
                 break;
             }
     }
 }
示例#2
0
        private void calculateCart()
        {
            double price;
            double discount = (ViewState["discount"] != null) ? double.Parse(ViewState["discount"].ToString()) : 0;
            CartBL cartBL = new CartBL();

            foreach (GridViewRow row in dgvCart.Rows)
            {
                //if (double.Parse(((Label)row.FindControl("lblProductPrice")).Text) == double.Parse(((Label)row.FindControl("lblUserPrice")).Text))
                //{
                    price = double.Parse(((Label)row.FindControl("lblProductPrice")).Text);
                    double discountPrice = price * (1 - ((double)discount) / 100);
                    double quantity = double.Parse(((TextBox)row.FindControl("txtQuantity")).Text);
                    int productID = int.Parse(((Label)row.FindControl("lblProductID")).Text);
                    ((Label)row.FindControl("lblUserPrice")).Text = string.Format("{0:N2}", discountPrice);
                    ((Label)row.FindControl("lblSum")).Text = string.Format("{0:N2}", (discountPrice * quantity));
                    cartBL.UpdateCartProduct(Session["cartID"].ToString(), productID, quantity, price, discountPrice);
                //}

            }
            calculateTotal();
        }