/development/Source/Modules/Blog/Data/SqlServer2000/Blog_Categories.cs
C# | 446 lines | 276 code | 48 blank | 122 comment | 28 complexity | 48b276067931012d4d8cebe4a74b9f21 MD5 | raw file
- #region Copyright © 2004, Nicholas Berardi
- /*
- * ManagedFusion (www.ManagedFusion.net) Copyright © 2004, Nicholas Berardi
- * All rights reserved.
- *
- * This code is protected under the Common Public License Version 1.0
- * The license in its entirety at <http://opensource.org/licenses/cpl.php>
- *
- * ManagedFusion is freely available from <http://www.ManagedFusion.net/>
- */
- #endregion
-
- ///////////////////////////////////////////////////////////////////////////
- // Description: Data Access class for the table 'Blog_Categories'
- // Generated by LLBLGen v1.21.2003.712 Final on: Wednesday, January 26, 2005, 4:47:11 PM
- // Because the Base Class already implements IDispose, this class doesn't.
- ///////////////////////////////////////////////////////////////////////////
- using System;
- using System.Data;
- using System.Data.SqlTypes;
- using System.Data.SqlClient;
-
- namespace OmniPortal.Modules.Blog.Data.SqlServer
- {
- /// <summary>
- /// Purpose: Data Access class for the table 'Blog_Categories'.
- /// </summary>
- public class Blog_Categories : DBInteractionBase
- {
- #region Class Member Declarations
- private SqlInt32 _iD;
- private SqlString _name;
- #endregion
-
-
- /// <summary>
- /// Purpose: Class constructor.
- /// </summary>
- public Blog_Categories()
- {
- // Nothing for now.
- }
-
-
- /// <summary>
- /// Purpose: Insert method. This method will insert one new row into the database.
- /// </summary>
- /// <returns>True if succeeded, otherwise an Exception is thrown. </returns>
- /// <remarks>
- /// Properties needed for this method:
- /// <UL>
- /// <LI>Name</LI>
- /// </UL>
- /// Properties set after a succesful call of this method:
- /// <UL>
- /// <LI>Identity</LI>
- /// <LI>ErrorCode</LI>
- /// </UL>
- /// </remarks>
- public override bool Insert()
- {
- SqlCommand cmdToExecute = new SqlCommand();
- cmdToExecute.CommandText = "dbo.[Blog_Categories_Insert]";
- cmdToExecute.CommandType = CommandType.StoredProcedure;
-
- // Use base class' connection object
- cmdToExecute.Connection = _mainConnection;
-
- try
- {
- cmdToExecute.Parameters.Add(new SqlParameter("@Name", SqlDbType.NVarChar, 64, ParameterDirection.Input, false, 0, 0, "", DataRowVersion.Proposed, _name));
- cmdToExecute.Parameters.Add(new SqlParameter("@Identity", SqlDbType.Int, 4, ParameterDirection.Output, true, 10, 0, "", DataRowVersion.Proposed, _iD));
- cmdToExecute.Parameters.Add(new SqlParameter("@ErrorCode", SqlDbType.Int, 4, ParameterDirection.Output, true, 10, 0, "", DataRowVersion.Proposed, _errorCode));
-
- if(_mainConnectionIsCreatedLocal)
- {
- // Open connection.
- _mainConnection.Open();
- }
- else
- {
- if(_mainConnectionProvider.IsTransactionPending)
- {
- cmdToExecute.Transaction = _mainConnectionProvider.CurrentTransaction;
- }
- }
-
- // Execute query.
- _rowsAffected = cmdToExecute.ExecuteNonQuery();
- _iD = (Int32)cmdToExecute.Parameters["@Identity"].Value;
- _errorCode = (Int32)cmdToExecute.Parameters["@ErrorCode"].Value;
-
- if(_errorCode != (int)LLBLError.AllOk)
- {
- // Throw error.
- throw new Exception("Stored Procedure 'Blog_Categories_Insert' reported the ErrorCode: " + _errorCode);
- }
-
- return true;
- }
- catch(Exception ex)
- {
- // some error occured. Bubble it to caller and encapsulate Exception object
- throw new Exception("Blog_Categories::Insert::Error occured.", ex);
- }
- finally
- {
- if(_mainConnectionIsCreatedLocal)
- {
- // Close connection.
- _mainConnection.Close();
- }
- cmdToExecute.Dispose();
- }
- }
-
-
- /// <summary>
- /// Purpose: Update method. This method will Update one existing row in the database.
- /// </summary>
- /// <returns>True if succeeded, otherwise an Exception is thrown. </returns>
- /// <remarks>
- /// Properties needed for this method:
- /// <UL>
- /// <LI>Identity</LI>
- /// <LI>Name</LI>
- /// </UL>
- /// Properties set after a succesful call of this method:
- /// <UL>
- /// <LI>ErrorCode</LI>
- /// </UL>
- /// </remarks>
- public override bool Update()
- {
- SqlCommand cmdToExecute = new SqlCommand();
- cmdToExecute.CommandText = "dbo.[Blog_Categories_Update]";
- cmdToExecute.CommandType = CommandType.StoredProcedure;
-
- // Use base class' connection object
- cmdToExecute.Connection = _mainConnection;
-
- try
- {
- cmdToExecute.Parameters.Add(new SqlParameter("@Identity", SqlDbType.Int, 4, ParameterDirection.Input, false, 10, 0, "", DataRowVersion.Proposed, _iD));
- cmdToExecute.Parameters.Add(new SqlParameter("@Name", SqlDbType.NVarChar, 64, ParameterDirection.Input, false, 0, 0, "", DataRowVersion.Proposed, _name));
- cmdToExecute.Parameters.Add(new SqlParameter("@ErrorCode", SqlDbType.Int, 4, ParameterDirection.Output, true, 10, 0, "", DataRowVersion.Proposed, _errorCode));
-
- if(_mainConnectionIsCreatedLocal)
- {
- // Open connection.
- _mainConnection.Open();
- }
- else
- {
- if(_mainConnectionProvider.IsTransactionPending)
- {
- cmdToExecute.Transaction = _mainConnectionProvider.CurrentTransaction;
- }
- }
-
- // Execute query.
- _rowsAffected = cmdToExecute.ExecuteNonQuery();
- _errorCode = (Int32)cmdToExecute.Parameters["@ErrorCode"].Value;
-
- if(_errorCode != (int)LLBLError.AllOk)
- {
- // Throw error.
- throw new Exception("Stored Procedure 'Blog_Categories_Update' reported the ErrorCode: " + _errorCode);
- }
-
- return true;
- }
- catch(Exception ex)
- {
- // some error occured. Bubble it to caller and encapsulate Exception object
- throw new Exception("Blog_Categories::Update::Error occured.", ex);
- }
- finally
- {
- if(_mainConnectionIsCreatedLocal)
- {
- // Close connection.
- _mainConnection.Close();
- }
- cmdToExecute.Dispose();
- }
- }
-
-
- /// <summary>
- /// Purpose: Delete method. This method will Delete one existing row in the database, based on the Primary Key.
- /// </summary>
- /// <returns>True if succeeded, otherwise an Exception is thrown. </returns>
- /// <remarks>
- /// Properties needed for this method:
- /// <UL>
- /// <LI>Identity</LI>
- /// </UL>
- /// Properties set after a succesful call of this method:
- /// <UL>
- /// <LI>ErrorCode</LI>
- /// </UL>
- /// </remarks>
- public override bool Delete()
- {
- SqlCommand cmdToExecute = new SqlCommand();
- cmdToExecute.CommandText = "dbo.[Blog_Categories_Delete]";
- cmdToExecute.CommandType = CommandType.StoredProcedure;
-
- // Use base class' connection object
- cmdToExecute.Connection = _mainConnection;
-
- try
- {
- cmdToExecute.Parameters.Add(new SqlParameter("@Identity", SqlDbType.Int, 4, ParameterDirection.Input, false, 10, 0, "", DataRowVersion.Proposed, _iD));
- cmdToExecute.Parameters.Add(new SqlParameter("@ErrorCode", SqlDbType.Int, 4, ParameterDirection.Output, true, 10, 0, "", DataRowVersion.Proposed, _errorCode));
-
- if(_mainConnectionIsCreatedLocal)
- {
- // Open connection.
- _mainConnection.Open();
- }
- else
- {
- if(_mainConnectionProvider.IsTransactionPending)
- {
- cmdToExecute.Transaction = _mainConnectionProvider.CurrentTransaction;
- }
- }
-
- // Execute query.
- _rowsAffected = cmdToExecute.ExecuteNonQuery();
- _errorCode = (Int32)cmdToExecute.Parameters["@ErrorCode"].Value;
-
- if(_errorCode != (int)LLBLError.AllOk)
- {
- // Throw error.
- throw new Exception("Stored Procedure 'Blog_Categories_Delete' reported the ErrorCode: " + _errorCode);
- }
-
- return true;
- }
- catch(Exception ex)
- {
- // some error occured. Bubble it to caller and encapsulate Exception object
- throw new Exception("Blog_Categories::Delete::Error occured.", ex);
- }
- finally
- {
- if(_mainConnectionIsCreatedLocal)
- {
- // Close connection.
- _mainConnection.Close();
- }
- cmdToExecute.Dispose();
- }
- }
-
-
- /// <summary>
- /// Purpose: Select method. This method will Select one existing row from the database, based on the Primary Key.
- /// </summary>
- /// <returns>DataTable object if succeeded, otherwise an Exception is thrown. </returns>
- /// <remarks>
- /// Properties needed for this method:
- /// <UL>
- /// <LI>Identity</LI>
- /// </UL>
- /// Properties set after a succesful call of this method:
- /// <UL>
- /// <LI>ErrorCode</LI>
- /// <LI>Identity</LI>
- /// <LI>Name</LI>
- /// </UL>
- /// Will fill all properties corresponding with a field in the table with the value of the row selected.
- /// </remarks>
- public override DataTable SelectOne()
- {
- SqlCommand cmdToExecute = new SqlCommand();
- cmdToExecute.CommandText = "dbo.[Blog_Categories_SelectOne]";
- cmdToExecute.CommandType = CommandType.StoredProcedure;
- DataTable toReturn = new DataTable("Blog_Categories");
- SqlDataAdapter adapter = new SqlDataAdapter(cmdToExecute);
-
- // Use base class' connection object
- cmdToExecute.Connection = _mainConnection;
-
- try
- {
- cmdToExecute.Parameters.Add(new SqlParameter("@Identity", SqlDbType.Int, 4, ParameterDirection.Input, false, 10, 0, "", DataRowVersion.Proposed, _iD));
- cmdToExecute.Parameters.Add(new SqlParameter("@ErrorCode", SqlDbType.Int, 4, ParameterDirection.Output, true, 10, 0, "", DataRowVersion.Proposed, _errorCode));
-
- if(_mainConnectionIsCreatedLocal)
- {
- // Open connection.
- _mainConnection.Open();
- }
- else
- {
- if(_mainConnectionProvider.IsTransactionPending)
- {
- cmdToExecute.Transaction = _mainConnectionProvider.CurrentTransaction;
- }
- }
-
- // Execute query.
- adapter.Fill(toReturn);
- _errorCode = (Int32)cmdToExecute.Parameters["@ErrorCode"].Value;
-
- if(_errorCode != (int)LLBLError.AllOk)
- {
- // Throw error.
- throw new Exception("Stored Procedure 'Blog_Categories_SelectOne' reported the ErrorCode: " + _errorCode);
- }
-
- if(toReturn.Rows.Count > 0)
- {
- _iD = (Int32)toReturn.Rows[0]["Identity"];
- _name = (string)toReturn.Rows[0]["Name"];
- }
- return toReturn;
- }
- catch(Exception ex)
- {
- // some error occured. Bubble it to caller and encapsulate Exception object
- throw new Exception("Blog_Categories::SelectOne::Error occured.", ex);
- }
- finally
- {
- if(_mainConnectionIsCreatedLocal)
- {
- // Close connection.
- _mainConnection.Close();
- }
- cmdToExecute.Dispose();
- adapter.Dispose();
- }
- }
-
-
- /// <summary>
- /// Purpose: SelectAll method. This method will Select all rows from the table.
- /// </summary>
- /// <returns>DataTable object if succeeded, otherwise an Exception is thrown. </returns>
- /// <remarks>
- /// Properties set after a succesful call of this method:
- /// <UL>
- /// <LI>ErrorCode</LI>
- /// </UL>
- /// </remarks>
- public override DataTable SelectAll()
- {
- SqlCommand cmdToExecute = new SqlCommand();
- cmdToExecute.CommandText = "dbo.[Blog_Categories_SelectAll]";
- cmdToExecute.CommandType = CommandType.StoredProcedure;
- DataTable toReturn = new DataTable("Blog_Categories");
- SqlDataAdapter adapter = new SqlDataAdapter(cmdToExecute);
-
- // Use base class' connection object
- cmdToExecute.Connection = _mainConnection;
-
- try
- {
- cmdToExecute.Parameters.Add(new SqlParameter("@ErrorCode", SqlDbType.Int, 4, ParameterDirection.Output, true, 10, 0, "", DataRowVersion.Proposed, _errorCode));
-
- if(_mainConnectionIsCreatedLocal)
- {
- // Open connection.
- _mainConnection.Open();
- }
- else
- {
- if(_mainConnectionProvider.IsTransactionPending)
- {
- cmdToExecute.Transaction = _mainConnectionProvider.CurrentTransaction;
- }
- }
-
- // Execute query.
- adapter.Fill(toReturn);
- _errorCode = (Int32)cmdToExecute.Parameters["@ErrorCode"].Value;
-
- if(_errorCode != (int)LLBLError.AllOk)
- {
- // Throw error.
- throw new Exception("Stored Procedure 'Blog_Categories_SelectAll' reported the ErrorCode: " + _errorCode);
- }
-
- return toReturn;
- }
- catch(Exception ex)
- {
- // some error occured. Bubble it to caller and encapsulate Exception object
- throw new Exception("Blog_Categories::SelectAll::Error occured.", ex);
- }
- finally
- {
- if(_mainConnectionIsCreatedLocal)
- {
- // Close connection.
- _mainConnection.Close();
- }
- cmdToExecute.Dispose();
- adapter.Dispose();
- }
- }
-
-
- #region Class Property Declarations
- public SqlInt32 ID
- {
- get
- {
- return _iD;
- }
- set
- {
- SqlInt32 iDTmp = (SqlInt32)value;
- if(iDTmp.IsNull)
- {
- throw new ArgumentOutOfRangeException("Identity", "Identity can't be NULL");
- }
- _iD = value;
- }
- }
-
-
- public SqlString Name
- {
- get
- {
- return _name;
- }
- set
- {
- SqlString nameTmp = (SqlString)value;
- if(nameTmp.IsNull)
- {
- throw new ArgumentOutOfRangeException("Name", "Name can't be NULL");
- }
- _name = value;
- }
- }
- #endregion
- }
- }