protected void btn_Submit_Add_Click(object sender, EventArgs e) { Bookstore_BO bookstorebo = new Bookstore_BO(); int ProductId = Convert.ToInt32(TB_ID_Add.Text); bookstorebo.retrieveProduct(ProductId); Product prodObj = bookstorebo.retrieveProduct(ProductId); if (prodObj != null) { TB_Error_Add.Text = "Product already exist, consider updating instead"; TB_Error_Add.Visible = true; } else { { int count = 0; //validate file upload string filename; if (FileUploadImage.HasFile) { string extension = System.IO.Path.GetExtension(FileUploadImage.FileName); if (extension == ".jpg" || extension == ".png") { filename = FileUploadImage.FileName; FileUploadImage.PostedFile.SaveAs(Server.MapPath("~/Image/") + filename); string ImageURL = "~/Image/" + filename; lbl_Image_Name.Text = ImageURL; //codes to send to BO } else { sb.AppendLine("File has to be .jpg or .png only"); count++; } } else { sb.AppendLine("Please upload an image"); count++; } //validate ID Textbox if (TB_ID_Add.Text.Trim() == "") { sb.AppendLine("Please indicate product ID"); count++; } else if (System.Text.RegularExpressions.Regex.IsMatch(TB_ID_Update.Text, " ^ [0-9]")) { sb.AppendLine("Please enter valid product ID"); count++; } //validate Name Textbox if (TB_Name_Add.Text.Trim() == "") { sb.AppendLine("Please indicate product name"); count++; } //validate Price Textbox if (TB_Price_Add.Text.Trim() == "" || TB_Price_Add.Text.All(Char.IsLetter)) { sb.AppendLine("Please amend product price"); count++; } //validate Education DDL if (Ddl_Edu_Add.SelectedItem.Text == "~Education Level~") { sb.AppendLine("Please indicate Education Level of product"); count++; } //validate Item DDL if (Ddl_Item_Add.SelectedItem.Text == "~Item Type~") { sb.AppendLine("Please indicate product type"); count++; } //validate Quantity if (TB_Quantity_Add.Text == "") { sb.AppendLine("Please enter available quantity of product"); count++; } if (count > 0) { lbl_Message.Text = ""; TB_Error_Add.Visible = true; TB_Error_Add.Text = sb.ToString(); } else { //codes to send to database bookstorebo.uploadProduct(TB_ID_Add.Text, lbl_Image_Name.Text, TB_Name_Add.Text, Convert.ToDouble(TB_Price_Add.Text), Ddl_Edu_Add.SelectedItem.Text, Ddl_Item_Add.SelectedItem.Text, Convert.ToInt32(TB_Quantity_Add.Text), lbl_Any.Text, lbl_AnyType.Text); FileUploadImage.Attributes.Clear(); TB_ID_Add.Text = ""; TB_Name_Add.Text = ""; TB_Price_Add.Text = ""; Ddl_Edu_Add.SelectedIndex = -1; Ddl_Item_Add.SelectedIndex = -1; TB_Quantity_Add.Text = ""; lbl_Message.Visible = true; lbl_Message.Text = "Product has been added successfully!"; TB_Error_Add.Text = ""; TB_Error_Add.Visible = false; } } } }