diff --git a/EDMDesigner/ClassCurrentUser.vb b/EDMDesigner/ClassCurrentUser.vb index de23b5dd..b8cf1bd1 100644 --- a/EDMDesigner/ClassCurrentUser.vb +++ b/EDMDesigner/ClassCurrentUser.vb @@ -7,9 +7,9 @@ Public Class ClassCurrentUser Private DBFirebird As Firebird Public Sub New(DBFirebird As Firebird) - Username = Environment.UserName + 'Username = Environment.UserName - Dim sql As String = $"SELECT FNGET_USER_ACCESS('edm','{Username}') FROM rdb$database" - Dim result = DBFirebird.GetExecuteScalar(sql) + 'Dim sql As String = $"SELECT FNGET_USER_ACCESS('edm','{Username}') FROM rdb$database" + 'Dim result = DBFirebird.GetScalarValue(sql) End Sub End Class diff --git a/EDMDesigner/EDMDesigner.vbproj b/EDMDesigner/EDMDesigner.vbproj index 07af393a..cac53184 100644 --- a/EDMDesigner/EDMDesigner.vbproj +++ b/EDMDesigner/EDMDesigner.vbproj @@ -75,9 +75,6 @@ ..\packages\FirebirdSql.Data.FirebirdClient.6.1.0\lib\net452\FirebirdSql.Data.FirebirdClient.dll - - ..\Modules.Database\bin\Debug\DigitalData.Modules.Database.dll - ..\packages\NLog.4.5.8\lib\net45\NLog.dll @@ -128,6 +125,12 @@ FrmMain.vb Form + + FrmNewTable.vb + + + Form + @@ -152,6 +155,9 @@ FrmMain.vb + + FrmNewTable.vb + VbMyResourcesResXFileCodeGenerator @@ -188,6 +194,10 @@ + + {eaf0ea75-5fa7-485d-89c7-b2d843b03a96} + Database + {903b2d7d-3b80-4be9-8713-7447b704e1b0} Logging diff --git a/EDMDesigner/FrmConnection.Designer.vb b/EDMDesigner/FrmConnection.Designer.vb index 4915e059..4b5bddd3 100644 --- a/EDMDesigner/FrmConnection.Designer.vb +++ b/EDMDesigner/FrmConnection.Designer.vb @@ -45,6 +45,7 @@ Partial Class FrmConnection Me.FbDatasourceTextBox.Name = "FbDatasourceTextBox" Me.FbDatasourceTextBox.Size = New System.Drawing.Size(227, 20) Me.FbDatasourceTextBox.TabIndex = 2 + Me.FbDatasourceTextBox.Text = "172.24.12.41" ' 'FbDatabaseLocationTextBox ' @@ -52,6 +53,7 @@ Partial Class FrmConnection Me.FbDatabaseLocationTextBox.Name = "FbDatabaseLocationTextBox" Me.FbDatabaseLocationTextBox.Size = New System.Drawing.Size(682, 20) Me.FbDatabaseLocationTextBox.TabIndex = 1 + Me.FbDatabaseLocationTextBox.Text = "172.24.12.41:E:\DB\Firebird\Databases\DD_EDM.FDB" ' 'FbUserTextBox ' @@ -59,6 +61,7 @@ Partial Class FrmConnection Me.FbUserTextBox.Name = "FbUserTextBox" Me.FbUserTextBox.Size = New System.Drawing.Size(140, 20) Me.FbUserTextBox.TabIndex = 3 + Me.FbUserTextBox.Text = "EDM_GUI" ' 'FbPasswordTextBox ' @@ -66,6 +69,7 @@ Partial Class FrmConnection Me.FbPasswordTextBox.Name = "FbPasswordTextBox" Me.FbPasswordTextBox.Size = New System.Drawing.Size(86, 20) Me.FbPasswordTextBox.TabIndex = 4 + Me.FbPasswordTextBox.Text = "dd" ' 'btnConnect ' diff --git a/EDMDesigner/FrmConnection.vb b/EDMDesigner/FrmConnection.vb index 983d6bcf..673b2e1a 100644 --- a/EDMDesigner/FrmConnection.vb +++ b/EDMDesigner/FrmConnection.vb @@ -1,7 +1,13 @@ -Imports Modules.Database +Imports DigitalData.Modules.Database Public Class FrmConnection + Public Property LogFactory As NLog.LogFactory + + Private _logger As NLog.Logger + Private Sub FrmConnection_Load(sender As Object, e As EventArgs) Handles MyBase.Load + _logger = LogFactory.GetCurrentClassLogger() + FbDatabaseLocationTextBox.DataBindings.Add("Text", My.Settings, "fbDatabaseLocation") FbDatasourceTextBox.DataBindings.Add("Text", My.Settings, "fbDatasource") FbUserTextBox.DataBindings.Add("Text", My.Settings, "fbUser") @@ -9,24 +15,35 @@ Public Class FrmConnection End Sub Private Sub BtnConnect_Click(sender As Object, e As EventArgs) Handles btnConnect.Click - My.Settings.Save() + Dim dbTest As Firebird - Dim dbTest As New Firebird(My.Settings.fbDatasource, My.Settings.fbDatabaseLocation, My.Settings.fbUser, My.Settings.fbPassword) + Try + dbTest = New Firebird(LogFactory, My.Settings.fbDatasource, My.Settings.fbDatabaseLocation, My.Settings.fbUser, My.Settings.fbPassword) - If dbTest.ConnectionFailed Then + If dbTest.ConnectionFailed Then + MsgBox("Connection failed!", MsgBoxStyle.Information, "Database Connection") + + lblConnectionStatus.Text = "No connection established" + lblConnectionStatus.BackColor = Color.Red + + DialogResult = DialogResult.None + Else + My.Settings.Save() + + MsgBox("Connection successful!", MsgBoxStyle.Information, "Database Connection") + + lblConnectionStatus.Text = "Connection established!" + lblConnectionStatus.BackColor = Color.GreenYellow + + DialogResult = DialogResult.OK + End If + Catch ex As Exception MsgBox("Connection failed!", MsgBoxStyle.Information, "Database Connection") lblConnectionStatus.Text = "No connection established" lblConnectionStatus.BackColor = Color.Red DialogResult = DialogResult.None - Else - MsgBox("Connection successful!", MsgBoxStyle.Information, "Database Connection") - - lblConnectionStatus.Text = "Connection established!" - lblConnectionStatus.BackColor = Color.GreenYellow - - DialogResult = DialogResult.OK - End If + End Try End Sub End Class \ No newline at end of file diff --git a/EDMDesigner/FrmMain.vb b/EDMDesigner/FrmMain.vb index 7d42e7cb..dac8a712 100644 --- a/EDMDesigner/FrmMain.vb +++ b/EDMDesigner/FrmMain.vb @@ -1,16 +1,18 @@ Imports DigitalData.Modules.Database Imports DigitalData.Modules.Logging +Imports System.IO Public Class FrmMain Private SelectedTable As Integer - Private Logger As NLog.Logger - Private LogWrapper As LogConfig + 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 + .Text = My.Settings.fbDatabaseLocation, + .Name = "DATABASE" } ' Übernode für Tabellen erstellen @@ -48,7 +50,7 @@ Public Class FrmMain End Function Private Sub Init() - DBFirebird = New Firebird(My.Settings.fbDatasource, My.Settings.fbDatabaseLocation, My.Settings.fbUser, My.Settings.fbPassword) + 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) @@ -56,39 +58,23 @@ Public Class FrmMain End If ' Get info about the logged in user - CurrentUser = New ClassCurrentUser(DBFirebird) + '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 - LogWrapper = New LogConfig(ClassLogger.PathType.CurrentDirectory) - - Logger = NLog.LogManager.GetCurrentClassLogger() - - Logger.Debug("DEBUG1") - Logger.Debug("DEBUG2") - Logger.Debug("DEBUG3") - LogWrapper.Debug = False - Logger.Debug("DEBUG4") - Logger.Debug("DEBUG5") - Logger.Debug("DEBUG6") - LogWrapper.Debug = True - Logger.Debug("DEBUG7") - Logger.Debug("DEBUG8") - Logger.Debug("DEBUG9") - - - Logger.Info("Starting EDMDesigner..") - - Logger.Error(New IO.FileNotFoundException("Central 66"), "This is Error!") + _logConfig = New LogConfig(ClassLogger.PathType.CurrentDirectory) + _logger = _logConfig.LogFactory.GetCurrentClassLogger() ' Check for existing database credentials While Not DatabaseSettingsExist() - Dim result As DialogResult = FrmConnection.ShowDialog() + Dim form As New FrmConnection With { + .LogFactory = _logConfig.LogFactory + } + Dim result As DialogResult = form.ShowDialog() + If result = DialogResult.OK Then Exit While End If @@ -129,20 +115,25 @@ Public Class FrmMain End Sub Private Sub DebugAnToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles DebugAnToolStripMenuItem.Click - LogWrapper.Debug = True + _logConfig.Debug = True End Sub Private Sub DebugAusToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles DebugAusToolStripMenuItem.Click - LogWrapper.Debug = False + _logConfig.Debug = False End Sub - Private Sub WriteDebugLogToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles WriteDebugLogToolStripMenuItem.Click - Logger.Debug("Welcome to monkey island!") + 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) Handles SpamTheLogToolStripMenuItem.Click + Private Sub SpamTheLogToolStripMenuItem_Click(sender As Object, e As EventArgs) For index = 1 To 100000 - Logger.Debug("Spam No. {0}", index) + _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 diff --git a/EDMDesigner/FrmNewTable.Designer.vb b/EDMDesigner/FrmNewTable.Designer.vb new file mode 100644 index 00000000..f2dffdcc --- /dev/null +++ b/EDMDesigner/FrmNewTable.Designer.vb @@ -0,0 +1,73 @@ + _ +Partial Class FrmNewTable + Inherits System.Windows.Forms.Form + + 'Das Formular überschreibt den Löschvorgang, um die Komponentenliste zu bereinigen. + _ + Protected Overrides Sub Dispose(ByVal disposing As Boolean) + Try + If disposing AndAlso components IsNot Nothing Then + components.Dispose() + End If + Finally + MyBase.Dispose(disposing) + End Try + End Sub + + 'Wird vom Windows Form-Designer benötigt. + Private components As System.ComponentModel.IContainer + + 'Hinweis: Die folgende Prozedur ist für den Windows Form-Designer erforderlich. + 'Das Bearbeiten ist mit dem Windows Form-Designer möglich. + 'Das Bearbeiten mit dem Code-Editor ist nicht möglich. + _ + Private Sub InitializeComponent() + Me.btnOK = New System.Windows.Forms.Button() + Me.TextBox1 = New System.Windows.Forms.TextBox() + Me.Label1 = New System.Windows.Forms.Label() + Me.SuspendLayout() + ' + 'btnOK + ' + Me.btnOK.Location = New System.Drawing.Point(311, 51) + Me.btnOK.Name = "btnOK" + Me.btnOK.Size = New System.Drawing.Size(75, 23) + Me.btnOK.TabIndex = 0 + Me.btnOK.Text = "OK" + Me.btnOK.UseVisualStyleBackColor = True + ' + 'TextBox1 + ' + Me.TextBox1.Location = New System.Drawing.Point(12, 25) + Me.TextBox1.Name = "TextBox1" + Me.TextBox1.Size = New System.Drawing.Size(374, 20) + Me.TextBox1.TabIndex = 1 + ' + 'Label1 + ' + Me.Label1.AutoSize = True + Me.Label1.Location = New System.Drawing.Point(12, 9) + Me.Label1.Name = "Label1" + Me.Label1.Size = New System.Drawing.Size(77, 13) + Me.Label1.TabIndex = 2 + Me.Label1.Text = "Tabellenname:" + ' + 'FrmNewTable + ' + Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!) + Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font + Me.ClientSize = New System.Drawing.Size(398, 98) + Me.Controls.Add(Me.Label1) + Me.Controls.Add(Me.TextBox1) + Me.Controls.Add(Me.btnOK) + Me.Name = "FrmNewTable" + Me.Text = "Neue Tabelle" + Me.ResumeLayout(False) + Me.PerformLayout() + + End Sub + + Friend WithEvents btnOK As Button + Friend WithEvents TextBox1 As TextBox + Friend WithEvents Label1 As Label +End Class diff --git a/EDMDesigner/FrmNewTable.resx b/EDMDesigner/FrmNewTable.resx new file mode 100644 index 00000000..1af7de15 --- /dev/null +++ b/EDMDesigner/FrmNewTable.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/EDMDesigner/FrmNewTable.vb b/EDMDesigner/FrmNewTable.vb new file mode 100644 index 00000000..29b30dc2 --- /dev/null +++ b/EDMDesigner/FrmNewTable.vb @@ -0,0 +1,31 @@ +Imports NLog +Imports DigitalData.Modules.Database + + +Public Class FrmNewTable + Private _logFactory As LogFactory + Private _logger As Logger + Private _db As Firebird + + Public Sub New(LogFactory As LogFactory) + ' Dieser Aufruf ist für den Designer erforderlich. + InitializeComponent() + + ' Fügen Sie Initialisierungen nach dem InitializeComponent()-Aufruf hinzu. + _logFactory = LogFactory + _logger = _logFactory.GetCurrentClassLogger() + End Sub + + Private Sub FrmNewTable_Load(sender As Object, e As KeyEventArgs) Handles Me.Load + Try + _db = New Firebird(_logFactory, My.Settings.fbDatasource, My.Settings.fbDatabaseLocation, My.Settings.fbUser, My.Settings.fbPassword) + Catch ex As Exception + MsgBox("Connection to DB failed!", MsgBoxStyle.Critical) + _logger.Error(ex) + End Try + End Sub + + Private Sub btnOK_Click(sender As Object, e As EventArgs) Handles btnOK.Click + + End Sub +End Class \ No newline at end of file diff --git a/EDMDesigner/frmMain.Designer.vb b/EDMDesigner/frmMain.Designer.vb index 168f2445..4baa2482 100644 --- a/EDMDesigner/frmMain.Designer.vb +++ b/EDMDesigner/frmMain.Designer.vb @@ -22,17 +22,16 @@ Partial Class FrmMain 'Das Bearbeiten mit dem Code-Editor ist nicht möglich. Private Sub InitializeComponent() - Me.components = New System.ComponentModel.Container() - Dim DockingContainer1 As DevExpress.XtraBars.Docking2010.Views.Tabbed.DockingContainer = New DevExpress.XtraBars.Docking2010.Views.Tabbed.DockingContainer() - Me.DocumentGroup1 = New DevExpress.XtraBars.Docking2010.Views.Tabbed.DocumentGroup(Me.components) - Me.Document1 = New DevExpress.XtraBars.Docking2010.Views.Tabbed.Document(Me.components) + Dim DockingContainer2 As DevExpress.XtraBars.Docking2010.Views.Tabbed.DockingContainer = New DevExpress.XtraBars.Docking2010.Views.Tabbed.DockingContainer() + Me.DocumentGroup1 = New DevExpress.XtraBars.Docking2010.Views.Tabbed.DocumentGroup() + Me.Document1 = New DevExpress.XtraBars.Docking2010.Views.Tabbed.Document() Me.StatusStrip1 = New System.Windows.Forms.StatusStrip() Me.ToolStripStatusLabelConState = New System.Windows.Forms.ToolStripStatusLabel() Me.treeViewMain = New System.Windows.Forms.TreeView() Me.gridControlTableProperties = New DevExpress.XtraGrid.GridControl() Me.gridViewTableProperties = New DevExpress.XtraGrid.Views.Grid.GridView() - Me.MySettingsBindingSource = New System.Windows.Forms.BindingSource(Me.components) - Me.contextMenuTable = New System.Windows.Forms.ContextMenuStrip(Me.components) + Me.MySettingsBindingSource = New System.Windows.Forms.BindingSource() + Me.contextMenuTable = New System.Windows.Forms.ContextMenuStrip() Me.TabelleBearbeitenToolStripMenuItem = New System.Windows.Forms.ToolStripMenuItem() Me.TabelleLöschenToolStripMenuItem = New System.Windows.Forms.ToolStripMenuItem() Me.ToolStripSeparator1 = New System.Windows.Forms.ToolStripSeparator() @@ -42,15 +41,15 @@ Partial Class FrmMain Me.DebugToolStripMenuItem = New System.Windows.Forms.ToolStripMenuItem() Me.DebugAnToolStripMenuItem = New System.Windows.Forms.ToolStripMenuItem() Me.DebugAusToolStripMenuItem = New System.Windows.Forms.ToolStripMenuItem() - Me.WriteDebugLogToolStripMenuItem = New System.Windows.Forms.ToolStripMenuItem() - Me.DockManager1 = New DevExpress.XtraBars.Docking.DockManager(Me.components) + Me.DockManager1 = New DevExpress.XtraBars.Docking.DockManager() Me.DockPanel1 = New DevExpress.XtraBars.Docking.DockPanel() Me.DockPanel1_Container = New DevExpress.XtraBars.Docking.ControlContainer() Me.DockPanel2 = New DevExpress.XtraBars.Docking.DockPanel() Me.DockPanel2_Container = New DevExpress.XtraBars.Docking.ControlContainer() - Me.DocumentManager1 = New DevExpress.XtraBars.Docking2010.DocumentManager(Me.components) - Me.TabbedView1 = New DevExpress.XtraBars.Docking2010.Views.Tabbed.TabbedView(Me.components) - Me.SpamTheLogToolStripMenuItem = New System.Windows.Forms.ToolStripMenuItem() + Me.DocumentManager1 = New DevExpress.XtraBars.Docking2010.DocumentManager() + Me.TabbedView1 = New DevExpress.XtraBars.Docking2010.Views.Tabbed.TabbedView() + Me.contextMenuDatabase = New System.Windows.Forms.ContextMenuStrip() + Me.NeueTabelleToolStripMenuItem = New System.Windows.Forms.ToolStripMenuItem() CType(Me.DocumentGroup1, System.ComponentModel.ISupportInitialize).BeginInit() CType(Me.Document1, System.ComponentModel.ISupportInitialize).BeginInit() Me.StatusStrip1.SuspendLayout() @@ -66,6 +65,7 @@ Partial Class FrmMain Me.DockPanel2_Container.SuspendLayout() CType(Me.DocumentManager1, System.ComponentModel.ISupportInitialize).BeginInit() CType(Me.TabbedView1, System.ComponentModel.ISupportInitialize).BeginInit() + Me.contextMenuDatabase.SuspendLayout() Me.SuspendLayout() ' 'DocumentGroup1 @@ -162,7 +162,7 @@ Partial Class FrmMain ' 'MenuStrip1 ' - Me.MenuStrip1.Items.AddRange(New System.Windows.Forms.ToolStripItem() {Me.DebugToolStripMenuItem, Me.WriteDebugLogToolStripMenuItem, Me.SpamTheLogToolStripMenuItem}) + Me.MenuStrip1.Items.AddRange(New System.Windows.Forms.ToolStripItem() {Me.DebugToolStripMenuItem}) Me.MenuStrip1.Location = New System.Drawing.Point(0, 0) Me.MenuStrip1.Name = "MenuStrip1" Me.MenuStrip1.Size = New System.Drawing.Size(955, 24) @@ -188,12 +188,6 @@ Partial Class FrmMain Me.DebugAusToolStripMenuItem.Size = New System.Drawing.Size(132, 22) Me.DebugAusToolStripMenuItem.Text = "Debug Aus" ' - 'WriteDebugLogToolStripMenuItem - ' - Me.WriteDebugLogToolStripMenuItem.Name = "WriteDebugLogToolStripMenuItem" - Me.WriteDebugLogToolStripMenuItem.Size = New System.Drawing.Size(108, 20) - Me.WriteDebugLogToolStripMenuItem.Text = "Write Debug Log" - ' 'DockManager1 ' Me.DockManager1.Form = Me @@ -254,14 +248,20 @@ Partial Class FrmMain ' Me.TabbedView1.DocumentGroups.AddRange(New DevExpress.XtraBars.Docking2010.Views.Tabbed.DocumentGroup() {Me.DocumentGroup1}) Me.TabbedView1.Documents.AddRange(New DevExpress.XtraBars.Docking2010.Views.BaseDocument() {Me.Document1}) - DockingContainer1.Element = Me.DocumentGroup1 - Me.TabbedView1.RootContainer.Nodes.AddRange(New DevExpress.XtraBars.Docking2010.Views.Tabbed.DockingContainer() {DockingContainer1}) + DockingContainer2.Element = Me.DocumentGroup1 + Me.TabbedView1.RootContainer.Nodes.AddRange(New DevExpress.XtraBars.Docking2010.Views.Tabbed.DockingContainer() {DockingContainer2}) ' - 'SpamTheLogToolStripMenuItem + 'contextMenuDatabase ' - Me.SpamTheLogToolStripMenuItem.Name = "SpamTheLogToolStripMenuItem" - Me.SpamTheLogToolStripMenuItem.Size = New System.Drawing.Size(95, 20) - Me.SpamTheLogToolStripMenuItem.Text = "Spam the Log!" + Me.contextMenuDatabase.Items.AddRange(New System.Windows.Forms.ToolStripItem() {Me.NeueTabelleToolStripMenuItem}) + Me.contextMenuDatabase.Name = "contextMenuDatabase" + Me.contextMenuDatabase.Size = New System.Drawing.Size(181, 48) + ' + 'NeueTabelleToolStripMenuItem + ' + Me.NeueTabelleToolStripMenuItem.Name = "NeueTabelleToolStripMenuItem" + Me.NeueTabelleToolStripMenuItem.Size = New System.Drawing.Size(180, 22) + Me.NeueTabelleToolStripMenuItem.Text = "Neue Tabelle.." ' 'FrmMain ' @@ -292,6 +292,7 @@ Partial Class FrmMain Me.DockPanel2_Container.ResumeLayout(False) CType(Me.DocumentManager1, System.ComponentModel.ISupportInitialize).EndInit() CType(Me.TabbedView1, System.ComponentModel.ISupportInitialize).EndInit() + Me.contextMenuDatabase.ResumeLayout(False) Me.ResumeLayout(False) Me.PerformLayout() @@ -322,6 +323,6 @@ Partial Class FrmMain Friend WithEvents DebugToolStripMenuItem As ToolStripMenuItem Friend WithEvents DebugAnToolStripMenuItem As ToolStripMenuItem Friend WithEvents DebugAusToolStripMenuItem As ToolStripMenuItem - Friend WithEvents WriteDebugLogToolStripMenuItem As ToolStripMenuItem - Friend WithEvents SpamTheLogToolStripMenuItem As ToolStripMenuItem + Friend WithEvents contextMenuDatabase As ContextMenuStrip + Friend WithEvents NeueTabelleToolStripMenuItem As ToolStripMenuItem End Class diff --git a/EDMDesigner/frmMain.resx b/EDMDesigner/frmMain.resx index 230f4e9e..48da4873 100644 --- a/EDMDesigner/frmMain.resx +++ b/EDMDesigner/frmMain.resx @@ -135,4 +135,7 @@ 728, 17 + + 892, 17 + \ No newline at end of file diff --git a/Modules.Database/Database.vbproj b/Modules.Database/Database.vbproj index 1f6b691a..60c9ab8a 100644 --- a/Modules.Database/Database.vbproj +++ b/Modules.Database/Database.vbproj @@ -11,6 +11,8 @@ 512 Windows v4.6.1 + + true @@ -88,6 +90,7 @@ + diff --git a/Modules.Database/Exceptions.vb b/Modules.Database/Exceptions.vb new file mode 100644 index 00000000..4f86f7e4 --- /dev/null +++ b/Modules.Database/Exceptions.vb @@ -0,0 +1,18 @@ +Public Class Exceptions + + Public Class DatabaseException + Inherits Exception + + Public Sub New() + End Sub + + Public Sub New(message As String) + MyBase.New(message) + End Sub + + Public Sub New(message As String, innerException As Exception) + MyBase.New(message, innerException) + End Sub + End Class + +End Class diff --git a/Modules.Database/Firebird.vb b/Modules.Database/Firebird.vb index 23fb391b..82a4d3f3 100644 --- a/Modules.Database/Firebird.vb +++ b/Modules.Database/Firebird.vb @@ -1,55 +1,102 @@ -Imports FirebirdSql.Data.FirebirdClient -Public Class Firebird - Private Shared Logger As NLog.Logger = NLog.LogManager.GetCurrentClassLogger - Public DBInitialized As Boolean = False - Private _connectionEstablished As Boolean = False - Private _connectionFailed As Boolean = False - Private ReadOnly dataSource As String - Private ReadOnly database As String - Private ReadOnly user As String - Private ReadOnly password As String - Public CurrentFBDConnectionString As String = "" - Public ReadOnly Property ConnectionString As String - Public ReadOnly Property ConnectionEstablished As Boolean - Get - Return _connectionEstablished - End Get - End Property +Imports NLog +Imports FirebirdSql.Data.FirebirdClient + +''' +''' MODULE: Firebird +''' +''' VERSION: 0.0.0.1 +''' +''' DATE: 03.09.2018 +''' +''' DESCRIPTION: +''' +''' DEPENDENCIES: NLog, >= 4.5.8 +''' +''' EntityFramework.Firebird, >= 6.1.0 +''' +''' FirebirdSql.Data.FirebirdClient, >= 6.0.0 +''' +''' PARAMETERS: LogFactory, NLog.LogFactory +''' The LogFactory containing the current log config. Used to instanciate the class logger for this and any dependent class +''' +''' DataSource, String +''' The location of the Database in the format `127.0.0.1:E:\Path\To\Database.FDB` +''' +''' Database, String +''' The server where the database lives, for example 127.0.0.1 or dd-vmx09-vm03 +''' +''' User, String +''' The user name to connect as +''' +''' Password, String +''' The user's password +''' +''' PROPERTIES: ConnectionEstablished, Boolean +''' If the last opened connection was successful +''' +''' ConnectionFailed, Boolean +''' If the last opened connection failed +''' +''' ConnectionString, String +''' The used connectionstring +''' +''' EXAMPLES: +''' +''' REMARKS: If the connection fails due to "wrong username or password", the cause might be that the server harddrive is full.. +''' +Public Class Firebird + Private _logger As Logger + Private _connectionServer As String + Private _connectionDatabase As String + Private _connectionUsername As String + Private _connectionPassword As String + + Public ReadOnly Property ConnectionEstablished As Boolean Public ReadOnly Property ConnectionFailed As Boolean - Get - Return _connectionFailed - End Get - End Property - Public Sub New(dataSource As String, database As String, user As String, password As String) - ConnectionString = BuildConnectionString(dataSource, database, user, password) - ' Save connection credentials - dataSource = dataSource - database = database - user = user - password = password + Public ReadOnly Property ConnectionString As String + + ''' + ''' + ''' + ''' + ''' + ''' + ''' + ''' + ''' + Public Sub New(LogFactory As LogFactory, Datasource As String, Database As String, User As String, Password As String) + _logger = LogFactory.GetCurrentClassLogger() + ' Test the connection first - Dim conn = Connect(ConnectionString) + Dim oConnectionString = GetConnectionString(Datasource, Database, User, Password) + Dim oConnection = GetConnection(oConnectionString) ' If initial connection was successfully, close it - conn?.Close() + oConnection?.Close() + + If oConnection Is Nothing Then + Throw New Exceptions.DatabaseException() + End If + + _connectionServer = Datasource + _connectionDatabase = Database + _connectionUsername = User + _connectionPassword = Password + _ConnectionString = oConnectionString End Sub - Private Function Connect(ConnectionString As String) As FbConnection + Private Function GetConnection(ConnectionString As String) As FbConnection Try - Dim conn = New FbConnection(ConnectionString) - conn.Open() - _connectionEstablished = True - _connectionFailed = False - Logger.Debug("Connection established!") - Logger.Debug($"User: {user}") - Logger.Debug($"DatabaseLocation: {database}") - Logger.Debug($"DatabaseServer: {dataSource}") + Dim oConnection = New FbConnection(ConnectionString) + oConnection.Open() + _ConnectionEstablished = True + _ConnectionFailed = False - Return conn + Return oConnection Catch ex As Exception - _connectionFailed = True - _connectionEstablished = False - Logger.Error(ex) + _ConnectionFailed = True + _ConnectionEstablished = False + _logger.Error(ex) Return Nothing End Try @@ -58,48 +105,46 @@ Public Class Firebird ''' ''' Builds a connectionstring from the provided arguments. ''' - ''' The database server where to connect to - ''' The datasource, eg. the path of the FDB-file - ''' The user used to connect to the database - ''' The password of the connecting user + ''' The database server where to connect to + ''' The datasource, eg. the path of the FDB-file + ''' The user used to connect to the database + ''' The password of the connecting user ''' A connectionstring - Private Function BuildConnectionString(dataSource As String, database As String, user As String, password As String) As String - Dim connectionStringBuilder = New FbConnectionStringBuilder With { - .DataSource = dataSource, - .Database = database, - .UserID = user, - .Password = password - } - Return connectionStringBuilder.ConnectionString + Private Function GetConnectionString(DataSource As String, Database As String, User As String, Password As String) As String + Return New FbConnectionStringBuilder With { + .DataSource = DataSource, + .Database = Database, + .UserID = User, + .Password = Password + }.ToString() End Function ''' ''' Executes a non-query command. ''' - ''' The command to execute + ''' The command to execute ''' True, if command was executed sucessfully. Otherwise false. - Public Function NewExecuteNonQuery(sqlCommand As String) As Boolean + Public Function ExecuteNonQuery(SqlCommand As String) As Boolean Try - Dim conn As FbConnection = Connect(ConnectionString) + Dim oConnection As FbConnection = GetConnection(ConnectionString) - If conn Is Nothing Then + If oConnection Is Nothing Then Return False End If - Dim transaction As FbTransaction = conn.BeginTransaction() - Dim command As New FbCommand With { - .CommandText = sqlCommand, - .Connection = conn, - .Transaction = transaction + Dim oTransaction As FbTransaction = oConnection.BeginTransaction() + Dim oCommand As New FbCommand With { + .CommandText = SqlCommand, + .Connection = oConnection, + .Transaction = oTransaction } - command.ExecuteNonQuery() - - transaction.Commit() - conn.Close() + oCommand.ExecuteNonQuery() + oTransaction.Commit() + oConnection.Close() Return True Catch ex As Exception - Logger.Error(ex, $"Error in ExecuteNonQuery while executing command: '{sqlCommand}'") + _logger.Error(ex, $"Error in ExecuteNonQuery while executing command: '{SqlCommand}'") Return False End Try End Function @@ -107,30 +152,30 @@ Public Class Firebird ''' ''' Executes a sql query resulting in a scalar value. ''' - ''' The query to execute + ''' The query to execute ''' The scalar value if the command was executed successfully. Nothing otherwise. - Public Function GetExecuteScalar(sqlQuery As String) As Object + Public Function GetScalarValue(SqlQuery As String) As Object Try - Dim conn As FbConnection = Connect(ConnectionString) + Dim oConnection As FbConnection = GetConnection(ConnectionString) - If conn Is Nothing Then + If oConnection Is Nothing Then Return Nothing End If - Dim transaction As FbTransaction = conn.BeginTransaction() - Dim command As New FbCommand With { - .CommandText = sqlQuery, - .Connection = conn, - .Transaction = transaction + Dim oTransaction As FbTransaction = oConnection.BeginTransaction() + Dim oCommand As New FbCommand With { + .CommandText = SqlQuery, + .Connection = oConnection, + .Transaction = oTransaction } - Dim result As Object = command.ExecuteScalar() + Dim oResult As Object = oCommand.ExecuteScalar() - transaction.Commit() - conn.Close() + oTransaction.Commit() + oConnection.Close() - Return result + Return oResult Catch ex As Exception - Logger.Error(ex, $"Error in ReturnScalar while executing command: '{sqlQuery}'") + _logger.Error(ex, $"Error in ReturnScalar while executing command: '{SqlQuery}'") Return Nothing End Try End Function @@ -138,29 +183,29 @@ Public Class Firebird ''' ''' Executes a sql query resulting in a table of values. ''' - ''' The query to execute + ''' The query to execute ''' A datatable containing the results if the command was executed successfully. Nothing otherwise. - Public Function GetDatatable(sqlQuery As String) As DataTable + Public Function GetDatatable(SqlQuery As String) As DataTable Try - Dim conn As FbConnection = Connect(ConnectionString) + Dim oConnection As FbConnection = GetConnection(ConnectionString) - If conn Is Nothing Then + If oConnection Is Nothing Then Return Nothing End If - Dim command As New FbCommand With { - .CommandText = sqlQuery, - .Connection = conn + Dim oCommand As New FbCommand With { + .CommandText = SqlQuery, + .Connection = oConnection } - Dim adapter As New FbDataAdapter(command) - Dim dt As New DataTable() + Dim oAdapter As New FbDataAdapter(oCommand) + Dim oDatatable As New DataTable() - adapter.Fill(dt) - conn.Close() + oAdapter.Fill(oDatatable) + oConnection.Close() - Return dt + Return oDatatable Catch ex As Exception - Logger.Error(ex, $"Error in ReturnDatatable while executing command: '{sqlQuery}'") + _logger.Error(ex, $"Error in ReturnDatatable while executing command: '{SqlQuery}'") Return Nothing End Try End Function