Beispiel #1
0
        public void updateProduct(string productID, string productname, string gender, string productFamilyId, string productdescription, string price, string quantity, string size, string color, string visibility, string productCat_Sub_ID, string brandID, string collection, string images, string email, string clientID, string fileNames1, string ecommecelink, string imgIDs, string productSKU, string masterPwd)
        {
            try
            {
                int productCategoryID = Convert.ToInt32(productCat_Sub_ID.Split('_')[1]);
                int productSubCategoryID = Convert.ToInt32(productCat_Sub_ID.Split('_')[0]);
                int pro_ID = 0;
                if (productID != "")
                    pro_ID = Convert.ToInt32(productID);
                MySQLBusinessLogic bl = new MySQLBusinessLogic();
                List<string> lstImgID = new List<string>();
                List<string> lstImgPath = new List<string>();
                List<string> lstImgOrgPath = new List<string>();
                DataTable dt = bl.GetStoreID(email);
                int storeID = Convert.ToInt32(dt.Rows[0].ItemArray[0]);
                int result = bl.UpdateProduct(pro_ID, productname, gender, Convert.ToInt32(productFamilyId), productdescription, Convert.ToDouble(price), quantity, size, color, Convert.ToInt32(visibility), productCategoryID, productSubCategoryID, Convert.ToInt32(brandID), collection, storeID, DateTime.Now, email, ecommecelink, productSKU, masterPwd);
                if (fileNames1 != "")
                {
                    //List<byte[]> lstb = new List<byte[]>();
                    //lstb = ImageUpload(images, fileNames1);

                    var fileNames = fileNames1.Split(',');
                    var fileimages = images.Split(',');
                    byte[] PrvImg = null;
                    List<byte[]> lstByte = new List<byte[]>();
                    string rootPath = System.Configuration.ConfigurationManager.AppSettings.GetValues("RootPath").First().ToString();
                    string rp = rootPath;
                    rootPath += storeID.ToString() + "\\";
                    var imageIDs = imgIDs.Split(',');
                    for (int i = 0; i < fileNames.Length; i++)
                    {

                        string fileName = fileNames[i];
                        string encodedFileName = fileimages[i];
                        if (fileName != encodedFileName)
                        {
                            fileName = Regex.Replace(fileName.Substring(0, fileName.LastIndexOf('.')), "[.;]", "_") + fileName.Substring(fileName.LastIndexOf('.'), (fileName.Length - fileName.LastIndexOf('.')));
                            //if (File.Exists(rootPath + fileName))
                            //    File.Delete(rootPath + fileName);
                            //System.IO.File.Move(rootPath + encodedFileName, rootPath + fileName);
                            if (File.Exists(rp + fileName))
                                File.Delete(rp + fileName);
                            System.IO.File.Move(rp + encodedFileName, rootPath + fileName);

                            //if (imageIDs.Contains("image1"))
                            //{

                            //    Image image = Image.FromFile(rootPath + fileName);
                            //    Image thumb = image.GetThumbnailImage(100, 100, () => false, IntPtr.Zero);
                            //    thumb.Save(Path.ChangeExtension(rootPath + fileName.Split('.')[0], "thumb"));
                            //    System.IO.File.Move(rootPath + fileName.Split('.')[0] + ".thumb", rootPath + "New" + fileName);
                            //    FileStream fs1 = new FileStream(rootPath + "New" + fileName, FileMode.Open, FileAccess.Read);
                            //    BinaryReader br1 = new BinaryReader(fs1);
                            //    PrvImg = br1.ReadBytes((int)fs1.Length);
                            //    br1.Close();
                            //    fs1.Close();
                            //    //File.Delete(rootPath + "New" + fileName);
                            //}

                        }
                        //test image save code
                        string FileName = rootPath + fileName;
                        byte[] ImageData;
                        FileStream fs = new FileStream(rootPath + fileName, FileMode.Open, FileAccess.Read);
                        using (var image1 = Image.FromStream(fs))
                        {
                            var newWidth = (int)(image1.Width * 0.9);
                            var newHeight = (int)(image1.Height * 0.9);
                            var thumbnailImg = new Bitmap(newWidth, newHeight);
                            var thumbGraph = Graphics.FromImage(thumbnailImg);
                            thumbGraph.CompositingQuality = CompositingQuality.HighQuality;
                            thumbGraph.SmoothingMode = SmoothingMode.HighQuality;
                            thumbGraph.InterpolationMode = InterpolationMode.HighQualityBicubic;
                            var imageRectangle = new Rectangle(0, 0, newWidth, newHeight);
                            thumbGraph.DrawImage(image1, imageRectangle);
                            thumbnailImg.Save(rootPath + "New" + fileName, image1.RawFormat);
                            FileStream fs2 = new FileStream(rootPath + "New" + fileName, FileMode.Open, FileAccess.Read);
                            BinaryReader br = new BinaryReader(fs2);
                            ImageData = br.ReadBytes((int)fs2.Length);
                            br.Close();
                            fs2.Close();
                        }
                        fs.Close();
                        //Image image1 = Image.FromFile(rootPath + fileName);
                        //Image thumb1 = image1.GetThumbnailImage(image1.Width, image1.Height, () => false, IntPtr.Zero);
                        //thumb1.Save(Path.ChangeExtension(rootPath + fileName.Split('.')[0], "thumb"));
                        //System.IO.File.Move(rootPath + fileName.Split('.')[0] + ".thumb", rootPath + "New" + fileName);
                        //FileStream fs = new FileStream(rootPath + "New" + fileName, FileMode.Open, FileAccess.Read);
                        //BinaryReader br = new BinaryReader(fs);
                        //ImageData = br.ReadBytes((int)fs.Length);
                        //br.Close();
                        //fs.Close();
                        lstImgPath.Add(rootPath + "New" + fileName);
                        lstImgOrgPath.Add(rootPath + fileName);
                        lstImgID.Add(imageIDs[i]);
                        //File.Delete(rootPath + "New" + fileName);
                        //File.Delete(rootPath + fileName);
                        if (ImageData.Length < 16777216)
                            lstByte.Add(ImageData);
                    }

                    if (lstByte.Count > 0)
                    {
                        DataTable dtImg = new DataTable();
                        dtImg = bl.GetProductImagePaths(pro_ID,storeID);
                        for (int i = 0; i < lstByte.Count; i++)
                        {
                            bool IsUpdate = false;
                            for (int k = 0; k < dtImg.Rows.Count; k++)
                            {
                                if (imageIDs[i] == dtImg.Rows[k].ItemArray[0].ToString()) {
                                    if (File.Exists(dtImg.Rows[k].ItemArray[2].ToString()))
                                        File.Delete(dtImg.Rows[k].ItemArray[2].ToString());
                                    if (File.Exists(dtImg.Rows[k].ItemArray[1].ToString()))
                                        File.Delete(dtImg.Rows[k].ItemArray[1].ToString());
                                    IsUpdate = true;
                                }
                            }
                            bl.UpdateProducts_Image(lstByte[i], pro_ID, imageIDs[i], PrvImg,lstImgPath[i],lstImgOrgPath[i],IsUpdate);
                        }
                    }
                }
                if (size != "" || color != "" || collection != "")
                {
                    if (bl.DeleteProductSpectication(pro_ID))
                    {
                        bl.AddSpecification(email, color, size, collection);
                    }
                }
                if (result == 1)
                    Clients.Client(clientID).productUpdated("1");
                else
                    Clients.Client(clientID).productUpdated("0");

            }
            catch (Exception ex)
            {
                Clients.Client(clientID).addedProduct("0");
            }
        }
