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

📄 viewarticle.aspx.cs

📁 bolog
💻 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.Timers;
using System.Data.OleDb;
using System.Configuration;
using System.Threading;
using System.Globalization; 

namespace MyBlog
{
	/// <summary>
	/// viewArticle 的摘要说明。
	/// </summary>
	public partial class viewArticle : System.Web.UI.Page
	{
		protected System.Web.UI.WebControls.ImageButton ImageButton1;
		protected System.Web.UI.WebControls.TextBox TextBox1;

		public string Left(string strChar,int intLong)
		{
			string val = strChar;
			int lon = intLong;
			int len = val.Length;
			if(lon<len)
			{
				val = val.Substring(0,lon)+"...";
			}
			return val;
		}

		protected void Page_Load(object sender, System.EventArgs e)
		{
			// 在此处放置用户代码以初始化页面

			int year = DateTime.Now.Year;
			if(year == 2009)
				lbCopyright.Text = "Copyright (c) " + year + " ";
			else
				lbCopyright.Text = "Copyright (c) 2009-" + year + " ";

			String strConn = ConfigurationSettings.AppSettings["webblog"] + Server.MapPath("WebBlog.mdb");
			OleDbConnection cn = new OleDbConnection();
			cn.ConnectionString = strConn;

			OleDbCommand myCommand = new OleDbCommand("select * from contextInfo where contextID = '"+Request["contextID"]+"'", cn);
			OleDbDataReader MyReader;
			cn.Open();
			MyReader = myCommand.ExecuteReader();
			while(MyReader.Read())
			{
				lbTitle.Text = MyReader["title"].ToString();
				lbContent.Text = MyReader["content"].ToString();
				if(MyReader["imageUrl"].ToString() != "" && MyReader["imageUrl"].ToString() != null)
				{
					Image2.Visible = true;
					Image2.ImageUrl = "images\\" + MyReader["imageUrl"].ToString();
				}
				else
					Image2.Visible = false;
			}

			MyReader.Close();
			String s = Request["contextID"].ToString();
			if(Request["flag"] != "2")
			{
				myCommand.Parameters.Clear();
				myCommand.CommandText = "update contextInfo set viewCount = viewCount + 1 where contextID = '{"+Request["contextID"]+"}'";
				myCommand.ExecuteNonQuery();
			}

			OleDbDataAdapter myCommand3 = new OleDbDataAdapter("select TOP 10 contextID,title from contextInfo order by viewCount DESC,releaseTime DESC", cn);
			DataSet ds3 = new DataSet();
			myCommand3.Fill(ds3, "contextInfo3");
			dlTop.DataSource = ds3;
			dlTop.DataBind();

			OleDbDataAdapter myCommand5 = new OleDbDataAdapter("select TOP 10 contextID,comment from commentInfo order by releaseTime DESC", cn);
			DataSet ds5 = new DataSet();
			myCommand5.Fill(ds5, "commentInfo");
			dlTopComment.DataSource = ds5;
			dlTopComment.DataBind();

			OleDbDataAdapter myCommand6 = new OleDbDataAdapter("select * from link", cn);
			DataSet ds6 = new DataSet();
			myCommand6.Fill(ds6, "link");
			dlLink.DataSource = ds6;
			dlLink.DataBind();

			cn.Close();
			
			OleDbDataAdapter myAdapter = new OleDbDataAdapter("select * from commentInfo where contextID = '"+Request["contextID"]+"'", cn);
			DataSet ds = new DataSet();
			myAdapter.Fill(ds, "commentInfo");

			commentDataGrid.DataSource = ds.Tables["commentInfo"].DefaultView;
			commentDataGrid.DataBind();


		}

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

		}
		#endregion

