protected void btnUpload_Click(object sender, EventArgs e)
    {
        if (Page.IsValid)
        {
            productManager objProduct = new productManager();
            ////insert image product
            HttpFileCollection uploadedFiles = Request.Files;
            bool   flg = false;
            string strImagesNameExist = string.Empty;
            string FileNameCount      = string.Empty;

            for (int im = 0; im < uploadedFiles.Count; im++)
            {
                HttpPostedFile userPostedFile = uploadedFiles[im];
                string         name           = userPostedFile.FileName;
                if (name != "null" && name != "")
                {
                    bool   imgFlag   = false;
                    string extension = Path.GetExtension(userPostedFile.FileName).ToString();
                    string name2     = name.Replace(extension, "");
                    string nameBox   = Request.Form["newr" + name2];
                    if (extension.ToLower() == ".png" || extension.ToLower() == ".jpg")
                    {
                        if (nameBox == null)
                        {
                            #region check SKU and ImageName

                            string NameFile = name2;
                            int    prodimageID;

                            string flname = name2.Substring(name2.Length - 1);
                            if (!CommonFunctions.IsValidValue(flname, true, false, false))
                            {
                                name2 = name2.TrimEnd(name2[name2.Length - 1]);
                            }
                            objProduct.sku = name2;
                            int prodId = objProduct.GetSkuCount();
                            int imgcnt = objProduct.GetproductsImageCount(prodId);

                            // for check images exist or not
                            DataTable dtImgname = new DataTable();
                            dtImgname = objProduct.GetProductImageNameByProductId(prodId);  // get the images from productid
                            if (dtImgname.Rows.Count > 0)
                            {
                                for (int ie = 0; ie < dtImgname.Rows.Count; ie++)
                                {
                                    if (Convert.ToString(dtImgname.Rows[ie]["imageName"]) == Convert.ToString(NameFile + ".jpg"))
                                    {
                                        if (strImagesNameExist == "")
                                        {
                                            strImagesNameExist += dtImgname.Rows[ie]["imageName"].ToString();
                                        }
                                        else
                                        {
                                            strImagesNameExist += "," + dtImgname.Rows[ie]["imageName"].ToString();
                                        }
                                        imgFlag = true;
                                        break;
                                    }

                                    // added on 20_12_2016
                                    if (Convert.ToString(dtImgname.Rows[ie]["imageName"]) == Convert.ToString(NameFile + ".png"))
                                    {
                                        if (strImagesNameExist == "")
                                        {
                                            strImagesNameExist += dtImgname.Rows[ie]["imageName"].ToString();
                                        }
                                        else
                                        {
                                            strImagesNameExist += "," + dtImgname.Rows[ie]["imageName"].ToString();
                                        }
                                        imgFlag = true;
                                        break;
                                    }
                                }
                            }

                            if (imgFlag == false)
                            {
                                if (strImagesNameExist == "")
                                {
                                    lblmsg.Visible = false;
                                }

                                objProduct.productId = 0;
                                objProduct.isactive  = 1;
                                //objProduct.imgLabel = NameFile;
                                objProduct.InsertProductImageItem();

                                if (prodId != 0 && imgcnt != 0 && flg == false)                         // if product id and image count both are in the table
                                {
                                    if (imgFlag == false)                                               // if false then updates record other wise display message
                                    {
                                        prodimageID                = objProduct.GetmaximageProductId(); // gat max productimageid
                                        objProduct.productId       = prodId;
                                        objProduct.productImagesId = prodimageID;
                                        objProduct.actualImageName = userPostedFile.FileName;
                                        objProduct.imageName       = UploadImageSKU(userPostedFile, name2, true);
                                        objProduct.isactive        = 1;
                                        objProduct.sortOrder       = 0;
                                        objProduct.imgLabel        = objProduct.imageName;
                                        objProduct.UpdateProductImagetem();
                                    }
                                    else
                                    {
                                        lblmsg.Visible = true;
                                        lblmsgs.Text   = strImagesNameExist + "Images are already exist.";
                                    }
                                }
                                else if (prodId != 0)  // no images avaliable in product images table
                                {
                                    flg                        = true;
                                    prodimageID                = objProduct.GetmaximageProductId(); // gat max productimageid
                                    objProduct.productId       = prodId;
                                    objProduct.productImagesId = prodimageID;
                                    objProduct.actualImageName = userPostedFile.FileName;
                                    objProduct.imageName       = UploadImageSKU(userPostedFile, NameFile, false);
                                    objProduct.isactive        = 1;
                                    objProduct.sortOrder       = 0;
                                    string pr_name = objProduct.GetProductNameByProductid();
                                    objProduct.imgLabel = Server.HtmlEncode(pr_name);
                                    objProduct.UpdateProductImagetem();
                                }
                                else
                                {
                                    prodimageID = objProduct.GetmaximageProductId();   // gat max productimageid
                                    objProduct.productImagesId = prodimageID;
                                    objProduct.actualImageName = userPostedFile.FileName;
                                    objProduct.imageName       = UploadImage(userPostedFile, prodimageID.ToString());
                                    objProduct.imgLabel        = objProduct.imageName;
                                    objProduct.UpdateImage();
                                }
                            }
                            else
                            {
                                //lblmsg.Visible = true;
                                //lblmsgs.Text = strImagesNameExist + "  Images are already exist.";

                                string[] FileMaxId = name.Split('.');
                                string   filesName = UploadImage(userPostedFile, FileMaxId[0].ToString());

                                if (FileNameCount == "")
                                {
                                    FileNameCount = filesName;
                                }
                                else
                                {
                                    FileNameCount += "," + filesName;
                                }

                                lblmsg.Visible = true;
                                lblmsgs.Text   = "image " + FileNameCount + " updates successfully.";
                            }

                            #endregion

                            //int prodimageID = objProduct.GetmaximageProductId();
                            //objProduct.productImagesId = prodimageID;
                            //objProduct.actualImageName = userPostedFile.FileName;
                            ////objProduct.imageName = UploadImage(userPostedFile, prodimageID);
                            ////objProduct.imgLabel = objProduct.imageName;
                            ////objProduct.UpdateImage();
                        }
                        else
                        {
                        }
                    }
                }
            }
            BindProduct();
        }
    }
