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 SK.MemberBLL;

namespace SK.MemberWeb.admin
{
	/// <summary>
	/// WebLogs 的摘要说明。
	/// </summary>
	public class WebLogs : BasePage
	{
		protected System.Web.UI.WebControls.Repeater lstWeblog;
		protected Wuqi.Webdiyer.AspNetPager pager;
		protected System.Web.UI.WebControls.DropDownList dpWebLogType;
		protected System.Web.UI.WebControls.Button btnDelete;
		WebLogSystem log = new WebLogSystem();
		RightMemberSystem rightmember = new RightMemberSystem();
	
		private void Page_Load(object sender, System.EventArgs e)
		{
			// 在此处放置用户代码以初始化页面
			if(!IsPostBack)
			{
				if(!rightmember.Allow(0,"WebLog",this.CurrentMemberID))
					Response.Redirect("noright.aspx");

				pager.PageSize = Convert.ToInt32(Main.GetValue("PageSize_WebLog"));
				BindDrop();
				BindData();
			}
		}

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

		}
		#endregion
		protected void Delete_Load(object sender, System.EventArgs e)
		{
			((LinkButton)sender).Attributes["onclick"]="return confirm('您确定要删除这个日志吗？');";
		}
		public string ShowType(object LogType)
		{
			string str = "";
			switch(Convert.ToInt32(LogType))
			{
				case 0:
					str = "添加记录";
					break;
				case 1:
					str = "删除记录";
					break;
				case 2:
					str = "修改记录";
					break;
				case 3:
					str = "安全问题";
					break;
				case 4:
					str = "帐务记录";
					break;
			}
			return str;
		}
		private void BindDrop()
		{
			dpWebLogType.Items.Add(new ListItem("全部","-1"));
			dpWebLogType.Items.Add(new ListItem("添加记录","0"));
			dpWebLogType.Items.Add(new ListItem("删除记录","1"));
			dpWebLogType.Items.Add(new ListItem("修改记录","2"));
			dpWebLogType.Items.Add(new ListItem("安全问题","3"));
			dpWebLogType.Items.Add(new ListItem("帐务记录","4"));
		}
		private void BindData()
		{
			if(dpWebLogType.SelectedValue=="-1")
			{
				pager.RecordCount = log.List_Count();
				lstWeblog.DataSource = log.List(pager.PageSize,pager.CurrentPageIndex);
				lstWeblog.DataBind();
			}
			else
			{
				pager.RecordCount = log.ListofType_Count((WebLogType)Convert.ToInt32(dpWebLogType.SelectedValue));
				lstWeblog.DataSource = log.ListofType((WebLogType)Convert.ToInt32(dpWebLogType.SelectedValue),pager.PageSize,pager.CurrentPageIndex);
				lstWeblog.DataBind();
			}
		}

		private void dpWebLogType_SelectedIndexChanged(object sender, System.EventArgs e)
		{
			BindData();
		}

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

		private void btnDelete_Click(object sender, System.EventArgs e)
		{
			log.DeleteAll();
			Response.Redirect("WebLogs.aspx");
		}

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