Ejemplo n.º 1
0
 public static SKUItem PopulateSKU(IDataReader reader)
 {
     if (reader == null)
     {
         return null;
     }
     SKUItem item = new SKUItem {
         SkuId = (string) reader["SkuId"],
         ProductId = (int) reader["ProductId"]
     };
     if (reader["SKU"] != DBNull.Value)
     {
         item.SKU = (string) reader["SKU"];
     }
     if (reader["Weight"] != DBNull.Value)
     {
         item.Weight = (decimal) reader["Weight"];
     }
     item.Stock = (int) reader["Stock"];
     if (reader["CostPrice"] != DBNull.Value)
     {
         item.CostPrice = (decimal) reader["CostPrice"];
     }
     item.SalePrice = (decimal) reader["SalePrice"];
     return item;
 }
Ejemplo n.º 2
0
 protected Dictionary<string, SKUItem> GetSkus(string skusXml)
 {
     XmlDocument document = new XmlDocument();
     Dictionary<string, SKUItem> dictionary = null;
     try
     {
         document.LoadXml(skusXml);
         XmlNodeList list = document.SelectNodes("//item");
         if ((list == null) || (list.Count == 0))
         {
             return null;
         }
         dictionary = new Dictionary<string, SKUItem>();
         foreach (XmlNode node in list)
         {
             SKUItem item2 = new SKUItem();
             item2.SKU = node.Attributes["skuCode"].Value;
             item2.SalePrice = decimal.Parse(node.Attributes["salePrice"].Value);
             item2.CostPrice = (node.Attributes["costPrice"].Value.Length > 0) ? decimal.Parse(node.Attributes["costPrice"].Value) : 0M;
             item2.PurchasePrice = decimal.Parse(node.Attributes["purchasePrice"].Value);
             item2.Stock = int.Parse(node.Attributes["qty"].Value);
             item2.AlertStock = int.Parse(node.Attributes["alertQty"].Value);
             item2.Weight = (node.Attributes["weight"].Value.Length > 0) ? int.Parse(node.Attributes["weight"].Value) : 0;
             SKUItem item = item2;
             string str = "";
             foreach (XmlNode node2 in node.SelectSingleNode("skuFields").ChildNodes)
             {
                 str = str + node2.Attributes["valueId"].Value + "_";
                 item.SkuItems.Add(int.Parse(node2.Attributes["attributeId"].Value), int.Parse(node2.Attributes["valueId"].Value));
             }
             XmlNode node3 = node.SelectSingleNode("memberPrices");
             if ((node3 != null) && (node3.ChildNodes.Count > 0))
             {
                 foreach (XmlNode node4 in node3.ChildNodes)
                 {
                     if (!(string.IsNullOrEmpty(node4.Attributes["price"].Value) || (node4.Attributes["price"].Value.Trim().Length == 0)))
                     {
                         item.MemberPrices.Add(int.Parse(node4.Attributes["id"].Value), decimal.Parse(node4.Attributes["price"].Value.Trim()));
                     }
                 }
             }
             XmlNode node5 = node.SelectSingleNode("distributorPrices");
             if ((node5 != null) && (node5.ChildNodes.Count > 0))
             {
                 foreach (XmlNode node6 in node5.ChildNodes)
                 {
                     if (!(string.IsNullOrEmpty(node6.Attributes["price"].Value) || (node6.Attributes["price"].Value.Trim().Length == 0)))
                     {
                         item.DistributorPrices.Add(int.Parse(node6.Attributes["id"].Value), decimal.Parse(node6.Attributes["price"].Value.Trim()));
                     }
                 }
             }
             item.SkuId = str.Substring(0, str.Length - 1);
             dictionary.Add(item.SkuId, item);
         }
         return dictionary;
     }
     catch
     {
         return null;
     }
 }
