private void ProcessTaobaoProductDown(HttpContext context) { ProductInfo product = new ProductInfo(); product.CategoryId = 0; product.BrandId = 0; product.ProductName = HttpUtility.UrlDecode(context.Request.Form["ProductName"]); product.ProductCode = context.Request.Form["ProductCode"]; product.Description = HttpUtility.UrlDecode(context.Request.Form["Description"]); if (context.Request.Form["SaleStatus"] == "onsale") { product.SaleStatus = ProductSaleStatus.OnSale; } else { product.SaleStatus = ProductSaleStatus.OnStock; } product.AddedDate = DateTime.Parse(context.Request.Form["AddedDate"]); product.TaobaoProductId = long.Parse(context.Request.Form["TaobaoProductId"]); string str = context.Request.Form["ImageUrls"]; if (!string.IsNullOrEmpty(str)) { this.DownloadImage(product, str, context); } product.TypeId = new int?(ProductTypeHelper.GetTypeId(context.Request.Form["TypeName"])); int weight = int.Parse(context.Request.Form["Weight"]); Dictionary <string, SKUItem> skus = this.GetSkus(product, weight, context); product.LowestSalePrice = skus.Values.First <SKUItem>().SalePrice; ProductActionStatus status = ProductHelper.AddProduct(product, skus, null, null); if (status == ProductActionStatus.Success) { TaobaoProductInfo taobaoProduct = this.GetTaobaoProduct(context); taobaoProduct.ProductId = product.ProductId; taobaoProduct.ProTitle = product.ProductName; taobaoProduct.Num = product.Stock; ProductHelper.UpdateToaobProduct(taobaoProduct); } context.Response.Write(status.ToString()); }
public AddProductResponse AddProduct(AddProductRequest request) { AddProductResponse addProductResponse = new AddProductResponse(); addProductResponse.Message = "Product not added successfully."; if (String.IsNullOrEmpty(request.AuthToken)) { addProductResponse.Message = "Please pass all mandatory fields."; return(addProductResponse); } AuthenticationToken authToken = new Helper().GetAuthenticationToken(request.AuthToken); if (authToken == null) { addProductResponse.Message = "Unauthorizes user."; return(addProductResponse); } if (String.IsNullOrEmpty(request.productInfo.Name) || String.IsNullOrEmpty(request.productInfo.Quantity)) { addProductResponse.Message = "Please pass all mandatory fields."; return(addProductResponse); } ProductEL productEL = new ProductEL(); productEL = MapperUtility.MapTo(request.productInfo, productEL); if (productHelper.AddProduct(productEL)) { addProductResponse.Message = "Product added successfully."; addProductResponse.IsSuccess = true; return(addProductResponse); } else { addProductResponse.Message = "Some error occured."; return(addProductResponse); } }
private async void SaveProduct(object obj) { Close?.Invoke(); if (edited == false) { await productsHelper.AddProduct( SelectedProduct?.ProductName ?? "no data", SelectedProduct?.Price ?? "0", SelectedProduct?.Date ?? "0/0/0000", SelectedProduct?.Status ?? "no" ); } if (edited == true) { await productsHelper.UpdateProduct( SelectedProduct.ID, SelectedProduct.ProductName, SelectedProduct.Price, SelectedProduct.Date, SelectedProduct.Status); } }
private void btnAdd_Click(object sender, System.EventArgs e) { decimal num; decimal num2; decimal num3; decimal?num4; decimal?marketPrice; int stock; int alertStock; decimal?num5; int lineId; if (!this.ValidateConverts(this.chkSkuEnabled.Checked, out num, out num2, out num3, out num4, out marketPrice, out stock, out alertStock, out num5, out lineId)) { return; } if (!this.chkSkuEnabled.Checked) { if (num3 <= 0m) { this.ShowMsg("商品一口价必须大于0", false); return; } if (num4.HasValue && num4.Value >= num3) { this.ShowMsg("商品成本价必须小于商品一口价", false); return; } if (!(num <= num2)) { this.ShowMsg("分销商采购价必须要小于其最低零售价", false); return; } } string text = this.editDescription.Text; if (this.ckbIsDownPic.Checked) { text = base.DownRemotePic(text); } ProductInfo productInfo = new ProductInfo { CategoryId = this.categoryId, TypeId = this.dropProductTypes.SelectedValue, ProductName = this.txtProductName.Text, ProductCode = this.txtProductCode.Text, LineId = lineId, LowestSalePrice = num2, MarketPrice = marketPrice, Unit = this.txtUnit.Text, ImageUrl1 = this.uploader1.UploadedImageUrl, ImageUrl2 = this.uploader2.UploadedImageUrl, ImageUrl3 = this.uploader3.UploadedImageUrl, ImageUrl4 = this.uploader4.UploadedImageUrl, ImageUrl5 = this.uploader5.UploadedImageUrl, ThumbnailUrl40 = this.uploader1.ThumbnailUrl40, ThumbnailUrl60 = this.uploader1.ThumbnailUrl60, ThumbnailUrl100 = this.uploader1.ThumbnailUrl100, ThumbnailUrl160 = this.uploader1.ThumbnailUrl160, ThumbnailUrl180 = this.uploader1.ThumbnailUrl180, ThumbnailUrl220 = this.uploader1.ThumbnailUrl220, ThumbnailUrl310 = this.uploader1.ThumbnailUrl310, ThumbnailUrl410 = this.uploader1.ThumbnailUrl410, ShortDescription = this.txtShortDescription.Text, Description = (string.IsNullOrEmpty(text) || text.Length <= 0) ? null : text, PenetrationStatus = this.chkPenetration.Checked ? PenetrationStatus.Already : PenetrationStatus.Notyet, Title = this.txtTitle.Text, MetaDescription = this.txtMetaDescription.Text, MetaKeywords = this.txtMetaKeywords.Text, AddedDate = System.DateTime.Now, BrandId = this.dropBrandCategories.SelectedValue, MainCategoryPath = CatalogHelper.GetCategory(this.categoryId).Path + "|" }; ProductSaleStatus saleStatus = ProductSaleStatus.OnSale; if (this.radInStock.Checked) { saleStatus = ProductSaleStatus.OnStock; } if (this.radUnSales.Checked) { saleStatus = ProductSaleStatus.UnSale; } if (this.radOnSales.Checked) { saleStatus = ProductSaleStatus.OnSale; } productInfo.SaleStatus = saleStatus; System.Collections.Generic.Dictionary <int, System.Collections.Generic.IList <int> > attrs = null; System.Collections.Generic.Dictionary <string, SKUItem> dictionary; if (this.chkSkuEnabled.Checked) { productInfo.HasSKU = true; dictionary = base.GetSkus(this.txtSkus.Text); } else { dictionary = new System.Collections.Generic.Dictionary <string, SKUItem> { { "0", new SKUItem { SkuId = "0", SKU = this.txtSku.Text, SalePrice = num3, CostPrice = num4.HasValue ? num4.Value : 0m, PurchasePrice = num, Stock = stock, AlertStock = alertStock, Weight = num5.HasValue ? num5.Value : 0m } } }; if (this.txtMemberPrices.Text.Length > 0) { base.GetMemberPrices(dictionary["0"], this.txtMemberPrices.Text); } if (this.txtDistributorPrices.Text.Length > 0) { base.GetDistributorPrices(dictionary["0"], this.txtDistributorPrices.Text); } } if (!string.IsNullOrEmpty(this.txtAttributes.Text) && this.txtAttributes.Text.Length > 0) { attrs = base.GetAttributes(this.txtAttributes.Text); } ValidationResults validationResults = Validation.Validate <ProductInfo>(productInfo, new string[] { "AddProduct" }); if (!validationResults.IsValid) { this.ShowMsg(validationResults); return; } System.Collections.Generic.IList <int> list = new System.Collections.Generic.List <int>(); if (!string.IsNullOrEmpty(this.txtProductTag.Text.Trim())) { string text2 = this.txtProductTag.Text.Trim(); string[] array; if (text2.Contains(",")) { array = text2.Split(new char[] { ',' }); } else { array = new string[] { text2 }; } string[] array2 = array; for (int i = 0; i < array2.Length; i++) { string value = array2[i]; list.Add(System.Convert.ToInt32(value)); } } ProductActionStatus productActionStatus = ProductHelper.AddProduct(productInfo, dictionary, attrs, list); if (productActionStatus == ProductActionStatus.Success) { this.ShowMsg("添加商品成功", true); base.Response.Redirect(Globals.GetAdminAbsolutePath(string.Format("/product/AddProductComplete.aspx?categoryId={0}&productId={1}", this.categoryId, productInfo.ProductId)), true); return; } if (productActionStatus == ProductActionStatus.AttributeError) { this.ShowMsg("添加商品失败,保存商品属性时出错", false); return; } if (productActionStatus == ProductActionStatus.DuplicateName) { this.ShowMsg("添加商品失败,商品名称不能重复", false); return; } if (productActionStatus == ProductActionStatus.DuplicateSKU) { this.ShowMsg("添加商品失败,商家编码不能重复", false); return; } if (productActionStatus == ProductActionStatus.SKUError) { this.ShowMsg("添加商品失败,商家编码不能重复", false); return; } if (productActionStatus == ProductActionStatus.ProductTagEroor) { this.ShowMsg("添加商品失败,保存商品标签时出错", false); return; } this.ShowMsg("添加商品失败,未知错误", false); }
private void btnAdd_Click(object sender, System.EventArgs e) { int displaySequence; decimal salePrice; decimal?costPrice; decimal?marketPrice; int stock; int factstock; decimal?num4; decimal?referralDeduct; decimal?subMemberDeduct; decimal?subReferralDeduct; decimal?deductFee; int buyCardinality; decimal?grossweight; //销售类型 int saletype = string.IsNullOrWhiteSpace(this.dropSaleType.SelectedValue) ? 1 : Convert.ToInt32(this.dropSaleType.SelectedValue); if (!this.ValidateConverts(this.chkSkuEnabled.Checked, out displaySequence, out salePrice, out costPrice, out marketPrice, out stock, out factstock, out num4, out referralDeduct, out subMemberDeduct, out subReferralDeduct, out deductFee, out buyCardinality, out grossweight)) { return; } if (saletype != 2) { if (this.ddlImportSourceType.SelectedValue == null || this.ddlImportSourceType.SelectedValue == 0) { this.ShowMsg("请选择原产地", false); return; } } if (saletype != 2) { if (this.ddlSupplier.SelectedValue == null || this.ddlSupplier.SelectedValue == 0) { this.ShowMsg("请选择供货商", false); return; } } if (this.ddlUnit.SelectedValue == null || this.ddlUnit.SelectedValue == "") { this.ShowMsg("请选择计量单位", false); return; } if (this.ddlShipping.SelectedValue == null || this.ddlShipping.SelectedValue == 0) { this.ShowMsg("请选择运费模版", false); return; } int ConversionRelation; if (!int.TryParse(this.txtConversionRelation.Text, out ConversionRelation)) { this.ShowMsg("输入换算关系不正确", false); return; } if (!this.chkSkuEnabled.Checked) { if (salePrice <= 0m) { this.ShowMsg("商品一口价必须大于0", false); return; } if (costPrice.HasValue && (costPrice.Value > salePrice || costPrice.Value < 0m)) { this.ShowMsg("商品成本价必须大于0且小于商品一口价", false); return; } if (!costPrice.HasValue) //|| !deductFee.HasValue { this.ShowMsg("商品成本价不能为空", false); //与扣点 return; } if (string.IsNullOrEmpty(txtProductStandard.Text)) { this.ShowMsg("未开启多规格时,商品规格必填", false); return; } } string text = Globals.StripScriptTags(this.txtProductName.Text.Trim()); text = Globals.StripHtmlXmlTags(text).Replace("\\", "").Replace("'", ""); if (string.IsNullOrEmpty(text) || text == "") { this.ShowMsg("商品名称不能为空,且不能包含脚本标签、HTML标签、XML标签、反斜杠(\\)、单引号(')!", false); return; } //判断是否存在广告关键字 Dictionary <string, string> msg; if (!ValidateKeyWordHelper.ValidateKeyWord(new Dictionary <string, string>() { { "商品名称", this.txtProductName.Text }, { "商品简介", this.txtShortDescription.Text } }, out msg)) { System.Text.StringBuilder showMsg = new System.Text.StringBuilder(); foreach (string k in msg.Keys) { showMsg.Append(k + "中不能包含广告词:" + msg[k] + ";"); } this.ShowMsg(showMsg.ToString(), false); return; } string text2 = this.editDescription.Text; string text3 = this.editmobbileDescription.Text; if (this.ckbIsDownPic.Checked) { text2 = base.DownRemotePic(text2); text3 = base.DownRemotePic(text3); } System.Text.RegularExpressions.Regex regex = new System.Text.RegularExpressions.Regex("<script[^>]*?>.*?</script>", System.Text.RegularExpressions.RegexOptions.IgnoreCase); ProductInfo productInfo = new ProductInfo { CategoryId = this.categoryId, TypeId = this.dropProductTypes.SelectedValue, ProductName = text, EnglishName = this.txtEnglishName.Text, SysProductName = this.txtsysProductName.Text.Trim(), ProductCode = this.txtProductCode.Text, MarketPrice = marketPrice, Unit = this.ddlUnit.SelectedItem.Text, ImageUrl1 = this.uploader1.UploadedImageUrl, ImageUrl2 = this.uploader2.UploadedImageUrl, ImageUrl3 = this.uploader3.UploadedImageUrl, ImageUrl4 = this.uploader4.UploadedImageUrl, ImageUrl5 = this.uploader5.UploadedImageUrl, ThumbnailUrl40 = this.uploader1.ThumbnailUrl40, ThumbnailUrl60 = this.uploader1.ThumbnailUrl60, ThumbnailUrl100 = this.uploader1.ThumbnailUrl100, ThumbnailUrl160 = this.uploader1.ThumbnailUrl160, ThumbnailUrl180 = this.uploader1.ThumbnailUrl180, ThumbnailUrl220 = this.uploader1.ThumbnailUrl220, ThumbnailUrl310 = this.uploader1.ThumbnailUrl310, ThumbnailUrl410 = this.uploader1.ThumbnailUrl410, ShortDescription = this.txtShortDescription.Text, IsCustomsClearance = this.ChkisCustomsClearance.Checked, Description = (!string.IsNullOrEmpty(text2) && text2.Length > 0) ? regex.Replace(text2, "") : null, MobblieDescription = (!string.IsNullOrEmpty(text3) && text3.Length > 0) ? regex.Replace(text3, "") : null, Title = this.txtTitle.Text, MetaDescription = this.txtMetaDescription.Text, MetaKeywords = this.txtMetaKeywords.Text, AddedDate = System.DateTime.Now, BrandId = this.dropBrandCategories.SelectedValue, MainCategoryPath = CatalogHelper.GetCategory(this.categoryId).Path + "|", IsfreeShipping = this.ChkisfreeShipping.Checked, ReferralDeduct = referralDeduct, SubMemberDeduct = subMemberDeduct, SubReferralDeduct = subReferralDeduct, TaxRateId = this.dropTaxRate.SelectedValue, TemplateId = this.ddlShipping.SelectedValue, SupplierId = this.ddlSupplier.SelectedValue, ImportSourceId = this.ddlImportSourceType.SelectedValue, IsApproved = true, BuyCardinality = buyCardinality, UnitCode = this.ddlUnit.SelectedValue, Manufacturer = txtManufacturer.Text, ItemNo = txtItemNo.Text, BarCode = txtBarCode.Text, Ingredient = txtIngredient.Text, ProductStandard = txtProductStandard.Text, ConversionRelation = ConversionRelation, ProductTitle = this.txtProductTitle.Text, SaleType = saletype, IsPromotion = this.ChkisPromotion.Checked, IsDisplayDiscount = this.ChkisDisplayDiscount.Checked, Purchase = int.Parse(this.Rd_Purchase.SelectedValue), SectionDay = int.Parse(this.txtSectionDay.Text), PurchaseMaxNum = int.Parse(this.txtMaxCount.Text.ToString()) }; ProductSaleStatus saleStatus = ProductSaleStatus.OnSale; if (this.radInStock.Checked) { saleStatus = ProductSaleStatus.OnStock; } if (this.radUnSales.Checked) { saleStatus = ProductSaleStatus.UnSale; } if (this.radOnSales.Checked) { saleStatus = ProductSaleStatus.OnSale; if (productInfo.SaleType != 2) { this.ShowMsg("商品还未完成归类操作,不能出售", false); return; } } productInfo.SaleStatus = saleStatus; //如果是组合商品,默认已审价 if (productInfo.SaleType == 2) { productInfo.IsApprovedPrice = 1; } else { productInfo.IsApprovedPrice = 0; } System.Collections.Generic.Dictionary <int, System.Collections.Generic.IList <int> > attrs = null; System.Collections.Generic.Dictionary <string, SKUItem> dictionary; if (this.chkSkuEnabled.Checked) { productInfo.HasSKU = true; dictionary = base.GetSkus(this.txtSkus.Text); } else { AutoCalcCostPriceAndDeductFee(salePrice, ref costPrice, ref deductFee); dictionary = new System.Collections.Generic.Dictionary <string, SKUItem> { { "0", new SKUItem { SkuId = "0", SKU = Globals.HtmlEncode(Globals.StripScriptTags(this.txtSku.Text.Trim()).Replace("\\", "")), SalePrice = salePrice, CostPrice = costPrice.HasValue ? costPrice.Value : 0m, Stock = stock, FactStock = factstock, Weight = num4.HasValue ? num4.Value : 0m, DeductFee = deductFee.HasValue ? deductFee.Value :0m, GrossWeight = grossweight.HasValue?grossweight.Value:0m } } }; if (this.txtMemberPrices.Text.Length > 0) { base.GetMemberPrices(dictionary["0"], this.txtMemberPrices.Text); } } if (!string.IsNullOrEmpty(this.txtAttributes.Text) && this.txtAttributes.Text.Length > 0) { attrs = base.GetAttributes(this.txtAttributes.Text); } ValidationResults validationResults = Validation.Validate <ProductInfo>(productInfo, new string[] { "AddProduct" }); if (!validationResults.IsValid) { this.ShowMsg(validationResults); return; } System.Collections.Generic.IList <int> list = new System.Collections.Generic.List <int>(); if (!string.IsNullOrEmpty(this.txtProductTag.Text.Trim())) { string text4 = this.txtProductTag.Text.Trim(); string[] array; if (text4.Contains(",")) { array = text4.Split(new char[] { ',' }); } else { array = new string[] { text4 }; } string[] array2 = array; for (int i = 0; i < array2.Length; i++) { string value = array2[i]; list.Add(System.Convert.ToInt32(value)); } } #region ==组合商品 List <ProductsCombination> combinations = new List <ProductsCombination>(); string combinationInfos = base.Request.Form["selectProductsinfo"]; string[] curCom = combinationInfos.Split(new char[] { ',' }); string[] curCom2 = curCom; for (int i = 0; i < curCom2.Length; i++) { string combinationInfo = curCom2[i]; ProductsCombination com = new ProductsCombination(); string[] array3 = combinationInfo.Split(new char[] { '|' }); if (array3.Length == 10) { com.SkuId = array3[0]; com.ProductId = array3[1] == "" ? 0 : Convert.ToInt32(array3[1]); com.ProductName = array3[2]; com.ThumbnailsUrl = array3[3]; decimal tempweight; if (decimal.TryParse(array3[4], out tempweight)) { com.Weight = tempweight; } com.SKU = array3[5]; com.SKUContent = array3[6]; com.Quantity = array3[8] == "" ? 0 : Convert.ToInt32(array3[8]); decimal tempprice; if (decimal.TryParse(array3[9], out tempprice)) { com.Price = tempprice; } combinations.Add(com); } } productInfo.CombinationItemInfos = combinations; #endregion if (productInfo.SaleType == 2) { decimal CombinationTotalPrice = 0M; foreach (var item in productInfo.CombinationItemInfos) { CombinationTotalPrice += item.Price * item.Quantity; } if (Math.Round(CombinationTotalPrice, 2) != Math.Round(salePrice, 2)) { this.ShowMsg("添加商品失败,组合商品一口价和组合商品明细总价不一致", false); return; } } ProductActionStatus productActionStatus = ProductHelper.AddProduct(productInfo, dictionary, attrs, list, combinations); if (productActionStatus == ProductActionStatus.Success) { this.ShowMsg("添加商品成功", true); base.Response.Redirect(Globals.GetAdminAbsolutePath(string.Format("/product/AddProductComplete.aspx?categoryId={0}&productId={1}", this.categoryId, productInfo.ProductId)), true); return; } if (productActionStatus == ProductActionStatus.AttributeError) { this.ShowMsg("添加商品失败,保存商品属性时出错", false); return; } if (productActionStatus == ProductActionStatus.DuplicateName) { this.ShowMsg("添加商品失败,商品名称不能重复", false); return; } if (productActionStatus == ProductActionStatus.DuplicateSKU) { this.ShowMsg("添加商品失败,商家编码不能重复", false); return; } if (productActionStatus == ProductActionStatus.SKUError) { this.ShowMsg("添加商品失败,商品规格错误", false); return; } if (productActionStatus == ProductActionStatus.ProductTagEroor) { this.ShowMsg("添加商品失败,保存商品标签时出错", false); return; } this.ShowMsg("添加商品失败,未知错误", false); }
private void btnAdd_Click(object sender, EventArgs e) { int num2; int num3; decimal num4; decimal?nullable; decimal?nullable2; decimal?nullable3; string str = this.ucFlashUpload1.Value.Trim(); this.ucFlashUpload1.Value = str; string[] strArray = str.Split(new char[] { ',' }); string[] strArray2 = new string[] { "", "", "", "", "" }; for (int i = 0; (i < strArray.Length) && (i < 5); i++) { strArray2[i] = strArray[i]; } if (this.ValidateConverts(this.chkSkuEnabled.Checked, out num4, out nullable, out nullable2, out num2, out nullable3, out num3)) { if (!this.chkSkuEnabled.Checked) { if (num4 <= 0M) { this.ShowMsg("商品一口价必须大于0", false); return; } if (nullable.HasValue && (nullable.Value >= num4)) { this.ShowMsg("商品成本价必须小于商品一口价", false); return; } } string text = this.editDescription.Text; if (this.ckbIsDownPic.Checked) { text = base.DownRemotePic(text); } ProductInfo target = new ProductInfo { CategoryId = this.categoryId, TypeId = this.dropProductTypes.SelectedValue, ProductName = this.txtProductName.Text, ProductCode = this.txtProductCode.Text, MarketPrice = nullable2, Unit = this.txtUnit.Text, ImageUrl1 = strArray2[0], ImageUrl2 = strArray2[1], ImageUrl3 = strArray2[2], ImageUrl4 = strArray2[3], ImageUrl5 = strArray2[4], ThumbnailUrl40 = strArray2[0].Replace("/images/", "/thumbs40/40_"), ThumbnailUrl60 = strArray2[0].Replace("/images/", "/thumbs60/60_"), ThumbnailUrl100 = strArray2[0].Replace("/images/", "/thumbs100/100_"), ThumbnailUrl160 = strArray2[0].Replace("/images/", "/thumbs160/160_"), ThumbnailUrl180 = strArray2[0].Replace("/images/", "/thumbs180/180_"), ThumbnailUrl220 = strArray2[0].Replace("/images/", "/thumbs220/220_"), ThumbnailUrl310 = strArray2[0].Replace("/images/", "/thumbs310/310_"), ThumbnailUrl410 = strArray2[0].Replace("/images/", "/thumbs410/410_"), ShortDescription = this.txtShortDescription.Text, IsfreeShipping = this.ChkisfreeShipping.Checked, Description = (!string.IsNullOrEmpty(text) && (text.Length > 0)) ? text : null, AddedDate = DateTime.Now, BrandId = this.dropBrandCategories.SelectedValue, MainCategoryPath = CatalogHelper.GetCategory(this.categoryId).Path + "|" }; ProductSaleStatus onSale = ProductSaleStatus.OnSale; if (this.radInStock.Checked) { onSale = ProductSaleStatus.OnStock; } if (this.radUnSales.Checked) { onSale = ProductSaleStatus.UnSale; } if (this.radOnSales.Checked) { onSale = ProductSaleStatus.OnSale; } target.SaleStatus = onSale; Dictionary <string, SKUItem> skus = null; Dictionary <int, IList <int> > attrs = null; if (this.chkSkuEnabled.Checked) { target.HasSKU = true; skus = base.GetSkus(this.txtSkus.Text); } else { Dictionary <string, SKUItem> dictionary3 = new Dictionary <string, SKUItem>(); SKUItem item = new SKUItem { SkuId = "0", SKU = this.txtSku.Text, SalePrice = num4, CostPrice = nullable.HasValue ? nullable.Value : 0M, Stock = num2, Weight = nullable3.HasValue ? nullable3.Value : 0M }; dictionary3.Add("0", item); skus = dictionary3; if (this.txtMemberPrices.Text.Length > 0) { base.GetMemberPrices(skus["0"], this.txtMemberPrices.Text); } } if (!string.IsNullOrEmpty(this.txtAttributes.Text) && (this.txtAttributes.Text.Length > 0)) { attrs = base.GetAttributes(this.txtAttributes.Text); } ValidationResults validateResults = Hishop.Components.Validation.Validation.Validate <ProductInfo>(target, new string[] { "AddProduct" }); if (!validateResults.IsValid) { this.ShowMsg(validateResults); } else { IList <int> tagsId = new List <int>(); if (!string.IsNullOrEmpty(this.txtProductTag.Text.Trim())) { string str3 = this.txtProductTag.Text.Trim(); string[] strArray3 = null; if (str3.Contains(",")) { strArray3 = str3.Split(new char[] { ',' }); } else { strArray3 = new string[] { str3 }; } foreach (string str4 in strArray3) { tagsId.Add(Convert.ToInt32(str4)); } } switch (ProductHelper.AddProduct(target, skus, attrs, tagsId, wid)) { case ProductActionStatus.Success: this.ShowMsg("添加商品成功", true); base.Response.Redirect(Globals.GetAdminAbsolutePath(string.Format("/product/AddProductComplete.aspx?categoryId={0}&productId={1}", this.categoryId, target.ProductId)), true); return; case ProductActionStatus.AttributeError: this.ShowMsg("添加商品失败,保存商品属性时出错", false); return; case ProductActionStatus.DuplicateName: this.ShowMsg("添加商品失败,商品名称不能重复", false); return; case ProductActionStatus.DuplicateSKU: this.ShowMsg("添加商品失败,商家编码不能重复", false); return; case ProductActionStatus.SKUError: this.ShowMsg("添加商品失败,商家编码不能重复", false); return; case ProductActionStatus.ProductTagEroor: this.ShowMsg("添加商品失败,保存商品标签时出错", false); return; } this.ShowMsg("添加商品失败,未知错误", false); } } }
public ActionResult Post([FromBody] Product product) { return(Ok(ProductHelper.AddProduct(product))); }
private void btnImport_Click(object sender, EventArgs e) { string selectedValue = this.dropFiles.SelectedValue; selectedValue = Path.Combine(this._dataPath, selectedValue); if (!File.Exists(selectedValue)) { this.ShowMsg("选择的数据包文件有问题!", false); } else { int num = 0; int num2 = 0; this.PrepareDataFiles(selectedValue); List <List <string> > list = this.ReadCsv(this.csvPath, true, '\t', Encoding.GetEncoding("GB2312")); int i = 0; for (int count = list.Count; i < count; i++) { ProductInfo productInfo = new ProductInfo(); productInfo.AuditStatus = ProductAuditStatus.Pass; try { List <string> list2 = list[i]; if (list2[18] != "") { DataTable brandCategories = CatalogHelper.GetBrandCategories(list2[18]); if (brandCategories.Rows.Count > 0) { productInfo.BrandId = Convert.ToInt32(brandCategories.Rows[0]["BrandId"]); } } if (list2[1] != "") { DataTable categoryes = CatalogHelper.GetCategoryes(list2[1]); if (categoryes.Rows.Count > 0) { productInfo.CategoryId = Convert.ToInt32(categoryes.Rows[0]["CategoryId"]); } else { productInfo.CategoryId = 0; } } else { productInfo.CategoryId = 0; } if (list2[7] != "") { string path = Path.Combine(this.csvPath.Replace(".csv", ""), list2[7]); using (StreamReader streamReader = new StreamReader(path, Encoding.GetEncoding("gb2312"))) { productInfo.Description = streamReader.ReadToEnd(); } } if (productInfo.CategoryId > 0) { productInfo.MainCategoryPath = CatalogHelper.GetCategory(productInfo.CategoryId).Path + "|"; } productInfo.HasSKU = (int.Parse(list2[19]) == 1); productInfo.ImageUrl1 = ""; productInfo.ImageUrl2 = ""; productInfo.ImageUrl3 = ""; productInfo.ImageUrl4 = ""; productInfo.ImageUrl5 = ""; if (list2[12] != "") { FileInfo fileInfo = new FileInfo(Path.Combine(this.csvPath.Replace(".csv", ""), list2[12])); if (fileInfo.Exists) { this.GetImg(fileInfo.FullName, ref productInfo, 1); } } if (list2[13] != "") { FileInfo fileInfo2 = new FileInfo(Path.Combine(this.csvPath.Replace(".csv", ""), list2[13])); if (fileInfo2.Exists) { this.GetImg(fileInfo2.FullName, ref productInfo, 2); } } if (list2[14] != "") { FileInfo fileInfo3 = new FileInfo(Path.Combine(this.csvPath.Replace(".csv", ""), list2[14])); if (fileInfo3.Exists) { this.GetImg(fileInfo3.FullName, ref productInfo, 3); } } if (list2[15] != "") { FileInfo fileInfo4 = new FileInfo(Path.Combine(this.csvPath.Replace(".csv", ""), list2[15])); if (fileInfo4.Exists) { this.GetImg(fileInfo4.FullName, ref productInfo, 4); } } if (list2[16] != "") { FileInfo fileInfo5 = new FileInfo(Path.Combine(this.csvPath.Replace(".csv", ""), list2[16])); if (fileInfo5.Exists) { this.GetImg(fileInfo5.FullName, ref productInfo, 5); } } if (list2[17] != "") { productInfo.MarketPrice = decimal.Parse(list2[17]); } if (list2[9] != "") { productInfo.Meta_Description = list2[9]; } if (list2[10] != "") { productInfo.Meta_Keywords = list2[10]; } if (list2[4] != "") { productInfo.ProductCode = list2[4]; } productInfo.ProductName = list2[3].Replace("\\", ""); string text = list2[11]; switch (text) { case "出售中": productInfo.SaleStatus = ProductSaleStatus.OnSale; break; case "下架区": productInfo.SaleStatus = ProductSaleStatus.UnSale; break; case "仓库中": productInfo.SaleStatus = ProductSaleStatus.OnStock; break; } if (list2[5] != "") { productInfo.ShortDescription = list2[5].Replace("\\", ""); } if (list2[8] != "") { productInfo.Title = list2[8].Replace("\\", ""); } if (list2[2] != "") { int typeId = ProductTypeHelper.GetTypeId(list2[2]); if (typeId > 0) { productInfo.TypeId = typeId; } } if (!productInfo.TypeId.HasValue) { productInfo.HasSKU = false; } if (list2[6] != "") { productInfo.Unit = list2[6]; } Dictionary <string, SKUItem> dictionary = null; Dictionary <int, IList <int> > dictionary2 = null; IList <int> list3 = new List <int>(); if (list2[20] == "") { dictionary = new Dictionary <string, SKUItem>(); SKUItem sKUItem = new SKUItem(); sKUItem.SkuId = "0"; sKUItem.CostPrice = decimal.Parse(list2[24].Split(';')[0]); sKUItem.SalePrice = decimal.Parse(list2[25].Split(';')[0]); sKUItem.SKU = list2[21].Split(';')[0]; sKUItem.Stock = int.Parse(list2[23].Split(';')[0]); sKUItem.Weight = decimal.Parse(list2[22].Split(';')[0]); dictionary.Add(sKUItem.SkuId, sKUItem); } else if (productInfo.TypeId.HasValue) { dictionary = new Dictionary <string, SKUItem>(); int value = productInfo.TypeId.Value; if (productInfo.HasSKU) { IList <AttributeInfo> attributes = ProductTypeHelper.GetAttributes(value, AttributeUseageMode.Choose); string[] array = list2[20].Split(';'); int num3 = array.Length; for (int j = 0; j < num3; j++) { SKUItem sKUItem2 = new SKUItem(); sKUItem2.CostPrice = decimal.Parse(list2[24].Split(';')[j]); sKUItem2.SalePrice = decimal.Parse(list2[25].Split(';')[j]); sKUItem2.SKU = list2[21].Split(';')[j]; sKUItem2.Stock = int.Parse(list2[23].Split(';')[j]); sKUItem2.Weight = decimal.Parse(list2[22].Split(';')[j]); string text2 = array[j]; Dictionary <int, int> dictionary3 = new Dictionary <int, int>(); string[] array2 = text2.Split(','); int num4 = 0; while (num4 < array2.Length) { string text3 = array2[num4]; string specificationName = text3.Split(':')[0]; string valueStr = text3.Split(':')[1]; int specificationId = ProductTypeHelper.GetSpecificationId(value, specificationName); if (specificationId > 0) { int specificationValueId = ProductTypeHelper.GetSpecificationValueId(specificationId, valueStr); if (specificationValueId > 0) { dictionary3.Add(specificationId, specificationValueId); num4++; continue; } productInfo.HasSKU = false; } else { productInfo.HasSKU = false; } break; } if (productInfo.HasSKU && dictionary3.Count > 0) { string text4 = ""; foreach (KeyValuePair <int, int> item in dictionary3) { sKUItem2.SkuItems.Add(item.Key, item.Value); text4 = text4 + item.Value + "_"; } sKUItem2.SkuId = text4.Substring(0, text4.Length - 1); dictionary.Add(sKUItem2.SkuId, sKUItem2); } } if (dictionary.Count > 0) { productInfo.HasSKU = true; } } else { SKUItem sKUItem3 = new SKUItem(); sKUItem3.SkuId = "0"; sKUItem3.CostPrice = decimal.Parse(list2[24].Split(';')[0]); sKUItem3.SalePrice = decimal.Parse(list2[25].Split(';')[0]); sKUItem3.SKU = list2[21].Split(';')[0]; sKUItem3.Stock = int.Parse(list2[23].Split(';')[0]); sKUItem3.Weight = int.Parse(list2[22].Split(';')[0]); dictionary.Add(sKUItem3.SkuId, sKUItem3); } } if (list2[26] != "" && productInfo.TypeId.HasValue) { int value2 = productInfo.TypeId.Value; dictionary2 = new Dictionary <int, IList <int> >(); IList <AttributeInfo> attributes2 = ProductTypeHelper.GetAttributes(value2, AttributeUseageMode.View); foreach (AttributeInfo attribute in ProductTypeHelper.GetAttributes(value2, AttributeUseageMode.MultiView)) { attributes2.Add(attribute); } string[] array3 = list2[26].Split(','); foreach (string text5 in array3) { string value3 = text5.Split(':')[0]; string valueStr2 = text5.Split(':')[1]; bool flag = false; int num5 = 0; foreach (AttributeInfo item2 in attributes2) { if (item2.AttributeName.Equals(value3)) { num5 = item2.AttributeId; flag = true; break; } } if (flag) { int specificationValueId2 = ProductTypeHelper.GetSpecificationValueId(num5, valueStr2); if (specificationValueId2 > 0) { if (dictionary2.ContainsKey(num5)) { dictionary2[num5].Add(specificationValueId2); } else { dictionary2.Add(num5, new List <int> { specificationValueId2 }); } } } } } if (list2[27] != "") { list3 = new List <int>(); IList <TagInfo> tags = CatalogHelper.GetTags(); string[] array4 = list2[27].Split(','); foreach (string value4 in array4) { foreach (TagInfo item3 in tags) { if (item3.TagName.Equals(value4)) { list3.Add(item3.TagID); break; } } } } productInfo.AddedDate = DateTime.Now; if (list2.Count >= 28) { productInfo.ProductType = ((!(list2[28].Trim() == "实物商品")) ? 1 : 0); } if (list2.Count >= 29) { productInfo.IsValid = (list2[29].ToInt(0) == 1); } if (list2.Count >= 30) { productInfo.ValidStartDate = ((!productInfo.IsValid) ? list2[30].ToDateTime() : null); } if (list2.Count >= 31) { productInfo.ValidEndDate = ((!productInfo.IsValid) ? list2[31].ToDateTime() : null); } if (list2.Count >= 32) { productInfo.IsRefund = (list2[32].ToInt(0) == 1); } if (list2.Count >= 33) { productInfo.IsOverRefund = (list2[33].ToInt(0) == 1); } if (list2.Count >= 34) { productInfo.IsGenerateMore = (list2[34].ToInt(0) == 1); } switch (ProductHelper.AddProduct(productInfo, dictionary, dictionary2, list3, null, false, "")) { case ProductActionStatus.Success: num++; break; case ProductActionStatus.AttributeError: num2++; break; case ProductActionStatus.DuplicateName: num2++; break; case ProductActionStatus.DuplicateSKU: num2++; break; case ProductActionStatus.SKUError: num2++; break; default: num2++; break; } } catch (Exception ex) { Globals.WriteExceptionLog(ex, null, "ImportFromLocal"); num2++; } } File.Delete(this.csvPath); File.Delete(selectedValue); this.BindFiles(); if (num2 == 0) { this.ShowMsg("此次商品批量导入操作已成功!", true); } else { this.ShowMsg("此次商品批量导入操作," + num2 + "件商品导入失败!", false); } } }
private void btnSaveInfo_Click(object sender, System.EventArgs e) { //获取当前子账号门店 ManagerInfo currentManager = ManagerHelper.GetCurrentManager(); storeId = ManagerHelper.getClientUserIdBySenderId(currentManager.UserId); if (storeId <= 0) { this.CloseWindow(); } bool flag = false; foreach (RepeaterItem rs in SelectedProducts.Items) { System.Web.UI.HtmlControls.HtmlInputCheckBox chb = ((System.Web.UI.HtmlControls.HtmlInputCheckBox)rs.FindControl("chkboxProductid")); if (chb.Checked) { string productid = chb.Value;//获取选中项的productid System.Collections.Generic.IList <int> tagsId = null; System.Collections.Generic.Dictionary <int, System.Collections.Generic.IList <int> > dictionary; ProductInfo product = ProductHelper.GetProductDetails(Convert.ToInt32(productid), out dictionary, out tagsId); product.StoreId = storeId;//当前商品为当前门店所有 //爽爽挝啡:新上架的门店商品默认为待审核状态 if (Hidistro.ControlPanel.Config.CustomConfigHelper.Instance.AutoShipping && Hidistro.ControlPanel.Config.CustomConfigHelper.Instance.AnonymousOrder) { product.ReviewState = 1;//待审核 } product.AddedDate = DateTime.Now; switch (ProductHelper.AddProduct(product, product.Skus, dictionary, tagsId)) { case ProductActionStatus.Success: flag = true; break; case ProductActionStatus.DuplicateName: this.ShowMsg("添加商品失败,商品名称不能重复", false); return; case ProductActionStatus.DuplicateSKU: this.ShowMsg("添加商品失败,商家编码不能重复", false); return; case ProductActionStatus.SKUError: this.ShowMsg("添加商品失败,商家编码不能重复", false); return; case ProductActionStatus.AttributeError: this.ShowMsg("添加商品失败,保存商品属性时出错", false); return; case ProductActionStatus.ProductTagEroor: this.ShowMsg("添加商品失败,保存商品标签时出错", false); return; } } } if (flag) { this.ShowMsg("添加商品成功", true); this.CloseWindow(); } /* * System.Data.DataTable dt = new System.Data.DataTable(); * dt.Columns.Add("ProductId"); * dt.Columns.Add("ProductName"); * dt.Columns.Add("ProductCode"); * dt.Columns.Add("MarketPrice"); * if (this.grdSelectedProducts.Rows.Count > 0) * { * decimal result = 0m; * foreach (System.Web.UI.WebControls.GridViewRow row in this.grdSelectedProducts.Rows) * { * int num = (int)this.grdSelectedProducts.DataKeys[row.RowIndex].Value; * System.Web.UI.WebControls.TextBox box = row.FindControl("txtProductName") as System.Web.UI.WebControls.TextBox; * System.Web.UI.WebControls.TextBox box2 = row.FindControl("txtProductCode") as System.Web.UI.WebControls.TextBox; * System.Web.UI.WebControls.TextBox box3 = row.FindControl("txtMarketPrice") as System.Web.UI.WebControls.TextBox; * if (!string.IsNullOrEmpty(box3.Text.Trim()) && !decimal.TryParse(box3.Text.Trim(), out result)) * { * break; * } * if (string.IsNullOrEmpty(box3.Text.Trim())) * { * result = 0m; * } * System.Data.DataRow row2 = dt.NewRow(); * row2["ProductId"] = num; * row2["ProductName"] = Globals.HtmlEncode(box.Text.Trim()); * row2["ProductCode"] = Globals.HtmlEncode(box2.Text.Trim()); * if (result >= 0m) * { * row2["MarketPrice"] = result; * } * dt.Rows.Add(row2); * } * if (ProductHelper.UpdateProductBaseInfo(dt)) * { * this.CloseWindow(); * } * else * { * this.ShowMsg("批量修改商品信息失败", false); * } * this.BindProduct(); * } */ }
private void btnImport_Click(object sender, System.EventArgs e) { string text = this.dropFiles.SelectedValue; text = System.IO.Path.Combine(this._dataPath, text); if (!System.IO.File.Exists(text)) { this.ShowMsg("选择的数据包文件有问题!", false); return; } int num = 0; int num2 = 0; this.PrepareDataFiles(new object[] { text }); System.Collections.Generic.List <System.Collections.Generic.List <string> > list = this.ReadCsv(this.csvPath, true, '\t', System.Text.Encoding.GetEncoding("GB2312")); int i = 0; int count = list.Count; while (i < count) { ProductInfo productInfo = new ProductInfo(); try { System.Collections.Generic.List <string> list2 = list[i]; if (list2[18] != "") { System.Data.DataTable brandCategories = CatalogHelper.GetBrandCategories(list2[18]); if (brandCategories.Rows.Count > 0) { productInfo.BrandId = new int?(System.Convert.ToInt32(brandCategories.Rows[0]["BrandId"])); } } if (list2[1] != "") { System.Data.DataTable categoryes = CatalogHelper.GetCategoryes(list2[1]); if (categoryes.Rows.Count > 0) { productInfo.CategoryId = System.Convert.ToInt32(categoryes.Rows[0]["CategoryId"]); } else { productInfo.CategoryId = 0; } } else { productInfo.CategoryId = 0; } if (list2[7] != "") { string path = System.IO.Path.Combine(this.csvPath.Replace(".csv", ""), list2[7]); using (System.IO.StreamReader streamReader = new System.IO.StreamReader(path, System.Text.Encoding.GetEncoding("gb2312"))) { productInfo.Description = streamReader.ReadToEnd(); } } if (productInfo.CategoryId > 0) { productInfo.MainCategoryPath = CatalogHelper.GetCategory(productInfo.CategoryId).Path + "|"; } productInfo.HasSKU = (int.Parse(list2[19]) == 1); productInfo.ImageUrl1 = ""; productInfo.ImageUrl2 = ""; productInfo.ImageUrl3 = ""; productInfo.ImageUrl4 = ""; productInfo.ImageUrl5 = ""; if (list2[12] != "") { System.IO.FileInfo fileInfo = new System.IO.FileInfo(System.IO.Path.Combine(this.csvPath.Replace(".csv", ""), list2[12])); if (fileInfo.Exists) { this.GetImg(fileInfo.FullName, ref productInfo, 1); } } if (list2[13] != "") { System.IO.FileInfo fileInfo2 = new System.IO.FileInfo(System.IO.Path.Combine(this.csvPath.Replace(".csv", ""), list2[13])); if (fileInfo2.Exists) { this.GetImg(fileInfo2.FullName, ref productInfo, 2); } } if (list2[14] != "") { System.IO.FileInfo fileInfo3 = new System.IO.FileInfo(System.IO.Path.Combine(this.csvPath.Replace(".csv", ""), list2[14])); if (fileInfo3.Exists) { this.GetImg(fileInfo3.FullName, ref productInfo, 3); } } if (list2[15] != "") { System.IO.FileInfo fileInfo4 = new System.IO.FileInfo(System.IO.Path.Combine(this.csvPath.Replace(".csv", ""), list2[15])); if (fileInfo4.Exists) { this.GetImg(fileInfo4.FullName, ref productInfo, 4); } } if (list2[16] != "") { System.IO.FileInfo fileInfo5 = new System.IO.FileInfo(System.IO.Path.Combine(this.csvPath.Replace(".csv", ""), list2[16])); if (fileInfo5.Exists) { this.GetImg(fileInfo5.FullName, ref productInfo, 5); } } if (list2[17] != "") { productInfo.MarketPrice = new decimal?(decimal.Parse(list2[17])); } if (list2[9] != "") { productInfo.MetaDescription = list2[9]; } if (list2[10] != "") { productInfo.MetaKeywords = list2[10]; } if (list2[4] != "") { productInfo.ProductCode = list2[4]; } productInfo.ProductName = list2[3]; string text2 = list2[11]; string a; if ((a = text2) != null) { if (!(a == "出售中")) { if (!(a == "下架区")) { if (a == "仓库中") { productInfo.SaleStatus = ProductSaleStatus.OnStock; } } else { productInfo.SaleStatus = ProductSaleStatus.UnSale; } } else { productInfo.SaleStatus = ProductSaleStatus.OnSale; } } if (list2[5] != "") { productInfo.ShortDescription = list2[5]; } if (list2[8] != "") { productInfo.Title = list2[8]; } if (list2[2] != "") { int typeId = ProductTypeHelper.GetTypeId(list2[2]); if (typeId > 0) { productInfo.TypeId = new int?(typeId); } } if (!productInfo.TypeId.HasValue) { productInfo.HasSKU = false; } if (list2[6] != "") { productInfo.Unit = list2[6]; } System.Collections.Generic.Dictionary <string, SKUItem> dictionary = null; System.Collections.Generic.Dictionary <int, System.Collections.Generic.IList <int> > dictionary2 = null; System.Collections.Generic.IList <int> list3 = new System.Collections.Generic.List <int>(); if (list2[20] == "") { dictionary = new System.Collections.Generic.Dictionary <string, SKUItem>(); SKUItem sKUItem = new SKUItem(); sKUItem.SkuId = "0"; sKUItem.CostPrice = decimal.Parse(list2[24].Split(new char[] { ';' })[0]); sKUItem.SalePrice = decimal.Parse(list2[25].Split(new char[] { ';' })[0]); sKUItem.SKU = list2[21].Split(new char[] { ';' })[0]; sKUItem.Stock = int.Parse(list2[23].Split(new char[] { ';' })[0]); sKUItem.Weight = decimal.Parse(list2[22].Split(new char[] { ';' })[0]); dictionary.Add(sKUItem.SKU, sKUItem); } else { if (productInfo.TypeId.HasValue) { dictionary = new System.Collections.Generic.Dictionary <string, SKUItem>(); int value = productInfo.TypeId.Value; if (productInfo.HasSKU) { ProductTypeHelper.GetAttributes(value, AttributeUseageMode.Choose); string[] array = list2[20].Split(new char[] { ';' }); int num3 = array.Length; for (int j = 0; j < num3; j++) { SKUItem sKUItem2 = new SKUItem(); sKUItem2.CostPrice = decimal.Parse(list2[24].Split(new char[] { ';' })[j]); sKUItem2.SalePrice = decimal.Parse(list2[25].Split(new char[] { ';' })[j]); sKUItem2.SKU = list2[21].Split(new char[] { ';' })[j]; sKUItem2.Stock = int.Parse(list2[23].Split(new char[] { ';' })[j]); sKUItem2.Weight = decimal.Parse(list2[22].Split(new char[] { ';' })[j]); string text3 = array[j]; System.Collections.Generic.Dictionary <int, int> dictionary3 = new System.Collections.Generic.Dictionary <int, int>(); string[] array2 = text3.Split(new char[] { ',' }); for (int k = 0; k < array2.Length; k++) { string text4 = array2[k]; string specificationName = text4.Split(new char[] { ':' })[0]; string valueStr = text4.Split(new char[] { ':' })[1]; int specificationId = ProductTypeHelper.GetSpecificationId(value, specificationName); if (specificationId <= 0) { productInfo.HasSKU = false; break; } int specificationValueId = ProductTypeHelper.GetSpecificationValueId(specificationId, valueStr); if (specificationValueId <= 0) { productInfo.HasSKU = false; break; } dictionary3.Add(specificationId, specificationValueId); } if (productInfo.HasSKU && dictionary3.Count > 0) { string text5 = ""; foreach (System.Collections.Generic.KeyValuePair <int, int> current in dictionary3) { sKUItem2.SkuItems.Add(current.Key, current.Value); text5 = text5 + current.Value + "_"; } sKUItem2.SkuId = text5.Substring(0, text5.Length - 1); dictionary.Add(sKUItem2.SKU, sKUItem2); } } if (dictionary.Count > 0) { productInfo.HasSKU = true; } } else { SKUItem sKUItem3 = new SKUItem(); sKUItem3.SkuId = "0"; sKUItem3.CostPrice = decimal.Parse(list2[24].Split(new char[] { ';' })[0]); sKUItem3.SalePrice = decimal.Parse(list2[25].Split(new char[] { ';' })[0]); sKUItem3.SKU = list2[21].Split(new char[] { ';' })[0]; sKUItem3.Stock = int.Parse(list2[23].Split(new char[] { ';' })[0]); sKUItem3.Weight = int.Parse(list2[22].Split(new char[] { ';' })[0]); dictionary.Add(sKUItem3.SKU, sKUItem3); } } } if (list2[26] != "" && productInfo.TypeId.HasValue) { int value2 = productInfo.TypeId.Value; dictionary2 = new System.Collections.Generic.Dictionary <int, System.Collections.Generic.IList <int> >(); System.Collections.Generic.IList <AttributeInfo> attributes = ProductTypeHelper.GetAttributes(value2, AttributeUseageMode.View); foreach (AttributeInfo current2 in ProductTypeHelper.GetAttributes(value2, AttributeUseageMode.MultiView)) { attributes.Add(current2); } string[] array2 = list2[26].Split(new char[] { ',' }); for (int k = 0; k < array2.Length; k++) { string text6 = array2[k]; string value3 = text6.Split(new char[] { ':' })[0]; string valueStr2 = text6.Split(new char[] { ':' })[1]; bool flag = false; int num4 = 0; foreach (AttributeInfo current3 in attributes) { if (current3.AttributeName.Equals(value3)) { num4 = current3.AttributeId; flag = true; break; } } if (flag) { int specificationValueId2 = ProductTypeHelper.GetSpecificationValueId(num4, valueStr2); if (specificationValueId2 > 0) { if (dictionary2.ContainsKey(num4)) { dictionary2[num4].Add(specificationValueId2); } else { dictionary2.Add(num4, new System.Collections.Generic.List <int> { specificationValueId2 }); } } } } } if (list2[27] != "") { list3 = new System.Collections.Generic.List <int>(); System.Data.DataTable tags = CatalogHelper.GetTags(); string[] array2 = list2[27].Split(new char[] { ',' }); for (int k = 0; k < array2.Length; k++) { string obj = array2[k]; foreach (System.Data.DataRow dataRow in tags.Rows) { if (dataRow["TagName"].Equals(obj)) { list3.Add(System.Convert.ToInt32(dataRow["TagId"])); break; } } } } productInfo.AddedDate = System.DateTime.Now; ProductActionStatus productActionStatus = ProductHelper.AddProduct(productInfo, dictionary, dictionary2, list3); if (productActionStatus == ProductActionStatus.Success) { num++; } else { if (productActionStatus == ProductActionStatus.AttributeError) { num2++; } else { if (productActionStatus == ProductActionStatus.DuplicateName) { num2++; } else { if (productActionStatus == ProductActionStatus.DuplicateSKU) { num2++; } else { if (productActionStatus == ProductActionStatus.SKUError) { num2++; } else { num2++; } } } } } } catch { num2++; } i++; } System.IO.DirectoryInfo directoryInfo = new System.IO.DirectoryInfo(this.csvPath.Replace(".csv", "")); directoryInfo.Delete(true); System.IO.File.Delete(this.csvPath); System.IO.File.Delete(text); this.BindFiles(); if (num2 == 0) { this.ShowMsg("此次商品批量导入操作已成功!", true); return; } this.ShowMsg("此次商品批量导入操作," + num2 + "件商品导入失败!", false); }
private void btnAdd_Click(object sender, EventArgs e) { bool isfreeShipping = false; int shippingTemplateId = 0; int num = default(int); decimal num2 = default(decimal); decimal?nullable = default(decimal?); decimal?marketPrice = default(decimal?); int stock = default(int); int warningStock = default(int); decimal weight = default(decimal); decimal?secondLevelDeduct = default(decimal?); decimal?subMemberDeduct = default(decimal?); decimal?threeLevelDeduct = default(decimal?); decimal num3 = default(decimal); if (this.ValidateConverts(this.chkSkuEnabled.Checked, out num, out num2, out nullable, out marketPrice, out stock, out warningStock, out weight, out secondLevelDeduct, out subMemberDeduct, out threeLevelDeduct, out shippingTemplateId, out num3, out isfreeShipping)) { if (!this.chkSkuEnabled.Checked) { if (num2 <= decimal.Zero) { this.ShowMsg("商品一口价必须大于0", false); return; } if (nullable.HasValue && nullable.Value >= num2) { this.ShowMsg("商品成本价必须小于商品一口价", false); return; } } string content = Globals.StripScriptTags(this.txtProductName.Text.Trim()); content = Globals.StripHtmlXmlTags(content).Replace("\\", "").Replace("'", ""); if (string.IsNullOrEmpty(content) || content == "") { this.ShowMsg("产品名称不能为空,且不能包含脚本标签、HTML标签、XML标签、反斜杠(\\)、单引号(')!", false); } else { string text = this.editDescription.Text; string text2 = this.editmobbileDescription.Text; if (this.ckbIsDownPic.Checked) { text = base.DownRemotePic(text); text2 = base.DownRemotePic(text2); } ProductImagesInfo productImagesInfo = this.SaveProductImages(); Regex regex = new Regex("<script[^>]*?>.*?</script>", RegexOptions.IgnoreCase); ProductInfo productInfo = new ProductInfo { CategoryId = this.categoryId, TypeId = this.dropProductTypes.SelectedValue, ProductName = content, ProductCode = this.txtProductCode.Text, MarketPrice = marketPrice, Unit = this.txtUnit.Text, ImageUrl1 = productImagesInfo.ImageUrl1, ImageUrl2 = productImagesInfo.ImageUrl2, ImageUrl3 = productImagesInfo.ImageUrl3, ImageUrl4 = productImagesInfo.ImageUrl4, ImageUrl5 = productImagesInfo.ImageUrl5, ThumbnailUrl40 = productImagesInfo.ThumbnailUrl40, ThumbnailUrl60 = productImagesInfo.ThumbnailUrl60, ThumbnailUrl100 = productImagesInfo.ThumbnailUrl100, ThumbnailUrl160 = productImagesInfo.ThumbnailUrl160, ThumbnailUrl180 = productImagesInfo.ThumbnailUrl180, ThumbnailUrl220 = productImagesInfo.ThumbnailUrl220, ThumbnailUrl310 = productImagesInfo.ThumbnailUrl310, ThumbnailUrl410 = productImagesInfo.ThumbnailUrl410, ShortDescription = this.txtShortDescription.Text, Description = ((!string.IsNullOrEmpty(text) && text.Length > 0) ? regex.Replace(text, "") : null), MobbileDescription = ((!string.IsNullOrEmpty(text2) && text2.Length > 0) ? regex.Replace(text2, "") : null), Title = this.txtTitle.Text, Meta_Description = this.txtMetaDescription.Text, Meta_Keywords = this.txtMetaKeywords.Text, AddedDate = DateTime.Now, BrandId = this.dropBrandCategories.SelectedValue, MainCategoryPath = CatalogHelper.GetCategory(this.categoryId).Path + "|", IsfreeShipping = isfreeShipping, SecondLevelDeduct = secondLevelDeduct, SubMemberDeduct = subMemberDeduct, ThreeLevelDeduct = threeLevelDeduct, ShippingTemplateId = shippingTemplateId, SupplierId = 0, AuditStatus = ProductAuditStatus.Pass, IsCrossborder = this.chkIsCrossborder.Checked, ProductType = ((!this.radPhysicalProduct.Checked) ? 1 : 0), IsValid = this.valid.Checked, ValidStartDate = this.validStartDate.Text.ToDateTime(), ValidEndDate = (this.validEndDate.Text + " 23:59:59").ToDateTime(), IsRefund = this.IsRefund.Checked, IsOverRefund = this.IsOverRefund.Checked, IsGenerateMore = this.IsGenerateMore.Checked }; ProductSaleStatus saleStatus = ProductSaleStatus.OnSale; if (this.radInStock.Checked) { saleStatus = ProductSaleStatus.OnStock; } if (this.radUnSales.Checked) { saleStatus = ProductSaleStatus.UnSale; } if (this.radOnSales.Checked) { saleStatus = ProductSaleStatus.OnSale; } productInfo.SaleStatus = saleStatus; Dictionary <string, SKUItem> dictionary = null; Dictionary <int, IList <int> > attrs = null; if (this.chkSkuEnabled.Checked) { productInfo.HasSKU = true; dictionary = base.GetSkus(this.txtSkus.Text, weight); } else { dictionary = new Dictionary <string, SKUItem> { { "0", new SKUItem { SkuId = "0", SKU = Globals.HtmlEncode(Globals.StripScriptTags(this.txtSku.Text.Trim()).Replace("\\", "")), SalePrice = num2, CostPrice = (nullable.HasValue ? nullable.Value : decimal.Zero), Stock = stock, WarningStock = warningStock, Weight = weight } } }; if (this.txtMemberPrices.Text.Length > 0) { base.GetMemberPrices(dictionary["0"], this.txtMemberPrices.Text); } } if (!string.IsNullOrEmpty(this.txtAttributes.Text) && this.txtAttributes.Text.Length > 0) { attrs = base.GetAttributes(this.txtAttributes.Text); } ValidationResults validationResults = Validation.Validate(productInfo, "AddProduct"); if (!validationResults.IsValid) { this.ShowMsg(validationResults); } else { IList <int> list = new List <int>(); if (!string.IsNullOrEmpty(this.txtProductTag.Text.Trim())) { string text3 = this.txtProductTag.Text.Trim(); string[] array = null; array = ((!text3.Contains(",")) ? new string[1] { text3 } : text3.Split(',')); string[] array2 = array; foreach (string value in array2) { list.Add(Convert.ToInt32(value)); } } List <ProductSpecificationImageInfo> attrImgs = this.SaveProductAttributeImages(); string inputItemJson = ""; if (this.radServiceProduct.Checked) { inputItemJson = this.hidJson.Value; } switch (ProductHelper.AddProduct(productInfo, dictionary, attrs, list, attrImgs, false, inputItemJson)) { case ProductActionStatus.Success: this.ShowMsg("添加商品成功", true); base.Response.Redirect(Globals.GetAdminAbsolutePath($"/product/AddProductComplete.aspx?categoryId={this.categoryId}&productId={productInfo.ProductId}"), true); break; case ProductActionStatus.AttributeError: this.ShowMsg("添加商品失败,保存商品属性时出错", false); break; case ProductActionStatus.DuplicateName: this.ShowMsg("添加商品失败,商品名称不能重复", false); break; case ProductActionStatus.DuplicateSKU: this.ShowMsg("添加商品失败,商家编码不能重复", false); break; case ProductActionStatus.SKUError: this.ShowMsg("添加商品失败,商家规格错误", false); break; case ProductActionStatus.ProductTagEroor: this.ShowMsg("添加商品失败,保存商品标签时出错", false); break; case ProductActionStatus.ProductAttrImgsError: this.ShowMsg("添加商品失败,保存商品规格图片时出错", false); break; default: this.ShowMsg("添加商品失败,未知错误", false); break; } } } } }
private void btnAdd_Click(object sender, EventArgs e) { int num; int num2; int num3; decimal num4; decimal num5; decimal num6; decimal?nullable; decimal?nullable2; int? nullable3; decimal nullable4; if (this.ValidateConverts(out num4, out num5, out num6, out nullable, out nullable2, out num, out num2, out nullable3, out num3, out nullable4)) { string text = this.editDescription.Text; text = base.DownRemotePic(text); ProductInfo target = new ProductInfo { CategoryId = this.categoryId, ProductName = this.txtProductName.Text, ProductCode = this.txtProductCode.Text, //15.09.20 ProductSubName = this.txtSubhead.Text, ProductShortName = this.txtProductShortName.Text, ProductBarCode = this.txtProBarCode.Text, LineId = num3, LowestSalePrice = num5, MarketPrice = nullable2, OriginalPrice = nullable4, ImageUrl1 = this.uploader1.UploadedImageUrl, ImageUrl2 = this.uploader2.UploadedImageUrl, ImageUrl3 = this.uploader3.UploadedImageUrl, ImageUrl4 = this.uploader4.UploadedImageUrl, ImageUrl5 = this.uploader5.UploadedImageUrl, ThumbnailUrl40 = this.uploader1.ThumbnailUrl40, ThumbnailUrl60 = this.uploader1.ThumbnailUrl60, ThumbnailUrl100 = this.uploader1.ThumbnailUrl100, ThumbnailUrl160 = this.uploader1.ThumbnailUrl160, ThumbnailUrl180 = this.uploader1.ThumbnailUrl180, ThumbnailUrl220 = this.uploader1.ThumbnailUrl220, ThumbnailUrl310 = this.uploader1.ThumbnailUrl310, ThumbnailUrl410 = this.uploader1.ThumbnailUrl410, ShortDescription = this.txtShortDescription.Text, Description = (!string.IsNullOrEmpty(text) && (text.Length > 0)) ? text : null, AddedDate = DateTime.Now, MainCategoryPath = ProductHelper.GetCategory(this.categoryId).Path + "|", }; ProductSaleStatus onSale = ProductSaleStatus.OnStock; if (this.radInStock.Checked) { onSale = ProductSaleStatus.OnStock; } if (this.radUnSales.Checked) { onSale = ProductSaleStatus.UnSale; } target.SaleStatus = onSale; ValidationResults validateResults = ExhibFlat.Components.Validation.Validation.Validate <ProductInfo>( target, new string[] { "AddProduct" }); if (!validateResults.IsValid) { this.ShowMsg(validateResults); } else { switch (ProductHelper.AddProduct(target)) { case ProductActionStatus.Success: this.ShowMsg("添加商品成功", true); base.Response.Redirect( Globals.GetAdminAbsolutePath( string.Format("/product/AddProductComplete.aspx?categoryId={0}&productId={1}", this.categoryId, target.ProductId)), true); return; case ProductActionStatus.AttributeError: this.ShowMsg("添加商品失败,保存商品属性时出错", false); return; case ProductActionStatus.DuplicateName: this.ShowMsg("添加商品失败,商品名称或商家编码不能重复", false); return; case ProductActionStatus.DuplicateSKU: this.ShowMsg("添加商品失败,SKU编码不能重复", false); return; case ProductActionStatus.SKUError: this.ShowMsg("添加商品失败,SKU编码不能重复", false); return; case ProductActionStatus.ProductTagEroor: this.ShowMsg("添加商品失败,保存商品标签时出错", false); return; } this.ShowMsg("添加商品失败,未知错误", false); } } }
private void btnAdd_Click(object sender, EventArgs e) { int stock = 0; // num; int alertStock = 0; // num2; int lineId = 0; // num3; decimal purchasePrice = 0m; // num4; decimal lowestSalePrice = 0m; // num5; decimal salePrice = 0m; // num6; decimal?costPrice = null; // nullable; decimal?marketPrice = null; // nullable2; int? weight = null; // nullable3; // (bool skuEnabled, out int displaySequence, out decimal purchasePrice, out decimal lowestSalePrice, out decimal salePrice, out decimal? costPrice, out decimal? marketPrice, out int stock, out int alertStock, out int? weight) if (ValidateConverts(chkSkuEnabled.Checked, out purchasePrice, out lowestSalePrice, out salePrice, out costPrice, out marketPrice, out stock, out alertStock, out weight, out lineId)) { if (!chkSkuEnabled.Checked) { if (salePrice <= 0M) { ShowMsg("商品一口价必须大于0", false); return; } if (costPrice.HasValue && (costPrice.Value >= salePrice)) { ShowMsg("商品成本价必须小于商品一口价", false); return; } if (purchasePrice > lowestSalePrice) { ShowMsg("分销商采购价必须要小于其最低零售价", false); return; } } string text = editDescription.Text; if (ckbIsDownPic.Checked) { text = base.DownRemotePic(text); } ProductInfo target = new ProductInfo(); target.CategoryId = categoryId; target.TypeId = dropProductTypes.SelectedValue; target.ProductName = txtProductName.Text; target.ProductCode = txtProductCode.Text; target.LineId = lineId; // num3; target.LowestSalePrice = lowestSalePrice; // num5; target.MarketPrice = marketPrice; // nullable2; target.Unit = txtUnit.Text; target.ImageUrl1 = uploader1.UploadedImageUrl; target.ImageUrl2 = uploader2.UploadedImageUrl; target.ImageUrl3 = uploader3.UploadedImageUrl; target.ImageUrl4 = uploader4.UploadedImageUrl; target.ImageUrl5 = uploader5.UploadedImageUrl; target.ThumbnailUrl40 = uploader1.ThumbnailUrl40; target.ThumbnailUrl60 = uploader1.ThumbnailUrl60; target.ThumbnailUrl100 = uploader1.ThumbnailUrl100; target.ThumbnailUrl160 = uploader1.ThumbnailUrl160; target.ThumbnailUrl180 = uploader1.ThumbnailUrl180; target.ThumbnailUrl220 = uploader1.ThumbnailUrl220; target.ThumbnailUrl310 = uploader1.ThumbnailUrl310; target.ThumbnailUrl410 = uploader1.ThumbnailUrl410; target.ShortDescription = txtShortDescription.Text; target.Description = (!string.IsNullOrEmpty(text) && (text.Length > 0)) ? text : null; target.PenetrationStatus = chkPenetration.Checked ? PenetrationStatus.Already : PenetrationStatus.Notyet; target.Title = txtTitle.Text; target.MetaDescription = txtMetaDescription.Text; target.MetaKeywords = txtMetaKeywords.Text; target.AddedDate = DateTime.Now; target.BrandId = dropBrandCategories.SelectedValue; target.MainCategoryPath = CatalogHelper.GetCategory(categoryId).Path + "|"; //ProductInfo info = info3; //ProductInfo target = info; ProductSaleStatus onSale = ProductSaleStatus.OnSale; if (radInStock.Checked) { onSale = ProductSaleStatus.OnStock; } if (radUnSales.Checked) { onSale = ProductSaleStatus.UnSale; } if (radOnSales.Checked) { onSale = ProductSaleStatus.OnSale; } target.SaleStatus = onSale; Dictionary <string, SKUItem> skus = null; Dictionary <int, IList <int> > attrs = null; if (chkSkuEnabled.Checked) { target.HasSKU = true; skus = base.GetSkus(txtSkus.Text); } else { // Dictionary<string, SKUItem> dictionary3 = new Dictionary<string, SKUItem>(); skus = new Dictionary <string, SKUItem>(); SKUItem item = new SKUItem(); item.SkuId = "0"; item.SKU = txtSku.Text; item.SalePrice = salePrice;// num6; item.CostPrice = costPrice.HasValue ? costPrice.Value : 0M; item.PurchasePrice = purchasePrice; item.Stock = stock; // num; item.AlertStock = alertStock; // num2; item.Weight = weight.HasValue ? weight.Value : 0; //dictionary3.Add("0", item); //skus = dictionary3; skus.Add("0", item); if (txtMemberPrices.Text.Length > 0) { base.GetMemberPrices(skus["0"], txtMemberPrices.Text); } if (txtDistributorPrices.Text.Length > 0) { base.GetDistributorPrices(skus["0"], txtDistributorPrices.Text); } } if (!(string.IsNullOrEmpty(txtAttributes.Text) || (txtAttributes.Text.Length <= 0))) { attrs = base.GetAttributes(txtAttributes.Text); } ValidationResults validateResults = Hishop.Components.Validation.Validation.Validate <ProductInfo>(target, new string[] { "AddProduct" }); if (!validateResults.IsValid) { ShowMsg(validateResults); } else { switch (ProductHelper.AddProduct(target, skus, attrs)) { case ProductActionStatus.Success: { ShowMsg("添加商品成功", true); Response.Redirect(Globals.GetAdminAbsolutePath(string.Format("/product/AddProductComplete.aspx?categoryId={0}&productId={1}", categoryId, target.ProductId)), true); return; } case ProductActionStatus.DuplicateName: { ShowMsg("添加商品失败,商品名称不能重复", false); return; } case ProductActionStatus.DuplicateSKU: { ShowMsg("添加商品失败,商家编码不能重复", false); return; } case ProductActionStatus.SKUError: { ShowMsg("添加商品失败,商家编码不能重复", false); return; } case ProductActionStatus.AttributeError: { ShowMsg("添加商品失败,保存商品属性时出错", false); return; } } ShowMsg("添加商品失败,未知错误", false); } } }
private void btnAdd_Click(object sender, EventArgs e) { int num; int num2; int num3; decimal num4; decimal num5; decimal num6; decimal?nullable; decimal?nullable2; int? nullable3; if (this.ValidateConverts(this.chkSkuEnabled.Checked, out num4, out num5, out num6, out nullable, out nullable2, out num, out num2, out nullable3, out num3)) { if (!this.chkSkuEnabled.Checked) { if (num6 <= 0M) { this.ShowMsg("商品一口价必须大于0", false); return; } if (nullable.HasValue && (nullable.Value >= num6)) { this.ShowMsg("商品成本价必须小于商品一口价", false); return; } if (num4 > num5) { this.ShowMsg("分销商采购价必须要小于其最低零售价", false); return; } } string text = this.editDescription.Text; if (this.ckbIsDownPic.Checked) { text = base.DownRemotePic(text); } ProductInfo target = new ProductInfo { CategoryId = this.categoryId, TypeId = this.dropProductTypes.SelectedValue, ProductName = this.txtProductName.Text, ProductCode = this.txtProductCode.Text, LineId = num3, LowestSalePrice = num5, MarketPrice = nullable2, Unit = this.txtUnit.Text, ImageUrl1 = this.uploader1.UploadedImageUrl, ImageUrl2 = this.uploader2.UploadedImageUrl, ImageUrl3 = this.uploader3.UploadedImageUrl, ImageUrl4 = this.uploader4.UploadedImageUrl, ImageUrl5 = this.uploader5.UploadedImageUrl, ThumbnailUrl40 = this.uploader1.ThumbnailUrl40, ThumbnailUrl60 = this.uploader1.ThumbnailUrl60, ThumbnailUrl100 = this.uploader1.ThumbnailUrl100, ThumbnailUrl160 = this.uploader1.ThumbnailUrl160, ThumbnailUrl180 = this.uploader1.ThumbnailUrl180, ThumbnailUrl220 = this.uploader1.ThumbnailUrl220, ThumbnailUrl310 = this.uploader1.ThumbnailUrl310, ThumbnailUrl410 = this.uploader1.ThumbnailUrl410, ShortDescription = this.txtShortDescription.Text, Description = (!string.IsNullOrEmpty(text) && (text.Length > 0)) ? text : null, PenetrationStatus = this.chkPenetration.Checked ? PenetrationStatus.Already : PenetrationStatus.Notyet, Title = this.txtTitle.Text, MetaDescription = this.txtMetaDescription.Text, MetaKeywords = this.txtMetaKeywords.Text, AddedDate = DateTime.Now, BrandId = this.dropBrandCategories.SelectedValue, MainCategoryPath = CatalogHelper.GetCategory(this.categoryId).Path + "|" }; ProductSaleStatus onSale = ProductSaleStatus.OnSale; if (this.radInStock.Checked) { onSale = ProductSaleStatus.OnStock; } if (this.radUnSales.Checked) { onSale = ProductSaleStatus.UnSale; } if (this.radOnSales.Checked) { onSale = ProductSaleStatus.OnSale; } target.SaleStatus = onSale; Dictionary <string, SKUItem> skus = null; Dictionary <int, IList <int> > attrs = null; if (this.chkSkuEnabled.Checked) { target.HasSKU = true; skus = base.GetSkus(this.txtSkus.Text); } else { Dictionary <string, SKUItem> dictionary3 = new Dictionary <string, SKUItem>(); SKUItem item = new SKUItem { SkuId = "0", SKU = this.txtSku.Text, SalePrice = num6, CostPrice = nullable.HasValue ? nullable.Value : 0M, PurchasePrice = num4, Stock = num, AlertStock = num2, Weight = nullable3.HasValue ? nullable3.Value : 0 }; dictionary3.Add("0", item); skus = dictionary3; if (this.txtMemberPrices.Text.Length > 0) { base.GetMemberPrices(skus["0"], this.txtMemberPrices.Text); } if (this.txtDistributorPrices.Text.Length > 0) { base.GetDistributorPrices(skus["0"], this.txtDistributorPrices.Text); } } if (!string.IsNullOrEmpty(this.txtAttributes.Text) && (this.txtAttributes.Text.Length > 0)) { attrs = base.GetAttributes(this.txtAttributes.Text); } ValidationResults validateResults = Hishop.Components.Validation.Validation.Validate <ProductInfo>(target, new string[] { "AddProduct" }); if (!validateResults.IsValid) { this.ShowMsg(validateResults); } else { IList <int> tagsId = new List <int>(); if (!string.IsNullOrEmpty(this.txtProductTag.Text.Trim())) { string str2 = this.txtProductTag.Text.Trim(); string[] strArray = null; if (str2.Contains(",")) { strArray = str2.Split(new char[] { ',' }); } else { strArray = new string[] { str2 }; } foreach (string str3 in strArray) { tagsId.Add(Convert.ToInt32(str3)); } } switch (ProductHelper.AddProduct(target, skus, attrs, tagsId)) { case ProductActionStatus.Success: this.ShowMsg("添加商品成功", true); base.Response.Redirect(Globals.GetAdminAbsolutePath(string.Format("/product/AddProductComplete.aspx?categoryId={0}&productId={1}", this.categoryId, target.ProductId)), true); return; case ProductActionStatus.AttributeError: this.ShowMsg("添加商品失败,保存商品属性时出错", false); return; case ProductActionStatus.DuplicateName: this.ShowMsg("添加商品失败,商品名称不能重复", false); return; case ProductActionStatus.DuplicateSKU: this.ShowMsg("添加商品失败,商家编码不能重复", false); return; case ProductActionStatus.SKUError: this.ShowMsg("添加商品失败,商家编码不能重复", false); return; case ProductActionStatus.ProductTagEroor: this.ShowMsg("添加商品失败,保存商品标签时出错", false); return; } this.ShowMsg("添加商品失败,未知错误", false); } } }
public void CreateProductWithNull() { _productHelper.AddProduct(null); }
private void btnAdd_Click(object sender, System.EventArgs e) { decimal num3; decimal?nullable; decimal?nullable2; int num4; decimal?nullable3; int num5; if (this.ValidateConverts(this.chkSkuEnabled.Checked, out num3, out nullable, out nullable2, out num4, out nullable3, out num5)) { if (!this.chkSkuEnabled.Checked) { if (num3 <= 0m) { this.ShowMsg("商品一口价必须大于0", false); return; } if (nullable.HasValue && nullable.Value >= num3) { this.ShowMsg("商品成本价必须小于商品一口价", false); return; } } string text = this.editDescription.Text; if (this.ckbIsDownPic.Checked) { text = base.DownRemotePic(text); } string str1 = this.ucFlashUpload1.Value.Trim(); //this.ucFlashUpload1.Value = str1; string[] strArrays = str1.Split(new char[] { ',' }); string[] strArrays1 = new string[] { "", "", "", "", "" }; string[] strArrays2 = strArrays1; for (int i = 0; i < (int)strArrays.Length && i < 5; i++) { strArrays2[i] = strArrays[i]; } ProductInfo target = null; string strChecks = ""; if (CustomConfigHelper.Instance.BrandShow) { for (int i = 0; i < this.BrandCategories.Items.Count; i++) { bool a = this.BrandCategories.Items[i].Selected; if (a) { strChecks += this.BrandCategories.Items[i].Value + ","; } } target = new ProductInfo { CategoryId = this.categoryId, TypeId = this.dropProductTypes.SelectedValue, ProductName = this.txtProductName.Text, ProductCode = this.txtProductCode.Text, MarketPrice = nullable2, Unit = this.txtUnit.Text, Range = Convert.ToInt32(this.DDLRange.SelectedValue), ImageUrl1 = strArrays2[0], ImageUrl2 = strArrays2[1], ImageUrl3 = strArrays2[2], ImageUrl4 = strArrays2[3], ImageUrl5 = strArrays2[4], ThumbnailUrl40 = strArrays2[0].Replace("/images/", "/thumbs40/40_"), ThumbnailUrl60 = strArrays2[0].Replace("/images/", "/thumbs60/60_"), ThumbnailUrl100 = strArrays2[0].Replace("/images/", "/thumbs100/100_"), ThumbnailUrl160 = strArrays2[0].Replace("/images/", "/thumbs160/160_"), ThumbnailUrl180 = strArrays2[0].Replace("/images/", "/thumbs180/180_"), ThumbnailUrl220 = strArrays2[0].Replace("/images/", "/thumbs220/220_"), ThumbnailUrl310 = strArrays2[0].Replace("/images/", "/thumbs310/310_"), ThumbnailUrl410 = strArrays2[0].Replace("/images/", "/thumbs410/410_"), ShortDescription = this.txtShortDescription.Text, IsfreeShipping = this.ChkisfreeShipping.Checked, Description = (!string.IsNullOrEmpty(text) && text.Length > 0) ? text : null, AddedDate = System.DateTime.Now, BrandId = strChecks.TrimEnd(','), MainCategoryPath = CatalogHelper.GetCategory(this.categoryId).Path + "|" }; } else { target = new ProductInfo { CategoryId = this.categoryId, TypeId = this.dropProductTypes.SelectedValue, ProductName = this.txtProductName.Text, ProductCode = this.txtProductCode.Text, MarketPrice = nullable2, Unit = this.txtUnit.Text, Range = Convert.ToInt32(this.DDLRange.SelectedValue), ImageUrl1 = strArrays2[0], ImageUrl2 = strArrays2[1], ImageUrl3 = strArrays2[2], ImageUrl4 = strArrays2[3], ImageUrl5 = strArrays2[4], ThumbnailUrl40 = strArrays2[0].Replace("/images/", "/thumbs40/40_"), ThumbnailUrl60 = strArrays2[0].Replace("/images/", "/thumbs60/60_"), ThumbnailUrl100 = strArrays2[0].Replace("/images/", "/thumbs100/100_"), ThumbnailUrl160 = strArrays2[0].Replace("/images/", "/thumbs160/160_"), ThumbnailUrl180 = strArrays2[0].Replace("/images/", "/thumbs180/180_"), ThumbnailUrl220 = strArrays2[0].Replace("/images/", "/thumbs220/220_"), ThumbnailUrl310 = strArrays2[0].Replace("/images/", "/thumbs310/310_"), ThumbnailUrl410 = strArrays2[0].Replace("/images/", "/thumbs410/410_"), ShortDescription = this.txtShortDescription.Text, IsfreeShipping = this.ChkisfreeShipping.Checked, Description = (!string.IsNullOrEmpty(text) && text.Length > 0) ? text : null, AddedDate = System.DateTime.Now, BrandId = this.dropBrandCategories.SelectedValue.ToString(), MainCategoryPath = CatalogHelper.GetCategory(this.categoryId).Path + "|" }; } ProductSaleStatus onSale = ProductSaleStatus.OnSale; if (this.radInStock.Checked) { onSale = ProductSaleStatus.OnStock; } if (this.radUnSales.Checked) { onSale = ProductSaleStatus.UnSale; } if (this.radOnSales.Checked) { onSale = ProductSaleStatus.OnSale; } target.SaleStatus = onSale; target.StoreId = ManagerHelper.GetCurrentManager().ClientUserId; //pro辣特殊需求,不同门店可以上架不同商品,商品扩展storeid存的是当前门店管理员的clientid,对应分销商表的userid System.Collections.Generic.Dictionary <int, System.Collections.Generic.IList <int> > attrs = null; System.Collections.Generic.Dictionary <string, SKUItem> skus; if (this.chkSkuEnabled.Checked) { target.HasSKU = true; skus = base.GetSkus(this.txtSkus.Text); } else { System.Collections.Generic.Dictionary <string, SKUItem> dictionary3 = new System.Collections.Generic.Dictionary <string, SKUItem>(); SKUItem item = new SKUItem { SkuId = "0", SKU = this.txtSku.Text, SalePrice = num3, CostPrice = nullable.HasValue ? nullable.Value : 0m, Stock = num4, Weight = nullable3.HasValue ? nullable3.Value : 0m }; dictionary3.Add("0", item); skus = dictionary3; if (this.txtMemberPrices.Text.Length > 0) { base.GetMemberPrices(skus["0"], this.txtMemberPrices.Text); } } if (!string.IsNullOrEmpty(this.txtAttributes.Text) && this.txtAttributes.Text.Length > 0) { attrs = base.GetAttributes(this.txtAttributes.Text); } ValidationResults validateResults = Validation.Validate <ProductInfo>(target, new string[] { "AddProduct" }); if (!validateResults.IsValid) { this.ShowMsg(validateResults); } else { System.Collections.Generic.IList <int> tagsId = new System.Collections.Generic.List <int>(); if (!string.IsNullOrEmpty(this.txtProductTag.Text.Trim())) { string str2 = this.txtProductTag.Text.Trim(); string[] strArray; if (str2.Contains(",")) { strArray = str2.Split(new char[] { ',' }); } else { strArray = new string[] { str2 }; } string[] array = strArray; for (int i = 0; i < array.Length; i++) { string str3 = array[i]; tagsId.Add(System.Convert.ToInt32(str3)); } } //获取当前子账号门店,以判断子门店是否编辑过商品,若点击保存,商品直接被设置为待审核状态 ManagerInfo currentManager = ManagerHelper.GetCurrentManager(); int storeId = ManagerHelper.getClientUserIdBySenderId(currentManager.UserId); //如果当前子门店编辑过,商品设置为待审核状态 爽爽挝啡2.0 if (storeId > 0 && CustomConfigHelper.Instance.AutoShipping && CustomConfigHelper.Instance.AnonymousOrder) { target.ReviewState = 1;//待审核 } //如果当前子门店编辑过,商品设置为待审核状态 爽爽挝啡2.0 if (storeId > 0 && CustomConfigHelper.Instance.AutoShipping && CustomConfigHelper.Instance.AnonymousOrder) { target.ReviewState = 1;//待审核 } switch (ProductHelper.AddProduct(target, skus, attrs, tagsId)) { case ProductActionStatus.Success: this.ShowMsg("添加商品成功", true); base.Response.Redirect(Globals.GetAdminAbsolutePath(string.Format("/product/AddProductComplete.aspx?categoryId={0}&productId={1}", this.categoryId, target.ProductId)), true); return; case ProductActionStatus.DuplicateName: this.ShowMsg("添加商品失败,商品名称不能重复", false); return; case ProductActionStatus.DuplicateSKU: this.ShowMsg("添加商品失败,商家编码不能重复", false); return; case ProductActionStatus.SKUError: this.ShowMsg("添加商品失败,商家编码不能重复", false); return; case ProductActionStatus.AttributeError: this.ShowMsg("添加商品失败,保存商品属性时出错", false); return; case ProductActionStatus.ProductTagEroor: this.ShowMsg("添加商品失败,保存商品标签时出错", false); return; } this.ShowMsg("添加商品失败,未知错误", false); } } }