Imports C1.Win.C1TrueDBGrid Imports System Imports System.Data Imports System.Data.SqlTypes Imports System.Data.SqlClient Imports DevComponents.AdvTree Imports DevComponents Namespace TKB.VV.Lifecycle Public Class clslifeCycle Public Enum SelectionType nur_eingesetzt = 1 nur_nicht_eingesetzt = 2 alle = 3 End Enum Public Enum SingleMultiSelectionType SingleSelection = 1 MultiSelection = 2 End Enum Public IMGLIST As ImageList Sub New() Produkttypen = Stammdaten.Get_Stammdaten("LC_Produkttyp", "Bezeichnung") Produkttypen_Copy = Produkttypen.Copy Produkttypen_Copy.Rows.Clear() Dim dr As DataRow dr = Produkttypen_Copy.NewRow dr.Item(0) = -1 dr.Item(1) = "Alle" Produkttypen_Copy.Rows.Add(dr) For Each r As DataRow In Produkttypen.Rows dr = Produkttypen_Copy.NewRow dr.Item(0) = r("lc_produkttypnr") dr.Item(1) = r("Bezeichnung") Produkttypen_Copy.Rows.Add(dr) Next Produkttypen_Copy1 = Produkttypen_Copy.Copy End Sub #Region "Deklarationen" Private Stammdaten As New TKB.VV.Stammdaten.clsStammdaten Dim treedata As New DataSet Public Produkttypen As New DataTable Public Produkttypen_Copy As New DataTable Public Produkttypen_Copy1 As New DataTable Public Produkte As New DataTable #End Region #Region "Struktur" Public Sub Load_Treestrukutr(ByRef tree As AdvTree, ByVal selectiontype As SelectionType, Optional OnlyStructure As Boolean = False, Optional SelBox As Boolean = False, Optional SelTyp As Integer = 0) tree.Nodes.Clear() Get_Produkte(OnlyStructure, selectiontype) LoadTree(treedata, tree, SelBox, SelTyp) End Sub Public Function IstStruktur(ByVal Tag As Integer) As Boolean For Each r As DataRow In treedata.Tables(0).Rows Try If r("id") = Tag And r("IstStruktur") = True Then Return True End If Catch End Try Next Return False End Function Public Function IstCopy(ByVal Tag As Integer) As Boolean For Each r As DataRow In treedata.Tables(0).Rows Try If r("id") = Tag And r("copy") = 1 Then Return True End If Catch End Try Next Return False End Function Public Function Get_Originalid(ByVal Tag As Integer) As Integer For Each r As DataRow In treedata.Tables(0).Rows Try If r("id") = Tag Then Return r("Originalid") End If Catch End Try Next Return 0 End Function Public Function Get_Produkte(OnLyProdukte As Boolean, ByVal Selectiontype As SelectionType) As DataTable treedata.Tables.Clear() treedata_for_search.Rows.Clear() Dim selectcommand As New SqlCommand Dim connection As New SqlConnection() Dim da As New SqlDataAdapter("", connection) If OnLyProdukte Then selectcommand.CommandText = "sp_lc_get_Struktur" Else selectcommand.CommandText = "[sp_lc_get_Struktur_Auswahl]" selectcommand.Parameters.Add("SelectionType", SqlDbType.Int, 4) selectcommand.Parameters(0).Value = Selectiontype End If 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 treedata_for_search.Columns.Add(dc) Catch End Try Else Try 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 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 Get_Produktliste() As DataTable Produkte.Rows.Clear() Dim selectcommand As New SqlCommand Dim connection As New SqlConnection() Dim da As New SqlDataAdapter("", connection) selectcommand.CommandText = "sp_lc_get_produkte" selectcommand.CommandType = CommandType.StoredProcedure selectcommand.Connection = connection Try connection.ConnectionString = Globals.sConnectionString connection.Open() da.SelectCommand = selectcommand da.Fill(Produkte) Catch ex As Exception Finally connection.Close() da.Dispose() selectcommand.Dispose() End Try End Function #End Region #Region "Tree" Private Sub LoadTree(ByVal treedata As DataSet, ByRef tree As AdvTree, ByVal SelBox As Boolean, ByVal SelType As Integer) 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, SelBox, SelType) oDS.Dispose() oDS = Nothing End If End Sub Private Sub LoadTreeView(ByVal oDS As DataSet, ByRef oTreeview As AdvTree, ByVal SelBox As Boolean, ByVal SelType As Integer) '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") oNode.ImageIndex = oDataRow("ImageIndex") 'oNode.TagString = oDataRow("beschreibung").ToString If oDataRow("Copy") = 1 Then 'Dim cell As New DevComponents.AdvTree.Cell 'oNode.Cells.Add(cell) 'cell.Images.Image = Me.IMGLIST.Images(0) oNode.Style = oTreeview.Styles(2) End If If SelBox = True Then If oDataRow.Item("IstStruktur") = False Then oNode.CheckBoxVisible = True If SelType = 1 Then oNode.CheckBoxStyle = DotNetBar.eCheckBoxStyle.RadioButton End If End If oTreeview.Nodes.Add(oNode) RecursivelyLoadTree(oDataRow, oNode, oTreeview, SelBox, SelType) End If End If Next oDataRow oDS.Dispose() oDS = Nothing End Sub Private Sub RecursivelyLoadTree(ByVal oDataRow As DataRow, ByRef oNode As DevComponents.AdvTree.Node, ByRef oTreeview As AdvTree, ByVal SelBox As Boolean, ByVal SelType As Integer) 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") 'oChildNode.TagString = oChildRow("Beschreibung").ToString If oChildRow("Copy") = 1 Then 'Dim cell As New DevComponents.AdvTree.Cell 'oChildNode.Cells.Add(cell) 'cell.Images.Image = Me.IMGLIST.Images(0) oChildNode.Style = oTreeview.Styles(2) End If If SelBox = True Then If oChildRow.Item("IstStruktur") = False Then oChildNode.CheckBoxVisible = True If SelType = 1 Then oChildNode.CheckBoxStyle = DotNetBar.eCheckBoxStyle.RadioButton End If End If oNode.Nodes.Add(oChildNode) RecursivelyLoadTree(oChildRow, oChildNode, oTreeview, SelBox, SelType) Next oChildRow End Sub Public Function FindNode(ByVal _nodeCollection As DevComponents.AdvTree.NodeCollection, ByVal SearchVal As Integer, ByVal SearchString As String) As DevComponents.AdvTree.Node Dim tmpNode As DevComponents.AdvTree.Node For Each _child As DevComponents.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 FindNode_string(ByVal _nodeCollection As DevComponents.AdvTree.NodeCollection, ByVal SearchVal As Integer, ByVal SearchString As String) As DevComponents.AdvTree.Node Dim tmpNode As DevComponents.AdvTree.Node For Each _child As DevComponents.AdvTree.Node In _nodeCollection 'If _child.Tag = SearchVal Then ' ' Return _child ' End If If UCase(_child.Text) = UCase(SearchString) Then Return _child End If tmpNode = FindNode_string(_child.Nodes, SearchVal, SearchString) If Not tmpNode Is Nothing Then Return tmpNode End If Next Return Nothing End Function Dim foundnode As Integer = 0 Dim searchstring As String = "" Public Treesearch As New DevComponents.AdvTree.AdvTree Dim treedata_for_search As New DataTable Public Function Init_Search() FoundNode = 0 Searchstring = "" Me.Treesearch.Nodes.Clear() End Function Public Function SearchNode(ByRef tree As DevComponents.AdvTree.AdvTree, ByVal SearchString As String) As DevComponents.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("Beschreibung")), UCase(SearchString)) > 0 Then Dim tn As New DevComponents.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 DevComponents.AdvTree.AdvTree) As DevComponents.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 DevComponents.AdvTree.AdvTree) As DevComponents.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 DevComponents.AdvTree.AdvTree) As DevComponents.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 DevComponents.AdvTree.AdvTree) As DevComponents.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 Update_Treesearch(ByVal Tag As Integer, ByVal ptag As Integer, ByVal Bezeichnung As String, ByVal Beschreibung As String) Exit Function For Each r As DataRow In treedata_for_search.Rows If r.Item(0) = Tag Then r.Item(1) = 1 = ptag r.Item(2) = Bezeichnung r.Item(4) = Beschreibung End If Next End Function Dim Allnodes As List(Of String) = New List(Of String) Dim subnodes As List(Of String) = New List(Of String) Public Function Init_search(ByRef treeview As DevComponents.AdvTree.AdvTree) Me.treedata_for_search.Clear() Me.treedata_for_search.Columns.Clear() Me.treedata_for_search.Columns.Add("key") Me.treedata_for_search.Columns.Add("Bez") Allnodes.Clear() subnodes.Clear() Dim i As Integer For Each n As DevComponents.AdvTree.Node In treeview.Nodes subnodes = GetChildren(n) For i = 0 To subnodes.Count - 1 Allnodes.Add(subnodes(i)) Next Dim r As DataRow = treedata_for_search.NewRow r.Item(0) = n.Tag.ToString r.Item(1) = n.Text treedata_for_search.Rows.Add(r) Allnodes.Add(n.Tag + n.Text) Next End Function Function GetChildren(parentNode As DevComponents.AdvTree.Node) As List(Of String) Dim nodes As List(Of String) = New List(Of String) GetAllChildren(parentNode, nodes) Return nodes End Function Sub GetAllChildren(parentNode As DevComponents.AdvTree.Node, nodes As List(Of String)) For Each childNode As DevComponents.AdvTree.Node In parentNode.Nodes nodes.Add(childNode.Tag.ToString + childNode.Text) Dim r As DataRow = treedata_for_search.NewRow r.Item(0) = childNode.Tag.ToString r.Item(1) = childNode.Text treedata_for_search.Rows.Add(r) GetAllChildren(childNode, nodes) Next End Sub Public Sub Search_First(ByRef tree As DevComponents.AdvTree.AdvTree, ByVal key As Integer, searchtext As String) For Each r As DataRow In Me.treedata_for_search.Rows If UCase(r(1).ToString).IndexOf((UCase(searchtext))) > -1 Then tree.SelectedNode = Me.FindNode(tree.Nodes, r(0), r(0)) Exit Sub End If Next End Sub Public Sub Search_Last(ByRef tree As DevComponents.AdvTree.AdvTree, ByVal key As Integer, searchtext As String) Dim found As Integer = -1 For Each r As DataRow In Me.treedata_for_search.Rows If UCase(r(1).ToString).IndexOf((UCase(searchtext))) > -1 Then found = r(0) End If Next If found <> -1 Then tree.SelectedNode = Me.FindNode(tree.Nodes, found, found) End If End Sub Public Sub Search_next(ByRef tree As DevComponents.AdvTree.AdvTree, ByVal key As Integer, searchtext As String) Dim found As Boolean = False For Each r As DataRow In Me.treedata_for_search.Rows If r(0) = key Then found = True End If If found And r(0) <> key Then If UCase(r(1).ToString).IndexOf((UCase(searchtext))) > -1 Then tree.SelectedNode = Me.FindNode(tree.Nodes, r(0), r(0)) Exit Sub End If End If Next If found <> -1 Then tree.SelectedNode = Me.FindNode(tree.Nodes, found, found) End If End Sub Public Sub Search_prev(ByRef tree As DevComponents.AdvTree.AdvTree, ByVal key As Integer, searchtext As String) Dim found As Integer = 1 For Each r As DataRow In Me.treedata_for_search.Rows If UCase(r(1).ToString).IndexOf((UCase(searchtext))) > -1 And r(0) <> key Then found = r(0) End If If r(0) = key Then tree.SelectedNode = FindNode(tree.Nodes, found, found) Exit Sub End If Next End Sub Public Sub Clear_Search() Try Me.treedata_for_search.Clear() Catch End Try End Sub #End Region Public Function TreeView_GetRootNode(objTV As DevComponents.AdvTree.AdvTree, node As DevComponents.AdvTree.Node) As DevComponents.AdvTree.Node Try If node.Parent Is Nothing Then Return Nothing Else Dim parent As DevComponents.AdvTree.Node = node.Parent While Not parent.Parent Is Nothing parent = parent.Parent End While Return parent End If Catch End Try End Function End Class End Namespace