Esempio n. 1
0
        public ShoppingCartItemInfo GetCartItemInfo(Member member, string skuId, int quantity, int storeId)
        {
            ShoppingCartItemInfo shoppingCartItemInfo = null;
            DbCommand            storedProcCommand    = this.database.GetStoredProcCommand("ss_ShoppingCart_GetItemInfo");

            this.database.AddInParameter(storedProcCommand, "Quantity", DbType.Int32, quantity);
            this.database.AddInParameter(storedProcCommand, "UserId", DbType.Int32, (member != null) ? member.UserId : 0);
            this.database.AddInParameter(storedProcCommand, "SkuId", DbType.String, skuId);
            this.database.AddInParameter(storedProcCommand, "GradeId", DbType.Int32, (member != null) ? member.GradeId : 0);
            using (IDataReader dataReader = this.database.ExecuteReader(storedProcCommand))
            {
                if (dataReader.Read())
                {
                    shoppingCartItemInfo                = new ShoppingCartItemInfo();
                    shoppingCartItemInfo.SkuId          = skuId;
                    shoppingCartItemInfo.ShippQuantity  = quantity;
                    shoppingCartItemInfo.Quantity       = quantity;
                    shoppingCartItemInfo.ProductId      = (int)dataReader["ProductId"];
                    shoppingCartItemInfo.BuyCardinality = 1;

                    if (dataReader["BuyCardinality"] != System.DBNull.Value)
                    {
                        shoppingCartItemInfo.BuyCardinality = (int)dataReader["BuyCardinality"];
                    }

                    shoppingCartItemInfo.Stock = 0;
                    if (DBNull.Value != dataReader["Stock"])
                    {
                        shoppingCartItemInfo.Stock = Convert.ToInt32(dataReader["Stock"]);
                    }
                    if (dataReader["SKU"] != DBNull.Value)
                    {
                        shoppingCartItemInfo.SKU = (string)dataReader["SKU"];
                    }
                    shoppingCartItemInfo.Name = (string)dataReader["ProductName"];
                    if (DBNull.Value != dataReader["Weight"])
                    {
                        shoppingCartItemInfo.Weight = (decimal)dataReader["Weight"];
                    }
                    shoppingCartItemInfo.MemberPrice = (shoppingCartItemInfo.AdjustedPrice = (decimal)dataReader["SalePrice"]);
                    if (DBNull.Value != dataReader["CountDownPrice"])
                    {
                        shoppingCartItemInfo.CountDownPrice = (decimal)dataReader["CountDownPrice"];
                    }
                    else
                    {
                        shoppingCartItemInfo.CountDownPrice = 0m;
                    }

                    if (DBNull.Value != dataReader["ThumbnailUrl40"])
                    {
                        shoppingCartItemInfo.ThumbnailUrl40 = dataReader["ThumbnailUrl40"].ToString();
                    }
                    if (DBNull.Value != dataReader["ThumbnailUrl60"])
                    {
                        shoppingCartItemInfo.ThumbnailUrl60 = dataReader["ThumbnailUrl60"].ToString();
                    }
                    if (DBNull.Value != dataReader["ThumbnailUrl100"])
                    {
                        shoppingCartItemInfo.ThumbnailUrl100 = dataReader["ThumbnailUrl100"].ToString();
                    }

                    if (DBNull.Value != dataReader["ThumbnailUrl160"])
                    {
                        shoppingCartItemInfo.ThumbnailUrl160 = dataReader["ThumbnailUrl160"].ToString();
                    }

                    if (DBNull.Value != dataReader["ThumbnailUrl180"])
                    {
                        shoppingCartItemInfo.ThumbnailUrl180 = dataReader["ThumbnailUrl180"].ToString();
                    }

                    if (DBNull.Value != dataReader["ThumbnailUrl220"])
                    {
                        shoppingCartItemInfo.ThumbnailUrl220 = dataReader["ThumbnailUrl220"].ToString();
                    }

                    if (DBNull.Value != dataReader["IsfreeShipping"])
                    {
                        shoppingCartItemInfo.IsfreeShipping = Convert.ToBoolean(dataReader["IsfreeShipping"]);
                    }
                    if (DBNull.Value != dataReader["TaxRate"])
                    {
                        shoppingCartItemInfo.TaxRate = Convert.ToDecimal(dataReader["TaxRate"]);
                    }
                    if (DBNull.Value != dataReader["MinTaxRate"])
                    {
                        shoppingCartItemInfo.MinTaxRate = Convert.ToDecimal(dataReader["MinTaxRate"]);
                    }
                    if (DBNull.Value != dataReader["MaxTaxRate"])
                    {
                        shoppingCartItemInfo.MaxTaxRate = Convert.ToDecimal(dataReader["MaxTaxRate"]);
                    }

                    if (DBNull.Value != dataReader["TaxRateId"])
                    {
                        shoppingCartItemInfo.TaxRateId = Convert.ToInt32(dataReader["TaxRateId"]);
                    }
                    if (DBNull.Value != dataReader["TemplateId"])
                    {
                        shoppingCartItemInfo.TemplateId = Convert.ToInt32(dataReader["TemplateId"]);
                    }
                    if (DBNull.Value != dataReader["SupplierId"])
                    {
                        shoppingCartItemInfo.SupplierId = Convert.ToInt32(dataReader["SupplierId"]);
                    }
                    if (DBNull.Value != dataReader["ShopName"])
                    {
                        shoppingCartItemInfo.SupplierName = dataReader["ShopName"].ToString();
                    }

                    if (DBNull.Value != dataReader["Logo"])
                    {
                        shoppingCartItemInfo.Logo = dataReader["Logo"].ToString();
                    }


                    shoppingCartItemInfo.IsCustomsClearance = false;
                    if (DBNull.Value != dataReader["IsCustomsClearance"])
                    {
                        shoppingCartItemInfo.IsCustomsClearance = Convert.ToBoolean(dataReader["IsCustomsClearance"]);
                    }
                    shoppingCartItemInfo.StoreId = storeId;//门店id

                    //品牌Id
                    if (DBNull.Value != dataReader["BrandId"])
                    {
                        shoppingCartItemInfo.BrandId = Convert.ToInt32(dataReader["BrandId"]);
                    }
                    //供应商Id
                    if (DBNull.Value != dataReader["CategoryId"])
                    {
                        shoppingCartItemInfo.CategoryId = Convert.ToInt32(dataReader["CategoryId"]);
                    }

                    // 销售类型
                    if (DBNull.Value != dataReader["SaleType"])
                    {
                        shoppingCartItemInfo.SaleType = Convert.ToInt32(dataReader["SaleType"]);
                    }

                    string text = string.Empty;
                    if (dataReader.NextResult())
                    {
                        while (dataReader.Read())
                        {
                            if (dataReader["AttributeName"] != DBNull.Value && !string.IsNullOrEmpty((string)dataReader["AttributeName"]) && dataReader["ValueStr"] != DBNull.Value && !string.IsNullOrEmpty((string)dataReader["ValueStr"]))
                            {
                                object obj = text;
                                text = string.Concat(new object[]
                                {
                                    obj,
                                    dataReader["AttributeName"],
                                    ":",
                                    dataReader["ValueStr"],
                                    "; "
                                });
                            }
                            shoppingCartItemInfo.DeductFee = decimal.Parse(dataReader["DeductFee"] == DBNull.Value ? "0" : dataReader["DeductFee"].ToString());
                        }
                    }
                    shoppingCartItemInfo.SkuContent = text;
                    PromotionInfo promotionInfo = null;
                    if (dataReader.NextResult() && dataReader.Read())
                    {
                        promotionInfo = DataMapper.PopulatePromote(dataReader);
                    }
                    if (promotionInfo != null)
                    {
                        shoppingCartItemInfo.PromoteType = promotionInfo.PromoteType;
                        switch (promotionInfo.PromoteType)
                        {
                        case PromoteType.Discount:
                            shoppingCartItemInfo.PromotionId   = promotionInfo.ActivityId;
                            shoppingCartItemInfo.PromotionName = promotionInfo.Name;
                            shoppingCartItemInfo.AdjustedPrice = shoppingCartItemInfo.MemberPrice * promotionInfo.DiscountValue;
                            break;

                        case PromoteType.Amount:
                            shoppingCartItemInfo.PromotionId   = promotionInfo.ActivityId;
                            shoppingCartItemInfo.PromotionName = promotionInfo.Name;
                            shoppingCartItemInfo.AdjustedPrice = promotionInfo.DiscountValue;
                            break;

                        case PromoteType.Reduced:
                            shoppingCartItemInfo.PromotionId   = promotionInfo.ActivityId;
                            shoppingCartItemInfo.PromotionName = promotionInfo.Name;
                            shoppingCartItemInfo.AdjustedPrice = shoppingCartItemInfo.MemberPrice - promotionInfo.DiscountValue;
                            break;

                        case PromoteType.QuantityDiscount:
                            if (shoppingCartItemInfo.Quantity >= (int)promotionInfo.Condition)
                            {
                                shoppingCartItemInfo.PromotionId   = promotionInfo.ActivityId;
                                shoppingCartItemInfo.PromotionName = promotionInfo.Name;
                                shoppingCartItemInfo.AdjustedPrice = shoppingCartItemInfo.MemberPrice * promotionInfo.DiscountValue;
                            }
                            break;

                        case PromoteType.SentGift:
                            shoppingCartItemInfo.PromotionId   = promotionInfo.ActivityId;
                            shoppingCartItemInfo.PromotionName = promotionInfo.Name;
                            shoppingCartItemInfo.IsSendGift    = true;
                            break;

                        case PromoteType.SentProduct:
                            if (shoppingCartItemInfo.Quantity / (int)promotionInfo.Condition >= 1)
                            {
                                shoppingCartItemInfo.PromotionId   = promotionInfo.ActivityId;
                                shoppingCartItemInfo.PromotionName = promotionInfo.Name;
                                shoppingCartItemInfo.ShippQuantity = shoppingCartItemInfo.Quantity + shoppingCartItemInfo.Quantity / (int)promotionInfo.Condition * (int)promotionInfo.DiscountValue;
                            }
                            break;

                        case PromoteType.PresentProduct:
                            if (shoppingCartItemInfo.Quantity / (int)promotionInfo.Condition >= 1)
                            {
                                shoppingCartItemInfo.PromotionId   = promotionInfo.ActivityId;
                                shoppingCartItemInfo.PromotionName = promotionInfo.Name;
                            }
                            break;

                        //单品满减
                        case PromoteType.ProductPromotion:
                            if (shoppingCartItemInfo.MemberPrice * shoppingCartItemInfo.Quantity >= promotionInfo.Condition)
                            {
                                shoppingCartItemInfo.PromotionId    = promotionInfo.ActivityId;
                                shoppingCartItemInfo.PromotionName  = promotionInfo.Name;
                                shoppingCartItemInfo.AdjustedPrice  = shoppingCartItemInfo.MemberPrice;
                                shoppingCartItemInfo.PromotionPrice = shoppingCartItemInfo.MemberPrice - promotionInfo.DiscountValue;
                                shoppingCartItemInfo.PromoteType    = PromoteType.ProductPromotion;
                            }
                            break;

                        //第二件减价
                        case PromoteType.SecondReducePrice:
                            if (shoppingCartItemInfo.Quantity >= 2 && shoppingCartItemInfo.MemberPrice * shoppingCartItemInfo.Quantity >= (promotionInfo.Condition))
                            {
                                shoppingCartItemInfo.PromotionId    = promotionInfo.ActivityId;
                                shoppingCartItemInfo.PromotionName  = promotionInfo.Name;
                                shoppingCartItemInfo.AdjustedPrice  = shoppingCartItemInfo.MemberPrice;
                                shoppingCartItemInfo.PromotionPrice = shoppingCartItemInfo.MemberPrice - promotionInfo.DiscountValue;
                                shoppingCartItemInfo.PromoteType    = PromoteType.SecondReducePrice;
                            }
                            break;

                        //第二件打折
                        case PromoteType.ProductDiscount:
                            if (shoppingCartItemInfo.Quantity >= 2)
                            {
                                shoppingCartItemInfo.PromotionId    = promotionInfo.ActivityId;
                                shoppingCartItemInfo.PromotionName  = promotionInfo.Name;
                                shoppingCartItemInfo.AdjustedPrice  = shoppingCartItemInfo.MemberPrice;
                                shoppingCartItemInfo.PromotionPrice = shoppingCartItemInfo.MemberPrice * promotionInfo.DiscountValue;
                                shoppingCartItemInfo.PromoteType    = PromoteType.ProductDiscount;
                            }
                            break;
                        }
                    }
                    // 促销活动(商品)中的赠送商品
                    if (dataReader.NextResult())
                    {
                        while (dataReader.Read())
                        {
                            ShoppingCartPresentInfo present = DataMapper.PopulatePresentCartItem(dataReader);
                            shoppingCartItemInfo.LinePresentPro.Add(present);
                        }
                    }

                    // 组合商品明细
                    if (dataReader.NextResult())
                    {
                        while (dataReader.Read())
                        {
                            ProductsCombination combination = DataMapper.PopulateCombinationCartItem(dataReader);
                            shoppingCartItemInfo.CombinationItemInfos.Add(combination);
                        }
                    }
                }
            }

            if (shoppingCartItemInfo != null && shoppingCartItemInfo.CombinationItemInfos != null &&
                shoppingCartItemInfo.CombinationItemInfos.Count > 1)
            {
                var SumBeforePrice = shoppingCartItemInfo.CombinationItemInfos.Take(shoppingCartItemInfo.CombinationItemInfos.Count - 1).Sum(t => t.Price * t.Quantity);

                if (shoppingCartItemInfo.CountDownPrice - SumBeforePrice > 0)
                {
                    int qty = shoppingCartItemInfo.CombinationItemInfos.LastOrDefault().Quantity;

                    decimal lastPrice = Math.Floor(((shoppingCartItemInfo.CountDownPrice - SumBeforePrice) / qty) * 100) / 100;

                    shoppingCartItemInfo.CombinationItemInfos.LastOrDefault().Price = lastPrice;
                }
            }

            return(shoppingCartItemInfo);
        }
