c#,winform,webform,treeview,无限级自动生成



 

16 AuthorizeMenuInfo权限菜单表

 

列名

类型

大小

说明

MenuID

Int

4

菜单ID

MenuName

Varchar

50

菜单名称

ParentID

Int

4

为此菜单的父菜单ID如果是顶级菜单则为0

FormName

Varchar

50

为单击菜单所要显示的窗体类名如果是还有下级菜单的则不要写。

IsModule

Varchar

1

是否还有子菜单,1有,0没有

Level

Int

4

层数

Remark

Varchar

200

备注

 

 

 

 

 

 

 

 

 


存储过程
/*
查询构造treeview所需信息
*/ None.gif
create
  procedure  GetTreeViewAuthorize
None.gif
as
None.gif
select  MenuID,MenuName,ParentID  from  AuthorizeMenuInfo
None.gif
go
None.gif

None.gif /*
根据父节点ID查找子节点信息
*/
None.gif
create   procedure  GetAuthorizeByParentID
None.gif
@ParentID   int
None.gif
as
None.gif
select   *   from  AuthorizeMenuInfo  where  ParentID = @ParentID
None.gif
go
None.gif


ExpandedBlockStart.gif ContractedBlock.gif /**/ /// <summary>
InBlock.gif        
/// 获取构建无限级treeview所需的菜单id,菜单名称,父菜单id
InBlock.gif        
/// 返回datatable
InBlock.gif        
/// </summary>
ExpandedBlockEnd.gif        
/// <returns>无限级treeview所需datatable</returns>

None.gif          public  DataTable GetTreeViewAuthorize()
ExpandedBlockStart.gifContractedBlock.gif        
dot.gif {
InBlock.gif            DataTable dt 
= new DataTable();
InBlock.gif
InBlock.gif            SqlConnection conn 
= new SqlConnection(connectionString);
InBlock.gif            SqlCommand cmd 
= new SqlCommand();
InBlock.gif            cmd.Connection 
= conn;
InBlock.gif            cmd.CommandText 
= "GetTreeViewAuthorize";
InBlock.gif            cmd.CommandType 
= CommandType.StoredProcedure;
InBlock.gif
InBlock.gif            
try
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                conn.Open();
InBlock.gif                
using (SqlDataReader reader = cmd.ExecuteReader())
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    
if(reader!=null)
InBlock.gif
InBlock.gif                        dt.Load(reader);
InBlock.gif                   
ExpandedSubBlockEnd.gif                }

ExpandedSubBlockEnd.gif            }

InBlock.gif            
catch
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
throw;
ExpandedSubBlockEnd.gif            }

InBlock.gif            
finally
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                conn.Close();
ExpandedSubBlockEnd.gif            }

InBlock.gif            
return dt;
ExpandedBlockEnd.gif        }

ExpandedBlockStart.gif ContractedBlock.gif /**/ /// <summary>
InBlock.gif        
/// 根据父节点ID查找子节点信息
InBlock.gif        
/// </summary>
InBlock.gif        
/// <param name="parentID">父节点ID</param>
ExpandedBlockEnd.gif        
/// <returns>子节点信息</returns>

None.gif          public  DataTable GetAuthorizeByParentID( int  parentID)
ExpandedBlockStart.gifContractedBlock.gif        
dot.gif {
InBlock.gif            DataTable dt 
= new DataTable();
InBlock.gif
InBlock.gif            SqlConnection conn 
= new SqlConnection(connectionString);
InBlock.gif            SqlCommand cmd 
= new SqlCommand();
InBlock.gif            cmd.Connection 
= conn;
InBlock.gif            cmd.CommandText 
= "GetAuthorizeByParentID";
InBlock.gif            cmd.Parameters.AddWithValue(
"@ParentID", parentID);
InBlock.gif            cmd.CommandType 
= CommandType.StoredProcedure;
InBlock.gif
InBlock.gif            
try
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                conn.Open();
InBlock.gif                
using (SqlDataReader reader = cmd.ExecuteReader())
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    
if (reader != null)
InBlock.gif
InBlock.gif                        dt.Load(reader);
InBlock.gif
ExpandedSubBlockEnd.gif                }

ExpandedSubBlockEnd.gif            }

InBlock.gif            
catch
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
throw;
ExpandedSubBlockEnd.gif            }

InBlock.gif            
finally
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                conn.Close();
ExpandedSubBlockEnd.gif            }

InBlock.gif            
return dt;
InBlock.gif
ExpandedBlockEnd.gif        }


ExpandedBlockStart.gif ContractedBlock.gif /**/ /// <summary>
InBlock.gif
/// 构造权限treeview
ExpandedBlockEnd.gif
/// </summary>

None.gif          private   void  fill_tvAuthList()
ExpandedBlockStart.gifContractedBlock.gif        
dot.gif {
InBlock.gif            DataTable dt 
= new DataTable();
InBlock.gif            BLLAuthorize bllAuthorize 
= new BLLAuthorize();
InBlock.gif            dt 
= bllAuthorize.GetTreeViewAuthorize();
InBlock.gif            DataRow[] rows 
= dt.Select("[ParentID]=0");
InBlock.gif            
for(int i=0;i<rows.GetUpperBound(0);i++)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                TreeNode treeNode 
= new TreeNode();
InBlock.gif                treeNode.Name 
= rows[i]["MenuID"].ToString();
InBlock.gif                treeNode.Text 
= rows[i]["MenuName"].ToString();
InBlock.gif                
InBlock.gif                DataRow[] rows1 
= dt.Select("[ParentID]=" + Convert.ToInt32(rows[i]["MenuID"]));
InBlock.gif                
if (rows1.GetUpperBound(0> -1)
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    
foreach (DataRow row in rows1)
ExpandedSubBlockStart.gifContractedSubBlock.gif                    
dot.gif{
InBlock.gif                        TreeNode node 
= new TreeNode();
InBlock.gif                        node.Name 
= row["MenuID"].ToString();
InBlock.gif                        node.Text 
= row["MenuName"].ToString();
InBlock.gif                        treeNode.Nodes.Add(node);
ExpandedSubBlockEnd.gif                    }

ExpandedSubBlockEnd.gif                }

InBlock.giftvAuthList.Nodes.Add(treeNode);
ExpandedSubBlockEnd.gif            }

ExpandedBlockEnd.gif        }

None.gif        
private   void  fill_tvAuthListNode(TreeNode treeNode)
ExpandedBlockStart.gifContractedBlock.gif        
dot.gif {
InBlock.gif           
// TreeNode[]nodes=new TreeNode[];
InBlock.gif
            DataTable dt = new DataTable();
InBlock.gif            BLLAuthorize bllAuthorize 
= new BLLAuthorize();
InBlock.gif            dt 
= bllAuthorize.GetAuthorizeByParentID(Convert.ToInt32(treeNode.Name));
InBlock.gif
InBlock.gif            
for (int i = 0; i < dt.Rows.Count; i++)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                TreeNode tNode 
= new TreeNode();
InBlock.gif                tNode.Name 
= dt.Rows[i]["MenuID"].ToString();
InBlock.gif                tNode.Text 
= dt.Rows[i]["MenuName"].ToString();
InBlock.gif                treeNode.Nodes.Add(tNode);
ExpandedSubBlockEnd.gif            }

ExpandedBlockEnd.gif        }

None.gif        
private   void  AddSysRoleForm_Load( object  sender, EventArgs e)
ExpandedBlockStart.gifContractedBlock.gif        
dot.gif {
InBlock.gif            fill_tvAuthList();
ExpandedBlockEnd.gif        }

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值