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

📄 content_view.aspx.cs

📁 具有一般blog的相册、文章、作品等功能程序结构也比较清晰采用三层结构开发(利用了SQLHelper.cs(源码))采用了UrlReWrite技术后台采用FTB(FreeTextBox)编辑器
💻 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 liuwei.FrameWork.Providers;
using liuwei.FrameWork.DB;
using liuwei.FrameWork;

namespace liuwei
{
	/// <summary>
	/// content_view 的摘要说明。
	/// </summary>
	public class content_view : System.Web.UI.Page
	{
		protected System.Web.UI.WebControls.Literal lbContent;
		protected System.Web.UI.WebControls.Literal lbPubTime;
		protected System.Web.UI.WebControls.Literal lbViewCount;
		protected System.Web.UI.WebControls.Literal lbTitle;
		protected System.Web.UI.WebControls.Literal lbTitle1;
		protected System.Web.UI.WebControls.Literal lbComment;
		protected System.Web.UI.WebControls.Literal lbMoreComment;
		protected System.Web.UI.WebControls.TextBox tbCommenter;
		protected System.Web.UI.WebControls.TextBox tbCommentUrl;
		protected System.Web.UI.WebControls.CheckBox cbRemember;
		protected System.Web.UI.WebControls.TextBox tbComment;
		protected System.Web.UI.WebControls.Button btnSubmit;
		protected System.Web.UI.WebControls.TextBox tbCommentTitle;
		protected System.Web.UI.WebControls.RequiredFieldValidator rfvTitle;
		protected System.Web.UI.WebControls.RequiredFieldValidator rfvName;
		protected System.Web.UI.WebControls.RequiredFieldValidator rfvComment;
		protected System.Web.UI.WebControls.Panel PanelComment;
		private int postID;
		private void Page_Load(object sender, System.EventArgs e)
		{
			// 在此处放置用户代码以初始化页面
			postID = Convert.ToInt32("" + Request.QueryString["postID"]);

			ContentViewProviders contentView = DbFormater.Instance().GetContentView(postID);
			lbTitle.Text = contentView.Title;
			lbTitle1.Text = contentView.Title;
			lbContent.Text = contentView.Content;
			lbPubTime.Text = contentView.PubTime.ToString("yy/MM/dd HH:mm");
			lbViewCount.Text = contentView.ViewCount.ToString();


			//评论
			if (contentView.AllowComment==true)
			{
				//re title
				tbCommentTitle.Text = "Re:" + contentView.Title;

				//more comments
				lbMoreComment.Text = "<ul><li><a href=\"comment," + contentView.PostID.ToString() + ".aspx\">More Comments(<strong>" + contentView.CommentCount.ToString() + "</strong>)</a></li></ul>";

				DataTable dt = DbProvider.Instance().GetCommentTop5(postID);

				lbComment.Text = "<ul>\n";
				if (dt.Rows.Count>0)
				{
					int counter=0;
					string remove="";
					while (counter < dt.Rows.Count)
					{
						if (HttpContext.Current.User.Identity.IsAuthenticated)
						{
							remove = "<a onclick=\"return confirm('are you sure?')\" href=\"admin/delcomment.aspx?commentid=" + dt.Rows[counter]["CommentID"] + "\">Remove</a>";
						}
						if (dt.Rows[counter]["CommenterUrl"].ToString()!="")
						{
							lbComment.Text += "<li><h5>" + dt.Rows[counter]["CommentTitle"].ToString() + "&nbsp;&nbsp;<a href=\"" + dt.Rows[counter]["CommenterUrl"].ToString() + "\" target=\"_blank\">" + dt.Rows[counter]["Commenter"].ToString() + "</a>&nbsp;<span class=\"timefont\">(" + dt.Rows[counter]["PubTime"].ToString() + ")</span> " + remove + "</h5>" + dt.Rows[counter]["Comment"].ToString() + "</li>\n";
					
						}
						else
						{
							lbComment.Text += "<li><h5>" + dt.Rows[counter]["CommentTitle"].ToString() + "&nbsp;&nbsp;" + dt.Rows[counter]["Commenter"].ToString() + "&nbsp;<span class=\"timefont\">(" + dt.Rows[counter]["PubTime"].ToString() + ")</span> " + remove + "</h5>" + dt.Rows[counter]["Comment"].ToString() + "</li>\n";
						}

						counter++;
					}
				}
				else
				{
					lbComment.Text+="<li>No comments posted yet.</li>";
				}
				lbComment.Text += "</ul>";
				dt.Clear();
				dt.Dispose();
				dt.Clear();
				dt.Dispose();

				if (!Page.IsPostBack)
				{
					//如果有cookies记录评论者
					HttpCookie user = Request.Cookies["CommentUser"];
					if(user != null)
					{
						tbCommenter.Text = user.Values["Name"];
						tbCommentUrl.Text = user.Values["Url"];
					}
				}
			}
			//不显示评论
			else
			{
				PanelComment.Visible=false;
			}
		}

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

		}
		#endregion

		private void btnSubmit_Click(object sender, System.EventArgs e)
		{
			if(Page.IsValid)
			{
				try
				{
					DbProvider.Instance().AddComment(postID,Common.SafeFormat(tbCommentTitle.Text),Common.SafeFormatWithUrl(tbComment.Text),Common.SafeFormat(tbCommenter.Text),Common.CheckForUrl(tbCommentUrl.Text),Common.GetUserIpAddress(Context));
					if(cbRemember.Checked)
					{
						HttpCookie user = new HttpCookie("CommentUser");
						user.Values["Name"] = tbCommenter.Text;
						user.Values["Url"] = tbCommentUrl.Text;
						user.Expires = DateTime.Now.AddDays(30);
						Response.Cookies.Add(user);
					}
					Response.Redirect ("Content," + Request.QueryString["Year"] + "," + Request.QueryString["Month"] + "," + Request.QueryString["Day"] + "," + postID + ".aspx#bottom");
				}
				catch
				{}
			}
		}
	}
}

⌨️ 快捷键说明

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