view.aspx.cs

来自「asp做的新闻系统」· CS 代码 · 共 170 行

CS
170
字号
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Data.OleDb;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

namespace Web.Forum
{
	/// <summary>
	/// View 的摘要说明。
	/// </summary>
	public class View : System.Web.UI.Page
	{
	
		public Web.DataAccess.DataAccess Das = new DataAccess.DataAccess();
		public string m_strTitle,m_strContent,m_strUserName,m_strPostDate,strForumName;
		public int nForumID,nBoardID;

		protected System.Web.UI.HtmlControls.HtmlTable Table4;
		protected System.Web.UI.WebControls.Button BtnCancel;
		protected System.Web.UI.WebControls.Button BtnSave;
		protected System.Web.UI.WebControls.TextBox TxtContent;
		protected System.Web.UI.HtmlControls.HtmlTable Table1;

		private void Page_Load(object sender, System.EventArgs e)
		{
			string strSql;
Session["UserName"] = "beyond";
			nBoardID =  int.Parse(Request["BoardID"].ToString());

			strSql = "select ForumID,title,content,username,postdate from forum where boardid=" + nBoardID;
			OleDbDataReader read = Das.GetDataReader(strSql);

			if(read.Read())
			{
				nForumID = int.Parse(read[0].ToString());
				switch(nForumID)
				{
					case 1:
						strForumName = "ASP.NET技术专题";
						break;
					case 2:
						strForumName = "C#.NET技术专题";
						break;
					case 3:
						strForumName = "VB.NET技术专题";
						break;
					case 4:
						strForumName = "VC++.NET技术专题";
						break;
					case 5:
						strForumName = "DOTNET书籍专区";
						break;
				}
				m_strTitle = read[1].ToString();
				m_strContent = read[2].ToString();
				m_strUserName = read[3].ToString();
				m_strPostDate = read[4].ToString();
			}

			read.Close();
		}

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

		}
		#endregion

		private void BtnSave_Click(object sender, System.EventArgs e)
		{
			string strSql,strContent;

			strContent = HTMLEncode(TxtContent.Text);

			strSql = "insert into Forum(ForumID,replyBoardID,content,username,postdate) values("
				+ nForumID + "," + nBoardID + ",'" + strContent + "','" + Session["UserName"].ToString() + "','" + DateTime.Now.ToString() + "')";

			if(Das.ExecSql(strSql))
			{
				Response.Write("<script language='javascript'>alert('保存成功!');</script>");
				TxtContent.Text = "";
			}
			else
				Response.Write("<script language='javascript'>alert('保存不成功,请重新保存!');</script>");
		}

		private string HTMLEncode(string str)
		{
			            
			str = str.Replace(">", "&gt;");			
			str = str.Replace("<", "&lt;");
			char ch;
			ch=(char)32;
			str = str.Replace(ch.ToString(), "&nbsp;");
			ch=(char)34;
			str = str.Replace(ch.ToString(), "&quot;");
			ch=(char)39;
			str = str.Replace(ch.ToString(), "&#39;");
			ch=(char)13;
			str = str.Replace(ch.ToString(), "");
			ch=(char)10;
			str = str.Replace(ch.ToString(), "<BR> ");

			return str;
		}

		private void BtnCancel_Click(object sender, System.EventArgs e)
		{
			TxtContent.Text = "";
		}

		public void Reply()
		{
			string strTitle,strContent,strUserName,strPostDate,strSql;

			strSql = "select title,content,username,postdate from forum where replyboardid=" + nBoardID;
			OleDbDataReader read = Das.GetDataReader(strSql);
			while(read.Read())
			{
				strTitle = read[0].ToString();
				strContent = read[1].ToString();
				strUserName = read[2].ToString();
				strPostDate = read[3].ToString();
						
				Response.Write("<TR>");
				Response.Write("<TD height='150' align='left' width='155' vAlign='top'>作者:" + strUserName);
				Response.Write("<br>发表时间:" + strPostDate);
				Response.Write("</TD>");
				Response.Write("<TD colSpan='3'>");
				Response.Write("<TABLE id='Table2' style='BORDER-RIGHT: 1px solid; BORDER-TOP: 1px solid; BORDER-LEFT: 1px solid; BORDER-BOTTOM: 1px solid; BORDER-COLLAPSE: collapse' borderColor='#dddddd' height='100%' cellSpacing='0' cellPadding='0' width='100%' align='center' bgColor='whitesmoke' borderColorLight='#dddddd' border='1' runat='server'>");
				Response.Write("<TR>");
				Response.Write("<TD align='right' width='80' vAlign='top'>回复:");
				Response.Write("</TD>");
				Response.Write("<TD colSpan='3' vAlign='top'>" + strContent);
				Response.Write("</TD>");
				Response.Write("</TR>");
				Response.Write("</TABLE>");
				Response.Write("</FONT>");
				Response.Write("</TD>");
				Response.Write("</TR>");
			}
		}

	}
}

⌨️ 快捷键说明

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