<% '數(shù)據(jù)庫字段為類屬性,添加、刪除、修改、操作檢查等函數(shù)為類的方法 Class Cls_Leibie Private nClassID,sClassName,nParentID,sParentPath,nDepth,nRootID,nChild,nOrderID,sFilePath '定義私有變量(類的屬性,即數(shù)據(jù)庫字段對(duì)應(yīng)的變量) Private rs,sql,ErrorStr Private Sub Class_Initialize() ErrorStr="" '初始化錯(cuò)誤信息為空 End Sub Private Sub Class_Terminate() '銷毀類時(shí)關(guān)閉數(shù)據(jù)庫連接 If IsObject(Conn) Then Conn.Close Set Conn = Nothing End If End Sub '*******************設(shè)置各個(gè)屬性****************************************************** Public Property Let ClassID(str) '獲取類別ID(主鍵) nClassID=str call ClassProperty() '獲取類別ID時(shí)調(diào)用此函數(shù)讀出類的所有屬性 End Property Public Property Let ClassName(str) '獲取類別名稱 sClassName=str End Property Public Property Get ClassName ClassName=sClassName End Property Public Property Let ParentID(str) '獲取類別父ID nParentID=str End Property Public Property Get ParentID ParentID=nParentID End Property Public Property Let ParentPath(str) '獲取父路徑ID sParentPath=str End Property Public Property Get ParentPath ParentPath=sParentPath End Property Public Property Let Depth(str) '獲取類別深度 nDepth=str End Property Public Property Get Depth Depth=nDepth End Property Public Property Let RootID(str) '獲取類別根ID nRootID=str End Property Public Property Get RootID RootID=nRootID End Property Public Property Let Child(str) '子類別個(gè)數(shù) nChild=str End Property Public Property Get Child Child=nChild End Property Public Property Let OrderID(str) '排序ID nOrderID=str End Property Public Property Get OrderID OrderID=nOrderID End Property Public Property Let FilePath(str) '類別文件根目錄(生成靜態(tài)文件路徑,小站老楊Web技術(shù)博客用的是生成靜態(tài),故設(shè)置此字段) sFilePath=str End Property Public Property Get FilePath FilePath=sFilePath End Property '****************************************************************************** Private Sub ClassProperty() '讀取類的所有屬性 sql="select * from ArticleClass where ClassID="& nClassID set rs=conn.execute(sql) if not rs.eof then sClassName=trim(rs("ClassName")) nParentID=trim(rs("ParentID")) sParentPath=trim(rs("ParentPath")) nDepth=trim(rs("Depth")) nRootID=trim(rs("RootID")) nChild=trim(rs("Child")) nOrderID=trim(rs("OrderID")) sFilePath=trim(rs("FilePath")) end if set rs=nothing End Sub Public Function FAddCheck() '類別添加檢查函數(shù),結(jié)果為0表示通過檢查,為1表示有錯(cuò)誤發(fā)生,有錯(cuò)誤發(fā)生時(shí)退出函數(shù),將錯(cuò)誤信息寫入錯(cuò)誤變量ErrorStr dim temprs FAddCheck=0 if sClassName="" then '類名為空 FAddCheck=1 ErrorStr="類名不能為空!" exit Function else if nParentID="" then '父id為空 FAddCheck=1 ErrorStr="父id不能為空!" exit Function else if nParentID<>0 then set temprs=conn.execute("select ClassID From ArticleClass where ClassID=" & nParentID) '父類別不存在 if temprs.eof then FAddCheck=1 ErrorStr="所屬類別不存在或已經(jīng)被刪除!" exit Function else sql="select ClassID from ArticleClass where ClassName='"& sClassName &"' and ParentID="& nParentID '類名重復(fù) set rs=conn.execute(sql) if not rs.eof then FAddCheck=1 ErrorStr="類名重復(fù)!" exit Function end if set rs=nothing end if set temprs=nothing else sql="select ClassID from ArticleClass where ClassName='"& sClassName &"' and ParentID="& nParentID '類名重復(fù) set rs=conn.execute(sql) if not rs.eof then FAddCheck=1 ErrorStr="類名重復(fù)!" exit Function end if set rs=nothing end if end if end if End Function Public Sub SAdd() dim maxClassID,maxRootID set rs = conn.execute("select Max(ClassID) from ArticleClass") '查找當(dāng)前數(shù)據(jù)庫中最大的類別id,如果沒有數(shù)據(jù)則設(shè)置為0,要插入的類別id為當(dāng)前最大id加1 maxClassID=rs(0) if isnull(maxClassID) then maxClassID=0 end if set rs=nothing nClassID=maxClassID+1 set rs=conn.execute("select max(rootid) From ArticleClass") '查找當(dāng)前數(shù)據(jù)庫中最大的根id,如果沒有數(shù)據(jù)則設(shè)置為0,要插入的根id為當(dāng)前最大根id加1 maxRootID=rs(0) if isnull(maxRootID) then maxRootID=0 end if nRootID=maxRootID+1 set rs=conn.execute("select RootID,Depth,ParentPath,Child,OrderID From ArticleClass where ClassID=" & nParentID) '查找父類別相應(yīng)信息 if not rs.eof then nRootID=trim(rs("Rootid")) '根id與父類別根id相同 sParentPath=trim(rs("ParentPath"))& "," &nParentID if cint(trim(nParentID))>0 then '父id大于0則有父類別,故要插入的類別的深度父類別的深度加1,父id不大于0則當(dāng)前要插入的類別為根類別,則深度為0 nDepth=cint(trim(rs("Depth")))+1 else nDepth=0 end if if cint(trim(rs("Child")))>0 then dim rsPrevOrderID '得到與本欄目同級(jí)的最后一個(gè)欄目的OrderID set rsPrevOrderID=conn.execute("select Max(OrderID) From ArticleClass where ParentID=" & ParentID) prevOrderID=rsPrevOrderID(0) '得到同一父欄目但比本欄目級(jí)數(shù)大的子欄目的最大OrderID,如果比前一個(gè)值大,則改用這個(gè)值。 set rsPrevOrderID=conn.execute("select Max(OrderID) From ArticleClass where ParentPath like '" & ParentPath & ",%'") if (not(rsPrevOrderID.bof and rsPrevOrderID.eof)) then if not IsNull(rsPrevOrderID(0)) then if rsPrevOrderID(0)>prevOrderID then prevOrderID=rsPrevOrderID(0) end if end if end if set rsPrevOrderID=nothing end if nOrderID=prevOrderID+1 else nOrderID=0 sParentPath="0" nDepth=0 end if set rs=nothing nChild=0 sql="insert into ArticleClass (ClassID,ClassName,ParentID,ParentPath,Depth,RootID,Child,OrderID,FilePath) values ("& nClassID &",'"& sClassName &"',"& nParentID &",'"& sParentPath &"',"& nDepth &","& nRootID &","& nChild &","& nOrderID &",'"& sFilePath &"')" conn.execute(sql) if ParentID>0 then '更新其父類的子欄目數(shù) conn.execute("update ArticleClass set child=child+1 where ClassID="& nParentID) '更新該欄目排序以及大于本需要和同在本分類下的欄目排序序號(hào) if prevOrderID<>"" then conn.execute("update ArticleClass set OrderID=OrderID+1 where rootid=" & nRootid & " and OrderID>"& prevOrderID &" and ClassID<>"& nClassID) end if end if End Sub Public Function FEditCheck() '類別修改檢查函數(shù),結(jié)果為0表示通過檢查,為1表示有錯(cuò)誤發(fā)生,有錯(cuò)誤發(fā)生時(shí)退出函數(shù),將錯(cuò)誤信息寫入錯(cuò)誤變量ErrorStr dim temprs FEditCheck=0 if nClassID="" then '類別id為空 FEditCheck=1 ErrorStr="類別id不能為空!" exit Function else if sClassName="" then '類名為空 FEditCheck=1 ErrorStr="類名不能為空!" exit Function else if nParentID<>0 then set temprs=conn.execute("select ClassID From ArticleClass where ClassID=" & nParentID) '父類別不存在 if temprs.eof then FAddCheck=1 ErrorStr="所屬類別不存在或已經(jīng)被刪除!" exit Function else set rs=conn.execute("select ClassID from ArticleClass where ClassName='"& sClassName &"' and ClassID<>"& nClassID &"and ParentID="& nParentID) if not rs.eof then '類名重復(fù) FEditCheck=1 ErrorStr="類名重復(fù)!" exit Function end if set rs=nothing end if set temprs=nothing end if end if end if End Function Public Sub SEdit() '類別修改 sql="update ArticleClass set ClassName='"& sClassName &"',FilePath='"& sFilePath &"' where ClassID="& nClassID conn.execute(sql) End Sub Public Function FDeleteCheck() '類別刪除檢查函數(shù),結(jié)果為0表示通過檢查,為1表示有錯(cuò)誤發(fā)生,有錯(cuò)誤發(fā)生時(shí)退出函數(shù),將錯(cuò)誤信息寫入錯(cuò)誤變量ErrorStr FDeleteCheck=0 '這里刪除沒有寫級(jí)聯(lián)刪除文章部分的代碼,刪除時(shí)應(yīng)該級(jí)聯(lián)刪除 if nClassID="" then FDeleteCheck=1 ErrorStr="要?jiǎng)h除的類別id不能為空!" exit Function else set rs=conn.execute("select Child from ArticleClass where ClassID="& nClassID) if rs.bof and rs.eof then FDeleteCheck=1 ErrorStr="類別不存在或者已經(jīng)被刪除!" exit Function else if trim(rs("Child"))>0 then FDeleteCheck=1 ErrorStr="該類別含有子類別,請(qǐng)刪除其子類別后再進(jìn)行刪除本類別的操作!" exit Function end if end if end if End Function Public Sub SDelete() if nDepth>0 then '修改父id孩子數(shù) conn.execute("update ArticleClass set child=child-1 where child>0 and ClassID=" & nParentID) end if sql="delete from ArticleClass where ClassID="& nClassID conn.execute(sql) End Sub Public Function FErrStr() FErrStr=ErrorStr End Function End Class %> index.asp <%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%> <% '作者站點(diǎn):www.guaishi.org '郵箱:guaishiorg@126.com 'QQ:514777880 Session.CodePage=65001 Response.Charset = "utf-8" %> <!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=utf-8" /> <title></title> <style type="text/css"> body{margin:0;padding:0;font-size:12px; background-color:#FFFFFF;} ul{ list-style-type:none; margin:0 0 0 20px; padding:0;} li{ white-space:nowrap; padding:0;} .childdiv{ background:url(images/dot.gif);background-repeat:repeat-y;} span { cursor:pointer;} </style> <script type="text/javascript"> var xmlHttp; //定義一個(gè)全局變量 var currentID=1;//設(shè)置當(dāng)前選中ID,如果此ID不存在則會(huì)發(fā)生js錯(cuò)誤 //類別顯示主函數(shù) //cid--子類別所在層id //id --類別id //pid--[+]和[-]圖標(biāo)id //fid--類別圖標(biāo)id function DivDisplay(cid,id,pid,fid) {