Imports OrgChartObjects
Partial Class OrgChart_OrgChart
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not IsPostBack Then
' init objects
Dim uscpNode As OrgTreeNode = initTree()
' traverse the tree and draw on the page
'Dim rowChildArray As ArrayList = Nothing
Dim rowNodeArray As New ArrayList
rowNodeArray.Add(uscpNode)
Dim flag As Boolean = True
' while we still have nodes
While flag
' create a row
Dim tableRow As New TableRow()
' as we go, we will collect all the children of the next row
Dim nextRowChildren As ArrayList = Nothing
' for each node in this row
For i As Integer = 0 To rowNodeArray.Count - 1
' get the node
Dim node As OrgTreeNode = CType(rowNodeArray.Item(i), OrgTreeNode)
' check for its children
If node.Children IsNot Nothing Then
' if this node has children, collect them and save them
For Each child As Object In node.Children
If nextRowChildren Is Nothing Then
nextRowChildren = New ArrayList()
End If
nextRowChildren.Add(CType(child, OrgTreeNode))
Next
End If
' depending on the number of children in the next row,
' attempt to center this row
' for this row create a control and add it
Dim tableCell As New TableCell()
Dim nodeTable As Table = createOrgNodeControl(node)
tableCell.Controls.Add(nodeTable)
tableRow.Controls.Add(tableCell)
Next
Me.TableOrgChart.Controls.Add(tableRow)
If nextRowChildren IsNot Nothing Then
' if we have more children to add to the list, get them
' for next iteration
rowNodeArray.Clear()
rowNodeArray = nextRowChildren
Else
' clean up
rowNodeArray.Clear()
flag = False
End If
End While
End If
End Sub
Private Function createOrgNodeControl(ByVal treeNode As OrgTreeNode) As Table
Dim myTable As New Table
myTable.ID = treeNode.Name
myTable.SkinID = "OrgChartNode"
Dim tableRow0 As New TableRow
Dim tableCell00 As New TableCell
Dim labelOrgName As New Label
labelOrgName.SkinID = "OrgNameLabel"
labelOrgName.Text = treeNode.Name
tableCell00.Controls.Add(labelOrgName)
tableRow0.Controls.Add(tableCell00)
myTable.Controls.Add(tableRow0)
If treeNode.MyPersonnel IsNot Nothing Then
For Each personnel As Personnel In treeNode.MyPersonnel
Dim tableRow As New TableRow
Dim tableCell As New TableCell
Dim personnelLabel As New Label
personnelLabel.SkinID = "PersonnelLabel"
personnelLabel.Text = personnel.Title & " " & personnel.Name
tableCell.Controls.Add(personnelLabel)
tableRow.Controls.Add(tableCell)
myTable.Controls.Add(tableRow)
Next
End If
If treeNode.Children IsNot Nothing Then
Dim tableRow1 As New TableRow
Dim tableCell01 As New TableCell
Dim tableCell02 As New TableCell
Dim expandLink As New HyperLink
Dim collapseLink As New HyperLink
expandLink.Text = "expand"
collapseLink.Text = "collapse"
Dim arguments As String = String.Empty
If treeNode.Children IsNot Nothing Then
For i As Integer = 0 To treeNode.Children.Count - 1
arguments += "'" & CType(treeNode.Children.Item(i), OrgTreeNode).Name & "'"
If i < treeNode.Children.Count - 1 Then
arguments += ", "
End If
Next
End If
expandLink.NavigateUrl = "javascript:expand(" & arguments & ");"
collapseLink.NavigateUrl = "javascript:collapse(" & arguments & ");"
tableCell01.Controls.Add(expandLink)
tableCell02.Controls.Add(collapseLink)
tableRow1.Controls.Add(tableCell01)
tableRow1.Controls.Add(tableCell02)
myTable.Controls.Add(tableRow1)
End If
If treeNode.ParentId <> -1 Then
myTable.Style.Add("visibility", "hidden")
'Else
' myTable.Style.Add("visibility", "visible")
End If
Return myTable
End Function
Private Function initTree() As OrgTreeNode
Dim uscpNode As New OrgTreeNode()
' some object init code here
Return uscpNode
End Function
End Class