#Region "树型目录生成"
''' <summary>
''' 生成树型目录
''' </summary>
''' <remarks></remarks>
Public Sub CreateTree()
Dim myTalbe As New DataTable
Dim control As New FundsFlowTypeController ' ModelInfoController为方法类
Dim li As New List(Of FundsFlowTypeInfo) 'ModelInfoInfo为实体类的名称
li = control.GetFundsFlowType '根据主键获取泛型集合
Dim len As Integer = 8
Dim xmlstr As String = ""
Dim sb As New StringBuilder(xmlstr)
Dim ht As New List(Of DictionaryEntry)
sb.Append("<?xml version='1.0' encoding='utf-8' ?>")
sb.Append("<a Text='" + li(0).FundsName + "' Value='" + li(0).TreeCode + "' >")
For i As Integer = 1 To li.Count - 1
If (i = li.Count - 1) Then
sb.Append("<a Text='" + li(i).FundsName + "' Value='" + li(i).TreeCode + "' ></a>")
If ht.Count = 0 Then
Exit For
End If
Dim index As Integer = ht.Count - 1
While index >= 0
Dim key As Integer = CType(ht.Item(index), DictionaryEntry).Key
sb.Append(ht(index).Value)
ht.RemoveAt(index)
index = index - 1
End While
Exit For
End If
If li(i + 1).TreeCode.Length > len Then '下一个节点长度大于当前节点时,当前节点不封闭
sb.Append("<a Text='" + li(i).FundsName + "' Value='" + li(i).TreeCode + "' >")
Dim dic As New DictionaryEntry
dic.Key = li(i).TreeCode.Length
dic.Value = "</a>"
ht.Add(dic)
ElseIf li(i + 1).TreeCode.Length = len Then '下一个节点长度等于当前节点时,当前节点封闭
sb.Append("<a Text='" + li(i).FundsName + "' Value='" + li(i).TreeCode + "'></a>")
Else
Dim nextlen As Integer = li(i + 1).TreeCode.Length
sb.Append("<a Text='" + li(i).FundsName + "' Value='" + li(i).TreeCode + "'></a>")
Dim index As Integer = ht.Count - 1
While index >= 0
Dim key As Integer = ht(index).Key
If key >= nextlen Then
sb.Append(ht(index).Value)
ht.RemoveAt(index)
Else
Exit While
End If
index = index - 1
End While
End If
len = li(i + 1).TreeCode.Length
Dim str As String = sb.ToString()
Next
sb.Append("</a>")
Dim mainstr = sb.ToString()
Dim XML As New XmlDataSource
XML.Data = mainstr
XML.EnableCaching = False
TrViewFundsType.DataSource = XML
TrViewFundsType.DataBind()
TrViewFundsType.Nodes(0).SelectAction = TreeNodeSelectAction.None
End Sub
#End Region
浙公网安备 33010602011771号