WIP: EDM Designer, Create Tables

This commit is contained in:
Jonathan Jenne 2018-09-03 17:24:17 +02:00
parent ae0bb16dc8
commit a2e233fe68
13 changed files with 490 additions and 174 deletions

View File

@ -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

View File

@ -75,9 +75,6 @@
<HintPath>..\packages\FirebirdSql.Data.FirebirdClient.6.1.0\lib\net452\FirebirdSql.Data.FirebirdClient.dll</HintPath>
</Reference>
<Reference Include="Microsoft.CSharp" />
<Reference Include="Modules.Database">
<HintPath>..\Modules.Database\bin\Debug\DigitalData.Modules.Database.dll</HintPath>
</Reference>
<Reference Include="NLog, Version=4.0.0.0, Culture=neutral, PublicKeyToken=5120e14c03d0593c, processorArchitecture=MSIL">
<HintPath>..\packages\NLog.4.5.8\lib\net45\NLog.dll</HintPath>
</Reference>
@ -128,6 +125,12 @@
<DependentUpon>FrmMain.vb</DependentUpon>
<SubType>Form</SubType>
</Compile>
<Compile Include="FrmNewTable.Designer.vb">
<DependentUpon>FrmNewTable.vb</DependentUpon>
</Compile>
<Compile Include="FrmNewTable.vb">
<SubType>Form</SubType>
</Compile>
<Compile Include="ModuleRuntimeVariables.vb" />
<Compile Include="My Project\AssemblyInfo.vb" />
<Compile Include="My Project\Application.Designer.vb">
@ -152,6 +155,9 @@
<EmbeddedResource Include="FrmMain.resx">
<DependentUpon>FrmMain.vb</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="FrmNewTable.resx">
<DependentUpon>FrmNewTable.vb</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="My Project\licenses.licx" />
<EmbeddedResource Include="My Project\Resources.resx">
<Generator>VbMyResourcesResXFileCodeGenerator</Generator>
@ -188,6 +194,10 @@
<WCFMetadata Include="Connected Services\" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Modules.Database\Database.vbproj">
<Project>{eaf0ea75-5fa7-485d-89c7-b2d843b03a96}</Project>
<Name>Database</Name>
</ProjectReference>
<ProjectReference Include="..\Modules.Logging\Logging.vbproj">
<Project>{903b2d7d-3b80-4be9-8713-7447b704e1b0}</Project>
<Name>Logging</Name>

View File

@ -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
'

View File

@ -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

View File

@ -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

73
EDMDesigner/FrmNewTable.Designer.vb generated Normal file
View File

@ -0,0 +1,73 @@
<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
Partial Class FrmNewTable
Inherits System.Windows.Forms.Form
'Das Formular überschreibt den Löschvorgang, um die Komponentenliste zu bereinigen.
<System.Diagnostics.DebuggerNonUserCode()> _
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.
<System.Diagnostics.DebuggerStepThrough()> _
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

View File

@ -0,0 +1,120 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

View File

@ -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

View File

@ -22,17 +22,16 @@ Partial Class FrmMain
'Das Bearbeiten mit dem Code-Editor ist nicht möglich.
<System.Diagnostics.DebuggerStepThrough()>
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

View File

@ -135,4 +135,7 @@
<metadata name="DocumentManager1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>728, 17</value>
</metadata>
<metadata name="contextMenuDatabase.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>892, 17</value>
</metadata>
</root>

View File

@ -11,6 +11,8 @@
<FileAlignment>512</FileAlignment>
<MyType>Windows</MyType>
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
<NuGetPackageImportStamp>
</NuGetPackageImportStamp>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
@ -88,6 +90,7 @@
<Import Include="System.Threading.Tasks" />
</ItemGroup>
<ItemGroup>
<Compile Include="Exceptions.vb" />
<Compile Include="Firebird.vb" />
<Compile Include="Oracle.vb" />
<Compile Include="MSSQLServer.vb" />

View File

@ -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

View File

@ -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
''' <summary>
''' 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..
''' </summary>
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
''' <summary>
'''
''' </summary>
''' <param name="LogFactory"></param>
''' <param name="Datasource"></param>
''' <param name="Database"></param>
''' <param name="User"></param>
''' <param name="Password"></param>
''' <exception cref="Exceptions.DatabaseException"></exception>
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
''' <summary>
''' Builds a connectionstring from the provided arguments.
''' </summary>
''' <param name="dataSource">The database server where to connect to</param>
''' <param name="database">The datasource, eg. the path of the FDB-file</param>
''' <param name="user">The user used to connect to the database</param>
''' <param name="password">The password of the connecting user</param>
''' <param name="DataSource">The database server where to connect to</param>
''' <param name="Database">The datasource, eg. the path of the FDB-file</param>
''' <param name="User">The user used to connect to the database</param>
''' <param name="Password">The password of the connecting user</param>
''' <returns>A connectionstring</returns>
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
''' <summary>
''' Executes a non-query command.
''' </summary>
''' <param name="sqlCommand">The command to execute</param>
''' <param name="SqlCommand">The command to execute</param>
''' <returns>True, if command was executed sucessfully. Otherwise false.</returns>
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
''' <summary>
''' Executes a sql query resulting in a scalar value.
''' </summary>
''' <param name="sqlQuery">The query to execute</param>
''' <param name="SqlQuery">The query to execute</param>
''' <returns>The scalar value if the command was executed successfully. Nothing otherwise.</returns>
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
''' <summary>
''' Executes a sql query resulting in a table of values.
''' </summary>
''' <param name="sqlQuery">The query to execute</param>
''' <param name="SqlQuery">The query to execute</param>
''' <returns>A datatable containing the results if the command was executed successfully. Nothing otherwise.</returns>
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