protected void btnSubmit_Click(object sender, EventArgs e) { DateTime currentDate = DateTime.Now; string username = Request.Cookies["userLoginSystem"].Value; bool check = true; string SKU = txtProductSKU.Text.Trim().ToUpper(); var productcheck = ProductController.GetBySKU(SKU); if (productcheck != null) { check = false; } else { var productvariable = ProductVariableController.GetBySKU(SKU); 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 { int parentID = ViewState["productid"].ToString().ToInt(0); var parentProduct = ProductController.GetByID(parentID); bool isHidden = false; double Stock = 0; double Regular_Price = Convert.ToDouble(pRegular_Price.Text); double CostOfGood = Convert.ToDouble(pCostOfGood.Text); double RetailPrice = Convert.ToDouble(pRetailPrice.Text); int StockStatus = 1; bool ManageStock = true; //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 + parentID.ToString() + '-' + convertToSlug(Path.GetFileName(f.FileName)); try { f.SaveAs(Server.MapPath(o)); ProductImage = o; } catch { } } } ProductVariableController.Insert(parentProduct.ID, parentProduct.ProductSKU, SKU, Stock, StockStatus, Regular_Price, CostOfGood, RetailPrice, ProductImage, ManageStock, isHidden, currentDate, username, Convert.ToInt32(parentProduct.SupplierID), parentProduct.SupplierName, Convert.ToDouble(pMinimumInventoryLevel.Text), Convert.ToDouble(pMaximumInventoryLevel.Text)); PJUtils.ShowMessageBoxSwAlert("Thêm biến thể sản phẩm thành công", "s", 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); } } } } } }
private void _updateProductVariation(tbl_Account acc) { if (String.IsNullOrEmpty(hdfVariableListInsert.Value)) { var strFunction = ""; strFunction = "HoldOn.close();"; strFunction = "swal({title: 'Lỗi', text: 'Quá trình cập nhật biến thể đã xảy ra lỗi', type: 'error'});"; JavaScript.BeforePageLoad(Page).ExecuteCustomScript(strFunction); return; } var productID = ViewState["ID"].ToString().ToInt(0); var productSKU = ViewState["SKU"].ToString(); var uploadPath = "/uploads/images/"; var imageDefault = "/App_Themes/Ann/image/placeholder.png"; #region Xóa biến thể var variationRemovalList = JsonConvert.DeserializeObject <List <string> >(hdfVariationRemovalList.Value); foreach (var sku in variationRemovalList) { ProductVariableController.removeByVariationSKU(sku); } #endregion #region Cập nhật biến thể var productVariationUpdateList = JsonConvert.DeserializeObject <List <ProductVariationUpdateModel> >(hdfVariableListInsert.Value); if (uploadVariationImage.HasFiles) { foreach (var file in uploadVariationImage.PostedFiles) { var fileName = file.FileName; var imageName = _uploadImage(productID, file); productVariationUpdateList .Where(x => x.image == uploadPath + fileName) .Select(x => { x.image = uploadPath + imageName; return(x); }); } } foreach (var item in productVariationUpdateList) { var now = DateTime.Now; // Kiểm tra sản phẩm biến thể có tồn tại hay không để thực hiện insert hoặc update var productVariation = ProductVariableController.GetByID(item.productVariationID); var image = String.Empty; if (item.image != imageDefault) { image = item.image.Replace(uploadPath, String.Empty); } if (productVariation != null) { // Thực hiện update biến thể var productVariationID = ProductVariableController.Update( ID: productVariation.ID, ProductID: productID, ParentSKU: productSKU, SKU: item.sku, Stock: Convert.ToDouble(productVariation.Stock), StockStatus: Convert.ToInt32(productVariation.StockStatus), Regular_Price: item.regularPrice, CostOfGood: item.costOfGood, RetailPrice: item.retailPrice, Image: image, ManageStock: true, IsHidden: false, ModifiedDate: now, ModifiedBy: acc.Username, SupplierID: Convert.ToInt32(productVariation.SupplierID), SupplierName: productVariation.SupplierName, MinimumInventoryLevel: item.minimumInventoryLevel, MaximumInventoryLevel: item.maximumInventoryLevel ); // Xóa tất cả giá trị của biến thể để cập nhật lại ProductVariableValueController.DeleteByProductVariableID(productVariation.ID); // Khởi tạo biến thể cho sản phẩm con _createVariationValue(new VariationValueUpdateModel() { productVariationID = Convert.ToInt32(productVariationID), productVariationSKU = item.sku, variationValueID = item.variationValueID, variationName = item.variationName, variationValueName = item.variationValueName, isHidden = false, createdDate = now, createdBy = acc.Username }); } else { // Tạo sản phẩm biến thể mới var productVariationID = ProductVariableController.Insert( ProductID: productID, ParentSKU: productSKU, SKU: item.sku, Stock: 0, StockStatus: item.stockStatus, Regular_Price: item.regularPrice, CostOfGood: item.costOfGood, RetailPrice: item.retailPrice, Image: image, ManageStock: true, IsHidden: false, CreatedDate: now, CreatedBy: acc.Username, SupplierID: ddlSupplier.SelectedValue.ToInt(0), SupplierName: ddlSupplier.SelectedItem.ToString(), MinimumInventoryLevel: item.minimumInventoryLevel, MaximumInventoryLevel: item.maximumInventoryLevel); // Khởi tạo biến thể cho sản phẩm con _createVariationValue(new VariationValueUpdateModel() { productVariationID = Convert.ToInt32(productVariationID), productVariationSKU = item.sku, variationValueID = item.variationValueID, variationName = item.variationName, variationValueName = item.variationValueName, isHidden = false, createdDate = now, createdBy = acc.Username }); } } #endregion }
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); } } }