namespace SK.MemberWeb.Templates.Default
{
	using System;
	using System.Data;
	using System.Drawing;
	using System.Web;
	using System.Web.UI.WebControls;
	using System.Web.UI.HtmlControls;
	using SK.MemberBLL;

	/// <summary>
	///		cu_Messages 的摘要说明。
	/// </summary>
	public class cu_Messages : BaseControl
	{
		protected SK.MemberWeb.Controls.ControlHolder ControlHolder4;
		protected SK.MemberWeb.Controls.ControlHolder ControlHolder6;
		protected SK.MemberWeb.Controls.ControlHolder ControlHolder5;
		protected SK.MemberWeb.Controls.ControlHolder ControlHolder7;
		protected Wuqi.Webdiyer.AspNetPager pager;
		protected System.Web.UI.WebControls.Repeater lstMsg;
		MessageSystem msg = new MessageSystem();

		private void Page_Load(object sender, System.EventArgs e)
		{
			// 在此处放置用户代码以初始化页面
			if(!IsPostBack)
			{
				pager.PageSize = Convert.ToInt32(Main.GetValue("PageSize_MessageList"));
				BindData();
			}
		}

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

		}
		#endregion
		private void BindData()
		{
			lstMsg.DataSource = msg.List(this.CurrentMemberID,pager.PageSize,pager.CurrentPageIndex);
			lstMsg.DataBind();
		}

		private void lstMsg_ItemCommand(object source, System.Web.UI.WebControls.RepeaterCommandEventArgs e)
		{
			if(e.CommandName=="Delete")
			{
				msg.Delete(e.CommandArgument);
			}
			BindData();
		}

		private void pager_PageChanged(object src, Wuqi.Webdiyer.PageChangedEventArgs e)
		{
			pager.CurrentPageIndex = e.NewPageIndex;
			BindData();
		}

		private void lstMsg_ItemDataBound(object sender, System.Web.UI.WebControls.RepeaterItemEventArgs e)
		{
			if(e.Item.ItemType==ListItemType.AlternatingItem || e.Item.ItemType==ListItemType.Item)
			{
				((LinkButton)e.Item.FindControl("del")).Attributes["onclick"] = "return confirm('确认要删除这条消息吗？');";
			}
		}
	}
}
