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; 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 (this.ddlShipping.SelectedValue == null || this.ddlShipping.SelectedValue == 0) { this.ShowMsg("请选择运费模版", false); return; } if (this.ddlUnit.SelectedValue == null || this.ddlUnit.SelectedValue == "") { this.ShowMsg("请选择计量单位", false); return; } if (this.ddlImportSourceType.SelectedValue == null || this.ddlImportSourceType.SelectedValue == 0) { 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; } } //供货商开关 bool needApprove = false; int supplierId = CheckSupplierRole(); if (supplierId != 0) { needApprove = SupplierHelper.GetSupplierApproveKey(supplierId); } 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, ProductCode = this.txtProductCode.Text, EnglishName = this.txtEnglishName.Text, SysProductName = this.txtsysProductName.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.HasValue ? this.ddlSupplier.SelectedValue : 0, 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, IsPromotion = this.ChkisPromotion.Checked, IsDisplayDiscount = this.ChkisDisplayDiscount.Checked, ProductTitle = this.txtProductTitle.Text, 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; this.ShowMsg("商品还未完成归类操作,不能出售", false); return; } 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 { 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)); } } 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}&approve={2}&supplier={3}", this.categoryId, productInfo.ProductId, productInfo.IsApproved, supplierId > 0 ? true : false)), 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); }