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;
namespace baoge
{
	/// <summary>
	/// listClassPic 的摘要说明。
	/// </summary>
	public class listClassPic : System.Web.UI.Page
	{
		protected System.Web.UI.WebControls.DataList DataList1;
		protected System.Web.UI.WebControls.Label Label1;
		protected System.Web.UI.WebControls.Label Label2;
		protected System.Web.UI.WebControls.Label Label3;
		protected System.Web.UI.WebControls.Button Button3;
		protected System.Web.UI.WebControls.Button Button1;
		protected System.Web.UI.WebControls.Button Button2;
		protected System.Web.UI.WebControls.Button Button4;
		protected System.Web.UI.WebControls.TextBox TextBox1;
		protected System.Web.UI.WebControls.Button Button5;
	
		private void Page_Load(object sender, System.EventArgs e)
		{
			if(!this.IsPostBack)
			{
				this.Label2.Text="1";
				this.databind();
				this.TextBox1.Text="1";
			}
		}


		private void databind()
		{
			int classID=Convert.ToInt32(Request.QueryString["classID"]);
			int CID=Convert.ToInt32(Request.QueryString["id"]);
			int curPage=Convert.ToInt32(this.Label2.Text);
			string dbPath=System.Configuration.ConfigurationSettings.AppSettings["dbPath"];
			//定义连接字符串
			string ConnStr="Provider=Microsoft.Jet.OleDb.4.0;Data Source="+Server.MapPath(dbPath);
			//创建数据库对像
			OleDbConnection connection=new OleDbConnection(ConnStr);

			String mysql="SELECT * FROM Article where ispic=true and ChannelID="+CID+" and ClassID="+classID+" order by ArticleID desc";
			//			String mysql="SELECT * FROM Article where ispic=true order by ArticleID desc";
			OleDbDataAdapter sda=new OleDbDataAdapter(mysql,connection);


			
			//			sda.SelectCommand=new SqlCommand("select * from employees",con);
			DataSet ds=new DataSet();
			sda.Fill(ds,"Article");
			System.Web.UI.WebControls.PagedDataSource ps=new PagedDataSource();
			ps.DataSource=ds.Tables["Article"].DefaultView;
			ps.AllowPaging=true;
			ps.PageSize=15;
			ps.CurrentPageIndex=curPage-1;
			this.Button1.Enabled=true;
			this.Button2.Enabled=true;
			
			if(curPage==1)
			{
				this.Button1.Enabled=false;
			}
			if(curPage==ps.PageCount)
			{
				this.Button2.Enabled=false;
			}
			
			
			this.DataList1.DataSource=ps;
			this.DataList1.DataBind();
			this.Label3.Text=Convert.ToString(ps.PageCount);
		}


		public string CutLen(string str, int Length)
		{
			int i = 0, j = 0;

			foreach(char Char in str)
			{
				if((int)Char > 127)
					i += 2;
				else
					i ++;

				if(i > Length)
				{
					str = str.Substring(0, j - 2) + "...";
					break;
				}
				j ++;
			}
			return str;
		} 

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

		}
		#endregion

		private void Button1_Click(object sender, System.EventArgs e)
		{
			this.Label2.Text=Convert.ToString(Convert.ToInt32(this.Label2.Text)-1);
			this.databind();
		}

		private void Button2_Click(object sender, System.EventArgs e)
		{
			this.Label2.Text=Convert.ToString(Convert.ToInt32(this.Label2.Text)+1);
			this.databind();
		}

		private void Button3_Click(object sender, System.EventArgs e)
		{
			this.Label2.Text="1";
			this.databind();
		}

		private void Button4_Click(object sender, System.EventArgs e)
		{
			this.Label2.Text=Convert.ToString(Convert.ToInt32(this.Label3.Text));
			this.databind();
		}

		private void Button5_Click(object sender, System.EventArgs e)
		{
			if(this.TextBox1.Text.ToString()=="0")
			{
				this.Label2.Text="1";
				this.databind();
			}
			else if(this.TextBox1.Text.ToString()=="")
			{
				this.Label2.Text="1";
				this.databind();
			}
		  
			else
			{
				this.Label2.Text=Convert.ToString(this.TextBox1.Text);
				this.databind();
			}
		}
	}
}