예제 #2
0
    protected void imgbtnApproveJob_Click(object sender, EventArgs e)
    {
        foreach (GridViewRow row in gvImportjob.Rows)
        {
            if (row.RowType == DataControlRowType.DataRow)
            {
                bool isChecked = row.Cells[0].Controls.OfType <CheckBox>().FirstOrDefault().Checked;
                if (isChecked)
                {
                    string Id = row.Cells[2].Controls.OfType <Label>().FirstOrDefault().Text;

                    productManager objprodct = new productManager();
                    DataTable      dtpro     = new DataTable();
                    try
                    {
                        // get the data from temp table
                        objprodct.id = Convert.ToInt32(Id);
                        dtpro        = objprodct.GetSingleImportInventoryValue();

                        string sku       = null;
                        string inventory = null;

                        //error_code = string.Empty;
                        bool checkValid = false;

                        sku       = Convert.ToString(dtpro.Rows[0]["sku"]);
                        inventory = Convert.ToString(dtpro.Rows[0]["inventory"]);

                        checkValid = checkValidDatatableDataInventory(sku, inventory);
                        if (checkValid == false)
                        {
                            objprodct.FileError           = error_code;
                            objprodct.FileErrorLineNumber = Convert.ToInt32(1);
                            objprodct.updateSingleImportProduct();
                        }
                        else
                        {
                            if (dtpro.Rows.Count > 0)
                            {
                                objprodct.sku       = Convert.ToString(dtpro.Rows[0]["sku"]);
                                objprodct.inventory = Convert.ToInt32(dtpro.Rows[0]["inventory"]);
                            }

                            int count = objprodct.GetSkuCount();

                            if (count > 0)
                            {
                                objprodct.productId = count;
                                objprodct.UpdateInventory();
                                // update status of page
                                objprodct.isStatus = Convert.ToByte(1);
                                objprodct.UpdateTempTableStatus();

                                objprodct.FileError           = error_code;
                                objprodct.FileErrorLineNumber = Convert.ToInt32(0);
                                objprodct.updateSingleImportProduct();
                            }
                            else
                            {
                                lblmsg.Visible = true;
                                lblmsgs.Text   = "SKU dose not exist";
                            }
                        }

                        //gvAdmin.EditIndex = -1;
                        //BindContents();
                    }
                    catch (Exception ex)
                    {
                        // throw ex;
                    }
                    finally { objprodct = null; dtpro = null; }
                }
            }
        }

        BindContents();
    }