public static List <ForumEstCommentbyEst> getoneForumAllCommentbyID(string forumID) { List <ForumEstCommentbyEst> fulists = new List <ForumEstCommentbyEst>(); try { SqlCommand command = new SqlCommand("Select * from ForumEstCommentbyEst where forumID=@forumID"); command.Parameters.AddWithValue("@forumID", forumID); command.Connection = connection; connection.Open(); SqlDataReader reader = command.ExecuteReader(); while (reader.Read()) { ForumEstCommentbyEst fu = new ForumEstCommentbyEst(); fu.forumcommentID = reader["forumcommentID"].ToString(); ForumEstablishment onef = ForumEstablishmentDB.getForumEstbyID(reader["forumID"].ToString()); fu.forumID = onef; fu.comments = reader["comments"].ToString(); Establishment u = EstablishmentDB.getEstablishmentByID(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); }
protected void btnSumbit_Click(object sender, EventArgs e) { if (tbxComment.Text == "") { lbloutput.Text = "The Comment field cannot be blank."; return; } else { lbloutput.Text = ""; if (Session["hyper1"].ToString() == "1") { ForumUser fu = ForumUserDB.getForumUserbyID(Session["hyper"].ToString()); Establishment es = (Establishment)Session["establishment"]; ForumUserCommentbyEst fue = new ForumUserCommentbyEst(fu, tbxComment.Text, es, System.DateTime.Now, "allow"); int num = ForumUserCommentbyEstDB.insertForumCommentUser(fue); if (num != 1) { lbloutput.Text = "Fail to comment!"; return; } else { Response.Redirect("ForumCommentE.aspx", true); } } else { ForumEstablishment fe = ForumEstablishmentDB.getForumEstbyID(Session["hyper1"].ToString()); Establishment es = (Establishment)Session["establishment"]; ForumEstCommentbyEst fee = new ForumEstCommentbyEst(fe, tbxComment.Text, es, System.DateTime.Now, "allow"); int num = ForumEstCommentbyEstDB.insertForumCommentEst(fee); if (num != 1) { lbloutput.Text = "Fail to comment!"; return; } else { Response.Redirect("ForumCommentE.aspx", true); } } } }
protected void Page_Load(object sender, EventArgs e) { if ((Establishment)Session["establishment"] == null) { Server.Transfer("Login.aspx"); } else { if (Session["hyper"].ToString() == "1") { if (Session["hyper1"].ToString() == "1") { Server.Transfer("EstForum.aspx"); } else { lblNotFound.Visible = false; ForumEstablishment fe = ForumEstablishmentDB.getForumEstbyID(Session["hyper1"].ToString()); lblheading.Text = "ForumID: #" + fe.forumID; List <ForumEstablishment> felist = new List <ForumEstablishment>(); felist.Add(fe); 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.comment = f.comments; tc.commentby = f.commentby.Name.ToString(); tc.time = f.date; tc.timeshow = datesub(f.date); if (f.status == "allow") { tclist.Add(tc); } } foreach (ForumEstCommentbyEst g in fece) { tempcomment tc = new tempcomment(); tc.comment = g.comments; tc.commentby = g.commentby.Name.ToString(); tc.time = g.date; tc.timeshow = datesub(g.date); if (g.status == "allow") { tclist.Add(tc); } } if (tclist.Count == 0) { lblNotFound.Visible = true; lblNotFound.Text = "There is no comment"; PanelCMT.Visible = false; } else { tclist = tclist.OrderBy(x => x.time).ToList(); tclist.Reverse(); lblNotFound.Text = ""; PanelCMT.Visible = true; GridView1.DataSource = tclist; GridView1.DataBind(); } } } else { ForumUser fu = ForumUserDB.getForumUserbyID(Session["hyper"].ToString()); lblheading.Text = "ForumID: #" + fu.forumID; List <ForumUser> flist = new List <ForumUser>(); flist.Add(fu); lbltitle.Text = fu.Title; lblmessage.Text = fu.message; lblUser.Text = fu.userID.username; lblDate.Text = string.Format("{0:dd/MM/yyyy}", fu.date); List <ForumUserCommentbyEst> fuce = ForumUserCommentbyEstDB.getoneForumAllCommentbyID(fu.forumID); List <ForumUserCommentbyUser> fucu = ForumUserCommentbyUserDB.getoneForumAllCommentbyID(fu.forumID); foreach (ForumUserCommentbyEst f in fuce) { tempcomment tc = new tempcomment(); tc.comment = f.comments; tc.commentby = f.commentby.Name.ToString(); tc.time = f.date; tc.timeshow = datesub(f.date); if (f.status == "allow") { tclist.Add(tc); } } foreach (ForumUserCommentbyUser g in fucu) { tempcomment tc = new tempcomment(); tc.comment = g.comments; tc.commentby = g.commentby.username.ToString(); tc.time = g.date; tc.timeshow = datesub(g.date); if (g.status == "allow") { tclist.Add(tc); } } if (tclist.Count == 0) { lblNotFound.Visible = true; lblNotFound.Text = "There is no comment"; PanelCMT.Visible = false; } else { tclist = tclist.OrderBy(x => x.time).ToList(); tclist.Reverse(); lblNotFound.Text = ""; PanelCMT.Visible = true; GridView1.DataSource = tclist; GridView1.DataBind(); } } } }