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

📄 index.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.Data.OleDb;
using System.Configuration;
using System.Threading;
using System.Globalization; 

namespace MyBlog
{
	/// <summary>
	/// index 的摘要说明。
	/// </summary>
	public partial class index : System.Web.UI.Page
	{
		protected System.Web.UI.WebControls.Label laCopyright;
	
		private void BindGrid(System.Web.UI.WebControls.DataGrid DataGrid, String strValue, int flag)
		{
			String strConn = ConfigurationSettings.AppSettings["webblog"] + Server.MapPath("WebBlog.mdb");
			OleDbConnection cn = new OleDbConnection();
			cn.ConnectionString = strConn;

			OleDbDataAdapter myCommand = new OleDbDataAdapter(strValue, cn);
			DataSet ds = new DataSet();
			myCommand.Fill(ds, "contextInfo3");
			DataTable dt = ds.Tables["contextInfo3"].Clone();

			if(flag == 1)
				ds.Tables["contextInfo3"].DefaultView.RowFilter="categoryID = 1";
			if(flag == 2)
				ds.Tables["contextInfo3"].DefaultView.RowFilter="categoryID = 2";
			if(flag == 3)
				ds.Tables["contextInfo3"].DefaultView.RowFilter="categoryID = 3";
			DataGrid.DataSource = ds.Tables["contextInfo3"].DefaultView;
			DataGrid.DataBind();
			
		}
		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 + "";
			//	if(!IsPostBack)
			//	{
					String strValue = "select ct.contextID, ct.categoryID, ct.authorName, ct.releaseTime, ct.content, ct.commentCount, ct.viewCount, ct.title, cg.categoryName From contextInfo ct LEFT JOIN category cg ON ct.categoryID = cg.categoryID ORDER BY ct.releaseTime DESC"; //LEFT JOIN commentInfo cm ON ct.contextID = cm.contextID"; 
					if(Session["cat"].ToString() == "0")
						BindGrid(contextDataGrid, strValue, 0);
					else if(Session["cat"].ToString() == "1")
						BindGrid(contextDataGrid, strValue, 1);
					else if(Session["cat"].ToString() == "2")
						BindGrid(contextDataGrid, strValue, 2);
					else
						BindGrid(contextDataGrid, strValue, 3);
					String strConn = ConfigurationSettings.AppSettings["webblog"] + Server.MapPath("WebBlog.mdb");
					OleDbConnection cn = new OleDbConnection();
					cn.ConnectionString = strConn;

					cn.Open();
					OleDbDataAdapter myCommand = new OleDbDataAdapter("select TOP 10 contextID,title from contextInfo order by viewCount DESC,releaseTime DESC", cn);
					DataSet ds = new DataSet();
					myCommand.Fill(ds, "contextInfo3");
					dlTop.DataSource = ds.Tables["contextInfo3"].DefaultView;
					dlTop.DataBind();

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

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

					cn.Close();

			//	}
			


			//Label s = (Label)contextDataGrid.Controls[0];
			//s.Text = "po";
			//((TextBox)(e.Item.Controls["yourTextBoxId"])).Text
		/*	String strConn = ConfigurationSettings.AppSettings["webblog"] + Server.MapPath("WebBlog.mdb");
			OleDbConnection cn = new OleDbConnection();
			cn.ConnectionString = strConn;

			cn.Open();
			OleDbDataAdapter myCommand = new OleDbDataAdapter("select TOP 3 contextID,title from contextInfo order by viewCount DESC", cn);
			DataSet ds = new DataSet();
			myCommand.Fill(ds, "contextInfo3");
			dlTop.DataSource = ds;
			dlTop.DataBind();

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

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

			cn.Close();*/
		}


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

		}
		#endregion

		private void contextDataGrid_PageIndexChanged(object source, System.Web.UI.WebControls.DataGridPageChangedEventArgs e)
		{
			contextDataGrid.CurrentPageIndex = e.NewPageIndex;
			String strValue = "select ct.contextID, ct.categoryID, ct.authorName, ct.releaseTime, ct.content, ct.commentCount, ct.viewCount, ct.title, cg.categoryName From contextInfo ct LEFT JOIN category cg ON ct.categoryID = cg.categoryID ORDER BY ct.releaseTime DESC"; 
			BindGrid(contextDataGrid, strValue, 0);
		}

		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 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;
		}

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


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

		protected void lbtLife_Click(object sender, System.EventArgs e)
		{
			Session["cat"] = 1;
			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");
		}

		private void ImageButton1_Click(object sender, System.Web.UI.ImageClickEventArgs e)
		{
			String strValue = "select ct.contextID, ct.categoryID, ct.authorName, ct.releaseTime, ct.content, ct.commentCount, ct.viewCount, ct.title, cg.categoryName From contextInfo ct LEFT JOIN category cg ON ct.categoryID = cg.categoryID ORDER BY ct.releaseTime DESC"; //LEFT JOIN commentInfo cm ON ct.contextID = cm.contextID"; 
			String strConn = ConfigurationSettings.AppSettings["webblog"] + Server.MapPath("WebBlog.mdb");
			OleDbConnection cn = new OleDbConnection();
			cn.ConnectionString = strConn;

			OleDbDataAdapter myCommand = new OleDbDataAdapter(strValue, cn);
			DataSet ds = new DataSet();
			myCommand.Fill(ds, "contextInfo3");
			DataTable dt = ds.Tables["contextInfo3"].Clone();

			ds.Tables["contextInfo3"].DefaultView.RowFilter="title like '%" + tbSearch.Text + "%'";
			contextDataGrid.DataSource = ds.Tables["contextInfo3"].DefaultView;
			contextDataGrid.DataBind();
		}
	}
}

⌨️ 快捷键说明

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