ASP tree map generation program connecting to the database (source code)

Source: Internet
Author: User

<% '****************************
'* * ***** generate a Program ********
'**** * ***********************
'suppose you have created an unitdatabase unittree, and the table is created in this database:
'Units (ID unit number integer is unique, name unit name string, upid superior unit number integer)
'Note: upid = 0 indicates that the unit is the root node unit.
'enter some data such as: (1, AA, 0) (2, AABB, 1) (3, AACC, 1) (4, aabb11, 2)
'to test the following program.
%>
<% 'create a database connection
set conn = server. createobject ("ADODB. connection ")
Conn. open "provider = sqloledb; Data Source = .; user ID = sa; Password =; database = unittree "
%>
<% 'subprocess: Generate tree chart subnode data
sub treenode (CODE)
sqlunit = "select ID, name "& _
" from units "& _
" where upid = "& code &" & _
"order by ID"
set rsunit = Conn. execute (sqlunit)
do while not rsunit. EOF
response. write ("Node" & rsunit ("ID") & "= appendchild (" & "Node" & code & ", foldernode ('" & rsunit ("name ") & "','" & rsunit ("ID") & "', 0)" & CHR (10)
call treenode (rsunit ("ID "))
rsunit. movenext
loop

End sub
%>
<HTML>
<Head>
<Title> drill analysis </title>
<Script language = "JavaScript">
/***************************** Generate tree chart data ****** ***************************/
Function generatetree ()
{
// Generate tree chart data
// ----- VBScript -----
<%
''Display Unit
Sqlunit0 = "select ID, name "&_
"From units "&_
"Where upid = 0 "&_
"Order by ID"
Set rsunit0 = conn. Execute (sqlunit0)
// Root node folderstree
Response. write ("folderstree = foldernode ('" & rsunit0 ("name") & "', '" & rsunit0 ("ID") & "', 1) "& CHR (10 ))
Response. Write ("Node" & rsunit0 ("ID") & "= folderstree" & CHR (10 ))
Call treenode (rsunit0 ("ID") // subnode data

%>
}
/**************************** The number of generated trees ends ******* ************************/
</SCRIPT>

<Script language = "JavaScript">
/************************ Related functions ************* ********************/
// Generate a node
Function foldernode (name, value, flagopen)
{
VaR arrayaux

Arrayaux = new array
Arrayaux [0] = flagopen // node close 0 or open 1
Arrayaux [1] = value //
Arrayaux [2] = Name // name

Return arrayaux
}

// Add the child in arrayaux [3]... [N]
Function appendchild (parent, child)
{
Parent [Parent. Length] = Child
Return child
}

// Draw nodes
// Parameter foldersnode: Node
// DOC: Document Object
// Level: node level
// Lastnode: whether it is the End Node
// Leftside: Image
Function redrawnode (foldersnode, Doc, level, lastnode, leftside)
{
Filename = "content. asp" // sets the hyperlink file, which can be rewritten according to your situation ...............

VaR J = 0
VaR I = 0

Doc. Write ("<Table border = 0 cellspacing = 0 cellpadding = 0> ")
Doc. Write ("<tr> <TD valign = middle nowrap> ")

Doc. Write (leftside)
**************************** **********/

If (level> 0) // not the root node
{
If (lastnode) // The Last Node
{
If (foldersnode. length> 3) // you have children.
{
If (foldersnode [0]) // and open
{
Doc. Write ("<a href = 'javascript: Top. openbranch (\" "+ foldersnode [2] +" \ ") '> ")
Doc. Write (" </a> ")
}
Else
{// But close
Doc. Write ("<a href = 'javascript: Top. openbranch (\" "+ foldersnode [2] +" \ ") '> ")
Doc. Write (" </a> ")
}
}
Else // no child
Doc. Write (" ")

Leftside = leftside + "

}
Else // non-last Node
{
If (foldersnode. length> 3) // you have children.
{
If (foldersnode [0]) // and open
{
Doc. Write ("<a href = 'javascript: Top. openbranch (\" "+ foldersnode [2] +" \ ") '> ")
Doc. Write (" </a> ")
}
Else
{// But close
Doc. Write ("<a href = 'javascript: Top. openbranch (\" "+ foldersnode [2] +" \ ") '> ")
Doc. Write (" </a> ")
}
}
Else // no child
Doc. Write (" ")

Leftside = leftside + "}

/****** Hand icons and hyperlinks **********/
Doc. Write ("<a href = '" + filename + "? Id = "+ foldersnode [1] +" & name = "+ foldersnode [2] +" 'target = folderframe> </a> ")
/******** Name and hyperlink ********/
Doc. Write ("<TD valign = middle align = left nowrap> ")
Doc. Write ("<a href = '" + filename + "? Id = "+ foldersnode [1] +" & name = "+ foldersnode [2] +" 'target = folderframe> <font size = 2 face = 'body'> "+ foldersnode [2] + "</font> </a> ")
// The above hyperlink provides the querystring value of ID and name ..........................................
}
Else // Root Node
{
/****** Hand icons and hyperlinks **********/
Doc. Write ("<a href = '" + filename + "? Id = "+ foldersnode [1] +" & name = "+ foldersnode [2] +" 'target = folderframe> </a> ")
/******** Name and hyperlink ********/
Doc. Write ("<TD valign = middle align = left nowrap> ")
Doc. Write ("<a href = '" + filename + "? Id = "+ foldersnode [1] +" & name = "+ foldersnode [2] +" 'target = folderframe> <font size = 2 face = 'body'> "+ foldersnode [2] + "</font> </a> ")
}

Doc. Write ("</table> ")
//////////////////////////////////////// ///////////////
If (foldersnode. length> 3 & foldersnode [0]) // if you have a child and open it, the node is displayed recursively.
{
Level = level + 1
For (I = 3; I <foldersnode. length; I ++)
If (I = foldersnode. Length-1)
Redrawnode (foldersnode [I], Doc, level, 1, leftside)
Else
Redrawnode (foldersnode [I], Doc, level, 0, leftside)
}
}

// The response is called by openbranch when the user clicks the hierarchical +/-number.
Function clickonfolderrec (foldersnode, Foldername)
{
VaR I = 0

If (foldersnode [2] = Foldername)
{
If (foldersnode [0]) // if it is enabled, disable it
Foldersnode [0] = 0
Else
Foldersnode [0] = 1
}
Else
{
For (I = 3; I <foldersnode. length; I ++)
Clickonfolderrec (foldersnode [I], Foldername)
}
}

// Open or close the node (response when the user clicks the hierarchical +/-number)
Function openbranch (branchname)
{

Clickonfolderrec (folderstree, branchname)
Timeoutid = setTimeout ("redrawtree ()", 100)
}

// Display the tree chart
Function redrawtree ()
{
VaR Doc = top.treeframe.w.20.doc ument
// Record the current scroll bar position
Posx = Doc. Body. scrollleft
Posy = Doc. Body. scrolltop

Doc. open ()
Doc. Write ("<body link = '# 0000ff 'vlink =' # 0000ff 'alink = '# ff0000' bgcolor = 'white'> ")
Redrawnode (folderstree, Doc, 0, 1 ,"")
Doc. Close ()

Doc. Body. scrollleft = posx
Doc. Body. scrolltop = posy
}

// The response function when the webpage is loaded
Function initializetree ()
{
Generatetree ()
Redrawtree ()
}
/*********************** Related function end ************* ************/
</SCRIPT>
</Head>

<Frameset Cols = "220, *" onLoad = "initializetree ()" framespacing = "1">
<Frame src = "pleft.htm" name = "treeframe" target = "_ Self" scrolling = "Auto">
<Frame src = "pright.htm" name = "folderframe" scrolling = "Auto">
</Frameset>

</Html>
<%
'The above program passed the test under win2000server + iis5.0 + sqlserver2000.
'================================================ ============================
'====== Author: Xia chuntao E-mail: Bluesky_521@yeah.net ======
'================================================ ============================
%>

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.