Ejemplo n.º 3
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            int num;
            int num2;
            decimal num3;
            decimal? nullable;
            decimal? nullable2;
            decimal? nullable3;
            if (this.categoryId == 0)
            {
                this.categoryId = (int)this.ViewState["ProductCategoryId"];
            }
            if (this.ValidateConverts(this.chkSkuEnabled.Checked, out num, out num3, out nullable, out nullable2, out num2, out nullable3))
            {
                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.fckDescription.Text;
                if (this.ckbIsDownPic.Checked)
                {
                    text = base.DownRemotePic(text);
                }
                ProductInfo target = new ProductInfo
                {
                    ProductId = this.productId,
                    CategoryId = this.categoryId,
                    TypeId = this.dropProductTypes.SelectedValue,
                    ProductName = this.txtProductName.Text,
                    ProductCode = this.txtProductCode.Text,
                    DisplaySequence = num,
                    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,
                    IsfreeShipping = this.ChkisfreeShipping.Checked,
                    Description = (!string.IsNullOrEmpty(text) && (text.Length > 0)) ? text : null,
                    AddedDate = DateTime.Now,
                    BrandId = this.dropBrandCategories.SelectedValue
                };
                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;
                CategoryInfo category = CatalogHelper.GetCategory(this.categoryId);
                if (category != null)
                {
                    target.MainCategoryPath = category.Path + "|";
                }
                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 = num3,
                        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);
                if (!validateResults.IsValid)
                {
                    this.ShowMsg(validateResults);
                }
                else
                {
                    IList<int> tagIds = 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)
                        {
                            tagIds.Add(Convert.ToInt32(str3));
                        }
                    }
                    switch (ProductHelper.UpdateProduct(target, skus, attrs, tagIds))
                    {
                        case ProductActionStatus.Success:
                            this.litralProductTag.SelectedValue = tagIds;
                            this.ShowMsg("修改商品成功", 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.OffShelfError:
                            this.ShowMsg("修改商品失败, 子站没在零售价范围内的商品无法下架", false);
                            return;

                        case ProductActionStatus.ProductTagEroor:
                            this.ShowMsg("修改商品失败,保存商品标签时出错", false);
                            return;
                    }
                    this.ShowMsg("修改商品失败,未知错误", false);
                }
            }
        }
Ejemplo n.º 4
0
        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);
                }
            }
        }
Ejemplo n.º 5
0
 protected void GetMemberPrices(SKUItem sku, string xml)
 {
     if (!string.IsNullOrEmpty(xml))
     {
         XmlDocument document = new XmlDocument();
         document.LoadXml(xml);
         foreach (XmlNode node in document.DocumentElement.SelectNodes("//grande"))
         {
             if (!(string.IsNullOrEmpty(node.Attributes["price"].Value) || (node.Attributes["price"].Value.Trim().Length == 0)))
             {
                 sku.MemberPrices.Add(int.Parse(node.Attributes["id"].Value), decimal.Parse(node.Attributes["price"].Value.Trim()));
             }
         }
     }
 }
Ejemplo n.º 6
0
 static Dictionary<string, SKUItem> ConverToSkus(int mappedProductId, DataSet productData, bool includeCostPrice, bool includeStock)
 {
     DataRow[] rowArray = productData.Tables["skus"].Select("ProductId=" + mappedProductId.ToString(CultureInfo.InvariantCulture));
     if (rowArray.Length == 0)
     {
         return null;
     }
     Dictionary<string, SKUItem> dictionary = new Dictionary<string, SKUItem>();
     foreach (DataRow row in rowArray)
     {
         string key = (string)row["NewSkuId"];
         SKUItem item2 = new SKUItem();
         item2.SkuId = key;
         item2.SKU = (string)row["SKU"];
         item2.SalePrice = (decimal)row["SalePrice"];
         item2.PurchasePrice = (decimal)row["PurchasePrice"];
         item2.AlertStock = (int)row["AlertStock"];
         SKUItem item = item2;
         if (row["Weight"] != DBNull.Value)
         {
             item.Weight = (int)row["Weight"];
         }
         if (includeCostPrice && (row["CostPrice"] != DBNull.Value))
         {
             item.CostPrice = (decimal)row["CostPrice"];
         }
         if (includeStock)
         {
             item.Stock = (int)row["Stock"];
         }
         DataRow[] rowArray2 = productData.Tables["skuItems"].Select("NewSkuId='" + key + "' AND MappedProductId=" + mappedProductId.ToString(CultureInfo.InvariantCulture));
         foreach (DataRow row2 in rowArray2)
         {
             item.SkuItems.Add((int)row2["SelectedAttributeId"], (int)row2["SelectedValueId"]);
         }
         dictionary.Add(key, item);
     }
     return dictionary;
 }
