Imports System Imports System.Data Imports System.Data.SqlTypes Imports System.Data.SqlClient Imports System.Windows.Forms Public Class frmDokSelect Private Dokumentvorlagen As New DataSet Private Connectionstring As String Public Sub New(ByVal Connstring As String) ' Dieser Aufruf ist für den Windows Form-Designer erforderlich. InitializeComponent() Connectionstring = Connstring ' Fügen Sie Initialisierungen nach dem InitializeComponent()-Aufruf hinzu. End Sub Private Sub BeendenToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BeendenToolStripMenuItem.Click Me.Close() End Sub Private Sub frmDokSelect_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Load_Tree() End Sub Private Sub Load_Tree() Read_Dokumente() Load_Treeview(Dokumentvorlagen, Tree) Me.Tree.ExpandAll() End Sub ''' ''' Auswertungen, für welche der User berechtigt ist, auslesen ''' ''' ''' Private Function Read_Dokumente() As DataTable Dim conn As New SqlConnection(Me.connectionstring) Dim scmCmdToExecute As SqlCommand = New SqlCommand() Dim dtToReturn As DataTable = New DataTable() Dim sdaAdapter As SqlDataAdapter = New SqlDataAdapter(scmCmdToExecute) scmCmdToExecute.CommandText = "dbo.sp_get_nativ_dokumente" scmCmdToExecute.CommandType = CommandType.StoredProcedure scmCmdToExecute.Connection = conn Try sdaAdapter.Fill(dtToReturn) Dokumentvorlagen.Tables.Clear() Dokumentvorlagen.Tables.Add(dtToReturn) Catch ex As Exception Throw New Exception("clsAuswertung::" & scmCmdToExecute.CommandText & "::Error occured." & ex.Message, ex) Finally scmCmdToExecute.Dispose() sdaAdapter.Dispose() End Try End Function ''' ''' Interne Relation aufbauen und Tree aufbauen ''' ''' ''' ''' Private Sub Load_Treeview(ByVal oSourceData As DataSet, ByRef tree As TreeView) If Not (oSourceData Is Nothing) Then Dim oView As DataView = oSourceData.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 ''' ''' Tree aufbauen ''' ''' ''' ''' Private Sub LoadTreeView(ByVal oDS As DataSet, ByRef oTreeview As TreeView) '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 Dim oNode As New TreeNode() oNode.Text = oDataRow("Bezeichnung").ToString() oNode.Tag = oDataRow("dokumentnr").ToString oNode.ToolTipText = oDataRow("Beschreibung").ToString oNode.ImageIndex = 0 oNode.SelectedImageIndex = 0 oNode.StateImageIndex = 0 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 TreeNode) Dim oChildRow As DataRow For Each oChildRow In oDataRow.GetChildRows("SelfRefenceRelation") Dim oChildNode As New TreeNode() oChildNode.Text = oChildRow("Bezeichnung").ToString() oChildNode.Tag = oChildRow("dokumentnr").ToString() If oChildRow("dokumentnr") < 0 Then oChildNode.ImageIndex = 0 oChildNode.SelectedImageIndex = 0 oChildNode.StateImageIndex = 0 oChildNode.ToolTipText = oChildRow("Beschreibung").ToString Else If oChildRow("Pfad").ToString.IndexOf(".doc") > 0 Then oChildNode.ImageIndex = 1 oChildNode.SelectedImageIndex = 1 oChildNode.StateImageIndex = 1 End If If oChildRow("Pfad").ToString.IndexOf(".xls") > 0 Then oChildNode.ImageIndex = 2 oChildNode.SelectedImageIndex = 2 oChildNode.StateImageIndex = 2 End If If oChildRow("Pfad").ToString.IndexOf(".ppt") > 0 Then oChildNode.ImageIndex = 3 oChildNode.SelectedImageIndex = 3 oChildNode.StateImageIndex = 3 End If If oChildRow("Pfad").ToString.IndexOf(".acc") > 0 Then oChildNode.ImageIndex = 4 oChildNode.SelectedImageIndex = 4 oChildNode.StateImageIndex = 4 End If If oChildRow("Pfad").ToString.IndexOf(".vs") > 0 Then oChildNode.ImageIndex = 5 oChildNode.SelectedImageIndex = 5 oChildNode.StateImageIndex = 5 End If If oChildRow("Pfad").ToString.IndexOf(".mpp") > 0 Then oChildNode.ImageIndex = 6 oChildNode.SelectedImageIndex = 6 oChildNode.StateImageIndex = 6 End If End If oChildNode.ToolTipText = oChildRow("Beschreibung").ToString oNode.Nodes.Add(oChildNode) RecursivelyLoadTree(oChildRow, oChildNode) Next oChildRow End Sub Private Sub Tree_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles Tree.DoubleClick Try Dim s As String If Me.Tree.SelectedNode.Tag < 0 Then Exit Sub For Each r As DataRow In Dokumentvorlagen.Tables(0).Rows If r.Item("Dokumentnr") = Me.Tree.SelectedNode.Tag Then s = r.Item("Pfad") If s.IndexOf(".doc") > 0 Then Dim w As New Microsoft.Office.Interop.Word.Application w.Documents.Add(r.Item("pfad").ToString) w.Visible = True w = Nothing End If If s.IndexOf(".xls") > 0 Then Dim xl As New Microsoft.Office.Interop.Excel.Application xl.Workbooks.Add(r.Item("Pfad").ToString) xl.Visible = True xl = Nothing End If If s.IndexOf(".ppt") > 0 Then Dim pp As New Microsoft.Office.Interop.PowerPoint.Application pp.Presentations.Open(FileName:=r.Item("Pfad"), Untitled:=True) pp.Visible = Microsoft.Office.Core.MsoTriState.msoTrue pp = Nothing End If Exit For End If Next Catch ex As Exception End Try End Sub End Class