asp结合数据库实现无限级分类的存储、再现、管理的源码

这是自己写,调试的时候总出问题,请高手们给看一下:

数据库结构:
---------------------------------------------------------------------------------------------------------------------------------------------
|      node_id      |  node_parent_id   |     node_name     |     node_deep     |     node_left     |    node_right     |    node_state     |
---------------------------------------------------------------------------------------------------------------------------------------------
|                29 |                 0 | food              |                 0 |                 1 |                16 |                 1 |
---------------------------------------------------------------------------------------------------------------------------------------------
|                30 |                29 | a                 |                 1 |                 2 |                 3 |                 1 |
---------------------------------------------------------------------------------------------------------------------------------------------
|                31 |                29 | b                 |                 1 |                 4 |                 5 |                 1 |
---------------------------------------------------------------------------------------------------------------------------------------------
|                32 |                29 | c                 |                 1 |                 6 |                15 |                 1 |
---------------------------------------------------------------------------------------------------------------------------------------------
|                33 |                32 | d                 |                 2 |                 7 |                14 |                 1 |
---------------------------------------------------------------------------------------------------------------------------------------------
|                34 |                33 | e                 |                 3 |                 8 |                 9 |                 1 |
---------------------------------------------------------------------------------------------------------------------------------------------
|                35 |                33 | f                 |                 3 |                10 |                11 |                 1 |
---------------------------------------------------------------------------------------------------------------------------------------------
|                36 |                33 | g                 |                 3 |                12 |                13 |                 1 |
---------------------------------------------------------------------------------------------------------------------------------------------

conntest.asp

<%
 dim conn
 dim db
 db="data/db3.mdb"
 Set conn = Server.CreateObject("ADODB.Connection")
        conn.CursorLocation=3
        conn.open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath(db)
%>

new_node.asp

<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>
<!--#include file="conn.asp"-->
<%
if trim(request("del_id"))<>"" then
node_left=int(request("node_left"))
node_right=int(request("node_right"))
conn.execute("delete from node where node_left>=" & node_left & " and node_right<=" & node_right)
jnum=(node_right-node_left)+1
conn.execute("update node set node_left=node_left-" & jnum & " where node_left>" & node_right)
conn.execute("update node set node_right=node_right-" & jnum & " where node_right>" & node_right)
response.Redirect("build_tree.asp")
end if
%>
<%
if trim(request("node_name"))<>"" then
if trim(request("next_level_node"))="创建节点" then
node_name=trim(request("node_name"))
node_parent_id=trim(request("node_parent_id"))
node_left=clng(trim(request("node_left")))
node_right=clng(trim(request("node_right")))
node_deep=trim(request("node_deep"))
conn.execute("update node set node_right=node_right+2 where node_right>=" & node_right)
conn.execute("update node set node_left=node_left+2 where node_left>" & node_right)
sql="insert into node(node_name,node_parent_id,node_deep,node_left,node_right) values('" & node_name & "','" & node_parent_id & "','" & node_deep & "','" & node_right & "','" & node_right+1 & "')"
conn.execute(sql)
end if
if trim(request("same_level_node"))="创建节点" then
node_name=trim(request("node_name"))
node_parent_id=trim(request("node_parent_id"))
node_left=clng(trim(request("node_left")))
node_right=clng(trim(request("node_right")))
node_deep=trim(request("node_deep"))
conn.execute("update node set node_right=node_right+2 where node_right>" & node_right)
conn.execute("update node set node_left=node_left+2 where node_left>" & node_right)
sql="insert into node(node_name,node_parent_id,node_deep,node_left,node_right) values('" & node_name & "','" & node_parent_id & "','" & node_deep & "','" & node_right+1 & "','" & node_right+2 & "')"
conn.execute(sql)
end if
response.Redirect("build_tree.asp")
end if
%>
<%
Function suojin(node_deep)
If node_deep>0 Then
For i=1 To node_deep
temp=temp & "|--"
Next
End if
suojin=temp
End Function
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>节点操作</title>
</head>
<body>
<form method="post" name="selected_node">
<select name="node_id" οnchange="document.selected_node.submit();">
<option selected>选择节点</option>
<%
Set rs=conn.execute("select * from node order by node_left asc")
Do Until rs.eof
response.write "<option value='" & rs("node_id") & "'>"
response.write suojin(rs("node_deep")) & rs("node_name")
response.write "</option>"
rs.movenext
If rs.eof Then Exit Do
Loop
Set rs=nothing
%>
</select>
</form>
<%
if trim(request("node_id"))<>"" then
node_id=trim(request("node_id"))
sql="select * from node where node_left<=(select node_left from node where node_id=" & node_id & ") and node_right>=(select node_right from node where node_id=" & node_id & ") order by node_left asc"
set rs=conn.execute(sql)
response.write "节点描述:"
Do Until rs.eof
response.write ">>" & rs("node_name")
rs.movenext
If rs.eof Then Exit Do
Loop
Set rs=nothing
set rs=conn.execute("select * from node where node_id=" & node_id)
node_deep=rs("node_deep")
node_parent_id=rs("node_parent_id")
node_left=rs("node_left")
node_right=rs("node_right")
set rs=nothing
if node_left>1 then
response.write "   [<a href='" & request.ServerVariables("URL") & "?del_id=" & request("node_id") & "&node_right=" & node_right & "&node_left=" & node_left & "'>删除</a>]"
response.write "   (深度:" & node_deep & "左值:" & node_left & "右值:" & node_right & ")"
else
response.write "   (深度:" & node_deep & "左值:" & node_left & "右值:" & node_right & ")"
end if
%>
<% if node_left>1 then %>
<form name="new_node1" method="post">
<input type="hidden" name="node_parent_id" value="<% =node_parent_id %>" />
<input type="hidden" name="node_right" value="<% =node_right %>"/>
<input type="hidden" name="node_left" value="<% =node_left %>"/>
<input type="hidden" name="node_deep" value="<% =node_deep %>"/>
(同级)节点名称:<input type="text" name="node_name" value=""/>
<input type="submit" name="same_level_node" value="创建节点" />
<input type="reset" value="重置"  />
</form>
<% end if %>
<form name="new_node2" method="post">
<input type="hidden" name="node_parent_id" value="<% =node_id %>" />
<input type="hidden" name="node_right" value="<% =node_right %>"/>
<input type="hidden" name="node_left" value="<% =node_left %>"/>
<input type="hidden" name="parent_deep" value="<% =node_deep %>"/>
<input type="hidden" name="node_deep" value="<% =node_deep+1 %>"/>
(下级)节点名称:<input type="text" name="node_name" value=""/>
<input type="submit" name="next_level_node" value="创建节点" />
<input type="reset" value="重置"  />
</form>
<%
end if
conn.close
set conn=nothing
%>
</body>
</html>

