protected void BtnUpdate_Click(object sender, EventArgs e)
        {
            if (!ValidateForm())
            {
                return;
            }
            BtnInsert.Visible = false;
            BtnUpdate.Visible = true;

            int    id        = Convert.ToInt32(txtId.Text.Trim());
            string name      = txtName.Text.Trim();
            int    quantity  = Convert.ToInt32(txtQuantity.Text.Trim());
            double price     = Convert.ToDouble(txtPrice.Text.Trim());
            string usage     = txtUsage.Text.Trim();
            int    cateID    = Convert.ToInt32(ddlCategory.SelectedValue);
            int    statusID  = Convert.ToInt32(ddlStatus.SelectedValue);
            string imageLink = txtImageLink.Text.Trim();

            ProductDTO dto    = new ProductDTO(id, name, quantity, price, usage, cateID, statusID, imageLink);
            ProductDAO dao    = new ProductDAO();
            bool       result = dao.UpdateProduct(dto);

            if (result)
            {
                lblMessage.Text = "Update is successful";
                GvProducts.DataBind();
            }
            else
            {
                lblMessage.Text = "Update is failed";
            }
            TxtOk.Text = "OK";
        }
        private void RefreshGridView()
        {
            updateProduct up = new updateProduct();

            upList = up.GetAllProducts();

            GvProducts.Visible    = true;
            GvProducts.DataSource = upList;
            GvProducts.DataBind();
        }
Example #3
0
        protected void Page_Load(object sender, EventArgs e)
        {
            ProductConnectedDao productConnectedDao = new ProductConnectedDao();

            _products = productConnectedDao.ReadAll();
            //Session["ProductList"] = concatImage();
            Session["ProductList"] = _products;
            if (!IsPostBack)
            {
                GvProducts.DataSource = (List <Product>)Session["ProductList"];
                GvProducts.DataBind();
            }
        }
        protected void BtnDelete_Click(object sender, EventArgs e)
        {
            int        id     = Convert.ToInt32(txtId.Text.Trim());
            ProductDAO dao    = new ProductDAO();
            bool       result = dao.DeleteProduct(id);

            if (result)
            {
                lblMessage.Text = "Delete is successful";
                ClearFields();
                GvProducts.DataBind();
                BtnInsert.Enabled = false;
                BtnUpdate.Enabled = false;
                BtnDelete.Enabled = false;
            }
            else
            {
                lblMessage.Text = "Delete is failed";
            }
            TxtOk.Text = "OK";
        }