Welcome Guest! You need to login or register to make posts.

Notification

Icon
Error

Options
Go to last post Go to first unread
Doc  
#1 Posted : Monday, February 02, 2004 8:20:00 AM(UTC)
Doc

Rank: Member

Groups: Member
Joined: 2/2/2004(UTC)
Posts: 2

Hi Guys, I've got a database (Access) of some 9,000+ Book & DVD categories for which I have been searching High & Low for a decent Tree Menuing system and due to the size of the data, thats also got good LoadOnDemand properties. After reviewing Numerous (20+) Menuing systems, I came across Deeptree :D and now I feel sure that this is the menu for my particular application. My problem is :( - How do I get my existing data into a format thats DeepTree friendly, preferably still retaining the data within a database structure rather than a directory structure on the server. My Current Database Schema is: ParentNode (Int) - refers to the Nodes parent BrowseNode (Int) - refers to the current node MenuValue (txt) - Whats Displayed on the menu MenuType (txt) - root, folder or document MenuLevel (int) - level within the tree 0 - 9 NodeUrl (txt) - Url of current Node inc folders Keywords (txt) - list of keywords to describe the node BrowseMode (txt) - specific item for my application I'm fairly new to programming in asp/javascript but if someone good give me a starting point, advice or point me in the right direction then Im sure that I can get this to work. Cheers guys Doc storemanager@superstorz.co.uk :D
Fedor  
#2 Posted : Monday, February 02, 2004 12:09:00 PM(UTC)
Fedor

Rank: Advanced Member

Groups: Member, Administration, Moderator
Joined: 7/28/2003(UTC)
Posts: 1,508

Thanks: 3 times
Was thanked: 49 time(s) in 48 post(s)
Hello, The sample which you downloaded use following table: Article_ID Article_Parent Article_Title Article_HasChildren Article_Path As you see: Article_ID = BrowseNode Article_Parent = BrowseNode Article_Title = MenuValue Article_HasChildren = MenuType Article_Path = NodeUrl So the easiest way is just modify in TOCData.aspx lines 73-76:
Code:
	MyCommand.CommandText = "SELECT Article_Parent FROM Article WHERE Article_ID=@Article_ID"
	MyCommand.Parameters.Clear
	MyCommand.Parameters.Add("@Article_ID", "@Article_ID")
to following one:
Code:
	MyCommand.CommandText = "SELECT ParentNode  FROM Article WHERE BrowseNode=@Article_ID"
	MyCommand.Parameters.Clear
	MyCommand.Parameters.Add("@Article_ID", "@Article_ID")
and lines 104-118:
Code:
        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"
to following one
Code:
        strSQL = "SELECT BrowseNode AS Article_ID, MenuValue AS Article_Title, MenuType, Article_Path FROM Article WHERE ParentNode AS "
        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"
Also you will have to change line 132 from:
Code:
			If myReader.Item("Article_HasChildren") Then
to following one:
Code:
			If myReader.Item("MenuType")="folder" Then
As you see the schema of your database and datbase used in script are very close, so I think it should be no problem to customize deep tree script for your needs. Fell free to ask me if you have any questions or problems.

Edited by user Thursday, December 20, 2007 6:52:54 PM(UTC)  | Reason: Not specified

Best regards, Fedor Skvortsov
Doc  
#3 Posted : Saturday, February 07, 2004 4:02:00 AM(UTC)
Doc

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, ÷ñÒ1814290429êÖ0õæ÷fedor@aurigma.com÷ñÒ1814290429êÖ1õæ÷
'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

Users browsing this topic
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.