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;

public partial class admin_user_sys_role_member : Fm.Bussiness.BasePage
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            Bind();
        }
    }
    //绑定基本权限
    void Bind()
    {
        Fm.Bussiness.public_select ps = new Fm.Bussiness.public_select();
        //绑定个人信息操作权限
        List_private.DataSource = ps.Getps("Fm_member_menu","*","parent=1");
        List_private.DataValueField = "mid";
        List_private.DataTextField = "mname";
        List_private.DataBind();
        //绑定内容信息操作权限
        List_info.DataSource = ps.Getps("Fm_member_menu","*","parent=2");
        List_info.DataValueField = "mid";
        List_info.DataTextField = "mname";
        List_info.DataBind();

        //显示所拥有的权限
        if (Request.QueryString["r_id"] != null)
        {
            int rid = int.Parse(Request.QueryString["r_id"].ToString());
            Fm.Bussiness.member member = new Fm.Bussiness.member();
            DataView dv = member.member_menu("rid="+rid+"");
            foreach (DataRow row in dv.Table.Rows)
            {
                //个人信息
                if (row["mid"].ToString() == Check_private.ToolTip)
                {
                    Check_private.Checked = true;
                }
                foreach (ListItem item in List_private.Items)
                {
                    if (item.Value == row["mid"].ToString())
                    {
                        item.Selected = true;
                    }
                }
                //内容管理
                if (row["mid"].ToString() == Check_info.ToolTip)
                {
                    Check_info.Checked = true;
                }
                foreach (ListItem item in List_info.Items)
                {
                    if (item.Value == row["mid"].ToString())
                    {
                        item.Selected = true;
                    }
                }
            }
        }
    }
    protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
    {
        int rid = int.Parse(Request.QueryString["r_id"].ToString());

        //实例化权限操作类 
        Fm.Bussiness.member member = new Fm.Bussiness.member();
        //实例化实体类
        Fm.EntityClass.Member_power power = new Fm.EntityClass.Member_power();
        power.rid = rid;
        bool bo = false;
        //清除原有权限
        member.MemberPowerDel(power);

        //添加个人新管理权限
        foreach (ListItem item in List_private.Items)
        {
            if (item.Selected)
            {
                power.mid = int.Parse(item.Value);
                member.MemberPowerAdd(power);
               // Response.Write(power.mid);
                bo = true;
            }
        }
        if (bo)
        {
            power.mid = int.Parse(Check_private.ToolTip);
            member.MemberPowerAdd(power);
            bo = false;
        }
        //内容管理权限
        foreach (ListItem item in List_info.Items)
        {
            if (item.Selected)
            {
                power.mid = int.Parse(item.Value);
                member.MemberPowerAdd(power);
                bo = true;
            }
        }
        if (bo)
        {
            power.mid = int.Parse(Check_info.ToolTip);
            member.MemberPowerAdd(power);
            bo = false;
        }
        Response.Redirect("../Erro.aspx?eid=该角色权限信息修改成功!&url=user/sys_role_set.aspx",false);
    }
}
