protected void btnCart_Click(object sender, EventArgs e)
    {
        InsertProductDetails();

        CartBAL balCart = new CartBAL();
        CartENT entCart = new CartENT();

        if (Session["UserID"] != null)
        {
            entCart.UserID = Convert.ToInt32(Session["UserID"]);
        }

        if (tempProductDetailsID != 0)
        {
            entCart.ProductDetailsID = tempProductDetailsID;
        }

        if (balCart.Insert(entCart))
        {
            lblMessage.Text       = "Add to Cart SuccessFullly";
            divMessage.Visible    = true;
            hlMessage.Text        = "View Cart";
            hlMessage.NavigateUrl = ("~/User/Cart.aspx");
            hlMessage.Visible     = true;
        }
        else
        {
            lblMessage.Text    = balCart.Message;
            divMessage.Visible = true;
        }
    }
示例#2
0
        public CartENT SelectByPK(SqlInt32 CartID, SqlInt32 UserID)
        {
            using (SqlConnection objConn = new SqlConnection(ConnectionString))
            {
                objConn.Open();

                using (SqlCommand objCmd = objConn.CreateCommand())
                {
                    try
                    {
                        #region prepare Command
                        objCmd.CommandType = CommandType.StoredProcedure;
                        objCmd.CommandText = "PR_Cart_SelectByPK";
                        objCmd.Parameters.AddWithValue("@CartID", CartID);
                        objCmd.Parameters.AddWithValue("@UserID", UserID);
                        #endregion prepare Command

                        #region ReadData and Set Controls
                        CartENT entCart = new CartENT();
                        using (SqlDataReader objSDR = objCmd.ExecuteReader())
                        {
                            while (objSDR.Read())
                            {
                                if (!objSDR["ProductDetailsID"].Equals(DBNull.Value))
                                {
                                    entCart.ProductDetailsID = Convert.ToInt32(objSDR["ProductDetailsID"]);
                                }

                                if (!objSDR["Quantity"].Equals(DBNull.Value))
                                {
                                    entCart.Quantity = Convert.ToInt32(objSDR["Quantity"]);
                                }
                            }
                        }
                        return(entCart);

                        #endregion ReadData and Set Controls
                    }
                    catch (SqlException sqlex)
                    {
                        Message = sqlex.InnerException.Message;
                        return(null);
                    }
                    catch (Exception ex)
                    {
                        Message = ex.InnerException.Message;
                        return(null);
                    }
                    finally
                    {
                        if (objConn.State == ConnectionState.Open)
                        {
                            objConn.Close();
                        }
                    }
                }
            }
        }
    protected void gvProductDetails_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName == "Remove")
        {
            if (e.CommandArgument != null)
            {
                ProductDetailsBAL balProductDetails = new ProductDetailsBAL();
                if (balProductDetails.Delete(Convert.ToInt32(e.CommandArgument.ToString().Trim()), Convert.ToInt32(Session["UserID"])))
                {
                    FillProductDetailsGridView();
                }
                else
                {
                    lblMessage.Text    = balProductDetails.Message;
                    divMessage.Visible = true;
                }
            }
        }
        else if (e.CommandName == "AddtoCart")
        {
            if (e.CommandArgument != null)
            {
                CartBAL balCart = new CartBAL();
                CartENT entCart = new CartENT();

                if (Session["UserID"] != null)
                {
                    entCart.UserID = Convert.ToInt32(Session["UserID"]);
                }

                if (e.CommandArgument != null)
                {
                    entCart.ProductDetailsID = Convert.ToInt32(e.CommandArgument.ToString().Trim());
                }

                if (balCart.Insert(entCart))
                {
                    lblMessage.Text    = "Add to Cart Successfully";
                    divMessage.Visible = true;
                    hlMessage.Text     = "View Cart";
                    hlMessage.Visible  = true;
                }
                else
                {
                    lblMessage.Text    = balCart.Message;
                    divMessage.Visible = true;
                }
            }
        }
    }
