public void GetProductVariableByProductID(int ProductID, string username, string password) { var rs = new ResponseClass(); if (Login(username, password)) { var ProductVariable = ProductVariableController.GetProductID(ProductID); if (ProductVariable.Count > 0) { rs.Code = APIUtils.GetResponseCode(APIUtils.ResponseCode.SUCCESS); rs.Status = APIUtils.ResponseMessage.Success.ToString(); foreach (var item in ProductVariable) { item.Stock = PJUtils.GetSotckProduct(1, item.SKU); if (item.Stock > 0) { item.StockStatus = 1; } else if (item.Stock == 0) { item.StockStatus = 2; } else if (item.StockStatus < 0) { item.StockStatus = 3; } } rs.ProductVariable = ProductVariable; } else { rs.Code = APIUtils.GetResponseCode(APIUtils.ResponseCode.NotFound); rs.Status = APIUtils.ResponseMessage.Error.ToString(); rs.Message = APIUtils.OBJ_DNTEXIST; } } else { rs.Code = APIUtils.GetResponseCode(APIUtils.ResponseCode.FAILED); rs.Status = APIUtils.ResponseMessage.Fail.ToString(); } Context.Response.ContentType = "application/json"; Context.Response.Write(JsonConvert.SerializeObject(rs, Formatting.Indented)); Context.Response.Flush(); Context.Response.End(); }
public static string getProduct(string textsearch, int typeinout) { 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); if (typeinout == 1) { var products = ProductController.GetByTextSearchIsHidden(textsearch.Trim(), false); if (products.Count > 0) { foreach (var item in products) { var productvariable = ProductVariableController.GetProductID(item.ID); 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.GetByProductVariableID(pv.ID); 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 = item.ProductTitle; p.ProductVariable = variable; p.ProductVariableName = variablename; p.ProductVariableValue = variablevalue; p.ProductType = 2; p.ProductImage = "<img src=\"" + pv.Image + "\" alt=\"\" style=\"width: 50px\" />"; p.ProductImageOrigin = pv.Image; 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 = item.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 = item.ID; p.ProductName = item.ProductTitle; p.ProductVariable = variable; p.ProductVariableName = variablename; p.ProductVariableValue = variablevalue; p.ProductType = 1; var img = ProductImageController.GetFirstByProductID(item.ID); if (img != null) { p.ProductImage = "<img src=\"" + img.ProductImage + "\" alt=\"\" style=\"width: 50px\" />"; p.ProductImageOrigin = img.ProductImage; } else { p.ProductImage = ""; p.ProductImageOrigin = ""; } p.QuantityInstock = total; p.QuantityInstockString = string.Format("{0:N0}", total); p.SKU = SKU; int supplierID = 0; if (item.SupplierID != null) { supplierID = item.SupplierID.ToString().ToInt(0); } p.SupplierID = supplierID; string supplierName = ""; if (!string.IsNullOrEmpty(item.SupplierName)) { supplierName = item.SupplierName; } p.SupplierName = supplierName; ps.Add(p); } } } } } } else { var products = ProductController.GetBySKU(textsearch); if (products != null) { var productvariable = ProductVariableController.GetProductID(products.ID); 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.GetByProductVariableID(pv.ID); 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 src=\"" + pv.Image + "\" alt=\"\" style=\"width: 50px\" />"; p.ProductImageOrigin = pv.Image; 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 (img != null) { p.ProductImage = "<img src=\"" + img.ProductImage + "\" alt=\"\" style=\"width: 50px\" />"; p.ProductImageOrigin = img.ProductImage; } else { p.ProductImage = ""; 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); 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.GetByProductVariableID(value.ID); 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.GetByID(Convert.ToInt32(value.ProductID)); if (product != null) { p.ProductName = product.ProductTitle; } p.ProductVariable = variable; p.ProductVariableName = variablename; p.ProductVariableValue = variablevalue; p.ProductType = 2; p.ProductImage = "<img src=\"" + value.Image + "\" alt=\"\" style=\"width:50px;\" />"; p.ProductImageOrigin = value.Image; 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)); }
/// <summary> /// Tải thông tin của biến thể /// </summary> /// <param name="productID"></param> private void _loadProductVariationInfo(int productID) { var html = new StringBuilder(); var variations = ProductVariableController .GetProductID(productID) .OrderByDescending(o => o.ID); var index = variations.Count(); foreach (var item in variations) { string VariableSKU = item.SKU; double RegularPrice = Convert.ToDouble(item.Regular_Price); double RetailPrice = Convert.ToDouble(item.RetailPrice); double CostOfGood = Convert.ToDouble(item.CostOfGood); int MinimumInventoryLevel = Convert.ToInt32(item.MinimumInventoryLevel); int MaximumInventoryLevel = Convert.ToInt32(item.MaximumInventoryLevel); string VariableImage = Thumbnail.getURL(item.Image, Thumbnail.Size.Source); string deleteVariableImage = "<a href='javascript:;' onclick='deleteImageVariable($(this))' class='btn-delete hide'><i class='fa fa-times' aria-hidden='true'></i> Xóa hình</a>"; if (!string.IsNullOrEmpty(item.Image)) { deleteVariableImage = "<a href='javascript:;' onclick='deleteImageVariable($(this))' class='btn-delete'><i class='fa fa-times' aria-hidden='true'></i> Xóa hình</a>"; } var value = ProductVariableValueController.GetByProductVariableID(item.ID); string selectVariable = ""; string variableID = ""; string variableName = ""; string variableValueID = ""; string variableValueName = ""; string dataVariableValue = ""; string labelVariableValue = ""; if (value != null) { foreach (var temp in value) { selectVariable += "<div class='row margin-bottom-15'><div class='col-md-5'>" + temp.VariableName + "</div><div class='col-md-7'>" + _getSelectVariable(temp.VariableName, temp.VariableValue) + "</div></div>"; variableID += VariableController.GetByName(temp.VariableName.ToString()).ID.ToString() + "|"; variableName += temp.VariableName.ToString() + "|"; variableValueID += temp.VariableValueID.ToString() + "|"; variableValueName += temp.VariableValue.ToString() + "|"; dataVariableValue += VariableController.GetByName(temp.VariableName.ToString()).ID.ToString() + ":" + temp.VariableValueID.ToString() + "|"; labelVariableValue += temp.VariableName.ToString() + ": " + temp.VariableValue.ToString() + " - "; } } html.AppendLine(String.Format("<div class='item-var-gen'")); html.AppendLine(String.Format(" data-index='{0}'", index)); html.AppendLine(String.Format(" data-product-variation-id='{0}'", item.ID)); html.AppendLine(String.Format(" data-name-id='{0}'", variableID)); html.AppendLine(String.Format(" data-value-id='{0}'", variableValueID)); html.AppendLine(String.Format(" data-name-text='{0}'", variableName)); html.AppendLine(String.Format(" data-value-text='{0}'", variableValueName)); html.AppendLine(String.Format(" data-name-value='{0}'", dataVariableValue)); html.AppendLine(String.Format(">")); html.AppendLine(String.Format(" <div class='col-md-12'>")); html.AppendLine(String.Format(" <div class='col-md-10 variable-label' onclick='showVariableContent($(this))'>")); html.AppendLine(String.Format(" <strong>#{0}</strong> - {1} {2}", index, labelVariableValue, VariableSKU)); html.AppendLine(String.Format(" </div>")); html.AppendLine(String.Format(" <div class='col-md-2 variable-removal'>")); html.AppendLine(String.Format(" <a href='javascript:;' onclick='deleteVariableItem($(this))' class='btn primary-btn fw-btn not-fullwidth'>")); html.AppendLine(String.Format(" <i class='fa fa-times' aria-hidden='true'></i>")); html.AppendLine(String.Format(" </a>")); html.AppendLine(String.Format(" </div>")); html.AppendLine(String.Format(" </div>")); html.AppendLine(String.Format(" <div class='col-md-12 variable-content'>")); html.AppendLine(String.Format(" <div class='row'>")); html.AppendLine(String.Format(" <div class='col-md-2'>")); html.AppendLine(String.Format(" <input type='file' class='productVariableImage upload-btn' onchange='onChangeVariationImage(this,$(this));' name='{0}'><img class='imgpreview' onclick='openUploadImage($(this))' data-file-name='{1}' src='{1}'>{2}", VariableSKU, VariableImage, deleteVariableImage)); html.AppendLine(String.Format(" </div>")); html.AppendLine(String.Format(" <div class='col-md-5'>")); html.AppendLine(String.Format(" {0}", selectVariable)); html.AppendLine(String.Format(" <div class='row margin-bottom-15'>")); html.AppendLine(String.Format(" <div class='col-md-5'>Mã sản phẩm</div>")); html.AppendLine(String.Format(" <div class='col-md-7'><input type='text' disabled class='form-control productvariablesku sku-input' value='{0}' disabled='disabled' readonly></div>", VariableSKU)); html.AppendLine(String.Format(" </div>")); html.AppendLine(String.Format(" </div>")); html.AppendLine(String.Format(" <div class='col-md-5'>")); html.AppendLine(String.Format(" <div class='row margin-bottom-15'>")); html.AppendLine(String.Format(" <div class='col-md-5'>Giá sỉ</div>")); html.AppendLine(String.Format(" <div class='col-md-7'><input class='form-control regularprice' type='number' value='{0}'> </div>", RegularPrice)); html.AppendLine(String.Format(" </div>")); html.AppendLine(String.Format(" <div class='row margin-bottom-15 cost-of-goods'>")); html.AppendLine(String.Format(" <div class='col-md-5'>Giá vốn</div>")); html.AppendLine(String.Format(" <div class='col-md-7'><input class='form-control costofgood cost-price' type='number' value='{0}'></div>", CostOfGood)); html.AppendLine(String.Format(" </div>")); html.AppendLine(String.Format(" <div class='row margin-bottom-15'>")); html.AppendLine(String.Format(" <div class='col-md-5'>Giá bán lẻ</div>")); html.AppendLine(String.Format(" <div class='col-md-7'><input class='form-control retailprice' type='number' value='{0}'></div>", RetailPrice)); html.AppendLine(String.Format(" </div>")); html.AppendLine(String.Format(" </div>")); html.AppendLine(String.Format(" </div>")); html.AppendLine(String.Format(" </div>")); html.AppendLine(String.Format("</div>")); index--; } if (variations.Count() > 0) { ltrVariables.Text = html.ToString(); } }
public void LoadData() { int id = Request.QueryString["id"].ToInt(0); if (id > 0) { var p = ProductController.GetByID(id); if (p == null) { PJUtils.ShowMessageBoxSwAlertError("Không tìm thấy sản phẩm " + id, "e", true, "/tat-ca-san-pham", Page); } else { ViewState["ID"] = id; ViewState["cateID"] = p.CategoryID; ViewState["SKU"] = p.ProductSKU; hdfParentID.Value = p.CategoryID.ToString(); hdfsetStyle.Value = p.ProductStyle.ToString(); ltrBack.Text = "<a href=\"/xem-san-pham?id=" + p.ID + "\" class=\"btn primary-btn fw-btn not-fullwidth\">Trở về</a>"; txtProductTitle.Text = p.ProductTitle; pContent.Content = p.ProductContent; txtProductSKU.Text = p.ProductSKU; pRegular_Price.Text = p.Regular_Price.ToString(); pCostOfGood.Text = p.CostOfGood.ToString(); pRetailPrice.Text = p.Retail_Price.ToString(); chkIsHidden.Checked = Convert.ToBoolean(p.IsHidden); ddlSupplier.SelectedValue = p.SupplierID.ToString(); ddlCategory.SelectedValue = p.CategoryID.ToString(); txtMaterials.Text = p.Materials; pMinimumInventoryLevel.Text = p.MinimumInventoryLevel.ToString(); pMaximumInventoryLevel.Text = p.MaximumInventoryLevel.ToString(); if (p.ProductImage != null) { ListProductThumbnail.Value = p.ProductImage; ProductThumbnail.ImageUrl = p.ProductImage; } var image = ProductImageController.GetByProductID(id); imageGallery.Text = "<ul class=\"image-gallery\">"; if (image != null) { foreach (var img in image) { imageGallery.Text += "<li><img src='" + img.ProductImage + "' /><a href='javascript:;' data-image-id='" + img.ID + "' onclick='deleteImageGallery($(this))' class='btn-delete'><i class=\"fa fa-times\" aria-hidden=\"true\"></i> Xóa hình</a></li>"; } } imageGallery.Text += "</ul>"; // Lấy tất cả biến thể ra List <tbl_ProductVariable> a = new List <tbl_ProductVariable>(); a = ProductVariableController.GetProductID(p.ID); if (a.Count > 0) { StringBuilder html = new StringBuilder(); int t = 1; foreach (var item in a) { string VariableSKU = item.SKU; double RegularPrice = Convert.ToDouble(item.Regular_Price); double RetailPrice = Convert.ToDouble(item.RetailPrice); double CostOfGood = Convert.ToDouble(item.CostOfGood); int MinimumInventoryLevel = Convert.ToInt32(item.MinimumInventoryLevel); int MaximumInventoryLevel = Convert.ToInt32(item.MaximumInventoryLevel); string VariableImage = "/App_Themes/Ann/image/placeholder.png"; string deleteVariableImage = "<a href='javascript:;' onclick='deleteImageVariable($(this))' class='btn-delete hide'><i class=\"fa fa-times\" aria-hidden=\"true\"></i> Xóa hình</a>"; if (!string.IsNullOrEmpty(item.Image)) { VariableImage = item.Image; deleteVariableImage = "<a href='javascript:;' onclick='deleteImageVariable($(this))' class='btn-delete'><i class=\"fa fa-times\" aria-hidden=\"true\"></i> Xóa hình</a>"; } var value = ProductVariableValueController.GetByProductVariableID(item.ID); string selectVariable = ""; string variableID = ""; string variableName = ""; string variableValueID = ""; string variableValueName = ""; string dataVariableValue = ""; string labelVariableValue = ""; if (value != null) { foreach (var temp in value) { selectVariable += "<div class='row margin-bottom-15'><div class='col-md-5'>" + temp.VariableName + "</div><div class='col-md-7'>" + getSelectVariable(temp.VariableName, temp.VariableValue) + "</div></div>"; variableID += VariableController.GetByName(temp.VariableName.ToString()).ID.ToString() + "|"; variableName += temp.VariableName.ToString() + "|"; variableValueID += temp.VariableValueID.ToString() + "|"; variableValueName += temp.VariableValue.ToString() + "|"; dataVariableValue += VariableController.GetByName(temp.VariableName.ToString()).ID.ToString() + ":" + temp.VariableValueID.ToString() + "|"; labelVariableValue += temp.VariableName.ToString() + ": " + temp.VariableValue.ToString() + " - "; } } html.AppendLine(String.Format("<div class='item-var-gen' data-name-id='{0}' data-value-id='{1}' data-name-text='{2}' data-value-text='{3}' data-name-value='{4}'>", variableID, variableValueID, variableName, variableValueName, dataVariableValue)); html.AppendLine(String.Format(" <div class='col-md-12 variable-label' onclick='showVariableContent($(this))'>")); html.AppendLine(String.Format(" <strong>#{0}</strong> - {1} {2}", t, labelVariableValue, VariableSKU)); html.AppendLine(String.Format(" </div>")); html.AppendLine(String.Format(" <div class='col-md-12 variable-content'>")); html.AppendLine(String.Format(" <div class='row'>")); html.AppendLine(String.Format(" <div class='col-md-2'>")); html.AppendLine(String.Format(" <input type='file' class='productVariableImage upload-btn' onchange='imagepreview(this,$(this));' name='{0}'><img class='imgpreview' onclick='openUploadImage($(this))' data-file-name='{1}' src='{1}'>{2}", dataVariableValue, VariableImage, deleteVariableImage)); html.AppendLine(String.Format(" </div>")); html.AppendLine(String.Format(" <div class='col-md-5'>")); html.AppendLine(String.Format(" {0}", selectVariable)); html.AppendLine(String.Format(" <div class='row margin-bottom-15'>")); html.AppendLine(String.Format(" <div class='col-md-5'>Mã sản phẩm</div>")); html.AppendLine(String.Format(" <div class='col-md-7'><input type='text' disabled class='form-control productvariablesku sku-input' value='{0}'></div>", VariableSKU)); html.AppendLine(String.Format(" </div>")); html.AppendLine(String.Format(" </div>")); html.AppendLine(String.Format(" <div class='col-md-5'>")); html.AppendLine(String.Format(" <div class='row margin-bottom-15'>")); html.AppendLine(String.Format(" <div class='col-md-5'>Giá sỉ</div>")); html.AppendLine(String.Format(" <div class='col-md-7'><input class='form-control regularprice' type='text' value='{0}'> </div>", RegularPrice)); html.AppendLine(String.Format(" </div>")); html.AppendLine(String.Format(" <div class='row margin-bottom-15 cost-of-goods'>")); html.AppendLine(String.Format(" <div class='col-md-5'>Giá vốn</div>")); html.AppendLine(String.Format(" <div class='col-md-7'><input class='form-control costofgood cost-price' type='text' value='{0}'></div>", CostOfGood)); html.AppendLine(String.Format(" </div>")); html.AppendLine(String.Format(" <div class='row margin-bottom-15'>")); html.AppendLine(String.Format(" <div class='col-md-5'>Giá bán lẻ</div>")); html.AppendLine(String.Format(" <div class='col-md-7'><input class='form-control retailprice' type='text' value='{0}'></div>", RetailPrice)); html.AppendLine(String.Format(" </div>")); html.AppendLine(String.Format(" <div class='row margin-bottom-15'>")); html.AppendLine(String.Format(" <div class='col-md-5'>Tồn kho ít nhất</div>")); html.AppendLine(String.Format(" <div class='col-md-7'><input class='form-control minimum' type='text' value='{0}'></div>", MinimumInventoryLevel)); html.AppendLine(String.Format(" </div>")); html.AppendLine(String.Format(" <div class='row margin-bottom-15'>")); html.AppendLine(String.Format(" <div class='col-md-5'>Tồn kho nhiều nhất</div>")); html.AppendLine(String.Format(" <div class='col-md-7'><input class='form-control maximum' type='text' value='{0}'></div>", MaximumInventoryLevel)); html.AppendLine(String.Format(" </div>")); html.AppendLine(String.Format(" </div>")); html.AppendLine(String.Format(" </div>")); html.AppendLine(String.Format(" </div>")); html.AppendLine(String.Format("</div>")); t++; } ltrVariables.Text = html.ToString(); } } } }