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;
using SK.MemberWeb.Controls;

namespace SK.MemberWeb.admin
{
	/// <summary>
	/// Payment_List 的摘要说明。
	/// </summary>
	public class Payment_List : BasePage
	{
		protected System.Web.UI.WebControls.Repeater lstPayment;
		protected Wuqi.Webdiyer.AspNetPager pager;
		PaymentSystem payment = new PaymentSystem();
		protected System.Web.UI.WebControls.Button btnDelete;
		RightMemberSystem rightmember = new RightMemberSystem();
	
		private void Page_Load(object sender, System.EventArgs e)
		{
			// 在此处放置用户代码以初始化页面
			btnDelete.Attributes["onclick"] = "return confirm('确认要删除选中的记录吗？');";
			if(!IsPostBack)
			{
				if(!rightmember.Allow(0,"Payment",this.CurrentMemberID))
					Response.Redirect("noright.aspx");

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

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

		}
		#endregion
		private void BindData()
		{
			pager.RecordCount = payment.List_Count();
			lstPayment.DataSource = payment.List(pager.PageSize,pager.CurrentPageIndex);
			lstPayment.DataBind();
		}

		private void lstPayment_ItemDataBound(object sender, System.Web.UI.WebControls.RepeaterItemEventArgs e)
		{
			if(e.Item.ItemType == ListItemType.AlternatingItem)
			{
				string info=String.Empty;
				DataRow dr = ((DataRowView)e.Item.DataItem).Row;
				if(dr["ProductID"]==DBNull.Value)
				{
					info+="购买积分<br>";
					info+=String.Format("{0}元，{1}个{2}",dr["v_amount"].ToString(),dr["PayPoint"].ToString(),Main.GetValue("PointName").ToString());
					((Label)e.Item.FindControl("lblAmountType_A")).Text = info;
				}
				else
				{
					info+=dr["ProductName"].ToString()+"包月<br>";
					info+=String.Format("{0}元，{1}个月",dr["v_amount"].ToString(),dr["PayMonth"].ToString());
					((Label)e.Item.FindControl("lblAmountType_A")).Text = info;
				}
				((Label)e.Item.FindControl("lblOperate_A")).Text = Convert.ToBoolean(dr["Operate"])?"<font color=blue>网银自动</font>":"<font color=red>手动续费</font>";
			}
			if(e.Item.ItemType == ListItemType.Item)
			{
				string info=String.Empty;
				DataRow dr = ((DataRowView)e.Item.DataItem).Row;
				if(dr["ProductID"]==DBNull.Value)
				{
					info+="购买积分<br>";
					info+=String.Format("{0}元，{1}个{2}",dr["v_amount"].ToString(),dr["PayPoint"].ToString(),Main.GetValue("PointName").ToString());
					((Label)e.Item.FindControl("lblAmountType_I")).Text = info;
				}
				else
				{
					info+=dr["ProductName"].ToString()+"包月<br>";
					info+=String.Format("{0}元，{1}个月",dr["v_amount"].ToString(),dr["PayMonth"].ToString());
					((Label)e.Item.FindControl("lblAmountType_I")).Text = info;
				}
				((Label)e.Item.FindControl("lblOperate_I")).Text = Convert.ToBoolean(dr["Operate"])?"<font color=blue>网银自动</font>":"<font color=red>手动续费</font>";
			}
		}

		private void btnDelete_Click(object sender, System.EventArgs e)
		{
			foreach(System.Web.UI.WebControls.RepeaterItem ri in lstPayment.Items)
			{
				if(ri.ItemType == ListItemType.AlternatingItem)
				{
					CheckBoxPlus del_a = (CheckBoxPlus)ri.FindControl("del_a");
					if(del_a.Checked)
						payment.Delete(del_a.CommandArgument);
				}
				if(ri.ItemType == ListItemType.Item)
				{
					CheckBoxPlus del_i = (CheckBoxPlus)ri.FindControl("del_i");
					if(del_i.Checked)
						payment.Delete(del_i.CommandArgument);
				}
			}
			BindData();
		}

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