45fan.com - 路饭网

搜索: 您的位置主页 > 网络频道 > 阅读资讯:如何能够无限分类添加新类别代码?

如何能够无限分类添加新类别代码?

2016-08-24 20:24:47 来源:www.45fan.com 【

如何能够无限分类添加新类别代码?

'无限分类添加新类别代码
'OrderID所有栏目的排列顺序
'RootOrderID同一顶栏目的排列顺序
'ClassOrderID同一父类栏目的排列顺序


if request("action")="AddSave" then

ChannelID=cint(trim(Request.Form("ChannelID")))
ParentClassID=trim(Request.Form("ParentID"))
ClassName=trim(Request.Form("ClassName"))
ClassFolderName=trim(Request.Form("ClassFolderName"))
ClassMemo=trim(Request.Form("ClassMemo"))
ClassKeyWords=trim(Request.Form("ClassKeyWords"))
ClassDescription=trim(Request.Form("ClassDescription"))
IsCreateFolder=trim(Request.Form("IsCreateFolder"))

if ClassName="" Then
response.write("<script>alert('系统出错!请返回填写栏目类别名称');history.go(-1);</script>")
response.End()
end if

if ClassFolderName="" Then
response.write("<script>alert('系统出错!请返回填写栏目类别目录文件夹');history.go(-1);</script>")
response.End()
end if

if ClassMemo="" Then
response.write("<script>alert('系统出错!请返回填写栏目类别说明');history.go(-1);</script>")
response.End()
end if

if ClassKeyWords="" Then
response.write("<script>alert('系统出错!请返回填写栏目类别搜索关键字');history.go(-1);</script>")
response.End()
end if

if ClassDescription="" Then
response.write("<script>alert('系统出错!请返回填写栏目类别搜索描述词');history.go(-1);</script>")
response.End()
end if


If IsValidWindowsFolderName(ClassFolderName)=False Then
response.Write("<script language=javascript>alert('目录名格式不正确,按确定返回重新填写');history.back();</script>")
response.End()
end if

ClassFolderName=Replace(PCase(ClassFolderName)," ","-")

'网站频道项目
set rs=server.CreateObject("Adodb.recordset")
sql="select * from SystemChannelList Where ChannelID="&ChannelID
rs.open sql,conn,1,3
if rs.eof and rs.bof then
rs.close
set rs=nothing
conn.close
set conn=nothing
response.write("<script>alert('无此频道数据,系统即将返回!');location.href='ClassList.asp';</script>")
response.End()
else
ChannelName =rs("ChannelName")
ChannelFolderUrl=rs("ChannelFolderUrl")
ChannelFolderPath=rs("ChannelFolderPath")
end if
rs.close
set rs=nothing

Session("ChannelID")=ChannelID
Session("ClassName")=ClassName
Session("ClassFolderName")=ClassFolderName
Session("ClassMemo")=ClassMemo
Session("ClassKeyWords")=ClassKeyWords
Session("ClassDescription")=ClassDescription
Session("IsCreateFolder")=IsCreateFolder



if ParentClassID=0 then
'添加顶类栏目
'查询父类相关数据
ParentClassName="" '父类名
ParentClassFolderName="" '父类目录名
ParentClassDepth=0 '父类深度
newClassRootID=0 '顶类ID
ParentClassIDPath=0 'ID路径

'获取已存在的最大栏目ClassID
MaxClassID = conn.execute("select Max(ClassID) as List1 From SoftClass")("List1")
if isnull(MaxClassID) then
newRootOrderID=1
newClassOrderID=1
newOrderID=1
PrevID=0
else
PrevID=MaxClassID

'获取同一父类栏目中的排列顺序
newClassOrderID=1

'获取同一顶类栏目中的排列顺序
newRootOrderID=1

'获取全部栏目的排列顺序
set rs1=conn.execute("select Count(*) From SoftClass")
if isnull(rs1(0)) then
newOrderID=1
else
newOrderID=rs1(0)+1
end if
set rs1=nothing

