public static ForumEstCommentbyUser getoneForumCommentbyID(string forumcommentID) { ForumEstCommentbyUser fu = new ForumEstCommentbyUser(); try { SqlCommand command = new SqlCommand("Select * from ForumEstCommentbyUser where forumcommentID=@forumcommentID"); command.Parameters.AddWithValue("@forumcommentID", forumcommentID); command.Connection = connection; connection.Open(); SqlDataReader reader = command.ExecuteReader(); while (reader.Read()) { fu.forumcommentID = reader["forumcommentID"].ToString(); ForumEstablishments onef = ForumEstablishmentsDB.getForumEstbyID(reader["forumID"].ToString()); fu.forumID = onef; fu.comments = reader["comments"].ToString(); AUser u = AUserDB.getUserbyID(reader["commentby"].ToString()); fu.commentby = u; fu.date = Convert.ToDateTime(reader["date"]); fu.status = reader["status"].ToString(); } reader.Close(); } finally { connection.Close(); } return(fu); }
public static List <ForumEstCommentbyUser> getalloneForumAllComment() { List <ForumEstCommentbyUser> fulists = new List <ForumEstCommentbyUser>(); try { SqlCommand command = new SqlCommand("Select * from ForumEstCommentbyUser"); command.Connection = connection; connection.Open(); SqlDataReader reader = command.ExecuteReader(); while (reader.Read()) { ForumEstCommentbyUser fu = new ForumEstCommentbyUser(); fu.forumcommentID = reader["forumcommentID"].ToString(); ForumEstablishments onef = ForumEstablishmentsDB.getForumEstbyID(reader["forumID"].ToString()); fu.forumID = onef; fu.comments = reader["comments"].ToString(); AUser u = AUserDB.getUserbyID(reader["commentby"].ToString()); fu.commentby = u; fu.date = Convert.ToDateTime(reader["date"]); fu.status = reader["status"].ToString(); fulists.Add(fu); } reader.Close(); } finally { connection.Close(); } return(fulists); }
public static ForumEstablishments getForumEstbyID(string id) { ForumEstablishments fu = new ForumEstablishments(); try { SqlCommand command = new SqlCommand("Select * from ForumEstablishment where forumID=@forumID"); command.Parameters.AddWithValue("@forumID", id); command.Connection = connection; connection.Open(); SqlDataReader reader = command.ExecuteReader(); while (reader.Read()) { fu.ForumID = reader["forumID"].ToString(); fu.title = reader["title"].ToString(); fu.message = reader["message"].ToString(); fu.date = Convert.ToDateTime(reader["date"]); fu.status = reader["status"].ToString(); Establishment es = EstablishmentDB.getEstablishmentByID(reader["establishmentID"].ToString()); fu.estID = es; } reader.Close(); } finally { connection.Close(); } return(fu); }
//add new forum to database public static int insertForum(ForumEstablishments u) { int num = -1; try { SqlCommand command = new SqlCommand("insert into ForumUser values(@title, @message, @date,@status,@establishmentID)"); command.Parameters.AddWithValue("@title", u.title); command.Parameters.AddWithValue("@message", u.message); command.Parameters.AddWithValue("@date", u.date); command.Parameters.AddWithValue("@status", u.date); command.Parameters.AddWithValue("@establishmentID", u.estID.ID); command.Connection = connection; connection.Open(); if (command.ExecuteNonQuery() > 0) { num = 1; } } finally { connection.Close(); } return(num); }
public static List <ForumEstablishments> getAllForumEstablishment() { List <ForumEstablishments> forumlists = new List <ForumEstablishments>(); try { SqlCommand command = new SqlCommand("Select * from ForumEstablishment"); command.Connection = connection; connection.Open(); SqlDataReader reader = command.ExecuteReader(); while (reader.Read()) { ForumEstablishments fu = new ForumEstablishments(); fu.ForumID = reader["forumID"].ToString(); fu.title = reader["title"].ToString(); fu.message = reader["message"].ToString(); fu.date = Convert.ToDateTime(reader["date"]); fu.status = reader["status"].ToString(); Establishment es = EstablishmentDB.getEstablishmentByID(reader["establishmentID"].ToString()); fu.estID = es; forumlists.Add(fu); } reader.Close(); } finally { connection.Close(); } return(forumlists); }
public ForumEstCommentbyEst(ForumEstablishments forumID, string comments, Establishment commentby, DateTime date, string status) { this.forumID = forumID; this.comments = comments; this.commentby = commentby; this.date = date; this.status = status; }
protected void gvEst_SelectedIndexChanged1(object sender, EventArgs e) { List <tempcomment> tclist = new List <tempcomment>(); Panel1.Visible = true; allelist = ForumEstablishmentsDB.getAllForumEstablishment(); ForumEstablishments fe = allelist[gvEst.PageSize * gvEst.PageIndex + gvEst.SelectedIndex]; gvEst.SelectedIndex = -1; Session["forumID"] = fe.forumID; lbltitle.Text = fe.Title; lblmessage.Text = fe.message; lblUser.Text = fe.estID.ID; lblDate.Text = string.Format("{0:dd/MM/yyyy}", fe.date); List <ForumEstCommentbyUser> fecu = ForumEstCommentbyUserDB.getoneForumAllCommentbyID(fe.forumID); List <ForumEstCommentbyEst> fece = ForumEstCommentbyEstDB.getoneForumAllCommentbyID(fe.forumID); foreach (ForumEstCommentbyUser f in fecu) { tempcomment tc = new tempcomment(); tc.comentID = f.forumcommentID; tc.comment = f.comments; tc.commentby = f.commentby.name.ToString(); tc.time = f.date; tc.status = f.status; tc.timeshow = datesub(f.date); tclist.Add(tc); } foreach (ForumEstCommentbyEst g in fece) { tempcomment tc = new tempcomment(); tc.comentID = g.forumcommentID; tc.comment = g.comments; tc.commentby = g.commentby.Name.ToString(); tc.time = g.date; tc.status = g.status; tc.timeshow = datesub(g.date); tclist.Add(tc); } if (tclist.Count == 0) { lblNotFound.Visible = true; } else { tclist = tclist.OrderBy(x => x.time).ToList(); tclist.Reverse(); lblNotFound.Visible = false; GridView1.DataSource = tclist; GridView1.DataBind(); } }
protected void gvEst_RowDeleting(object sender, GridViewDeleteEventArgs e) { allelist = ForumEstablishmentsDB.getAllForumEstablishment(); ForumEstablishments fe = allelist[gvEst.PageSize * gvEst.PageIndex + e.RowIndex]; if (fe.status == "allow") { fe.status = "ban"; } else { fe.status = "allow"; } ForumEstablishmentsDB.updateEstForum(fe); allelist = ForumEstablishmentsDB.getAllForumEstablishment(); gvEst.DataSource = allelist; gvEst.DataBind(); }
public static int updateEstForum(ForumEstablishments u) { int result; try { SqlCommand command = new SqlCommand("Update ForumEstablishment set status=@status where title=@title"); command.Parameters.AddWithValue("@title", u.title); command.Parameters.AddWithValue("@status", u.status); command.Connection = connection; connection.Open(); result = command.ExecuteNonQuery(); } finally { connection.Close(); } return(result); }