Imports System.Data.SqlTypes Imports System.Data.SqlClient Imports DevComponents Public Class clsUebersichtre #Region "Deklarationen" Dim WithEvents evh As _Generic_Event_Handler.Generic_Event_Handler = Globals.Generic_Event_Handler Dim treedata As New DataSet Dim TreeaufbauSuche As Boolean = False Dim TreeaufbauNr As Integer = 0 Dim FoundNode As Integer = 0 Dim Searchstring As String = "" Public Treesearch As New AdvTree.AdvTree Dim Datenklasse As New _DataClass.DataClass #End Region #Region "Tree" Public Sub Load_Treeview(ByRef tree As DevComponents.AdvTree.AdvTree) Globals.treedata_for_search.Rows.Clear() treedata.Tables.Clear() TreeaufbauNr = -1 For Each dr As DataRow In Globals.Objekt.Rows If dr.Item("Aktiv") = True Then Load_Treedata(dr.Item("Bezeichnung")) If Not (treedata Is Nothing) Then Dim oView As DataView = treedata.Tables(0).DefaultView Dim oTable As DataTable = oView.Table Dim oDS As DataSet = New DataSet() oDS.Tables.Add(oTable.Copy()) If oDS.Relations.Contains("SelfRefenceRelation") = False Then oDS.Relations.Add("SelfRefenceRelation", _ oDS.Tables(0).Columns("id"), _ oDS.Tables(0).Columns("Parentid")) End If oTable.Dispose() oTable = Nothing LoadTreeView(oDS, tree) oDS.Dispose() oDS = Nothing End If End If Next End Sub Public Function Load_Treedata(ByVal datatype As String) As DataTable treedata.Tables.Clear() Dim selectcommand As New SqlCommand Dim connection As New SqlConnection() Dim da As New SqlDataAdapter("", connection) selectcommand.CommandText = "sp_get_struktur" selectcommand.Parameters.Add("@Root", SqlDbType.VarChar) selectcommand.Parameters(0).Value = datatype selectcommand.CommandType = CommandType.StoredProcedure selectcommand.Connection = connection Try connection.ConnectionString = Globals.sConnectionString connection.Open() da.SelectCommand = selectcommand da.Fill(treedata, "Tree") If treedata_for_search.Rows.Count < 1 Then For Each c As DataColumn In treedata.Tables(0).Columns If c.ColumnName = "ErweiterteSuche" Then Dim dc As New DataColumn dc.ColumnName = "ErweiterteSuche" dc.DataType = System.Type.GetType("System.String") dc.DefaultValue = " " Try Globals.treedata_for_search.Columns.Add(dc) Catch End Try Else Try Globals.treedata_for_search.Columns.Add(c.ColumnName) Catch End Try End If Next End If For Each row As DataRow In treedata.Tables(0).Rows Globals.treedata_for_search.ImportRow(row) Next Catch ex As Exception 'MsgBox(ex.Message) Finally connection.Close() da.Dispose() selectcommand.Dispose() End Try End Function Public Function Update_TreeSearch(ByVal fnkt As String, ByVal Keyvalue As String, ByVal treestruktur As DevComponents.AdvTree.AdvTree) If Globals.Update_Treedata_for_search = False Then 'Exit Function End If treedata_for_search.Rows.Clear() GetAllNodes(treestruktur) Globals.Update_Treedata_for_search = False End Function Protected Function GetAllNodes(ByVal treestruktur As DevComponents.AdvTree.AdvTree) As List(Of TreeNode) Dim allNodes As List(Of TreeNode) = New List(Of TreeNode)() ' start recursion for each root node of the treeview For i As Integer = 0 To TreeStruktur.Nodes.Count - 1 GetAllNodes(TreeStruktur.Nodes(i), allNodes) Next Return allNodes End Function Protected Sub GetAllNodes(ByVal subRoot As DevComponents.AdvTree.Node, ByVal allNodes As List(Of TreeNode)) ' check for null (this can be removed since within th If (subRoot Is Nothing) Then Exit Sub End If ' add subroot Dim r As DataRow r = treedata_for_search.NewRow r.Item(0) = subRoot.Tag Try r.Item(1) = subRoot.Parent.Tag Catch r.Item(1) = 0 End Try r.Item(2) = subRoot.Text r.Item(3) = subRoot.ImageIndex treedata_for_search.Rows.Add(r) 'allNodes.Add(subRoot) ' add all it's children For i As Integer = 0 To subRoot.Nodes.Count - 1 GetAllNodes(subRoot.Nodes(i), allNodes) Next End Sub ''' ''' Tree aufbauen ''' ''' ''' ''' Private Sub LoadTreeView(ByVal oDS As DataSet, ByRef oTreeview As DevComponents.AdvTree.AdvTree) 'Dim oTreeView As TreeView = New TreeView() Dim oDataRow As DataRow For Each oDataRow In oDS.Tables(0).Rows If Not oDataRow.IsNull("Parentid") Then If oDataRow.Item("Parentid") = 0 Then 'If oDataRow.IsNull("Parentid") Then Dim oNode As New DevComponents.AdvTree.Node oNode.Text = Trim(oDataRow("Bezeichnung").ToString()) Try 'oNode.ToolTipText = Trim(oDataRow("ErweiterteSuche").ToString) Catch End Try oNode.Tag = oDataRow("id").ToString oNode.ImageIndex = oDataRow("ImageIndex") oTreeview.Nodes.Add(oNode) RecursivelyLoadTree(oDataRow, oNode) End If End If Next oDataRow oDS.Dispose() oDS = Nothing End Sub ''' ''' Child-Nodes hinzufügen ''' ''' ''' ''' Private Sub RecursivelyLoadTree(ByVal oDataRow As DataRow, ByRef oNode As DevComponents.AdvTree.Node) Dim oChildRow As DataRow For Each oChildRow In oDataRow.GetChildRows("SelfRefenceRelation") Dim oChildNode As New DevComponents.AdvTree.Node oChildNode.Text = Trim(oChildRow("Bezeichnung").ToString()) oChildNode.Tag = oChildRow("id").ToString() oChildNode.ImageIndex = oChildRow("ImageIndex") oNode.Nodes.Add(oChildNode) RecursivelyLoadTree(oChildRow, oChildNode) Next oChildRow End Sub Public Function FindNode(ByVal _nodeCollection As AdvTree.NodeCollection, ByVal SearchVal As Integer, ByVal SearchString As String) As AdvTree.Node Dim tmpNode As AdvTree.Node For Each _child As AdvTree.Node In _nodeCollection If _child.Tag = SearchVal Then Return _child End If ' If InStr(UCase(_child.Text), UCase(SearchString)) > 0 Then ' Return _child ' End If tmpNode = FindNode(_child.Nodes, SearchVal, SearchString) If Not tmpNode Is Nothing Then Return tmpNode End If Next Return Nothing End Function Public Function TreeView_GetRootNode(objTV As AdvTree.AdvTree, node As AdvTree.Node) As _DataClass.DataClass.Struktur_Selectiontype Try If node.Parent Is Nothing Then Return Datenklasse.Get_Selectiontype(node.Text) Else Dim parent As AdvTree.Node = node.Parent While Not parent.Parent Is Nothing parent = parent.Parent End While Return Datenklasse.Get_Selectiontype(Trim(parent.Text)) End If Catch End Try End Function Public Function Init_Search() FoundNode = 0 Searchstring = "" Me.Treesearch.Nodes.Clear() End Function Public Function SearchNode(ByRef tree As AdvTree.AdvTree, ByVal SearchString As String) As AdvTree.Node 'Return tree.FindNodeByCellText(SearchString) Me.Treesearch.Nodes.Clear() For Each dr As DataRow In treedata_for_search.Rows 'InStr(UCase(SearchString), UCase(dr.Item("Bezeichnung"))) If InStr(UCase(dr.Item("Bezeichnung")), UCase(SearchString)) > 0 Or InStr(UCase(dr.Item("ErweiterteSuche")), UCase(SearchString)) > 0 Then Dim tn As New AdvTree.Node tn.Text = dr.Item("Bezeichnung") tn.Tag = dr.Item("id") Treesearch.Nodes.Add(tn) End If Next Return FindFirst(tree) End Function Public Function FindFirst(ByRef Tree As AdvTree.AdvTree) As AdvTree.Node Try If Me.Treesearch.Nodes.Count > 0 Then Me.Treesearch.SelectedNode = Me.Treesearch.Nodes(0) Return FindNode(Tree.Nodes, Treesearch.SelectedNode.Tag, "") Catch End Try End Function Public Function FindNextNode(ByRef tree As AdvTree.AdvTree) As AdvTree.Node Try Treesearch.SelectedNode = Treesearch.SelectedNode.NextNode If Treesearch.SelectedNode Is Nothing Then Return FindFirst(tree) End If Return Me.FindNode(tree.Nodes, Treesearch.SelectedNode.Tag, "") Catch ex As Exception End Try End Function Public Function FindPrevNode(ByRef tree As AdvTree.AdvTree) As AdvTree.Node Try Treesearch.SelectedNode = Treesearch.SelectedNode.PrevNode If Treesearch.SelectedNode Is Nothing Then Return FindLastNode(tree) End If Return Me.FindNode(tree.Nodes, Treesearch.SelectedNode.Tag, "") Catch ex As Exception End Try End Function Public Function FindLastNode(ByRef tree As AdvTree.AdvTree) As AdvTree.Node Try Treesearch.SelectedNode = Treesearch.Nodes(Treesearch.Nodes.Count - 1) Return Me.FindNode(tree.Nodes, Treesearch.SelectedNode.Tag, "") Catch ex As Exception End Try End Function Public Function Get_DBObjektname(ByVal type As Integer) As String For Each dr As DataRow In Globals.Objekt.Rows If dr.Item("Objektnr") = type Then Return dr.Item("DBOBject") Exit For End If Next End Function #End Region #Region "EVH-Ereignisse" Private Sub evh_Strucktur_Changed(ByVal keyvalue As Integer, ByVal treehanlde As Integer) Handles evh.Strucktur_Changed Try Catch End Try End Sub #End Region End Class