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 System.Collections.Generic;
using Fm.Bussiness;

public partial class Left :BasePage
{
   
    protected void Page_Load(object sender, EventArgs e)
    {

        if (!IsPostBack)
        {
            BindMenu();
         
        }

    }
    //绑定主菜单栏
    void BindMenu()
    {
        Fm_Admin_Login login = new Fm_Admin_Login();
        string where = "(m_parent=0) and (";//主菜单查询条件
        string subwhere = "(m_parent<>0) and (";//子菜单查询条件
        List<int> r_id = Session["r_id"] as List<int>;
        foreach (int k in r_id)
        {
            where += "r_id=" + k.ToString() + " or ";
            subwhere += "r_id=" + k.ToString() + " or ";
        }
        int or = where.LastIndexOf("or");
        where = where.Remove(or);
        where += ")";

        int sor = subwhere.LastIndexOf("or");

        subwhere = subwhere.Remove(sor);

        subwhere += ")";
        ViewState["subwhere"] = subwhere;

        //绑定主菜单栏
        Rep_Menu.DataSource = login.Admin_Menu(where);

        Rep_Menu.DataBind();

        //绑定菜主单栏2（用于区分子栏目的绑定）
       // Sub_menu.DataSource = login.Admin_Menu(where);
        //Sub_menu.DataBind();


    }
    //绑定子栏目
    protected void Rep_Menu_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
           Fm_Admin_Login login = new Fm_Admin_Login();
           string m_id = (e.Item.DataItem as DataRowView)["m_id"].ToString();//获取绑定的菜单栏ID

           Repeater sub_rep = e.Item.FindControl("Rep_sub") as Repeater;//获取父级数据集中的控件
           //绑定数据源
           sub_rep.DataSource=login.Admin_Menu(ViewState["subwhere"].ToString() + " and (m_parent=" + m_id + ")");
           sub_rep.DataBind(); 
         
    }
}
