protected void btnsave_Click(object sender, EventArgs e) { if (Request["type"] == "Edit") { long Id = Convert.ToInt64(Request["ID"]); var item = db.Find(Id); if (item != null) { item.Title = txtbt.Text; item.ImgStr = hfimg.Value; item.ShortTxt = txtbz.Text; item.Content = txtnr.Text; item.CID = Convert.ToInt64(ddllm.SelectedValue); if (db.Edit(item)) { Page.ClientScript.RegisterStartupScript(GetType(), "e1", "edOK();", true); } else { Page.ClientScript.RegisterStartupScript(GetType(), "e2", "layer.alert('修改失败');", true); } } else { //找不到数据就返回列表 Response.Redirect("LinksListPG.aspx"); } } else { Models.Article item = new Models.Article(); item.Title = txtbt.Text; item.ImgStr = hfimg.Value; item.ProductTxt = ""; item.ShortTxt = txtbz.Text; item.Content = txtnr.Text; item.AddTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); item.Clicks = 1; item.CID = Convert.ToInt64(ddllm.SelectedValue); if (db.Add(item)) { Page.ClientScript.RegisterStartupScript(GetType(), "a1", "adOK()", true); } else { Page.ClientScript.RegisterStartupScript(GetType(), "a2", "layer.alert('添加失败');", true); } } }
public ReturnValue AddOrEdit(Article entity) { ReturnValue retValue = new ReturnValue(); if (string.IsNullOrEmpty(entity.Subject)) { retValue.IsExists = false; retValue.Message = "标题不能为空"; return retValue; } if (string.IsNullOrEmpty(entity.Body)) { retValue.IsExists = false; retValue.Message = "正文不能为空"; return retValue; } VwArticle old = null; using (ArticleDal dal = new ArticleDal()) { if (entity.ID > 0) { old = dal.GetVw(entity.ID); } if (old == null) { if (dal.Add(entity)) { retValue.IsExists = true; retValue.Message = "保存成功"; old = dal.GetVw(entity.ID); } else { retValue.IsExists = false; retValue.Message = "保存失败"; } } else //修改 { if (dal.Modify(entity)) { retValue.IsExists = true; retValue.Message = "修改成功"; old = dal.GetVw(entity.ID); } else { retValue.IsExists = false; retValue.Message = "修改失败"; } } } if (retValue.IsExists) { //TODO: 修改Html HtmlManager htmMg = new HtmlManager(); htmMg.CreateHtml(old); } retValue.PutValue("vw", old); return retValue; }