/// <summary> /// Occurs when the Product Update Button is Clicked /// Level: External /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void btnUpdate_Click(object sender, EventArgs e) { try { if (Page.IsValid) { lblImageError.Text = ""; lblErrorDisplay.Text = " "; Tuple <string, UploadResult> myResult = new UploadImage().Upload(fuImage); string PreviousURL = new ProductsLogic().RetrieveProductByID(gvProducts.SelectedValue.ToString()).ImageURL; string ProductID = gvProducts.SelectedValue.ToString(); string Name = txtName.Text; string Description = txtDescription.Text; bool Status = Convert.ToBoolean(ddlStatus.SelectedValue); int CategoryID = Convert.ToInt32(ddlCategory.SelectedValue); int SupplierID = Convert.ToInt32(ddlSupplier.SelectedValue); int ReorderLevel = Convert.ToInt32(txtReorderLevel.Text); double VatRate = Convert.ToDouble(txtVatRate.Text); string ImageURL = null; if (myResult.Item2 == UploadResult.InvalidExtension) { lblImageError.Text = "Invalid Image Extension"; } else if (myResult.Item2 == UploadResult.NoImageFound) { new ProductsLogic().UpdateProduct(ProductID, Name, Description, ImageURL, Status, CategoryID, VatRate, SupplierID, ReorderLevel); gvProducts.DataSource = new ProductsLogic().RetrieveAllProducts(); gvProducts.DataBind(); } else { File.Delete(Server.MapPath(PreviousURL)); ImageURL = myResult.Item1; new ProductsLogic().UpdateProduct(ProductID, Name, Description, ImageURL, Status, CategoryID, VatRate, SupplierID, ReorderLevel); gvProducts.DataSource = new ProductsLogic().RetrieveAllProducts(); gvProducts.DataBind(); imgProduct.ImageUrl = Page.ResolveClientUrl(ImageURL); } } } catch (Exception Exception) { throw Exception; } }
/// <summary> /// Occurs when The Product Add Button is Clicked /// Level: External /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void btnAdd_Click(object sender, EventArgs e) { try { if (Page.IsValid) { lblImageError.Text = ""; lblErrorDisplay.Text = " "; Tuple <string, UploadResult> myResult = new UploadImage().Upload(fuImage); if (myResult.Item2 == UploadResult.InvalidExtension) { lblImageError.Text = "Invalid Image Extension"; } else if (myResult.Item2 == UploadResult.NoImageFound) { lblImageError.Text = "No Image Found"; } else { string Name = txtName.Text; string Description = txtDescription.Text; bool Status = Convert.ToBoolean(ddlStatus.SelectedValue); int CategoryID = Convert.ToInt32(ddlCategory.SelectedValue); int SupplierID = Convert.ToInt32(ddlSupplier.SelectedValue); double VatRate = Convert.ToDouble(txtVatRate.Text); int ReorderLevel = Convert.ToInt32(txtReorderLevel.Text); string ImageURL = myResult.Item1; new ProductsLogic().AddProduct(Name, Status, Description, ImageURL, CategoryID, VatRate, SupplierID, ReorderLevel); gvProducts.DataSource = new ProductsLogic().RetrieveAllProducts(); gvProducts.DataBind(); gvProducts.SelectedIndex = -1; txtName.Text = ""; txtDescription.Text = ""; txtVatRate.Text = ""; txtReorderLevel.Text = ""; ddlStatus.SelectedValue = "true"; ddlSupplier.SelectedValue = "0"; ddlCategory.SelectedValue = "0"; } } } catch (Exception Exception) { throw Exception; } }
/// <summary> /// Occurs when The Product Add Button is Clicked /// Level: External /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void btnAdd_Click(object sender, EventArgs e) { try { if (Page.IsValid) { lblImageError.Text = ""; lblErrorDisplay.Text = " "; Tuple<string, UploadResult> myResult = new UploadImage().Upload(fuImage); if (myResult.Item2 == UploadResult.InvalidExtension) { lblImageError.Text = "Invalid Image Extension"; } else if (myResult.Item2 == UploadResult.NoImageFound) { lblImageError.Text = "No Image Found"; } else { string Name = txtName.Text; string Description = txtDescription.Text; bool Status = Convert.ToBoolean(ddlStatus.SelectedValue); int CategoryID = Convert.ToInt32(ddlCategory.SelectedValue); int SupplierID = Convert.ToInt32(ddlSupplier.SelectedValue); double VatRate = Convert.ToDouble(txtVatRate.Text); int ReorderLevel = Convert.ToInt32(txtReorderLevel.Text); string ImageURL = myResult.Item1; new ProductsLogic().AddProduct(Name, Status, Description, ImageURL, CategoryID, VatRate, SupplierID, ReorderLevel); gvProducts.DataSource = new ProductsLogic().RetrieveAllProducts(); gvProducts.DataBind(); gvProducts.SelectedIndex = -1; txtName.Text = ""; txtDescription.Text = ""; txtVatRate.Text = ""; txtReorderLevel.Text = ""; ddlStatus.SelectedValue = "true"; ddlSupplier.SelectedValue = "0"; ddlCategory.SelectedValue = "0"; } } } catch (Exception Exception) { throw Exception; } }
/// <summary> /// Occurs when the Product Update Button is Clicked /// Level: External /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void btnUpdate_Click(object sender, EventArgs e) { try { if (Page.IsValid) { lblImageError.Text = ""; lblErrorDisplay.Text = " "; Tuple<string, UploadResult> myResult = new UploadImage().Upload(fuImage); string PreviousURL = new ProductsLogic().RetrieveProductByID(gvProducts.SelectedValue.ToString()).ImageURL; string ProductID = gvProducts.SelectedValue.ToString(); string Name = txtName.Text; string Description = txtDescription.Text; bool Status = Convert.ToBoolean(ddlStatus.SelectedValue); int CategoryID = Convert.ToInt32(ddlCategory.SelectedValue); int SupplierID = Convert.ToInt32(ddlSupplier.SelectedValue); int ReorderLevel = Convert.ToInt32(txtReorderLevel.Text); double VatRate = Convert.ToDouble(txtVatRate.Text); string ImageURL = null; if (myResult.Item2 == UploadResult.InvalidExtension) { lblImageError.Text = "Invalid Image Extension"; } else if (myResult.Item2 == UploadResult.NoImageFound) { new ProductsLogic().UpdateProduct(ProductID, Name, Description, ImageURL, Status, CategoryID, VatRate, SupplierID, ReorderLevel); gvProducts.DataSource = new ProductsLogic().RetrieveAllProducts(); gvProducts.DataBind(); } else { File.Delete(Server.MapPath(PreviousURL)); ImageURL = myResult.Item1; new ProductsLogic().UpdateProduct(ProductID, Name, Description, ImageURL, Status, CategoryID, VatRate, SupplierID, ReorderLevel); gvProducts.DataSource = new ProductsLogic().RetrieveAllProducts(); gvProducts.DataBind(); imgProduct.ImageUrl = Page.ResolveClientUrl(ImageURL); } } } catch (Exception Exception) { throw Exception; } }