public static string getProduct(string textsearch) { List <ProductGetOut> result = new List <ProductGetOut>(); string username = HttpContext.Current.Request.Cookies["usernameLoginSystem"].Value; var acc = AccountController.GetByUsername(username); if (acc != null) { int AgentID = Convert.ToInt32(acc.AgentID); var product = ProductController.GetBySKU(textsearch.Trim().ToUpper()); if (product != null) { if (product.ProductStyle == 1) { result.Add(_getProduct(product)); } else { var productvariable = ProductVariableController.GetByParentSKU(product.ProductSKU); result.AddRange(_getProductVariation(productvariable, product)); } } else { var productvariable = ProductVariableController.GetAllBySKU(textsearch.Trim().ToUpper()); result.AddRange(_getProductVariation(productvariable)); } } return(JsonConvert.SerializeObject(result)); }
public static string getAllProductImage(string sku) { var product = ProductController.GetBySKU(sku); List<string> images = new List<string>(); if (product != null) { images.Add(product.ProductImage); // lấy ảnh sản phẩm từ thư viện var imageProduct = ProductImageController.GetByProductID(product.ID); if(imageProduct != null) { foreach (var img in imageProduct) { images.Add(img.ProductImage); } } // lấy ảnh sản phẩm từ biến thể var variable = ProductVariableController.GetByParentSKU(product.ProductSKU); if(variable != null) { foreach (var v in variable) { images.Add(v.Image); } } } JavaScriptSerializer serializer = new JavaScriptSerializer(); return serializer.Serialize(images.Distinct().ToList()); }
public static string getProduct(string textsearch) { List <ProductGetOut> ps = new List <ProductGetOut>(); string username = HttpContext.Current.Request.Cookies["userLoginSystem"].Value; var acc = AccountController.GetByUsername(username); if (acc != null) { int AgentID = Convert.ToInt32(acc.AgentID); var products = ProductController.GetBySKU(textsearch.Trim().ToUpper()); if (products != null) { var productvariable = ProductVariableController.GetByParentSKU(products.ProductSKU); if (productvariable.Count > 0) { foreach (var pv in productvariable) { string SKU = pv.SKU.Trim().ToUpper(); var check = StockManagerController.GetBySKU(AgentID, SKU); if (check.Count > 0) { double total = PJUtils.TotalProductQuantityInstock(AgentID, SKU); if (total > 0) { var variables = ProductVariableValueController.GetByProductVariableSKU(pv.SKU); if (variables.Count > 0) { string variablename = ""; string variablevalue = ""; string variable = ""; foreach (var v in variables) { variable += v.VariableName.Trim() + ": " + v.VariableValue.Trim() + "|"; variablename += v.VariableName.Trim() + "|"; variablevalue += v.VariableValue.Trim() + "|"; } ProductGetOut p = new ProductGetOut(); p.ID = pv.ID; p.ProductName = products.ProductTitle; p.ProductVariable = variable; p.ProductVariableName = variablename; p.ProductVariableValue = variablevalue; p.ProductType = 2; var product = ProductController.GetBySKU(pv.ParentSKU); if (!string.IsNullOrEmpty(pv.Image)) { p.ProductImage = "<img src=\"" + pv.Image + "\" />"; p.ProductImageOrigin = pv.Image; } else if (!string.IsNullOrEmpty(product.ProductImage)) { p.ProductImage = "<img src=\"" + product.ProductImage + "\" />"; p.ProductImageOrigin = product.ProductImage; } else { p.ProductImage = "<img src=\"/App_Themes/Ann/image/placeholder.png\" />"; p.ProductImageOrigin = ""; } p.QuantityInstock = total; p.QuantityInstockString = string.Format("{0:N0}", total); p.SKU = SKU; int supplierID = 0; if (pv.SupplierID != null) { supplierID = pv.SupplierID.ToString().ToInt(0); } p.SupplierID = supplierID; string supplierName = ""; if (!string.IsNullOrEmpty(pv.SupplierName)) { supplierName = pv.SupplierName; } p.SupplierName = supplierName; ps.Add(p); } } } } } else { string SKU = products.ProductSKU.Trim().ToUpper(); var check = StockManagerController.GetBySKU(AgentID, SKU); if (check.Count > 0) { double total = PJUtils.TotalProductQuantityInstock(AgentID, SKU); if (total > 0) { string variablename = ""; string variablevalue = ""; string variable = ""; ProductGetOut p = new ProductGetOut(); p.ID = products.ID; p.ProductName = products.ProductTitle; p.ProductVariable = variable; p.ProductVariableName = variablename; p.ProductVariableValue = variablevalue; p.ProductType = 1; var img = ProductImageController.GetFirstByProductID(products.ID); if (!string.IsNullOrEmpty(products.ProductImage)) { p.ProductImage = "<img src=\"" + products.ProductImage + "\" />"; p.ProductImageOrigin = products.ProductImage; } else if (img != null) { p.ProductImage = "<img src=\"" + img.ProductImage + "\" />"; p.ProductImageOrigin = img.ProductImage; } else { p.ProductImage = "<img src=\"/App_Themes/Ann/image/placeholder.png\" />"; p.ProductImageOrigin = ""; } p.SKU = SKU; p.QuantityInstock = total; p.QuantityInstockString = string.Format("{0:N0}", total); int supplierID = 0; if (products.SupplierID != null) { supplierID = products.SupplierID.ToString().ToInt(0); } p.SupplierID = supplierID; string supplierName = ""; if (!string.IsNullOrEmpty(products.SupplierName)) { supplierName = products.SupplierName; } p.SupplierName = supplierName; ps.Add(p); } } } } else { var productvariable = ProductVariableController.GetAllBySKU(textsearch.Trim().ToUpper()); if (productvariable != null) { foreach (var value in productvariable) { string SKU = value.SKU.Trim().ToUpper(); var check = StockManagerController.GetBySKU(AgentID, SKU); if (check.Count > 0) { double total = PJUtils.TotalProductQuantityInstock(AgentID, SKU); if (total > 0) { var variables = ProductVariableValueController.GetByProductVariableSKU(value.SKU); if (variables.Count > 0) { string variablename = ""; string variablevalue = ""; string variable = ""; foreach (var v in variables) { variable += v.VariableName + ": " + v.VariableValue + "|"; variablename += v.VariableName + "|"; variablevalue += v.VariableValue + "|"; } ProductGetOut p = new ProductGetOut(); p.ID = value.ID; var product = ProductController.GetBySKU(value.ParentSKU); if (product != null) { p.ProductName = product.ProductTitle; } p.ProductVariable = variable; p.ProductVariableName = variablename; p.ProductVariableValue = variablevalue; p.ProductType = 2; if (!string.IsNullOrEmpty(value.Image)) { p.ProductImage = "<img src=\"" + value.Image + "\" />"; p.ProductImageOrigin = value.Image; } else if (!string.IsNullOrEmpty(product.ProductImage)) { p.ProductImage = "<img src=\"" + product.ProductImage + "\" />"; p.ProductImageOrigin = product.ProductImage; } else { p.ProductImage = "<img src=\"/App_Themes/Ann/image/placeholder.png\" />"; p.ProductImageOrigin = ""; } p.SKU = value.SKU.Trim().ToUpper(); p.QuantityInstock = total; p.QuantityInstockString = string.Format("{0:N0}", total); int supplierID = 0; if (value.SupplierID != null) { supplierID = value.SupplierID.ToString().ToInt(0); } p.SupplierID = supplierID; string supplierName = ""; if (!string.IsNullOrEmpty(value.SupplierName)) { supplierName = value.SupplierName; } p.SupplierName = supplierName; ps.Add(p); } } } } } } } JavaScriptSerializer serializer = new JavaScriptSerializer(); return(serializer.Serialize(ps)); }
public static string getProduct(string textsearch, int gettotal) { List <ProductGetOut> ps = new List <ProductGetOut>(); string username = HttpContext.Current.Request.Cookies["userLoginSystem"].Value; var acc = AccountController.GetByUsername(username); if (acc != null) { int AgentID = Convert.ToInt32(acc.AgentID); var product = ProductController.GetBySKU(textsearch.Trim().ToUpper()); // Kiểm tra sản phẩm có trong table Product không? if (product != null) // Nếu sản phẩm có trong table Product thì... { var productvariable = ProductVariableController.GetByParentSKU(product.ProductSKU); // Kiểm tra sản phẩm cha là variable hay simple? if (productvariable.Count > 0) // Nếu sản phẩm cha là variable thì... { foreach (var pv in productvariable) { string SKU = pv.SKU.Trim().ToUpper(); var variables = ProductVariableValueController.GetByProductVariableSKU(pv.SKU); if (variables.Count > 0) { string variablename = ""; string variablevalue = ""; string variable = ""; string variablesave = ""; foreach (var v in variables) { variable += v.VariableName.Trim() + ": " + v.VariableValue.Trim() + "<br/>"; variablesave += v.VariableName.Trim() + ": " + v.VariableValue.Trim() + "|"; variablename += v.VariableName.Trim() + "|"; variablevalue += v.VariableValue.Trim() + "|"; } ProductGetOut p = new ProductGetOut(); p.ID = pv.ID; p.ProductName = product.ProductTitle; p.ProductVariable = variable; p.ProductVariableSave = variablesave; p.ProductVariableName = variablename; p.ProductVariableValue = variablevalue; p.ProductType = 2; if (!string.IsNullOrEmpty(pv.Image)) { p.ProductImage = "<img src=\"" + pv.Image + "\" />"; p.ProductImageOrigin = pv.Image; } else if (!string.IsNullOrEmpty(product.ProductImage)) { p.ProductImage = "<img src=\"" + product.ProductImage + "\" />"; p.ProductImageOrigin = product.ProductImage; } else { p.ProductImage = "<img src=\"/App_Themes/Ann/image/placeholder.png\" />"; p.ProductImageOrigin = ""; } if (gettotal == 1) { double total = PJUtils.TotalProductQuantityInstock(AgentID, SKU); var mainstock = PJUtils.TotalProductQuantityInstock(1, SKU); p.QuantityMainInstock = mainstock; p.QuantityMainInstockString = string.Format("{0:N0}", mainstock); p.QuantityInstock = total; p.QuantityInstockString = string.Format("{0:N0}", total); } p.SKU = SKU; p.Giabansi = Convert.ToDouble(pv.Regular_Price); p.stringGiabansi = string.Format("{0:N0}", pv.Regular_Price); p.Giabanle = Convert.ToDouble(pv.RetailPrice); p.stringGiabanle = string.Format("{0:N0}", pv.RetailPrice); ps.Add(p); } } } else // Nếu sản phẩm cha là simple thì... { string SKU = product.ProductSKU.Trim().ToUpper(); double mainstock = PJUtils.TotalProductQuantityInstock(1, SKU); ProductGetOut p = new ProductGetOut(); p.ID = product.ID; p.ProductName = product.ProductTitle; p.ProductVariable = ""; p.ProductVariableSave = ""; p.ProductVariableName = ""; p.ProductVariableValue = ""; p.ProductType = 1; if (!string.IsNullOrEmpty(product.ProductImage)) { p.ProductImage = "<img src=\"" + product.ProductImage + "\" />"; p.ProductImageOrigin = product.ProductImage; } else { p.ProductImage = "<img src=\"/App_Themes/Ann/image/placeholder.png\" />"; p.ProductImageOrigin = ""; } p.SKU = SKU; p.QuantityMainInstock = mainstock; p.QuantityMainInstockString = string.Format("{0:N0}", mainstock); p.QuantityInstock = mainstock; p.QuantityInstockString = string.Format("{0:N0}", mainstock); p.Giabansi = Convert.ToDouble(product.Regular_Price); p.stringGiabansi = string.Format("{0:N0}", product.Regular_Price); p.Giabanle = Convert.ToDouble(product.Retail_Price); p.stringGiabanle = string.Format("{0:N0}", product.Retail_Price); ps.Add(p); } } else // Nếu không nằm trong table Product thì... { var productvariable = ProductVariableController.GetBySKU(textsearch.Trim().ToUpper()); // Nếu sản phẩm là con (nằm trong table ProductVariable) thì... if (productvariable != null) { string SKU = productvariable.SKU.Trim().ToUpper(); var variables = ProductVariableValueController.GetByProductVariableSKU(SKU); if (variables.Count > 0) { string variablename = ""; string variablevalue = ""; string variable = ""; string variablesave = ""; foreach (var v in variables) { variable += v.VariableName + ": " + v.VariableValue + "<br/>"; variablesave += v.VariableName.Trim() + ": " + v.VariableValue.Trim() + "|"; variablename += v.VariableName + "|"; variablevalue += v.VariableValue + "|"; } double mainstock = PJUtils.TotalProductQuantityInstock(1, SKU); ProductGetOut p = new ProductGetOut(); p.ID = productvariable.ID; var _product = ProductController.GetBySKU(productvariable.ParentSKU); if (_product != null) { p.ProductName = _product.ProductTitle; } p.ProductVariable = variable; p.ProductVariableSave = variablesave; p.ProductVariableName = variablename; p.ProductVariableValue = variablevalue; p.ProductType = 2; if (!string.IsNullOrEmpty(productvariable.Image)) { p.ProductImage = "<img src=\"" + productvariable.Image + "\" />"; p.ProductImageOrigin = productvariable.Image; } else if (_product != null && !string.IsNullOrEmpty(_product.ProductImage)) { p.ProductImage = "<img src=\"" + _product.ProductImage + "\" />"; p.ProductImageOrigin = _product.ProductImage; } else { p.ProductImage = "<img src=\"/App_Themes/Ann/image/placeholder.png\" />"; p.ProductImageOrigin = ""; } p.SKU = SKU; p.QuantityMainInstock = mainstock; p.QuantityMainInstockString = string.Format("{0:N0}", mainstock); p.QuantityInstock = mainstock; p.QuantityInstockString = string.Format("{0:N0}", mainstock); p.Giabansi = Convert.ToDouble(productvariable.Regular_Price); p.stringGiabansi = string.Format("{0:N0}", productvariable.Regular_Price); p.Giabanle = Convert.ToDouble(productvariable.Regular_Price); p.stringGiabanle = string.Format("{0:N0}", productvariable.Regular_Price); ps.Add(p); } } } } JavaScriptSerializer serializer = new JavaScriptSerializer(); return(serializer.Serialize(ps)); }
public static string getAllCategoryImage(double productPrice = 0) { List <string> result = new List <string>(); string rootPath = HostingEnvironment.ApplicationPhysicalPath; string uploadsImagesPath = rootPath + "/uploads/images/"; using (var dbe = new inventorymanagementEntities()) { var products = dbe.tbl_Product.Where(p => p.CategoryID == 44).OrderByDescending(o => o.ID).ToList(); if (productPrice > 0) { products = products.Where(p => p.Regular_Price == productPrice).ToList(); } else if (productPrice == -1) { products = products.Where(p => p.Regular_Price != 30000 && p.Regular_Price != 35000 && p.Regular_Price != 49000 && p.Regular_Price != 135000).ToList(); } if (products != null) { List <string> images = new List <string>(); foreach (var item in products) { var stock = StockManagerController.getStock(item.ID, 0); double quantity = 0; if (stock.Count > 0) { quantity = stock .Select(s => s.Type == 2 ? (s.QuantityCurrent.Value - s.Quantity.Value) : (s.QuantityCurrent.Value + s.Quantity.Value)) .Sum(s => s); } // Chỉ lấy ảnh sản phẩm còn hàng if (quantity >= 3) { // lấy ảnh đại diện string imgAdd = item.ProductImage; if (File.Exists(uploadsImagesPath + imgAdd)) { images.Add(imgAdd); } // lấy ảnh sản phẩm từ thư viện var imageProduct = ProductImageController.GetByProductID(item.ID); if (imageProduct != null) { foreach (var img in imageProduct) { imgAdd = img.ProductImage; if (File.Exists(uploadsImagesPath + imgAdd)) { images.Add(imgAdd); } } } // lấy ảnh sản phẩm từ biến thể var variable = ProductVariableController.GetByParentSKU(item.ProductSKU); if (variable != null) { foreach (var v in variable) { if (!String.IsNullOrEmpty(v.Image)) { imgAdd = v.Image; if (File.Exists(uploadsImagesPath + imgAdd)) { images.Add(imgAdd); } } } } } } images = images.Distinct().ToList(); if (images.Count() > 0) { // lấy hình gốc for (int i = 0; i < images.Count; i++) { result.Add(Thumbnail.getURL(images[i], Thumbnail.Size.Source)); } } } } JavaScriptSerializer serializer = new JavaScriptSerializer(); return(serializer.Serialize(result.ToList())); }
public static string getAllProductImage1MB(string sku) { List <string> result = new List <string>(); string rootPath = HostingEnvironment.ApplicationPhysicalPath; string uploadsImagesPath = rootPath + "/uploads/images/"; var product = ProductController.GetBySKU(sku); if (product != null) { List <string> images = new List <string>(); // lấy ảnh đại diện string imgAdd = product.ProductImage; if (File.Exists(uploadsImagesPath + imgAdd)) { images.Add(imgAdd); } // lấy ảnh sản phẩm từ thư viện var imageProduct = ProductImageController.GetByProductID(product.ID); if (imageProduct != null) { foreach (var img in imageProduct) { imgAdd = img.ProductImage; if (File.Exists(uploadsImagesPath + imgAdd)) { images.Add(imgAdd); } } } // lấy ảnh sản phẩm từ biến thể var variable = ProductVariableController.GetByParentSKU(product.ProductSKU); if (variable != null) { foreach (var v in variable) { if (!String.IsNullOrEmpty(v.Image)) { imgAdd = v.Image; if (File.Exists(uploadsImagesPath + imgAdd)) { images.Add(imgAdd); } } } } // lọc hình trùng lặp images = images.Distinct().ToList(); if (images.Count() > 0) { for (int i = 0; i < images.Count - 1; i++) { for (int y = i + 1; y < images.Count; y++) { string img1 = Thumbnail.getURL(images[i], Thumbnail.Size.Micro); string img2 = Thumbnail.getURL(images[y], Thumbnail.Size.Micro); // so sánh 2 hình và lọc hình trùng lặp Bitmap bmp1 = (Bitmap)Bitmap.FromFile(rootPath + img1); Bitmap bmp2 = (Bitmap)Bitmap.FromFile(rootPath + img2); if (CompareBitmapsLazy(bmp1, bmp2)) { images.RemoveAt(y); y--; } } } } // lấy hình dưới 1MB for (int i = 0; i < images.Count; i++) { string item = uploadsImagesPath + images[i]; var size = new System.IO.FileInfo(item).Length; if (size > 1000000) { // kiểm tra size hình rộng 600px item = uploadsImagesPath + "600/" + images[i]; if (File.Exists(item)) { size = new System.IO.FileInfo(item).Length; if (size > 1000000) { result.Add(Thumbnail.getURL(images[i], Thumbnail.Size.Large)); } else { result.Add(Thumbnail.getURL(images[i], Thumbnail.Size.XLarge)); } } else { result.Add(Thumbnail.getURL(images[i], Thumbnail.Size.Large)); } } else { result.Add(Thumbnail.getURL(images[i], Thumbnail.Size.Source)); } } } JavaScriptSerializer serializer = new JavaScriptSerializer(); return(serializer.Serialize(result.ToList())); }
public static string getProduct(string textsearch) { List <ProductGetOut> ps = new List <ProductGetOut>(); string username = HttpContext.Current.Request.Cookies["usernameLoginSystem"].Value; var acc = AccountController.GetByUsername(username); if (acc != null) { int AgentID = Convert.ToInt32(acc.AgentID); var products = ProductController.GetBySKU(textsearch.Trim().ToUpper()); if (products != null) { var productvariable = ProductVariableController.GetByParentSKU(products.ProductSKU); if (productvariable.Count > 0) { foreach (var pv in productvariable) { var variables = ProductVariableValueController.GetByProductVariableSKU(pv.SKU); if (variables.Count > 0) { string variablename = ""; string variablevalue = ""; string variable = ""; foreach (var v in variables) { variable += v.VariableName.Trim() + ": " + v.VariableValue.Trim() + "|"; variablename += v.VariableName.Trim() + "|"; variablevalue += v.VariableValue.Trim() + "|"; } ProductGetOut p = new ProductGetOut(); p.ID = pv.ID; p.ProductName = products.ProductTitle; p.ProductVariable = variable; p.ProductVariableName = variablename; p.ProductVariableValue = variablevalue; p.ProductType = 2; p.ProductImage = "<img onclick='openImage($(this))' src='" + Thumbnail.getURL(pv.Image, Thumbnail.Size.Normal) + "'>"; p.ProductImageOrigin = Thumbnail.getURL(pv.Image, Thumbnail.Size.Source); p.SKU = pv.SKU.Trim().ToUpper(); int supplierID = 0; if (pv.SupplierID != null) { supplierID = pv.SupplierID.ToString().ToInt(0); } p.SupplierID = supplierID; string supplierName = ""; if (!string.IsNullOrEmpty(pv.SupplierName)) { supplierName = pv.SupplierName; } p.SupplierName = supplierName; double total = PJUtils.TotalProductQuantityInstock(AgentID, pv.SKU); p.WarehouseQuantity = string.Format("{0:N0}", total); ps.Add(p); } } } else { string variablename = ""; string variablevalue = ""; string variable = ""; ProductGetOut p = new ProductGetOut(); p.ID = products.ID; p.ProductName = products.ProductTitle; p.ProductVariable = variable; p.ProductVariableName = variablename; p.ProductVariableValue = variablevalue; p.ProductType = 1; p.ProductImage = "<img onclick='openImage($(this))' src='" + Thumbnail.getURL(products.ProductImage, Thumbnail.Size.Normal) + "'>"; p.ProductImageOrigin = Thumbnail.getURL(products.ProductImage, Thumbnail.Size.Source); p.SKU = products.ProductSKU.Trim().ToUpper(); int supplierID = 0; if (products.SupplierID != null) { supplierID = products.SupplierID.ToString().ToInt(0); } p.SupplierID = supplierID; string supplierName = ""; if (!string.IsNullOrEmpty(products.SupplierName)) { supplierName = products.SupplierName; } p.SupplierName = supplierName; double total = PJUtils.TotalProductQuantityInstock(AgentID, products.ProductSKU); p.WarehouseQuantity = string.Format("{0:N0}", total); ps.Add(p); } } else { var productvariable = ProductVariableController.GetAllBySKU(textsearch.Trim().ToUpper()); if (productvariable != null) { foreach (var value in productvariable) { var variables = ProductVariableValueController.GetByProductVariableSKU(value.SKU); if (variables.Count > 0) { string variablename = ""; string variablevalue = ""; string variable = ""; foreach (var v in variables) { variable += v.VariableName + ": " + v.VariableValue + "|"; variablename += v.VariableName + "|"; variablevalue += v.VariableValue + "|"; } ProductGetOut p = new ProductGetOut(); p.ID = value.ID; var product = ProductController.GetBySKU(value.ParentSKU); if (product != null) { p.ProductName = product.ProductTitle; } p.ProductVariable = variable; p.ProductVariableName = variablename; p.ProductVariableValue = variablevalue; p.ProductType = 2; p.ProductImage = "<img onclick='openImage($(this))' src='" + Thumbnail.getURL(value.Image, Thumbnail.Size.Normal) + "'>"; p.ProductImageOrigin = Thumbnail.getURL(value.Image, Thumbnail.Size.Source); p.SKU = value.SKU.Trim().ToUpper(); int supplierID = 0; if (value.SupplierID != null) { supplierID = value.SupplierID.ToString().ToInt(0); } p.SupplierID = supplierID; string supplierName = ""; if (!string.IsNullOrEmpty(value.SupplierName)) { supplierName = value.SupplierName; } p.SupplierName = supplierName; double total = PJUtils.TotalProductQuantityInstock(AgentID, value.SKU); p.WarehouseQuantity = string.Format("{0:N0}", total); ps.Add(p); } } } } } JavaScriptSerializer serializer = new JavaScriptSerializer(); return(serializer.Serialize(ps)); }