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>
	/// RightEdit 的摘要说明。
	/// </summary>
	public class RightEdit : BasePage
	{
		protected System.Web.UI.WebControls.Label lblRightName;
		protected System.Web.UI.WebControls.ListBox lstHasRight;
		protected System.Web.UI.WebControls.HyperLink lnkLeftAll;
		protected System.Web.UI.WebControls.HyperLink lnkRightAll;
		protected System.Web.UI.WebControls.HyperLink lnkLeft;
		protected System.Web.UI.WebControls.HyperLink lnkRight;
		protected System.Web.UI.WebControls.ListBox lstNoRight;
		protected Sorke.ListTransfer ListTransfer1;
		protected System.Web.UI.WebControls.Button btnSave;
		RightSystem right = new RightSystem();
		RightMemberSystem rightmember = new RightMemberSystem();
	
		private void Page_Load(object sender, System.EventArgs e)
		{
			// 在此处放置用户代码以初始化页面
			lnkRight.Attributes["onclick"] = ListTransfer1.ClientMoveSelected;
			lnkLeft.Attributes["onclick"] = ListTransfer1.ClientMoveBackSelected;
			lnkRightAll.Attributes["onclick"] = ListTransfer1.ClientMoveAll;
			lnkLeftAll.Attributes["onclick"] = ListTransfer1.ClientMoveBackAll;

			if(!IsPostBack)
			{
				if(!rightmember.Allow(0,"Right",this.CurrentMemberID))
					Response.Redirect("noright.aspx");

				ViewState["RightID"] = Request.QueryString["id"];
				BindData();
			}
		}

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

		}
		#endregion
		private void BindData()
		{
			DataRow dr = right.Info(ViewState["RightID"]);
			lblRightName.Text = dr["RightName"].ToString();

			lstHasRight.DataSource = rightmember.List(ViewState["RightID"],true);
			lstHasRight.DataTextField = "MemberName";
			lstHasRight.DataValueField = "MemberID";
			lstHasRight.DataBind();

			lstNoRight.DataSource = rightmember.List(ViewState["RightID"],false);
			lstNoRight.DataTextField = "MemberName";
			lstNoRight.DataValueField = "MemberID";
			lstNoRight.DataBind();
		}

		private void btnSave_Click(object sender, System.EventArgs e)
		{
			rightmember.Delete(ViewState["RightID"]);
			foreach(ListItem li in lstHasRight.Items)
			{
				rightmember.Add(ViewState["RightID"],li.Value);
			}
			Response.Redirect("rights.aspx");
		}
	}
}
