用ASP+XML实现CSDN的菜单(数据库),可分权限管理.

    我在开发公司OA系统的时候.想找一个CSDN的菜单.可是网上有这样的代码.可是不是基于数据库,也不能按权限管理.我就写了一个.我的这个.只有一个程序文件和一个数据库.文件很少,也很容易查错.但是功能完全实现了!

数据库结构:

Table:Menu
  ID
  parentid,int,4
  MenuName,Char,20
  Link,Char,50

Table:UserLevel
  ID
  UserID,int,4
  MenuID,int,4

-------------------------------------程序源文件:MenuList.Asp------------------------------

<%
'-------------------------------'
'源创商务策划有限公司-OA系统
'模块名称:可权限控制的菜单
'-------------------------------'

set conn = Server.CreateObject("ADODB.Connection")
conn.Open("Provider=Microsoft.Jet.OLEDB.4.0;Data Source="+Server.mappath("tree.mdb")+";Persist Security Info=False")
%>




<script>
//code by star 20003-4-7
var HC = "color:#990000;border:1px solid #cccccc";
var SC = "background-color:#efefef;border:1px solid #cccccc;color:#000000;";
var IO = null;
function initTree(){
?var rootn = document.all.menuXML.documentElement;
?var sd = 0;
?document.onselectstart = function(){return false;}
?document.all.treeBox.appendChild(createTree(rootn,sd));
}
function createTree(thisn,sd){
?var nodeObj = document.createElement("span");
?var upobj = document.createElement("span");
?with(upobj){
??style.marginLeft = sd*10;
??className = thisn.hasChildNodes()?"hasItems":"Items";
??innerHTML = "" + thisn.getAttribute("text") +"";
??
??onmousedown = function(){
???if(event.button != 1) return;
???if(this.getAttribute("cn")){
????this.setAttribute("open",!this.getAttribute("open"));
????this.cn.style.display = this.getAttribute("open")?"inline":"none";
????this.all.tags("img")[0].src = this.getAttribute("open")?"expand.gif":"contract.gif";
???}
???if(IO){
????IO.runtimeStyle.cssText = "";
????IO.setAttribute("selected",false);
???}
???IO = this;
???this.setAttribute("selected",true);
???this.runtimeStyle.cssText = SC;
??}
??onmouseover = function(){
???if(this.getAttribute("selected"))return;
???this.runtimeStyle.cssText = HC;
??}
??onmouseout = function(){
???if(this.getAttribute("selected"))return;
???this.runtimeStyle.cssText = "";
??}
??oncontextmenu = contextMenuHandle;
??onclick = clickHandle;
?}

?if(thisn.getAttribute("treeId") != null){
??upobj.setAttribute("treeId",thisn.getAttribute("treeId"));
?}
?if(thisn.getAttribute("href") != null){
??upobj.setAttribute("href",thisn.getAttribute("href"));
?}
?if(thisn.getAttribute("target") != null){
??upobj.setAttribute("target",thisn.getAttribute("target"));
?}

?nodeObj.appendChild(upobj);
?nodeObj.insertAdjacentHTML("beforeEnd","
")

?if(thisn.hasChildNodes()){
??var i;
??var nodes = thisn.childNodes;
??var cn = document.createElement("span");
??upobj.setAttribute("cn",cn);
??if(thisn.getAttribute("open") != null){
???upobj.setAttribute("open",(thisn.getAttribute("open")=="true"));
???upobj.getAttribute("cn").style.display = upobj.getAttribute("open")?"inline":"none";
???if( !upobj.getAttribute("open"))upobj.all.tags("img")[0].src ="contract.gif";
??}
??
??for(i=0;i
??nodeObj.appendChild(cn);
?}
?else{
??upobj.all.tags("img")[0].src ="endnode.gif";
?}
?return nodeObj;
}
window.onload = initTree;
</script>

<script>
function clickHandle(){
if((this.getAttribute("href")!=null)&&(this.getAttribute("href")!="http://"))
{parent.mainFrame.location.href=this.getAttribute("href");}?? //在MainFrame窗口打开连接。
}

function contextMenuHandle(){
?event.returnValue = false;
?var treeId = this.getAttribute("treeId");
?// your code here
}
</script>




<%

Set rs = Conn.Execute("SELECT (select count(*) from Menu where Menu.parentid=x.id and Menu.ID in (SELECT UserLevel.menuid FROM UserLevel WHERE UserLevel.userid = 1)) AS children, * FROM Menu AS x WHERE x.id in (SELECT UserLevel.menuid FROM UserLevel WHERE UserLevel.userid = 1)")
?
?Do while not rs.eof
? if rs("ParentID")=0 then
?? Count = Rs ("children")
?? %>
? " href="<%=rs("Link")%>" open="false" treeId="<%=rs("ID")%>">
?? <%
?? rs.MoveNext
? end if
?
? for i=1 to Count
??? %>
????????????? ? " href="<%=rs("Link")%>" open="false" treeId="<%=rs("ID")%>">
??
??? <%
??? Rs.MoveNext
? Next
?Response.write(" ")
Loop


rs.close
Conn.close
Set rs = Nothing
Set Conn = Nothing
%>








-----------------------------------------------------------------------------------------------------

源代码下载:http://www.9559.cn/more.asp?name=David&id=4

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值