end if

ClassFolderPath=ClassFolderName
ClassLocalPath=ChannelFolderPath&"/"&ClassFolderPath
ClassFolderUrl=ChannelFolderUrl&"/"&Replace(ClassFolderPath,"/","/")
else
'添加子类栏目

'分添加到一级栏目下和添加到N级栏目下两种情况

'查询目标父类相关数据
set rsParent=server.CreateObject("Adodb.recordset")
sqlParent="select * from SoftClass where ClassID="&ParentClassID
rsParent.open sqlParent,conn,1,3
if rsParent.eof and rsParent.bof then
response.write("<script>alert('未能查询到父类类别对应的数据!系统即将返回上一页');history.go(-1);</script>")
response.End()
else
ParentClassID=rsParent("ClassID")
ParentClassName=rsParent("ClassName") '父类名
ParentClassFolderName=rsParent("ClassFolderName") '父类目录名
ParentClassFolderPath=rsParent("ClassFolderPath") '父类目录名
ParentClassFolderUrl=rsParent("ClassFolderUrl") '父类访问路径
ParentClassDepth=rsParent("ClassDepth") '父类深度
ParentClassIDPath=rsParent("ParentIDPath")
Child=rsParent("Child")

if ParentClassDepth=0 then'如果目标父栏目是一级栏目

oldClassRootID=rsParent("RootID") '原始RootID
newClassRootID=rsParent("ClassID") '最新RootID

if Child>0 then'如果添加栏目到有子栏目的一级栏目下

'获取即将添加的栏目ClassID
MaxClassID = conn.execute("select Max(ClassID) as List1 From SoftClass where ParentID="&ParentClassID)("List1")
PrevID=MaxClassID

'获取同一父类的子栏目中的排列顺序
set rs1=conn.execute("select Max(ClassOrderID) From SoftClass where ParentID="&ParentClassID)
if isnull(rs1(0)) then
newClassOrderID=1
else
newClassOrderID=rs1(0)+1
end if
set rs1=nothing

'获取同一顶类的子栏目中的排列顺序
set rs1=conn.execute("select Max(RootOrderID) From SoftClass where ParentIDPath like '"&ParentClassIDPath&","&newClassRootID&",%'")
if isnull(rs1(0)) then
newRootOrderID=conn.execute("select RootOrderID,ClassID From SoftClass where ClassID="&MaxClassID)("RootOrderID")+1
else
newRootOrderID=rs1(0)+1
end if
set rs1=nothing

'获取全部栏目中的的排列顺序

set rs1=conn.execute("select Max(OrderID) From SoftClass where ParentIDPath like '"&ParentIDPath&","&MaxClassID&",%' and RootID>0")
if isnull(rs1(0)) then
newOrderID=conn.execute("select OrderID,ClassID From SoftClass where ClassID="&MaxClassID&" and RootID>0")("OrderID")+1
else
newOrderID=rs1(0)+1
end if
set rs1=nothing

'更新其他后面栏目RootID,ClassID对应的RootOrderID,ClassOrderID,OrderID
'RootOrderID,ClassOrderID也不需要动
conn.execute("update SoftClass set RootOrderID=RootOrderID+1 where RootOrderID>="&newRootOrderID)

conn.execute("update SoftClass set OrderID=OrderID+1 where OrderID>="&newOrderID)

else'如果目标栏目没有子栏目

PrevID=0
newRootOrderID=2
newClassOrderID=1
'获取全部栏目中的的排列顺序
set rs1=conn.execute("select Max(OrderID) From SoftClass where ParentIDPath like '"&ParentIDPath&","&MaxClassID&",%' and RootID>0")
if isnull(rs1(0)) then
newOrderID=2
else
newOrderID=rs1(0)+1
end if
set rs1=nothing


'更新其他后面栏目RootID,ClassID对应的RootOrderID,ClassOrderID,OrderID
'RootOrderID,ClassOrderID也不需要动
conn.execute("update SoftClass set OrderID=OrderID+1 where OrderID>="&newOrderID)

