Beispiel #1
0
        //Button click changes/updates product details
        protected void EditProduct_Click(object sender, EventArgs e)
        {
            //Get the product id using URL parameter
            String param      = Request.QueryString["ID"];
            int    product_ID = Convert.ToInt32(param);

            //If ID is not null
            if (product_ID > 0)
            {
                //Conversion from String to Integer
                int price    = Convert.ToInt32(ProPrice.Value);
                int maskID   = Convert.ToInt32(ProCategory.Value);
                int quantity = Convert.ToInt32(ProQuantity.Value);

                //Get the current admin logged in
                int admin = Convert.ToInt32(Session["LoggedInUser"]);

                int active = 0;
                //If product is active, change it to 1
                if (ProActive.Value.Equals("1"))
                {
                    active = 1;
                }
                else
                {
                    active = 0;
                }

                string edit = SR.Editproduct(ProName.Value, ProDescription.Value, price, product_ID, active, maskID, admin, quantity);

                //if edit is successful
                if (edit.Equals("updated"))
                {
                    Response.Redirect("Home.aspx");
                }
                //if edit is unsuccessful
                else if (edit.Equals("unsuccessful update"))
                {
                    error.Value   = "Product edit changes not saved. ";
                    error.Visible = true;
                }
                //if product doesn't exist.
                else if (edit.Equals("product does not exist"))
                {
                    error.Value   = "Product doesn't exist.";
                    error.Visible = true;
                }
            }
            else
            {
                Response.Redirect("AboutProduct.aspx");
            }
        }