Esempio n. 2
0
        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);
        }
Esempio n. 3
0
        private void btnSave_Click(object sender, System.EventArgs e)
        {
            if (this.categoryId == 0)
            {
                this.categoryId = (int)this.ViewState["ProductCategoryId"];
            }
            int     displaySequence;
            decimal salePrice;
            decimal?costPrice;
            decimal?marketPrice;
            int     stock;
            int     factstock;
            decimal?num3;
            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 num3, out referralDeduct, out subMemberDeduct, out subReferralDeduct, out deductFee, out buyCardinality, out grossweight))
            {
                return;
            }
            decimal adminFraction = 0m;

            if (string.IsNullOrWhiteSpace(txtAdminFraction.Text) || !decimal.TryParse(txtAdminFraction.Text, out adminFraction))
            {
                this.ShowMsg("请输入正确的提升权重值", false);
                return;
            }
            int ConversionRelation;

            if (!int.TryParse(this.txtConversionRelation.Text, out ConversionRelation))
            {
                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;
            }
            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;
                }
            }
            //判断是否存在广告关键字
            Dictionary <string, string> msg;

            if (!ValidateKeyWordHelper.ValidateKeyWord(new Dictionary <string, string>()
            {
                { "商品名称", this.txtProductName.Text }, { "商品简介", this.txtShortDescription.Text }
            }, out msg))
            {
                string showM = "";
                foreach (string k in msg.Keys)
                {
                    showM += k + "中不能包含广告词:" + msg[k] + ";";
                }
                this.ShowMsg(showM, false);
                return;
            }



            string text2 = this.fckDescription.Text;
            string text3 = this.fckmobbileDescription.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 = ProductHelper.GetProductDetails(this.productId);


            if (productInfo.ConversionRelation != ConversionRelation)
            {
                if (productInfo.Stock > 0)
                {
                    this.ShowMsg("销售库存大于0不允许修改换算系数", false);
                    return;
                }
            }
            //ProductInfo productInfo = new ProductInfo
            //{
            productInfo.ProductId          = this.productId;
            productInfo.CategoryId         = this.categoryId;
            productInfo.TypeId             = this.dropProductTypes.SelectedValue;
            productInfo.ProductName        = text;
            productInfo.ProductCode        = this.txtProductCode.Text;
            productInfo.AdminFraction      = adminFraction;
            productInfo.DisplaySequence    = displaySequence;
            productInfo.MarketPrice        = marketPrice;
            productInfo.Unit               = this.ddlUnit.SelectedItem.Text;
            productInfo.ImageUrl1          = this.uploader1.UploadedImageUrl;
            productInfo.ImageUrl2          = this.uploader2.UploadedImageUrl;
            productInfo.ImageUrl3          = this.uploader3.UploadedImageUrl;
            productInfo.ImageUrl4          = this.uploader4.UploadedImageUrl;
            productInfo.ImageUrl5          = this.uploader5.UploadedImageUrl;
            productInfo.ThumbnailUrl40     = this.uploader1.ThumbnailUrl40;
            productInfo.ThumbnailUrl60     = this.uploader1.ThumbnailUrl60;
            productInfo.ThumbnailUrl100    = this.uploader1.ThumbnailUrl100;
            productInfo.ThumbnailUrl160    = this.uploader1.ThumbnailUrl160;
            productInfo.ThumbnailUrl180    = this.uploader1.ThumbnailUrl180;
            productInfo.ThumbnailUrl220    = this.uploader1.ThumbnailUrl220;
            productInfo.ThumbnailUrl310    = this.uploader1.ThumbnailUrl310;
            productInfo.ThumbnailUrl410    = this.uploader1.ThumbnailUrl410;
            productInfo.ShortDescription   = this.txtShortDescription.Text;
            productInfo.IsfreeShipping     = this.ChkisfreeShipping.Checked;
            productInfo.IsCustomsClearance = this.ChkisCustomsClearance.Checked;

            productInfo.IsDisplayDiscount = this.ChkisDisplayDiscount.Checked;

            productInfo.IsPromotion = this.ChkisPromotion.Checked;

            productInfo.Description        = (!string.IsNullOrEmpty(text2) && text2.Length > 0) ? regex.Replace(text2, "") : null;
            productInfo.MobblieDescription = (!string.IsNullOrEmpty(text3) && text3.Length > 0) ? regex.Replace(text3, "") : null;
            productInfo.Title              = this.txtTitle.Text;
            productInfo.MetaDescription    = this.txtMetaDescription.Text;
            productInfo.MetaKeywords       = this.txtMetaKeywords.Text;
            productInfo.AddedDate          = System.DateTime.Now;
            productInfo.BrandId            = this.dropBrandCategories.SelectedValue;
            productInfo.ReferralDeduct     = referralDeduct;
            productInfo.SubMemberDeduct    = subMemberDeduct;
            productInfo.SubReferralDeduct  = subReferralDeduct;
            productInfo.TaxRateId          = this.dropTaxRate.SelectedValue;
            productInfo.TemplateId         = this.ddlShipping.SelectedValue;
            productInfo.SupplierId         = this.ddlSupplier.SelectedValue;
            productInfo.ImportSourceId     = this.ddlImportSourceType.SelectedValue;
            productInfo.BuyCardinality     = buyCardinality;
            productInfo.UnitCode           = this.ddlUnit.SelectedValue;
            productInfo.Manufacturer       = txtManufacturer.Text;
            productInfo.ItemNo             = txtItemNo.Text;
            productInfo.BarCode            = txtBarCode.Text;
            productInfo.Ingredient         = txtIngredient.Text;
            productInfo.ProductStandard    = txtProductStandard.Text;
            productInfo.ConversionRelation = ConversionRelation;
            productInfo.ProductTitle       = this.txtProductTitle.Text;//商品副标题
            productInfo.SaleType           = string.IsNullOrWhiteSpace(this.dropSaleType.SelectedValue) ? 1 : Convert.ToInt32(this.dropSaleType.SelectedValue);
            productInfo.EnglishName        = this.txtEnglishName.Text;
            productInfo.SysProductName     = this.txtsysProductName.Text;
            productInfo.Purchase           = int.Parse(this.Rd_Purchase.SelectedValue);
            productInfo.SectionDay         = int.Parse(this.txtSectionDay.Text);
            productInfo.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.SaleStatus != ProductSaleStatus.OnSale && ProductHelper.IsExitNoClassifyProduct(this.productId.ToString()))
                {
                    if (productInfo.SaleType != 2)
                    {
                        this.ShowMsg("商品还未完成归类操作,不能出售", false);
                        return;
                    }
                }
            }
            productInfo.SaleStatus = saleStatus;
            CategoryInfo category = CatalogHelper.GetCategory(this.categoryId);

            if (category != null)
            {
                productInfo.MainCategoryPath = category.Path + "|";
            }
            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);

                if (!string.IsNullOrEmpty(ArrhidProductRegistrationNumber.Value))
                {
                    Dictionary <string, string>[] dic = Newtonsoft.Json.JsonConvert.DeserializeObject <Dictionary <string, string>[]>(ArrhidProductRegistrationNumber.Value);

                    foreach (string item in dictionary.Keys)
                    {
                        foreach (Dictionary <string, string> d in dic)
                        {
                            if (d["SKU"] == dictionary[item].SKU)
                            {
                                dictionary[item].ProductRegistrationNumber = d["ProductRegistrationNumber"];
                                dictionary[item].LJNo = d["LJNo"];
                                int wmsstock;
                                int.TryParse(d["WMSStock"], out wmsstock);
                                dictionary[item].WMSStock = wmsstock;
                                //decimal dcgrossweight=0m;
                                //decimal.TryParse(d["GrossWeight"], out dcgrossweight);
                                //dictionary[item].GrossWeight = dcgrossweight;
                                //decimal dcweight = 0m;
                                //decimal.TryParse(d["Weight"], out dcweight);
                                //dictionary[item].Weight = dcweight;
                                break;
                            }
                        }
                    }
                }
            }
            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    = num3.HasValue ? num3.Value : 0m,
                            DeductFee = deductFee.HasValue ? deductFee.Value : 0m,
                            ProductRegistrationNumber = hidProductRegistrationNumber.Value,
                            LJNo        = hidLJNo.Value,
                            WMSStock    = productInfo.DefaultSku.WMSStock,
                            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);

            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.UpdateProduct(productInfo, dictionary, attrs, list, combinations);
            if (productActionStatus == ProductActionStatus.Success)
            {
                this.litralProductTag.SelectedValue = list;
                this.ShowMsg("修改商品成功", true);
                base.Response.Redirect(Globals.GetAdminAbsolutePath(string.Format("/product/AddProductComplete.aspx?categoryId={0}&productId={1}&IsEdit=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);
        }