Пример #1
0
 private void btnAdd_Click(object sender, EventArgs e)
 {
     if (!ValidateInputData())
     {
         return;
     }
     try
     {
         bool result = DataBaseAccess.AddProduct(
             txtProductName.Text,
             Convert.ToInt32(textProductQuantity.Text),
             Convert.ToDouble(textProductPrice.Text),
             DataBaseAccess.GetCategoryByName(comboBoxCategory.Text)
             );
         if (result)
         {
             MessageBox.Show("product added successfully", "Success", MessageBoxButtons.OK);
             btnRefresh_Click(sender, e);
         }
         else
         {
             throw new Exception();
         }
     }
     catch (Exception)
     {
         MessageBox.Show("Falid to add product please try again", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }
Пример #2
0
        protected void btnInsertProd_Click(object sender, EventArgs e)
        {
            var pDesc  = prodDescript.Text;
            var pPrice = prodPrice.Text;
            var pStock = prodStock.Text;

            int numb;

            decimal dec;

            if (!decimal.TryParse(pPrice, out dec))
            {
                Response.Redirect("ManageProducts.aspx");
            }

            if (!int.TryParse(pStock, out numb))
            {
                Response.Redirect("ManageProducts.aspx");
            }

            var price = Convert.ToDecimal(pPrice);
            var stock = Convert.ToInt32(pStock);



            var result = DataBaseAccess.AddProduct(pDesc, price, stock);


            if (result)
            {
                Response.Redirect("ManageProducts.aspx");
            }
            else
            {
                divModal.Visible = true;
            }

            LoadData();
        }