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>
	/// Product_List 的摘要说明。
	/// </summary>
	public class Product_List : BasePage
	{
		protected System.Web.UI.WebControls.Repeater lstProduct;
		ProductSystem product = new ProductSystem();
		RightMemberSystem rightmember = new RightMemberSystem();
	
		private void Page_Load(object sender, System.EventArgs e)
		{
			// 在此处放置用户代码以初始化页面
			if(!IsPostBack)
			{
				if(!rightmember.Allow(0,"Payment",this.CurrentMemberID))
					Response.Redirect("noright.aspx");

				BindData();
			}
		}

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

		}
		#endregion
		protected void Delete_Load(object sender, System.EventArgs e)
		{
			((LinkButton)sender).Attributes["onclick"]="return confirm('您确定要删除这个站点吗？');";
		}
		private void BindData()
		{
			lstProduct.DataSource = product.List();
			lstProduct.DataBind();
		}

		private void lstProduct_ItemDataBound(object sender, System.Web.UI.WebControls.RepeaterItemEventArgs e)
		{
			if(e.Item.ItemType==ListItemType.AlternatingItem)
			{
				Label lblMonthly_A = (Label)e.Item.FindControl("lblMonthly_A");
				if(Convert.ToBoolean(((DataRowView)e.Item.DataItem).Row["AllowMonthly"]))
					lblMonthly_A.Text = String.Format("{0}元/月",((DataRowView)e.Item.DataItem).Row["MonthlyPayment"].ToString());
				else
				{
					lblMonthly_A.Text = "不允许包月";
					lblMonthly_A.ForeColor = Color.Red;
				}

			}
			if(e.Item.ItemType==ListItemType.Item)
			{
				Label lblMonthly_I = (Label)e.Item.FindControl("lblMonthly_I");
				if(Convert.ToBoolean(((DataRowView)e.Item.DataItem).Row["AllowMonthly"]))
					lblMonthly_I.Text = String.Format("{0}元/月",((DataRowView)e.Item.DataItem).Row["MonthlyPayment"].ToString());
				else
				{
					lblMonthly_I.Text = "不允许包月";
					lblMonthly_I.ForeColor = Color.Red;
				}
			}
		}

		private void lstProduct_ItemCommand(object source, System.Web.UI.WebControls.RepeaterCommandEventArgs e)
		{
			if(e.CommandName=="Delete")
			{
				product.Delete(e.CommandArgument);
			}
			Response.Redirect("Product_List.aspx");
		}
	}
}