Пример #1
0
        private int AddProduct()
        {
            int rtnValue = 0;
            string strErr = "";
            if (this.txtProductName.Text == "")
            {
                strErr += "产品名称不能为空!\\n";
            }
            if (!PageValidate.IsDecimal(txtTradePrice.Text))
            {
                strErr += "市场价输入有误!\\n";
            }
            if (!PageValidate.IsDecimal(txtMerchantPrice.Text))
            {
                strErr += "销售价输入有误!\\n";
            }
            if (!PageValidate.IsDecimal(txtReducePrice.Text))
            {
                strErr += "直降价输入有误!\\n";
            }
            if (!PageValidate.IsNumber(txtScore.Text))
            {
                strErr += "商品积分输入有误!\\n";
            }
            if (!PageValidate.IsDecimal(txtWeight.Text))
            {
                strErr += "商品重量输入有误!\\n";
            }
            if (this.fulImage.FileName == "")
            {
                strErr += "产品图片不能为空!\\n";
            }
            if (this.txtKeywords.Text == "")
            {
                strErr += "关键词不能为空!\\n";
            }
            if (this.TextBox_Description.Text == "")
            {
                strErr += "商品简介不能为空!\\n";
            }
            if (!PageValidate.IsNumber(drpStatus.SelectedValue))
            {
                strErr += "商品状态选择有误!\\n";
            }
            int TempNewsID = 0;
            if (!String.IsNullOrEmpty(txtNewsID.Text) && !int.TryParse(txtNewsID.Text, out TempNewsID))
            {
                strErr += "关联资讯ID输入有误!\\n";
            }

            if (strErr != "")
            {
                MessageBox.Show(this, strErr);
                rtnValue = 1;
                return rtnValue;
            }

            if (bll.Exists(txtProductName.Text))
            {
                MessageBox.Show(this, "对不起,该商品名称已存在,无法添加同名商品");
                rtnValue = 1;
                return rtnValue;
            }
            CategoryModel cate = new CategoryModelBll().GetModel(Convert.ToInt32(txtCategoryID.Value));

            string[] MainImages;

            if (ProductMainImageRule.SaveProductMainImage(ProductID, cate.CatePath, fulImage.PostedFile, out MainImages))
            {
                ProductModel product = new ProductModel();

                product.ProductId = ProductID;
                product.ProductCode = String.IsNullOrEmpty(txtProductCode.Text) ? ProductID.ToString() : txtProductCode.Text;
                product.ProductName = txtProductName.Text;

                product.CateId = cate.CateId;
                product.CatePath = cate.CatePath;
                product.InsertTime = DateTime.Now;
                product.ChangeTime = DateTime.Now;
                product.Keywords = txtKeywords.Text;
                product.Brief = TextBox_Description.Text;
                product.BrandID = Convert.ToInt32(DropDown_Brand.SelectedValue);

                product.SmallImage = MainImages[0];
                product.MediumImage = MainImages[1];
                product.LargeImage = MainImages[2];

                product.MerchantPrice = Convert.ToDecimal(txtMerchantPrice.Text);
                product.ReducePrice = Convert.ToDecimal(txtReducePrice.Text);
                product.TradePrice = Convert.ToDecimal(txtTradePrice.Text);
                product.PageView = 0;
                product.Score = 0;
                //product.SortValue = "";
                product.Status = Convert.ToInt32(drpStatus.SelectedValue);
                product.Stock = int.MaxValue;

                product.Specifications = TextBox_Specification.Text;
                product.PackingList = TextBox_Packing.Text;
                product.AfterSaleService = TextBox_Service.Text;
                product.OfferSet = TextBox_OfferSet.Text;

                product.Weight = Convert.ToDecimal(txtWeight.Text);

                product.StockTip = GetStockTip();
                product.RelateProducts = txtRelateProduct.Text.Replace(",",",");

                new ProductNewsBll().Add(new ProductNewsModel() { ProdutID = ProductID, NewsID = TempNewsID });

                bll.Add(product);

                //添加产品检索属性
                foreach (GridViewRow row in GridView_Parameter.Rows)
                {
                    RadioButtonList ParameterValueList =((RadioButtonList)row.Cells[0].FindControl("RadioList_ParameterValue"));
                    if (!String.IsNullOrEmpty(ParameterValueList.SelectedValue))
                    {
                        int ParameterID = Convert.ToInt32(((HiddenField)row.Cells[0].FindControl("Hidden_ParameterID")).Value);
                        string ParameterValue = Convert.ToString(ParameterValueList.SelectedItem.Text);
                        ProductParaModel para = new ProductParaModel();

                        para.ParaId = ParameterID;
                        para.ProductId = product.ProductId;
                        para.ParaValue = ParameterValue;

                        pvBll.Add(para);
                    }
                }
                //添加产品基本属性
                foreach (GridViewRow row in GridView_Specification.Rows)
                {
                    RadioButtonList ParameterValueList = ((RadioButtonList)row.Cells[0].FindControl("RadioList_SpecificationValue"));
                    if (!String.IsNullOrEmpty(ParameterValueList.SelectedValue))
                    {
                        int ParameterID = Convert.ToInt32(((HiddenField)row.Cells[0].FindControl("Hidden_SpecificationID")).Value);
                        string ParameterValue = Convert.ToString(ParameterValueList.SelectedItem.Text);
                        ProductParaModel para = new ProductParaModel();

                        para.ParaId = ParameterID;
                        para.ProductId = product.ProductId;
                        para.ParaValue = ParameterValue;

                        pvBll.Add(para);
                    }
                }
                //添加商品多图
                foreach (string s in Request.Files.AllKeys)
                {
                    if (s.StartsWith("multiImageUpload") && Request.Files[s].ContentLength>0)
                    {
                        string[] FileNames;
                        ProductMultiImageRule.SaveProductMultiImage(ProductID,cate.CatePath, Request.Files[s], out FileNames);

                        if (FileNames != null)
                        {
                            ProductImageModel model = new ProductImageModel();
                            model.ImageId = CommDataHelper.GetNewSerialNum("pd");
                            model.ProductId = ProductID;
                            model.LargeImage = FileNames[1];
                            model.OriginImage = FileNames[2];
                            model.SmallImage = FileNames[0];
                            model.Title = String.Empty;

                            new ProductImageModelBll().Add(model);
                        }
                    }
                }

                //创建索引
                try
                {
                    DataIndexerProduct SearchIndexer = new DataIndexerProduct(Config.Searches["product"]);
                    SearchIndexer.CreateSingleIndex(new Search.Entities.ProductModel()
                    {
                        EntityIdentity = product.ProductId,
                        CategoryID = product.CateId,
                        CategoryPath = product.CatePath,
                        CreateTime = product.InsertTime,
                        Description = product.Brief,
                        Keywords = product.Keywords,
                        Price = product.MerchantPrice,
                        ProcessType = NoName.NetShop.Search.Entities.EntityProcessType.insert,
                        ProductImage = product.MediumImage,
                        ProductName = product.ProductName,
                        UpdateTime = product.ChangeTime
                    });
                }
                catch { }

                return rtnValue;
            }
            else
            {
                MessageBox.Show(this, "图片上传失败,请检查!");
                rtnValue = 1;
                return rtnValue;
            }
        }
