140 lines
4.8 KiB
VB.net
140 lines
4.8 KiB
VB.net
Imports DigitalData.Modules.Database
|
|
Imports DigitalData.Modules.Logging
|
|
Imports System.IO
|
|
|
|
Public Class FrmMain
|
|
Private SelectedTable As Integer
|
|
Private _logger As NLog.Logger
|
|
Private _logConfig As LogConfig
|
|
Private DBFirebird As Firebird
|
|
|
|
Private Sub CreateTableNodesFromDatatable(dt As DataTable)
|
|
' Node der Datenbank erstellen
|
|
Dim dbNode As New TreeNode With {
|
|
.Text = My.Settings.fbDatabaseLocation,
|
|
.Name = "DATABASE"
|
|
}
|
|
|
|
' Übernode für Tabellen erstellen
|
|
Dim tablesNode As New TreeNode With {
|
|
.Text = "Tabellen",
|
|
.Name = "TABLES"
|
|
}
|
|
|
|
' Nodes für Tabellen erstellen
|
|
Dim tableNodeList As New List(Of TreeNode)
|
|
|
|
For Each row As DataRow In dt.Rows
|
|
Dim node As New TreeNode With {
|
|
.Text = row.Item("TABLE"),
|
|
.Tag = row.Item("TABLE_ID")
|
|
}
|
|
|
|
tableNodeList.Add(node)
|
|
Next
|
|
|
|
' Nodes zusammenfügen
|
|
tablesNode.Nodes.AddRange(tableNodeList.ToArray)
|
|
dbNode.Nodes.Add(tablesNode)
|
|
|
|
' Nodes einhängen
|
|
treeViewMain.Nodes.Add(dbNode)
|
|
End Sub
|
|
|
|
Private Function LoadTables()
|
|
Return DBFirebird.GetDatatable("SELECT DISTINCT T.TABLE_ID,T.""TABLE"" from VWEDM_TABLE_COLUMN T")
|
|
End Function
|
|
|
|
Private Function DatabaseSettingsExist()
|
|
Return My.Settings.fbDatabaseLocation <> String.Empty And My.Settings.fbDatasource <> String.Empty And My.Settings.fbUser <> String.Empty And My.Settings.fbPassword <> String.Empty
|
|
End Function
|
|
|
|
Private Sub Init()
|
|
DBFirebird = New Firebird(_logConfig.LogFactory, My.Settings.fbDatasource, My.Settings.fbDatabaseLocation, My.Settings.fbUser, My.Settings.fbPassword)
|
|
|
|
If DBFirebird.ConnectionFailed Then
|
|
MsgBox("Database connection failed. Please check the log.", vbCritical)
|
|
Exit Sub
|
|
End If
|
|
|
|
' Get info about the logged in user
|
|
'CurrentUser = New ClassCurrentUser(DBFirebird)
|
|
|
|
Dim dt As DataTable = LoadTables()
|
|
CreateTableNodesFromDatatable(dt)
|
|
End Sub
|
|
|
|
Private Sub FrmMain_Load(sender As Object, e As EventArgs) Handles Me.Load
|
|
_logConfig = New LogConfig(ClassLogger.PathType.CurrentDirectory)
|
|
_logger = _logConfig.LogFactory.GetCurrentClassLogger()
|
|
|
|
' Check for existing database credentials
|
|
While Not DatabaseSettingsExist()
|
|
Dim form As New FrmConnection With {
|
|
.LogFactory = _logConfig.LogFactory
|
|
}
|
|
Dim result As DialogResult = form.ShowDialog()
|
|
|
|
If result = DialogResult.OK Then
|
|
Exit While
|
|
End If
|
|
End While
|
|
|
|
Init()
|
|
End Sub
|
|
|
|
Private Sub TreeViewMain_NodeMouseClick(sender As Object, e As TreeNodeMouseClickEventArgs) Handles treeViewMain.NodeMouseClick
|
|
If e.Button = MouseButtons.Right Then
|
|
SelectedTable = -1
|
|
|
|
' Wenn kein Node geklickt wurde, aussteigen
|
|
If e.Node Is Nothing OrElse e.Node.Parent Is Nothing Then
|
|
Exit Sub
|
|
End If
|
|
|
|
Dim parentName As String = e.Node.Parent.Name
|
|
|
|
' Das Kontextmenü für den angeklickten Node öffnen
|
|
Select Case parentName
|
|
Case "TABLES"
|
|
SelectedTable = e.Node.Tag
|
|
contextMenuTable.Show(MousePosition)
|
|
End Select
|
|
|
|
treeViewMain.SelectedNode = e.Node
|
|
End If
|
|
End Sub
|
|
|
|
Private Sub SpaltenBearbeitenToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles SpaltenBearbeitenToolStripMenuItem.Click
|
|
Dim dt As DataTable = DBFirebird.GetDatatable($"SELECT * FROM VWEDM_TABLE_COLUMN WHERE TABLE_ID = {SelectedTable}")
|
|
gridControlTableProperties.DataSource = dt
|
|
End Sub
|
|
|
|
Private Sub TabelleBearbeitenToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles TabelleBearbeitenToolStripMenuItem.Click
|
|
|
|
End Sub
|
|
|
|
Private Sub DebugAnToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles DebugAnToolStripMenuItem.Click
|
|
_logConfig.Debug = True
|
|
End Sub
|
|
|
|
Private Sub DebugAusToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles DebugAusToolStripMenuItem.Click
|
|
_logConfig.Debug = False
|
|
End Sub
|
|
|
|
Private Sub WriteDebugLogToolStripMenuItem_Click(sender As Object, e As EventArgs)
|
|
_logger.Debug("Welcome to monkey island!")
|
|
End Sub
|
|
|
|
Private Sub SpamTheLogToolStripMenuItem_Click(sender As Object, e As EventArgs)
|
|
For index = 1 To 100000
|
|
_logger.Debug("Spam No. {0}", index)
|
|
Next
|
|
End Sub
|
|
|
|
Private Sub NeueTabelleToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles NeueTabelleToolStripMenuItem.Click
|
|
Dim frm As New FrmNewTable(_logConfig.LogFactory)
|
|
frm.ShowDialog()
|
|
End Sub
|
|
End Class
|