Rank: Member
Groups: Member
Joined: 2/2/2004(UTC) Posts: 2
|
Thanks for your advice, I've managed to get it working both on my SQL Hosting Service and also my Local Server for which I use Access as the database. In the end I found that to convert my existing data to utilise your existing script was easier than I thought, so now Im running your Original Script for my SQL connection and a modified script for my Access connection. For any of your customers who want to use this script to connect to Microsoft Access Database I have included the modified script below. Simply replace the original TOCdata.aspx file supplied in the download with this script to connect to an access database. Once again, Many thanks for your help Best Regards Doc Code:<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.OleDB" %>
<%--
'********************************************************************************
'Aurigma (c) January 2004
'Fedor Skvortsov, fedor@aurigma.com
'MicroSoft Access 2000 OleDb Connect Version
'********************************************************************************
--%>
<script language="VB" runat="server">
' Jet Oledb connection - Where Access Database is located at Root/deeptree3/database/article.mdb
Dim strConnectionString as String = "Provider=Microsoft.Jet.OLEDB.4.0;" & "Data Source="&server.mappath("/deeptree3/database/article.mdb;")
Private intID As Integer
Private strPath As String
Private arrExpandedNodes As ArrayList
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Response.Write("<html>" & vbNewLine)
Response.Write(" <head>" & vbNewLine)
Response.Write(" <meta http-equiv=""Content-Type"" content=""text/html;charset=windows-1251"">" & vbNewLine)
Response.Write(" <" & "script language=""javascript"">" & vbNewLine)
Response.Write("//Node class" & vbNewLine)
Response.Write("function node(name, href, icon, target, src, selected, children){" & vbNewLine)
Response.Write(" this.name = name;" & vbNewLine)
Response.Write(" this.href = href;" & vbNewLine)
Response.Write(" this.icon = icon;" & vbNewLine)
Response.Write(" this.target = target;" & vbNewLine)
Response.Write(" this.src = src;" & vbNewLine)
Response.Write(" this.selected = selected;" & vbNewLine)
Response.Write(" this.children = children;" & vbNewLine)
Response.Write("}" & vbNewLine)
Try
intID = CInt(Request.QueryString("id"))
Catch
intID = 0
End Try
strPath = Request.QueryString("path")
'Display only one level deep or process TOC synchronizing
If strPath <> "" Then
SynchronizeTree()
Else
BuildTree(-1, 0)
End If
Response.Write("//Call buildTree" & vbNewLine)
Response.Write("window.parent.buildTree(oNodes0);" & vbNewLine)
Response.Write(" </" & "script>" & vbNewLine)
Response.Write(" </head>" & vbNewLine)
Response.Write(" <body>" & vbNewLine)
Response.Write(" </body>" & vbNewLine)
Response.Write("</html>" & vbNewLine)
End Sub
Public Sub SynchronizeTree()
'Open database
Dim MyConnection As New OleDbConnection(strConnectionString)
MyConnection.Open()
Dim MyCommand As OleDbCommand
'Get ID of article with specified path
MyCommand = New OleDbCommand("SELECT Article_ID FROM Article WHERE Article_Path=@Article_Path", MyConnection)
MyCommand.Parameters.Add("@Article_Path", strPath)
Dim objArticle_ID As Object = MyCommand.ExecuteScalar
'Raise from the children to the root nodes
arrExpandedNodes = New ArrayList()
MyCommand.CommandText = "SELECT Article_Parent FROM Article WHERE Article_ID=@Article_ID"
MyCommand.Parameters.Clear
MyCommand.Parameters.Add("@Article_ID", "@Article_ID")
While (Not IsNothing(objArticle_ID)) And (Not Convert.IsDBNull(objArticle_ID)) And _
(arrExpandedNodes.Count < 20)
arrExpandedNodes.Add(CInt(objArticle_ID))
MyCommand.Parameters("@Article_ID").Value = CInt(objArticle_ID)
objArticle_ID = MyCommand.ExecuteScalar
End While
If arrExpandedNodes.Count = 0 Or arrExpandedNodes.Count >= 20 Then
intID = 0
BuildTree(-1, 0)
Else
arrExpandedNodes.Reverse()
BuildTree(0, 0)
End If
'Close database
MyConnection.Close()
End Sub
'Index specifies Index in arrExpandedNodes array. If Index = -1 then it doesn't applies
Sub BuildTree(ByVal Index As Integer, ByVal intJavascriptId1 As Integer)
'Level of tree
Response.Write("var oNodes" & intJavascriptID1 & "=new Array();" & vbNewLine)
Dim MyCommand As OleDbCommand
Dim MyConnection As OleDbConnection = New OleDbConnection(strConnectionString)
MyConnection.Open()
Dim myReader As OleDbDataReader
Dim strSQL As String
Try
strSQL = "SELECT Article_ID, Article_Title, Article_HasChildren, Article_Path FROM Article WHERE Article_Parent"
If Index <> -1 Then
If Index = 0 Then
strSQL = strSQL & " IS NULL"
Else
strSQL = strSQL & "=" & arrExpandedNodes(Index - 1)
End If
Else
If intID <> 0 Then
strSQL = strSQL & "=" & CStr(intID)
Else
strSQL = strSQL & " IS NULL"
End If
End If
strSQL = strSQL & " ORDER BY Article_Order"
MyCommand = New OleDBCommand(strSQL, MyConnection)
myReader = MyCommand.ExecuteReader()
Dim intJavascriptID2 As Integer = 0
Dim blnAttachSubtree As Boolean
While myReader.Read
blnAttachSubtree = False
Response.Write("oNodes" & intJavascriptID1 & "[" & intJavascriptID2 & "] = new node(""")
Response.Write(myReader.Item("Article_Title"))
Response.Write(""", """)
If Not Convert.IsDBNull(myReader.Item("Article_Path")) Then
Response.Write(myReader.Item("Article_Path"))
End If
Response.Write("""")
If myReader.Item("Article_HasChildren") Then
Response.Write(", ""folder"", ""Main""")
If Index <> -1 Then
If Index < arrExpandedNodes.Count - 1 Then
If arrExpandedNodes(Index) = CInt(myReader.Item("Article_ID")) Then
blnAttachSubtree = True
Else
Response.Write(", ""TOCData.aspx?id=" & myReader.Item("Article_ID") & """")
End If
Else
Response.Write(", ""TOCData.aspx?id=" & myReader.Item("Article_ID") & """")
End If
Else
Response.Write(", ""TOCData.aspx?id=" & myReader.Item("Article_ID") & """")
End If
Else
Response.Write(", ""item"", ""Main"", null")
End If
If Index <> -1 Then
If arrExpandedNodes(arrExpandedNodes.Count - 1) = CInt(myReader.Item("Article_ID")) Then
Response.Write(", true")
End If
End If
Response.Write(");" & vbNewLine)
If blnAttachSubtree Then
BuildTree(Index + 1, intJavascriptId1 + 1)
Response.Write("oNodes" & intJavascriptID1 & "[" & intJavascriptID2 & "].children = oNodes" & intJavascriptID1 + 1 & ";" & vbNewLine)
End If
intJavascriptID2 = intJavascriptID2 + 1
End While
Catch
Finally
myReader.Close()
MyConnection.Close()
End Try
End Sub
</script>
Edited by user Monday, December 28, 2009 2:50:51 PM(UTC)
| Reason: Not specified
|