public int InsertNotice(NewsModel news) { SqlParameter[] param = { new SqlParameter("@Title", SqlDbType.VarChar, 50), new SqlParameter("@NoticeContent", SqlDbType.Text), new SqlParameter("@NoticePerSon",SqlDbType.VarChar,20) }; param[0].Value = news.Title; param[1].Value = news.NoticeContent; param[2].Value = news.NoticePerson; int result = SqlHelp.ExecuteNonQuery("prc_InsertNews", CommandType.StoredProcedure, param); return result; }
protected void Add_Click(object sender, EventArgs e) { NewsModel news = new NewsModel(); news.Title = txtNoticeTitle.Text.Trim(); news.NoticeContent = ftbContent.Text.Trim(); news.NoticePerson = user.Name; bool flag = bll.InsertNotice(news); if (flag) { Page.ClientScript.RegisterStartupScript(GetType(), "OnSubmit", "<script>alert('添加成功');location.href='NewsInfo.aspx';</script>"); } else { Page.ClientScript.RegisterStartupScript(GetType(), "OnSubmit", "<script>alert('添加失败');</script>"); } }
public NewsModel ShowNewsByID(int id) { SqlParameter param=new SqlParameter("@ID",SqlDbType.Int,5); param.Value=id; SqlDataReader dr = SqlHelp.ExecuteReader("prc_ShowNewsByID", CommandType.StoredProcedure,param); dr.Read(); NewsModel news = new NewsModel(); if (dr.HasRows) { news.Title = dr[0].ToString(); news.NoticeDate = Convert.ToDateTime(dr[1]); news.NoticeContent = dr[2].ToString(); } dr.Close(); return news; }
public List<NewsModel> ShowNews() { SqlDataReader dr= SqlHelp.ExecuteReader("prc_ShowNews", CommandType.StoredProcedure); List<NewsModel> list = new List<NewsModel>(); while (dr.Read()) { NewsModel news = new NewsModel(); news.ID = Convert.ToInt32(dr[0]); news.Title = dr[1].ToString(); news.NoticeDate = Convert.ToDateTime(dr[2]); news.NoticeContent = dr[3].ToString(); list.Add(news); } dr.Close(); return list; }
protected void Edit_Click(object sender, EventArgs e) { NewsModel news = new NewsModel(); news.Title = txtNoticeTitle.Text.Trim(); news.NoticeContent = ftbContent.Text.Trim(); news.NoticePerson = user.Name; news.ID = int.Parse(Request.QueryString["ID"].ToString()); bool flag = bll.UpdateNews(news); if (flag) { Page.ClientScript.RegisterStartupScript(GetType(), "OnSubmit", "<script>alert('修改成功');location.href='NewsInfo.aspx';</script>"); } else { Page.ClientScript.RegisterStartupScript(GetType(), "OnSubmit", "<script>alert('修改失败');</script>"); } }
public List<NewsModel> GetNewsByCondition(string condition) { SqlParameter param = new SqlParameter("@Condition", SqlDbType.VarChar, 255); param.Value = condition; SqlDataReader dr = SqlHelp.ExecuteReader("prc_GetNewsByCondition", CommandType.StoredProcedure,param); List<NewsModel> list = new List<NewsModel>(); while (dr.Read()) { NewsModel news = new NewsModel(); news.ID = Convert.ToInt32(dr[0]); news.Title = dr[1].ToString(); news.NoticeDate = Convert.ToDateTime(dr[2]); news.NoticeContent = dr[3].ToString(); news.NoticePerson = dr[4].ToString(); list.Add(news); } dr.Close(); return list; }
protected void Page_Load(object sender, EventArgs e) { int id = Convert.ToInt32(Request.QueryString["ID"]); news = bll.ShowNewsByID(id); Page.DataBind(); }
public bool UpdateNews(NewsModel news) { int result = dal.UpdateNews(news); return result == 0 ? false : true; }
public bool InsertNotice(NewsModel news) { int result = dal.InsertNotice(news); return result == 0 ? false : true; }