Modules.Database

This commit is contained in:
Digital Data - Marlon Schreiber 2018-08-16 15:27:46 +02:00
parent f8e3b3628e
commit b8c28b516c
12 changed files with 427 additions and 64 deletions

View File

@ -1,16 +1,15 @@
Imports DD_FirebirdDLL Imports Modules.Database
Public Class ClassCurrentUser Public Class ClassCurrentUser
Public Username As String Public Username As String
Public Language As String Public Language As String
Private DB As ClassFirebird Private DBFirebird As Firebird
Public Sub New(DB As ClassFirebird) Public Sub New(DBFirebird As Firebird)
Username = Environment.UserName Username = Environment.UserName
DB = DB
Dim sql As String = $"SELECT FNGET_USER_ACCESS('edm','{Username}') FROM rdb$database" Dim sql As String = $"SELECT FNGET_USER_ACCESS('edm','{Username}') FROM rdb$database"
Dim result = DB.ReturnScalar(sql) Dim result = DBFirebird.GetExecuteScalar(sql)
End Sub End Sub
End Class End Class

View File

@ -1,22 +1,22 @@
Imports System.IO Imports System.IO
Imports DD_FirebirdDLL Imports Modules.Database
Public Class ClassInit Public Class ClassInit
Public Shared Function Init_user() Public Shared Function Init_user()
Try Try
USER_USERNAME = Environment.UserName USER_USERNAME = Environment.UserName
Dim sql = String.Format("select FNGET_USER_ACCESS('edm','{0}') from rdb$database", USER_USERNAME) Dim sql = String.Format("select FNGET_USER_ACCESS('edm','{0}') from rdb$database", USER_USERNAME)
Dim result = ClassDBFirebird.ExecuteScalar(sql, LOGGERFilePath) 'Dim result = Firebird.ExecuteScalar(sql, LOGGERFilePath)
sql = String.Format("SELECT * FROM VW_TBEDM_USER WHERE UPPER(LOGIN_NAME) = UPPER('{0}')", USER_USERNAME) 'sql = String.Format("SELECT * FROM VW_TBEDM_USER WHERE UPPER(LOGIN_NAME) = UPPER('{0}')", USER_USERNAME)
DT_USER = ClassDBFirebird.ReturnDatatable(sql, LOGGERFilePath) 'DT_USER = ClassDBFirebird.ReturnDatatable(sql, LOGGERFilePath)
If Not IsNothing(result) Then 'If Not IsNothing(result) Then
If Not IsNothing(DT_USER) Then ' If Not IsNothing(DT_USER) Then
USER_LANGUAGE = DT_USER.Rows(0).Item("LANGUAGE") ' USER_LANGUAGE = DT_USER.Rows(0).Item("LANGUAGE")
End If ' End If
Return result ' Return result
Else 'Else
Return False ' Return False
End If 'End If
Catch ex As Exception Catch ex As Exception
End Try End Try

View File

@ -47,9 +47,6 @@
<OptionInfer>On</OptionInfer> <OptionInfer>On</OptionInfer>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<Reference Include="DD_FirebirdDLL">
<HintPath>..\..\DDFirebirdDLL\DD_FirebirdDLL\bin\Debug\DD_FirebirdDLL.dll</HintPath>
</Reference>
<Reference Include="DevExpress.Data.v18.1, Version=18.1.5.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" /> <Reference Include="DevExpress.Data.v18.1, Version=18.1.5.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" />
<Reference Include="DevExpress.Pdf.v18.1.Core, Version=18.1.5.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" /> <Reference Include="DevExpress.Pdf.v18.1.Core, Version=18.1.5.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" />
<Reference Include="DevExpress.Office.v18.1.Core, Version=18.1.5.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" /> <Reference Include="DevExpress.Office.v18.1.Core, Version=18.1.5.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" />
@ -78,6 +75,9 @@
<HintPath>..\packages\FirebirdSql.Data.FirebirdClient.6.1.0\lib\net452\FirebirdSql.Data.FirebirdClient.dll</HintPath> <HintPath>..\packages\FirebirdSql.Data.FirebirdClient.6.1.0\lib\net452\FirebirdSql.Data.FirebirdClient.dll</HintPath>
</Reference> </Reference>
<Reference Include="Microsoft.CSharp" /> <Reference Include="Microsoft.CSharp" />
<Reference Include="Modules.Database">
<HintPath>..\Modules.Database\bin\Debug\Modules.Database.dll</HintPath>
</Reference>
<Reference Include="NLog, Version=4.0.0.0, Culture=neutral, PublicKeyToken=5120e14c03d0593c, processorArchitecture=MSIL"> <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> <HintPath>..\packages\NLog.4.5.8\lib\net45\NLog.dll</HintPath>
</Reference> </Reference>