end if

else

'如果目标父类是N级栏目ClassDepth>1级别
newClassRootID=rsParent("RootID")
oldClassRootID=rsParent("RootID") '最新RootID
response.Write("<br>"&oldClassRootID)
topClassRootID=conn.execute("select RootID,ClassID From SoftClass where ClassID="&oldClassRootID)("RootID")
response.Write("<br>"&topClassRootID)

if Child>0 then'如果目标N级父栏目已存在子栏目

'获取即将添加的栏目ClassID
MaxClassID = conn.execute("select Max(ClassID) as List1 From SoftClass where ParentID="&ParentClassID)("List1")
PrevID=MaxClassID
'获取同一父类栏目中的排列顺序
set rs1=conn.execute("select Max(ClassOrderID) From SoftClass where ParentID="&ParentClassID)
newClassOrderID=rs1(0)+1
set rs1=nothing

'获取同一顶类的子栏目中的排列顺序

set rs1=conn.execute("select Max(RootOrderID) From SoftClass where ParentIDPath like '"&ParentIDPath&","&MaxClassID&",%'")

if isnull(rs1(0)) then
newRootOrderID=conn.execute("select RootOrderID,ClassID From SoftClass where ClassID="&MaxClassID)(0)+1
else
newRootOrderID=rs1(0)+1
end if
set rs1=nothing

'获取全部栏目中的排列顺序
set rs1=conn.execute("select Max(OrderID) From SoftClass where ParentIDPath like '"&ParentIDPath&","&MaxClassID&",%'")

if isnull(rs1(0)) then
newOrderID=conn.execute("select OrderID,ClassID From SoftClass where ClassID="&MaxClassID)(0)+1
else
newOrderID=rs1(0)+2
end if
set rs1=nothing

'更新其他后面栏目RootID,ClassID对应的RootOrderID,ClassOrderID,OrderID
'RootOrderID,ClassOrderID也不需要动
conn.execute("update SoftClass set RootOrderID=RootOrderID+1 where RootOrderID>="&newRootOrderID&" and RootID="&oldClassRootID)
conn.execute("update SoftClass set OrderID=OrderID+1 where OrderID>="&newOrderID)

else'如果目标N级父栏目不存在子栏目

PrevID=0
'获取同一父类栏目中的排列顺序
newClassOrderID=1

'获取同一顶类栏目中的排列顺序
'如果前面有子栏目,且子栏目有别的子栏目
set rs1=conn.execute("select Max(RootOrderID) From SoftClass where ParentIDPath like '"&ParentClassIDPath&",%'")
if isnull(rs1(0)) then
newRootOrderID=conn.execute("select Max(RootOrderID) From SoftClass where ClassDepth="&ParentClassDepth&"")(0)+1
else
newRootOrderID=rs1(0)+1
end if

set rs1=nothing
response.Write("<br>"&newRootOrderID)
response.Write("<br>"&topClassRootID)
conn.execute("update SoftClass set RootOrderID=RootOrderID+1 where RootOrderID>="&newRootOrderID&" and RootID="&oldClassRootID)

'获取全部栏目中的排列顺序
newOrderID=conn.execute("select OrderID,ClassID From SoftClass where ClassID="&ParentClassID)("OrderID")+1


'更新其他后面栏目RootID,ClassID对应的RootOrderID,ClassOrderID,OrderID
'RootOrderID,ClassOrderID也不需要动
conn.execute("update SoftClass set OrderID=OrderID+1 where OrderID>="&newOrderID)
'conn.execute("update SoftClass set OrderID=OrderID+1 where RootID>"&topClassRootID&" and ParentID=0")
'conn.execute("update SoftClass set OrderID=OrderID+1 where RootID>"&oldClassRootID&" and ParentID>0")
end if

end if

end if

rsParent.close
set rsParent=nothing

