/// <summary> /// 编辑 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void btnSave_Click(object sender, EventArgs e) { //更新 //更新 string addrpic = Labelbgpic.Text; if (fppic.HasFile) { string name = this.fppic.PostedFile.FileName; int i = name.LastIndexOf('.'); string extname = name.Substring(i); string filename = DateTime.Now.ToString("yyyyMMddhhmmssfff"); string path = filename + extname; string savePath = Server.MapPath(@"..\..\uploads\" + filename + extname); fppic.PostedFile.SaveAs(savePath); addrpic = path; } string title = txt_title.Text; int tid = int.Parse(ddltid.SelectedValue); string bgpic = addrpic; string memo = Textarea1.Value; SP.Model.news model = new SP.Model.news(); model.title = title; model.tid = tid; model.bgpic = bgpic; model.memo = memo; model.nid = int.Parse(Request.QueryString["id"]); bll.Update(model); Page.ClientScript.RegisterStartupScript(this.GetType(), "alert", "<script>alert('操作成功,请返回!');location.href='List.aspx';</script>"); }
//初始化 private void ShowInfo() { if (Request.QueryString["id"] != null) { SP.BLL.news bll = new SP.BLL.news(); //根据编号得到相应的记录 DataSet ds = bll.GetList(" nid=" + Request.QueryString["id"]); SP.Model.news model = bll.GetModel(int.Parse(Request.QueryString["id"])); if (ds.Tables[0].Rows.Count > 0) { DataRow sdr = ds.Tables[0].Rows[0]; lblnid.Text = sdr["nid"].ToString(); lbltitle.Text = sdr["title"].ToString(); lbltid.Text = sdr["tname"].ToString(); imgbgpic.ImageUrl = "../../uploads/" + model.bgpic; lblmemo.Text = sdr["memo"].ToString(); lblatime.Text = sdr["atime"].ToString(); } } }
/// <summary> /// 更新一条数据 /// </summary> public bool Update(SP.Model.news model) { return(dal.Update(model)); }
/// <summary> /// 增加一条数据 /// </summary> public int Add(SP.Model.news model) { return(dal.Add(model)); }