Imports System Imports System.Data Imports System.Data.SqlTypes Imports System.Data.SqlClient Namespace DB Public Class clsPersonal Inherits clsDBInteractionBase #Region " Class Member Declarations " Private m_bAktiv As SqlBoolean Private m_daErstellt_am, m_daMutiert_am As SqlDateTime Private m_iSequenz, m_iPersonalnr, m_iMutierer, m_iParentID As SqlInt32 Private m_sNextControlDate, m_sVerantwTKBMA, m_sHauptnutzer, m_sEMail, m_sBeschreibung, m_sTGNummer, m_sName, m_sBezeichnung 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_Personal_Insert]" scmCmdToExecute.CommandType = CommandType.StoredProcedure ' // Use base class' connection object scmCmdToExecute.Connection = m_scoMainConnection Try scmCmdToExecute.Parameters.Add(New SqlParameter("@iPersonalnr", SqlDbType.Int, 4, ParameterDirection.Input, False, 10, 0, "", DataRowVersion.Proposed, m_iPersonalnr)) 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("@sTGNummer", SqlDbType.VarChar, 255, ParameterDirection.Input, True, 0, 0, "", DataRowVersion.Proposed, m_sTGNummer)) scmCmdToExecute.Parameters.Add(New SqlParameter("@sName", SqlDbType.VarChar, 255, ParameterDirection.Input, True, 0, 0, "", DataRowVersion.Proposed, m_sName)) scmCmdToExecute.Parameters.Add(New SqlParameter("@iSequenz", SqlDbType.Int, 4, ParameterDirection.Input, True, 10, 0, "", DataRowVersion.Proposed, m_iSequenz)) 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("@sVerantwTKBMA", SqlDbType.VarChar, 255, ParameterDirection.Input, True, 0, 0, "", DataRowVersion.Proposed, m_sVerantwTKBMA)) scmCmdToExecute.Parameters.Add(New SqlParameter("@sNextControlDate", SqlDbType.VarChar, 255, ParameterDirection.Input, True, 0, 0, "", DataRowVersion.Proposed, m_sNextControlDate)) scmCmdToExecute.Parameters.Add(New SqlParameter("@sEMail", SqlDbType.VarChar, 255, ParameterDirection.Input, True, 0, 0, "", DataRowVersion.Proposed, m_sEMail)) scmCmdToExecute.Parameters.Add(New SqlParameter("@sHauptnutzer", SqlDbType.VarChar, 255, ParameterDirection.Input, True, 0, 0, "", DataRowVersion.Proposed, m_sHauptnutzer)) 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_Personal_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("clsPersonal::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_Personal_Update]" scmCmdToExecute.CommandType = CommandType.StoredProcedure ' // Use base class' connection object scmCmdToExecute.Connection = m_scoMainConnection Try scmCmdToExecute.Parameters.Add(New SqlParameter("@iPersonalnr", SqlDbType.Int, 4, ParameterDirection.Input, False, 10, 0, "", DataRowVersion.Proposed, m_iPersonalnr)) 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("@sTGNummer", SqlDbType.VarChar, 255, ParameterDirection.Input, True, 0, 0, "", DataRowVersion.Proposed, m_sTGNummer)) scmCmdToExecute.Parameters.Add(New SqlParameter("@sName", SqlDbType.VarChar, 255, ParameterDirection.Input, True, 0, 0, "", DataRowVersion.Proposed, m_sName)) scmCmdToExecute.Parameters.Add(New SqlParameter("@iSequenz", SqlDbType.Int, 4, ParameterDirection.Input, True, 10, 0, "", DataRowVersion.Proposed, m_iSequenz)) 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("@sVerantwTKBMA", SqlDbType.VarChar, 255, ParameterDirection.Input, True, 0, 0, "", DataRowVersion.Proposed, m_sVerantwTKBMA)) scmCmdToExecute.Parameters.Add(New SqlParameter("@sNextControlDate", SqlDbType.VarChar, 255, ParameterDirection.Input, True, 0, 0, "", DataRowVersion.Proposed, m_sNextControlDate)) scmCmdToExecute.Parameters.Add(New SqlParameter("@sEMail", SqlDbType.VarChar, 255, ParameterDirection.Input, True, 0, 0, "", DataRowVersion.Proposed, m_sEMail)) scmCmdToExecute.Parameters.Add(New SqlParameter("@sHauptnutzer", SqlDbType.VarChar, 255, ParameterDirection.Input, True, 0, 0, "", DataRowVersion.Proposed, m_sHauptnutzer)) 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_Personal_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("clsPersonal::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_Personal_Delete]" scmCmdToExecute.CommandType = CommandType.StoredProcedure ' // Use base class' connection object scmCmdToExecute.Connection = m_scoMainConnection Try scmCmdToExecute.Parameters.Add(New SqlParameter("@iPersonalnr", SqlDbType.Int, 4, ParameterDirection.Input, False, 10, 0, "", DataRowVersion.Proposed, m_iPersonalnr)) 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_Personal_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("clsPersonal::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_Personal_SelectOne]" scmCmdToExecute.CommandType = CommandType.StoredProcedure Dim dtToReturn As DataTable = new DataTable("Personal") Dim sdaAdapter As SqlDataAdapter = new SqlDataAdapter(scmCmdToExecute) ' // Use base class' connection object scmCmdToExecute.Connection = m_scoMainConnection Try scmCmdToExecute.Parameters.Add(new SqlParameter("@iPersonalnr", SqlDbType.Int, 4, ParameterDirection.Input, False, 10, 0, "", DataRowVersion.Proposed, m_iPersonalnr)) 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_Personal_SelectOne' reported the ErrorCode: " & m_iErrorCode.ToString()) End If If dtToReturn.Rows.Count > 0 Then m_iPersonalnr = New SqlInt32(CType(dtToReturn.Rows(0)("Personalnr"), 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)("TGNummer") Is System.DBNull.Value Then m_sTGNummer = SqlString.Null Else m_sTGNummer = New SqlString(CType(dtToReturn.Rows(0)("TGNummer"), String)) End If If dtToReturn.Rows(0)("Name") Is System.DBNull.Value Then m_sName = SqlString.Null Else m_sName = New SqlString(CType(dtToReturn.Rows(0)("Name"), String)) End If If dtToReturn.Rows(0)("Sequenz") Is System.DBNull.Value Then m_iSequenz = SqlInt32.Null Else m_iSequenz = New SqlInt32(CType(dtToReturn.Rows(0)("Sequenz"), Integer)) 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)("VerantwTKBMA") Is System.DBNull.Value Then m_sVerantwTKBMA = SqlString.Null Else m_sVerantwTKBMA = New SqlString(CType(dtToReturn.Rows(0)("VerantwTKBMA"), String)) End If If dtToReturn.Rows(0)("NextControlDate") Is System.DBNull.Value Then m_sNextControlDate = SqlString.Null Else m_sNextControlDate = New SqlString(CType(dtToReturn.Rows(0)("NextControlDate"), String)) End If If dtToReturn.Rows(0)("EMail") Is System.DBNull.Value Then m_sEMail = SqlString.Null Else m_sEMail = New SqlString(CType(dtToReturn.Rows(0)("EMail"), String)) End If If dtToReturn.Rows(0)("Hauptnutzer") Is System.DBNull.Value Then m_sHauptnutzer = SqlString.Null Else m_sHauptnutzer = New SqlString(CType(dtToReturn.Rows(0)("Hauptnutzer"), String)) End If End If Return dtToReturn Catch ex As Exception ' // some error occured. Bubble it to caller and encapsulate Exception object Throw New Exception("clsPersonal::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_Personal_SelectAll]" scmCmdToExecute.CommandType = CommandType.StoredProcedure Dim dtToReturn As DataTable = new DataTable("Personal") 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_Personal_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("clsPersonal::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 [iPersonalnr]() As SqlInt32 Get Return m_iPersonalnr End Get Set(ByVal Value As SqlInt32) Dim iPersonalnrTmp As SqlInt32 = Value If iPersonalnrTmp.IsNull Then Throw New ArgumentOutOfRangeException("iPersonalnr", "iPersonalnr can't be NULL") End If m_iPersonalnr = 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 [sTGNummer]() As SqlString Get Return m_sTGNummer End Get Set(ByVal Value As SqlString) m_sTGNummer = Value End Set End Property Public Property [sName]() As SqlString Get Return m_sName End Get Set(ByVal Value As SqlString) m_sName = Value End Set End Property Public Property [iSequenz]() As SqlInt32 Get Return m_iSequenz End Get Set(ByVal Value As SqlInt32) m_iSequenz = 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 [sVerantwTKBMA]() As SqlString Get Return m_sVerantwTKBMA End Get Set(ByVal Value As SqlString) m_sVerantwTKBMA = Value End Set End Property Public Property [sNextControlDate]() As SqlString Get Return m_sNextControlDate End Get Set(ByVal Value As SqlString) m_sNextControlDate = Value End Set End Property Public Property [sEMail]() As SqlString Get Return m_sEMail End Get Set(ByVal Value As SqlString) m_sEMail = Value End Set End Property Public Property [sHauptnutzer]() As SqlString Get Return m_sHauptnutzer End Get Set(ByVal Value As SqlString) m_sHauptnutzer = Value End Set End Property #End Region End Class End Namespace