You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

264 lines
8.7 KiB

Imports System.Data.SqlClient
Public Class DataAccess
#Region "Public methods"
'''<summary>Gibt eine Liste mit allen Tabellen welche gesichert werden müssen zurück</summary>
'''<param name="ds"></param>
Overloads Shared Sub GetTableList(ByRef ds As DataSet)
Dim sqlConn As New SqlConnection
Dim sqlCmd As New SqlCommand
Dim da As New SqlDataAdapter
Try
sqlCmd.CommandText = "EDKB05_ListJournalSaveTabellen"
sqlCmd.CommandType = CommandType.StoredProcedure
sqlCmd.Connection = sqlConn
Dim settings As New EDKB05.Common.Settings
sqlCmd.CommandTimeout = settings.GetSqlTimeout()
sqlConn.ConnectionString = EDKB05.Common.Datenbank.GetDSN()
da.SelectCommand = sqlCmd
da.Fill(ds, "JournalSaveTabellenList")
Catch ex As Exception
Throw ex
Finally
If sqlCmd Is Nothing Then
sqlCmd.Dispose()
End If
If sqlConn Is Nothing Then
sqlConn.Dispose()
End If
If da Is Nothing Then
da.Dispose()
End If
End Try
End Sub
'''<summary>Gibt alle zu sichernden Daten von einer Tabelle zurück</summary>
'''<param name="month">Zu sichernder Monat (Format mm.yyyy)</param>
'''<param name="dateField">Das Feld, welches das Vergleichsdatum enthält</param>
'''<param name="tableName">Der Name der Tabelle</param>
Overloads Shared Function GetTableData(ByVal month As String, ByVal dateField As String, ByVal tableName As String) As SqlDataReader
Dim sqlConn As New SqlConnection
Dim sqlCmd As New SqlCommand
Dim da As New SqlDataAdapter
Try
sqlCmd.CommandText = "EDKB05_GetTableData"
sqlCmd.CommandType = CommandType.StoredProcedure
sqlCmd.Connection = sqlConn
Dim settings As New EDKB05.Common.Settings
sqlCmd.CommandTimeout = settings.GetSqlTimeout()
sqlConn.ConnectionString = EDKB05.Common.Datenbank.GetDSN()
sqlCmd.Parameters.Add(New SqlParameter("@LastMonth", month))
sqlCmd.Parameters.Add(New SqlParameter("@DateField", dateField))
sqlCmd.Parameters.Add(New SqlParameter("@TableName", tableName))
'da.SelectCommand = sqlCmd
'da.Fill(ds, "TableData")
sqlConn.Open()
Return sqlCmd.ExecuteReader(CommandBehavior.SingleResult)
Catch ex As Exception
Throw ex
Finally
If sqlCmd Is Nothing Then
sqlCmd.Dispose()
End If
If sqlConn Is Nothing Then
sqlConn.Dispose()
End If
If da Is Nothing Then
da.Dispose()
End If
End Try
End Function
'''<summary>Erstellt einen neuen Eintrag in der Journal Tabelle</summary>
'''<param name="fileName">Name der erstellten Zips</param>
'''<param name="month">Verarbeiteter Monat im Format mm.yyyy</param>
'''<param name="eintragNr">Gitb die Id des erstellten Journals zurück</param>
Overloads Shared Sub InsJounal(ByVal fileName As String, ByVal month As String, ByRef eintragNr As Integer)
Dim sqlConn As New SqlConnection
Dim sqlCmd As New SqlCommand
Try
sqlCmd.CommandText = "EDKB05_InsJournal"
sqlCmd.CommandType = CommandType.StoredProcedure
sqlCmd.Connection = sqlConn
Dim settings As New EDKB05.Common.Settings
sqlCmd.CommandTimeout = settings.GetSqlTimeout()
sqlConn.ConnectionString = EDKB05.Common.Datenbank.GetDSN()
sqlCmd.Parameters.Add(New SqlParameter("@FileName", fileName))
sqlCmd.Parameters.Add(New SqlParameter("@Month", month))
sqlCmd.Parameters.Add(New SqlParameter("@EintragNr", 0))
sqlCmd.Parameters("@EintragNr").Direction = ParameterDirection.Output
sqlConn.Open()
sqlCmd.ExecuteNonQuery()
eintragNr = CInt(sqlCmd.Parameters("@EintragNr").Value)
Catch ex As Exception
Throw ex
Finally
If sqlCmd Is Nothing Then
sqlCmd.Dispose()
End If
If sqlConn Is Nothing Then
sqlConn.Dispose()
End If
End Try
End Sub
'''<summary>Erstellt einen neuen Eintrag in der Tabelle JournalDetail</summary>
'''<param name="journalNr"></param>
'''<param name="tableName"></param>
'''<param name="rowCount"></param>
Overloads Shared Sub InsJounalDetail(ByVal journalNr As Integer, ByVal tableName As String, ByVal rowCount As Integer)
Dim sqlConn As New SqlConnection
Dim sqlCmd As New SqlCommand
Try
sqlCmd.CommandText = "EDKB05_InsJournalDetail"
sqlCmd.CommandType = CommandType.StoredProcedure
sqlCmd.Connection = sqlConn
Dim settings As New EDKB05.Common.Settings
sqlCmd.CommandTimeout = settings.GetSqlTimeout()
sqlConn.ConnectionString = EDKB05.Common.Datenbank.GetDSN()
sqlCmd.Parameters.Add(New SqlParameter("@JournalNr", journalNr))
sqlCmd.Parameters.Add(New SqlParameter("@TableName", tableName))
sqlCmd.Parameters.Add(New SqlParameter("@RowCount", rowCount))
sqlConn.Open()
sqlCmd.ExecuteNonQuery()
Catch ex As Exception
Throw ex
Finally
If sqlCmd Is Nothing Then
sqlCmd.Dispose()
End If
If sqlConn Is Nothing Then
sqlConn.Dispose()
End If
End Try
End Sub
'''<summary>Löscht alle Journale, welche von der verantwortlichen Person bestätigt wurden</summary>
Overloads Shared Sub DelJournale()
Dim sqlConn As New SqlConnection
Dim sqlCmd As New SqlCommand
Try
sqlCmd.CommandText = "EDKB05_DelJournale"
sqlCmd.CommandType = CommandType.StoredProcedure
sqlCmd.Connection = sqlConn
Dim settings As New EDKB05.Common.Settings
sqlCmd.CommandTimeout = settings.GetSqlTimeout()
sqlConn.ConnectionString = EDKB05.Common.Datenbank.GetDSN()
sqlConn.Open()
sqlCmd.ExecuteNonQuery()
Catch ex As Exception
Throw ex
Finally
If sqlCmd Is Nothing Then
sqlCmd.Dispose()
End If
If sqlConn Is Nothing Then
sqlConn.Dispose()
End If
End Try
End Sub
'''<summary>Markiert ein Journal als vollständig</summary>
'''<param name="journalNr"></param>
Overloads Shared Sub UpdJournalSetVollstaendig(ByVal journalNr As Integer)
Dim sqlConn As New SqlConnection
Dim sqlCmd As New SqlCommand
Try
sqlCmd.CommandText = "EDKB05_UpdJournalSetVollstaendig"
sqlCmd.CommandType = CommandType.StoredProcedure
sqlCmd.Connection = sqlConn
Dim settings As New EDKB05.Common.Settings
sqlCmd.CommandTimeout = settings.GetSqlTimeout()
sqlConn.ConnectionString = EDKB05.Common.Datenbank.GetDSN()
sqlCmd.Parameters.Add(New SqlParameter("@JournalNr", journalNr))
sqlConn.Open()
sqlCmd.ExecuteNonQuery()
Catch ex As Exception
Throw ex
Finally
If sqlCmd Is Nothing Then
sqlCmd.Dispose()
End If
If sqlConn Is Nothing Then
sqlConn.Dispose()
End If
End Try
End Sub
'''<summary>Gibt alle zu Löschenden ZipDateinamen zurück</summary>
'''<param name="ds"></param>
Overloads Shared Function GetFileNameForDeletet(ByRef ds As DataSet) As SqlDataReader
Dim sqlConn As New SqlConnection
Dim sqlCmd As New SqlCommand
Dim da As New SqlDataAdapter
GetFileNameForDeletet = Nothing
Try
sqlCmd.CommandText = "EDKB05_GetFileNameForDeletet"
sqlCmd.CommandType = CommandType.StoredProcedure
sqlCmd.Connection = sqlConn
Dim settings As New EDKB05.Common.Settings
sqlCmd.CommandTimeout = settings.GetSqlTimeout()
sqlConn.ConnectionString = EDKB05.Common.Datenbank.GetDSN()
da.SelectCommand = sqlCmd
da.Fill(ds, "JournalSaveTabellenList")
Catch ex As Exception
Throw ex
Finally
If sqlCmd Is Nothing Then
sqlCmd.Dispose()
End If
If sqlConn Is Nothing Then
sqlConn.Dispose()
End If
If da Is Nothing Then
da.Dispose()
End If
End Try
End Function
#End Region
End Class