Imports System Imports System.Data Imports System.Data.SqlTypes Imports System.Data.SqlClient Namespace DB Public Class clsVorgabe Inherits clsDBInteractionBase #Region " Class Member Declarations " Private m_bAktiv As SqlBoolean Private m_daErstellt_am, m_daMutiert_am, m_daGueltig_Bis As SqlDateTime Private m_iVorgabeID, m_iMutierer, m_iParentID As SqlInt32 Private m_sBezeichnung, m_sDefinition, m_sBeschreibung, m_sKapitel, m_sErgaenzungen, m_sKapitelNr As SqlString #End Region Public Sub New() ' // Nothing for now. End Sub Overrides Public Function Insert() As Boolean Dim scmCmdToExecute As SqlCommand = New SqlCommand() scmCmdToExecute.CommandText = "dbo.[pr_Vorgabe_Insert]" scmCmdToExecute.CommandType = CommandType.StoredProcedure ' // Use base class' connection object scmCmdToExecute.Connection = m_scoMainConnection Try scmCmdToExecute.Parameters.Add(New SqlParameter("@iVorgabeID", SqlDbType.Int, 4, ParameterDirection.Input, False, 10, 0, "", DataRowVersion.Proposed, m_iVorgabeID)) scmCmdToExecute.Parameters.Add(New SqlParameter("@iParentID", SqlDbType.Int, 4, ParameterDirection.Input, True, 10, 0, "", DataRowVersion.Proposed, m_iParentID)) scmCmdToExecute.Parameters.Add(New SqlParameter("@sBezeichnung", SqlDbType.VarChar, 255, ParameterDirection.Input, True, 0, 0, "", DataRowVersion.Proposed, m_sBezeichnung)) scmCmdToExecute.Parameters.Add(New SqlParameter("@sBeschreibung", SqlDbType.VarChar, 255, ParameterDirection.Input, True, 0, 0, "", DataRowVersion.Proposed, m_sBeschreibung)) scmCmdToExecute.Parameters.Add(New SqlParameter("@sKapitelNr", SqlDbType.VarChar, 255, ParameterDirection.Input, True, 0, 0, "", DataRowVersion.Proposed, m_sKapitelNr)) scmCmdToExecute.Parameters.Add(New SqlParameter("@sKapitel", SqlDbType.VarChar, 255, ParameterDirection.Input, True, 0, 0, "", DataRowVersion.Proposed, m_sKapitel)) scmCmdToExecute.Parameters.Add(New SqlParameter("@sDefinition", SqlDbType.VarChar, 1024, ParameterDirection.Input, True, 0, 0, "", DataRowVersion.Proposed, m_sDefinition)) scmCmdToExecute.Parameters.Add(New SqlParameter("@sErgaenzungen", SqlDbType.VarChar, 1024, ParameterDirection.Input, True, 0, 0, "", DataRowVersion.Proposed, m_sErgaenzungen)) scmCmdToExecute.Parameters.Add(New SqlParameter("@bAktiv", SqlDbType.Bit, 1, ParameterDirection.Input, True, 0, 0, "", DataRowVersion.Proposed, m_bAktiv)) scmCmdToExecute.Parameters.Add(New SqlParameter("@daErstellt_am", SqlDbType.DateTime, 8, ParameterDirection.Input, True, 0, 0, "", DataRowVersion.Proposed, m_daErstellt_am)) scmCmdToExecute.Parameters.Add(New SqlParameter("@daMutiert_am", SqlDbType.DateTime, 8, ParameterDirection.Input, True, 0, 0, "", DataRowVersion.Proposed, m_daMutiert_am)) scmCmdToExecute.Parameters.Add(New SqlParameter("@iMutierer", SqlDbType.Int, 4, ParameterDirection.Input, True, 10, 0, "", DataRowVersion.Proposed, m_iMutierer)) scmCmdToExecute.Parameters.Add(New SqlParameter("@daGueltig_Bis", SqlDbType.DateTime, 8, ParameterDirection.Input, True, 0, 0, "", DataRowVersion.Proposed, m_daGueltig_Bis)) scmCmdToExecute.Parameters.Add(new SqlParameter("@iErrorCode", SqlDbType.Int, 4, ParameterDirection.Output, True, 10, 0, "", DataRowVersion.Proposed, m_iErrorCode)) If m_bMainConnectionIsCreatedLocal Then ' // Open connection. m_scoMainConnection.Open() Else If m_cpMainConnectionProvider.bIsTransactionPending Then scmCmdToExecute.Transaction = m_cpMainConnectionProvider.stCurrentTransaction End If End If ' // Execute query. m_iRowsAffected = scmCmdToExecute.ExecuteNonQuery() m_iErrorCode = New SqlInt32(CType(scmCmdToExecute.Parameters.Item("@iErrorCode").Value, SqlInt32)) If Not m_iErrorCode.Equals(New SqlInt32(LLBLError.AllOk)) Then ' // Throw error. Throw New Exception("Stored Procedure 'pr_Vorgabe_Insert' reported the ErrorCode: " & m_iErrorCode.ToString()) End If Return True Catch ex As Exception ' // some error occured. Bubble it to caller and encapsulate Exception object Throw New Exception("clsVorgabe::Insert::Error occured.", ex) Finally If m_bMainConnectionIsCreatedLocal Then ' // Close connection. m_scoMainConnection.Close() End If scmCmdToExecute.Dispose() End Try End Function Overrides Public Function Update() As Boolean Dim scmCmdToExecute As SqlCommand = New SqlCommand() scmCmdToExecute.CommandText = "dbo.[pr_Vorgabe_Update]" scmCmdToExecute.CommandType = CommandType.StoredProcedure ' // Use base class' connection object scmCmdToExecute.Connection = m_scoMainConnection Try scmCmdToExecute.Parameters.Add(New SqlParameter("@iVorgabeID", SqlDbType.Int, 4, ParameterDirection.Input, False, 10, 0, "", DataRowVersion.Proposed, m_iVorgabeID)) scmCmdToExecute.Parameters.Add(New SqlParameter("@iParentID", SqlDbType.Int, 4, ParameterDirection.Input, True, 10, 0, "", DataRowVersion.Proposed, m_iParentID)) scmCmdToExecute.Parameters.Add(New SqlParameter("@sBezeichnung", SqlDbType.VarChar, 255, ParameterDirection.Input, True, 0, 0, "", DataRowVersion.Proposed, m_sBezeichnung)) scmCmdToExecute.Parameters.Add(New SqlParameter("@sBeschreibung", SqlDbType.VarChar, 255, ParameterDirection.Input, True, 0, 0, "", DataRowVersion.Proposed, m_sBeschreibung)) scmCmdToExecute.Parameters.Add(New SqlParameter("@sKapitelNr", SqlDbType.VarChar, 255, ParameterDirection.Input, True, 0, 0, "", DataRowVersion.Proposed, m_sKapitelNr)) scmCmdToExecute.Parameters.Add(New SqlParameter("@sKapitel", SqlDbType.VarChar, 255, ParameterDirection.Input, True, 0, 0, "", DataRowVersion.Proposed, m_sKapitel)) scmCmdToExecute.Parameters.Add(New SqlParameter("@sDefinition", SqlDbType.VarChar, 1024, ParameterDirection.Input, True, 0, 0, "", DataRowVersion.Proposed, m_sDefinition)) scmCmdToExecute.Parameters.Add(New SqlParameter("@sErgaenzungen", SqlDbType.VarChar, 1024, ParameterDirection.Input, True, 0, 0, "", DataRowVersion.Proposed, m_sErgaenzungen)) scmCmdToExecute.Parameters.Add(New SqlParameter("@bAktiv", SqlDbType.Bit, 1, ParameterDirection.Input, True, 0, 0, "", DataRowVersion.Proposed, m_bAktiv)) scmCmdToExecute.Parameters.Add(New SqlParameter("@daErstellt_am", SqlDbType.DateTime, 8, ParameterDirection.Input, True, 0, 0, "", DataRowVersion.Proposed, m_daErstellt_am)) scmCmdToExecute.Parameters.Add(New SqlParameter("@daMutiert_am", SqlDbType.DateTime, 8, ParameterDirection.Input, True, 0, 0, "", DataRowVersion.Proposed, m_daMutiert_am)) scmCmdToExecute.Parameters.Add(New SqlParameter("@iMutierer", SqlDbType.Int, 4, ParameterDirection.Input, True, 10, 0, "", DataRowVersion.Proposed, m_iMutierer)) scmCmdToExecute.Parameters.Add(New SqlParameter("@daGueltig_Bis", SqlDbType.DateTime, 8, ParameterDirection.Input, True, 0, 0, "", DataRowVersion.Proposed, m_daGueltig_Bis)) scmCmdToExecute.Parameters.Add(new SqlParameter("@iErrorCode", SqlDbType.Int, 4, ParameterDirection.Output, True, 10, 0, "", DataRowVersion.Proposed, m_iErrorCode)) If m_bMainConnectionIsCreatedLocal Then ' // Open connection. m_scoMainConnection.Open() Else If m_cpMainConnectionProvider.bIsTransactionPending Then scmCmdToExecute.Transaction = m_cpMainConnectionProvider.stCurrentTransaction End If End If ' // Execute query. m_iRowsAffected = scmCmdToExecute.ExecuteNonQuery() m_iErrorCode = New SqlInt32(CType(scmCmdToExecute.Parameters.Item("@iErrorCode").Value, SqlInt32)) If Not m_iErrorCode.Equals(New SqlInt32(LLBLError.AllOk)) Then ' // Throw error. Throw New Exception("Stored Procedure 'pr_Vorgabe_Update' reported the ErrorCode: " & m_iErrorCode.ToString()) End If Return True Catch ex As Exception ' // some error occured. Bubble it to caller and encapsulate Exception object Throw New Exception("clsVorgabe::Update::Error occured.", ex) Finally If m_bMainConnectionIsCreatedLocal Then ' // Close connection. m_scoMainConnection.Close() End If scmCmdToExecute.Dispose() End Try End Function Overrides Public Function Delete() As Boolean Dim scmCmdToExecute As SqlCommand = New SqlCommand() scmCmdToExecute.CommandText = "dbo.[pr_Vorgabe_Delete]" scmCmdToExecute.CommandType = CommandType.StoredProcedure ' // Use base class' connection object scmCmdToExecute.Connection = m_scoMainConnection Try scmCmdToExecute.Parameters.Add(New SqlParameter("@iVorgabeID", SqlDbType.Int, 4, ParameterDirection.Input, False, 10, 0, "", DataRowVersion.Proposed, m_iVorgabeID)) scmCmdToExecute.Parameters.Add(new SqlParameter("@iErrorCode", SqlDbType.Int, 4, ParameterDirection.Output, True, 10, 0, "", DataRowVersion.Proposed, m_iErrorCode)) If m_bMainConnectionIsCreatedLocal Then ' // Open connection. m_scoMainConnection.Open() Else If m_cpMainConnectionProvider.bIsTransactionPending Then scmCmdToExecute.Transaction = m_cpMainConnectionProvider.stCurrentTransaction End If End If ' // Execute query. m_iRowsAffected = scmCmdToExecute.ExecuteNonQuery() m_iErrorCode = New SqlInt32(CType(scmCmdToExecute.Parameters.Item("@iErrorCode").Value, SqlInt32)) If Not m_iErrorCode.Equals(New SqlInt32(LLBLError.AllOk)) Then ' // Throw error. Throw New Exception("Stored Procedure 'pr_Vorgabe_Delete' reported the ErrorCode: " & m_iErrorCode.ToString()) End If Return True Catch ex As Exception ' // some error occured. Bubble it to caller and encapsulate Exception object Throw New Exception("clsVorgabe::Delete::Error occured.", ex) Finally If m_bMainConnectionIsCreatedLocal Then ' // Close connection. m_scoMainConnection.Close() End If scmCmdToExecute.Dispose() End Try End Function Overrides Public Function SelectOne() As DataTable Dim scmCmdToExecute As SqlCommand = New SqlCommand() scmCmdToExecute.CommandText = "dbo.[pr_Vorgabe_SelectOne]" scmCmdToExecute.CommandType = CommandType.StoredProcedure Dim dtToReturn As DataTable = new DataTable("Vorgabe") Dim sdaAdapter As SqlDataAdapter = new SqlDataAdapter(scmCmdToExecute) ' // Use base class' connection object scmCmdToExecute.Connection = m_scoMainConnection Try scmCmdToExecute.Parameters.Add(new SqlParameter("@iVorgabeID", SqlDbType.Int, 4, ParameterDirection.Input, False, 10, 0, "", DataRowVersion.Proposed, m_iVorgabeID)) scmCmdToExecute.Parameters.Add(new SqlParameter("@iErrorCode", SqlDbType.Int, 4, ParameterDirection.Output, True, 10, 0, "", DataRowVersion.Proposed, m_iErrorCode)) If m_bMainConnectionIsCreatedLocal Then ' // Open connection. m_scoMainConnection.Open() Else If m_cpMainConnectionProvider.bIsTransactionPending Then scmCmdToExecute.Transaction = m_cpMainConnectionProvider.stCurrentTransaction End If End If ' // Execute query. sdaAdapter.Fill(dtToReturn) m_iErrorCode = New SqlInt32(CType(scmCmdToExecute.Parameters.Item("@iErrorCode").Value, SqlInt32)) If Not m_iErrorCode.Equals(New SqlInt32(LLBLError.AllOk)) Then ' // Throw error. Throw New Exception("Stored Procedure 'pr_Vorgabe_SelectOne' reported the ErrorCode: " & m_iErrorCode.ToString()) End If If dtToReturn.Rows.Count > 0 Then m_iVorgabeID = New SqlInt32(CType(dtToReturn.Rows(0)("VorgabeID"), Integer)) If dtToReturn.Rows(0)("ParentID") Is System.DBNull.Value Then m_iParentID = SqlInt32.Null Else m_iParentID = New SqlInt32(CType(dtToReturn.Rows(0)("ParentID"), Integer)) End If If dtToReturn.Rows(0)("Bezeichnung") Is System.DBNull.Value Then m_sBezeichnung = SqlString.Null Else m_sBezeichnung = New SqlString(CType(dtToReturn.Rows(0)("Bezeichnung"), String)) End If If dtToReturn.Rows(0)("Beschreibung") Is System.DBNull.Value Then m_sBeschreibung = SqlString.Null Else m_sBeschreibung = New SqlString(CType(dtToReturn.Rows(0)("Beschreibung"), String)) End If If dtToReturn.Rows(0)("KapitelNr") Is System.DBNull.Value Then m_sKapitelNr = SqlString.Null Else m_sKapitelNr = New SqlString(CType(dtToReturn.Rows(0)("KapitelNr"), String)) End If If dtToReturn.Rows(0)("Kapitel") Is System.DBNull.Value Then m_sKapitel = SqlString.Null Else m_sKapitel = New SqlString(CType(dtToReturn.Rows(0)("Kapitel"), String)) End If If dtToReturn.Rows(0)("Definition") Is System.DBNull.Value Then m_sDefinition = SqlString.Null Else m_sDefinition = New SqlString(CType(dtToReturn.Rows(0)("Definition"), String)) End If If dtToReturn.Rows(0)("Ergaenzungen") Is System.DBNull.Value Then m_sErgaenzungen = SqlString.Null Else m_sErgaenzungen = New SqlString(CType(dtToReturn.Rows(0)("Ergaenzungen"), String)) End If If dtToReturn.Rows(0)("Aktiv") Is System.DBNull.Value Then m_bAktiv = SqlBoolean.Null Else m_bAktiv = New SqlBoolean(CType(dtToReturn.Rows(0)("Aktiv"), Boolean)) End If If dtToReturn.Rows(0)("Erstellt_am") Is System.DBNull.Value Then m_daErstellt_am = SqlDateTime.Null Else m_daErstellt_am = New SqlDateTime(CType(dtToReturn.Rows(0)("Erstellt_am"), Date)) End If If dtToReturn.Rows(0)("Mutiert_am") Is System.DBNull.Value Then m_daMutiert_am = SqlDateTime.Null Else m_daMutiert_am = New SqlDateTime(CType(dtToReturn.Rows(0)("Mutiert_am"), Date)) End If If dtToReturn.Rows(0)("Mutierer") Is System.DBNull.Value Then m_iMutierer = SqlInt32.Null Else m_iMutierer = New SqlInt32(CType(dtToReturn.Rows(0)("Mutierer"), Integer)) End If If dtToReturn.Rows(0)("Gueltig_Bis") Is System.DBNull.Value Then m_daGueltig_Bis = SqlDateTime.Null Else m_daGueltig_Bis = New SqlDateTime(CType(dtToReturn.Rows(0)("Gueltig_Bis"), Date)) End If End If Return dtToReturn Catch ex As Exception ' // some error occured. Bubble it to caller and encapsulate Exception object Throw New Exception("clsVorgabe::SelectOne::Error occured.", ex) Finally If m_bMainConnectionIsCreatedLocal Then ' // Close connection. m_scoMainConnection.Close() End If scmCmdToExecute.Dispose() sdaAdapter.Dispose() End Try End Function Overrides Public Function SelectAll() As DataTable Dim scmCmdToExecute As SqlCommand = New SqlCommand() scmCmdToExecute.CommandText = "dbo.[pr_Vorgabe_SelectAll]" scmCmdToExecute.CommandType = CommandType.StoredProcedure Dim dtToReturn As DataTable = new DataTable("Vorgabe") Dim sdaAdapter As SqlDataAdapter = new SqlDataAdapter(scmCmdToExecute) ' // Use base class' connection object scmCmdToExecute.Connection = m_scoMainConnection Try scmCmdToExecute.Parameters.Add(new SqlParameter("@iErrorCode", SqlDbType.Int, 4, ParameterDirection.Output, True, 10, 0, "", DataRowVersion.Proposed, m_iErrorCode)) If m_bMainConnectionIsCreatedLocal Then ' // Open connection. m_scoMainConnection.Open() Else If m_cpMainConnectionProvider.bIsTransactionPending Then scmCmdToExecute.Transaction = m_cpMainConnectionProvider.stCurrentTransaction End If End If ' // Execute query. sdaAdapter.Fill(dtToReturn) m_iErrorCode = New SqlInt32(CType(scmCmdToExecute.Parameters.Item("@iErrorCode").Value, SqlInt32)) If Not m_iErrorCode.Equals(New SqlInt32(LLBLError.AllOk)) Then ' // Throw error. Throw New Exception("Stored Procedure 'pr_Vorgabe_SelectAll' reported the ErrorCode: " & m_iErrorCode.ToString()) End If Return dtToReturn Catch ex As Exception ' // some error occured. Bubble it to caller and encapsulate Exception object Throw New Exception("clsVorgabe::SelectAll::Error occured.", ex) Finally If m_bMainConnectionIsCreatedLocal Then ' // Close connection. m_scoMainConnection.Close() End If scmCmdToExecute.Dispose() sdaAdapter.Dispose() End Try End Function #Region " Class Property Declarations " Public Property [iVorgabeID]() As SqlInt32 Get Return m_iVorgabeID End Get Set(ByVal Value As SqlInt32) Dim iVorgabeIDTmp As SqlInt32 = Value If iVorgabeIDTmp.IsNull Then Throw New ArgumentOutOfRangeException("iVorgabeID", "iVorgabeID can't be NULL") End If m_iVorgabeID = Value End Set End Property Public Property [iParentID]() As SqlInt32 Get Return m_iParentID End Get Set(ByVal Value As SqlInt32) m_iParentID = Value End Set End Property Public Property [sBezeichnung]() As SqlString Get Return m_sBezeichnung End Get Set(ByVal Value As SqlString) m_sBezeichnung = Value End Set End Property Public Property [sBeschreibung]() As SqlString Get Return m_sBeschreibung End Get Set(ByVal Value As SqlString) m_sBeschreibung = Value End Set End Property Public Property [sKapitelNr]() As SqlString Get Return m_sKapitelNr End Get Set(ByVal Value As SqlString) m_sKapitelNr = Value End Set End Property Public Property [sKapitel]() As SqlString Get Return m_sKapitel End Get Set(ByVal Value As SqlString) m_sKapitel = Value End Set End Property Public Property [sDefinition]() As SqlString Get Return m_sDefinition End Get Set(ByVal Value As SqlString) m_sDefinition = Value End Set End Property Public Property [sErgaenzungen]() As SqlString Get Return m_sErgaenzungen End Get Set(ByVal Value As SqlString) m_sErgaenzungen = Value End Set End Property Public Property [bAktiv]() As SqlBoolean Get Return m_bAktiv End Get Set(ByVal Value As SqlBoolean) m_bAktiv = Value End Set End Property Public Property [daErstellt_am]() As SqlDateTime Get Return m_daErstellt_am End Get Set(ByVal Value As SqlDateTime) m_daErstellt_am = Value End Set End Property Public Property [daMutiert_am]() As SqlDateTime Get Return m_daMutiert_am End Get Set(ByVal Value As SqlDateTime) m_daMutiert_am = Value End Set End Property Public Property [iMutierer]() As SqlInt32 Get Return m_iMutierer End Get Set(ByVal Value As SqlInt32) m_iMutierer = Value End Set End Property Public Property [daGueltig_Bis]() As SqlDateTime Get Return m_daGueltig_Bis End Get Set(ByVal Value As SqlDateTime) m_daGueltig_Bis = Value End Set End Property #End Region End Class End Namespace