手机
当前位置:查字典教程网 >编程开发 >ASP教程 >asp下生成目录树结构的类
asp下生成目录树结构的类
摘要:关于生成目录树结构的类本程序有两文件test.asp和tree.asp还有一些图标文件1。test.asp调用类生成树代码如下tree2。t...

关于生成目录树结构的类

本程序有两文件test.asp和tree.asp还有一些图标文件

1。test.asp调用类生成树代码如下

<%@Language=VBScript%>

<html>

<head>

<linkrel="stylesheet"href="tree.css">

<title>tree</title>

</head>

<>

<%

'========================================

'BUILDINGATREEPROGRAMATICALLY

'========================================

'Thisapproachwouldbebestsuitedforbuilding

'dynamictreesusingFor..Nextloopsandsuch.

SetMyTree2=NewTree

MyTree2.Top=10

MyTree2.Left=10

MyTree2.ExpandImage="plus.gif"

MyTree2.CollapseImage="minus.gif"

MyTree2.LeafImage="webpage.gif"

'Noticetheindentationusedtoreprensentthehierarchy

SetNode1=MyTree2.CreateChild("script")

SetSubNode1=Node1.CreateChild("server")

SetsecSubNode1=SubNode1.CreateChild("html")

secSubNode1.CreateChild"<AHREF=""http://127.0.0.1/"">asp</A>"

secSubNode1.CreateChild"<AHREF=""http://127.0.0.1/"">php</A>"

secSubNode1.CreateChild"<AHREF=""http://127.0.0.1/"">jsp</A>"

SetSubNode2=Node1.CreateChild("os")

SubNode2.CreateChild"<AHREF=""#"">winnt</A>"

SubNode2.CreateChild"<AHREF=""#"">win2000</A>"

SetNode2=MyTree2.CreateChild("Desktop")

Node2.CreateChild"<AHREF=""#"">AreaCodeLookup</A>"

Node2.CreateChild"<AHREF=""#"">ArinBasedWhoisSearch</A>"

Node2.CreateChild"<AHREF=""#"">WorldTimeZoneMap</A>"

MyTree2.Draw()

SetMyTree2=Nothing

%>

</BODY>

</HTML>

2。tree.asp类的定义代码如下

<%

'******************************************************

'Author:JacobGilley

'Email:avis7@airmail.net

'MyTerms:Youcanusethiscontrolinanywayyouseefit

'causeIhavenomeanstoenforceanyguidelines

'orBSthatmostdevelopersthinktheycanget

'youtoagreetobyspoutingoutwordslike

'"intellectualproperty"and"TheCodeGods".

'-VivalaMicrosoft!

'******************************************************

DimgblTreeNodeCount:gblTreeNodeCount=1

ClassTreeNode

PublicValue

PublicExpandImage

PublicCollapseImage

PublicLeafImage

PublicExpanded

PrivatemszName

PrivatemcolChildren

PrivatembChildrenInitialized

PublicPropertyGetChildCount()

ChildCount=mcolChildren.Count

EndProperty

PrivateSubClass_Initialize()

mszName="node"&CStr(gblTreeNodeCount)

gblTreeNodeCount=gblTreeNodeCount+1

mbChildrenInitialized=False

Expanded=False

EndSub

PrivateSubClass_Terminate()

IfmbChildrenInitializedAndIsObject(mcolChildren)Then

mcolChildren.RemoveAll()

SetmcolChildren=Nothing

EndIf

EndSub

PrivateSubInitChildList()

SetmcolChildren=Server.CreateObject("Scripting.Dictionary")

mbChildrenInitialized=True

EndSub

PrivateSubLoadState()

IfRequest(mszName)="1"OrRequest("togglenode")=mszNameThen

Expanded=True

EndIf

EndSub

PublicFunctionCreateChild(szValue)

IfNotmbChildrenInitializedThenInitChildList()

SetCreateChild=NewTreeNode

CreateChild.Value=szValue

CreateChild.ExpandImage=ExpandImage

CreateChild.CollapseImage=CollapseImage

CreateChild.LeafImage=LeafImage

mcolChildren.AddmcolChildren.Count+1,CreateChild

EndFunction

PublicSubDraw()

LoadState()

Response.Write"<tableborder=""0"">"&vbCrLf

Response.Write"<tr><td>"&vbCrLf

IfExpandedThen