View File

@ -1,4 +1,4 @@
Imports DD_FirebirdDLL Imports Modules.Database
Public Class FrmConnection Public Class FrmConnection
Private Sub FrmConnection_Load(sender As Object, e As EventArgs) Handles MyBase.Load Private Sub FrmConnection_Load(sender As Object, e As EventArgs) Handles MyBase.Load
@ -11,7 +11,7 @@ Public Class FrmConnection
Private Sub BtnConnect_Click(sender As Object, e As EventArgs) Handles btnConnect.Click Private Sub BtnConnect_Click(sender As Object, e As EventArgs) Handles btnConnect.Click
My.Settings.Save() My.Settings.Save()
Dim dbTest As New ClassFirebird(My.Settings.fbDatasource, My.Settings.fbDatabaseLocation, My.Settings.fbUser, My.Settings.fbPassword) Dim dbTest As New Firebird(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") MsgBox("Connection failed!", MsgBoxStyle.Information, "Database Connection")

View File

@ -1,11 +1,11 @@
Imports DD_FirebirdDLL Imports Modules.Database
Imports Modules.Logging Imports Modules.Logging
Public Class FrmMain Public Class FrmMain
Private SelectedTable As Integer Private SelectedTable As Integer
Private Logger As NLog.Logger Private Logger As NLog.Logger
Private LogWrapper As Logger Private LogWrapper As Logger
Private DB As ClassFirebird Private DBFirebird As Firebird
Private Sub CreateTableNodesFromDatatable(dt As DataTable) Private Sub CreateTableNodesFromDatatable(dt As DataTable)
' Node der Datenbank erstellen ' Node der Datenbank erstellen
@ -40,7 +40,7 @@ Public Class FrmMain
End Sub End Sub
Private Function LoadTables() Private Function LoadTables()
Return DB.ReturnDatatable("SELECT DISTINCT T.TABLE_ID,T.""TABLE"" from VWEDM_TABLE_COLUMN T") Return DBFirebird.GetDatatable("SELECT DISTINCT T.TABLE_ID,T.""TABLE"" from VWEDM_TABLE_COLUMN T")
End Function End Function
Private Function DatabaseSettingsExist() Private Function DatabaseSettingsExist()
@ -48,15 +48,15 @@ Public Class FrmMain
End Function End Function
Private Sub Init() Private Sub Init()
DB = New ClassFirebird(My.Settings.fbDatasource, My.Settings.fbDatabaseLocation, My.Settings.fbUser, My.Settings.fbPassword) DBFirebird = New Firebird(My.Settings.fbDatasource, My.Settings.fbDatabaseLocation, My.Settings.fbUser, My.Settings.fbPassword)
If DB.ConnectionFailed Then If DBFirebird.ConnectionFailed Then
MsgBox("Database connection failed. Please check the log.", vbCritical) MsgBox("Database connection failed. Please check the log.", vbCritical)
Exit Sub Exit Sub
End If End If
' Get info about the logged in user ' Get info about the logged in user
CurrentUser = New ClassCurrentUser(DB) CurrentUser = New ClassCurrentUser(DBFirebird)
Dim dt As DataTable = LoadTables() Dim dt As DataTable = LoadTables()
CreateTableNodesFromDatatable(dt) CreateTableNodesFromDatatable(dt)
@ -65,7 +65,7 @@ Public Class FrmMain
Private Sub FrmMain_Load(sender As Object, e As EventArgs) Handles Me.Load Private Sub FrmMain_Load(sender As Object, e As EventArgs) Handles Me.Load
LogWrapper = New Logger("EDMDesigner", ClassLogger.PathType.CurrentDirectory) LogWrapper = New Logger(ClassLogger.PathType.CurrentDirectory)
Logger = NLog.LogManager.GetCurrentClassLogger() Logger = NLog.LogManager.GetCurrentClassLogger()
@ -120,7 +120,7 @@ Public Class FrmMain
End Sub End Sub
Private Sub SpaltenBearbeitenToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles SpaltenBearbeitenToolStripMenuItem.Click Private Sub SpaltenBearbeitenToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles SpaltenBearbeitenToolStripMenuItem.Click
Dim dt As DataTable = DB.ReturnDatatable($"SELECT * FROM VWEDM_TABLE_COLUMN WHERE TABLE_ID = {SelectedTable}") Dim dt As DataTable = DBFirebird.GetDatatable($"SELECT * FROM VWEDM_TABLE_COLUMN WHERE TABLE_ID = {SelectedTable}")
gridControlTableProperties.DataSource = dt gridControlTableProperties.DataSource = dt
End Sub End Sub

View File

@ -0,0 +1,28 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</configSections>
<entityFramework>
<defaultConnectionFactory type="EntityFramework.Firebird.FbConnectionFactory, EntityFramework.Firebird" />
<providers>
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
<provider invariantName="FirebirdSql.Data.FirebirdClient" type="EntityFramework.Firebird.FbProviderServices, EntityFramework.Firebird" />
</providers>
</entityFramework>
<system.data>
<DbProviderFactories>
<remove invariant="FirebirdSql.Data.FirebirdClient" />
<add name="FirebirdClient Data Provider" invariant="FirebirdSql.Data.FirebirdClient" description=".NET Framework Data Provider for Firebird" type="FirebirdSql.Data.FirebirdClient.FirebirdClientFactory, FirebirdSql.Data.FirebirdClient" />
</DbProviderFactories>
</system.data>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="FirebirdSql.Data.FirebirdClient" publicKeyToken="3750abcc3150b00c" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>

View File

@ -1,4 +1,167 @@
Public Class Firebird Imports FirebirdSql.Data.FirebirdClient
Public Class Firebird
Private Shared Logger As NLog.Logger = NLog.LogManager.GetCurrentClassLogger Private Shared Logger As NLog.Logger = NLog.LogManager.GetCurrentClassLogger
Public DBInitialized As Boolean = False 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
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
' Test the connection first
Dim conn = Connect(ConnectionString)
' If initial connection was successfully, close it
conn?.Close()
End Sub
Private Function Connect(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}")
Return conn
Catch ex As Exception
_connectionFailed = True
_connectionEstablished = False
Logger.Error(ex)
Return Nothing
End Try
End Function
''' <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>
''' <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
End Function
''' <summary>
''' Executes a non-query command.
''' </summary>
''' <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
Try
Dim conn As FbConnection = Connect(ConnectionString)
If conn 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
}
command.ExecuteNonQuery()
transaction.Commit()
conn.Close()
Return True
Catch ex As Exception
Logger.Error(ex, $"Error in ExecuteNonQuery while executing command: '{sqlCommand}'")
Return False
End Try
End Function
''' <summary>
''' Executes a sql query resulting in a scalar value.
''' </summary>
''' <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
Try
Dim conn As FbConnection = Connect(ConnectionString)
If conn 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 result As Object = command.ExecuteScalar()
transaction.Commit()
conn.Close()
Return result
Catch ex As Exception
Logger.Error(ex, $"Error in ReturnScalar while executing command: '{sqlQuery}'")
Return Nothing
End Try
End Function
''' <summary>
''' Executes a sql query resulting in a table of values.
''' </summary>
''' <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
Try
Dim conn As FbConnection = Connect(ConnectionString)
If conn Is Nothing Then
Return Nothing
End If
Dim command As New FbCommand With {
.CommandText = sqlQuery,
.Connection = conn
}
Dim adapter As New FbDataAdapter(command)
Dim dt As New DataTable()
adapter.Fill(dt)
conn.Close()
Return dt
Catch ex As Exception
Logger.Error(ex, $"Error in ReturnDatatable while executing command: '{sqlQuery}'")
Return Nothing
End Try
End Function
End Class End Class

