Example #1
0
        protected void btnUpdate_Click(object sender, EventArgs e)
        {
            bool        passRequirements = true;
            int         producttypeid    = Convert.ToInt32(txtProductTypeId.Text);
            ProductType pt2             = ProductTypeRepository.FindProductTypeById(producttypeid);
            String      producttypename = txtProductTypeName.Text;
            ProductType pt = ProductTypeRepository.FindProductTypeByName(producttypename);

            if (txtProductTypeId.Text == "" || pt2 == null)
            {
                warningProductTypeId.Visible = true;
                passRequirements             = false;
            }
            if (txtProductTypeName.Text == "" || producttypename.Length < 5 || pt != null)
            {
                passRequirements = false;
                warningProductTypeName.Visible = true;
            }
            if (txtDescription.Text == "")
            {
                passRequirements           = false;
                warningDescription.Visible = true;
            }
            if (passRequirements == true)
            {
                String description = txtDescription.Text;

                ProductTypeRepository.Update(producttypeid, producttypename, description);

                Response.Redirect("Home.aspx");
            }
        }
        protected void btnDeleteProductType_Click(object sender, EventArgs e)
        {
            int         producttypeid = Convert.ToInt32(txtProductTypeId.Text);
            ProductType pt            = ProductTypeRepository.FindProductTypeById(producttypeid);
            Product     p             = ProductRepository.FindProductByType(producttypeid);

            if (pt == null || txtProductTypeId.Text == "" || p != null)
            {
                warningProductTypeId.Visible = true;
            }
            else
            {
                ProductTypeRepository.Delete(producttypeid);
                Response.Redirect("ViewProductType.aspx");
            }
        }
Example #3
0
        protected void btnInsert_Click(object sender, EventArgs e)
        {
            bool        passRequirements = true;
            int         producttypeid    = Convert.ToInt32(txtProductTypeId.Text);
            ProductType pt    = ProductTypeRepository.FindProductTypeById(producttypeid);
            int         price = Convert.ToInt32(txtPrice.Text);
            int         stock = Convert.ToInt32(txtStock.Text);

            if (txtProductTypeId.Text == "" || pt == null)
            {
                passRequirements             = false;
                warningProductTypeId.Visible = true;
            }
            if (txtProductName.Text == "")
            {
                passRequirements           = false;
                warningProductName.Visible = true;
            }
            if (txtPrice.Text == "" || price < 1000 || price % 1000 != 0)
            {
                passRequirements     = false;
                warningPrice.Visible = true;
            }
            if (txtStock.Text == "" || stock < 1)
            {
                passRequirements     = false;
                warningStock.Visible = true;
            }
            if (passRequirements == true)
            {
                String productname = txtProductName.Text;


                Product newProduct = ProductFactory.CreateProduct(producttypeid, productname, price, stock);
                ProductRepository.Create(newProduct);

                Response.Redirect("Home.aspx");
            }
        }