protected void BT_AddGoods_Click(object sender, EventArgs e) { GoodsService mygoodsservice = new GoodsService(); if (FU_Pic.HasFile) { bool fileOk = false; if (C_BeginTime.SelectedDate > C_EndTime.SelectedDate) { Response.Write("<script>alert('开始日期不能大于结束日期!!')</script>"); } else { string fileExtension = System.IO.Path.GetExtension(FU_Pic.FileName).ToLower(); //限定只能上传jpg和gif图片 string[] allowExtension = { ".jpg", ".gif", ".bmp", ".png", ".jpeg" }; //对上传的文件的类型进行一个个匹对 for (int i = 0; i < allowExtension.Length; i++) { if (fileExtension == allowExtension[i]) { fileOk = true; break; } } if (fileOk) { Guid aid = Guid.NewGuid(); string filePath = "../../../images/Groupon/Upload/" + aid.ToString() + fileExtension; FU_Pic.SaveAs(MapPath(filePath));//把文件上传到服务器的绝对路径上 GoodsDspModel model = new GoodsDspModel() { GoodsID = new Guid(Label1.Text.ToString().Trim()), GoodsBeginTime = C_BeginTime.SelectedDate, GoodsBuyCount = 0, GoodsDetailsContent = editor1.InnerText, GoodsEndTime = C_EndTime.SelectedDate, GoodsIsOn = false, GoodsName = TB_GoodsName.Text.ToString().Trim(), GoodsNowPrice = float.Parse(TB_NowPrice.Text.ToString().Trim()), GoodsOldPrice = float.Parse(TB_OldPrice.Text.ToString().Trim()), GoodsPicURL = filePath }; mygoodsservice.UpdateGoods(model); Response.Write("<script>alert('修改成功')</script>"); } else { Response.Write("<script>alert('文件格式错误!')</script>"); } } } else { Response.Write("<script>alert('请您选择上传的文件!!')</script>"); } }
/// <summary> /// 创建商品 /// </summary> /// <param name="model">新建广告模型</param> public void CreateGoods(GoodsDspModel model) { IRepository <Goods> rep = Factory.Factory <IRepository <Goods> > .GetConcrete <Goods>(); try { //string goodsname,float goodsnowprice,string goodspicurl,float goodsoldprice,int goodsbuycount,DateTime goodsbegintime,DateTime goodsendtime,string goodsdetailscontent,bool goodsison rep.Add(new Goods(model.GoodsID, model.GoodsName, model.GoodsNowPrice, model.GoodsPicURL, model.GoodsOldPrice, model.GoodsBuyCount, model.GoodsBeginTime, model.GoodsEndTime, model.GoodsDetailsContent, model.GoodsIsOn)); rep.PersistAll(); } catch { } }
/// <summary> /// 修改商品 /// </summary> /// <param name="model">修改商品</param> public void UpdateGoods(GoodsDspModel model) { IRepository <Goods> rep = Factory.Factory <IRepository <Goods> > .GetConcrete <Goods>(); Goods a = null; try { a = rep.GetByKey(model.GoodsID); a.GoodsBeginTime = model.GoodsBeginTime; a.GoodsBuyCount = model.GoodsBuyCount; a.GoodsDetailsContent = model.GoodsDetailsContent; a.GoodsEndTime = model.GoodsEndTime; a.GoodsIsOn = model.GoodsIsOn; a.GoodsName = model.GoodsName; a.GoodsNowPrice = model.GoodsNowPrice; a.GoodsOldPrice = model.GoodsOldPrice; a.GoodsPicURL = model.GoodsPicURL; rep.Update(a); rep.PersistAll(); } catch { } }