diff --git a/VERAG_PROG_ALLGEMEIN/AVISO/cDatenbankAVISO.vb b/VERAG_PROG_ALLGEMEIN/AVISO/cDatenbankAVISO.vb index 02821350..497f09a9 100644 --- a/VERAG_PROG_ALLGEMEIN/AVISO/cDatenbankAVISO.vb +++ b/VERAG_PROG_ALLGEMEIN/AVISO/cDatenbankAVISO.vb @@ -6,6 +6,7 @@ Imports System.Data.SqlClient Imports System.Globalization Imports System.Reflection Imports System.Web.UI.WebControls.WebParts +Imports System.Windows.Forms Public Class cSqlDb @@ -2437,6 +2438,568 @@ Public Class cVermerkeDAL End Class +Public Class cAvisoTvNew + Public Property TVID As Integer + Public Property TvTextBezeichnungID As Integer + Public Property TvTextBezeichnung As String + Public Property FixeZeile1RTF As String + Public Property FixeZeile1HTML As String + Public Property FixeZeile2 As String + Public Property FixeZeile3 As String + Public Property StandortID As Integer + Public Property Standort As String + Public Property Art As String + Public Property StartDate As Date? + Public Property EndDate As Date? + Public Property StartTime As TimeSpan? + Public Property EndTime As TimeSpan? + Public Property IsRecurring As Boolean? + Public Property IsMonday As Boolean? + Public Property IsTuesday As Boolean? + Public Property IsWednesday As Boolean? + Public Property IsThursday As Boolean? + Public Property IsFriday As Boolean? + Public Property IsSaturday As Boolean? + Public Property IsSunday As Boolean? + Public Property IsActive As Boolean + Public Property Position As String + + Public Property FontFamily As String = "Microsoft Sans Serif" + Public Property FontSize As Single = 12.0F + Public Property FontStyle As String = "Regular" + Public Property TextColor As String = "Black" + Public Property BackColor As String = "White" + Public Property TextAlignment As String = "Left" + +End Class + +Public Class cTvTextBezeichnung + Public Property TvTextBezeichnungID As Integer + Public Property TvTextBezeichnung As String +End Class + + +Public Class cAvisoTvNewDAL + + ' Methode zum Abrufen der StandortID basierend auf dem Standortnamen + Public Function GetStandortID(standort As String) As Integer + Dim standortID As Integer = 0 + Dim sql As String = "SELECT StandortID FROM Standorte WHERE Standort = @Standort" + + Try + Dim conn As SqlConnection = cDatenbankAVISO.GetNewOpenConnectionWithoutError() + If conn Is Nothing Then + Throw New Exception("Die Datenbankverbindung konnte nicht hergestellt werden.") + End If + + Using cmd As New SqlCommand(sql, conn) + cmd.Parameters.AddWithValue("@Standort", standort) + Dim result As Object = cmd.ExecuteScalar() + If result IsNot Nothing AndAlso Not IsDBNull(result) Then + standortID = Convert.ToInt32(result) + End If + End Using + Catch ex As SqlException + ' Ausnahme weiterwerfen mit spezifischer Fehlermeldung + Throw New Exception("SQL Fehler beim Abrufen der StandortID: " & ex.Message) + Catch ex As Exception + ' Allgemeine Ausnahme weiterwerfen + Throw New Exception("Allgemeiner Fehler beim Abrufen der StandortID: " & ex.Message) + End Try + + Return standortID + End Function + + Public Function LadenAlleTvTextBezeichnungen() As List(Of cTvTextBezeichnung) + Dim bezeichnungen As New List(Of cTvTextBezeichnung)() + + Try + Dim conn As SqlConnection = cDatenbankAVISO.GetNewOpenConnectionWithoutError() + If conn Is Nothing Then + Throw New Exception("Die Datenbankverbindung konnte nicht hergestellt werden.") + End If + + Dim sql As String = " + SELECT TvTextBezeichnungID, TvTextBezeichnung + FROM AvisoTvNew + ORDER BY TvTextBezeichnung + " + + Using cmd As New SqlCommand(sql, conn) + Using dr As SqlDataReader = cmd.ExecuteReader() + While dr.Read() + Dim bezeichnung As New cTvTextBezeichnung() With { + .TvTextBezeichnungID = Convert.ToInt32(dr("TvTextBezeichnungID")), + .TvTextBezeichnung = Convert.ToString(dr("TvTextBezeichnung")) + } + bezeichnungen.Add(bezeichnung) + End While + End Using + End Using + Catch ex As SqlException + Throw New Exception("SQL Fehler beim Laden der TvTextBezeichnungen: " & ex.Message) + Catch ex As Exception + Throw New Exception("Allgemeiner Fehler beim Laden der TvTextBezeichnungen: " & ex.Message) + End Try + + Return bezeichnungen + End Function + + + + + + ' Methode zum Überprüfen, ob eine TvTextBezeichnung bereits für einen Standort existiert + Public Function IstTvTextBezeichnungVorhanden(tvTextBezeichnung As String) As Boolean + Dim vorhanden As Boolean = False + Dim sql As String = "SELECT COUNT(*) + FROM AvisoTvNew + WHERE TvTextBezeichnung = @TvTextBezeichnung" + + Try + Dim conn As SqlConnection = cDatenbankAVISO.GetNewOpenConnectionWithoutError() + If conn Is Nothing Then + Throw New Exception("Die Datenbankverbindung konnte nicht hergestellt werden.") + End If + + Using cmd As New SqlCommand(sql, conn) + cmd.Parameters.AddWithValue("@TvTextBezeichnung", tvTextBezeichnung) + Dim count As Integer = Convert.ToInt32(cmd.ExecuteScalar()) + If count > 0 Then + vorhanden = True + End If + End Using + Catch ex As SqlException + ' Ausnahme weiterwerfen mit spezifischer Fehlermeldung + Throw New Exception("SQL Fehler beim Überprüfen der TvTextBezeichnung: " & ex.Message) + Catch ex As Exception + ' Allgemeine Ausnahme weiterwerfen + Throw New Exception("Allgemeiner Fehler beim Überprüfen der TvTextBezeichnung: " & ex.Message) + End Try + + Return vorhanden + End Function + + ' Methode zum Lesen von AvisoTvNew-Einträgen + + Public Sub LesenAvisoTvNew(tvid As Integer, bezeichnung As String, standort As String, ByRef liste As List(Of cAvisoTvNew)) + Dim sql As String = "SELECT + stv.TvTextBezeichnungID, + stv.StandortID, + a.TvTextBezeichnung, + s.Standort, + stv.Position, + a.FixeZeile1RTF, + a.FixeZeile2, + a.FixeZeile3, + a.Art, + a.StartDate, + a.EndDate, + a.StartTime, + a.EndTime, + a.IsRecurring, + a.IsMonday, + a.IsTuesday, + a.IsWednesday, + a.IsThursday, + a.IsFriday, + a.IsSaturday, + a.IsSunday, + a.IsActive + FROM AvisoTvNew a + JOIN StandortTvBezeichnung stv ON a.TvTextBezeichnungID = stv.TvTextBezeichnungID + JOIN StandorteTV s ON stv.StandortID = s.StandortID + WHERE 1=1" + + If tvid <> 0 Then + sql &= " AND a.TvTextBezeichnungID = @TvTextBezeichnungID" + End If + + If Not String.IsNullOrWhiteSpace(bezeichnung) Then + sql &= " AND a.TVTextBezeichnung LIKE @TVTextBezeichnung" + End If + + If Not String.IsNullOrWhiteSpace(standort) Then + sql &= " AND s.Standort = @Standort" + End If + + Try + Dim conn As SqlConnection = cDatenbankAVISO.GetNewOpenConnectionWithoutError() + If conn Is Nothing Then + Throw New Exception("Die Datenbankverbindung konnte nicht hergestellt werden.") + End If + + Dim cmd As New SqlCommand(sql, conn) + If tvid <> 0 Then + cmd.Parameters.AddWithValue("@TvTextBezeichnungID", tvid) + End If + + If Not String.IsNullOrWhiteSpace(bezeichnung) Then + cmd.Parameters.AddWithValue("@TVTextBezeichnung", "%" & bezeichnung & "%") + End If + + If Not String.IsNullOrWhiteSpace(standort) Then + cmd.Parameters.AddWithValue("@Standort", standort) + End If + + Dim dr As SqlDataReader = cmd.ExecuteReader() + While dr.Read() + Dim aviso As New cAvisoTvNew() With { + .TvTextBezeichnungID = Convert.ToInt32(dr("TvTextBezeichnungID")), + .StandortID = Convert.ToInt32(dr("StandortID")), + .TvTextBezeichnung = Convert.ToString(dr("TVTextBezeichnung")), + .Standort = Convert.ToString(dr("Standort")), + .Position = If(IsDBNull(dr("Position")), Nothing, Convert.ToString(dr("Position"))), + .FixeZeile1RTF = If(IsDBNull(dr("FixeZeile1RTF")), Nothing, Convert.ToString(dr("FixeZeile1RTF"))), + .FixeZeile2 = If(IsDBNull(dr("FixeZeile2")), Nothing, Convert.ToString(dr("FixeZeile2"))), + .FixeZeile3 = If(IsDBNull(dr("FixeZeile3")), Nothing, Convert.ToString(dr("FixeZeile3"))), + .Art = If(IsDBNull(dr("Art")), Nothing, Convert.ToString(dr("Art"))), + .StartDate = If(IsDBNull(dr("StartDate")), CType(Nothing, Date?), Convert.ToDateTime(dr("StartDate"))), + .EndDate = If(IsDBNull(dr("EndDate")), CType(Nothing, Date?), Convert.ToDateTime(dr("EndDate"))), + .StartTime = If(IsDBNull(dr("StartTime")), CType(Nothing, TimeSpan?), Convert.ToDateTime(dr("StartTime")).TimeOfDay), + .EndTime = If(IsDBNull(dr("EndTime")), CType(Nothing, TimeSpan?), Convert.ToDateTime(dr("EndTime")).TimeOfDay), + .IsRecurring = If(IsDBNull(dr("IsRecurring")), CType(Nothing, Boolean?), Convert.ToBoolean(dr("IsRecurring"))), + .IsMonday = If(IsDBNull(dr("IsMonday")), CType(Nothing, Boolean?), Convert.ToBoolean(dr("IsMonday"))), + .IsTuesday = If(IsDBNull(dr("IsTuesday")), CType(Nothing, Boolean?), Convert.ToBoolean(dr("IsTuesday"))), + .IsWednesday = If(IsDBNull(dr("IsWednesday")), CType(Nothing, Boolean?), Convert.ToBoolean(dr("IsWednesday"))), + .IsThursday = If(IsDBNull(dr("IsThursday")), CType(Nothing, Boolean?), Convert.ToBoolean(dr("IsThursday"))), + .IsFriday = If(IsDBNull(dr("IsFriday")), CType(Nothing, Boolean?), Convert.ToBoolean(dr("IsFriday"))), + .IsSaturday = If(IsDBNull(dr("IsSaturday")), CType(Nothing, Boolean?), Convert.ToBoolean(dr("IsSaturday"))), + .IsSunday = If(IsDBNull(dr("IsSunday")), CType(Nothing, Boolean?), Convert.ToBoolean(dr("IsSunday"))), + .IsActive = Convert.ToBoolean(dr("IsActive")) + } + liste.Add(aviso) + End While + dr.Close() + cmd.Dispose() + conn.Close() + Catch ex As SqlException + ' Ausnahme weiterwerfen mit spezifischer Fehlermeldung + Throw New Exception("SQL Fehler beim Lesen der Daten: " & ex.Message) + Catch ex As Exception + ' Allgemeine Ausnahme weiterwerfen + Throw New Exception("Allgemeiner Fehler beim Lesen der Daten: " & ex.Message) + End Try + End Sub + + Public Sub LesenAlleAvisoTvNew(ByRef liste As List(Of cAvisoTvNew)) + ' Basis-SQL-Abfrage ohne Filter + Dim sql As String = "SELECT + a.TvTextBezeichnungID, + a.TvTextBezeichnung, + a.FixeZeile1RTF, + a.FixeZeile2, + a.FixeZeile3, + a.Art, + a.StartDate, + a.EndDate, + a.StartTime, + a.EndTime, + a.IsRecurring, + a.IsMonday, + a.IsTuesday, + a.IsWednesday, + a.IsThursday, + a.IsFriday, + a.IsSaturday, + a.IsSunday, + a.IsActive + FROM AvisoTvNew a" + + Dim conn As SqlConnection = Nothing + Dim cmd As SqlCommand = Nothing + Dim dr As SqlDataReader = Nothing + + Try + conn = cDatenbankAVISO.GetNewOpenConnectionWithoutError() + If conn Is Nothing Then + Throw New Exception("Die Datenbankverbindung konnte nicht hergestellt werden.") + End If + + cmd = New SqlCommand(sql, conn) + + ' Keine Parameter erforderlich, da keine Filter + + ' Daten lesen und Objekte erstellen + dr = cmd.ExecuteReader() + While dr.Read() + Dim aviso As New cAvisoTvNew() With { + .TvTextBezeichnungID = If(IsDBNull(dr("TvTextBezeichnungID")), 0, Convert.ToInt32(dr("TvTextBezeichnungID"))), + .TvTextBezeichnung = If(IsDBNull(dr("TvTextBezeichnung")), String.Empty, dr("TvTextBezeichnung").ToString()), + .FixeZeile1RTF = If(IsDBNull(dr("FixeZeile1RTF")), Nothing, dr("FixeZeile1RTF").ToString()), + .FixeZeile2 = If(IsDBNull(dr("FixeZeile2")), Nothing, dr("FixeZeile2").ToString()), + .FixeZeile3 = If(IsDBNull(dr("FixeZeile3")), Nothing, dr("FixeZeile3").ToString()), + .Art = If(IsDBNull(dr("Art")), Nothing, dr("Art").ToString()), + .StartDate = If(IsDBNull(dr("StartDate")), CType(Nothing, Date?), Convert.ToDateTime(dr("StartDate"))), + .EndDate = If(IsDBNull(dr("EndDate")), CType(Nothing, Date?), Convert.ToDateTime(dr("EndDate"))), + .StartTime = If(IsDBNull(dr("StartTime")), CType(Nothing, TimeSpan?), Convert.ToDateTime(dr("StartTime")).TimeOfDay), + .EndTime = If(IsDBNull(dr("EndTime")), CType(Nothing, TimeSpan?), Convert.ToDateTime(dr("EndTime")).TimeOfDay), + .IsRecurring = If(IsDBNull(dr("IsRecurring")), CType(Nothing, Boolean?), Convert.ToBoolean(dr("IsRecurring"))), + .IsMonday = If(IsDBNull(dr("IsMonday")), CType(Nothing, Boolean?), Convert.ToBoolean(dr("IsMonday"))), + .IsTuesday = If(IsDBNull(dr("IsTuesday")), CType(Nothing, Boolean?), Convert.ToBoolean(dr("IsTuesday"))), + .IsWednesday = If(IsDBNull(dr("IsWednesday")), CType(Nothing, Boolean?), Convert.ToBoolean(dr("IsWednesday"))), + .IsThursday = If(IsDBNull(dr("IsThursday")), CType(Nothing, Boolean?), Convert.ToBoolean(dr("IsThursday"))), + .IsFriday = If(IsDBNull(dr("IsFriday")), CType(Nothing, Boolean?), Convert.ToBoolean(dr("IsFriday"))), + .IsSaturday = If(IsDBNull(dr("IsSaturday")), CType(Nothing, Boolean?), Convert.ToBoolean(dr("IsSaturday"))), + .IsSunday = If(IsDBNull(dr("IsSunday")), CType(Nothing, Boolean?), Convert.ToBoolean(dr("IsSunday"))), + .IsActive = If(IsDBNull(dr("IsActive")), False, Convert.ToBoolean(dr("IsActive"))) + } + + liste.Add(aviso) + End While + dr.Close() + cmd.Dispose() + conn.Close() + Catch ex As SqlException + ' Ausnahme weiterwerfen mit spezifischer Fehlermeldung + Throw New Exception($"SQL Fehler beim Lesen der Daten: {ex.Message}") + Catch ex As Exception + ' Allgemeine Ausnahme weiterwerfen + Throw New Exception($"Allgemeiner Fehler beim Lesen der Daten: {ex.Message}") + End Try + End Sub + + + + + ' Methode zum Speichern von AvisoTvNew-Einträgen + Public Sub SpeichernAvisoTvNew(aviso As cAvisoTvNew) + Dim conn As SqlConnection = Nothing + Dim cmd As SqlCommand = Nothing + Dim cmdLink As SqlCommand = Nothing + Dim transaction As SqlTransaction = Nothing + + Try + conn = cDatenbankAVISO.GetNewOpenConnectionWithoutError() + If conn Is Nothing Then + Throw New Exception("Die Datenbankverbindung konnte nicht hergestellt werden.") + End If + + ' Beginnen einer Transaktion, um Konsistenz zu gewährleisten + transaction = conn.BeginTransaction() + + Dim sql As String + + If aviso.TvTextBezeichnungID = 0 Then + ' Neuanlage + sql = "INSERT INTO AvisoTvNew ( + TvTextBezeichnung, + FixeZeile1RTF, + FixeZeile1HTML, + FixeZeile2, + FixeZeile3, + StartDate, + EndDate, + StartTime, + EndTime, + IsRecurring, + IsMonday, + IsTuesday, + IsWednesday, + IsThursday, + IsFriday, + IsSaturday, + IsSunday, + IsActive + ) VALUES ( + @TvTextBezeichnung, + @FixeZeile1RTF, + @FixeZeile1HTML, + @FixeZeile2, + @FixeZeile3, + @StartDate, + @EndDate, + @StartTime, + @EndTime, + @IsRecurring, + @IsMonday, + @IsTuesday, + @IsWednesday, + @IsThursday, + @IsFriday, + @IsSaturday, + @IsSunday, + @IsActive + ); + SELECT CAST(scope_identity() AS int);" + Else + ' Aktualisierung + sql = "UPDATE AvisoTvNew SET + FixeZeile1RTF = @FixeZeile1RTF, + FixeZeile1HTML = @FixeZeile1HTML, + FixeZeile2 = @FixeZeile2, + FixeZeile3 = @FixeZeile3, + StartDate = @StartDate, + EndDate = @EndDate, + StartTime = @StartTime, + EndTime = @EndTime, + IsRecurring = @IsRecurring, + IsMonday = @IsMonday, + IsTuesday = @IsTuesday, + IsWednesday = @IsWednesday, + IsThursday = @IsThursday, + IsFriday = @IsFriday, + IsSaturday = @IsSaturday, + IsSunday = @IsSunday, + IsActive = @IsActive + WHERE TvTextBezeichnungID = @TvTextBezeichnungID" + End If + + cmd = New SqlCommand(sql, conn, transaction) + + cmd.Parameters.AddWithValue("@FixeZeile1RTF", If(String.IsNullOrWhiteSpace(aviso.FixeZeile1RTF), CType(Nothing, String), aviso.FixeZeile1RTF)) + cmd.Parameters.AddWithValue("@FixeZeile1HTML", If(String.IsNullOrWhiteSpace(aviso.FixeZeile1HTML), CType(Nothing, String), aviso.FixeZeile1HTML)) + cmd.Parameters.AddWithValue("@FixeZeile2", If(String.IsNullOrWhiteSpace(aviso.FixeZeile2), CType(Nothing, String), aviso.FixeZeile2)) + cmd.Parameters.AddWithValue("@FixeZeile3", If(String.IsNullOrWhiteSpace(aviso.FixeZeile3), CType(Nothing, String), aviso.FixeZeile3)) + cmd.Parameters.AddWithValue("@StartDate", If(aviso.StartDate.HasValue, CType(aviso.StartDate.Value, Object), DBNull.Value)) + cmd.Parameters.AddWithValue("@EndDate", If(aviso.EndDate.HasValue, CType(aviso.EndDate.Value, Object), DBNull.Value)) + cmd.Parameters.AddWithValue("@StartTime", If(aviso.StartTime.HasValue, CType(aviso.StartTime.Value, Object), DBNull.Value)) + cmd.Parameters.AddWithValue("@EndTime", If(aviso.EndTime.HasValue, CType(aviso.EndTime.Value, Object), DBNull.Value)) + cmd.Parameters.AddWithValue("@IsRecurring", aviso.IsRecurring) + cmd.Parameters.AddWithValue("@IsMonday", aviso.IsMonday) + cmd.Parameters.AddWithValue("@IsTuesday", aviso.IsTuesday) + cmd.Parameters.AddWithValue("@IsWednesday", aviso.IsWednesday) + cmd.Parameters.AddWithValue("@IsThursday", aviso.IsThursday) + cmd.Parameters.AddWithValue("@IsFriday", aviso.IsFriday) + cmd.Parameters.AddWithValue("@IsSaturday", aviso.IsSaturday) + cmd.Parameters.AddWithValue("@IsSunday", aviso.IsSunday) + cmd.Parameters.AddWithValue("@IsActive", aviso.IsActive) + + If aviso.TvTextBezeichnungID <> 0 Then + cmd.Parameters.AddWithValue("@TvTextBezeichnungID", aviso.TvTextBezeichnungID) + End If + + If aviso.TvTextBezeichnungID = 0 Then + cmd.Parameters.AddWithValue("@TvTextBezeichnung", aviso.TvTextBezeichnung) + + ' Neuanlage: Führen Sie das INSERT aus und holen Sie die generierte ID + Dim result As Object = cmd.ExecuteScalar() + If result Is Nothing OrElse IsDBNull(result) Then + Throw New Exception("Das INSERT hat keine ID zurückgegeben.") + End If + aviso.TvTextBezeichnungID = Convert.ToInt32(result) + Else + ' Aktualisierung: Führen Sie das UPDATE aus + cmd.ExecuteNonQuery() + End If + + ' Einfügen oder Aktualisieren in die StandortTvBezeichnung-Tabelle + Dim sqlLink As String = " + IF EXISTS ( + SELECT 1 FROM StandortTvBezeichnung + WHERE StandortID = @StandortID AND TvTextBezeichnungID = @TvTextBezeichnungID + ) + BEGIN + UPDATE StandortTvBezeichnung + SET Position = @Position, + FontFamily = @FontFamily, + FontSize = @FontSize, + FontStyle = @FontStyle, + TextColor = @TextColor, + BackColor = @BackColor, + TextAlignment = @TextAlignment + WHERE StandortID = @StandortID AND TvTextBezeichnungID = @TvTextBezeichnungID + END + ELSE + BEGIN + INSERT INTO StandortTvBezeichnung (StandortID, TvTextBezeichnungID, Position, FontFamily, FontSize, FontStyle, TextColor, BackColor, TextAlignment) + VALUES (@StandortID, @TvTextBezeichnungID, @Position, @FontFamily, @FontSize, @FontStyle, @TextColor, @BackColor, @TextAlignment) + END + " + + cmdLink = New SqlCommand(sqlLink, conn, transaction) + cmdLink.Parameters.AddWithValue("@StandortID", aviso.StandortID) + cmdLink.Parameters.AddWithValue("@TvTextBezeichnungID", aviso.TvTextBezeichnungID) + cmdLink.Parameters.AddWithValue("@Position", If(String.IsNullOrEmpty(aviso.Position), DBNull.Value, aviso.Position)) + cmdLink.Parameters.AddWithValue("@FontFamily", aviso.FontFamily) + cmdLink.Parameters.AddWithValue("@FontSize", aviso.FontSize) + cmdLink.Parameters.AddWithValue("@FontStyle", aviso.FontStyle) + cmdLink.Parameters.AddWithValue("@TextColor", aviso.TextColor) + cmdLink.Parameters.AddWithValue("@BackColor", aviso.BackColor) + cmdLink.Parameters.AddWithValue("@TextAlignment", aviso.TextAlignment) + + cmdLink.ExecuteNonQuery() + + ' Transaktion committen, wenn alle Operationen erfolgreich waren + transaction.Commit() + + Catch ex As SqlException + ' Fehlerbehandlung: Transaktion zurückrollen und Fehler weiterwerfen + If transaction IsNot Nothing Then + Try + transaction.Rollback() + Catch rollbackEx As Exception + Throw New Exception("Fehler beim Zurückrollen der Transaktion: " & rollbackEx.Message) + End Try + End If + Throw New Exception("SQL Fehler beim Speichern des Eintrags: " & ex.Message) + Catch ex As Exception + ' Allgemeine Fehlerbehandlung: Transaktion zurückrollen und Fehler weiterwerfen + If transaction IsNot Nothing Then + Try + transaction.Rollback() + Catch rollbackEx As Exception + Throw New Exception("Fehler beim Zurückrollen der Transaktion: " & rollbackEx.Message) + End Try + End If + Throw New Exception("Allgemeiner Fehler beim Speichern des Eintrags: " & ex.Message) + Finally + ' Ressourcen manuell freigeben + If cmdLink IsNot Nothing Then + cmdLink.Dispose() + cmdLink = Nothing + End If + + If cmd IsNot Nothing Then + cmd.Dispose() + cmd = Nothing + End If + + If transaction IsNot Nothing Then + transaction.Dispose() + transaction = Nothing + End If + + If conn IsNot Nothing Then + conn.Close() + conn = Nothing + End If + End Try + End Sub + + + + ' Methode zum Setzen eines Eintrags auf inaktiv + Public Sub SetzeAufInaktiv(ByVal hID As Integer) + Dim sql As String = "UPDATE AvisoTvNew SET IsActive = 0 WHERE TVID = @TVID" + + Try + Dim conn As SqlConnection = cDatenbankAVISO.GetNewOpenConnectionWithoutError() + If conn Is Nothing Then + Throw New Exception("Die Datenbankverbindung konnte nicht hergestellt werden.") + End If + + Using cmd As New SqlCommand(sql, conn) + cmd.Parameters.AddWithValue("@TVID", hID) + Dim rowsAffected As Integer = cmd.ExecuteNonQuery() + If rowsAffected = 0 Then + Throw New Exception("Der Datensatz konnte nicht auf inaktiv gesetzt werden. Möglicherweise existiert er nicht mehr.") + End If + End Using + Catch ex As SqlException + ' Ausnahme weiterwerfen mit spezifischer Fehlermeldung + Throw New Exception("AvisoTvNew-Eintrag kann nicht auf inaktiv gesetzt werden! " & vbCrLf & ex.Message) + Catch ex As Exception + ' Allgemeine Ausnahme weiterwerfen + Throw New Exception("Fehler beim Setzen auf inaktiv: " & ex.Message) + End Try + End Sub + +End Class + + + + Public Class cAvisoTV Property TVID As Long = 0 Property FixeZeile1 As String