Пример #2
0
        protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            if (e.CommandName.ToLower() == "d")
            {
                int ProductID = Convert.ToInt32(e.CommandArgument);
                bll.Delete(ProductID);
                MessageBox.Show(this, "删除成功");
                BindData(AspNetPager.CurrentPageIndex);

                DataIndexerProduct SearchIndexer = new DataIndexerProduct(Config.Searches["product"]);
                SearchIndexer.DeleteSingleIndex(ProductID);
            }
            if (e.CommandName.ToLower() == "s1")
            {
                int ProductID = Convert.ToInt32(e.CommandArgument);
                new SalesProductModelBll().SetSalesProduct(ProductID, SalesProductType.热销商品);
                BindData(AspNetPager.CurrentPageIndex);
            }
            if (e.CommandName.ToLower() == "d1")
            {
                int ProductID = Convert.ToInt32(e.CommandArgument);
                new SalesProductModelBll().DesetSalesProduct(ProductID, SalesProductType.热销商品);
                BindData(AspNetPager.CurrentPageIndex);
            }
            if (e.CommandName.ToLower() == "s2")
            {
                int ProductID = Convert.ToInt32(e.CommandArgument);
                new SalesProductModelBll().SetSalesProduct(ProductID, SalesProductType.直降特卖);
                BindData(AspNetPager.CurrentPageIndex);
            }
            if (e.CommandName.ToLower() == "d2")
            {
                int ProductID = Convert.ToInt32(e.CommandArgument);
                new SalesProductModelBll().DesetSalesProduct(ProductID, SalesProductType.直降特卖);
                BindData(AspNetPager.CurrentPageIndex);
            }
            if (e.CommandName.ToLower() == "s3")
            {
                int ProductID = Convert.ToInt32(e.CommandArgument);
                new SalesProductModelBll().SetSalesProduct(ProductID, SalesProductType.鼎鼎推荐);
                BindData(AspNetPager.CurrentPageIndex);
            }
            if (e.CommandName.ToLower() == "d3")
            {
                int ProductID = Convert.ToInt32(e.CommandArgument);
                new SalesProductModelBll().DesetSalesProduct(ProductID, SalesProductType.鼎鼎推荐);
                BindData(AspNetPager.CurrentPageIndex);
            }
        }