'根据父类数据得到当前路径相关参数
ClassFolderPath=ParentClassFolderPath&"/"&ClassFolderName
ClassLocalPath=ChannelFolderPath&"/"&ClassFolderPath
ClassFolderUrl=ChannelFolderUrl&"/"&Replace(ClassFolderPath,"/","/")

end if

'创建对应的类别目录
if IsCreateFolder=1 then
CreateFolder ClassLocalPath,IsCreateFolder
end if

'response.Write("<br>"&newOrderID)
'response.Write("<br>"&newRootOrderID)
'response.Write("<br>"&newClassOrderID)

'添加新数据并修改相关字段数值

UserIP = Request.ServerVariables("HTTP_X_FORWARDED_FOR")
If UserIP = "" Then UserIP = Request.ServerVariables("REMOTE_ADDR")
UserFrom=Cstr(Request.ServerVariables("HTTP_REFERER"))

CorrectSqlClassFolderName=replace(ClassFolderName,"'","''")
CorrectSqlClassName=replace(ClassName,"'","''")
set rs=server.CreateObject("Adodb.recordset")
sql="select * from SoftClass where ClassFolderName='"&CorrectSqlClassFolderName&"' and ClassName='"&CorrectSqlClassName&"' and ParentID="&ParentClassID
rs.open sql,conn,3,3
if not rs.eof and not rs.bof then
rs.close
set rs=nothing
conn.close
set conn=nothing
response.write("<script>alert('此栏目类别数据已经存在!系统即将返回');history.go(-1);</script>")
response.end
else
rs.addnew

rs("ChannelID")=ChannelID
rs("ChannelName")=ChannelName
rs("ChannelFolderPath")=ChannelFolderPath
rs("ChannelFolderUrl")=ChannelFolderUrl

if ParentClassID=0 then
'一级目录的深度为0
rs("ParentName")=""
rs("ParentID")=0
rs("ClassDepth")=0
rs("ParentIDPath")="0"
else
rs("ParentName")=ParentClassName
rs("ParentID")=ParentClassID



rs("ClassDepth")=Cint(ParentClassDepth)+1
rs("ParentIDPath")=ParentClassIDPath&","&ParentClassID
end if
rs("OrderID")=newOrderID
rs("RootOrderID")=newRootOrderID
rs("ClassOrderID")=newClassOrderID
rs("RootID")=newClassRootID
rs("PrevID")=PrevID

rs("ClassName")=ClassName
rs("ClassFolderName")=ClassFolderName
rs("ClassFolderPath")=ClassFolderPath
rs("ClassLocalPath")=ClassLocalPath

rs("ClassMemo")=ClassMemo
rs("ClassKeyWords")=ClassKeyWords
rs("ClassDescription")=ClassDescription
rs("IsCreateFolder")=IsCreateFolder



rs("AddUser")=Session("ManagerUserName")
rs("AddTime")=now()
rs("AddIP")=UserIP
rs("AddFrom")=UserFrom
rs.update
end if
rs.close
set rs=nothing
newClassID=conn.execute("Select ClassID,OrderID from SoftClass where OrderID="&newOrderID)("ClassID")
'更新同一父栏目的上一个栏目的“NextID”字段值
if PrevID>0 then
conn.execute("update SoftClass set NextID=" & newClassID & " where ClassID=" & PrevID)
end if

if ParentClassID>0 then
'更新父栏目中的子栏目数量
Child=conn.execute("Select Count(*) as List1 from SoftClass where ParentID="&ParentClassID)("List1")
conn.execute("Update SoftClass Set Child="&Child&" where ClassID="&ParentClassID)
end if

conn.close
set conn=nothing
response.write("<script>alert('栏目类别"&ClassName&"添加完成!系统即将返回列表');location.href='ClassList.asp';</script>")
response.End()
end if


本文地址:http://www.45fan.com/a/question/67084.html
Tags: 代码 目的 OrderID
编辑:路饭网
关于我们 | 联系我们 | 友情链接 | 网站地图 | Sitemap | App | 返回顶部