protected void btn_Update_Click(object sender, EventArgs e)
        {
            Product product = (Product)Session["Product"];
            int     id      = product.Id;
            string  name    = txt_watchName.Text;
            int     price   = int.Parse(txt_watchPrice.Text);
            int     stock   = int.Parse(txt_stock.Text);
            string  pic     = FileUpload1.FileName;

            if (txt_stock.Text != null && txt_watchName.Text != null && txt_watchPrice.Text != null && !FileUpload1.HasFile)
            {
                if (!pic.EndsWith(".jpg") && !pic.EndsWith(".png"))
                {
                    lbl_error.Text = "File must .png or .jpg";
                }
                else if (stock <= 0)
                {
                    lbl_error.Text = "You must input stock greater than 0";
                }
                else
                {
                    FileUpload1.SaveAs("D:\\DedeAndres-2001544801-Assigment\\UploadProduct\\" + FileUpload1.FileName);
                    string  input      = "D:\\DedeAndres-2001544801-Assigment\\UploadProduct\\" + FileUpload1.FileName;
                    Product newProduct = FactoryProduct.createProduct(name, price, stock, input);
                    RepositProduct.updateProduct(id, newProduct);
                    Response.Redirect("ManageProduct.aspx");
                }
            }
            else
            {
                lbl_error.Text = "You must fill all data";
            }
        }
Esempio n. 2
0
        protected void btn_addProduct_Click(object sender, EventArgs e)
        {
            string watchName  = txt_watchName.Text;
            int    watchPrice = int.Parse(txt_watchPrice.Text);
            int    stock      = int.Parse(txt_stock.Text);
            string img        = FileUpload1.FileName;

            if (watchName != null && txt_watchPrice.Text != null && txt_stock.Text != null && img != null)
            {
                if (!img.EndsWith(".jpg") && !img.EndsWith(".png"))
                {
                    lbl_error.Text = "File must .png or .jpg";
                }
                else if (stock <= 0)
                {
                    lbl_error.Text = "You must input stock greater than 0";
                }
                else
                {
                    FileUpload1.SaveAs("D:\\DedeAndres-2001544801-Assigment\\UploadProduct\\" + FileUpload1.FileName);
                    string input = "D:\\DedeAndres-2001544801-Assigment\\UploadProduct\\" + FileUpload1.FileName;
                    RepositProduct.insertProduct(FactoryProduct.createProduct(watchName, watchPrice, stock, input));
                    Response.Redirect("addProduct.aspx");
                }
            }
            else
            {
                lbl_error.Text = "You must fill all data";
            }
        }
        protected void btn_delete_Click(object sender, EventArgs e)
        {
            int productID = Int32.Parse(((Button)sender).Attributes["ProductID"]);

            RepositProduct.deleteProduct(productID);
            load();
        }
        protected void btn_update_Click1(object sender, EventArgs e)
        {
            int productID = Int32.Parse(((Button)sender).Attributes["ProductID"]);

            Product getProduct = RepositProduct.getProduct(productID);

            Session["Product"] = getProduct;
            Response.Redirect("UpdateProduct.aspx");
        }
 public void load()
 {
     GridView1.DataSource = RepositProduct.getAll();
     GridView1.DataBind();
 }