protected void Button1_Click(object sender, EventArgs e) { int published = 0; if (drpPublish.SelectedIndex == 0) published = 1; //Session["userid"] = 1; ForumThread thread = new ForumThread(txtTitle.Text, txtContent.Text, drpSection.SelectedItem.Text, published, Convert.ToInt32(Session["userid"])); thread.CreateThreadintoDb(); }
public List <ForumThread> GetNThreads(int initial, int length) { SqlConnection con1 = new SqlConnection(ConfigurationManager.ConnectionStrings["globaldb"].ConnectionString); string q1 = "SELECT * FROM f_Thread where published=1 and SectionId = " + this.SectionId + " order by DateCreated"; SqlDataReader rdr; SqlCommand com1 = new SqlCommand(q1, con1); con1.Open(); rdr = com1.ExecuteReader(); ForumThread thread; List <ForumThread> NThreads = new List <ForumThread>(); int n = 1; while (rdr.Read()) { //NThreads = new List<ForumThread>(); thread = new ForumThread(); thread.ThreadID = Convert.ToInt32(rdr["ThreadID"]); thread.ThreadTitle = rdr["ThreadTitle"].ToString(); thread.ThreadBody = rdr["ThreadBody"].ToString(); if (thread.ThreadBody.Length > 200) { thread.ThreadBody = thread.ThreadBody.Substring(0, 200); thread.ThreadBody += "..."; } thread.SectionId = Convert.ToInt32(rdr["SectionID"]); thread.DateCreated = Convert.ToDateTime(rdr["DateCreated"]); if (rdr["DateModified"] != DBNull.Value) { thread.DateModified = Convert.ToDateTime(rdr["DateModified"]); } if (rdr["DatePublished"] != DBNull.Value) { thread.DatePublished = Convert.ToDateTime(rdr["DatePublished"]); } thread.Published = 1; thread.CreatorId = Convert.ToInt32(rdr["CreatorId"]); thread.getAuthor(); if (n >= initial && n <= initial + length - 1)//improve efficiency { NThreads.Add(thread); } n++; } con1.Close(); return(NThreads); }
protected void Page_Load(object sender, EventArgs e) { if (!(Convert.ToInt32(Session["userid"]) > 0)) Response.Redirect("../Pages/Registration.aspx"); if (IsPostBack) return; reply_pages = 1; NReplies = new List<ForumReply>(); int threadid=Convert.ToInt32(Request.QueryString["threadid"]); section = Request.QueryString["section"]; category = Request.QueryString["category"]; reply = Request.QueryString["reply"]; thr = new ForumThread(); thr.GetThread(threadid); NReplies = thr.GetNReplies(Convert.ToInt32(reply),10); }
protected void Page_Load(object sender, EventArgs e) { //Session["userid"] = 1; Session["forumid"] = 1; if (!(Convert.ToInt32(Session["userid"]) > 0)) Response.Redirect("../Pages/Registration.aspx?error=1"); if (IsPostBack) return; threadid = Convert.ToInt32(Request.QueryString["threadid"]); ForumThread thr = new ForumThread(); thr.GetThread(threadid); List<string> categories = new List<string>(); categories = ForumCategory.GetPublishedCategoryNames(Convert.ToInt32(Session["forumid"])); categories.Insert(0, "Select a category"); drpCategory.DataSource = categories; drpCategory.DataBind(); if (Request.QueryString["sec"] != null) { drpCategory.SelectedValue = Request.QueryString["cat"].ToString(); if (drpCategory.SelectedIndex > 0) { drpSection.DataSource = ForumSection.GetAllSectionNames(drpCategory.SelectedItem.Text); drpSection.DataBind(); drpSection.SelectedValue=sec = Request.QueryString["sec"].ToString(); } else { drpSection.Items.Clear(); drpSection.Items.Add("Select a section"); } } if (thr != null) { txtTitle.Text = thr.ThreadTitle; txtContent.Text = thr.ThreadBody; if (thr.Published == 1) drpPublish.SelectedIndex = 0; else drpPublish.SelectedIndex = 1; } }
protected void Button1_Click(object sender, EventArgs e) { int published = 0; if (drpPublish.SelectedIndex == 0) published = 1; bool toggle = false; //Session["userid"] = 1; ForumThread thread = new ForumThread(); thread.Published = published; thread.ThreadBody = txtContent.Text; thread.ThreadTitle = txtTitle.Text; thread.DateModified = DateTime.Now; thread.ThreadID = threadid; if (!(togglecount % 2 == 0)) toggle = true; else toggle = false; //thread.DatePublished = DateTime.Now; thread.SectionId = ForumSection.GetSectionIdbyName(sec); thread.UpdateThreadIntoDb(toggle); //thread.CreateThreadintoDb(); }