View File

@ -1,9 +1,10 @@
Imports System.Data.SqlClient Imports System.Data.SqlClient
Public Class SQLServer Public Class MSSQLServer
Private Shared Logger As NLog.Logger = NLog.LogManager.GetCurrentClassLogger Private Shared Logger As NLog.Logger = NLog.LogManager.GetCurrentClassLogger
Public DBInitialized As Boolean = False Public DBInitialized As Boolean = False
Public CurrentSQLConnectionString As String = "" Public CurrentSQLConnectionString As String = ""
Private CurrentSQLConnection As SqlClient.SqlConnection
Public Sub New(CONSTRING As String) Public Sub New(CONSTRING As String)
Init(CONSTRING) Init(CONSTRING)
End Sub End Sub
@ -17,11 +18,38 @@ Public Class SQLServer
DBInitialized = True DBInitialized = True
Return True Return True
Catch ex As Exception Catch ex As Exception
DBInitialized = False
Logger.Error(ex) Logger.Error(ex)
'clsLogger.Add("Error in DatabaseInit: " & ex.Message, True) 'clsLogger.Add("Error in DatabaseInit: " & ex.Message, True)
Return False Return False
End Try End Try
End Function End Function
Private Function GetSQLConnection()
Try
If IsNothing(CurrentSQLConnection) Then
Dim oSQLconnect As New SqlClient.SqlConnection
oSQLconnect.ConnectionString = CurrentSQLConnectionString
CurrentSQLConnection = oSQLconnect
CurrentSQLConnection.Open()
Else
If CurrentSQLConnection.State <> ConnectionState.Open Then
Logger.Warn($"Actual ConnectionState is: '{CurrentSQLConnection.State.ToString}'")
Try
CurrentSQLConnection.Open()
Return True
Catch ex As Exception
Logger.Warn("Could not reconnect to database!")
Return False
End Try
End If
End If
Return True
Catch ex As Exception
Logger.Error(ex)
Return False
End Try
End Function
''' <summary> ''' <summary>
''' Returns a datatable for a sql-statement ''' Returns a datatable for a sql-statement
''' </summary> ''' </summary>
@ -31,17 +59,19 @@ Public Class SQLServer
''' <remarks></remarks> ''' <remarks></remarks>
Public Function GetDatatable(sqlcommand As String, Optional commandtimeout As Integer = 120) As DataTable Public Function GetDatatable(sqlcommand As String, Optional commandtimeout As Integer = 120) As DataTable
Try Try
Dim oSQLconnect As New SqlClient.SqlConnection Dim dt As DataTable = New DataTable()
If GetSQLConnection() = False Then
Return Nothing
End If
Dim oSQLCOmmand As SqlClient.SqlCommand Dim oSQLCOmmand As SqlClient.SqlCommand
oSQLconnect.ConnectionString = CurrentSQLConnectionString
oSQLconnect.Open() oSQLCOmmand = CurrentSQLConnection.CreateCommand()
oSQLCOmmand = oSQLconnect.CreateCommand()
oSQLCOmmand.CommandText = sqlcommand oSQLCOmmand.CommandText = sqlcommand
oSQLCOmmand.CommandTimeout = commandtimeout oSQLCOmmand.CommandTimeout = commandtimeout
Dim adapter1 As SqlClient.SqlDataAdapter = New SqlClient.SqlDataAdapter(oSQLCOmmand) Dim adapter1 As SqlClient.SqlDataAdapter = New SqlClient.SqlDataAdapter(oSQLCOmmand)
Dim dt As DataTable = New DataTable()
adapter1.Fill(dt) adapter1.Fill(dt)
oSQLconnect.Close()
Return dt Return dt
Catch ex As Exception Catch ex As Exception
Logger.Error(ex) Logger.Error(ex)
@ -58,16 +88,17 @@ Public Class SQLServer
''' <remarks></remarks> ''' <remarks></remarks>
Public Function NewExecutenonQuery(executeStatement As String, Optional commandtimeout As Integer = 120) As Boolean Public Function NewExecutenonQuery(executeStatement As String, Optional commandtimeout As Integer = 120) As Boolean
Try Try
Dim oSQLconnect As New SqlClient.SqlConnection If GetSQLConnection() = False Then
Return Nothing
End If
'Dim oSQLconnect As New SqlClient.SqlConnection
Dim oSQLCOmmand As SqlClient.SqlCommand Dim oSQLCOmmand As SqlClient.SqlCommand
oSQLconnect.ConnectionString = CurrentSQLConnectionString
oSQLconnect.Open() oSQLCOmmand = CurrentSQLConnection.CreateCommand()
oSQLCOmmand = oSQLconnect.CreateCommand()
oSQLCOmmand.CommandText = executeStatement oSQLCOmmand.CommandText = executeStatement
oSQLCOmmand.CommandTimeout = commandtimeout oSQLCOmmand.CommandTimeout = commandtimeout
oSQLCOmmand.ExecuteNonQuery() oSQLCOmmand.ExecuteNonQuery()
oSQLCOmmand.Dispose() oSQLCOmmand.Dispose()
oSQLconnect.Close()
Return True Return True
Catch ex As Exception Catch ex As Exception
Logger.Error(ex) Logger.Error(ex)
@ -82,22 +113,21 @@ Public Class SQLServer
''' <param name="commandtimeout">Optional Timeout</param> ''' <param name="commandtimeout">Optional Timeout</param>
''' <remarks></remarks> ''' <remarks></remarks>
Public Sub NewExecuteNonQueryAsync(executeStatement As String, Optional commandtimeout As Integer = 120) Public Sub NewExecuteNonQueryAsync(executeStatement As String, Optional commandtimeout As Integer = 120)
Dim oSQLconnect As New SqlClient.SqlConnection If GetSQLConnection() = False Then
Exit Sub
End If
Dim oSQLCOmmand As SqlClient.SqlCommand Dim oSQLCOmmand As SqlClient.SqlCommand
Dim callback As New AsyncCallback(AddressOf Execute_non_Query_Async_Callback) Dim callback As New AsyncCallback(AddressOf Execute_non_Query_Async_Callback)
Try Try
oSQLconnect.ConnectionString = CurrentSQLConnectionString oSQLCOmmand = CurrentSQLConnection.CreateCommand()
oSQLconnect.Open()
oSQLCOmmand = oSQLconnect.CreateCommand()
oSQLCOmmand.CommandText = executeStatement oSQLCOmmand.CommandText = executeStatement
oSQLCOmmand.CommandTimeout = commandtimeout oSQLCOmmand.CommandTimeout = commandtimeout
oSQLCOmmand.BeginExecuteNonQuery(callback, oSQLCOmmand) oSQLCOmmand.BeginExecuteNonQuery(callback, oSQLCOmmand)
oSQLCOmmand.Dispose()
Catch ex As Exception Catch ex As Exception
Logger.Error(ex) Logger.Error(ex)
Logger.Debug("executeStatement: " & executeStatement) Logger.Debug("executeStatement: " & executeStatement)
Finally
oSQLCOmmand.Dispose()
oSQLconnect.Close()
End Try End Try
End Sub End Sub
@ -116,18 +146,16 @@ Public Class SQLServer
Public Function NewExecuteScalar(executeStatement As String, Optional commandtimeout As Integer = 120) Public Function NewExecuteScalar(executeStatement As String, Optional commandtimeout As Integer = 120)
Dim result Dim result
Try Try
Dim oSQLconnect As New SqlClient.SqlConnection If GetSQLConnection() = False Then
Dim oSQLCOmmand As SqlClient.SqlCommand Return Nothing
oSQLconnect.ConnectionString = CurrentSQLConnectionString End If
oSQLconnect.Open()
oSQLCOmmand = oSQLconnect.CreateCommand()
Dim oSQLCOmmand As SqlClient.SqlCommand
oSQLCOmmand = CurrentSQLConnection.CreateCommand()
oSQLCOmmand.CommandText = executeStatement oSQLCOmmand.CommandText = executeStatement
oSQLCOmmand.CommandTimeout = commandtimeout oSQLCOmmand.CommandTimeout = commandtimeout
result = oSQLCOmmand.ExecuteScalar() result = oSQLCOmmand.ExecuteScalar()
oSQLCOmmand.Dispose() oSQLCOmmand.Dispose()
oSQLconnect.Close()
Return result Return result
Catch ex As Exception Catch ex As Exception
Logger.Error(ex) Logger.Error(ex)