Ejemplo n.º 7
0
 public static void ImportProducts(DataTable productData, int categoryId, int lineId, int? brandId, ProductSaleStatus saleStatus)
 {
     if ((productData != null) && (productData.Rows.Count > 0))
     {
         foreach (DataRow row in productData.Rows)
         {
             string[] strArray;
             ProductInfo product = new ProductInfo();
             product.CategoryId = categoryId;
             product.MainCategoryPath = CatalogHelper.GetCategory(categoryId).Path + "|";
             product.ProductName = (string)row["ProductName"];
             product.ProductCode = (string)row["SKU"];
             product.LineId = lineId;
             product.BrandId = brandId;
             if (row["Description"] != DBNull.Value)
             {
                 product.Description = (string)row["Description"];
             }
             product.PenetrationStatus = PenetrationStatus.Notyet;
             product.AddedDate = DateTime.Now;
             product.SaleStatus = saleStatus;
             product.HasSKU = false;
             HttpContext current = HttpContext.Current;
             if (row["ImageUrl1"] != DBNull.Value)
             {
                 product.ImageUrl1 = (string)row["ImageUrl1"];
             }
             if (!(string.IsNullOrEmpty(product.ImageUrl1) || (product.ImageUrl1.Length <= 0)))
             {
                 strArray = ProcessImages(current, product.ImageUrl1);
                 product.ThumbnailUrl40 = strArray[0];
                 product.ThumbnailUrl60 = strArray[1];
                 product.ThumbnailUrl100 = strArray[2];
                 product.ThumbnailUrl160 = strArray[3];
                 product.ThumbnailUrl180 = strArray[4];
                 product.ThumbnailUrl220 = strArray[5];
                 product.ThumbnailUrl310 = strArray[6];
                 product.ThumbnailUrl410 = strArray[7];
             }
             if (row["ImageUrl2"] != DBNull.Value)
             {
                 product.ImageUrl2 = (string)row["ImageUrl2"];
             }
             if (!(string.IsNullOrEmpty(product.ImageUrl2) || (product.ImageUrl2.Length <= 0)))
             {
                 strArray = ProcessImages(current, product.ImageUrl2);
             }
             if (row["ImageUrl3"] != DBNull.Value)
             {
                 product.ImageUrl3 = (string)row["ImageUrl3"];
             }
             if (!(string.IsNullOrEmpty(product.ImageUrl3) || (product.ImageUrl3.Length <= 0)))
             {
                 strArray = ProcessImages(current, product.ImageUrl3);
             }
             if (row["ImageUrl4"] != DBNull.Value)
             {
                 product.ImageUrl4 = (string)row["ImageUrl4"];
             }
             if (!(string.IsNullOrEmpty(product.ImageUrl4) || (product.ImageUrl4.Length <= 0)))
             {
                 strArray = ProcessImages(current, product.ImageUrl4);
             }
             if (row["ImageUrl5"] != DBNull.Value)
             {
                 product.ImageUrl5 = (string)row["ImageUrl5"];
             }
             if (!(string.IsNullOrEmpty(product.ImageUrl5) || (product.ImageUrl5.Length <= 0)))
             {
                 strArray = ProcessImages(current, product.ImageUrl5);
             }
             SKUItem item = new SKUItem();
             item.SkuId = "_0";
             item.SKU = (string)row["SKU"];
             product.LowestSalePrice = item.PurchasePrice = item.SalePrice = (decimal)row["SalePrice"];
             if (row["Stock"] != DBNull.Value)
             {
                 item.Stock = (int)row["Stock"];
             }
             if (row["Weight"] != DBNull.Value)
             {
                 item.Weight = (int)row["Weight"];
             }
             Dictionary<string, SKUItem> skus = new Dictionary<string, SKUItem>();
             skus.Add(item.SkuId, item);
             AddProduct(product, skus, null);
         }
     }
 }
