namespace baoge
{
	using System;
	using System.Data;
	using System.Drawing;
	using System.Web;
	using System.Web.UI.WebControls;
	using System.Web.UI.HtmlControls;
    using System.Configuration;
    using System.Collections;
	using System.ComponentModel;
    using System.Web.SessionState;
	using System.Web.UI;
	using System.Data.OleDb;
	
	/// <summary>
	///		SY_DataListPic 的摘要说明。
	/// </summary>
	public class SY_DataListPic : System.Web.UI.UserControl
	{
		protected System.Web.UI.WebControls.HyperLink HyperLink1;
		protected System.Web.UI.WebControls.DataList DataList1;

		private void Page_Load(object sender, System.EventArgs e)
		{
			if(!this.IsPostBack)
			{

				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 top 7 * FROM Article where ispic=true order by ArticleID desc";
			
				OleDbDataAdapter da=new OleDbDataAdapter(mysql,connection);
				DataSet ds=new DataSet();
				da.Fill(ds,"Article");
				this.DataList1.DataSource = ds.Tables["Article"];
				this.DataList1.DataBind();
			}
		}


		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.Load += new System.EventHandler(this.Page_Load);

		}
		#endregion
	}
}