node_change.asp


<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>
<!--#include file="conntest.asp"-->
<%
if trim(request("from_node"))<>"" and trim(request("to_node"))<>"" then
mytest=trim(request("node_level"))
to_id=trim(request("to_node"))
from_str=Split(trim(request("from_node")), ",", -1, 1)
from_left=from_str(0)
if from_left>1 then
conn.BeginTrans
from_right=from_str(1)
from_deep=from_str(2)
del_num=((from_right-from_left-1)/2+1)*2
conn.execute("update node set node_state=0 where node_left between " & from_left & " and " & from_right)
conn.execute("update node set node_left=node_left-" & del_num & " where node_left>" & from_right)
conn.execute("update node set node_right=node_right-" & del_num & " where node_right>" & from_right)
set rs=conn.execute("select * from node where node_state=1 and node_id=" & to_id)
to_left=rs("node_left")
to_right=rs("node_right")
to_deep=rs("node_deep")
set rs=nothing
mytest=trim(request("node_level"))
jnum1=((from_right-from_left-1)/2+1)*2
if mytest=0 then
conn.execute("update node set node_left=node_left+" & jnum1 & " where node_state=1 and node_left>" & to_right)
conn.execute("update node set node_right=node_right+" & jnum1 & " where node_state=1 and node_right>" & to_right)
end if
if mytest=1 then
conn.execute("update node set node_left=node_left+" & jnum1 & " where node_state=1 and node_left>" & to_right)
conn.execute("update node set node_right=node_right+" & jnum1 & " where node_state=1 and node_right>=" & to_right)
end if
if mytest=0 then
jnum2=from_left-(to_right+1)
jdeep=from_deep-to_deep
conn.execute("update node set node_left=node_left-" & jnum2 & ",node_right=node_right-" & jnum2 & ",node_state=1 where node_state=0")
conn.execute("update node set node_deep=node_deep-" & jdeep & ",node_state=1 where node_state=0")
end if
if mytest=1 then
jnum2=from_left-(to_left+1)
jdeep=from_deep-(to_deep+1)
conn.execute("update node set node_left=node_left-" & jnum2 & ",node_right=node_right-" & jnum2 & " where node_state=0")
conn.execute("update node set node_deep=node_deep-" & jdeep & ",node_state=1 where node_state=0")
end if
if conn.errors.count=0 then
conn.CommitTrans    
else
conn.RollbackTrans
end if
else
response.Write "你选择的是根节点,他不能被移动----" & "<a href='" & request.ServerVariables("HTTP_REFERER") & "'>返回</a>"
response.end
end if
end if
%>
<%
Function suojin(node_deep)
If node_deep>0 Then
For i=1 To node_deep
temp=temp & "|--"
Next
End if
suojin=temp
End Function
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>节点移动操作</title>
</head>
<body>
<form method="post" name="selected_node">
<select name="from_node">
<option selected>选择节点</option>
<%
Set rs=conn.execute("select * from node where node_state=1 order by node_left asc")
Do Until rs.eof
response.write "<option value='" & rs("node_left") & "," & rs("node_right") & "," & rs("node_deep") & "'>"
response.write suojin(rs("node_deep")) & rs("node_name")
response.write "</option>"
rs.movenext
If rs.eof Then Exit Do
Loop
Set rs=nothing
%>
</select>
<input type="submit" name="sub1" value="移到" />
<label><input type="radio" name="node_level" value="0" checked="checked" />同级</label>
<label><input type="radio" name="node_level" value="1" />下级</label>
<select name="to_node">
<option selected>选择节点</option>
<%
Set rs=conn.execute("select * from node where node_state=1 order by node_left asc")
Do Until rs.eof
response.write "<option value='" & rs("node_id") & "'>"
response.write suojin(rs("node_deep")) & rs("node_name")
response.write "</option>"
rs.movenext
If rs.eof Then Exit Do
Loop
Set rs=nothing
%>
</select>
</form>
</body>
</html>
<%
conn.close
set conn=nothing
%>

 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值