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

    技术2022-05-11  107

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

    数据库结构:---------------------------------------------------------------------------------------------------------------------------------------------|      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"))<>"" thennode_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)+1conn.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"))<>"" thenif trim(request("next_level_node"))="创建节点" thennode_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 ifif trim(request("same_level_node"))="创建节点" thennode_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 ifresponse.Redirect("build_tree.asp")end if%><%Function suojin(node_deep)If node_deep>0 ThenFor i=1 To node_deeptemp=temp & "|--"Next End ifsuojin=tempEnd 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.eofresponse.write "<option value='" & rs("node_id") & "'>"response.write suojin(rs("node_deep")) & rs("node_name")response.write "</option>"rs.movenextIf rs.eof Then Exit DoLoopSet rs=nothing%></select></form><%if trim(request("node_id"))<>"" thennode_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.eofresponse.write ">>" & rs("node_name")rs.movenextIf rs.eof Then Exit DoLoopSet rs=nothingset 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=nothingif node_left>1 thenresponse.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 & ")"elseresponse.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 ifconn.closeset 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"))<>"" thenmytest=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 thenconn.BeginTrans from_right=from_str(1)from_deep=from_str(2)del_num=((from_right-from_left-1)/2+1)*2conn.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=nothingmytest=trim(request("node_level"))jnum1=((from_right-from_left-1)/2+1)*2if mytest=0 thenconn.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 ifif mytest=1 thenconn.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 ifif mytest=0 thenjnum2=from_left-(to_right+1)jdeep=from_deep-to_deepconn.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 ifif mytest=1 thenjnum2=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 ifif conn.errors.count=0 thenconn.CommitTrans     elseconn.RollbackTransend ifelseresponse.Write "你选择的是根节点,他不能被移动----" & "<a href='" & request.ServerVariables("HTTP_REFERER") & "'>返回</a>"response.endend ifend if%><%Function suojin(node_deep)If node_deep>0 ThenFor i=1 To node_deeptemp=temp & "|--"Next End ifsuojin=tempEnd 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.eofresponse.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.movenextIf rs.eof Then Exit DoLoopSet 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.eofresponse.write "<option value='" & rs("node_id") & "'>"response.write suojin(rs("node_deep")) & rs("node_name")response.write "</option>"rs.movenextIf rs.eof Then Exit DoLoopSet rs=nothing%></select></form></body></html><%conn.closeset conn=nothing%>

     


    最新回复(0)