Esempio n. 1
0
 //Add new product function
 public void addData()
 {
     try
     {
         if ((GVProducts.FooterRow.FindControl("txtNameFooter") as TextBox).Text == "" || (GVProducts.FooterRow.FindControl("txtTypeFooter") as TextBox).Text == "" || (GVProducts.FooterRow.FindControl("txtPlatformFooter") as TextBox).Text == "" || (GVProducts.FooterRow.FindControl("txtAmountAvailableFooter") as TextBox).Text == "" || (GVProducts.FooterRow.FindControl("txtPriceFooter") as TextBox).Text == "" || (GVProducts.FooterRow.FindControl("txtDescriptionFooter") as TextBox).Text == "")
         {
             lblSuccess.Visible = true;
             lblSuccess.Text    = "Data Missing!";
             populateGV();
             populateDDL();
         }
         else
         {
             BL.Inventory inventory  = new BL.Inventory();
             var          ctrl       = GVProducts.FooterRow.FindControl("fileImgSaveFooter");
             var          fileUpload = (FileUpload)ctrl;
             var          img        = fileUpload.PostedFile.FileName;
             string       image      = img;
             string       imgFile    = Path.GetFileName(image);
             string       folderPath = Server.MapPath("~/Images/");
             fileUpload.SaveAs(folderPath + Path.GetFileName(fileUpload.FileName));
             string name = (GVProducts.FooterRow.FindControl("txtNameFooter") as TextBox).Text.Trim();
             var    selectedCategoryStr = (GVProducts.FooterRow.FindControl("ddlCategoryFooter") as DropDownList).SelectedValue;
             int    selectedCategory    = int.Parse(selectedCategoryStr);
             var    AmntAvStr           = (GVProducts.FooterRow.FindControl("txtAmountAvailableFooter") as TextBox).Text.Trim();
             int    AmountAvailable     = int.Parse(AmntAvStr);
             var    priceString         = (GVProducts.FooterRow.FindControl("txtPriceFooter") as TextBox).Text.Trim();
             int    price    = int.Parse(priceString);
             string type     = (GVProducts.FooterRow.FindControl("txtTypeFooter") as TextBox).Text.Trim();
             string platform = (GVProducts.FooterRow.FindControl("txtPlatformFooter") as TextBox).Text.Trim();
             string desc     = (GVProducts.FooterRow.FindControl("txtDescriptionFooter") as TextBox).Text.Trim();
             inventory.BLAddProducts(name, selectedCategory, type, platform, AmountAvailable, price, desc, image);
             if (lblSuccess.Visible)
             {
                 lblSuccess.Visible = false;
             }
             populateGV();
             populateDDL();
         }
     }
     catch
     {
         lblSuccess.Visible = true;
         lblSuccess.Text    = "Error Adding Data! Ensure Data Is In Correct Format And All Data Is Filled Out!";
         populateGV();
         populateDDL();
     }
 }