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);
            }
        }
Beispiel #2
0
        private void SaveData()
        {
            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.txtKeywords.Text == "")
            {
                strErr += "关键词不能为空!\\n";
            }
            if (this.TextBox_Brief.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输入有误";
            }

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

            ProductModel product = bll.GetModel(ProductID);

            product.ProductName   = txtProductName.Text;
            product.ProductCode   = txtProductCode.Text;
            product.CateId        = Convert.ToInt32(txtCategoryID.Value);
            product.TradePrice    = Convert.ToDecimal(txtTradePrice.Text);
            product.MerchantPrice = Convert.ToDecimal(txtMerchantPrice.Text);
            product.ReducePrice   = Convert.ToDecimal(txtReducePrice.Text);
            product.Status        = Convert.ToInt32(drpStatus.SelectedValue);
            product.Keywords      = txtKeywords.Text;
            product.Brief         = TextBox_Brief.Text;
            product.BrandID       = Convert.ToInt32(DropDown_Brand.SelectedValue);

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

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

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

            product.ChangeTime = DateTime.Now;

            if (fulImage.FileName != String.Empty)
            {
                string[] MainImages;
                ProductMainImageRule.SaveProductMainImage(ProductID, product.CatePath, fulImage.PostedFile, out MainImages);
                product.SmallImage  = MainImages[0];
                product.MediumImage = MainImages[1];
                product.LargeImage  = MainImages[2];
            }

            //更新检索属性
            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.Save(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.Save(para);
                }
            }
            //添加商品多图
            foreach (string s in Request.Files.AllKeys)
            {
                if (s.StartsWith("multiImageUpload") && Request.Files[s].ContentLength > 0)
                {
                    string[] FileNames;
                    ProductMultiImageRule.SaveProductMultiImage(ProductID, product.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);
                    }
                }
            }

            //更新关联资讯ID
            new ProductNewsBll().Save(new ProductNewsModel()
            {
                ProdutID = product.ProductId, NewsID = TempNewsID
            });

            bll.Update(product);


            //重建索引
            try
            {
                DataIndexerProduct SearchIndexer = new DataIndexerProduct(Config.Searches["product"]);
                SearchIndexer.DeleteSingleIndex(product.ProductId);
                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 { }
        }