Ejemplo n.º 8
0
 public override ProductInfo GetProductDetails(int productId, out Dictionary<int, IList<int>> attrs, out IList<int> distributorUserIds)
 {
     ProductInfo info = null;
     attrs = null;
     distributorUserIds = new List<int>();
     DbCommand sqlStringCommand = database.GetSqlStringCommand("SELECT * FROM Hishop_Products WHERE ProductId = @ProductId;SELECT skus.SkuId, s.AttributeId, s.ValueId, skus.SKU, skus.SalePrice, skus.CostPrice, skus.PurchasePrice, skus.Stock, skus.AlertStock, skus.[Weight] FROM Hishop_SKUItems s right outer join Hishop_SKUs skus on s.SkuId = skus.SkuId WHERE skus.ProductId = @ProductId ORDER BY (SELECT DisplaySequence FROM Hishop_Attributes WHERE AttributeId = s.AttributeId) DESC;SELECT s.SkuId, smp.GradeId, smp.MemberSalePrice FROM Hishop_SKUMemberPrice smp INNER JOIN Hishop_SKUs s ON smp.SkuId=s.SkuId WHERE s.ProductId=@ProductId;SELECT s.SkuId, sdp.GradeId, sdp.DistributorPurchasePrice FROM Hishop_SKUDistributorPrice sdp INNER JOIN Hishop_SKUs s ON sdp.SkuId=s.SkuId WHERE s.ProductId=@ProductId;SELECT AttributeId, ValueId FROM Hishop_ProductAttributes WHERE ProductId = @ProductId; SELECT UserId FROM Hishop_DistributorProductLines WHERE LineId = (SELECT LineId FROM Hishop_Products WHERE ProductId = @ProductId)");
     database.AddInParameter(sqlStringCommand, "ProductId", DbType.Int32, productId);
     using (IDataReader reader = database.ExecuteReader(sqlStringCommand))
     {
         string str;
         if (reader.Read())
         {
             info = DataMapper.PopulateProduct(reader);
         }
         if (info == null)
         {
             return info;
         }
         reader.NextResult();
         while (reader.Read())
         {
             str = (string)reader["SkuId"];
             if (!info.Skus.ContainsKey(str))
             {
                 SKUItem item2 = new SKUItem();
                 item2.SkuId = str;
                 item2.ProductId = productId;
                 SKUItem item = item2;
                 if (reader["SKU"] != null)
                 {
                     item.SKU = (string)reader["SKU"];
                 }
                 if (reader["Weight"] != DBNull.Value)
                 {
                     item.Weight = (int)reader["Weight"];
                 }
                 item.Stock = (int)reader["Stock"];
                 item.AlertStock = (int)reader["AlertStock"];
                 if (reader["CostPrice"] != DBNull.Value)
                 {
                     item.CostPrice = (decimal)reader["CostPrice"];
                 }
                 item.SalePrice = (decimal)reader["SalePrice"];
                 item.PurchasePrice = (decimal)reader["PurchasePrice"];
                 info.Skus.Add(str, item);
             }
             if ((reader["AttributeId"] != DBNull.Value) && (reader["ValueId"] != DBNull.Value))
             {
                 info.Skus[str].SkuItems.Add((int)reader["AttributeId"], (int)reader["ValueId"]);
             }
         }
         reader.NextResult();
         while (reader.Read())
         {
             str = (string)reader["SkuId"];
             info.Skus[str].MemberPrices.Add((int)reader["GradeId"], (decimal)reader["MemberSalePrice"]);
         }
         reader.NextResult();
         while (reader.Read())
         {
             str = (string)reader["SkuId"];
             info.Skus[str].DistributorPrices.Add((int)reader["GradeId"], (decimal)reader["DistributorPurchasePrice"]);
         }
         reader.NextResult();
         attrs = new Dictionary<int, IList<int>>();
         while (reader.Read())
         {
             int key = (int)reader["AttributeId"];
             int num2 = (int)reader["ValueId"];
             if (!attrs.ContainsKey(key))
             {
                 IList<int> list = new List<int>();
                 list.Add(num2);
                 attrs.Add(key, list);
             }
             else
             {
                 attrs[key].Add(num2);
             }
         }
         reader.NextResult();
         while (reader.Read())
         {
             distributorUserIds.Add((int)reader["UserId"]);
         }
     }
     return info;
 }
