/// <summary> /// 增加一条数据 /// </summary> public bool Add(entity_News model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into News("); strSql.Append("sid,title,Content,CreateTime,type,CreatePeople)"); strSql.Append(" values ("); strSql.Append("@sid,@title,@Content,@CreateTime,@type,@CreatePeople)"); SqlParameter[] parameters = { new SqlParameter("@sid", SqlDbType.NVarChar, 50), new SqlParameter("@title", SqlDbType.NVarChar, 500), new SqlParameter("@Content", SqlDbType.NVarChar, -1), new SqlParameter("@CreateTime", SqlDbType.NVarChar, 50), new SqlParameter("@type", SqlDbType.NVarChar, 50), new SqlParameter("@CreatePeople", SqlDbType.NVarChar, 50) }; parameters[0].Value = model.sid; parameters[1].Value = model.title; parameters[2].Value = model.Content; parameters[3].Value = model.CreateTime; parameters[4].Value = model.type; parameters[5].Value = model.CreatePeople; int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }
protected void Submit_Click(object sender, EventArgs e) { if (this.CreateTime.Value == "") { Page.ClientScript.RegisterStartupScript(Page.GetType(), "message", "<script language='javascript' defer>alert('创建时间不能为空!');</script>"); return; } entity_users user = Session["adminName"] as entity_users; entity_News news = new entity_News(); news.Content = Common.StringHelp.HTMLToText(this.newsContent.Value.Trim()); news.sid = ViewState["sid"].ToString(); news.type = ""; news.title = this.newsName.Text.Trim(); news.CreateTime = this.CreateTime.Value; news.CreatePeople = user.userID; if (this.FileUpload.FileName != null) { //img.Add(); } if (bll.Add(news)) { Page.ClientScript.RegisterStartupScript(Page.GetType(), "message", "<script language='javascript' defer>alert('添加成功');</script>"); ////// ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "alert", "alert('添加成功')", true); Response.Redirect("selectedNews.aspx"); } else { Page.ClientScript.RegisterStartupScript(Page.GetType(), "message", "<script language='javascript' defer>alert('添加失败');</script>"); //////ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "alert", "alert('添加失败')", true); } }
/// <summary> /// 得到一个对象实体 /// </summary> public entity_News DataRowToModel(DataRow row) { entity_News model = new entity_News(); if (row != null) { if (row["sid"] != null) { model.sid = row["sid"].ToString(); } if (row["title"] != null) { model.title = row["title"].ToString(); } if (row["Content"] != null) { model.Content = row["Content"].ToString(); } if (row["CreateTime"] != null) { model.CreateTime = row["CreateTime"].ToString(); } if (row["type"] != null) { model.type = row["type"].ToString(); } if (row["CreatePeople"] != null) { model.CreatePeople = row["CreatePeople"].ToString(); } } return(model); }
private void DataBind(string sid) { entity_News news = bll.GetModel(sid); this.title.Text = news.title; this.Content.Text = Common.StringHelp.TextToHTMl(news.Content); this.ReleaseDate.Text = news.CreateTime; }
private void DataBind(string TitleType) { entity_News news = bll.GetEntity(TitleType); this.title.Text = news.title; this.Content.Text = StringHelp.TextToHTMl(news.Content); this.ReleaseDate.Text = news.CreateTime; }
/// <summary> /// 将获取到的值绑定到控件中 /// </summary> public void databinding() { entity_News news = bll.GetModel(sid); this.newsName.Text = news.title; this.CreateTime.Value = news.CreateTime; this.newsContent.InnerText = Common.StringHelp.TextToHTMl(news.Content); }
/// <summary> /// 更新一条数据 /// </summary> public bool Update(entity_News model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update News set "); strSql.Append("title=@title,"); strSql.Append("Content=@Content,"); strSql.Append("CreateTime=@CreateTime,"); strSql.Append("type=@type,"); strSql.Append("CreatePeople=@CreatePeople"); strSql.Append(" where sid=@sid "); SqlParameter[] parameters = { new SqlParameter("@title", SqlDbType.NVarChar, 500), new SqlParameter("@Content", SqlDbType.NVarChar, -1), new SqlParameter("@CreateTime", SqlDbType.NVarChar, 50), new SqlParameter("@type", SqlDbType.NVarChar, 50), new SqlParameter("@CreatePeople", SqlDbType.NVarChar, 50), new SqlParameter("@sid", SqlDbType.NVarChar, 50) }; parameters[0].Value = model.title; parameters[1].Value = model.Content; parameters[2].Value = model.CreateTime; parameters[3].Value = model.type; parameters[4].Value = model.CreatePeople; parameters[5].Value = model.sid; int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }
/// <summary> /// 提交按钮 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void Submit_Click(object sender, EventArgs e) { entity_users user = Session["adminName"] as entity_users; entity_News news = bll.GetModel(sid); news.Content = Common.StringHelp.HTMLToText(this.newsContent.Value.Trim()); news.title = this.newsName.Text.Trim(); news.type = type; news.CreateTime = this.CreateTime.Value; news.CreatePeople = user.userID; if (bll.Update(news)) { Page.ClientScript.RegisterStartupScript(Page.GetType(), "message", "<script language='javascript' defer>alert('修改成功');</script>"); //////ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "alert", "alert('修改成功')", true); Response.Redirect("selectedNews.aspx?type=" + type); } else { Page.ClientScript.RegisterStartupScript(Page.GetType(), "message", "<script language='javascript' defer>alert('修改失败');</script>"); //////ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "alert", "alert('修改失败')", true); } }
/// <summary> /// 得到一个对象实体 /// </summary> public entity_News GetEntity(string type) { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 sid,title,Content,CreateTime,type,CreatePeople from News "); strSql.Append(" where type=@type "); SqlParameter[] parameters = { new SqlParameter("@type", SqlDbType.NVarChar, 50) }; parameters[0].Value = type; entity_News model = new entity_News(); DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { return(DataRowToModel(ds.Tables[0].Rows[0])); } else { return(null); } }
/// <summary> /// 更新一条数据 /// </summary> public bool Update(entity_News model) { return(dal.Update(model)); }
/// <summary> /// 增加一条数据 /// </summary> public bool Add(entity_News model) { return(dal.Add(model)); }