Initial commit
This commit is contained in:
345
clsNativ/frmDokManager.vb
Normal file
345
clsNativ/frmDokManager.vb
Normal file
@@ -0,0 +1,345 @@
|
||||
Imports System
|
||||
Imports System.Data
|
||||
Imports System.Data.SqlTypes
|
||||
Imports System.Data.SqlClient
|
||||
Imports System.Windows.Forms
|
||||
Imports System.IO
|
||||
|
||||
Public Class frmDokManager
|
||||
|
||||
Private Dokumentvorlagen As New DataSet
|
||||
Private Connectionstring As String
|
||||
Dim ssort As Integer
|
||||
|
||||
Dim da As SqlDataAdapter
|
||||
Dim ds As New DataSet
|
||||
Dim co As New SqlConnection
|
||||
Dim cb As SqlCommandBuilder
|
||||
Dim dbkey As Integer = 0
|
||||
|
||||
|
||||
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()
|
||||
Me.Tree.AllowDrop = True
|
||||
End Sub
|
||||
|
||||
Private Sub Load_Tree()
|
||||
Read_Dokumente()
|
||||
Load_Treeview(Dokumentvorlagen, Tree)
|
||||
Me.Tree.ExpandAll()
|
||||
End Sub
|
||||
|
||||
|
||||
''' <summary>
|
||||
''' Auswertungen, für welche der User berechtigt ist, auslesen
|
||||
''' </summary>
|
||||
''' <returns></returns>
|
||||
''' <remarks></remarks>
|
||||
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 = "select * from dbo.NativHierarchie"
|
||||
scmCmdToExecute.CommandType = CommandType.Text
|
||||
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
|
||||
''' <summary>
|
||||
''' Interne Relation aufbauen und Tree aufbauen
|
||||
''' </summary>
|
||||
''' <param name="oSourceData"></param>
|
||||
''' <param name="tree"></param>
|
||||
''' <remarks></remarks>
|
||||
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("Eintragnr"), _
|
||||
oDS.Tables(0).Columns("Parentid"))
|
||||
End If
|
||||
oTable.Dispose()
|
||||
oTable = Nothing
|
||||
LoadTreeView(oDS, tree)
|
||||
oDS.Dispose()
|
||||
oDS = Nothing
|
||||
End If
|
||||
End Sub
|
||||
|
||||
''' <summary>
|
||||
''' Tree aufbauen
|
||||
''' </summary>
|
||||
''' <param name="oDS"></param>
|
||||
''' <param name="oTreeview"></param>
|
||||
''' <remarks></remarks>
|
||||
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("pfad").ToString
|
||||
'oNode.ToolTipText = oDataRow("Beschreibung").ToString
|
||||
oNode.ToolTipText = ""
|
||||
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
|
||||
|
||||
''' <summary>
|
||||
''' Child-Nodes hinzufügen
|
||||
''' </summary>
|
||||
''' <param name="oDataRow"></param>
|
||||
''' <param name="oNode"></param>
|
||||
''' <remarks></remarks>
|
||||
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("pfad").ToString()
|
||||
If oChildRow("pfad").ToString = "" Then
|
||||
oChildNode.ImageIndex = 0
|
||||
oChildNode.SelectedImageIndex = 0
|
||||
oChildNode.StateImageIndex = 0
|
||||
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
|
||||
|
||||
Public Sub TreeView1_ItemDrag(ByVal sender As System.Object, ByVal e As System.Windows.Forms.ItemDragEventArgs) Handles Tree.ItemDrag
|
||||
DoDragDrop(e.Item, DragDropEffects.Move)
|
||||
End Sub
|
||||
|
||||
Public Sub TreeView1_DragEnter(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles Tree.DragEnter
|
||||
e.Effect = DragDropEffects.Move
|
||||
End Sub
|
||||
Public Sub TreeView1_DragDrop(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles Tree.DragDrop
|
||||
Dim NewNode As TreeNode
|
||||
If e.Data.GetDataPresent("System.Windows.Forms.TreeNode", True) Then
|
||||
Dim pt As System.Drawing.Point
|
||||
Dim DestinationNode As TreeNode
|
||||
pt = Tree.PointToClient(New System.Drawing.Point(e.X, e.Y))
|
||||
DestinationNode = Tree.GetNodeAt(pt)
|
||||
NewNode = CType(e.Data.GetData("System.Windows.Forms.TreeNode"), TreeNode)
|
||||
If Not DestinationNode.Equals(NewNode) Then
|
||||
DestinationNode.Nodes.Add(CType(NewNode.Clone, TreeNode))
|
||||
DestinationNode.Expand()
|
||||
NewNode.Remove()
|
||||
End If
|
||||
End If
|
||||
If e.Data.GetDataPresent(DataFormats.FileDrop) Then
|
||||
Dim filePaths As String() = CType(e.Data.GetData(DataFormats.FileDrop), String())
|
||||
For Each fileLoc As String In filePaths
|
||||
If File.Exists(fileLoc) Then
|
||||
Dim pt As System.Drawing.Point
|
||||
Dim DestinationNode As TreeNode
|
||||
pt = Tree.PointToClient(New System.Drawing.Point(e.X, e.Y))
|
||||
DestinationNode = Tree.GetNodeAt(pt)
|
||||
NewNode = New TreeNode(fileLoc)
|
||||
NewNode.Tag = fileLoc
|
||||
If Not DestinationNode.Equals(NewNode) Then
|
||||
DestinationNode.Nodes.Add(CType(NewNode.Clone, TreeNode))
|
||||
DestinationNode.Expand()
|
||||
NewNode.Remove()
|
||||
End If
|
||||
End If
|
||||
Next fileLoc
|
||||
End If
|
||||
|
||||
End Sub
|
||||
|
||||
Private Sub NeuerEintragToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles NeuerEintragToolStripMenuItem.Click
|
||||
Dim a As String
|
||||
Dim tn As New TreeNode()
|
||||
Dim tnnew As New TreeNode()
|
||||
a = InputBox("Bezeichnung des neuen Eintrags:")
|
||||
If a = "" Then Exit Sub
|
||||
tn = Me.Tree.SelectedNode
|
||||
tnnew = tn.Nodes.Add(a)
|
||||
With tnnew
|
||||
.Tag() = -1
|
||||
.ImageIndex() = 0
|
||||
.SelectedImageIndex() = 0
|
||||
End With
|
||||
End Sub
|
||||
|
||||
Private Sub EintragLöschenToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles EintragLöschenToolStripMenuItem.Click
|
||||
Dim tn As New TreeNode()
|
||||
Dim tnp As New TreeNode()
|
||||
Dim i As Integer
|
||||
tn = Tree.SelectedNode
|
||||
tnp = tn.Parent
|
||||
If Not (Tree.SelectedNode Is Nothing) Then
|
||||
tn.Remove()
|
||||
End If
|
||||
End Sub
|
||||
|
||||
Private Sub EintragUmbenennenToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles EintragUmbenennenToolStripMenuItem.Click
|
||||
Dim a As String
|
||||
a = InputBox("Neuer Name:")
|
||||
If a = "" Then Exit Sub
|
||||
Tree.SelectedNode.Text = a
|
||||
End Sub
|
||||
|
||||
Private Sub ToolStripButton1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripButton1.Click
|
||||
Me.Close()
|
||||
End Sub
|
||||
|
||||
Private Sub ToolStripButton2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripButton2.Click
|
||||
Load_From_Db()
|
||||
dbkey = 0
|
||||
ds.Tables(0).Rows.Clear()
|
||||
da.Update(ds, "vorlagen")
|
||||
Save_Data()
|
||||
|
||||
End Sub
|
||||
|
||||
Private Sub Load_From_Db()
|
||||
Try
|
||||
da = New SqlDataAdapter("Select * from NativHierarchie", Connectionstring)
|
||||
cb = New SqlCommandBuilder(da)
|
||||
da.Fill(ds, "vorlagen")
|
||||
Catch ex As Exception
|
||||
MsgBox(ex.Message)
|
||||
End Try
|
||||
End Sub
|
||||
Private Sub Save_Data()
|
||||
ListNodeCollectionRecursive(Me.Tree.Nodes(0), 0)
|
||||
End Sub
|
||||
Private Sub ListNodeCollectionRecursive(ByVal tnParent As TreeNode, ByRef iSort As Integer)
|
||||
Dim tn As TreeNode
|
||||
If tnParent.GetNodeCount(False) > 0 Then
|
||||
tn = tnParent.Nodes(0)
|
||||
Else
|
||||
tn = Nothing
|
||||
End If
|
||||
ssort = 0
|
||||
Do Until tn Is Nothing
|
||||
iSort = iSort + 1
|
||||
ListNodeSave(tn, iSort)
|
||||
If tn.GetNodeCount(False) > 0 Then
|
||||
Call ListNodeCollectionRecursive(tn, iSort)
|
||||
End If
|
||||
tn = tn.NextNode
|
||||
Loop
|
||||
End Sub
|
||||
|
||||
Private Sub ListNodeSave(ByVal tn As TreeNode, ByRef isort As Integer)
|
||||
Dim r As DataRow
|
||||
r = ds.Tables(0).NewRow
|
||||
r.Item("Eintragnr") = dbkey
|
||||
r.Item("Bezeichnung") = tn.Text
|
||||
r.Item("Parentid") = tn.Parent.Tag
|
||||
r.Item("Erstellt_am") = Now
|
||||
r.Item("Mutiert_am") = Now
|
||||
r.Item("Mutierer") = 1
|
||||
r.Item("Aktiv") = True
|
||||
r.Item("Pfad") = tn.Tag
|
||||
ds.Tables(0).Rows.Add(r)
|
||||
End Sub
|
||||
|
||||
End Class
|
||||
Reference in New Issue
Block a user