View File

@ -43,6 +43,18 @@
<OptionInfer>On</OptionInfer> <OptionInfer>On</OptionInfer>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<Reference Include="EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL">
<HintPath>..\packages\EntityFramework.6.2.0\lib\net45\EntityFramework.dll</HintPath>
</Reference>
<Reference Include="EntityFramework.Firebird, Version=6.1.0.0, Culture=neutral, PublicKeyToken=42d22d092898e5f8, processorArchitecture=MSIL">
<HintPath>..\packages\EntityFramework.Firebird.6.1.0\lib\net452\EntityFramework.Firebird.dll</HintPath>
</Reference>
<Reference Include="EntityFramework.SqlServer, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL">
<HintPath>..\packages\EntityFramework.6.2.0\lib\net45\EntityFramework.SqlServer.dll</HintPath>
</Reference>
<Reference Include="FirebirdSql.Data.FirebirdClient, Version=6.0.0.0, Culture=neutral, PublicKeyToken=3750abcc3150b00c, processorArchitecture=MSIL">
<HintPath>..\packages\FirebirdSql.Data.FirebirdClient.6.0.0\lib\net452\FirebirdSql.Data.FirebirdClient.dll</HintPath>
</Reference>
<Reference Include="Microsoft.CSharp" /> <Reference Include="Microsoft.CSharp" />
<Reference Include="NLog, Version=4.0.0.0, Culture=neutral, PublicKeyToken=5120e14c03d0593c, processorArchitecture=MSIL"> <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> <HintPath>..\packages\NLog.4.5.8\lib\net45\NLog.dll</HintPath>
@ -51,6 +63,7 @@
<HintPath>P:\Visual Studio Projekte\Bibliotheken\Oracle.ManagedDataAccess.dll</HintPath> <HintPath>P:\Visual Studio Projekte\Bibliotheken\Oracle.ManagedDataAccess.dll</HintPath>
</Reference> </Reference>
<Reference Include="System" /> <Reference Include="System" />
<Reference Include="System.ComponentModel.DataAnnotations" />
<Reference Include="System.Configuration" /> <Reference Include="System.Configuration" />
<Reference Include="System.Data" /> <Reference Include="System.Data" />
<Reference Include="System.IO.Compression" /> <Reference Include="System.IO.Compression" />
@ -77,7 +90,7 @@
<ItemGroup> <ItemGroup>
<Compile Include="Firebird.vb" /> <Compile Include="Firebird.vb" />
<Compile Include="Oracle.vb" /> <Compile Include="Oracle.vb" />
<Compile Include="SQLServer.vb" /> <Compile Include="MSSQLServer.vb" />
<Compile Include="My Project\AssemblyInfo.vb" /> <Compile Include="My Project\AssemblyInfo.vb" />
<Compile Include="My Project\Application.Designer.vb"> <Compile Include="My Project\Application.Designer.vb">
<AutoGen>True</AutoGen> <AutoGen>True</AutoGen>
@ -103,6 +116,7 @@
</EmbeddedResource> </EmbeddedResource>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<None Include="App.config" />
<None Include="My Project\Application.myapp"> <None Include="My Project\Application.myapp">
<Generator>MyApplicationCodeGenerator</Generator> <Generator>MyApplicationCodeGenerator</Generator>
<LastGenOutput>Application.Designer.vb</LastGenOutput> <LastGenOutput>Application.Designer.vb</LastGenOutput>

