asp.net1.1下許可權配置系統從設計到實現(二)

來源:互聯網
上載者:User
     此許可權系統的涉及到的資料表結構如下:

 

很簡單,有圖在此一目瞭然。一個角色對應多個功能,而每個功能又包含很多子功能,所以在設計的時候考慮要用到這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實現。

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.