public void ud()
    {
        foreach (RepeaterItem i in Repeater3.Items)
        {
            FileUpload fu  = (FileUpload)i.FindControl("FileUpload1");
            Label      lbl = (Label)i.FindControl("lblIDIMG");
            if (fu.HasFile)
            {
                if (!ck.CheckFileType(fu.FileName))
                {
                    tam = 1;
                    break;
                }
            }
        }
        if (FileUploadMore.HasFile)
        {
            foreach (var file1 in FileUploadMore.PostedFiles)
            {
                if (!ck.CheckFileType(file1.FileName))
                {
                    tam = 1;
                    break;
                }
            }
        }
        if (tam == 0)
        {
            foreach (RepeaterItem i in Repeater3.Items)
            {
                FileUpload fu  = (FileUpload)i.FindControl("FileUpload1");
                Label      lbl = (Label)i.FindControl("lblIDIMG");
                if (fu.HasFile)
                {
                    int    n111     = Convert.ToInt32(lbl.Text);
                    string fileName = "images/product-category/" + fu.FileName;
                    string filePath = MapPath(fileName);
                    fu.SaveAs(filePath);
                    product_image ima = cl.getImage(n111);
                    ima.img_url = fu.FileName;
                    cl.UpdateimgProd(ima);
                }
            }
            if (FileUploadMore.HasFile)
            {
                foreach (var file1 in FileUploadMore.PostedFiles)
                {
                    string fileName = "images/product-category/" + file1.FileName;
                    string filePath = MapPath(fileName);
                    file1.SaveAs(filePath);
                    ip1         = new product_image();
                    ip1.id_prod = p.id_pro;
                    ip1.img_url = file1.FileName;
                    cl.AddimgProd(ip1);
                }
            }

            if ((int)ViewState["bf"] == 1)
            {
                p.id_cat        = idCate;
                ViewState["bf"] = 0;
            }
            if (ck.checkstringnull(txtName.Text.Trim()))
            {
                if (ck.checkstringnull(txtPrice.Text.Trim()))
                {
                    if (ck.checknumber(txtPrice.Text.Trim()))
                    {
                        if (ck.checkstring(txtName.Text.Trim(), 50))
                        {
                            if (p.pro_name == txtName.Text.Trim())
                            {
                                p.pro_name  = txtName.Text.Trim();
                                p.pro_price = float.Parse(txtPrice.Text.Trim());
                                cl.UpdateProduct(p);
                                load_pro();
                            }
                            else
                            {
                                if (cl.checkalprod(txtName.Text.Trim()))
                                {
                                    p.pro_name  = txtName.Text.Trim();
                                    p.pro_price = float.Parse(txtPrice.Text.Trim());
                                    cl.UpdateProduct(p);
                                    load_pro();
                                }
                                else
                                {
                                    ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert('Product Name Already Exist')", true);
                                }
                            }
                        }
                        else
                        {
                            ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert('Product Name Too Long')", true);
                        }
                    }
                    else
                    {
                        ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert('Product Price Is Incorrect')", true);
                    }
                }
                else
                {
                    ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert('Please Type Product Price')", true);
                }
            }
            else
            {
                ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert('Please Type Product Name')", true);
            }
        }
        else
        {
            ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert('Many Images Too Large Or Not Format(.jpg|.png|.gif)')", true);
            load_pro();
            loadCate();
        }
    }
Example #2
0
 protected void btnAddPro_Click(object sender, EventArgs e)
 {
     if (FileU.HasFile)
     {
         foreach (var file in FileU.PostedFiles)
         {
             if (!ck.CheckFileType(file.FileName))
             {
                 tam = 1;
                 break;
             }
         }
         if (tam == 0)
         {
             int dem = 0;
             pr = new category_product_detail();
             if ((int)ViewState["bf"] == 1)
             {
                 pr.id_cat       = idCate;
                 ViewState["bf"] = 0;
             }
             else
             {
                 drCate.SelectedIndex = 0;
                 pr.id_cat            = Convert.ToInt32(drCate.SelectedItem.Value);
             }
             if (ck.checkstringnull(tbName1.Text))
             {
                 if (ck.checkstringnull(tbPrice1.Text))
                 {
                     if (ck.checknumber(tbPrice1.Text))
                     {
                         if (ck.checkstring(tbName1.Text, 50))
                         {
                             if (cl.checkalprod(tbName1.Text.Trim()))
                             {
                                 pr.pro_name  = tbName1.Text.Trim();
                                 pr.pro_price = float.Parse(tbPrice1.Text.Trim());
                                 cl.AddProduct(pr);
                                 foreach (var file in FileU.PostedFiles)
                                 {
                                     string fileName = "images/product-category/" + file.FileName;
                                     string filePath = MapPath(fileName);
                                     file.SaveAs(filePath);
                                     ip            = new product_image();
                                     ip.id_prod    = pr.id_pro;
                                     ip.img_url    = file.FileName;
                                     imgS.ImageUrl = ip.img_url;
                                     if (dem == 0)
                                     {
                                         ip.sub_img = 1;
                                     }
                                     else
                                     {
                                         ip.sub_img = 0;
                                     }
                                     dem++;
                                     cl.AddimgProd(ip);
                                 }
                             }
                             else
                             {
                                 ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert('Product Name Already Exist')", true);
                             }
                         }
                         else
                         {
                             ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert('Product Name Too Long')", true);
                         }
                     }
                     else
                     {
                         ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert('Product Price Is Incorrect')", true);
                     }
                 }
                 else
                 {
                     ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert('Please Type Product Price')", true);
                 }
             }
             else
             {
                 ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert('Please Type Product Name')", true);
             }
         }
         else
         {
             ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert('Image File Too Large Or Not Format(.jpg|.png|.gif)')", true);
         }
     }
     else
     {
         ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert('Please Choose Image')", true);
     }
     load_Prod();
     loadCate();
     clearall();
 }