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.Text;
using System.IO;
namespace baoge.Admin
{
	/// <summary>
	/// Admin_ListPhoto 的摘要说明。
	/// </summary>
	public class Admin_ListPhoto : System.Web.UI.Page
	{
		protected System.Web.UI.WebControls.DataGrid NewsGrid;
		protected Wuqi.Webdiyer.AspNetPager haha;
	
		private void Page_Load(object sender, System.EventArgs e)
		{
			if(Session["AdminName"]==null)
			{
				Response.Redirect("Admin_Login.aspx");
			}
			if(!this.IsPostBack)
			{
				OleDbConnection objConnection=new OleDbConnection ("provider=Microsoft.jet.OLEDB.4.0;data Source="+Server.MapPath("../DataBase/DataBase.mdb")+";");
				OleDbCommand objCommand=new OleDbCommand("select count(*) from photo",objConnection);
				objConnection.Open();
				haha.RecordCount=(int)objCommand.ExecuteScalar();
				objConnection.Close();
				BindGrid();

			}
		}


		protected void BindGrid()
		{
		
			//取得数据库路径
			string dbPath=System.Configuration.ConfigurationSettings.AppSettings["dbPath"];
			//定义数据库连接字符串
			string ACconnStr="Provider=Microsoft.Jet.OleDb.4.0;Data Source="+Server.MapPath(dbPath);
			//创建数据库连接对像
			OleDbConnection ACconn=new OleDbConnection(ACconnStr);
			ACconn.Open();
			//定义SQL语句
			string ACsql="select * from photo order by Soft_ID desc";
			//定义数据适配器
			OleDbDataAdapter ACda=new OleDbDataAdapter(ACsql,ACconn);
			//创建数据集
			DataSet ACds=new DataSet();
			//从指定的索引开始取PageSize条记录
			ACda.Fill(ACds,haha.PageSize*(haha.CurrentPageIndex-1),haha.PageSize,"CurDataTable");
			//			ACda.Fill(ACds,"CurDataTable");
			//创建所有数集
			ACda.Fill(ACds,"AllDataTable");
			//设置DataGrid控件实际显示的项数
			NewsGrid.VirtualItemCount=ACds.Tables["AllDataTable"].Rows.Count;
			//数据绑定
			NewsGrid.DataSource=ACds.Tables["CurDataTable"];
			NewsGrid.DataBind();
			haha.CustomInfoText=" 共有留言<font color=\"blue\"><b>"+haha.RecordCount.ToString()+"</b></font>条";
			haha.CustomInfoText+=" 共有<font color=\"blue\"><b>"+haha.PageCount.ToString()+"</b></font>页";
			haha.CustomInfoText+=" 当前为第<font color=\"red\"><b>"+haha.CurrentPageIndex.ToString()+"</b></font>页";
			ACda.Dispose();
			ACconn.Close();

		}


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

		}
		#endregion

		private void haha_PageChanged(object src, Wuqi.Webdiyer.PageChangedEventArgs e)
		{
			haha.CurrentPageIndex=e.NewPageIndex;
			this.BindGrid();
		}
	}
}
