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> /// 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); } } }
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); } } } }
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); } } } } } }
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); } } }