⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 subforum.aspx.cs

📁 c#网络编程及应用-刘瑞新
💻 CS
字号:
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;

namespace WebApplication
{
	/// <summary>
	/// subforum 的摘要说明。
	/// </summary>
	public class subforum : System.Web.UI.Page
	{
		protected System.Web.UI.WebControls.Label LabelTitle;
		protected System.Web.UI.WebControls.HyperLink HyperLink1;
		protected System.Web.UI.WebControls.HyperLink HyperLink2;
		protected System.Web.UI.WebControls.HyperLink HyperLink3;
		protected System.Web.UI.WebControls.Table TableAnswer;
	
		private void Page_Load(object sender, System.EventArgs e)
		{
			// 在此处放置用户代码以初始化页面
			this.LabelTitle.Text=Session["zhuti"].ToString();
			FillTextBox("mainforum",true);
			FillTextBox("subforum",false);

		}

		#region Web 窗体设计器生成的代码
		override protected void OnInit(EventArgs e)
		{
			//
			// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
			//
			InitializeComponent();
			base.OnInit(e);
		}
		
		/// <summary>
		/// 设计器支持所需的方法 - 不要使用代码编辑器修改
		/// 此方法的内容。
		/// </summary>
		private void InitializeComponent()
		{    
			this.Load += new System.EventHandler(this.Page_Load);

		}
		#endregion

		private void FillTextBox(string tableName,bool clearTable)
		{
			if(clearTable==true)
			{
				this.TableAnswer.Rows.Clear();
			}
			SqlConnection conn=new SqlConnection(MyClass.ConnString);
			SqlCommand command=null;
			if(tableName=="mainforum")
			{
				command=new SqlCommand("select * from "+tableName
					+" where id="+Session["mainid"].ToString(),conn);
			}
			else
			{
				command=new SqlCommand("select * from "+tableName
					+" where titleid="+Session["mainid"].ToString(),conn);
			}
			SqlDataReader rd=null;
			int num=GetRecordNumber(tableName);
			Label[] label=new Label[num];
			HyperLink[] hyperLink=new HyperLink[num];
			TextBox[] textbox=new TextBox[num];
			conn.Open();
			rd=command.ExecuteReader();
			int i=0;
			while(rd.Read())
			{
				TableRow row=new TableRow();
				TableCell cell=new TableCell();
				label[i]=new Label();
				label[i].Font.Size=FontUnit.XSmall;
				if(tableName=="mainforum")
				{
					label[i].Text="发布者:"+rd["author"].ToString()+
						"<br>主题:"+rd["title"].ToString()+
						"<br>最后修改时间:"+rd["releasetime"].ToString()+"&nbsp&nbsp";
				}
				else
				{
					label[i].Text="发布者:"+rd["author"].ToString()
						+"<br>最后修改时间:"+rd["lastmodifytime"].ToString()+"&nbsp&nbsp";
				}
				cell.Controls.Add(label[i]);
				hyperLink[i]=new HyperLink();
				hyperLink[i].Font.Size=FontUnit.XSmall;
				hyperLink[i].Text="[修改内容]";
				hyperLink[i].Target="_top";
				hyperLink[i].ForeColor=Color.Red;
				if(tableName=="mainforum")
				{
					hyperLink[i].NavigateUrl="modifyForum.aspx?mess=1";
				}
				else
				{
					hyperLink[i].NavigateUrl="modifyForum.aspx?mess=2&subid="
						+rd["id"].ToString();
				}
				cell.Controls.Add(hyperLink[i]);
				row.Cells.Add(cell);
				this.TableAnswer.Rows.Add(row);
				row=new TableRow();
				cell=new TableCell();
				textbox[i]=new TextBox();
				textbox[i].TextMode=TextBoxMode.MultiLine;
				textbox[i].Font.Size=FontUnit.XSmall;
				textbox[i].ReadOnly=true;
				textbox[i].BorderColor=Color.Black;
				textbox[i].BackColor=Color.FromArgb(0xec,0xf5,0xee);
				textbox[i].Width=700;
				textbox[i].Height=100;
				textbox[i].Text=""+rd["content"].ToString();
				cell.Controls.Add(textbox[i]);
				row.Cells.Add(cell);
				this.TableAnswer.Rows.Add(row);
			}
			rd.Close();
			conn.Close();
		}

		private int GetRecordNumber(string tableName)
		{
			int recordNumber=0;
			SqlConnection conn=new SqlConnection(MyClass.ConnString);
			SqlCommand command=new SqlCommand("select count(*) as recordnum from "
				+tableName,conn);
			SqlDataReader rd=null;
			conn.Open();
			rd=command.ExecuteReader();
			if(rd.Read())
			{
				recordNumber=Convert.ToInt32(rd["recordnum"]);
			}
			rd.Close();
			conn.Close();
			return recordNumber;
		}

	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -