/// <summary> /// Load news /// </summary> private void LoadData() { News news = new News(); news = NewsBLL.GetNewsByID(Request.QueryString["ID"].ToString())[0]; txtTitle.Text = news.Title; txtSubject.Text = news.Subject; ftbBody.Text = news.Content; cbActive.Checked =Convert.ToBoolean(news.Active); lblReport.Text = ""; }
private void LoadData() { News news =new News(); news = NewsBLL.GetNewsByID(Request.QueryString["ID"].ToString())[0]; lblTitle.Text = news.Title; ltrSubject.Text = news.Subject; ltrContent.Text = news.Content; lblCreateDate.Text = "Page last updated at: " + Convert.ToDateTime(news.CreateDate).ToLongDateString(); }
public News NewsIDatareader(IDataReader dr) { News obj = new News(); obj.ID = (dr["ID"] is DBNull) ? string.Empty : dr["ID"].ToString(); obj.Title = (dr["Title"] is DBNull) ? string.Empty : dr["Title"].ToString(); obj.Subject = (dr["Subject"] is DBNull) ? string.Empty : dr["Subject"].ToString(); obj.Content = (dr["Content"] is DBNull) ? string.Empty : dr["Content"].ToString(); obj.CreateDate = (dr["CreateDate"] is DBNull) ? string.Empty : dr["CreateDate"].ToString(); obj.Active = (dr["Active"] is DBNull) ? string.Empty : dr["Active"].ToString(); return obj; }
public bool InsertNews(News news) { using (SqlCommand cmd = GetCommand("insertNews", CommandType.StoredProcedure)) { AddParameter(cmd, "@Title", news.Title); AddParameter(cmd, "@Subject", news.Subject); AddParameter(cmd, "@Content", news.Content); int result = ExeNonQuery(cmd); return result > 0; } }
public List<News> GetAllNews() { List<News> list = new List<News>(); using (SqlCommand cmd = GetCommand("getAllNews", CommandType.StoredProcedure)) { News news = new News(); using (SqlDataReader dr = ExeDataReader(cmd)) { if (dr.HasRows) { while (dr.Read()) { list.Add(news.NewsIDatareader(dr)); } } } news = null; } return list; }
protected void btnCreate_Click(object sender, EventArgs e) { if (Page.IsValid) { News news = new News(); news.Title = txtTitle.Text; news.Subject = txtSubject.Text; news.Content = ftbBody.Text; bool result = NewsBLL.InsertNews(news); if (result) { lblReport.Text = "Create new News Successful!"; Response.AddHeader("REFRESH", "2;URL=NewsManagement.aspx"); } else { lblReport.Text = "Insert Eror!"; } } }
public List<News> GetNewsByID(string id) { List<News> list = new List<News>(); using (SqlCommand cmd = GetCommand("getNewsByID", CommandType.StoredProcedure)) { AddParameter(cmd, "@ID", Convert.ToInt32(id)); News news = new News(); using (SqlDataReader dr = ExeDataReader(cmd)) { if (dr.HasRows) { while (dr.Read()) { list.Add(news.NewsIDatareader(dr)); } } } news = null; } return list; }
protected void btnUpdate_Click(object sender, EventArgs e) { if (Page.IsValid) { News news = new News(); news = NewsBLL.GetNewsByID(Request.QueryString["ID"].ToString())[0]; news.Title = txtTitle.Text; news.Subject = txtSubject.Text; news.Content = ftbBody.Text; news.Active = (cbActive.Checked) ? "1" : "0"; bool result = NewsBLL.UpdateNews(news); if (result) { lblReport.Text = "Update News Successful!"; Response.AddHeader("REFRESH", "2;URL=NewsManagement.aspx"); } else { lblReport.Text = "Update Eror!"; } } }
public List<News> SearchNewsByTitle(string title) { List<News> list = new List<News>(); using (SqlCommand cmd = GetCommand("SearchNewsByTitle", CommandType.StoredProcedure)) { AddParameter(cmd, "@Title", title); News news = new News(); using (SqlDataReader dr = ExeDataReader(cmd)) { if (dr.HasRows) { while (dr.Read()) { list.Add(news.NewsIDatareader(dr)); } } } news = null; } return list; }
public static bool UpdateNews(News news) { return db.UpdateNews(news); }
public static bool InsertNews(News news) { return db.InsertNews(news); }