Example #1
0
        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public ShowShop.Model.Product.ProductInfo GetModel(int productID)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select top 1 ProductID,ProductNo,cid,BrandID,ProductName,ProductAttachName,ShopPrice,MarketPrice,Synopsis,ProductContent,Unit,CreateTime,UpdateTime,AutoUp,AutoDown,Thumbnail from Product ");
            strSql.Append(" where ProductID=@ProductID ");
            SqlParameter[] parameters = {
                    new SqlParameter("@ProductID", SqlDbType.Int,4)};
            parameters[0].Value = productID;

            ShowShop.Model.Product.ProductInfo model = new ShowShop.Model.Product.ProductInfo();
            DataSet ds = ChangeHope.DataBase.SQLServerHelper.Query(strSql.ToString(), parameters);
            if (ds.Tables[0].Rows.Count > 0)
            {
                if (ds.Tables[0].Rows[0]["ProductID"].ToString() != "")
                {
                    model.ProductID = int.Parse(ds.Tables[0].Rows[0]["ProductID"].ToString());
                }
                model.ProductNo = ds.Tables[0].Rows[0]["ProductNo"].ToString();
                model.ProductName = ds.Tables[0].Rows[0]["ProductName"].ToString();
                model.ProductAttachName = ds.Tables[0].Rows[0]["ProductAttachName"].ToString();
                model.ClassID = int.Parse(ds.Tables[0].Rows[0]["cid"].ToString());
                if (ds.Tables[0].Rows[0]["BrandID"].ToString() != "")
                {
                    model.BrandID = int.Parse(ds.Tables[0].Rows[0]["BrandID"].ToString());
                }
                if (ds.Tables[0].Rows[0]["ShopPrice"].ToString() != "")
                {
                    model.ShopPrice = decimal.Parse(ds.Tables[0].Rows[0]["ShopPrice"].ToString());
                }
                if (ds.Tables[0].Rows[0]["MarketPrice"].ToString() != "")
                {
                    model.MarketPrice = decimal.Parse(ds.Tables[0].Rows[0]["MarketPrice"].ToString());
                }
                model.Thumbnail = ds.Tables[0].Rows[0]["Thumbnail"].ToString();
                model.Synopsis = ds.Tables[0].Rows[0]["Synopsis"].ToString();
                model.ProductContent = ds.Tables[0].Rows[0]["ProductContent"].ToString();

                if (ds.Tables[0].Rows[0]["Unit"].ToString() != "")
                {
                    model.Unit = ds.Tables[0].Rows[0]["Unit"].ToString();
                }

                if (ds.Tables[0].Rows[0]["UpdateTime"].ToString() != "")
                {
                    model.UpdateTime = DateTime.Parse(ds.Tables[0].Rows[0]["UpdateTime"].ToString());
                }
                if (ds.Tables[0].Rows[0]["AutoUp"].ToString() != "")
                {
                    model.AutoUp = DateTime.Parse(ds.Tables[0].Rows[0]["AutoUp"].ToString());
                }
                if (ds.Tables[0].Rows[0]["AutoDown"].ToString() != "")
                {
                    model.AutoDown = DateTime.Parse(ds.Tables[0].Rows[0]["AutoDown"].ToString());
                }

                return model;
            }
            else
            {
                return null;
            }
        }
        protected void butSave_Click(object sender, EventArgs e)
        {
            ShowShop.BLL.Product.ProductInfo bll = new ShowShop.BLL.Product.ProductInfo();
            ShowShop.Model.Product.ProductInfo model = new ShowShop.Model.Product.ProductInfo();
            #region 数据准备
            model.ProductNo = lb_ProductNo.Text.Trim();//商品编号
            model.ProductName = this.txtProductName.Text;//商品名称
            model.ProductAttachName = txtProductAttachName.Text.Trim();//附加名称
            model.ClassID = this.hfcid.Value != "" ? int.Parse(this.hfcid.Value) : 0;//商品类别Id
            model.BrandID = Convert.ToInt32(ChangeHope.WebPage.PageRequest.GetFormString("selBrand"));//品牌
            model.Unit = ChangeHope.WebPage.PageRequest.GetFormString("selUnit") == "0" ? "" : ChangeHope.WebPage.PageRequest.GetFormString("selUnit");//商品单位
            model.MarketPrice = this.txtMarketPrice.Text.Trim() != "" ? Convert.ToDecimal(this.txtMarketPrice.Text.Trim()) : 0;//市场价格
            model.ShopPrice = this.txtCostPrice.Text.Trim() != "" ? Convert.ToDecimal(this.txtCostPrice.Text.Trim()) : 0;//商城价格
            model.Synopsis = this.txtDescription.Text;//商品简介
            model.ProductContent = this.txtContent.Value;//商品明细
            model.AutoUp = this.txtFilingTime.Text.Trim() != "" ? Convert.ToDateTime(this.txtFilingTime.Text.Trim()) : System.DateTime.Now;//上架时间
            model.AutoDown = this.txtDownTime.Text.Trim() != "" ? Convert.ToDateTime(this.txtDownTime.Text.Trim()) : Convert.ToDateTime("2020-01-01");//下架时间
            model.UpdateTime = System.DateTime.Now;//更新时间
            model.IsAuto = Convert.ToInt32(rblIsShelves.SelectedValue);//是否上架

            #endregion
            #region 图片
            string thumbnailPath = System.Configuration.ConfigurationManager.AppSettings["ImgThumbnailPath"].ToString();
            string SavePath = "/imageFile/product/thumbnail";
            string thumbnail = string.Empty;
            if (fuPic.HasFile)
            {
                //原图
                ChangeHope.Common.UploadFile uf = new ChangeHope.Common.UploadFile();
                uf.ExtensionLim = ".gif,.jpg,.jpeg,.bmp";
                uf.FileLengthLim = 1024;
                uf.PostedFile = this.fuPic;
                uf.SavePath = SavePath;
                if (uf.Upload())
                {
                    thumbnail = uf.FilePath;
                }
                else
                {
                    this.ltlMsg.Text = "操作失败," + uf.Message + "";
                    this.pnlMsg.Visible = true;
                    this.pnlMsg.CssClass = "actionOk";
                    return;
                }
            }
            model.Thumbnail = thumbnail;//缩略图地址
            #endregion
            if (ViewState["ID"] != null)
            {
                ShowShop.Common.PromptInfo.Popedom("001008004", "对不起,您没有编辑权限");
                model.ProductID = Convert.ToInt32(ViewState["ID"].ToString());
                //相册
                string AlbumInfo = Album(100, 100, true, Convert.ToInt32(ViewState["ID"].ToString()));
                string reStr = string.Empty;
                ChangeHope.WebPage.BasePage.PageRight("操作成功,您的已修改该商品信息。", "product_list.aspx?q_PutoutType=", "<li>" + reStr + "</li>");
            }
            else
            {
                ShowShop.Common.PromptInfo.Popedom("001008002", "对不起,您没有新增权限");
                //相册

                int productId = bll.Add(model);
                string AlbumInfo = Album(100, 100, false, productId);
                string reStr = string.Empty;
                if (productId > 0)
                {
                    ChangeHope.WebPage.BasePage.PageRight("操作成功,您的添加的商品信息已保存。", "product_info_edit.aspx?putoutType=", "<li>" + reStr + "</li>");
                }
                else
                {
                    ChangeHope.WebPage.BasePage.PageError("操作失败,您的添加的商品信息保存失败。", "product_info_edit.aspx?putoutType=", "<li>" + reStr + "</li>");
                }
            }
        }