Esempio n. 1
0
        protected void btnAdd_Click(object sender, EventArgs e)
        {
            string report = isValidImage();

            if (!report.Equals("valid"))
            {
                errorMessage = report;
                ScriptManager.RegisterStartupScript(this, GetType(), "Error", "invalidImage();", true);
            }
            else
            {
                string path = "../Uploads/" + imageUpload.FileName;

                /*
                 * check whether user fill all the required field or not
                 * server-site validation
                 */
                if (IsValid)
                {
                    Product product = new Product
                    {
                        ProductCode        = txtProductCode.Text,
                        ProductName        = txtProductName.Text,
                        ProductCategory    = Convert.ToInt32(ddlProductCategory.SelectedValue),
                        ProductDescription = taProductDesc.InnerText,
                        ProductPrice       = txtProductPrice.Text,
                        ProductImage       = path,
                        ProductCompany     = Convert.ToInt32(ddlProductCompany.SelectedValue),
                        ProductQuantity    = Convert.ToInt32(txtProductQuantity.Text)
                    };

                    ECommerceBusiness ecb = new ECommerceBusiness
                    {
                        ProductObj = product
                    };

                    ecb.AddNewProduct();
                    resetForm();
                    Page.ClientScript.RegisterStartupScript(this.GetType(), "Reg_Conf", "alert('Successfully added a new product into database!')", true);
                }
                else
                {
                    Validation.InnerText = "Please fill up all the necessary fields";
                }
            }
        }