protected void btnFpost_Click(object sender, EventArgs e) { if (tbxFtitle.Text == "") { lblOutputPost.Text = "Title cannot to blank"; return; } else if (tbxFmessage.Text == "") { lblOutputPost.Text = "Message cannot to blank"; return; } else { Establishment es = (Establishment)Session["establishment"]; ForumEstablishment fu = new ForumEstablishment(tbxFtitle.Text, tbxFmessage.Text, DateTime.Now, "allow", es); int num = ForumEstablishmentDB.insertForum(fu); if (num != 1) { lblOutputPost.Text = "Cannot Post Forum Right Now!"; return; } else { lblOutputPost.Text = "Successfully Posted!"; lblGVOutput.Text = ""; tbxFmessage.Text = ""; tbxFtitle.Text = ""; Panel1.Visible = true; elist = ForumEstablishmentDB.getAllForumEstbyStatus(); gvEst.DataSource = elist; gvEst.DataBind(); } } }
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); }
public static ForumEstablishment getForumEstbyID(string id) { ForumEstablishment fu = new ForumEstablishment(); 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(ForumEstablishment u) { int num = -1; try { SqlCommand command = new SqlCommand("insert into ForumEstablishment 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.status); 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 <ForumEstablishment> getAllForumEstablishment() { List <ForumEstablishment> forumlists = new List <ForumEstablishment>(); try { SqlCommand command = new SqlCommand("Select * from ForumEstablishment"); command.Connection = connection; connection.Open(); SqlDataReader reader = command.ExecuteReader(); while (reader.Read()) { ForumEstablishment fu = new ForumEstablishment(); 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(ForumEstablishment 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 <ForumEstablishment> elist = ForumEstablishmentDB.getAllForumEstbyStatus(); ForumEstablishment afa = elist[gvEst.PageSize * gvEst.PageIndex + gvEst.SelectedIndex]; Session["hyper1"] = afa.forumID; Session["hyper"] = "1"; Server.Transfer("ForumCommentE.aspx"); }
protected void gvEst_SelectedIndexChanged1(object sender, EventArgs e) { List <tempcomment> tclist = new List <tempcomment>(); Panel1.Visible = true; allelist = ForumEstablishmentDB.getAllForumEstablishment(); ForumEstablishment 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 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(); } } } }