/// <summary> /// Cập nhật thư viện hình ảnh sản phẩm /// </summary> /// <param name="productID"></param> private void _updateImageGallery(int productID, tbl_Account acc) { // Delete Image if (!String.IsNullOrEmpty(hdfDeleteImageGallery.Value)) { var imageIDList = hdfDeleteImageGallery.Value .Split(',') .Where(x => !String.IsNullOrEmpty(x)) .ToList(); foreach (var strID in imageIDList) { ProductImageController.Delete(Convert.ToInt32(strID)); } } // Add Image if (uploadImageGallery.HasFiles) { foreach (HttpPostedFile httpPostedFile in uploadImageGallery.PostedFiles) { var fileName = _uploadImage(productID, httpPostedFile); ProductImageController.Insert(productID, fileName, false, DateTime.Now, acc.Username); } } }
public void GetProductImageByProductID(int ProductID, string username, string password) { var rs = new ResponseClass(); if (Login(username, password)) { var ProductImage = ProductImageController.GetByProductID(ProductID); if (ProductImage.Count > 0) { rs.Code = APIUtils.GetResponseCode(APIUtils.ResponseCode.SUCCESS); rs.Status = APIUtils.ResponseMessage.Success.ToString(); rs.ProductImage = ProductImage; } 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 List <product_imageinfo> SelectProductImagebyProductId(string productId) { ProductImageController productImageCon = new ProductImageController(); List <product_imageinfo> query; return(query = productImageCon.SelectProductImageByProductID(productId)); }
public void LoadData() { int id = Request.QueryString["id"].ToInt(0); if (id > 0) { ViewState["ID"] = id; var pi = ProductImageController.GetByID(id); if (pi != null) { if (pi.ProductImage != null) { imgDaiDien.ImageUrl = pi.ProductImage; } chkIsHidden.Checked = Convert.ToBoolean(pi.IsHidden); int productid = Convert.ToInt32(pi.ProductID); if (productid > 0) { var product = ProductController.GetByID(productid); if (product != null) { ViewState["productid"] = productid; ltrBack.Text = "<a href=\"/danh-sach-anh-san-pham?id=" + product.ID + "\" class=\"btn primary-btn fw-btn not-fullwidth\">Trở về</a>"; } } } } }
public void CreateProductImage() { DateTime currentDate = DateTime.Now; var products = ProductController.GetAll(""); if (products.Count > 0) { foreach (var p in products) { if (!string.IsNullOrEmpty(p.ProductImage)) { string images = p.ProductImage; if (images.Contains("|")) { string[] img = images.Split('|'); if (img.Length > 0) { for (int i = 0; i < img.Length; i++) { string itemimg = img[i]; ProductImageController.Insert(p.ID, itemimg, false, currentDate, "admin"); } } } else { ProductImageController.Insert(p.ID, images, false, currentDate, "admin"); } } } } }
/// <summary> /// Tải tập hình ảnh của sản phẩm /// </summary> /// <param name="productID"></param> private void _loadImageGallery(int productID) { var images = ProductImageController.GetByProductID(productID); imageGallery.Text = "<ul class='image-gallery'>"; foreach (var img in images) { imageGallery.Text += "<li><img src='" + Thumbnail.getURL(img.ProductImage, Thumbnail.Size.Source) + "'><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>"; }
public void GetProductByCategory(int CategoryID, int limit, string username, string password, int showHomePage, int minQuantity, int changeProductName) { var rs = new ResponseClass(); if (Login(username, password)) { var Product = ProductController.GetProductAPI(CategoryID, limit, showHomePage, minQuantity, changeProductName); if (Product.Count > 0) { rs.Code = APIUtils.GetResponseCode(APIUtils.ResponseCode.SUCCESS); rs.Status = APIUtils.ResponseMessage.Success.ToString(); foreach (var item in Product) { if (!string.IsNullOrEmpty(item.ProductImage)) { item.ProductContent += String.Format("<p><img src='/wp-content/uploads/{0}' alt='{1}'/></p>", item.ProductImage.Split('/')[3], item.ProductTitle); } var productImage = ProductImageController.GetByProductID(item.ID); if (productImage.Count() > 0) { foreach (var image in productImage) { item.ProductImage += "|" + image.ProductImage; item.ProductContent += String.Format("<p><img src='/wp-content/uploads/{0}' alt='{1}'/></p>", image.ProductImage.Split('/')[3], item.ProductTitle); } } } rs.Product = Product; } 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(); }
protected void btnLogin_Click(object sender, EventArgs e) { DateTime currentDate = DateTime.Now; string username = Request.Cookies["userLoginSystem"].Value; var acc = AccountController.GetByUsername(username); if (acc != null) { if (acc.RoleID == 0) { int id = Convert.ToInt32(ViewState["ID"]); var pi = ProductImageController.GetByID(id); if (pi != null) { bool isHidden = chkIsHidden.Checked; ///Lưu ảnh string duongdan = "/uploads/images/"; string IMG = ""; if (hinhDaiDien.UploadedFiles.Count > 0) { foreach (UploadedFile f in hinhDaiDien.UploadedFiles) { var o = duongdan + Guid.NewGuid() + f.GetExtension(); try { f.SaveAs(Server.MapPath(o)); IMG = o; } catch { } } } else { IMG = imgDaiDien.ImageUrl; } ProductImageController.Update(id, IMG, isHidden, currentDate, username); PJUtils.ShowMessageBoxSwAlert("Cập nhật hình ảnh thành công", "s", true, Page); } } } }
protected void btnLogin_Click(object sender, EventArgs e) { DateTime currentDate = DateTime.Now; string username = Request.Cookies["userLoginSystem"].Value; var acc = AccountController.GetByUsername(username); if (acc != null) { if (acc.RoleID == 0) { int productID = ViewState["productid"].ToString().ToInt(0); bool isHidden = chkIsHidden.Checked; ///Lưu ảnh string path = "/uploads/images/"; string IMG = ""; if (hinhDaiDien.UploadedFiles.Count > 0) { foreach (UploadedFile f in hinhDaiDien.UploadedFiles) { var o = path + productID.ToString() + '-' + convertToSlug(Path.GetFileName(f.FileName)); try { f.SaveAs(Server.MapPath(o)); IMG = o; ProductImageController.Insert(productID, IMG, isHidden, currentDate, username); } catch { } } PJUtils.ShowMessageBoxSwAlert("Thêm hình ảnh thành công", "s", true, Page); } else { PJUtils.ShowMessageBoxSwAlert("Vui lòng chọn hình ảnh", "e", true, Page); } } } }
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 void LoadData() { string s = ""; if (Request.QueryString["s"] != null) { s = Request.QueryString["s"]; } List <tbl_ProductImage> a = new List <tbl_ProductImage>(); int productID = Request.QueryString["id"].ToInt(0); if (productID > 0) { var product = ProductController.GetByID(productID); if (product != null) { var cate = CategoryController.GetByID(Convert.ToInt32(product.CategoryID)); lblCategoryName.Text = product.ProductTitle; ltrAddnew.Text = "<a href=\"/them-anh-san-pham?productid=" + productID + "\" class=\"h45-btn primary-btn btn\">Thêm mới</a>"; } a = ProductImageController.GetByProductID(productID); pagingall(a); } }
public void LoadData(int userRole) { int id = Request.QueryString["id"].ToInt(0); var p = new tbl_Product(); if (id > 0) { p = ProductController.GetByID(id); } else if (id == 0) { int variableid = Request.QueryString["variableid"].ToInt(0); p = ProductController.GetByVariableID(variableid); } 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; ltrEdit1.Text = ""; if (Convert.ToInt32(ViewState["role"]) == 0 || Convert.ToInt32(ViewState["role"]) == 1) { ltrEdit1.Text += "<a href=\"/thong-tin-san-pham?id=" + p.ID + "\" class=\"btn primary-btn fw-btn not-fullwidth\"><i class=\"fa fa-pencil-square-o\" aria-hidden=\"true\"></i> Chỉnh sửa</a>"; ltrEdit1.Text += "<a href=\"/tao-san-pham\" class=\"btn primary-btn fw-btn not-fullwidth print-invoice-merged\"><i class=\"fa fa-file-text-o\" aria-hidden=\"true\"></i> Thêm mới</a>"; ltrEdit1.Text += "<a href=\"javascript:;\" onclick=\"ShowUpProductToWeb('" + p.ProductSKU + "', '" + p.ID + "', 'false', 'false');\" class=\"up-product-" + p.ID + " btn primary-btn not-fullwidth print-invoice-merged " + (p.ShowHomePage == 1 ? "" : "hide") + "\"><i class=\"fa fa-upload\" aria-hidden=\"true\"></i> Đồng bộ</a>"; } ltrEdit1.Text += "<a href=\"javascript:;\" onclick=\"copyProductInfo(" + p.ID + ")\" class=\"btn primary-btn not-fullwidth print-invoice-merged\"><i class=\"fa fa-files-o\"></i> Copy thông tin</a>"; ltrEdit1.Text += "<a href=\"javascript:;\" onclick=\"getAllProductImage('" + p.ProductSKU + "');\" class=\"btn primary-btn not-fullwidth print-invoice-merged\"><i class=\"fa fa-cloud-download\"></i> Tải tất cả hình ảnh</a>"; ltrEdit2.Text = ltrEdit1.Text; lbProductTitle.Text = p.ProductTitle; pContent.Text = p.ProductContent; lblSKU.Text = p.ProductSKU; var a = ProductController.GetAllSql(0, p.ProductSKU); if (a.Count() > 0) { foreach (var item in a) { lbProductStock.Text = item.TotalProductInstockQuantityLeft.ToString(); ddlStockStatus.SelectedValue = item.StockStatus.ToString(); } } else { lbProductStock.Text = "0"; } lbRegularPrice.Text = string.Format("{0:N0}", p.Regular_Price); ltrCostOfGood.Text = ""; if (userRole == 0) { ltrCostOfGood.Text += "<div class='form-row'>"; ltrCostOfGood.Text += " <div class='row-left'>"; ltrCostOfGood.Text += " Giá vốn"; ltrCostOfGood.Text += " </div>"; ltrCostOfGood.Text += " <div class='row-right'>"; ltrCostOfGood.Text += " <span class='form-control'>" + string.Format("{0:N0}", p.CostOfGood) + "</span>"; ltrCostOfGood.Text += " </div>"; ltrCostOfGood.Text += "</div>"; } lbRetailPrice.Text = string.Format("{0:N0}", p.Retail_Price); ddlSupplier.SelectedValue = p.SupplierID.ToString(); ddlCategory.SelectedValue = p.CategoryID.ToString(); lbMaterials.Text = p.Materials; // thư viện ảnh var image = ProductImageController.GetByProductID(id); imageGallery.Text = "<ul class=\"image-gallery\">"; imageGallery.Text += "<li><img src=\"" + p.ProductImage + "\" /><a href='" + p.ProductImage + "' download class='btn download-btn download-image h45-btn'><i class='fa fa-cloud-download'></i> Tải hình này</a></li>"; if (image != null) { foreach (var img in image) { if (img.ProductImage != p.ProductImage) { imageGallery.Text += "<li><img src=\"" + img.ProductImage + "\" /><a href='" + img.ProductImage + "' download class='btn download-btn download-image h45-btn'><i class='fa fa-cloud-download'></i> Tải hình này</a></li>"; } } } imageGallery.Text += "</ul>"; hdfTable.Value = p.ProductStyle.ToString(); } List <tbl_ProductVariable> b = new List <tbl_ProductVariable>(); b = ProductVariableController.SearchProductID(p.ID, ""); pagingall(b, userRole); }
protected void btnSave_Click(object sender, EventArgs e) { Productinfo prinfo = new Productinfo(); ProductController pcon = new ProductController(); prinfo.ProductName = txtProductName.Text.Trim(); prinfo.Product_description = txtDesc.Text.Trim(); prinfo.Color = txtColor.Text.Trim(); prinfo.Size = txtSize.Text.Trim(); prinfo.Manufacture_Country = txtMade.Text.Trim(); prinfo.UnitPrice = Convert.ToDecimal(txtSellPrice.Text.Trim()); prinfo.Manufacture_date = Convert.ToDateTime(txtManuDate.Text.Trim()); prinfo.Expired_date = Convert.ToDateTime(txtExpDate.Text.Trim()); prinfo.Product_Expired_date = Convert.ToDateTime(txtExpDate.Text.Trim()); prinfo.BrandID = ddlBrand.SelectedItem.Value; prinfo.CategoryID = ddlCateogry.SelectedItem.Value; prinfo.SupplierID = ddlSupplier.SelectedItem.Value; prinfo.UMID = ddlUM.SelectedItem.Value; //pcon.InsertProduct(prinfo); string productID = pcon.InsertProduct(prinfo); Inventoryinfo invinfo = new Inventoryinfo(); Invertorycontroller invCon = new Invertorycontroller(); invinfo.ProductID = productID; invinfo.UnitInStock = Convert.ToInt32(txtUnitStock.Text.Trim()); string invId = invCon.InsertInventory(invinfo); ReorderInfo rinfo = new ReorderInfo(); ReorderController rcon = new ReorderController(); rinfo.ProductID = productID; rinfo.InventoryID = invId; rinfo.ReorderUnit = txtReorder.Text.Trim(); rcon.InsertReorder(rinfo); Cell_Priceinfoinfo cinfo = new Cell_Priceinfoinfo(); Cell_PriceController ccon = new Cell_PriceController(); cinfo.Cell_Price1 = Convert.ToDecimal(txtBuyPrice.Text.Trim()); cinfo.Cell_Price2 = Convert.ToDecimal(txtSellPrice.Text.Trim()); cinfo.Product_id = productID; cinfo.UMID = ddlUM.SelectedItem.Value; ccon.InsertCell_Price(cinfo); if (fuMain.HasFile) { product_imageinfo piminfo = new product_imageinfo(); ProductImageController pimcon = new ProductImageController(); piminfo.ProductID = productID; piminfo.Images = fuMain.FileBytes; piminfo.MainPic = true; pimcon.InsertProductImage(piminfo); } if (fuLeft.HasFile) { product_imageinfo piminfo = new product_imageinfo(); ProductImageController pimcon = new ProductImageController(); piminfo.ProductID = productID; piminfo.Images = fuLeft.FileBytes; pimcon.InsertProductImage(piminfo); } if (FuBehind.HasFile) { product_imageinfo piminfo = new product_imageinfo(); ProductImageController pimcon = new ProductImageController(); piminfo.ProductID = productID; piminfo.Images = FuBehind.FileBytes; piminfo.MainPic = false; pimcon.InsertProductImage(piminfo); } if (fuRight.HasFile) { product_imageinfo piminfo = new product_imageinfo(); ProductImageController pimcon = new ProductImageController(); piminfo.ProductID = productID; piminfo.Images = fuRight.FileBytes; piminfo.MainPic = false; pimcon.InsertProductImage(piminfo); } if (fuFront.HasFile) { product_imageinfo piminfo = new product_imageinfo(); ProductImageController pimcon = new ProductImageController(); piminfo.ProductID = productID; piminfo.Images = fuFront.FileBytes; piminfo.MainPic = false; pimcon.InsertProductImage(piminfo); } if (fuBottom.HasFile) { product_imageinfo piminfo = new product_imageinfo(); ProductImageController pimcon = new ProductImageController(); piminfo.ProductID = productID; piminfo.Images = fuBottom.FileBytes; piminfo.MainPic = false; pimcon.InsertProductImage(piminfo); } ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert('New Product Inserted Successfully!')", true); }
public void LoadData() { string username = HttpContext.Current.Request.Cookies["usernameLoginSystem"].Value; var acc = AccountController.GetByUsername(username); int id = Request.QueryString["id"].ToInt(0); string sku = Request.QueryString["sku"]; var p = new tbl_Product(); if (id > 0) { p = ProductController.GetByID(id); } else if (id == 0) { int variableid = Request.QueryString["variableid"].ToInt(0); if (variableid != 0) { p = ProductController.GetByVariableID(variableid); } else { if (sku != "") { p = ProductController.GetBySKU(sku); if (p == null) { p = ProductController.GetByVariableSKU(sku); } } } } if (p == null) { PJUtils.ShowMessageBoxSwAlertError("Không tìm thấy sản phẩm " + id, "e", true, "/tat-ca-san-pham", Page); } else { this.Title = String.Format("{0} - Sản phẩm", p.ProductSKU.ToTitleCase()); ViewState["ID"] = id; ViewState["cateID"] = p.CategoryID; ViewState["SKU"] = p.ProductSKU; ltrEdit1.Text = ""; if (acc.RoleID == 0 || acc.RoleID == 1 || acc.Username == "nhom_zalo502") { ltrEdit1.Text += "<a href='/thong-tin-san-pham?id=" + p.ID + "' class='btn primary-btn fw-btn not-fullwidth'><i class='fa fa-pencil-square-o' aria-hidden='true'></i> Chỉnh sửa</a>"; ltrEdit1.Text += "<a href='/tao-san-pham' class='btn primary-btn fw-btn not-fullwidth print-invoice-merged'><i class='fa fa-file-text-o' aria-hidden='true'></i> Thêm mới</a>"; if (p.ShowHomePage == 1) { ltrEdit1.Text += "<a href='javascript:;' onclick='showProductSyncModal(`" + p.ProductSKU + "`, " + p.ID + ", " + p.CategoryID + ");' class='btn primary-btn not-fullwidth print-invoice-merged'><i class='fa fa-upload' aria-hidden='true'></i> Đồng bộ</a>"; } } ltrEdit1.Text += "<a href='javascript:;' onclick='copyProductInfo(" + p.ID + ")' class='btn primary-btn not-fullwidth print-invoice-merged'><i class='fa fa-files-o'></i> Copy thông tin</a>"; ltrEdit1.Text += "<a href='javascript:;' onclick='getAllProductImage(`" + p.ProductSKU + "`);' class='btn primary-btn not-fullwidth print-invoice-merged'><i class='fa fa-cloud-download'></i> Tải tất cả hình ảnh</a>"; if (acc.RoleID == 0 || acc.Username == "nhom_zalo502") { ltrEdit1.Text += "<a href='javascript:;' onclick='deleteProduct(" + p.ID + ");' class='btn primary-btn not-fullwidth print-invoice-merged btn-red'><i class='fa fa-times'></i> Xóa sản phẩm</a>"; ltrEdit1.Text += "<a href='javascript:;' data-toggle='modal' data-target='#modalUpdateProductSKU' data-backdrop='static' data-keyboard='false' class='btn primary-btn not-fullwidth print-invoice-merged btn-blue'><i class='fa fa-times'></i> Sửa mã sản phẩm</a>"; } ltrEdit2.Text = ltrEdit1.Text; lbProductTitle.Text = p.ProductTitle; pContent.Text = p.ProductContent; lblSKU.Text = p.ProductSKU; txtOldSKU.Text = p.ProductSKU; // Create order fileter var filter = new ProductFilterModel() { search = p.ProductSKU }; // Create pagination var page = new PaginationMetadataModel(); var a = ProductController.GetAllSql(filter, ref page); if (page.totalCount > 0) { foreach (var item in a) { lbProductStock.Text = item.TotalProductInstockQuantityLeft.ToString(); ddlStockStatus.SelectedValue = item.StockStatus.ToString(); } } else { lbProductStock.Text = "0"; } lbOldPrice.Text = string.Format("{0:N0}", p.Old_Price); lbRegularPrice.Text = string.Format("{0:N0}", p.Regular_Price); ltrCostOfGood.Text = ""; if (acc.RoleID == 0) { ltrCostOfGood.Text += "<div class='form-row'>"; ltrCostOfGood.Text += " <div class='row-left'>"; ltrCostOfGood.Text += " Giá vốn"; ltrCostOfGood.Text += " </div>"; ltrCostOfGood.Text += " <div class='row-right'>"; ltrCostOfGood.Text += " <span class='form-control'>" + string.Format("{0:N0}", p.CostOfGood) + "</span>"; ltrCostOfGood.Text += " </div>"; ltrCostOfGood.Text += "</div>"; } lbRetailPrice.Text = string.Format("{0:N0}", p.Retail_Price); ddlSupplier.SelectedValue = p.SupplierID.ToString(); ddlCategory.SelectedValue = p.CategoryID.ToString(); lbMaterials.Text = p.Materials; lbColor.Text = p.Color; // Hàng order ddlPreOrder.SelectedValue = p.PreOrder ? "1" : "0"; // thư viện ảnh var image = ProductImageController.GetByProductID(id); imageGallery.Text = "<ul class='image-gallery'>"; imageGallery.Text += "<li><img src='" + Thumbnail.getURL(p.ProductImage, Thumbnail.Size.Normal) + "'><a href='" + Thumbnail.getURL(p.ProductImage, Thumbnail.Size.Source) + "' download class='btn download-btn download-image h45-btn'><i class='fa fa-cloud-download'></i> Tải hình này</a></li>"; if (image != null) { foreach (var img in image) { if (img.ProductImage != p.ProductImage) { imageGallery.Text += "<li><img src='" + Thumbnail.getURL(img.ProductImage, Thumbnail.Size.Normal) + "'><a href='" + Thumbnail.getURL(img.ProductImage, Thumbnail.Size.Source) + "' download class='btn download-btn download-image h45-btn'><i class='fa fa-cloud-download'></i> Tải hình này</a></li>"; } } } imageGallery.Text += "</ul>"; hdfTable.Value = p.ProductStyle.ToString(); // Init Tag var tagIDList = ProductTagController.get(p.ID, 0) .Select(x => x.name) .ToList(); hdfTags.Value = String.Join(",", tagIDList); List <tbl_ProductVariable> b = new List <tbl_ProductVariable>(); b = ProductVariableController.SearchProductID(p.ID, ""); if (b != null) { pagingall(b, Convert.ToInt32(acc.RoleID)); } } }
protected void btnSubmit_Click(object sender, EventArgs e) { string username = Request.Cookies["usernameLoginSystem"].Value; var acc = AccountController.GetByUsername(username); DateTime currentDate = DateTime.Now; if (acc != null) { if (acc.RoleID == 0 || acc.RoleID == 1 || acc.Username == "nhom_zalo502") { int cateID = hdfParentID.Value.ToInt(); if (cateID > 0) { string ProductSKU = txtProductSKU.Text.Trim().ToUpper(); var check = true; var productcheck = ProductController.GetBySKU(ProductSKU); if (productcheck != null) { check = false; } else { var productvariable = ProductVariableController.GetBySKU(ProductSKU); if (productvariable != null) { check = false; } } if (check == false) { PJUtils.ShowMessageBoxSwAlert("Mã sản phẩm đã tồn tại, hãy kiểm tra lại", "e", false, Page); } else { string ProductTitle = Regex.Replace(txtProductTitle.Text.Trim(), @"\s*\,\s*|\s*\;\s*", " - "); string ProductContent = pContent.Content.ToString(); double ProductStock = 0; int StockStatus = 3; double Regular_Price = Convert.ToDouble(pRegular_Price.Text); double CostOfGood = Convert.ToDouble(pCostOfGood.Text); double Retail_Price = Convert.ToDouble(pRetailPrice.Text); int supplierID = ddlSupplier.SelectedValue.ToInt(0); string supplierName = ddlSupplier.SelectedItem.ToString(); string mainColor = ddlColor.SelectedValue.Trim(); int a = 1; var preOrder = ddlPreOrder.SelectedValue == "1" ? true : false; double Old_Price = String.IsNullOrEmpty(pOld_Price.Text) ? 0 : Convert.ToDouble(pOld_Price.Text); double MinimumInventoryLevel = pMinimumInventoryLevel.Text.ToInt(0); double MaximumInventoryLevel = pMaximumInventoryLevel.Text.ToInt(0); if (hdfsetStyle.Value == "2") { MinimumInventoryLevel = 0; MaximumInventoryLevel = 0; a = hdfsetStyle.Value.ToInt(); } int ShowHomePage = ddlShowHomePage.SelectedValue.ToInt(0); var prodNew = new tbl_Product() { CategoryID = cateID, ProductOldID = 0, ProductTitle = ProductTitle, ProductContent = ProductContent, ProductSKU = ProductSKU, ProductStock = ProductStock, StockStatus = StockStatus, ManageStock = true, Regular_Price = Regular_Price, CostOfGood = CostOfGood, Retail_Price = Retail_Price, ProductImage = String.Empty, ProductType = a, IsHidden = false, CreatedDate = currentDate, CreatedBy = username, SupplierID = supplierID, SupplierName = supplierName, Materials = txtMaterials.Text, MinimumInventoryLevel = MinimumInventoryLevel, MaximumInventoryLevel = MaximumInventoryLevel, ProductStyle = a, ShowHomePage = ShowHomePage, Color = mainColor, PreOrder = preOrder, Old_Price = Old_Price }; string kq = ProductController.Insert(prodNew); prodNew.ID = Convert.ToInt32(kq); if (!String.IsNullOrEmpty(hdfTags.Value)) { var tagList = JsonConvert.DeserializeObject <List <TagModel> >(hdfTags.Value); if (tagList.Count > 0) { // Get tag new var tagNew = TagController.insert(tagList, acc); var productTag = tagList .GroupJoin( tagNew, t => t.name.ToLower(), n => n.Name.ToLower(), (t, n) => new { t, n } ) .SelectMany( x => x.n.DefaultIfEmpty(), (parent, child) => new ProductTag { TagID = child != null ? child.ID : parent.t.id, ProductID = prodNew.ID, ProductVariableID = 0, SKU = prodNew.ProductSKU, CreatedBy = acc.ID, CreatedDate = currentDate } ) .ToList(); ProductTagController.insert(productTag); } } //Phần thêm ảnh đại diện sản phẩm string path = "/uploads/images/"; string ProductImage = ""; if (ProductThumbnailImage.UploadedFiles.Count > 0) { foreach (UploadedFile f in ProductThumbnailImage.UploadedFiles) { var o = path + kq + '-' + Slug.ConvertToSlug(Path.GetFileName(f.FileName), isFile: true); if (!File.Exists(Server.MapPath(o))) { f.SaveAs(Server.MapPath(o)); // Thumbnail Thumbnail.create(Server.MapPath(o), 85, 113); Thumbnail.create(Server.MapPath(o), 159, 212); Thumbnail.create(Server.MapPath(o), 240, 320); Thumbnail.create(Server.MapPath(o), 350, 467); Thumbnail.create(Server.MapPath(o), 600, 0); } ProductImage = Path.GetFileName(Server.MapPath(o)); } } string updateImage = ProductController.UpdateImage(kq.ToInt(), ProductImage); //Phần thêm ảnh đại diện sản phẩm sạch không có đóng dấu string ProductImageClean = ""; if (ProductThumbnailImageClean.UploadedFiles.Count > 0) { foreach (UploadedFile f in ProductThumbnailImageClean.UploadedFiles) { var o = path + kq + "-clean-" + Slug.ConvertToSlug(Path.GetFileName(f.FileName), isFile: true); if (!File.Exists(Server.MapPath(o))) { f.SaveAs(Server.MapPath(o)); // Thumbnail Thumbnail.create(Server.MapPath(o), 85, 113); Thumbnail.create(Server.MapPath(o), 159, 212); Thumbnail.create(Server.MapPath(o), 240, 320); Thumbnail.create(Server.MapPath(o), 350, 467); Thumbnail.create(Server.MapPath(o), 600, 0); } ProductImageClean = Path.GetFileName(Server.MapPath(o)); } } string updateImageClean = ProductController.UpdateImageClean(kq.ToInt(), ProductImageClean); //Phần thêm thư viện ảnh sản phẩm string IMG = ""; if (hinhDaiDien.UploadedFiles.Count > 0) { foreach (UploadedFile f in hinhDaiDien.UploadedFiles) { var o = path + kq + '-' + Slug.ConvertToSlug(Path.GetFileName(f.FileName), isFile: true); if (!File.Exists(Server.MapPath(o))) { f.SaveAs(Server.MapPath(o)); // Thumbnail Thumbnail.create(Server.MapPath(o), 85, 113); Thumbnail.create(Server.MapPath(o), 159, 212); Thumbnail.create(Server.MapPath(o), 240, 320); Thumbnail.create(Server.MapPath(o), 350, 467); Thumbnail.create(Server.MapPath(o), 600, 0); } IMG = Path.GetFileName(Server.MapPath(o)); ProductImageController.Insert(kq.ToInt(), IMG, false, currentDate, username); } } if (kq.ToInt(0) > 0) { int ProductID = kq.ToInt(0); string variable = hdfVariableListInsert.Value; if (!string.IsNullOrEmpty(variable)) { string[] items = variable.Split(','); for (int i = 0; i < items.Length - 1; i++) { string item = items[i]; string[] itemElement = item.Split(';'); string datanameid = itemElement[0]; string[] datavalueid = itemElement[1].Split('|'); string datanametext = itemElement[2]; string datavaluetext = itemElement[3]; string productvariablesku = itemElement[4].Trim().ToUpper(); string regularprice = itemElement[5]; string costofgood = itemElement[6]; string retailprice = itemElement[7]; string[] datanamevalue = itemElement[8].Split('|'); string imageUpload = itemElement[4]; int _MaximumInventoryLevel = itemElement[9].ToInt(0); int _MinimumInventoryLevel = itemElement[10].ToInt(0); int stockstatus = itemElement[11].ToInt(); HttpPostedFile postedFile = Request.Files["" + imageUpload + ""]; string image = ""; if (postedFile != null && postedFile.ContentLength > 0) { var o = path + kq + '-' + Slug.ConvertToSlug(Path.GetFileName(postedFile.FileName), isFile: true); if (!File.Exists(Server.MapPath(o))) { postedFile.SaveAs(Server.MapPath(o)); // Thumbnail Thumbnail.create(Server.MapPath(o), 85, 113); Thumbnail.create(Server.MapPath(o), 159, 212); Thumbnail.create(Server.MapPath(o), 240, 320); Thumbnail.create(Server.MapPath(o), 350, 467); Thumbnail.create(Server.MapPath(o), 600, 0); } image = Path.GetFileName(Server.MapPath(o)); } string kq1 = ProductVariableController.Insert(ProductID, ProductSKU, productvariablesku, 0, stockstatus, Convert.ToDouble(regularprice), Convert.ToDouble(costofgood), Convert.ToDouble(retailprice), image, true, false, currentDate, username, supplierID, supplierName, _MinimumInventoryLevel, _MaximumInventoryLevel); string color = ""; string size = ""; int ProductVariableID = 0; if (kq1.ToInt(0) > 0) { ProductVariableID = kq1.ToInt(0); color = datavalueid[0]; size = datavalueid[1]; string[] Data = datanametext.Split('|'); string[] DataValue = datavaluetext.Split('|'); for (int k = 0; k < Data.Length - 2; k++) { int variablevalueID = datavalueid[k].ToInt(); string variableName = Data[k]; string variableValueName = DataValue[k]; ProductVariableValueController.Insert(ProductVariableID, productvariablesku, variablevalueID, variableName, variableValueName, false, currentDate, username); } } ProductVariableController.UpdateColorSize(ProductVariableID, color, size); } } PJUtils.ShowMessageBoxSwAlertCallFunction("Tạo sản phẩm thành công", "s", true, "redirectTo(" + kq + ")", Page); } } } } } }
protected void btnSubmit_Click(object sender, EventArgs e) { string username = Request.Cookies["userLoginSystem"].Value; var acc = AccountController.GetByUsername(username); DateTime currentDate = DateTime.Now; if (acc != null) { if (acc.RoleID == 0 || acc.RoleID == 1) { int cateID = hdfParentID.Value.ToInt(); if (cateID > 0) { string ProductSKU = txtProductSKU.Text.Trim().ToUpper(); var check = true; var productcheck = ProductController.GetBySKU(ProductSKU); if (productcheck != null) { check = false; } else { var productvariable = ProductVariableController.GetBySKU(ProductSKU); if (productvariable != null) { check = false; } } if (check == false) { PJUtils.ShowMessageBoxSwAlert("Trùng mã sản phẩm vui lòng kiểm tra lại", "e", false, Page); } else { string ProductTitle = txtProductTitle.Text.ToString(); string ProductContent = pContent.Content.ToString(); double ProductStock = 0; int StockStatus = 3; double Regular_Price = Convert.ToDouble(pRegular_Price.Text); double CostOfGood = Convert.ToDouble(pCostOfGood.Text); double Retail_Price = Convert.ToDouble(pRetailPrice.Text); int supplierID = ddlSupplier.SelectedValue.ToInt(0); string supplierName = ddlSupplier.SelectedItem.ToString(); int a = 1; double MinimumInventoryLevel = pMinimumInventoryLevel.Text.ToInt(0); double MaximumInventoryLevel = pMaximumInventoryLevel.Text.ToInt(0); if (hdfsetStyle.Value == "2") { MinimumInventoryLevel = 0; MaximumInventoryLevel = 0; a = hdfsetStyle.Value.ToInt(); } int ShowHomePage = ddlShowHomePage.SelectedValue.ToInt(0); string kq = ProductController.Insert(cateID, 0, ProductTitle, ProductContent, ProductSKU, ProductStock, StockStatus, true, Regular_Price, CostOfGood, Retail_Price, "", 0, false, currentDate, username, supplierID, supplierName, txtMaterials.Text, MinimumInventoryLevel, MaximumInventoryLevel, a, ShowHomePage); //Phần thêm ảnh đại diện sản phẩm string path = "/uploads/images/"; string ProductImage = ""; if (ProductThumbnailImage.UploadedFiles.Count > 0) { foreach (UploadedFile f in ProductThumbnailImage.UploadedFiles) { var o = path + kq + '-' + Path.GetFileName(f.FileName); try { f.SaveAs(Server.MapPath(o)); ProductImage = o; } catch { } } } string updateImage = ProductController.UpdateImage(kq.ToInt(), ProductImage); //Phần thêm thư viện ảnh sản phẩm string IMG = ""; if (hinhDaiDien.UploadedFiles.Count > 0) { foreach (UploadedFile f in hinhDaiDien.UploadedFiles) { var o = path + kq + '-' + Path.GetFileName(f.FileName); try { f.SaveAs(Server.MapPath(o)); IMG = o; ProductImageController.Insert(kq.ToInt(), IMG, false, currentDate, username); } catch { } } } if (kq.ToInt(0) > 0) { int ProductID = kq.ToInt(0); string variable = hdfVariableListInsert.Value; if (!string.IsNullOrEmpty(variable)) { string[] items = variable.Split(','); for (int i = 0; i < items.Length - 1; i++) { string item = items[i]; string[] itemElement = item.Split(';'); string datanameid = itemElement[0]; string[] datavalueid = itemElement[1].Split('|'); string datanametext = itemElement[2]; string datavaluetext = itemElement[3]; string productvariablesku = itemElement[4].Trim().ToUpper(); string regularprice = itemElement[5]; string costofgood = itemElement[6]; string retailprice = itemElement[7]; string[] datanamevalue = itemElement[8].Split('|'); string imageUpload = itemElement[8]; int _MaximumInventoryLevel = itemElement[9].ToInt(0); int _MinimumInventoryLevel = itemElement[10].ToInt(0); int stockstatus = itemElement[11].ToInt(); HttpPostedFile postedFile = Request.Files["" + imageUpload + ""]; string image = ""; if (postedFile != null && postedFile.ContentLength > 0) { var o = path + kq + '-' + Path.GetFileName(postedFile.FileName); postedFile.SaveAs(Server.MapPath(o)); image = o; } string kq1 = ProductVariableController.Insert(ProductID, ProductSKU, productvariablesku, 0, stockstatus, Convert.ToDouble(regularprice), Convert.ToDouble(costofgood), Convert.ToDouble(retailprice), image, true, false, currentDate, username, supplierID, supplierName, _MinimumInventoryLevel, _MaximumInventoryLevel); string color = ""; string size = ""; int ProductVariableID = 0; if (kq1.ToInt(0) > 0) { ProductVariableID = kq1.ToInt(0); color = datavalueid[0]; size = datavalueid[1]; string[] Data = datanametext.Split('|'); string[] DataValue = datavaluetext.Split('|'); for (int k = 0; k < Data.Length - 2; k++) { int variablevalueID = datavalueid[k].ToInt(); string variableName = Data[k]; string variableValueName = DataValue[k]; ProductVariableValueController.Insert(ProductVariableID, productvariablesku, variablevalueID, variableName, variableValueName, false, currentDate, username); } } ProductVariableController.UpdateColorSize(ProductVariableID, color, size); } } PJUtils.ShowMessageBoxSwAlertCallFunction("Tạo sản phẩm thành công", "s", true, "redirectTo(" + kq + ")", Page); } } } } } }
public void LoadData() { int ID = Request.QueryString["id"].ToInt(0); if (ID > 0) { var order = OrderController.GetByID(ID); if (order == null) { PJUtils.ShowMessageBoxSwAlertError("Không tìm thấy đơn hàng " + ID, "e", true, "/danh-sach-don-hang-chuyen-hoan", Page); } else { hdfOrderID.Value = order.ID.ToString(); string username = HttpContext.Current.Request.Cookies["userLoginSystem"].Value; var acc = AccountController.GetByUsername(username); // check order condition if (acc.RoleID != 0) { if (order.ExcuteStatus == 4) { PJUtils.ShowMessageBoxSwAlertError("Đơn hàng này đã chuyển hoàn", "w", false, "", Page); } else { if (order.CreatedBy != acc.Username) { PJUtils.ShowMessageBoxSwAlertError("Đơn hàng này không phải của bạn", "e", true, "/danh-sach-don-hang-chuyen-hoan", Page); } if (order.ExcuteStatus == 1) { PJUtils.ShowMessageBoxSwAlertError("Đơn hàng này chưa hoàn tất nên không thể chuyển hoàn", "e", true, "/danh-sach-don-hang-chuyen-hoan", Page); } if (order.ExcuteStatus == 3) { PJUtils.ShowMessageBoxSwAlertError("Đơn hàng này đã hủy nên không thể chuyển hoàn", "e", true, "/danh-sach-don-hang-chuyen-hoan", Page); } if (order.ShippingType == 1) { PJUtils.ShowMessageBoxSwAlertError("Đơn hàng này lấy trực tiếp nên không thể chuyển hoàn", "e", true, "/danh-sach-don-hang-chuyen-hoan", Page); } } } else { if (order.ExcuteStatus == 4) { PJUtils.ShowMessageBoxSwAlertError("Đơn hàng này đã chuyển hoàn", "w", false, "", Page); } else { if (order.ExcuteStatus == 1) { PJUtils.ShowMessageBoxSwAlertError("Đơn hàng này chưa hoàn tất nên không thể chuyển hoàn", "e", true, "/danh-sach-don-hang-chuyen-hoan", Page); } if (order.ExcuteStatus == 3) { PJUtils.ShowMessageBoxSwAlertError("Đơn hàng này đã hủy nên không thể chuyển hoàn", "e", true, "/danh-sach-don-hang-chuyen-hoan", Page); } if (order.ShippingType == 1) { PJUtils.ShowMessageBoxSwAlertError("Đơn hàng này lấy trực tiếp nên không thể chuyển hoàn", "e", true, "/danh-sach-don-hang-chuyen-hoan", Page); } } } ViewState["ID"] = ID; Response.Cookies["odid"].Value = ID.ToString(); int AgentID = Convert.ToInt32(order.AgentID); txtPhone.Text = order.CustomerPhone; txtFullname.Text = order.CustomerName; txtAddress.Text = order.CustomerAddress; var cus = CustomerController.GetByID(order.CustomerID.Value); if (cus != null) { txtNick.Text = cus.Nick; txtZalo.Text = cus.Zalo; txtFacebook.Text = cus.Facebook; if (!string.IsNullOrEmpty(cus.Facebook)) { ltrFb.Text += "<a href =\"" + cus.Facebook + "\" class=\"btn primary-btn fw-btn not-fullwidth\" target=\"_blank\">Xem</a>"; } } int customerID = Convert.ToInt32(order.CustomerID); ltrViewDetail.Text = "<a href=\"javascript:;\" class=\"btn primary-btn fw-btn not-fullwidth\" onclick=\"viewCustomerDetail('" + customerID + "')\"><i class=\"fa fa-address-card-o\" aria-hidden=\"true\"></i> Xem chi tiết</a>"; ltrViewDetail.Text += "<a href=\"chi-tiet-khach-hang?id=" + customerID + "\" class=\"btn primary-btn fw-btn not-fullwidth edit-customer-btn\" target=\"_blank\"><i class=\"fa fa-pencil-square-o\" aria-hidden=\"true\"></i> Chỉnh sửa</a>"; var d = DiscountCustomerController.getbyCustID(customerID); if (d.Count > 0) { var da = d[0].DiscountAmount; hdfIsDiscount.Value = "1"; hdfDiscountAmount.Value = da.ToString(); ltrDiscountInfo.Text = "<strong>Khách hàng được chiết khấu: " + string.Format("{0:N0}", Convert.ToDouble(da)) + " vnđ/sản phẩm.</strong>"; } else { hdfIsDiscount.Value = "0"; hdfDiscountAmount.Value = "0"; } int customerType = Convert.ToInt32(order.OrderType); ltrCustomerType.Text = ""; ltrCustomerType.Text += "<select disabled class=\"form-control customer-type\" onchange=\"getProductPrice($(this))\">"; if (customerType == 1) { ltrCustomerType.Text += "<option value=\"2\">Khách mua sỉ</option>"; ltrCustomerType.Text += "<option value=\"1\" selected>Khách mua lẻ</option>"; } else { ltrCustomerType.Text += "<option value=\"2\" selected>Khách mua sỉ</option>"; ltrCustomerType.Text += "<option value=\"1\">Khách mua lẻ</option>"; } ltrCustomerType.Text += "</select>"; double ProductQuantity = 0; double totalPrice = Convert.ToDouble(order.TotalPrice); double totalPriceNotDiscount = Convert.ToDouble(order.TotalPriceNotDiscount); hdfcheckR.Value = ""; int totalrefund = 0; if (order.RefundsGoodsID > 0) { var re = RefundGoodController.GetByID(order.RefundsGoodsID.Value); if (re != null) { totalrefund = Convert.ToInt32(re.TotalPrice); hdfcheckR.Value = order.RefundsGoodsID.ToString() + "," + re.TotalPrice; } ltrtotalpricedetail.Text = string.Format("{0:N0}", totalPrice - totalrefund); ltrTotalPriceRefund.Text = string.Format("{0:N0}", totalrefund); } hdfDiscountInOrder.Value = ""; if (order.DiscountPerProduct > 0) { hdfDiscountInOrder.Value = order.DiscountPerProduct.ToString(); } int paymentStatus = Convert.ToInt32(order.PaymentStatus); int excuteStatus = Convert.ToInt32(order.ExcuteStatus); int shipping = Convert.ToInt32(order.ShippingType); int TransportCompanyID = Convert.ToInt32(order.TransportCompanyID); int TransportCompanySubID = Convert.ToInt32(order.TransportCompanySubID); int PostalDeliveryType = Convert.ToInt32(order.PostalDeliveryType); int paymenttype = Convert.ToInt32(order.PaymentType); #region Lấy danh sách sản phẩm var orderdetails = OrderDetailController.GetByOrderID(ID); string html = ""; string Print = ""; if (orderdetails.Count > 0) { int t = 0; int orderitem = 0; foreach (var item in orderdetails) { ProductQuantity += Convert.ToDouble(item.Quantity); int ProductType = Convert.ToInt32(item.ProductType); int ProductID = Convert.ToInt32(item.ProductID); int ProductVariableID = Convert.ToInt32(item.ProductVariableID); double ItemPrice = Convert.ToDouble(item.Price); string SKU = item.SKU; double Giabansi = 0; double Giabanle = 0; string stringGiabansi = ""; string stringGiabanle = ""; double QuantityInstock = 0; string ProductImageOrigin = ""; string ProductVariable = ""; string ProductName = ""; int PID = 0; string ProductVariableName = ""; string ProductVariableValue = ""; string ProductVariableSave = ""; double QuantityMainInstock = 0; string ProductImage = ""; string QuantityMainInstockString = ""; string QuantityInstockString = ""; string productVariableDescription = item.ProductVariableDescrition; if (ProductType == 1) { PID = ProductID; var product = ProductController.GetBySKU(SKU); if (product != null) { double mainstock = PJUtils.TotalProductQuantityInstock(1, SKU); if (customerType == 1) { Giabansi = Convert.ToDouble(product.Regular_Price); Giabanle = ItemPrice; } else { Giabansi = ItemPrice; Giabanle = Convert.ToDouble(product.Retail_Price); } stringGiabansi = string.Format("{0:N0}", Giabansi); stringGiabanle = string.Format("{0:N0}", Giabanle); string variablename = ""; string variablevalue = ""; string variable = ""; QuantityInstock = mainstock; QuantityInstockString = string.Format("{0:N0}", mainstock); var img = ProductImageController.GetFirstByProductID(product.ID); if (!string.IsNullOrEmpty(product.ProductImage)) { ProductImage = "<img src=\"" + product.ProductImage + "\" />"; ProductImageOrigin = product.ProductImage; } else if (img != null) { ProductImage = "<img src=\"" + img.ProductImage + "\" />"; ProductImageOrigin = img.ProductImage; } else { ProductImage = "<img src=\"/App_Themes/Ann/image/placeholder.png\" />"; ProductImageOrigin = ""; } ProductVariable = variable; ProductName = product.ProductTitle; QuantityMainInstock = mainstock; QuantityMainInstockString = string.Format("{0:N0}", mainstock); ProductVariableSave = item.ProductVariableDescrition; ProductVariableName = variablename; ProductVariableValue = variablevalue; } } else { PID = ProductVariableID; var productvariable = ProductVariableController.GetBySKU(SKU); if (productvariable != null) { SKU = productvariable.SKU.Trim().ToUpper(); double mainstock = PJUtils.TotalProductQuantityInstock(1, SKU); if (customerType == 1) { Giabansi = Convert.ToDouble(productvariable.Regular_Price); Giabanle = ItemPrice; } else { Giabansi = ItemPrice; Giabanle = Convert.ToDouble(productvariable.RetailPrice); } stringGiabansi = string.Format("{0:N0}", Giabansi); stringGiabanle = string.Format("{0:N0}", Giabanle); string variablename = ""; string variablevalue = ""; string variable = ""; string[] vs = productVariableDescription.Split('|'); if (vs.Length - 1 > 0) { for (int i = 0; i < vs.Length - 1; i++) { string[] items = vs[i].Split(':'); variable += items[0] + ":" + items[1] + "<br/>"; variablename += items[0] + "|"; variablevalue += items[1] + "|"; } } QuantityInstock = mainstock; QuantityInstockString = string.Format("{0:N0}", mainstock); var _product = ProductController.GetByID(Convert.ToInt32(productvariable.ProductID)); if (!string.IsNullOrEmpty(productvariable.Image)) { ProductImage = "<img src=\"" + productvariable.Image + "\" />"; ProductImageOrigin = productvariable.Image; } else if (_product != null && !string.IsNullOrEmpty(_product.ProductImage)) { ProductImage = "<img src=\"" + _product.ProductImage + "\" />"; ProductImageOrigin = _product.ProductImage; } else { ProductImage = "<img src=\"/App_Themes/Ann/image/placeholder.png\" />"; ProductImageOrigin = ""; } ProductVariable = variable; if (_product != null) { ProductName = _product.ProductTitle; } QuantityMainInstock = mainstock; QuantityMainInstockString = string.Format("{0:N0}", mainstock); ProductVariableSave = item.ProductVariableDescrition; ProductVariableName = variablename; ProductVariableValue = variablevalue; } } orderitem++; html += "<tr class=\"product-result\" data-orderdetailid=\"" + item.ID + "\" data-giabansi=\"" + Giabansi + "\" data-giabanle=\"" + Giabanle + "\" " + "data-quantityinstock=\"" + QuantityInstock + "\" data-productimageorigin=\"" + ProductImageOrigin + "\" " + "data-productvariable=\"" + ProductVariable + "\" data-productname=\"" + ProductName + "\" " + "data-sku=\"" + SKU + "\" data-producttype=\"" + ProductType + "\" data-id=\"" + PID + "\" " + "data-productnariablename=\"" + ProductVariableName + "\" " + "data-productvariablevalue =\"" + ProductVariableValue + "\" " + "data-productvariablesave =\"" + ProductVariableSave + "\" " + "data-quantitymaininstock=\"" + QuantityMainInstock + "\">"; html += " <td class=\"order-item\">" + orderitem + ""; html += " <td class=\"image-item\">" + ProductImage + ""; html += " <td class=\"name-item\">" + ProductName + "</td>"; html += " <td class=\"sku-item\">" + SKU + "</td>"; html += " <td class=\"variable-item\">" + ProductVariable + "</td>"; html += " <td class=\"price-item gia-san-pham\" data-price=\"" + ItemPrice + "\">" + string.Format("{0:N0}", ItemPrice) + "</td>"; html += " <td class=\"quantity-item soluong\">" + QuantityInstockString + "</td>"; html += " <td class=\"quantity-item\"><input disabled data-quantity=\"" + item.Quantity + "\" value=\"" + item.Quantity + "\" type=\"text\" class=\"form-control in-quanlity\" value=\"1\" onblur=\"checkQuantiy($(this))\" onkeypress='return event.charCode >= 48 && event.charCode <= 57'/></td>"; int k = Convert.ToInt32(ItemPrice) * Convert.ToInt32(item.Quantity); html += "<td class=\"total-item totalprice-view\">" + string.Format("{0:N0}", k) + "</td>"; html += " <td class=\"trash-item\"><a href=\"javascript:;\" class=\"link-btn\"><i class=\"fa fa-trash\"></i></a> </td>"; html += "</tr>"; Print += " <tr>"; t++; Print += "<td>" + t + "</td>"; Print += "<td>" + SKU + " - " + ProductName + " - " + ProductVariableSave.Replace("|", ", ") + "</td> "; Print += "<td>" + item.Quantity + "</td>"; Print += "<td>" + string.Format("{0:N0}", ItemPrice) + "</td>"; Print += "<td> " + string.Format("{0:N0}", k) + "</td>"; Print += "</tr>"; } ltrProducts.Text = html; } #endregion ddlPaymentStatus.SelectedValue = paymentStatus.ToString(); ddlExcuteStatus.SelectedValue = excuteStatus.ToString(); ddlPaymentType.SelectedValue = paymenttype.ToString(); ddlShippingType.SelectedValue = shipping.ToString(); ddlPostalDeliveryType.SelectedValue = PostalDeliveryType.ToString(); LoadTransportCompanySubID(TransportCompanyID); ddlTransportCompanyID.SelectedValue = TransportCompanyID.ToString(); ddlTransportCompanySubID.SelectedValue = TransportCompanySubID.ToString(); txtShippingCode.Text = order.ShippingCode; txtOrderNote.Text = order.OrderNote; ltrProductQuantity.Text = string.Format("{0:N0}", ProductQuantity) + " sản phẩm"; ltrTotalNotDiscount.Text = string.Format("{0:N0}", Convert.ToDouble(order.TotalPriceNotDiscount)); ltrTotalprice.Text = string.Format("{0:N0}", Convert.ToDouble(order.TotalPrice)); pDiscount.Value = order.DiscountPerProduct; pFeeShip.Value = Convert.ToDouble(order.FeeShipping); ltrOtherFeeName.Text = order.OtherFeeName; txtOtherFeeName.Text = order.OtherFeeName; pOtherFee.Value = Convert.ToDouble(order.OtherFeeValue); ltrTotalAfterCK.Text = string.Format("{0:N0}", (Convert.ToDouble(order.TotalPriceNotDiscount) - Convert.ToDouble(order.TotalDiscount))); ltrOrderID.Text = ID.ToString(); ltrCreateBy.Text = order.CreatedBy; ltrCreateDate.Text = order.CreatedDate.ToString(); ltrDateDone.Text = "Chưa hoàn tất"; if (order.DateDone != null) { ltrDateDone.Text = order.DateDone.ToString(); } ltrOrderNote.Text = order.OrderNote; ltrOrderQuantity.Text = ProductQuantity.ToString(); ltrOrderTotalPrice.Text = string.Format("{0:N0}", Convert.ToDouble(order.TotalPrice)); ltrOrderStatus.Text = PJUtils.OrderExcuteStatus(Convert.ToInt32(order.ExcuteStatus)); ltrOrderType.Text = PJUtils.OrderType(Convert.ToInt32(order.OrderType)); } } }
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 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", "e", true, "/", Page); } else { if (p.CategoryID != 44) { PJUtils.ShowMessageBoxSwAlertError("Không tìm thấy sản phẩm", "e", true, "/", Page); } this.Title = String.Format("{0} - {1}", p.ProductTitle.ToTitleCase(), p.ProductSKU); ViewState["ID"] = id; ViewState["cateID"] = p.CategoryID; ViewState["SKU"] = p.ProductSKU; ltrProductName.Text = p.ProductSKU + " - " + p.ProductTitle; ltrRegularPrice.Text = "<p><strong>📌 Giá sỉ</strong>: " + (p.Regular_Price / 1000).ToString() + "k</p>"; ltrRetailPrice.Text = "<p><strong>📌 Giá lẻ</strong>: " + (p.Retail_Price / 1000).ToString() + "k</p>"; if (!string.IsNullOrEmpty(p.Materials)) { ltrContent.Text += "<p>" + p.Materials + "</p>"; } if (!string.IsNullOrEmpty(p.ProductContent)) { string content = Regex.Replace(p.ProductContent, @"<img\s[^>]*>(?:\s*?</img>)?", "").ToString(); ltrContent.Text += "<p>" + content + "</p>"; } if (p.ProductImage != null) { ProductThumbnail.Text = "<p><img src='" + Thumbnail.getURL(p.ProductImage, Thumbnail.Size.Source) + "'><a href='" + Thumbnail.getURL(p.ProductImage, Thumbnail.Size.Source) + "' download class='btn download-btn download-image h45-btn'><i class='fa fa-cloud-download'></i> Tải hình này</a></p>"; } var image = ProductImageController.GetByProductID(id); if (image != null) { foreach (var img in image) { if (img.ProductImage != p.ProductImage) { imageGallery.Text += "<p><img src='" + Thumbnail.getURL(img.ProductImage, Thumbnail.Size.Source) + "'><a href='" + Thumbnail.getURL(img.ProductImage, Thumbnail.Size.Source) + "' download class='btn download-btn download-image h45-btn'><i class='fa fa-cloud-download'></i> Tải hình này</a></p>"; } } } var v = ProductVariableController.SearchProductID(id, ""); string css = "col-xs-6"; if (v.Count > 0) { css = "col-xs-4"; } StringBuilder htmlButton = new StringBuilder(); htmlButton.Append("<div class='" + css + "'>"); htmlButton.Append(" <div class='row'>"); htmlButton.Append(" <p><a href='javascript:;' class='btn primary-btn copy-btn h45-btn' onclick='copyProduct(`" + p.ID + "`);'><i class='fa fa-files-o' aria-hidden='true'></i> Copy mô tả</a></p>"); htmlButton.Append(" </div>"); htmlButton.Append("</div>"); if (v.Count > 0) { htmlButton.Append("<div class='" + css + "'>"); htmlButton.Append(" <div class='row'>"); htmlButton.Append(" <p><a href='#variableTable' class='btn download-btn h45-btn'><i class='fa fa-list-ul' aria-hidden='true'></i> Biến thể</a></p>"); htmlButton.Append(" </div>"); htmlButton.Append("</div>"); ltrVariableList.Text = "<h3><i class='fa fa-list-ul' aria-hidden='true'></i> Danh sách biến thể</h3>"; pagingall(v); } htmlButton.Append("<div class='" + css + "'>"); htmlButton.Append(" <div class='row'>"); htmlButton.Append(" <a href='javascript:;' class='btn primary-btn h45-btn' onclick='getAllProductImage(`" + p.ProductSKU + "`);'><i class='fa fa-cloud-download' aria-hidden='true'></i> Tải hình</a>"); htmlButton.Append(" </div>"); htmlButton.Append("</div>"); ltrButton.Text = htmlButton.ToString(); } } }
protected void btnSubmit_Click(object sender, EventArgs e) { string username = Request.Cookies["userLoginSystem"].Value; var acc = AccountController.GetByUsername(username); int cateID = ViewState["cateID"].ToString().ToInt(0); int ProductID = ViewState["ID"].ToString().ToInt(0); if (cateID > 0) { string ProductTitle = txtProductTitle.Text; string ProductContent = pContent.Content; string ProductSKU = ViewState["SKU"].ToString(); double ProductStock = 0; int StockStatus = 0; bool ManageStock = true; double Regular_Price = Convert.ToDouble(pRegular_Price.Text); double CostOfGood = Convert.ToDouble(pCostOfGood.Text); double Retail_Price = Convert.ToDouble(pRetailPrice.Text); bool IsHidden = chkIsHidden.Checked; int CategoryID = hdfParentID.Value.ToInt(); double MinimumInventoryLevel = 0; if (pMinimumInventoryLevel.Text != "") { MinimumInventoryLevel = Convert.ToDouble(pMinimumInventoryLevel.Text); } double MaximumInventoryLevel = 0; if (pMaximumInventoryLevel.Text != "") { MaximumInventoryLevel = Convert.ToDouble(pMaximumInventoryLevel.Text); } //Phần thêm ảnh đại diện sản phẩm string path = "/uploads/images/"; string ProductImage = ListProductThumbnail.Value; if (ProductThumbnailImage.UploadedFiles.Count > 0) { foreach (UploadedFile f in ProductThumbnailImage.UploadedFiles) { var o = path + ProductID + '-' + convertToSlug(Path.GetFileName(f.FileName)); try { f.SaveAs(Server.MapPath(o)); ProductImage = o; } catch { } } } if (ProductImage != ListProductThumbnail.Value) { if (File.Exists(Server.MapPath(ListProductThumbnail.Value))) { File.Delete(Server.MapPath(ListProductThumbnail.Value)); } } // Delete Image Gallery string deleteImageGallery = hdfDeleteImageGallery.Value; if (deleteImageGallery != "") { string[] deletelist = deleteImageGallery.Split(','); for (int i = 0; i < deletelist.Length - 1; i++) { var img = ProductImageController.GetByID(Convert.ToInt32(deletelist[i])); if (img != null) { var product = ProductController.GetByID(ProductID); // Delete image if (!string.IsNullOrEmpty(img.ProductImage) && img.ProductImage != product.ProductImage) { string fileImage = Server.MapPath(img.ProductImage); File.Delete(fileImage); } string delete = ProductImageController.Delete(img.ID); } } } // Update product string kq = ProductController.Update(ProductID, CategoryID, 0, ProductTitle, ProductContent, ProductSKU, ProductStock, StockStatus, ManageStock, Regular_Price, CostOfGood, Retail_Price, ProductImage, 0, IsHidden, DateTime.Now, username, ddlSupplier.SelectedValue.ToInt(0), ddlSupplier.SelectedItem.ToString(), txtMaterials.Text, MinimumInventoryLevel, MaximumInventoryLevel); // Upload image gallery if (UploadImages.HasFiles) { foreach (HttpPostedFile uploadedFile in UploadImages.PostedFiles) { var o = path + ProductID + '-' + convertToSlug(Path.GetFileName(uploadedFile.FileName)); uploadedFile.SaveAs(Server.MapPath(o)); ProductImageController.Insert(ProductID, o, false, DateTime.Now, username); } } if (kq.ToInt(0) > 0) { // Update Variable if (hdfsetStyle.Value == "2") { string variable = hdfVariableListInsert.Value; if (!string.IsNullOrEmpty(variable)) { string[] items = variable.Split(','); for (int i = 0; i < items.Length - 1; i++) { string item = items[i]; string[] itemElement = item.Split(';'); string datanameid = itemElement[0]; string[] datavalueid = itemElement[1].Split('|'); string datanametext = itemElement[2]; string datavaluetext = itemElement[3]; string productvariablesku = itemElement[4].Trim().ToUpper(); string regularprice = itemElement[5]; string costofgood = itemElement[6]; string retailprice = itemElement[7]; string[] datanamevalue = itemElement[8].Split('|'); string imageUpload = itemElement[8]; int _MaximumInventoryLevel = itemElement[9].ToInt(0); int _MinimumInventoryLevel = itemElement[10].ToInt(0); int stockstatus = itemElement[11].ToInt(); string imageSrc = itemElement[13]; string kq1 = ""; // Check variable var Variable = ProductVariableController.GetBySKU(productvariablesku); if (Variable != null) { // Update image string image = Variable.Image; if (imageSrc == "/App_Themes/Ann/image/placeholder.png") { // Delete old image if (!string.IsNullOrEmpty(Variable.Image)) { string fileImage = Server.MapPath(Variable.Image); File.Delete(fileImage); image = ""; } } else { if (imageSrc != Variable.Image) { HttpPostedFile postedFile = Request.Files["" + imageUpload + ""]; if (postedFile != null && postedFile.ContentLength > 0) { // Upload image var o = path + ProductID + '-' + convertToSlug(Path.GetFileName(postedFile.FileName)); postedFile.SaveAs(Server.MapPath(o)); image = o; // Delete old image if (!string.IsNullOrEmpty(Variable.Image)) { string fileImage = Server.MapPath(Variable.Image); File.Delete(fileImage); } } else { // Delete old image if (!string.IsNullOrEmpty(Variable.Image)) { string fileImage = Server.MapPath(Variable.Image); File.Delete(fileImage); image = ""; } } } } // Update variable kq1 = ProductVariableController.Update(Variable.ID, ProductID, Variable.ParentSKU, productvariablesku, Convert.ToDouble(Variable.Stock), Convert.ToInt32(Variable.StockStatus), Convert.ToDouble(regularprice), Convert.ToDouble(costofgood), Convert.ToDouble(retailprice), image, true, false, DateTime.Now, username, Convert.ToInt32(Variable.SupplierID), Variable.SupplierName, _MinimumInventoryLevel, _MaximumInventoryLevel); // Delete all productVariableValue bool deleteVariableValue = ProductVariableValueController.DeleteByProductVariableID(Variable.ID); } else { string image = ""; HttpPostedFile postedFile = Request.Files["" + imageUpload + ""]; if (postedFile != null && postedFile.ContentLength > 0) { // Upload image var o = path + ProductID + '-' + convertToSlug(Path.GetFileName(postedFile.FileName)); postedFile.SaveAs(Server.MapPath(o)); image = o; } // Insert new variable kq1 = ProductVariableController.Insert(ProductID, ProductSKU, productvariablesku, 0, stockstatus, Convert.ToDouble(regularprice), Convert.ToDouble(costofgood), Convert.ToDouble(retailprice), image, true, false, DateTime.Now, username, ddlSupplier.SelectedValue.ToInt(0), ddlSupplier.SelectedItem.ToString(), _MinimumInventoryLevel, _MaximumInventoryLevel); } // Update ProductVariableValue if (kq1.ToInt(0) > 0) { string[] Data = datanametext.Split('|'); string[] DataValue = datavaluetext.Split('|'); for (int k = 0; k < Data.Length - 1; k++) { int variablevalueID = datavalueid[k].ToInt(); string variableName = Data[k]; string variableValueName = DataValue[k]; ProductVariableValueController.Insert(kq1.ToInt(), productvariablesku, variablevalueID, variableName, variableValueName, false, DateTime.Now, username); } } } } } PJUtils.ShowMessageBoxSwAlert("Cập nhật sản phẩm thành công", "s", true, Page); } } }
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(); } } } }
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, "/sp", Page); } else { this.Title = String.Format("{0} - {1}", p.ProductTitle.ToTitleCase(), p.ProductSKU); ViewState["ID"] = id; ViewState["cateID"] = p.CategoryID; ViewState["SKU"] = p.ProductSKU; ltrProductName.Text = p.ProductSKU + " - " + p.ProductTitle; // Create order fileter var filter = new ProductFilterModel() { search = p.ProductSKU }; // Create pagination var page = new PaginationMetadataModel(); var a = ProductController.GetAllSql(filter, ref page); if (page.totalCount > 0) { foreach (var item in a) { string StockStatus = ""; if (item.StockStatus == 1) { StockStatus = "Còn hàng"; } else { StockStatus = "Hết hàng"; } ltrProductStock.Text = "<p><strong>✱ Kho</strong>: " + StockStatus + " (" + item.TotalProductInstockQuantityLeft.ToString() + " cái)</p>"; } } else { ltrProductStock.Text = "<p><strong>✱ Kho</strong>: Đang nhập hàng</p>"; } ltrRegularPrice.Text = "<p><strong>📌 Giá sỉ</strong>: " + (p.Regular_Price / 1000).ToString() + "k</p>"; ltrRetailPrice.Text = "<p><strong>📌 Giá lẻ</strong>: " + ((p.Retail_Price + 20000) / 1000).ToString() + "k</p>"; if (!string.IsNullOrEmpty(p.Materials)) { ltrMaterials.Text = "<p><strong>🔖 Chất liệu</strong>: " + p.Materials + "</p>"; } if (!string.IsNullOrEmpty(p.ProductContent)) { string content = Regex.Replace(p.ProductContent, @"<img\s[^>]*>(?:\s*?</img>)?", "").ToString(); ltrContent.Text = "<p><strong>🔖 Mô tả</strong>: " + content + "</p>"; } if (p.ProductImage != null) { ProductThumbnail.Text = "<p><img src='" + Thumbnail.getURL(p.ProductImage, Thumbnail.Size.Large) + "'><a href='" + Thumbnail.getURL(p.ProductImage, Thumbnail.Size.Source) + "' download class='btn download-btn download-image h45-btn'><i class='fa fa-cloud-download'></i> Tải hình này</a></p>"; } var image = ProductImageController.GetByProductID(id); if (image != null) { foreach (var img in image) { if (img.ProductImage != p.ProductImage) { imageGallery.Text += "<p><img src='" + Thumbnail.getURL(img.ProductImage, Thumbnail.Size.Large) + "'><a href='" + Thumbnail.getURL(img.ProductImage, Thumbnail.Size.Source) + "' download class='btn download-btn download-image h45-btn'><i class='fa fa-cloud-download'></i> Tải hình này</a></p>"; } } } var v = ProductVariableController.SearchProductID(id, ""); string css = "col-xs-6"; if (v.Count > 0) { css = "col-xs-4"; } StringBuilder htmlButton = new StringBuilder(); htmlButton.Append("<div class='" + css + "'>"); htmlButton.Append(" <div class='row'>"); htmlButton.Append(" <p><a href='javascript:;' class='btn primary-btn copy-btn h45-btn' onclick='copyProduct(`" + p.ID + "`);'><i class='fa fa-files-o' aria-hidden='true'></i> Copy</a></p>"); htmlButton.Append(" </div>"); htmlButton.Append("</div>"); if (v.Count > 0) { htmlButton.Append("<div class='" + css + "'>"); htmlButton.Append(" <div class='row'>"); htmlButton.Append(" <p><a href='#variableTable' class='btn download-btn h45-btn'><i class='fa fa-list-ul' aria-hidden='true'></i> Biến thể</a></p>"); htmlButton.Append(" </div>"); htmlButton.Append("</div>"); ltrVariableList.Text = "<h3><i class='fa fa-list-ul' aria-hidden='true'></i> Danh sách biến thể</h3>"; pagingall(v); } htmlButton.Append("<div class='" + css + "'>"); htmlButton.Append(" <div class='row'>"); htmlButton.Append(" <a href='javascript:;' class='btn primary-btn h45-btn' onclick='getAllProductImage(`" + p.ProductSKU + "`);'><i class='fa fa-cloud-download' aria-hidden='true'></i> Tải hình</a>"); htmlButton.Append(" </div>"); htmlButton.Append("</div>"); ltrButton.Text = htmlButton.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, "/sp", Page); } else { ViewState["ID"] = id; ViewState["cateID"] = p.CategoryID; ViewState["SKU"] = p.ProductSKU; ltrProductName.Text = p.ProductSKU + " - " + p.ProductTitle; var a = ProductController.GetAllSql(0, p.ProductSKU); if (a.Count() > 0) { foreach (var item in a) { string StockStatus = ""; if (item.StockStatus == 1) { StockStatus = "Còn hàng"; } else { StockStatus = "Hết hàng"; } ltrProductStock.Text = "<p><strong>✱ Kho</strong>: " + StockStatus + " (" + item.TotalProductInstockQuantityLeft.ToString() + " cái)</p>"; } } else { ltrProductStock.Text = "<p><strong>✱ Kho</strong>: Đang nhập hàng</p>"; } ltrRegularPrice.Text = "<p><strong>📌 Giá sỉ</strong>: " + (p.Regular_Price / 1000).ToString() + "k</p>"; ltrRetailPrice.Text = "<p><strong>📌 Giá lẻ</strong>: " + ((p.Retail_Price + 20000) / 1000).ToString() + "k</p>"; if (!string.IsNullOrEmpty(p.Materials)) { ltrMaterials.Text = "<p><strong>🔖 Chất liệu</strong>: " + p.Materials + "</p>"; } if (!string.IsNullOrEmpty(p.ProductContent)) { ltrContent.Text = "<p><strong>🔖 Mô tả</strong>: " + p.ProductContent + "</p>"; } if (p.ProductImage != null) { ProductThumbnail.Text = "<p><img src=\"" + p.ProductImage + "\" /><a href='" + p.ProductImage + "' download class='btn download-btn download-image h45-btn'><i class='fa fa-cloud-download'></i> Tải hình này</a></p>"; } var image = ProductImageController.GetByProductID(id); if (image != null) { foreach (var img in image) { if (img.ProductImage != p.ProductImage) { imageGallery.Text += "<p><img src=\"" + img.ProductImage + "\" /><a href='" + img.ProductImage + "' download class='btn download-btn download-image h45-btn'><i class='fa fa-cloud-download'></i> Tải hình này</a></p>"; } } } ltrCopyProductInfoButton.Text = "<p><a href=\"javascript:;\" class=\"btn primary-btn copy-btn h45-btn\" onclick=\"copyProduct(" + p.ID + ")\"><i class=\"fa fa-files-o\" aria-hidden=\"true\"></i> Copy</a></p>"; ltrDownloadProductImageButton.Text = "<a href =\"javascript:;\" class=\"btn primary-btn h45-btn\" onclick=\"getAllProductImage('" + p.ProductSKU + "');\"><i class=\"fa fa-cloud-download\" aria-hidden=\"true\"></i> Tải hình</a>"; var v = ProductVariableController.SearchProductID(id, ""); if (v.Count > 0) { ltrViewVariableListButton.Text = "<p><a href='#variableTable' class='btn download-btn h45-btn'><i class='fa fa-list-ul' aria-hidden='true'></i> Biến thể</a></p>"; ltrVariableList.Text = "<h3><i class='fa fa-list-ul' aria-hidden='true'></i> Danh sách biến thể</h3>"; pagingall(v); } } } }
public static string getProduct(string textsearch, int typeinout) { 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); 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=\"" + Thumbnail.getURL(pv.Image, Thumbnail.Size.Small) + "\" alt=\"\" style=\"width: 50px\" />"; p.ProductImageOrigin = Thumbnail.getURL(pv.Image, Thumbnail.Size.Small); 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=\"" + Thumbnail.getURL(img.ProductImage, Thumbnail.Size.Small) + "\" alt=\"\" style=\"width: 50px\" />"; p.ProductImageOrigin = Thumbnail.getURL(img.ProductImage, Thumbnail.Size.Small); } 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=\"" + Thumbnail.getURL(pv.Image, Thumbnail.Size.Small) + "\" alt=\"\" style=\"width: 50px\" />"; p.ProductImageOrigin = Thumbnail.getURL(pv.Image, Thumbnail.Size.Small); 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=\"" + Thumbnail.getURL(img.ProductImage, Thumbnail.Size.Small) + "\" alt=\"\" style=\"width: 50px\" />"; p.ProductImageOrigin = Thumbnail.getURL(img.ProductImage, Thumbnail.Size.Small); } 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.GetBySKU(textsearch); if (productvariable != null) { string SKU = productvariable.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(productvariable.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 = productvariable.ID; var product = ProductController.GetByID(Convert.ToInt32(productvariable.ProductID)); if (product != null) { p.ProductName = product.ProductTitle; } p.ProductVariable = variable; p.ProductVariableName = variablename; p.ProductVariableValue = variablevalue; p.ProductType = 2; p.ProductImage = "<img src=\"" + Thumbnail.getURL(productvariable.Image, Thumbnail.Size.Small) + "\" alt=\"\" style=\"width:50px;\" />"; p.ProductImageOrigin = Thumbnail.getURL(productvariable.Image, Thumbnail.Size.Small); p.SKU = productvariable.SKU.Trim().ToUpper(); p.QuantityInstock = total; p.QuantityInstockString = string.Format("{0:N0}", total); int supplierID = 0; if (productvariable.SupplierID != null) { supplierID = productvariable.SupplierID.ToString().ToInt(0); } p.SupplierID = supplierID; string supplierName = ""; if (!string.IsNullOrEmpty(productvariable.SupplierName)) { supplierName = productvariable.SupplierName; } p.SupplierName = supplierName; ps.Add(p); } } } } } } } JavaScriptSerializer serializer = new JavaScriptSerializer(); return(serializer.Serialize(ps)); }
protected void btnSave_Click(object sender, EventArgs e) { DateTime currentDate = DateTime.Now; int AgentID = 0; string username = Request.Cookies["usernameLoginSystem"].Value; if (!string.IsNullOrEmpty(username)) { var a = AccountController.GetByUsername(username); if (a != null) { AgentID = Convert.ToInt32(a.AgentID); string phone = hdfPhone.Value; if (!string.IsNullOrEmpty(phone)) { var cust = CustomerController.GetByPhone(phone); if (cust != null) { #region Tạo đơn hàng đổi tra int custID = cust.ID; string totalprice = hdfTotalPrice.Value; string totalquantity = hdfTotalQuantity.Value; string totalrefund = hdfTotalRefund.Value; var agent = AgentController.GetByID(AgentID); string agentName = ""; if (agent != null) { agentName = agent.AgentName; } //insert ddlstatus, refundnote int status = ddlRefundStatus.SelectedValue.ToInt(); string RefundsNote = txtRefundsNote.Text; int rID = RefundGoodController.Insert(AgentID, totalprice, status, custID, Convert.ToInt32(totalquantity), totalrefund, agentName, cust.CustomerName, cust.CustomerPhone, currentDate, username, RefundsNote); #endregion if (rID > 0) { string listString = hdfListProduct.Value; string[] items = listString.Split('|'); if (items.Length - 1 > 0) { for (int i = 0; i < items.Length - 1; i++) { #region Tạo chi tiết đơn hàng đổi tra string[] element = items[i].Split(';'); var sku = element[0]; var orderID = element[1].ToInt(0); var orderDetailID = element[2]; var ProductName = element[3]; var GiavonPerProduct = Convert.ToDouble(element[5]); var SoldPricePerProduct = Convert.ToDouble(element[6]); var DiscountPricePerProduct = Convert.ToDouble(element[7]); var quantity = Convert.ToDouble(element[10]); var quantityMax = Convert.ToDouble(element[8]); var ProductType = element[4].ToInt(1); var RefundType = element[9].ToInt(1); var RefundFeePerProduct = Convert.ToDouble(element[11]); var TotalPriceRow = element[12]; var PriceNotFeeRefund = SoldPricePerProduct * quantity; var rdTotalRefundFee = RefundFeePerProduct * quantity; int rdID = RefundGoodDetailController.Insert(rID, AgentID, orderID, ProductName, custID, sku, quantity, quantityMax, PriceNotFeeRefund.ToString(), ProductType, true, RefundType, RefundFeePerProduct.ToString(), rdTotalRefundFee.ToString(), GiavonPerProduct.ToString(), DiscountPricePerProduct.ToString(), SoldPricePerProduct.ToString(), TotalPriceRow, currentDate, username); #endregion #region Cập nhật stock if (rdID > 0) { if (RefundType < 3) { int typeRe = 0; string note = ""; if (RefundType == 1) { note = "Đổi size"; typeRe = 8; } else if (RefundType == 2) { note = "Đổi sản phẩm"; typeRe = 9; } if (ProductType == 1) { var product = ProductController.GetBySKU(sku); if (product != null) { int productID = product.ID; string ProductImageOrigin = ""; var ProductImage = ProductImageController.GetFirstByProductID(product.ID); if (ProductImage != null) { ProductImageOrigin = ProductImage.ProductImage; } StockManagerController.Insert( new tbl_StockManager { AgentID = AgentID, ProductID = productID, ProductVariableID = 0, Quantity = quantity, QuantityCurrent = 0, Type = 1, NoteID = note, OrderID = orderID, Status = typeRe, SKU = sku, CreatedDate = currentDate, CreatedBy = username, MoveProID = 0, ParentID = productID, }); } } else { string ProductVariableName = ""; string ProductVariableValue = ""; string ProductVariable = ""; int parentID = 0; string parentSKU = ""; string ProductImageOrigin = ""; int ID = 0; var productvariable = ProductVariableController.GetBySKU(sku); if (productvariable != null) { ID = productvariable.ID; ProductImageOrigin = productvariable.Image; parentSKU = productvariable.ParentSKU; var variables = ProductVariableValueController.GetByProductVariableID(productvariable.ID); if (variables.Count > 0) { foreach (var v in variables) { ProductVariable += v.VariableName.Trim() + ":" + v.VariableValue.Trim() + "|"; ProductVariableName += v.VariableName + "|"; ProductVariableValue += v.VariableValue + "|"; } } } if (!string.IsNullOrEmpty(parentSKU)) { var product = ProductController.GetBySKU(parentSKU); if (product != null) { parentID = product.ID; } } StockManagerController.Insert( new tbl_StockManager { AgentID = AgentID, ProductID = 0, ProductVariableID = ID, Quantity = quantity, QuantityCurrent = 0, Type = 1, NoteID = note, OrderID = orderID, Status = typeRe, SKU = sku, CreatedDate = currentDate, CreatedBy = username, MoveProID = 0, ParentID = parentID, }); } } } #endregion } RefundGoodController.updateQuantityCOGS(rID); PJUtils.ShowMessageBoxSwAlertCallFunction("Tạo đơn hàng đổi trả thành công", "s", true, "redirectTo(" + rID + ")", Page); } } } } } } }
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 AclProductController(ProductsController legacyProductController, ProductImageController legacyProductImageController) { _legacyProductController = legacyProductController ?? throw new ArgumentNullException(nameof(legacyProductController)); _legacyProductImageController = legacyProductImageController ?? throw new ArgumentNullException(nameof(legacyProductImageController)); }
public void LoadData() { int ID = Request.QueryString["id"].ToInt(0); if (ID > 0) { string username = Request.Cookies["usernameLoginSystem"].Value; var acc = AccountController.GetByUsername(username); if (acc != null) { int agentIDReceive = Convert.ToInt32(acc.AgentID); var mp = MoveProController.GetByIDAndAgentIDReceive(ID, agentIDReceive); if (mp != null) { ViewState["ID"] = ID; int agentIDSend = Convert.ToInt32(mp.AgentIDSend); string agentSendname = ""; string agentReceivename = ""; var agentSend = AgentController.GetByID(agentIDSend); if (agentSend != null) { agentSendname = agentSend.AgentName; } var agentReceive = AgentController.GetByID(agentIDReceive); if (agentReceive != null) { agentReceivename = agentReceive.AgentName; } ltrAgentReceive.Text = agentReceivename; ltrAgentSend.Text = agentSendname; int mpStatus = Convert.ToInt32(mp.Status); ltrNote.Text = mp.Note; if (mpStatus < 3) { ltrbutton1.Text = "<a href=\"javascript:;\" class=\"btn primary-btn fw-btn not-fullwidth\" onclick=\"inProduct()\">Cập nhật</a>"; ltrbutton2.Text = "<div class=\"float-right\"><a href=\"javascript:;\" class=\"btn primary-btn fw-btn not-fullwidth\" onclick=\"inProduct()\">Cập nhật</a></div>"; } #region LoadDDL //Lấy trạng thái StringBuilder htmlStatus = new StringBuilder(); htmlStatus.Append("<select id=\"moveProStatus\" class=\"form-control\" style=\"width: 20%; display: inline-block\">"); if (mpStatus == 2) { htmlStatus.Append("<option value=\"2\" selected>Đã chuyển</option>"); htmlStatus.Append("<option value=\"3\">Đã hoàn tất</option>"); } else if (mpStatus == 3) { htmlStatus.Append("<option value=\"2\">Đã chuyển</option>"); htmlStatus.Append("<option value=\"3\" selected>Đã hoàn tất</option>"); } htmlStatus.Append("</select>"); ltrMoProStatus.Text = htmlStatus.ToString(); //Lấy nhà cung cấp //var supplier = SupplierController.GetAllWithIsHidden(false); //StringBuilder htmlSupplier = new StringBuilder(); //htmlSupplier.Append("<select id=\"supplierList\" class=\"form-control\" style=\"width: 20%; float: left; margin-right: 10px\">"); //htmlSupplier.Append("<option value=\"0\">Tất cả nhà cung cấp</option>"); //if (supplier.Count > 0) //{ // foreach (var s in supplier) // { // htmlSupplier.Append("<option value=\"" + s.ID + "\">" + s.SupplierName + "</option>"); // } //} //htmlSupplier.Append("</select>"); //ltrSupplier.Text = htmlSupplier.ToString(); #endregion #region Lấy danh sách sản phẩm var mpDetail = MoveProDetailController.GetByMoveProID(ID); string html = ""; if (mpDetail.Count > 0) { string listSKU = ""; foreach (var item in mpDetail) { listSKU += item.SKU + "|"; int ProductType = Convert.ToInt32(item.ProductType); int ProductID = Convert.ToInt32(item.ProductID); int ProductVariableID = Convert.ToInt32(item.ProductVariableID); string SKU = item.SKU; double QuantityInstock = 0; string ProductImageOrigin = ""; string ProductVariable = ""; string ProductName = ""; int PID = 0; string ProductVariableName = ""; string ProductVariableValue = ""; string ProductVariableSave = ""; double QuantityMainInstock = 0; string ProductImage = ""; string QuantityMainInstockString = ""; string QuantityInstockString = ""; string productVariableDescription = item.ProductVariableDescription; string SupplierName = item.SupplierName; if (ProductType == 1) { PID = ProductID; var product = ProductController.GetBySKU(SKU); if (product != null) { double total = PJUtils.TotalProductQuantityInstock(agentIDSend, SKU); string variablename = ""; string variablevalue = ""; string variable = ""; double mainstock = PJUtils.TotalProductQuantityInstock(1, SKU); QuantityInstock = total; QuantityInstockString = string.Format("{0:N0}", total); var img = ProductImageController.GetFirstByProductID(product.ID); if (img != null) { ProductImage = "<img src=\"" + Thumbnail.getURL(img.ProductImage, Thumbnail.Size.Small) + "\" alt=\"\" style=\"width: 50px\" />"; ProductImageOrigin = Thumbnail.getURL(img.ProductImage, Thumbnail.Size.Small); } else { ProductImage = ""; ProductImageOrigin = ""; } ProductVariable = variable; ProductName = product.ProductTitle; QuantityMainInstock = mainstock; QuantityMainInstockString = string.Format("{0:N0}", mainstock); ProductVariableSave = item.ProductVariableDescription; ProductVariableName = variablename; ProductVariableValue = variablevalue; } } else { PID = ProductVariableID; var productvariable = ProductVariableController.GetBySKU(SKU); if (productvariable != null) { SKU = productvariable.SKU.Trim().ToUpper(); double total = PJUtils.TotalProductQuantityInstock(agentIDSend, SKU); string variablename = ""; string variablevalue = ""; string variable = ""; string[] vs = productVariableDescription.Split('|'); if (vs.Length - 1 > 0) { for (int i = 0; i < vs.Length - 1; i++) { string[] items = vs[i].Split(':'); variable += items[0] + ":" + items[1] + "<br/>"; variablename += items[0] + "|"; variablevalue += items[1] + "|"; } } double mainstock = PJUtils.TotalProductQuantityInstock(1, SKU); QuantityInstock = total; QuantityInstockString = string.Format("{0:N0}", total); ProductImage = "<img src=\"" + Thumbnail.getURL(productvariable.Image, Thumbnail.Size.Small) + "\" alt=\"\" style=\"width:50px;\" />"; ProductImageOrigin = Thumbnail.getURL(productvariable.Image, Thumbnail.Size.Small); ProductVariable = variable; var product1 = ProductController.GetByID(Convert.ToInt32(productvariable.ProductID)); if (product1 != null) { ProductName = product1.ProductTitle; } QuantityMainInstock = mainstock; QuantityMainInstockString = string.Format("{0:N0}", mainstock); ProductVariableSave = item.ProductVariableDescription; ProductVariableName = variablename; ProductVariableValue = variablevalue; } } html += "<tr class=\"product-result\" data-mpdid=\"" + item.ID + "\" data-quantityinstock=\"" + QuantityInstock + "\" data-productimageorigin=\"" + ProductImageOrigin + "\" data-productvariable=\"" + ProductVariableSave + "\" data-productname=\"" + ProductName + "\" data-sku=\"" + SKU + "\" data-producttype=\"" + ProductType + "\" data-id=\"" + item.ID + "\" data-productnariablename=\"" + ProductVariableName + "\" data-productvariablevalue =\"" + ProductVariableValue + "\">"; html += " <td>" + ProductImage + ""; html += " <td>" + ProductName + "</td>"; html += " <td>" + SKU + "</td>"; html += " <td>" + SupplierName + "</td>"; html += " <td>" + ProductVariable + "</td>"; html += " <td>" + item.QuantiySend + "</td>"; html += " <td style=\"width:20%;\"><input type=\"text\" min=\"0\" class=\"form-control in-quanlity\" style=\"width: 40%;margin: 0 auto;\" value=\"" + item.QuantityReceive + "\" onkeyup=\"checkQuantiy($(this))\" onkeypress='return event.charCode >= 48 && event.charCode <= 57'/></td>"; //html += " <td><a href=\"javascript:;\" onclick=\"deleteRow($(this))\">Xóa</a></td>"; //html += " <td></td>"; html += "</tr>"; } ltrProducts.Text = html; hdfListProductSend.Value = listSKU; } #endregion } } } }
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 void LoadData(int userRole) { 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; if (Convert.ToInt32(ViewState["role"]) == 0 || Convert.ToInt32(ViewState["role"]) == 1) { ltrEdit1.Text = "<a href=\"/thong-tin-san-pham.aspx?id=" + p.ID + "\" class=\"btn primary-btn fw-btn not-fullwidth\">Chỉnh sửa</a>"; ltrEdit2.Text = "<a href=\"/thong-tin-san-pham.aspx?id=" + p.ID + "\" class=\"btn primary-btn fw-btn not-fullwidth\">Chỉnh sửa</a>"; } lbProductTitle.Text = p.ProductTitle; pContent.Text = p.ProductContent; lblSKU.Text = p.ProductSKU; var a = ProductController.GetAllSql(0, p.ProductSKU); if (a.Count() > 0) { foreach (var item in a) { lbProductStock.Text = item.TotalProductInstockQuantityLeft.ToString(); ddlStockStatus.SelectedValue = item.StockStatus.ToString(); } } else { lbProductStock.Text = "0"; } lbRegularPrice.Text = string.Format("{0:N0}", p.Regular_Price); ltrCostOfGood.Text = ""; if (userRole == 0) { ltrCostOfGood.Text += "<div class='form-row'>"; ltrCostOfGood.Text += " <div class='row-left'>"; ltrCostOfGood.Text += " Giá vốn"; ltrCostOfGood.Text += " </div>"; ltrCostOfGood.Text += " <div class='row-right'>"; ltrCostOfGood.Text += " <span class='form-control'>" + string.Format("{0:N0}", p.CostOfGood) + "</span>"; ltrCostOfGood.Text += " </div>"; ltrCostOfGood.Text += "</div>"; } lbRetailPrice.Text = string.Format("{0:N0}", p.Retail_Price); ddlSupplier.SelectedValue = p.SupplierID.ToString(); ddlCategory.SelectedValue = p.CategoryID.ToString(); lbMaterials.Text = p.Materials; lbpMinimumInventoryLevel.Text = p.MinimumInventoryLevel.ToString(); lbpMaximumInventoryLevel.Text = p.MaximumInventoryLevel.ToString(); 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 + "\" /></li>"; } } imageGallery.Text += "</ul>"; if (p.ProductImage != null) { ProductThumbnail.ImageUrl = p.ProductImage; } hdfTable.Value = p.ProductStyle.ToString(); var ka = ProductVariableController.SearchProductID(p.ID, ""); if (ka != null) { //var value = ProductVariableValueController.GetByProductVariableID(a.ID); } } List <tbl_ProductVariable> b = new List <tbl_ProductVariable>(); b = ProductVariableController.SearchProductID(id, ""); pagingall(b, userRole); } }