Files
ITSM/___Archiv/ITSM - Kopie/Vertragsverwaltung/LifeCycle/clslifeCycle.vb
2021-04-20 09:35:24 +02:00

158 lines
5.6 KiB
VB.net

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
Sub New()
Produkttypen = Stammdaten.Get_Stammdaten("LC_Produkttyp", "Bezeichnung")
End Sub
#Region "Deklarationen"
Private Stammdaten As New TKB.VV.Stammdaten.clsStammdaten
Dim treedata As New DataSet
Public Produkttypen As New DataTable
#End Region
#Region "Struktur"
Public Sub Load_Treestrukutr(ByRef tree As AdvTree)
tree.Nodes.Clear()
Get_Produkte()
LoadTree(treedata, tree)
End Sub
Private Function Get_Produkte() As DataTable
treedata.Tables.Clear()
Dim selectcommand As New SqlCommand
Dim connection As New SqlConnection()
Dim da As New SqlDataAdapter("", connection)
selectcommand.CommandText = "[sp_lc_get_Struktur_Auswahl]"
selectcommand.CommandType = CommandType.StoredProcedure
selectcommand.Connection = connection
Try
connection.ConnectionString = Globals.sConnectionString
connection.Open()
da.SelectCommand = selectcommand
da.Fill(treedata, "Tree")
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)
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 Sub
Private Sub LoadTreeView(ByVal oDS As DataSet, ByRef oTreeview As 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")
oNode.ImageIndex = oDataRow("ImageIndex")
oTreeview.Nodes.Add(oNode)
RecursivelyLoadTree(oDataRow, oNode)
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)
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 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(ByVal _nodeCollection As TreeNodeCollection, ByVal SearchVal As Integer, ByVal SearchString As String) As TreeNode
' Dim tmpNode As TreeNode
' For Each _child As TreeNode In _nodeCollection
' If _child.Tag = SearchVal 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
#End Region
End Class
End Namespace