TreeVIew树形菜单

 

  ///   <summary>
        
///  绑定根节点
        
///   </summary>
         protected  void BindParentTree()
        {
             // 取得当前登录用户id
             int userId = Session[ " uid "]!= null? int.Parse(Session[ " uid "].ToString()):- 1;
            
            List<Model.MenusInfo> list =  new BLL.MenusInfo().GetModelList( "  (MenuID in(select PreMenuID from MenusInfo where MenusInfo.MenuID in(select roleAuthority.MenuID from RoleAuthority roleAuthority where roleAuthority.RoleID in(select userRole.RoleID from UserRole userRole where userRole.UserID= "+userId + " )))) ");
             for ( int i =  0; i < list.Count; i++)
            {
                TreeNode tn =  new TreeNode();
                tn.Text = list[i].MenuName;
                tn.Value = list[i].MenuID.ToString();
                 this.TVMenu.Nodes.Add(tn);
                tn.Expanded =  false;
                 // BindSecondTreeItems(tn, Convert.ToInt32(list[i].MenuID));
                BindTreeItems (tn, Convert.ToInt32(list[i].MenuID));
            }
        }
         /// //  <summary>
        
/// // 绑定二级目录菜单
        
/// //  </summary>
        
/// //  <param name="tn"></param>
        
/// //  <param name="menuid"></param>
         // protected void BindSecondTreeItems(TreeNode tn, int menuid)
        
// {
        
//      // 取得当前登录用户id
        
//     int userId = int.Parse(Session["uid"].ToString());
        
//     List<Model.MenusInfo> list = new BLL.MenusInfo().GetModelList(" MenusInfo.MenuID in(select roleAuthority.MenuID from RoleAuthority roleAuthority where roleAuthority.RoleID in(select userRole.RoleID from UserRole userRole where userRole.UserID=" + userId + ")) and PreMenuID='" + menuid + "' and MenuInfo='事项办理'");
        
//      if (list.Count > 0)
        
//     {
        
//         TreeNode secondonetn = new TreeNode();
        
//         secondonetn.Text = "事项办理";
        
//         secondonetn.Value = "事项办理";
        
//         tn.ChildNodes.Add(secondonetn);
        
//         BindTreeItems(secondonetn, Convert.ToInt32(list[0].PreMenuID),1);
        
//     }
        
//      List<Model.MenusInfo> list1 = new BLL.MenusInfo().GetModelList(" MenusInfo.MenuID in(select roleAuthority.MenuID from RoleAuthority roleAuthority where roleAuthority.RoleID in(select userRole.RoleID from UserRole userRole where userRole.UserID=" + userId + ")) and  PreMenuID='" + menuid + "' and MenuInfo='台帐管理与统计分析'");
        
//     if (list1.Count > 0)
        
//     {
        
//         TreeNode secondtwotn = new TreeNode();
        
//         secondtwotn.Text = "台账管理与统计";
        
//         secondtwotn.Value = "台账管理与统计";
        
//         tn.ChildNodes.Add(secondtwotn);
        
//         BindTreeItems(secondtwotn, Convert.ToInt32(list1[0].PreMenuID),2);
        
//     }
        
//     if(list1 .Count <=0&&list .Count <=0)
        
//     {
        
//         BindTreeItems(tn, menuid,0);
        
//     }
        
//     tn.Expanded = false;
            
        
// }
         ///   <summary>
        
///  绑定子节点
        
///   </summary>
        
///   <param name="tn"></param>
        
///   <param name="parent"></param>
         protected  void BindTreeItems(TreeNode tn,  int parentid)
        {
             // 取得当前登录用户id
             int userId = Session[ " uid "] !=  null ?  int.Parse(Session[ " uid "].ToString()) : - 1;
            List<Model.MenusInfo> listitem =  new BLL.MenusInfo().GetModelList( " MenuID= " + parentid);
             string sflag =  "";
             if (listitem.Count >  0)
            {
                sflag = listitem[ 0].MenuName;
            }
             string sql  =  "  MenusInfo.MenuID in(select roleAuthority.MenuID from RoleAuthority roleAuthority where roleAuthority.RoleID in(select userRole.RoleID from UserRole userRole where userRole.UserID= " + userId +  " )) and PreMenuID= " + parentid +  "";
            List<Model.MenusInfo> list =  new BLL.MenusInfo().GetModelList(sql);
             for ( int i =  0; i < list.Count; i++)
            {
                TreeNode itemtn =  new TreeNode();
                 if (sflag.IndexOf ( " 台账管理 ")!=- 1)
                {
                    itemtn.Text =list[i].MenuInfo+ " - "+list[i].MenuName;
                }
                 else
                {
                    itemtn.Text = list[i].MenuName;
                }
                itemtn.Value = list[i].MenuID.ToString();
                itemtn.Target =  " mainFrame ";
                itemtn.NavigateUrl = list[i].MenuAddress;
                tn.ChildNodes.Add(itemtn);
                 // itemtn.ExpandAll();
                itemtn.Expanded =  false;
            }
        }
         #region
         /// //  <summary>
        
/// // 绑定子节点
        
/// //  </summary>
        
/// //  <param name="tn"></param>
        
/// //  <param name="parent"></param>
         // protected void BindTreeItems(TreeNode tn, int parentid,int flag)
        
// {
        
//      // 取得当前登录用户id
        
//     int userId = int.Parse(Session["uid"].ToString());
        
//     string sql = "";
        
//     if (flag == 0)
        
//     {
        
//         sql = " MenusInfo.MenuID in(select roleAuthority.MenuID from RoleAuthority roleAuthority where roleAuthority.RoleID in(select userRole.RoleID from UserRole userRole where userRole.UserID=" + userId + ")) and PreMenuID=" + parentid + "";
        
//     }
        
//     else if (flag == 1)
        
//     {
        
//         sql = " MenusInfo.MenuID in(select roleAuthority.MenuID from RoleAuthority roleAuthority where roleAuthority.RoleID in(select userRole.RoleID from UserRole userRole where userRole.UserID=" + userId + ")) and PreMenuID=" + parentid + " and MenuInfo='事项办理'";
        
//     }
        
//     else
        
//     {
        
//         sql = " MenusInfo.MenuID in(select roleAuthority.MenuID from RoleAuthority roleAuthority where roleAuthority.RoleID in(select userRole.RoleID from UserRole userRole where userRole.UserID=" + userId + ")) and PreMenuID=" + parentid + " and MenuInfo='台帐管理与统计分析'";
        
//     }
        
//     List<Model.MenusInfo> list = new BLL.MenusInfo().GetModelList(sql);
        
//     for (int i = 0; i < list.Count; i++)
        
//     {
        
//         TreeNode itemtn = new TreeNode();
        
//         itemtn.Text = list[i].MenuName;
        
//         itemtn.Value = list[i].MenuID.ToString();
        
//         itemtn.Target = "mainFrame";
        
//         itemtn.NavigateUrl =list[i].MenuAddress ;
        
//         tn.ChildNodes.Add(itemtn);
        
//          // itemtn.ExpandAll();
        
//         itemtn.Expanded = false;
        
//     }
        
// }
         #endregion
         protected  void TVMenu_SelectedNodeChanged( object sender, EventArgs e)
        {
             for( int i= 0;i<TVMenu .Nodes .Count;i++)
            {
                 if (TVMenu.Nodes[i].Selected)
                {
                    TVMenu.Nodes[i].Expand();
                }
            }
        }

 

转载于:https://www.cnblogs.com/mikehhs/archive/2012/04/30/2477065.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值