View File

@ -3,4 +3,133 @@ Public Class Oracle
Private Shared Logger As NLog.Logger = NLog.LogManager.GetCurrentClassLogger Private Shared Logger As NLog.Logger = NLog.LogManager.GetCurrentClassLogger
Public DBInitialized As Boolean = False Public DBInitialized As Boolean = False
Public CurrentOracleConnectionString As String = "" Public CurrentOracleConnectionString As String = ""
Public Sub New(CONSTRING As String)
Init(CONSTRING)
End Sub
Public Function Init(CONSTRING As String)
Try
Dim oSQLconnect As New OracleConnection
oSQLconnect.ConnectionString = CONSTRING
oSQLconnect.Open()
oSQLconnect.Close()
CurrentOracleConnectionString = CONSTRING
DBInitialized = True
Return True
Catch ex As Exception
DBInitialized = False
Logger.Error(ex)
'clsLogger.Add("Error in DatabaseInit: " & ex.Message, True)
Return False
End Try
End Function
''' <summary>
''' Returns a datatable for a sql-statement
''' </summary>
''' <param name="sqlcommand">sqlcommand for datatable (select XYZ from TableORView)</param>
''' <param name="commandtimeout">Optional Timeout</param>
''' <returns>Returns a datatable</returns>
''' <remarks></remarks>
Public Function GetDatatable(sqlcommand As String, Optional commandtimeout As Integer = 120) As DataTable
Try
Dim oSQLconnect As New OracleConnection
Dim oSQLCOmmand As OracleCommand
oSQLconnect.ConnectionString = CurrentOracleConnectionString
oSQLconnect.Open()
oSQLCOmmand = oSQLconnect.CreateCommand()
oSQLCOmmand.CommandText = sqlcommand
oSQLCOmmand.CommandTimeout = commandtimeout
Dim adapter1 As OracleDataAdapter = New OracleDataAdapter(oSQLCOmmand)
Dim dt As DataTable = New DataTable()
adapter1.Fill(dt)
oSQLconnect.Close()
Return dt
Catch ex As Exception
Logger.Error(ex)
Logger.Debug("sqlcommand: " & sqlcommand)
Return Nothing
End Try
End Function
''' <summary>
''' Executes the passed sql-statement
''' </summary>
''' <param name="executeStatement">the sql statement</param>
''' <param name="commandtimeout">Optional Timeout</param>
''' <returns>Returns true if properly executed, else false</returns>
''' <remarks></remarks>
Public Function NewExecutenonQuery(executeStatement As String, Optional commandtimeout As Integer = 120) As Boolean
Try
Dim oSQLconnect As New OracleConnection
Dim oSQLCOmmand As OracleCommand
oSQLconnect.ConnectionString = CurrentOracleConnectionString
oSQLconnect.Open()
oSQLCOmmand = oSQLconnect.CreateCommand()
oSQLCOmmand.CommandText = executeStatement
oSQLCOmmand.CommandTimeout = commandtimeout
oSQLCOmmand.ExecuteNonQuery()
oSQLCOmmand.Dispose()
oSQLconnect.Close()
Return True
Catch ex As Exception
Logger.Error(ex)
Logger.Debug("executeStatement: " & executeStatement)
Return False
End Try
End Function
''' <summary>
''' Executes the passed sql-statement in asyncmode
''' </summary>
''' <param name="executeStatement">the sql statement</param>
''' <param name="commandtimeout">Optional Timeout</param>
''' <remarks></remarks>
Public Sub NewExecuteNonQueryAsync(executeStatement As String, Optional commandtimeout As Integer = 120)
Dim oSQLconnect As New OracleConnection
Dim oSQLCOmmand As OracleCommand
Dim callback As New AsyncCallback(AddressOf Execute_non_Query_Async_Callback)
Try
oSQLconnect.ConnectionString = CurrentOracleConnectionString
oSQLconnect.Open()
oSQLCOmmand = oSQLconnect.CreateCommand()
oSQLCOmmand.CommandText = executeStatement
oSQLCOmmand.CommandTimeout = commandtimeout
oSQLCOmmand.ExecuteNonQuery()
oSQLCOmmand.Dispose()
oSQLconnect.Close()
Catch ex As Exception
Logger.Error(ex)
Logger.Debug("executeStatement: " & executeStatement)
End Try
End Sub
Private Sub Execute_non_Query_Async_Callback(ByVal result As IAsyncResult)
Dim command As OracleCommand = CType(result.AsyncState, OracleCommand)
Dim res = command.ExecuteNonQuery
Logger.Info(String.Format("Finished executing Async database operation: {0}", command.CommandText))
End Sub
''' <summary>
''' Executes the passed sql-statement as Scalar
''' </summary>
''' <param name="executeStatement">the sql statement</param>
''' <param name="commandtimeout">Optional Timeout</param>
''' <returns>Returns true if properly executed, else false</returns>
''' <remarks></remarks>
Public Function NewExecuteScalar(executeStatement As String, Optional commandtimeout As Integer = 120)
Dim result
Try
Dim oSQLconnect As New OracleConnection
Dim oSQLCOmmand As OracleCommand
oSQLconnect.ConnectionString = CurrentOracleConnectionString
oSQLconnect.Open()
oSQLCOmmand = oSQLconnect.CreateCommand()
oSQLCOmmand.CommandText = executeStatement
oSQLCOmmand.CommandTimeout = commandtimeout
result = oSQLCOmmand.ExecuteScalar()
oSQLCOmmand.Dispose()
oSQLconnect.Close()
Return result
Catch ex As Exception
Logger.Error(ex)
Logger.Debug("executeStatement: " & executeStatement)
Return Nothing
End Try
End Function
End Class End Class

View File

@ -1,4 +1,7 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<packages> <packages>
<package id="EntityFramework" version="6.2.0" targetFramework="net461" />
<package id="EntityFramework.Firebird" version="6.1.0" targetFramework="net461" />
<package id="FirebirdSql.Data.FirebirdClient" version="6.0.0" targetFramework="net461" />
<package id="NLog" version="4.5.8" targetFramework="net461" /> <package id="NLog" version="4.5.8" targetFramework="net461" />
</packages> </packages>

View File

@ -202,7 +202,7 @@ Public Class Windream
Dim i As Integer = 0 Dim i As Integer = 0
Dim value = aValues(i) Dim value = aValues(i)
Dim oWMValueConverted Dim oWMValueConverted = Nothing
Dim vektor As Boolean = False Dim vektor As Boolean = False
'Den Typ des Index-Feldes auslesen 'Den Typ des Index-Feldes auslesen
@ -353,7 +353,7 @@ Public Class Windream
''' <param name="folderObjecttype">Obcjectype Name</param> ''' <param name="folderObjecttype">Obcjectype Name</param>
''' <returns>Returns true when Otype was set, false if not</returns> ''' <returns>Returns true when Otype was set, false if not</returns>
''' <remarks></remarks> ''' <remarks></remarks>
Public Function NewObjecttypeForFolder(folderpath As String, folderObjecttype As String) Public Function NewObjecttypeForFolder(folderpath As String, folderObjecttype As String) As Boolean
Try Try
Dim result As Boolean = False Dim result As Boolean = False
Dim WMFolder As WINDREAMLib.WMObject Dim WMFolder As WINDREAMLib.WMObject
@ -397,9 +397,8 @@ Public Class Windream
Catch ex As Exception Catch ex As Exception
' wenn das entsperren nicht geklappt hat, dann war die Datei auch nicht gesperrt ' wenn das entsperren nicht geklappt hat, dann war die Datei auch nicht gesperrt
End Try End Try
Return result
End If End If
Return result
Catch ex As Exception Catch ex As Exception
Logger.Error(ex) Logger.Error(ex)
@ -733,7 +732,7 @@ Public Class Windream
Try Try
Dim missing As Boolean = False Dim missing As Boolean = False
Dim valueCount As Integer = 0 Dim valueCount As Integer = 0
Dim ValueArray() Dim ValueArray() = Nothing
'Jeden Wert des Vektorfeldes durchlaufen 'Jeden Wert des Vektorfeldes durchlaufen
Dim DT_RESULT = GetValueforIndex(oDocument.aPath, vktIndexName) Dim DT_RESULT = GetValueforIndex(oDocument.aPath, vktIndexName)
If DT_RESULT.Rows.Count > 0 Then If DT_RESULT.Rows.Count > 0 Then
@ -922,7 +921,7 @@ Public Class Windream
Return False Return False
End If End If
Dim containsvalue As Boolean = False Dim containsvalue As Boolean = False
Dim ValueArray() Dim ValueArray() = Nothing
'Jeden Wert des Vektorfeldes durchlaufen 'Jeden Wert des Vektorfeldes durchlaufen
Dim WMValue = oWMFile.GetVariableValue(vktIndexName) Dim WMValue = oWMFile.GetVariableValue(vktIndexName)
If WMValue Is Nothing = False Then If WMValue Is Nothing = False Then