protected void deleteproducttype_Click(object sender, EventArgs e)
        {
            Int32 deletebyID = 0;

            Int32.TryParse(id.Text.ToString(), out deletebyID);
            bool cekKedua   = RepositoryProduct.CekProductTypeID(deletebyID);
            bool cekPertama = RepositoryProductType.CekID(deletebyID);

            if (cekPertama)
            {
                if (cekKedua)
                {
                    Response.Write("<script>alert('Deleted product type can not have reference to other table.')</script>");
                }
                else
                {
                    RepositoryProductType.DeleteProductType(deletebyID);
                    Response.Write("<script>alert('Delete product type successfully.')</script>");
                    refresh();
                }
            }
            else
            {
                Response.Write("<script>alert('ID does not exists.')</script>");
            }
        }
        protected void newproducttype_Click(object sender, EventArgs e)
        {
            Int32 myid = 0;

            Int32.TryParse(id.Text.ToString(), out myid);
            bool cekid = RepositoryProductType.CekID(myid);

            if (cekid)
            {
                Response.Redirect("InsertNewProductTypePage.aspx?id=" + myid);
            }
            else
            {
                Response.Write("<script>alert('ID does not exists.')</script>");
            }
        }
Пример #3
0
        protected void updateproduct_Click(object sender, EventArgs e)
        {
            Int32 prodtypeid = 0;
            Int32 price      = 0;
            Int32 stock      = 0;
            Int32 ID         = 0;

            Int32.TryParse(producttypeid.Text.ToString(), out ID);
            bool cek = RepositoryProductType.CekID(ID);

            if (cek)
            {
                String name = productname.Text.ToString();
                if (Int32.TryParse(producttypeid.Text.ToString(), out prodtypeid) &&
                    Int32.TryParse(productstock.Text.ToString(), out stock) &&
                    Int32.TryParse(productprice.Text.ToString(), out price) && name != "")
                {
                    if (validation(price, stock))
                    {
                        Int32 myid = Int32.Parse(Request.QueryString["id"]);
                        RepositoryProduct.UpdateProduct(myid, prodtypeid, name, price, stock);
                        Response.Write("<script>alert('Update product successfully.')</script>");
                    }
                    else
                    {
                        Response.Write("<script>alert('Stock must be 1 or more and price must be above 1000 and multiply of 1000.')</script>");
                    }
                }
                else
                {
                    Response.Write("<script>alert('Data can not be null and non numeric value.')</script>");
                }
            }
            else
            {
                Response.Write("<script>alert('Product type id does not exists.')</script>");
            }
        }