		protected void btSubmit_Click(object sender, System.EventArgs e)
		{
			String insertCmd = "insert into commentInfo(comment, releaseTime, author, email, contextID) values(@comment, @releaseTime, @contextID, @author, @email)";
			String strConn = ConfigurationSettings.AppSettings["webblog"] + Server.MapPath("WebBlog.mdb");
			OleDbConnection cn = new OleDbConnection();
			cn.ConnectionString = strConn;

			OleDbCommand myCommand = new OleDbCommand(insertCmd, cn);
			myCommand.Parameters.Add(new OleDbParameter("@comment", OleDbType.VarChar, 65535));
			myCommand.Parameters["@comment"].Value = tbComment.Text;
			myCommand.Parameters.Add(new OleDbParameter("@releaseTime", OleDbType.VarChar, 50));
			myCommand.Parameters["@releaseTime"].Value = DateTime.Now.ToString();;
			myCommand.Parameters.Add(new OleDbParameter("@author", OleDbType.VarChar, 50));
			myCommand.Parameters["@author"].Value = tbAuthor.Text;
			myCommand.Parameters.Add(new OleDbParameter("@email", OleDbType.VarChar, 50));
			myCommand.Parameters["@email"].Value = tbEmail.Text;
			myCommand.Parameters.Add(new OleDbParameter("@contextID", OleDbType.VarChar, 38));
			String s = Request["contextID"].ToString().ToString();
			myCommand.Parameters["@contextID"].Value = Request["contextID"].ToString().ToUpper();
			cn.Open();
			try
			{
				myCommand.ExecuteNonQuery();
				//Response.Redirect("index.aspx");
			}
			catch(System.Data.OleDb.OleDbException)
			{
			}

			myCommand.Parameters.Clear();
			myCommand.CommandText = "update contextInfo set commentCount = commentCount + 1 where contextID = '{"+Request["contextID"]+"}'";
			myCommand.ExecuteNonQuery();

			myCommand.Parameters.Clear();
			myCommand.CommandText = "select * from contextInfo where contextID = '"+Request["contextID"]+"'";
			OleDbDataReader MyReader;
			MyReader = myCommand.ExecuteReader();
			while(MyReader.Read())
			{
				lbTitle.Text = MyReader["title"].ToString();
				lbContent.Text = MyReader["content"].ToString();
			}

			MyReader.Close();

			OleDbDataAdapter myAdapter = new OleDbDataAdapter("select * from commentInfo where contextID = '"+Request["contextID"]+"'", cn);
			DataSet ds = new DataSet();
			myAdapter.Fill(ds, "commentInfo");

			commentDataGrid.DataSource = ds.Tables["commentInfo"].DefaultView;
			commentDataGrid.DataBind();

			cn.Close();
			
		}

		protected void btReset_Click(object sender, System.EventArgs e)
		{
			tbComment.Text = "";
			tbAuthor.Text = "";
			tbEmail.Text = "";
			tbPassword.Text = "";
		}

		private void Calendar2_DayRender(object sender, System.Web.UI.WebControls.DayRenderEventArgs e)
		{
			if (e.Day.IsOtherMonth)
				e.Cell.Controls.Clear();
		}

		protected void Calendar2_PreRender(object sender, System.EventArgs e)
		{
			Thread threadCurrent = Thread.CurrentThread;
 			CultureInfo ciNew = (CultureInfo)threadCurrent.CurrentCulture.Clone();
 			ciNew.DateTimeFormat.DayNames = new string[]{"日", "一", "二", "三", "四", "五", "六"};
 			ciNew.DateTimeFormat.FirstDayOfWeek = DayOfWeek.Sunday;
 			threadCurrent.CurrentCulture = ciNew;
		}

		protected void lbtLife_Click(object sender, System.EventArgs e)
		{
			Session["cat"] = 1;
			Response.Redirect("index.aspx");
		}

		protected void lbtIndex_Click(object sender, System.EventArgs e)
		{
			Session["cat"] = 0;
			Response.Redirect("index.aspx");
		}

		protected void lbtTec_Click(object sender, System.EventArgs e)
		{
			Session["cat"] = 2;
			Response.Redirect("index.aspx");
		}

		protected void lbtYuan_Click(object sender, System.EventArgs e)
		{
			Session["cat"] = 3;
			Response.Redirect("index.aspx");
		}

	}
}

⌨️ 快捷键说明

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