using System; using System.Data; using System.Data.SqlTypes; using System.Data.SqlClient; namespace edoka_dms { public class clsKey_tabelle : clsDBInteractionBase { #region Class Member Declarations private SqlBoolean m_bAktiv; private SqlDateTime m_daErstellt_am, m_daMutiert_am; private SqlInt32 m_iKeynr, m_iKey_wert, m_iMandantnr, m_iMutierer; private SqlString m_sBeschreibung; #endregion public clsKey_tabelle() { // Nothing for now. } public override bool Insert() { SqlCommand scmCmdToExecute = new SqlCommand(); scmCmdToExecute.CommandText = "dbo.[pr_key_tabelle_Insert]"; scmCmdToExecute.CommandType = CommandType.StoredProcedure; // Use base class' connection object scmCmdToExecute.Connection = m_scoMainConnection; try { scmCmdToExecute.Parameters.Add(new SqlParameter("@sbeschreibung", SqlDbType.VarChar, 255, ParameterDirection.Input, false, 0, 0, "", DataRowVersion.Proposed, m_sBeschreibung)); scmCmdToExecute.Parameters.Add(new SqlParameter("@ikey_wert", SqlDbType.Int, 4, ParameterDirection.Input, false, 10, 0, "", DataRowVersion.Proposed, m_iKey_wert)); scmCmdToExecute.Parameters.Add(new SqlParameter("@imandantnr", SqlDbType.Int, 4, ParameterDirection.Input, true, 10, 0, "", DataRowVersion.Proposed, m_iMandantnr)); 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("@ikeynr", SqlDbType.Int, 4, ParameterDirection.Output, true, 10, 0, "", DataRowVersion.Proposed, m_iKeynr)); scmCmdToExecute.Parameters.Add(new SqlParameter("@iErrorCode", SqlDbType.Int, 4, ParameterDirection.Output, true, 10, 0, "", DataRowVersion.Proposed, m_iErrorCode)); if(m_bMainConnectionIsCreatedLocal) { // Open connection. m_scoMainConnection.Open(); } else { if(m_cpMainConnectionProvider.bIsTransactionPending) { scmCmdToExecute.Transaction = m_cpMainConnectionProvider.stCurrentTransaction; } } // Execute query. m_iRowsAffected = scmCmdToExecute.ExecuteNonQuery(); m_iKeynr = (Int32)scmCmdToExecute.Parameters["@ikeynr"].Value; m_iErrorCode = (Int32)scmCmdToExecute.Parameters["@iErrorCode"].Value; if(m_iErrorCode != (int)LLBLError.AllOk) { // Throw error. throw new Exception("Stored Procedure 'pr_key_tabelle_Insert' reported the ErrorCode: " + m_iErrorCode); } return true; } catch(Exception ex) { // some error occured. Bubble it to caller and encapsulate Exception object throw new Exception("clsKey_tabelle::Insert::Error occured.", ex); } finally { if(m_bMainConnectionIsCreatedLocal) { // Close connection. m_scoMainConnection.Close(); } scmCmdToExecute.Dispose(); } } public override bool Update() { SqlCommand scmCmdToExecute = new SqlCommand(); scmCmdToExecute.CommandText = "dbo.[pr_key_tabelle_Update]"; scmCmdToExecute.CommandType = CommandType.StoredProcedure; // Use base class' connection object scmCmdToExecute.Connection = m_scoMainConnection; try { scmCmdToExecute.Parameters.Add(new SqlParameter("@ikeynr", SqlDbType.Int, 4, ParameterDirection.Input, false, 10, 0, "", DataRowVersion.Proposed, m_iKeynr)); scmCmdToExecute.Parameters.Add(new SqlParameter("@sbeschreibung", SqlDbType.VarChar, 255, ParameterDirection.Input, false, 0, 0, "", DataRowVersion.Proposed, m_sBeschreibung)); scmCmdToExecute.Parameters.Add(new SqlParameter("@ikey_wert", SqlDbType.Int, 4, ParameterDirection.Input, false, 10, 0, "", DataRowVersion.Proposed, m_iKey_wert)); scmCmdToExecute.Parameters.Add(new SqlParameter("@imandantnr", SqlDbType.Int, 4, ParameterDirection.Input, true, 10, 0, "", DataRowVersion.Proposed, m_iMandantnr)); 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("@iErrorCode", SqlDbType.Int, 4, ParameterDirection.Output, true, 10, 0, "", DataRowVersion.Proposed, m_iErrorCode)); if(m_bMainConnectionIsCreatedLocal) { // Open connection. m_scoMainConnection.Open(); } else { if(m_cpMainConnectionProvider.bIsTransactionPending) { scmCmdToExecute.Transaction = m_cpMainConnectionProvider.stCurrentTransaction; } } // Execute query. m_iRowsAffected = scmCmdToExecute.ExecuteNonQuery(); m_iErrorCode = (Int32)scmCmdToExecute.Parameters["@iErrorCode"].Value; if(m_iErrorCode != (int)LLBLError.AllOk) { // Throw error. throw new Exception("Stored Procedure 'pr_key_tabelle_Update' reported the ErrorCode: " + m_iErrorCode); } return true; } catch(Exception ex) { // some error occured. Bubble it to caller and encapsulate Exception object throw new Exception("clsKey_tabelle::Update::Error occured.", ex); } finally { if(m_bMainConnectionIsCreatedLocal) { // Close connection. m_scoMainConnection.Close(); } scmCmdToExecute.Dispose(); } } public override bool Delete() { SqlCommand scmCmdToExecute = new SqlCommand(); scmCmdToExecute.CommandText = "dbo.[pr_key_tabelle_Delete]"; scmCmdToExecute.CommandType = CommandType.StoredProcedure; // Use base class' connection object scmCmdToExecute.Connection = m_scoMainConnection; try { scmCmdToExecute.Parameters.Add(new SqlParameter("@ikeynr", SqlDbType.Int, 4, ParameterDirection.Input, false, 10, 0, "", DataRowVersion.Proposed, m_iKeynr)); scmCmdToExecute.Parameters.Add(new SqlParameter("@iErrorCode", SqlDbType.Int, 4, ParameterDirection.Output, true, 10, 0, "", DataRowVersion.Proposed, m_iErrorCode)); if(m_bMainConnectionIsCreatedLocal) { // Open connection. m_scoMainConnection.Open(); } else { if(m_cpMainConnectionProvider.bIsTransactionPending) { scmCmdToExecute.Transaction = m_cpMainConnectionProvider.stCurrentTransaction; } } // Execute query. m_iRowsAffected = scmCmdToExecute.ExecuteNonQuery(); m_iErrorCode = (Int32)scmCmdToExecute.Parameters["@iErrorCode"].Value; if(m_iErrorCode != (int)LLBLError.AllOk) { // Throw error. throw new Exception("Stored Procedure 'pr_key_tabelle_Delete' reported the ErrorCode: " + m_iErrorCode); } return true; } catch(Exception ex) { // some error occured. Bubble it to caller and encapsulate Exception object throw new Exception("clsKey_tabelle::Delete::Error occured.", ex); } finally { if(m_bMainConnectionIsCreatedLocal) { // Close connection. m_scoMainConnection.Close(); } scmCmdToExecute.Dispose(); } } public override DataTable SelectOne() { SqlCommand scmCmdToExecute = new SqlCommand(); scmCmdToExecute.CommandText = "dbo.[pr_key_tabelle_SelectOne]"; scmCmdToExecute.CommandType = CommandType.StoredProcedure; DataTable dtToReturn = new DataTable("key_tabelle"); SqlDataAdapter sdaAdapter = new SqlDataAdapter(scmCmdToExecute); // Use base class' connection object scmCmdToExecute.Connection = m_scoMainConnection; try { scmCmdToExecute.Parameters.Add(new SqlParameter("@ikeynr", SqlDbType.Int, 4, ParameterDirection.Input, false, 10, 0, "", DataRowVersion.Proposed, m_iKeynr)); scmCmdToExecute.Parameters.Add(new SqlParameter("@iErrorCode", SqlDbType.Int, 4, ParameterDirection.Output, true, 10, 0, "", DataRowVersion.Proposed, m_iErrorCode)); if(m_bMainConnectionIsCreatedLocal) { // Open connection. m_scoMainConnection.Open(); } else { if(m_cpMainConnectionProvider.bIsTransactionPending) { scmCmdToExecute.Transaction = m_cpMainConnectionProvider.stCurrentTransaction; } } // Execute query. sdaAdapter.Fill(dtToReturn); m_iErrorCode = (Int32)scmCmdToExecute.Parameters["@iErrorCode"].Value; if(m_iErrorCode != (int)LLBLError.AllOk) { // Throw error. throw new Exception("Stored Procedure 'pr_key_tabelle_SelectOne' reported the ErrorCode: " + m_iErrorCode); } if(dtToReturn.Rows.Count > 0) { m_iKeynr = (Int32)dtToReturn.Rows[0]["keynr"]; m_sBeschreibung = (string)dtToReturn.Rows[0]["beschreibung"]; m_iKey_wert = (Int32)dtToReturn.Rows[0]["key_wert"]; m_iMandantnr = dtToReturn.Rows[0]["mandantnr"] == System.DBNull.Value ? SqlInt32.Null : (Int32)dtToReturn.Rows[0]["mandantnr"]; m_bAktiv = dtToReturn.Rows[0]["aktiv"] == System.DBNull.Value ? SqlBoolean.Null : (bool)dtToReturn.Rows[0]["aktiv"]; m_daErstellt_am = dtToReturn.Rows[0]["erstellt_am"] == System.DBNull.Value ? SqlDateTime.Null : (DateTime)dtToReturn.Rows[0]["erstellt_am"]; m_daMutiert_am = dtToReturn.Rows[0]["mutiert_am"] == System.DBNull.Value ? SqlDateTime.Null : (DateTime)dtToReturn.Rows[0]["mutiert_am"]; m_iMutierer = dtToReturn.Rows[0]["mutierer"] == System.DBNull.Value ? SqlInt32.Null : (Int32)dtToReturn.Rows[0]["mutierer"]; } return dtToReturn; } catch(Exception ex) { // some error occured. Bubble it to caller and encapsulate Exception object throw new Exception("clsKey_tabelle::SelectOne::Error occured.", ex); } finally { if(m_bMainConnectionIsCreatedLocal) { // Close connection. m_scoMainConnection.Close(); } scmCmdToExecute.Dispose(); sdaAdapter.Dispose(); } } public override DataTable SelectAll() { SqlCommand scmCmdToExecute = new SqlCommand(); scmCmdToExecute.CommandText = "dbo.[pr_key_tabelle_SelectAll]"; scmCmdToExecute.CommandType = CommandType.StoredProcedure; DataTable dtToReturn = new DataTable("key_tabelle"); SqlDataAdapter sdaAdapter = 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) { // Open connection. m_scoMainConnection.Open(); } else { if(m_cpMainConnectionProvider.bIsTransactionPending) { scmCmdToExecute.Transaction = m_cpMainConnectionProvider.stCurrentTransaction; } } // Execute query. sdaAdapter.Fill(dtToReturn); m_iErrorCode = (Int32)scmCmdToExecute.Parameters["@iErrorCode"].Value; if(m_iErrorCode != (int)LLBLError.AllOk) { // Throw error. throw new Exception("Stored Procedure 'pr_key_tabelle_SelectAll' reported the ErrorCode: " + m_iErrorCode); } return dtToReturn; } catch(Exception ex) { // some error occured. Bubble it to caller and encapsulate Exception object throw new Exception("clsKey_tabelle::SelectAll::Error occured.", ex); } finally { if(m_bMainConnectionIsCreatedLocal) { // Close connection. m_scoMainConnection.Close(); } scmCmdToExecute.Dispose(); sdaAdapter.Dispose(); } } #region Class Property Declarations public SqlInt32 iKeynr { get { return m_iKeynr; } set { SqlInt32 iKeynrTmp = (SqlInt32)value; if(iKeynrTmp.IsNull) { throw new ArgumentOutOfRangeException("iKeynr", "iKeynr can't be NULL"); } m_iKeynr = value; } } public SqlString sBeschreibung { get { return m_sBeschreibung; } set { SqlString sBeschreibungTmp = (SqlString)value; if(sBeschreibungTmp.IsNull) { throw new ArgumentOutOfRangeException("sBeschreibung", "sBeschreibung can't be NULL"); } m_sBeschreibung = value; } } public SqlInt32 iKey_wert { get { return m_iKey_wert; } set { SqlInt32 iKey_wertTmp = (SqlInt32)value; if(iKey_wertTmp.IsNull) { throw new ArgumentOutOfRangeException("iKey_wert", "iKey_wert can't be NULL"); } m_iKey_wert = value; } } public SqlInt32 iMandantnr { get { return m_iMandantnr; } set { m_iMandantnr = value; } } public SqlBoolean bAktiv { get { return m_bAktiv; } set { m_bAktiv = value; } } public SqlDateTime daErstellt_am { get { return m_daErstellt_am; } set { m_daErstellt_am = value; } } public SqlDateTime daMutiert_am { get { return m_daMutiert_am; } set { m_daMutiert_am = value; } } public SqlInt32 iMutierer { get { return m_iMutierer; } set { m_iMutierer = value; } } #endregion } }