public int GetStoreIDbyPhone(string phone) { int retVal = 0; try { MySQLBusinessLogic bl = new MySQLBusinessLogic(); DataTable dt = new DataTable(); dt = bl.GetStoreID(phone); retVal = Convert.ToInt32(dt.Rows[0].ItemArray[0]); } catch (Exception ex) { retVal = 0; } return retVal; }
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(""); } }
public void addProduct(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 productSKU, string masterPwd) { try { MySQLBusinessLogic bl = new MySQLBusinessLogic(); DataTable dt = bl.GetStoreID(email); int storeID = Convert.ToInt32(dt.Rows[0].ItemArray[0]); int productCategoryID = Convert.ToInt32(productCat_Sub_ID.Split('_')[1]); int productSubCategoryID = Convert.ToInt32(productCat_Sub_ID.Split('_')[0]); List<string> lstImgID = new List<string>(); List<string> lstImgPath = new List<string>(); List<string> lstImgOrgPath = new List<string>(); 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() + "\\"; 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(rp + fileName)) File.Delete(rp + fileName); System.IO.File.Move(rp + encodedFileName, rootPath + fileName); //if (i == 0) //{ // 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 + "Thumb" + fileName); // FileStream fs1 = new FileStream(rootPath + "Thumb" + fileName, FileMode.Open, FileAccess.Read); // BinaryReader br1 = new BinaryReader(fs1); // PrvImg = br1.ReadBytes((int)fs1.Length); // br1.Close(); // fs1.Close(); //// File.Delete(rootPath + "Thumb" + 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(); //File.Delete(rootPath + "New" + fileName); lstImgPath.Add(rootPath + "New" + fileName); lstImgOrgPath.Add(rootPath + fileName); lstImgID.Add("image" + (i + 1)); //File.Delete(rootPath + fileName); if (ImageData.Length < 16777216) lstByte.Add(ImageData); } //int brandID = 0; //brandID = bl.GetBrandNameID(brand); //if (brandID == 0) //{ // brandID = bl.InsertBrandandGetID(brand); //} int retVal = bl.AddProduct(productname, gender, Convert.ToInt32(productFamilyId), productdescription, Convert.ToDouble(price), quantity, size, color, Convert.ToInt32(visibility), productCategoryID, productSubCategoryID, Convert.ToInt32(brandID), collection, images, storeID, DateTime.Now, email, lstByte, PrvImg, ecommecelink, productSKU, masterPwd,lstImgID,lstImgPath,lstImgOrgPath); if (size != "" || color != "" || collection != "") { bl.AddSpecification(email, color, size, collection); } if (retVal == 1) Clients.Client(clientID).addedProduct("1"); else Clients.Client(clientID).addedProduct("0"); } catch (Exception ex) { Clients.Client(clientID).addedProduct("0"); } }
public void isLimitReached(string phone, string clientID) { try { MySQLBusinessLogic bl = new MySQLBusinessLogic(); DataTable dt = bl.GetStoreID(phone); int storeID = Convert.ToInt32(dt.Rows[0].ItemArray[0]); int result = bl.ProductLimitReached(retailerProductLimit, phone, storeID); // 1- Limit reached // 2- about to reach - nearby // 3- not reached limit if (result == 1) Clients.Client(clientID).limitReached("1", retailerProductLimit); else if (result == 2) Clients.Client(clientID).limitReached("2", retailerProductLimit); else if (result == 3) Clients.Client(clientID).limitReached("3", retailerProductLimit); else Clients.Client(clientID).limitReached("0", retailerProductLimit); } catch (Exception ex) { Clients.Client(clientID).limitReached("0"); //LogFile(ex.Message, ex.ToString(), email); } }