Response.Write"<ahref=""javascript:collapseNode('"&mszName&"')""><imgsrc="""&CollapseImage&"""border=""0""></a>"&vbCrLf

ElseIfNotmbChildrenInitializedThen

Response.Write"<imgsrc="""&LeafImage&"""border=0>"&vbCrLf

Else

Response.Write"<ahref=""javascript:expandNode('"&mszName&"')""><imgsrc="""&ExpandImage&"""border=""0""></a>"&vbCrLf

EndIf

Response.Write"</td>"&vbCrLf

Response.Write"<td>"&Value&"</td></tr>"&vbCrLf

IfExpandedThen

Response.Write"<inputtype=""hidden""name="""&mszName&"""value=""1"">"&vbCrLf

IfmbChildrenInitializedThen

Response.Write"<tr><td></td>"&vbCrLf

Response.Write"<td>"&vbCrLf

ForEachChildNodeInmcolChildren.Items

ChildNode.Draw()

Next

Response.Write"</td>"&vbCrLf

Response.Write"</tr>"&vbCrLf

EndIf

EndIf

Response.Write"</table>"&vbCrLf

EndSub

EndClass

ClassTree

PublicTop

PublicLeft

PublicExpandImage

PublicCollapseImage

PublicLeafImage

PrivatemszPosition

PrivatemcolChildren

PublicPropertyLetAbsolute(bData)

IfbDataThenmszPosition="absolute"ElsemszPosition="relative"

EndProperty

PublicPropertyGetAbsolute()

Absolute=CBool(mszPosition="absolute")

EndProperty

PrivateSubClass_Initialize()

SetmcolChildren=Server.CreateObject("Scripting.Dictionary")

mnTop=0

mnLeft=0

mszPosition="absolute"

EndSub

PrivateSubClass_Terminate()

mcolChildren.RemoveAll()

SetmcolChildren=Nothing

EndSub

PublicFunctionCreateChild(szValue)

SetCreateChild=NewTreeNode

CreateChild.Value=szValue

CreateChild.ExpandImage=ExpandImage

CreateChild.CollapseImage=CollapseImage

CreateChild.LeafImage=LeafImage

mcolChildren.AddmcolChildren.Count+1,CreateChild

EndFunction

PublicSubLoadTemplate(szFileName)

DimobjWorkingNode

DimcolNodeStack

DimfsObj,tsObj

DimszLine

DimnCurrDepth,nNextDepth

SetcolNodeStack=Server.CreateObject("Scripting.Dictionary")

SetfsObj=CreateObject("Scripting.FileSystemObject")

SettsObj=fsObj.OpenTextFile(szFileName,1)

nCurrDepth=0

WhileNottsObj.AtEndOfLine

nNextDepth=1

szLine=tsObj.ReadLine()

IfnCurrDepth=0Then

SetobjWorkingNode=CreateChild(Trim(szLine))

nCurrDepth=1

Else

WhileMid(szLine,nNextDepth,1)=vbTabOrMid(szLine,nNextDepth,1)=""

nNextDepth=nNextDepth+1

WEnd

IfnNextDepth>1ThenszLine=Trim(Mid(szLine,nNextDepth))

IfszLine<>""Then

IfnNextDepth>nCurrDepthThen

IfcolNodeStack.Exists(nCurrDepth)Then

SetcolNodeStack.Item(nCurrDepth)=objWorkingNode

Else

colNodeStack.AddnCurrDepth,objWorkingNode

EndIf

SetobjWorkingNode=objWorkingNode.CreateChild(szLine)

nCurrDepth=nCurrDepth+1

ElseIfnNextDepth<=nCurrDepthThen

IfnNextDepth>1Then

nNextDepth=nNextDepth-1

WhileNotcolNodeStack.Exists(nNextDepth)AndnNextDepth>1

nNextDepth=nNextDepth-1

WEnd

SetobjWorkingNode=colNodeStack.Item(nNextDepth)

SetobjWorkingNode=objWorkingNode.CreateChild(szLine)

nNextDepth=nNextDepth+1

Else

SetobjWorkingNode=CreateChild(szLine)

EndIf

nCurrDepth=nNextDepth

EndIf

EndIf

EndIf

WEnd

tsObj.Close()

SettsObj=Nothing

SetfsObj=Nothing

colNodeStack.RemoveAll()

SetcolNodeStack=Nothing

EndSub

PublicSubDraw()

AddClientScript()

Response.Write"<divid=""treectrl""style=""left:"&Left&"px;top:"&Top&"px;position:"&mszPosition&";"">"&vbCrLf

Response.Write"<formname=""treectrlfrm""action="""&Request.ServerVariables("SCRIPT_NAME")&"""method=""get"">"&vbCrLf

Response.Write"<tableborder=""0"">"&vbCrLf

Response.Write"<tr><td>"&vbCrLf

ForEachChildNodeInmcolChildren.Items

ChildNode.Draw()

Next

Response.Write"</td></tr>"&vbCrLf

Response.Write"</table>"&vbCrLf

Response.Write"<inputtype=""hidden""name=""togglenode""value="""">"&vbCrLf

Response.Write"</form>"&vbCrLf

Response.Write"</div>"&vbCrLf

EndSub

PrivateSubAddClientScript()

%>

<scriptlanguage="JavaScript">

functionexpandNode(szNodeName)

{

if(document.layers!=null){

document.treectrl.document.treectrlfrm.togglenode.value=szNodeName;

document.treectrl.document.treectrlfrm.submit();

}

else{

document.all["treectrlfrm"].togglenode.value=szNodeName;

document.all["treectrlfrm"].submit();

}

}

functioncollapseNode(szNodeName)

{

if(document.layers!=null){

document.treectrl.document.treectrlfrm.elements[szNodeName].value=-1;

document.treectrl.document.treectrlfrm.submit();

}

else{

document.treectrlfrm.elements[szNodeName].value=-1;

document.treectrlfrm.submit();

}

}

</script>

<%

EndSub

EndClass

%>

【asp下生成目录树结构的类】相关文章:

asp缓存类

newasp中main类

asp简单文本计数器

ASP下操作Excel技术总结分析

asp中实现随机分组程序的代码

一个ACCESS数据库访问的类第1/3页

关于ASP生成伪参数技巧

Asp中代码与页面的分离

asp从缓存读数据实例

asp获取用户真实IP地址的方法

精品推荐
分类导航