示例#4
0
        public Boolean Update(CartENT entCart, SqlInt32 CartID, SqlInt32 UserID)
        {
            CartDAL dalCart = new CartDAL();

            if (dalCart.Update(entCart, CartID, UserID))
            {
                return(true);
            }
            else
            {
                Message = dalCart.Message;
                return(false);
            }
        }
示例#5
0
        public Boolean Insert(CartENT entCart)
        {
            CartDAL dalCart = new CartDAL();

            if (dalCart.Insert(entCart))
            {
                return(true);
            }
            else
            {
                Message = dalCart.Message;
                return(false);
            }
        }
示例#6
0
        public Boolean Insert(CartENT entCart)
        {
            using (SqlConnection objConn = new SqlConnection(ConnectionString))
            {
                objConn.Open();

                using (SqlCommand objCmd = objConn.CreateCommand())
                {
                    try
                    {
                        #region prepare Command
                        objCmd.CommandType = CommandType.StoredProcedure;
                        objCmd.CommandText = "PR_Cart_Insert";
                        objCmd.Parameters.Add("@CartID", SqlDbType.Int, 4).Direction    = ParameterDirection.Output;
                        objCmd.Parameters.Add("@UserID", SqlDbType.Int).Value           = entCart.UserID;
                        objCmd.Parameters.Add("@ProductDetailsID", SqlDbType.Int).Value = entCart.ProductDetailsID;
                        #endregion prepare Command

                        objCmd.ExecuteNonQuery();

                        if (objCmd.Parameters["@CartID"] != null)
                        {
                            entCart.CartID = Convert.ToInt32(objCmd.Parameters["@CartID"].Value);
                        }

                        return(true);
                    }
                    catch (SqlException sqlex)
                    {
                        Message = sqlex.InnerException.Message;
                        return(false);
                    }
                    catch (Exception ex)
                    {
                        Message = ex.InnerException.Message;
                        return(false);
                    }
                    finally
                    {
                        if (objConn.State == ConnectionState.Open)
                        {
                            objConn.Close();
                        }
                    }
                }
            }
        }
示例#7
0
        public Boolean Update(CartENT entCart, SqlInt32 CartID, SqlInt32 UserID)
        {
            using (SqlConnection objConn = new SqlConnection(ConnectionString))
            {
                objConn.Open();

                using (SqlCommand objCmd = objConn.CreateCommand())
                {
                    try
                    {
                        #region prepare Command
                        objCmd.CommandType = CommandType.StoredProcedure;
                        objCmd.CommandText = "PR_Cart_Update";
                        objCmd.Parameters.AddWithValue("@CartID", CartID);
                        objCmd.Parameters.AddWithValue("@UserID", UserID);
                        objCmd.Parameters.AddWithValue("@ProductDetailsID", entCart.ProductDetailsID);
                        objCmd.Parameters.AddWithValue("@Quantity", entCart.Quantity);
                        #endregion prepare Command

                        objCmd.ExecuteNonQuery();

                        return(true);
                    }
                    catch (SqlException sqlex)
                    {
                        Message = sqlex.InnerException.Message;
                        return(false);
                    }
                    catch (Exception ex)
                    {
                        Message = ex.InnerException.Message;
                        return(false);
                    }
                    finally
                    {
                        if (objConn.State == ConnectionState.Open)
                        {
                            objConn.Close();
                        }
                    }
                }
            }
        }
示例#8
0
    protected void btnUpdateCart_Click(object sender, EventArgs e)
    {
        CartBAL balCart = new CartBAL();
        CartENT entCart = new CartENT();

        foreach (GridViewRow row in gvCartDetails.Rows)
        {
            int intCartID = int.Parse((row.FindControl("lblCartID") as Label).Text);
            entCart.ProductDetailsID = int.Parse((row.FindControl("lblProductDetailsID") as Label).Text);
            entCart.Quantity         = int.Parse((row.FindControl("txtQuantity") as TextBox).Text);

            if (balCart.Update(entCart, intCartID, Convert.ToInt32(Session["UserID"])))
            {
                FillProductDetailsGridView();
            }
            else
            {
                lblMessage.Text    = balCart.Message;
                divMessage.Visible = true;
            }
        }
    }