コード例 #1
0
        protected void btn_AddCart_Click(object sender, EventArgs e)
        {
            Bookstore_BO bookstorebo = new Bookstore_BO();

            productId = bookstorebo.retrieveProductId(lbl_Item.Text).ToString();
            int OldQuantity = Convert.ToInt32(bookstorebo.retrieveProductQuantity(Convert.ToInt32(productId)));
            int NewQuantity = OldQuantity - Convert.ToInt32(TB_Quantity.Text);

            if (NewQuantity >= 0)
            {
                int IdExist = Convert.ToInt32(bookstorebo.retrieveProductIdFromCart(Convert.ToInt32(productId)));
                if (IdExist > 0)
                {
                    bookstorebo.updateQuantityInCartDB(Convert.ToInt32(productId), Convert.ToInt32(TB_Quantity.Text));
                }
                else
                {
                    ImageURL = bookstorebo.retrieveImageString(Convert.ToInt32(productId));
                    NAME     = GridView1.SelectedRow.Cells[2].Text.ToString();
                    PRICE    = Convert.ToDecimal(GridView1.SelectedRow.Cells[3].Text);
                    Quantity = Convert.ToInt32(TB_Quantity.Text.Trim());
                    bookstorebo.AddProduct(Convert.ToInt32(productId), ImageURL, NAME, PRICE, Quantity);
                }
            }
            else
            {
                lbl_Error.Visible = true;
            }


            lbl_Item.Text       = "";
            TB_Quantity.Text    = "";
            lbl_Success.Visible = true;
        }