Wrox Home  
Search P2P Archive for: Go

  Return to Index  

aspdotnet_website_programming thread: threaded messages


Message #1 by "Todd Mueller" <lenny_92675@y...> on Wed, 20 Nov 2002 21:32:43
anyone create a threaded topic list? Im looking at doing this and trying 
to find the optimal way of doing so.

Todd
Message #2 by "Todd Mueller" <lenny_92675@y...> on Fri, 22 Nov 2002 16:34:17
i figured out how to do the message threading

if anyone is interested let me know.

Todd
Message #3 by "Todd Mueller" <lenny_92675@y...> on Fri, 22 Nov 2002 18:57:01
namespace SGK.WebModules.Forums.Web
{
	/// <summary>
	/// Summary description for Topic_New.
	/// </summary>
	public class Topic_New : SGK.SGKWeb.Web.SGKWebPage
	{
		protected System.Web.UI.WebControls.DataList DataList1;
		protected System.Web.UI.WebControls.DataList MyDataList;
		protected System.Web.UI.WebControls.Label lblSubject;
		protected System.Web.UI.WebControls.Label lblBGColor;
		
		public DataTable dtFinal = new DataTable("Messages");

		private void Page_Load(object sender, System.EventArgs e)
		{
			if (Request.QueryString["TopicID"] == null)
			{
				// We don't have a valid ForumID, so go 
back to the main page.
				Response.Redirect("forums.aspx");
			}
			
			int TopicID = int.Parse(Request["TopicID"]);

			// call the LoadMessages Function
			LoadMessages(TopicID);
		}

		// loadmessages with topicID
		private void LoadMessages(int TopicID)
		{
			// Prepare Final Table
			dtFinal.Columns.Add("ReplyID", System.Type.GetType
("System.Int32"));
			dtFinal.Columns.Add("Subject", System.Type.GetType
("System.String"));
			dtFinal.Columns.Add("PostedBy", System.Type.GetType
("System.String"));
			dtFinal.Columns.Add("Date", System.Type.GetType
("System.String"));
			dtFinal.Columns.Add("bg", System.Type.GetType
("System.String"));
			ProcessRows(0, 0, TopicID);

			// Bind Final List
			MyDataList.DataSource = dtFinal;
			MyDataList.DataBind();
		}

		// process rows with variables parentID, level, topicID
		private void ProcessRows(int parentID, int level, int 
TopicID)
		{
			DataTable dtTemp = new DataTable();
			
			dtTemp = GetMessages(parentID, TopicID);	
			for (int i =0; i < dtTemp.Rows.Count; i++)
			{
				DataRow tempRow = dtFinal.NewRow();
				tempRow["ReplyID"] = dtTemp.Rows[i]
["ReplyID"];
				tempRow["Subject"] = "<a 
href=topic_new.aspx?TopicID=" + TopicID + "&replyID=" + dtTemp.Rows[i]
["ReplyID"] + ">" + dtTemp.Rows[i]["Subject"] + "</a>";
				tempRow["PostedBy"] = dtTemp.Rows[i]
["FirstName"] + " " + dtTemp.Rows[i]["LastName"];
				tempRow["Date"] = dtTemp.Rows[i]
["AddedDate"];
			
				// check to see if message user selected 
is the one where currently in
				if (Request.QueryString["replyID"] != 
null) 
				{
					if (Request.QueryString
["replyID"].ToString() == tempRow["ReplyID"].ToString())
					{
						tempRow["bg"] = "pink";

						// add image
						if (level > 0)
						{
							tempRow["Subject"] 
= "<img src=images/replytoopen.gif border=0>&nbsp;&nbsp;" + tempRow
["Subject"];
						}
						else if(level ==0)
						{
							tempRow["Subject"] 
= "<img src=images/replytoopen.gif border=0>&nbsp;&nbsp;" + tempRow
["Subject"];
						}
					}
					else
					{
						// add image
						if (level > 0)
						{
							tempRow["Subject"] 
= "<img src=images/replyarrow.gif border=0>&nbsp;&nbsp;" + tempRow
["Subject"];
						}
						else if(level ==0)
						{
							tempRow["Subject"] 
= "<img src=images/replyto.gif border=0>&nbsp;&nbsp;" + tempRow["Subject"];
						}
					}


					
				}
				else
				{
					// add image
					if (level > 0)
					{
						tempRow["Subject"] = "<img 
src=images/replyarrow.gif border=0>&nbsp;&nbsp;" + tempRow["Subject"];
					}
					else if(level ==0)
					{
						tempRow["Subject"] = "<img 
src=images/replyto.gif border=0>&nbsp;&nbsp;" + tempRow["Subject"];
					}
				}

				// add spacing
				for (int j =0; j<level; j++)
				{
					tempRow["Subject"] 
= "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" + tempRow["Subject"];
				}

				dtFinal.Rows.Add(tempRow);
				ProcessRows(int.Parse(dtTemp.Rows[i]
["ReplyID"].ToString()), level + 1, TopicID);
				//tempRow;
			}
	}

		private DataTable GetMessages(int parentID, int TopicID) 
		{

			DataTable localDT = new DataTable();

			SqlConnection MyConnection = new SqlConnection
(Configuration.ModuleConfig.GetSettings().ConnectionString);
			
			string sql = "SELECT Forums_Replies.Subject, 
Forums_Replies.Message, Forums_Replies.ReplyID, Forums_Replies.InReplyTo, 
Accounts_Users.FirstName, Accounts_Users.LastName, 
Forums_Replies.AddedDate FROM Forums_Members INNER JOIN Accounts_Users ON 
Forums_Members.UserID = Accounts_Users.UserID INNER JOIN Forums_Topics 
INNER JOIN Forums_Replies ON Forums_Topics.TopicID = 
Forums_Replies.TopicID ON Forums_Members.MemberID = 
Forums_Replies.MemberID ";
			sql = sql += "WHERE Forums_Topics.TopicID =" + 
TopicID + " AND Forums_Replies.InReplyTo =" + parentID;
			
			SqlDataAdapter adapt = new SqlDataAdapter(sql, 
MyConnection);
			DataSet ds = new DataSet();

			//trap for any errors
			try
			{
				MyConnection.Open();
				adapt.Fill(ds, "Messages");

				MyConnection.Close();
			}
			catch (Exception e)
			{
				Trace.Warn(e.Message);
			}

			//If Not dr.Item("forum") Is Nothing Then
			//lblSubject.Text = ds.Tables("forum").ToString
			//End If

			if (ds.Tables["Messages"] != null)
			{
				localDT = ds.Tables["Messages"];
			}
			
			// return the value
			return localDT;
		}


		#region Web Form Designer generated code
		override protected void OnInit(EventArgs e)
		{
			//
			// CODEGEN: This call is required by the ASP.NET 
Web Form Designer.
			//
			base.OnInit(e);
			InitializeComponent();
			
		}
		
		/// <summary>
		/// Required method for Designer support - do not modify
					/// the contents of this method 
with the code editor.
					/// </summary>
		private void InitializeComponent()
		{    
			this.Load += new System.EventHandler
(this.Page_Load);

		}
		#endregion



	}
}

  Return to Index