Ejemplo n.º 1
0
    protected void gvProduct_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName == "DeleteRecord")
        {
            if (e.CommandArgument != null)
            {
                ProductBAL balProduct = new ProductBAL();
                ProductENT entProduct = new ProductENT();

                #region Delete image from folder
                entProduct = balProduct.SelectByPK(Convert.ToInt32(e.CommandArgument.ToString()));
                FileInfo path = new FileInfo(Server.MapPath(entProduct.ProductImage.Value.ToString()));
                path.Delete();
                #endregion Delete image from folder

                if (balProduct.Delete(Convert.ToInt32(e.CommandArgument.ToString().Trim())))
                {
                    FillProductGridView();
                }
                else
                {
                    lblMessage.Text    = balProduct.Message;
                    divMessage.Visible = true;
                }
            }
        }
    }
    private void FillProductDetails(Int32 ProductID)
    {
        ProductENT entProduct = new ProductENT();
        ProductBAL balProduct = new ProductBAL();

        entProduct = balProduct.SelectByPK(ProductID);

        if (!entProduct.Equals(null))
        {
            imgProduct.ImageUrl = entProduct.ProductImage.Value.ToString();
            lblProductName.Text = entProduct.ProductName.Value.ToString();
            lblPrice.Text       = entProduct.Price.Value.ToString();
            lblDescription.Text = entProduct.Description.Value.ToString();

            if (Request.QueryString["CategoryName"] == "T-shirt")
            {
                divTshirt.Visible = true;
            }

            else if (Request.QueryString["CategoryName"] == "Calendar")
            {
                divCalendar.Visible = true;
            }

            else if (Request.QueryString["CategoryName"] == "Canvas")
            {
                divCanvas.Visible = true;
            }
        }
    }
    private void FillControls(SqlInt32 ProductID)
    {
        ProductBAL balProduct = new ProductBAL();
        ProductENT entProduct = new ProductENT();

        entProduct = balProduct.SelectByPK(ProductID);

        if (!entProduct.CategoryID.IsNull)
        {
            ddlCategoryID.SelectedValue = entProduct.CategoryID.Value.ToString();
        }

        if (!entProduct.ProductName.IsNull)
        {
            txtProductName.Text = entProduct.ProductName.Value.ToString();
        }

        if (!entProduct.Description.IsNull)
        {
            txtDescription.Text = entProduct.Description.Value.ToString();
        }

        if (!entProduct.Price.IsNull)
        {
            txtPrice.Text = entProduct.Price.Value.ToString();
        }
    }
    private void LoadControls(SqlInt32 ProductID)
    {
        ProductENT entProduct = new ProductENT();
        ProductBAL balProduct = new ProductBAL();

        entProduct = balProduct.SelectByPK(ProductID);

        if (!entProduct.ProductName.IsNull)
        {
            txtProductName.Text = entProduct.ProductName.Value.ToString();
        }
    }