public static bool Delete(dbo_ReadNewsClass clsdbo_ReadNews) { SqlConnection connection = SAMDataClass.GetConnection(); string deleteProcedure = "[dbo].[ReadNewsDelete]"; SqlCommand deleteCommand = new SqlCommand(deleteProcedure, connection); deleteCommand.CommandType = CommandType.StoredProcedure; if (clsdbo_ReadNews.News_ID != null) { deleteCommand.Parameters.AddWithValue("@OldNews_ID", clsdbo_ReadNews.News_ID); } else { deleteCommand.Parameters.AddWithValue("@OldNews_ID", DBNull.Value); } if (clsdbo_ReadNews.User_ID != null) { deleteCommand.Parameters.AddWithValue("@OldUser_ID", clsdbo_ReadNews.User_ID); } else { deleteCommand.Parameters.AddWithValue("@OldUser_ID", DBNull.Value); } if (clsdbo_ReadNews.Read_Date.HasValue == true) { deleteCommand.Parameters.AddWithValue("@OldRead_Date", clsdbo_ReadNews.Read_Date); } else { deleteCommand.Parameters.AddWithValue("@OldRead_Date", DBNull.Value); } deleteCommand.Parameters.Add("@ReturnValue", System.Data.SqlDbType.Int); deleteCommand.Parameters["@ReturnValue"].Direction = ParameterDirection.Output; try { connection.Open(); deleteCommand.ExecuteNonQuery(); int count = System.Convert.ToInt32(deleteCommand.Parameters["@ReturnValue"].Value); if (count > 0) { return(true); } else { return(false); } } catch (SqlException) { return(false); } finally { connection.Close(); } }
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { try { string News_ID = Request.QueryString["News_ID"]; hdfNEWS_ID.Value = News_ID; // Session.Remove("News_ID"); dbo_NewsClass2 _news = dbo_NewsDataClass2.Select_Record(News_ID); if (!string.IsNullOrEmpty(_news.Content_FileName)) { lnkBContentFile.Text = _news.Content_FileName; lnkBContentFile.CommandArgument = News_ID; } else { lnkBContentFile.Visible = false; } if (_news.Photo_MemoryStream != null) { imgNewsPhoto.ImageUrl = string.Format("data:image/png;base64,{0}", Convert.ToBase64String(_news.Photo_MemoryStream, 0, _news.Photo_MemoryStream.Length)); } txtSubjectDiv.InnerHtml = _news.Subject; // txtSubjectH1.Text = txtContentDiv.InnerHtml = _news.Content; txtStart_Effective_Date.Text = _news.Start_Date.Value.ToShortDateString(); txtEnd_Effective_Date.Text = _news.End_Date.Value.ToShortDateString(); // linkVidoes.Attributes.Add("href", _news.VDO_Hyperlink); linkVidoes.HRef = _news.VDO_Hyperlink; linkVidoes.InnerText = _news.VDO_Hyperlink; gg.Src = _news.VDO_Hyperlink; dbo_ReadNewsClass readnew = new dbo_ReadNewsClass(); readnew.User_ID = HttpContext.Current.Request.Cookies["User_ID"].Value; readnew.News_ID = News_ID; readnew.Read_Date = DateTime.Now; dbo_ReadNewsDataClass.Add(readnew); } catch (Exception ex) { } } }
public static dbo_ReadNewsClass Select_Record(String News_ID) { dbo_ReadNewsClass clsdbo_ReadNews = new dbo_ReadNewsClass(); SqlConnection connection = SAMDataClass.GetConnection(); string selectProcedure = "[ReadNewsSelect]"; SqlCommand selectCommand = new SqlCommand(selectProcedure, connection); selectCommand.CommandType = CommandType.StoredProcedure; selectCommand.Parameters.AddWithValue("@News_ID", News_ID); try { connection.Open(); SqlDataReader reader = selectCommand.ExecuteReader(CommandBehavior.SingleRow); if (reader.Read()) { clsdbo_ReadNews.News_ID = reader["News_ID"] is DBNull ? null : reader["News_ID"].ToString(); clsdbo_ReadNews.User_ID = reader["User_ID"] is DBNull ? null : reader["User_ID"].ToString(); clsdbo_ReadNews.Read_Date = reader["Read_Date"] is DBNull ? null : (DateTime?)reader["Read_Date"]; } else { clsdbo_ReadNews = null; } reader.Close(); } catch (SqlException) { return(clsdbo_ReadNews); } finally { connection.Close(); } return(clsdbo_ReadNews); }