using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.OleDb;
using System.Text;
public partial class BackCenter_Role_RolePower : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        #region 过期和权限

        PageFunc.IfLogin(this.Page);
        //PubPageFunc.PageHavePurview(this.Page, "2001");

        #endregion
        if (!IsPostBack)
        {
            //BindPower();
        }
    }
    //#region 绑定权限设置
    //protected void BindPower()
    //{
    //    string sql_SelectFirst = string.Empty;
    //    if (Session["Account"].ToString() == "admin")//admin能选择全部
    //    {
    //        //Id栏目ID ClassId父栏目ID Name栏目名称
    //        //查询创建角色权限列表
    //        sql_SelectFirst = "select [id],[CreateClassId],[Classname] from NT_Class ";
    //    }
    //    else
    //    {

    //        //Id栏目ID ClassId父栏目ID Name栏目名称
    //        //查询创建角色权限列表
    //        sql_SelectFirst = string.Format("select a.id,a.CreateClassId,a.classname from ");
    //        sql_SelectFirst += string.Format("  NT_Class as a, NT_RoleClass as b ,NT_Role as c ");
    //        sql_SelectFirst += string.Format(" where a.id=b.classid and b.roleid=c.createroleid and c.id={0}", Request.QueryString["id"]);
    //    }
    //    this.tr_power.Nodes.Clear();
    //    DataSet ds = DbHelperOleDb.ExecuteDataSet(CommandType.Text, sql_SelectFirst, null);

    //    //查询已配置栏目列表
    //    string sql_SelectSeconed = string.Format("select id,classid,roleid from ");
    //    sql_SelectSeconed += string.Format("  NT_RoleClass ");
    //    sql_SelectSeconed += string.Format(" where roleid={0}", Request.QueryString["id"]);
    //    DataSet dsSelect = DbHelperOleDb.ExecuteDataSet(CommandType.Text, sql_SelectSeconed, null);
    //    ds.Tables[0].Columns.Add("checked");
    //    foreach (DataRow dr in ds.Tables[0].Rows)
    //    {
    //        dr["checked"] = 0;
    //        if (dsSelect.Tables[0].Select(string.Format("classid={0}", dr["id"])).Length > 0)
    //        {
    //            dr["checked"] = 1;
    //        }
    //    }
    //    DataView dv = new DataView(ds.Tables[0]);
    //    //取根栏目
    //    dv.RowFilter = "CreateClassId=0";

    //    foreach (DataRowView drv in dv)
    //    {
    //        TreeNode node = new TreeNode();
    //        node.Text = drv["className"].ToString();
    //        node.Value = drv["Id"].ToString();
    //        if (Convert.ToInt16(drv["checked"]) == 1)
    //        {
    //            node.Checked = true;
    //        }
    //        node.Target = "mainFrame";
    //        node.NavigateUrl = "javascript:;";
    //        this.tr_power.Nodes.Add(node);
    //        AddChildNode(ds.Tables[0], node);
    //    }
    //}
    //#endregion

    //#region 递归以实现无限级树
    //private void AddChildNode(DataTable dt, TreeNode node)
    //{
    //    DataView dv = new DataView(dt);//建立dt的表视图
    //    dv.RowFilter = "CreateClassId = " + node.Value + ""; //过滤
    //    foreach (DataRowView drv1 in dv)
    //    {
    //        TreeNode ChildNode = new TreeNode();
    //        ChildNode.Text = drv1["className"].ToString();
    //        ChildNode.Value = drv1["Id"].ToString();
    //        if (Convert.ToInt16(drv1["checked"]) == 1)
    //        {
    //            ChildNode.Checked = true;
    //        }

    //        ChildNode.Target = "mainFrame";
    //        ChildNode.NavigateUrl = "javascript:;";
    //        ChildNode.Expanded = true;//展开属性为FALSE
    //        node.ChildNodes.Add(ChildNode);
    //        AddChildNode(dt, ChildNode);
    //    }
    //}
    //#endregion

    //#region 用户组权限绑定(递归写入数据库)
    //protected void PowerSave(TreeNodeCollection nodes)
    //{
    //    string[] strSqlList = new string[1];
    //    strSqlList[0] = string.Format("delete from NT_RoleClass where RoleId={0}", Request.QueryString["id"]);

    //    foreach (TreeNode node in nodes)
    //    {

    //        StringBuilder strSql = new StringBuilder();
    //        strSql.Append("insert into NT_RoleClass (");
    //        strSql.Append("RoleId,ClassId) values");
    //        strSql.Append("(" + Request.QueryString["id"] + "," + node.Value + ")");

    //        strSqlList = StringFunc.ArrayAddItem(strSqlList, strSql.ToString());
    //    }
    //    DbHelperOleDb.ExecuteSqlTran(strSqlList);
    //    JavaScriptFunc.AlertAndRedirect(this.Page, "配置成功", "RoleIndex.aspx?ClassId=" + Request["ClassId"] + "");
    //}
    //#endregion

    #region 绑定权限设置
    protected void BindPower()
    {
        string sql_SelectFirst = string.Empty;
        if (Session["Account"].ToString() == "Admin")//Admin能选择全部
        {
            //Id栏目ID ClassId父栏目ID Name栏目名称
            //查询创建角色权限列表
            sql_SelectFirst += "select [id],[CreateClassId],[ClassName] from NT_Class";
        }
        else
        {
            //Id栏目ID ClassId父栏目ID Name栏目名称
            //查询创建角色权限列表
            sql_SelectFirst=string.Format("select a.id,a.CreateClassId,ClassName from ");
            sql_SelectFirst += string.Format(" NT_Class as a,NT_RoleClass as b,NT_Role as c");
            sql_SelectFirst += string.Format(" where a.id=b.ClassId and b.RoleId=c.CreateRoleId and c.id={0}", Request.QueryString["ID"].ToString());
        }
        this.tr_power.Nodes.Clear();
    }
    #endregion

    protected void btnSave_Click(object sender, EventArgs e)
    {
        //PowerSave(tr_power.CheckedNodes);
    }
}