Beispiel #2
0
        public void getProductDetails(string email, string productID, string isDuplicate, string clientID)
        {
            try
            {
                int prod_ID = 0;
                if (productID != "")
                    prod_ID = Convert.ToInt32(productID);
                MySQLBusinessLogic bl = new MySQLBusinessLogic();
                DataTable dtStore = bl.GetStoreID(email);
                int storeID = Convert.ToInt32(dtStore.Rows[0].ItemArray[0]);

                DataTable dt = new DataTable();
                dt = bl.GetProductDetails(storeID, prod_ID);

                DataTable dtImage = new DataTable();
                DataTable dtImgPaths = new DataTable();
                //if (prod_ID != 0)
                string json2 = "";
                string ImageData = "";
                if (isDuplicate == "false")
                {
                    //dtImage = bl.GetProductImageDetails(storeID, prod_ID);
                    dtImgPaths = bl.GetProductImagePaths(prod_ID,storeID);
                }
                string js3 = "";
                if (dt.Rows.Count > 0)
                {
                    string json = ConvertDataTabletoString(dt);

                    //
                    if (prod_ID != 0)
                    {
                        for (int k = 0; k < dtImgPaths.Rows.Count; k++)
                        {
                            js3 += ",\"" + dtImgPaths.Rows[k].ItemArray[1].ToString().Split('\\')[dtImgPaths.Rows[k].ItemArray[1].ToString().Split('\\').Length - 2] + "/" + dtImgPaths.Rows[k].ItemArray[1].ToString().Split('\\').Last() + "\"";
                            //js3 += ",\"" + dtImgPaths.Rows[k].ItemArray[1].ToString().Replace('\\', '/') + "\"";
                        }
                    }
                    else
                    {
                        for (int k = 0; k < dtImgPaths.Rows.Count; k++)
                        {
                            json2 += ",\"" + dtImgPaths.Rows[k].ItemArray[1].ToString().Split('\\')[dtImgPaths.Rows[k].ItemArray[1].ToString().Split('\\').Length - 2] + "/" + dtImgPaths.Rows[k].ItemArray[1].ToString().Split('\\').Last() + "\"";
                            //json2 += ",\"" + dtImgPaths.Rows[k].ItemArray[1].ToString().Replace('\\','/')+ "\"";
                        }
                    }

                    //
                    if (dtImage.Rows.Count > 0)
                    {
                        if (prod_ID != 0)
                        {
                            //for (int i = 0; i < dtImage.Columns.Count; i++)
                            //{
                            //    if (dtImage.Rows[0].ItemArray[i].GetType().Name != "DBNull")
                            //    {
                            //        byte[] bytes = (Byte[])dtImage.Rows[0].ItemArray[i];
                            //        if (bytes.Length < 16777216)
                            //        {
                            //            string base64String = Convert.ToBase64String(bytes, 0, bytes.Length);
                            //            string ImageUrl = "data:image/png;base64," + base64String;
                            //            json2 += ", \"" + ImageUrl + "\"";

                            //        }
                            //        else
                            //            json2 += ",\"NoImage\"";
                            //    }
                            //    else
                            //    {
                            //        json2 += ",\"NoImage\"";
                            //    }
                            //}
                        }
                        else
                        {
                            //for (int i = 0; i < dtImage.Rows.Count; i++)
                            //{
                            //    if (dtImage.Rows[i].ItemArray[0].GetType().Name != "DBNull")
                            //    {
                            //        byte[] bytes = (Byte[])dtImage.Rows[i].ItemArray[0];
                            //        if (bytes.Length < 16777216)
                            //        {
                            //            string base64String = Convert.ToBase64String(bytes, 0, bytes.Length);
                            //            string ImageUrl = "data:image/png;base64," + base64String;
                            //            json2 += ", \"" + ImageUrl + "\"";
                            //        }
                            //        else
                            //            json2 += ",\"NoImage\"";
                            //    }
                            //    else
                            //    {
                            //        json2 += ",\"NoImage\"";
                            //    }
                            //}
                        }
                    }
                    if (isDuplicate == "false"&&json2!="")
                    {
                        ImageData = "{\"ImageUrl\":[" + json2.Remove(0, 1) + "]}";
                    }
                    else
                    {
                        ImageData = "";
                    }
                    string ImgDataPath = "";
                    if(js3!=null&&js3!="")
                        ImgDataPath = "{\"ImageUrl\":[" + js3.Remove(0, 1) + "]}";

                    Clients.Client(clientID).productDetails(json, ImageData, ImgDataPath);
                }
                else
                {
                    Clients.Client(clientID).productDetails("");
                }
            }
            catch (Exception ex)
            {
                Clients.Client(clientID).productDetails("");
            }
        }
Beispiel #3
0
 public void removeProduct(string productID, string trID, string clientID)
 {
     try
     {
         if (productID != "")
         {
             int pro_id = Convert.ToInt32(productID);
             MySQLBusinessLogic bl = new MySQLBusinessLogic();
             if (bl.RemoveProduct(pro_id))
             {
                 DataTable dt = new DataTable();
                 dt = bl.GetProductImagePaths(pro_id, 0);
                 for (int i = 0; i < dt.Rows.Count; i++)
                 {
                     if (File.Exists(dt.Rows[i].ItemArray[2].ToString()))
                         File.Delete(dt.Rows[i].ItemArray[2].ToString());
                     if (File.Exists(dt.Rows[i].ItemArray[1].ToString()))
                         File.Delete(dt.Rows[i].ItemArray[1].ToString());
                 }
                 Clients.Client(clientID).removedProduct("1", trID);
             }
             else
             {
                 Clients.Client(clientID).removedProduct("0", trID);
             }
         }
     }
     catch (Exception ex)
     {
         Clients.Client(clientID).removedProduct("0", trID);
     }
 }