Ejemplo n.º 9
0
        /// <summary>
        /// 保存按钮事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnSave_Click(object sender, EventArgs e)
        {
            int displaySequence = 0;
            int stock = 0;// num2;
            int alertStock = 0;// num3;
            decimal purchasePrice = 0m;
            decimal lowestSalePrice = 0m;// num5;
            decimal salePrice = 0m;// num6;
            decimal? costPrice = null;// nullable;
            decimal? marketPrice = null;// nullable2;
            int? weight = null;// nullable3;

            if (categoryId == 0)
            {
                categoryId = (int)ViewState["ProductCategoryId"];
            }

               // (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 displaySequence, out purchasePrice, out lowestSalePrice, out salePrice, out costPrice, out marketPrice, out stock, out alertStock, out weight))
            {
                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 = fckDescription.Text;
                if (ckbIsDownPic.Checked)
                {
                    text = base.DownRemotePic(text);
                }
                ProductInfo productInfo = new ProductInfo();
                productInfo.ProductId = productId;
                productInfo.CategoryId = categoryId;
                productInfo.TypeId = dropProductTypes.SelectedValue;
                productInfo.ProductName = txtProductName.Text;
                productInfo.ProductCode = txtProductCode.Text;
                productInfo.DisplaySequence = displaySequence;
                productInfo.LineId = dropProductLines.SelectedValue.Value;
                productInfo.LowestSalePrice = lowestSalePrice;
                productInfo.MarketPrice = marketPrice;// nullable2;
                productInfo.Unit = txtUnit.Text;
                productInfo.ImageUrl1 = uploader1.UploadedImageUrl;
                productInfo.ImageUrl2 = uploader2.UploadedImageUrl;
                productInfo.ImageUrl3 = uploader3.UploadedImageUrl;
                productInfo.ImageUrl4 = uploader4.UploadedImageUrl;
                productInfo.ImageUrl5 = uploader5.UploadedImageUrl;
                productInfo.ThumbnailUrl40 = uploader1.ThumbnailUrl40;
                productInfo.ThumbnailUrl60 = uploader1.ThumbnailUrl60;
                productInfo.ThumbnailUrl100 = uploader1.ThumbnailUrl100;
                productInfo.ThumbnailUrl160 = uploader1.ThumbnailUrl160;
                productInfo.ThumbnailUrl180 = uploader1.ThumbnailUrl180;
                productInfo.ThumbnailUrl220 = uploader1.ThumbnailUrl220;
                productInfo.ThumbnailUrl310 = uploader1.ThumbnailUrl310;
                productInfo.ThumbnailUrl410 = uploader1.ThumbnailUrl410;
                productInfo.ShortDescription = txtShortDescription.Text;
                productInfo.Description = (!string.IsNullOrEmpty(text) && (text.Length > 0)) ? text : null;
                productInfo.PenetrationStatus = chkPenetration.Checked ? PenetrationStatus.Already : PenetrationStatus.Notyet;
                productInfo.Title = txtTitle.Text;
                productInfo.MetaDescription = txtMetaDescription.Text;
                productInfo.MetaKeywords = txtMetaKeywords.Text;
                productInfo.AddedDate = DateTime.Now;
                productInfo.BrandId = dropBrandCategories.SelectedValue;
                //ProductInfo info = productInfo;
                //ProductInfo target = info;
                productInfo.BrandId = dropBrandCategories.SelectedValue;
                ProductSaleStatus onSale = ProductSaleStatus.OnSale;
                if (radInStock.Checked)
                {
                    onSale = ProductSaleStatus.OnStock;
                }
                if (radUnSales.Checked)
                {
                    onSale = ProductSaleStatus.UnSale;
                }
                if (radOnSales.Checked)
                {
                    onSale = ProductSaleStatus.OnSale;
                }
                productInfo.SaleStatus = onSale;
                CategoryInfo category = CatalogHelper.GetCategory(categoryId);
                if (category != null)
                {
                    productInfo.MainCategoryPath = category.Path + "|";
                }
                Dictionary<string, SKUItem> skus = new Dictionary<string,SKUItem>();
                Dictionary<int, IList<int>> attrs = null;
                if (chkSkuEnabled.Checked)
                {
                    productInfo.HasSKU = true;
                    skus = base.GetSkus(txtSkus.Text);
                }
                else
                {
                    //Dictionary<string, SKUItem> skuList = new Dictionary<string, SKUItem>();

                    SKUItem item = new SKUItem();
                    item.SkuId = "0";
                    item.SKU = txtSku.Text;
                    item.SalePrice = salePrice;
                    item.CostPrice = costPrice.HasValue ? costPrice.Value : 0M;
                    item.PurchasePrice = purchasePrice;// num4;
                    item.Stock = stock;// num2;
                    item.AlertStock = alertStock;// num3;
                    item.Weight = weight.HasValue ? weight.Value : 0;

                    //skuList.Add("0", item);
                    skus.Add("0", item);
                    //skus = dictionary3;

                    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>(productInfo);
                if (!validateResults.IsValid)
                {
                    ShowMsg(validateResults);
                }
                else
                {
                    if (ViewState["distributorUserIds"] == null)
                    {
                        ViewState["distributorUserIds"] = new List<int>();
                    }
                    int type = 0;
                    if (((productInfo.LineId > 0) && (int.Parse(hdlineId.Value) > 0)) && (productInfo.LineId != int.Parse(hdlineId.Value)))
                    {
                        type = 6;
                    }
                    if (!chkPenetration.Checked)
                    {
                        type = 5;
                    }
                    if (type == 5)
                    {
                        AdminPage.SendMessageToDistributors(productInfo.ProductId.ToString(), type);
                    }
                    else if (type == 6)
                    {
                        toline = dropProductLines.SelectedItem.Text;
                        AdminPage.SendMessageToDistributors(hdlineId.Value + "|" + toline, type);
                    }
                    switch (ProductHelper.UpdateProduct(productInfo, skus, attrs, (IList<int>)ViewState["distributorUserIds"]))
                    {
                        case ProductActionStatus.Success:
                            ShowMsg("修改商品成功", true);
                            base.Response.Redirect(Globals.GetAdminAbsolutePath(string.Format("/product/EditProductComplete.aspx?productId={0}", productInfo.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;

                        case ProductActionStatus.OffShelfError:
                            ShowMsg("修改商品失败, 子站没在零售价范围内的商品无法下架", false);
                            return;
                    }
                    ShowMsg("修改商品失败,未知错误", false);
                }
            }
        }
Ejemplo n.º 10
0
 public static void ImportProducts(DataTable productData, int categoryId, int lineId, int? brandId, ProductSaleStatus saleStatus, bool isImportFromTaobao)
 {
     if ((productData != null) && (productData.Rows.Count > 0))
     {
         foreach (DataRow row in productData.Rows)
         {
             string[] strArray;
             ProductInfo product = new ProductInfo {
                 CategoryId = categoryId,
                 MainCategoryPath = CatalogHelper.GetCategory(categoryId).Path + "|",
                 ProductName = (string) row["ProductName"],
                 ProductCode = (string) row["SKU"],
                 BrandId = brandId
             };
             if (row["Description"] != DBNull.Value)
             {
                 product.Description = (string) row["Description"];
             }
             product.AddedDate = DateTime.Now;
             product.SaleStatus = saleStatus;
             product.HasSKU = false;
             HttpContext current = HttpContext.Current;
             if (row["ImageUrl1"] != DBNull.Value)
             {
                 product.ImageUrl1 = (string) row["ImageUrl1"];
             }
             if (!(string.IsNullOrEmpty(product.ImageUrl1) || (product.ImageUrl1.Length <= 0)))
             {
                 strArray = ProcessImages(current, product.ImageUrl1);
                 product.ThumbnailUrl40 = strArray[0];
                 product.ThumbnailUrl60 = strArray[1];
                 product.ThumbnailUrl100 = strArray[2];
                 product.ThumbnailUrl160 = strArray[3];
                 product.ThumbnailUrl180 = strArray[4];
                 product.ThumbnailUrl220 = strArray[5];
                 product.ThumbnailUrl310 = strArray[6];
                 product.ThumbnailUrl410 = strArray[7];
             }
             if (row["ImageUrl2"] != DBNull.Value)
             {
                 product.ImageUrl2 = (string) row["ImageUrl2"];
             }
             if (!(string.IsNullOrEmpty(product.ImageUrl2) || (product.ImageUrl2.Length <= 0)))
             {
                 strArray = ProcessImages(current, product.ImageUrl2);
             }
             if (row["ImageUrl3"] != DBNull.Value)
             {
                 product.ImageUrl3 = (string) row["ImageUrl3"];
             }
             if (!(string.IsNullOrEmpty(product.ImageUrl3) || (product.ImageUrl3.Length <= 0)))
             {
                 strArray = ProcessImages(current, product.ImageUrl3);
             }
             if (row["ImageUrl4"] != DBNull.Value)
             {
                 product.ImageUrl4 = (string) row["ImageUrl4"];
             }
             if (!(string.IsNullOrEmpty(product.ImageUrl4) || (product.ImageUrl4.Length <= 0)))
             {
                 strArray = ProcessImages(current, product.ImageUrl4);
             }
             if (row["ImageUrl5"] != DBNull.Value)
             {
                 product.ImageUrl5 = (string) row["ImageUrl5"];
             }
             if (!(string.IsNullOrEmpty(product.ImageUrl5) || (product.ImageUrl5.Length <= 0)))
             {
                 strArray = ProcessImages(current, product.ImageUrl5);
             }
             SKUItem item = new SKUItem {
                 SkuId = "0",
                 SKU = (string) row["SKU"]
             };
             if (row["Stock"] != DBNull.Value)
             {
                 item.Stock = (int) row["Stock"];
             }
             if (row["Weight"] != DBNull.Value)
             {
                 item.Weight = (decimal) row["Weight"];
             }
             item.SalePrice = (decimal) row["SalePrice"];
             Dictionary<string, SKUItem> skus = new Dictionary<string, SKUItem>();
             skus.Add(item.SkuId, item);
             ProductActionStatus status = AddProduct(product, skus, null, null);
             if (isImportFromTaobao && (status == ProductActionStatus.Success))
             {
                 TaobaoProductInfo taobaoProduct = new TaobaoProductInfo {
                     ProductId = product.ProductId,
                     ProTitle = product.ProductName,
                     Cid = (long) row["Cid"]
                 };
                 if (row["StuffStatus"] != DBNull.Value)
                 {
                     taobaoProduct.StuffStatus = (string) row["StuffStatus"];
                 }
                 taobaoProduct.Num = (long) row["Num"];
                 taobaoProduct.LocationState = (string) row["LocationState"];
                 taobaoProduct.LocationCity = (string) row["LocationCity"];
                 taobaoProduct.FreightPayer = (string) row["FreightPayer"];
                 if (row["PostFee"] != DBNull.Value)
                 {
                     taobaoProduct.PostFee = (decimal) row["PostFee"];
                 }
                 if (row["ExpressFee"] != DBNull.Value)
                 {
                     taobaoProduct.ExpressFee = (decimal) row["ExpressFee"];
                 }
                 if (row["EMSFee"] != DBNull.Value)
                 {
                     taobaoProduct.EMSFee = (decimal) row["EMSFee"];
                 }
                 taobaoProduct.HasInvoice = (bool) row["HasInvoice"];
                 taobaoProduct.HasWarranty = (bool) row["HasWarranty"];
                 taobaoProduct.HasDiscount = (bool) row["HasDiscount"];
                 taobaoProduct.ValidThru = (long) row["ValidThru"];
                 if (row["ListTime"] != DBNull.Value)
                 {
                     taobaoProduct.ListTime = (DateTime) row["ListTime"];
                 }
                 else
                 {
                     taobaoProduct.ListTime = DateTime.Now;
                 }
                 if (row["PropertyAlias"] != DBNull.Value)
                 {
                     taobaoProduct.PropertyAlias = (string) row["PropertyAlias"];
                 }
                 if (row["InputPids"] != DBNull.Value)
                 {
                     taobaoProduct.InputPids = (string) row["InputPids"];
                 }
                 if (row["InputStr"] != DBNull.Value)
                 {
                     taobaoProduct.InputStr = (string) row["InputStr"];
                 }
                 if (row["SkuProperties"] != DBNull.Value)
                 {
                     taobaoProduct.SkuProperties = (string) row["SkuProperties"];
                 }
                 if (row["SkuQuantities"] != DBNull.Value)
                 {
                     taobaoProduct.SkuQuantities = (string) row["SkuQuantities"];
                 }
                 if (row["SkuPrices"] != DBNull.Value)
                 {
                     taobaoProduct.SkuPrices = (string) row["SkuPrices"];
                 }
                 if (row["SkuOuterIds"] != DBNull.Value)
                 {
                     taobaoProduct.SkuOuterIds = (string) row["SkuOuterIds"];
                 }
                 UpdateToaobProduct(taobaoProduct);
             }
         }
     }
 }