asp.net1.1下权限配置系统从设计到实现(二)

     此权限系统的涉及到的数据表结构如下:

 

很简单,有图在此一目了然。一个角色对应多个功能,而每个功能又包含很多子功能,所以在设计的时候考虑要用到这5张表。在进行开发之前需要安装和配置TreeView控件,如果不知道怎么用可以参看这里:http://jigee.cnblogs.com/archive/2006/04/14/375623.html;应为实现这样的系统主要问题是解决TreeView的问题,开发的时候考虑到代码的简洁和以后便于维护,所以放在了UserControl中,这个对你可能没什么关系,主要是因为我们的系统还有其他模块要集成在一起,通过动态加载用户控件的形式来完成页面的切换工作!PS:为了不涉及公司代码的外泄,我只将写出一些与公司信息无关但又是实现此功能的核心代码,也就是说只写与TreeView有关的部分代码,OK!不说了开始我们的codeing ! TeeView的HTML如下:

<div id="dvRolesFunction" style="BORDER-RIGHT: #99ccff 2px solid; BORDER-TOP: #99ccff 2px solid; OVERFLOW: auto; BORDER-LEFT: #99ccff 2px solid; WIDTH: 400px; BORDER-BOTTOM: #99ccff 2px solid; HEIGHT: 485px">
<iewc:treeview id="tvRoleFunctions" runat="server"SystemImagesPath="../webctrl_client/1_0/treeimages/" showlines="true" shoplus="true">
</iewc:treeview>
</div>

填充TeeView控件的主要代码如下:

private void FillFuntionAndPointInfo()
{
    
string name, value;
    TreeNode parentTreeNode 
= null;
    TreeNode childTreeNode;
    DataSet ds 
= MappingUser.GetFunctionAndFunctionPoint();
   if (ds != null && ds.Tables[0!= null)
   {
                
for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                {
                    value 
= Common.GetFieldValue(ds.Tables[0].Rows[i]["functionid"], ""); //为了获得有效的返回值
                    name 
= Common.GetFieldValue(ds.Tables[0].Rows[i]["functionname"], "");//  .DLL不会公开
                    
if (parentTreeNode == null || parentTreeNode.Text != name)
                    {
                        parentTreeNode 
= new TreeNode();
                        parentTreeNode.Text 
= name;
                        parentTreeNode.CheckBox
=true;
                        parentTreeNode.ID 
=value; 
                        parentTreeNode.Expandable
=ExpandableValue.Auto; 
                        tvRoleFunctions.Nodes.Add(parentTreeNode);
                    }
                    value 
= Common.GetFieldValue(ds.Tables[0].Rows[i]["functionpointid"], "").Trim();
                    name 
= Common.GetFieldValue(ds.Tables[0].Rows[i]["functionpointname"], "");
                    
if (value.Length > 0)
                    {
                        childTreeNode 
= new TreeNode();
                        childTreeNode.Text 
= name;
                        childTreeNode.CheckBox
=true
                        childTreeNode.ID  
= value;
                        childTreeNode.Expandable
=ExpandableValue.Auto; 
                        parentTreeNode.Nodes.Add(childTreeNode);
                    }
                }
            }
        }

GetFunctionAndFunctionPoint()方法用到的Sql语句如下:

SELECT   functionid,
                  b.name 
AS functionname,
                  functionpointid,
                  c.name 
AS functionpointname
                   
FROM    Function b (NOLOCK),
                                   
FunctionRelationPoint a (NOLOCK)
                                    
LEFT JOIN FunctionPoint c (NOLOCK) ON a.FunctionPointID = c.id
                                
WHERE    a.FunctionID = b.id
                                
ORDER BY functionid,functionpointid

下次写作预告:
怎么用脚本实现TreeView的父子节点联动和全选的功能,之前我在网上和CSDN找过一个实现父子节点联动效果的方法,可惜是在TreeView.htc文件中实现,由于考虑到项目部署时可能带来问题,干脆自己用javaScript实现。

posted on 2006-06-08 16:32  kim  阅读(3457)  评论(2编辑  收藏  举报

导航