/// <summary>
        /// 获得数据列表
        /// </summary>
        public List <ProductParaModel> GetModelList(string strWhere)
        {
            DataSet ds = dal.GetList(strWhere);
            List <ProductParaModel> modelList = new List <ProductParaModel>();
            int rowsCount = ds.Tables[0].Rows.Count;

            if (rowsCount > 0)
            {
                ProductParaModel model;
                for (int n = 0; n < rowsCount; n++)
                {
                    model = new ProductParaModel();
                    if (ds.Tables[0].Rows[n]["ProductId"].ToString() != "")
                    {
                        model.ProductId = int.Parse(ds.Tables[0].Rows[n]["ProductId"].ToString());
                    }
                    if (ds.Tables[0].Rows[n]["ParaId"].ToString() != "")
                    {
                        model.ParaId = int.Parse(ds.Tables[0].Rows[n]["ParaId"].ToString());
                    }
                    model.ParaValue = ds.Tables[0].Rows[n]["ParaValue"].ToString();
                    modelList.Add(model);
                }
            }
            return(modelList);
        }
 /// <summary>
 ///  ����һ������
 /// </summary>
 public void Add(ProductParaModel model)
 {
     DbCommand dbCommand = dbw.GetStoredProcCommand("UP_pdProductPara_ADD");
     dbw.AddInParameter(dbCommand, "ProductId", DbType.Int32, model.ProductId);
     dbw.AddInParameter(dbCommand, "ParaId", DbType.Int32, model.ParaId);
     dbw.AddInParameter(dbCommand, "ParaValue", DbType.AnsiString, model.ParaValue);
     dbw.ExecuteNonQuery(dbCommand);
 }
        /// <summary>
        ///  更新一条数据
        /// </summary>
        public void Update(ProductParaModel model)
        {
            DbCommand dbCommand = dbw.GetStoredProcCommand("UP_pdProductPara_Update");

            dbw.AddInParameter(dbCommand, "ProductId", DbType.Int32, model.ProductId);
            dbw.AddInParameter(dbCommand, "ParaId", DbType.Int32, model.ParaId);
            dbw.AddInParameter(dbCommand, "ParaValue", DbType.AnsiString, model.ParaValue);
            dbw.ExecuteNonQuery(dbCommand);
        }
 public void Save(ProductParaModel model)
 {
     if (!Exists(model.ProductId, model.ParaId))
     {
         Add(model);
     }
     else
     {
         Update(model);
     }
 }
        /// <summary>
        /// 对象实体绑定数据
        /// </summary>
        public ProductParaModel ReaderBind(IDataReader dataReader)
        {
            ProductParaModel model = new ProductParaModel();
            object           ojb;

            ojb = dataReader["ProductId"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.ProductId = (int)ojb;
            }
            ojb = dataReader["ParaId"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.ParaId = (int)ojb;
            }
            model.ParaValue = dataReader["ParaValue"].ToString();
            return(model);
        }
        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public ProductParaModel GetModel(int ProductId, int ParaId)
        {
            DbCommand dbCommand = dbr.GetStoredProcCommand("UP_pdProductPara_GetModel");

            dbr.AddInParameter(dbCommand, "ProductId", DbType.Int32, ProductId);
            dbr.AddInParameter(dbCommand, "ParaId", DbType.Int32, ParaId);

            ProductParaModel model = null;

            using (IDataReader dataReader = dbr.ExecuteReader(dbCommand))
            {
                if (dataReader.Read())
                {
                    model = ReaderBind(dataReader);
                }
            }
            return(model);
        }
예제 #7
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;
            }
        }
예제 #8
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 { }
        }
 /// <summary>
 /// ����ʵ�������
 /// </summary>
 public ProductParaModel ReaderBind(IDataReader dataReader)
 {
     ProductParaModel model=new ProductParaModel();
     object ojb;
     ojb = dataReader["ProductId"];
     if(ojb != null && ojb != DBNull.Value)
     {
         model.ProductId=(int)ojb;
     }
     ojb = dataReader["ParaId"];
     if(ojb != null && ojb != DBNull.Value)
     {
         model.ParaId=(int)ojb;
     }
     model.ParaValue=dataReader["ParaValue"].ToString();
     return model;
 }
 /// <summary>
 /// 更新一条数据
 /// </summary>
 public void Update(ProductParaModel model)
 {
     dal.Update(model);
 }
 /// <summary>
 /// 增加一条数据
 /// </summary>
 public void Add(ProductParaModel model)
 {
     dal.Add(model);
 }
 /// <summary>
 /// ����һ������
 /// </summary>
 public void Add(ProductParaModel model)
 {
     dal.Add(model);
 }
 /// <summary>
 /// ����һ������
 /// </summary>
 public void Update(ProductParaModel model)
 {
     dal.Update(model);
 }
 public void Save(ProductParaModel model)
 {
     if (!Exists(model.ProductId, model.ParaId))
     {
         Add(model);
     }
     else
     {
         Update(model);
     }
 }
 /// <summary>
 /// ��������б�
 /// </summary>
 public List<ProductParaModel> GetModelList(string strWhere)
 {
     DataSet ds = dal.GetList(strWhere);
     List<ProductParaModel> modelList = new List<ProductParaModel>();
     int rowsCount = ds.Tables[0].Rows.Count;
     if (rowsCount > 0)
     {
         ProductParaModel model;
         for (int n = 0; n < rowsCount; n++)
         {
             model = new ProductParaModel();
             if(ds.Tables[0].Rows[n]["ProductId"].ToString()!="")
             {
                 model.ProductId=int.Parse(ds.Tables[0].Rows[n]["ProductId"].ToString());
             }
             if(ds.Tables[0].Rows[n]["ParaId"].ToString()!="")
             {
                 model.ParaId=int.Parse(ds.Tables[0].Rows[n]["ParaId"].ToString());
             }
             model.ParaValue=ds.Tables[0].Rows[n]["ParaValue"].ToString();
             modelList.Add(model);
         }
     }
     return modelList;
 }