using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using TopWinCMS.BLL;
using TopWinCMS.Common;
using TopWinCMS.Model;
public partial class Admin_Member_MemberRole : System.Web.UI.Page
{
    protected string strOperation = "";

    MemberRoleManage MyClassBLL = new MemberRoleManage();
    MemberRoleInfo model = new MemberRoleInfo();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            RightsCheck.CheckWorkPower("MM_1");

            string Action = Request["Action"];
            if (Action == null)
            {
                GV_List.EmptyDataTemplate=TopWinCMS.WebFactory.PageBase.GetTemplate(this);
                BindGrid();
                panel1.Visible = false;
            }
            else if (Action == "ReadOnly")
            {
                BT_Add.Visible = false;
                CB_ALL.Visible = false;
            }
            else if (Action == "Add")
            {
                GV_List.Visible = false;
                panel1.Visible = true;
                BT_Add.Text = "添加";
                LB_Path.Text = Config.SiteName + " →  <a href=\"Member_Role.aspx\">会员角色管理</a> → 添加角色";
            }
            else if (Action == "Edit")
            {
                GV_List.Visible = false;
                panel1.Visible = true;
                BT_Add.Text = "修改";
                LB_Path.Text = Config.SiteName + " →  <a href=\"Member_Role.aspx\">会员角色管理</a> → 修改角色";
            }
            if (Action != null)
            {
                if (Request["ID"] != null)
                {
                    model = MyClassBLL.EditLoad(Request["ID"]);

                    TB_RoleName.Text = model.RoleName;
                    NTB_Rank.Text = model.Rank;

                    strOperation = model.RolePower;
                }
                GetMemberPower();
            }
        }
    }
    private void BindGrid()
    {
        LB_Path.Text = Config.SiteName + " →  <a href=\"Member_Role.aspx\">会员角色管理</a> ";
        MyClassBLL.BindList(GV_List);
    }
    private void GetMemberPower()
    {
        DataList1.DataSource = new RightsManage().GetMemberPower();
        DataList1.DataBind();
    }
    protected DataSet BindMemberPower(object RootID)
    {
        return new RightsManage().BindMemberPower(RootID);
    }
    protected void BT_Add_Click(object sender, EventArgs e)
    {
        string str = Request.Form["chkOperation"];
        if (Request["Action"] == "Add")
        {
            model.RoleName = TB_RoleName.Text;
            model.RolePower = (string.IsNullOrEmpty(str) == true ? "" : str);
            model.Rank = NTB_Rank.Text;

            MyClassBLL.Add(model);
        }
        else if (Request["Action"] == "Edit")
        {
            model.ID = Request["ID"];
            model.RoleName = TB_RoleName.Text;
            model.RolePower = (string.IsNullOrEmpty(str) == true ? "" : str);
            model.Rank = NTB_Rank.Text;

            MyClassBLL.Edit(model);
        }
    }
 
    protected void GV_List_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType != DataControlRowType.DataRow)
        {
            return;
        }
        TableCell myTableCell;
        //定义对“删除”单元格的引用
        myTableCell = e.Row.Cells[6];
        //定义对“删除”单元格中控件的引用
        LinkButton btnDel = (LinkButton)myTableCell.Controls[0];
        //添加当单击时弹出确认对话框的自定义属性
        btnDel.Attributes.Add("onclick", "return confirm('您真的要删除吗？属于该角色的会员要一起删掉的哦！');");
    }
 

    protected void GV_List_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {

        model.ID = GV_List.DataKeys[e.RowIndex].Value.ToString();

        MyClassBLL.Delete(model);
    }

    protected void GV_List_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        this.GV_List.PageIndex = e.NewPageIndex;
        BindGrid();
    }

 
 
}