using System;
using System.Data;
using System.Data.SqlTypes;
using System.Data.SqlClient;
using System.Collections;
using YellowbridgeSoftwareInc.Info;
namespace YellowbridgeSoftwareInc.PersistBase
{
/// <summary>
/// Purpose: Data Access class for the table 'Shippers'.
/// </summary>
public abstract class Shippers
{
SqlConnection _cn;
public Shippers( string connectionString )
{
_cn = new SqlConnection( connectionString );
}
public Shippers( SqlConnection cn )
{
_cn = cn;
}
#region Select One Methods
public ShippersInfo SelectOneInfo( int ShipperID )
{
SqlCommand cmd = new SqlCommand();
DataTable dt = new DataTable("Shippers");
cmd.CommandText = "dbo.[yb_Shippers_SelectByID]";
cmd.CommandType = CommandType.StoredProcedure;
int errorCode = 0;
SqlInt32 _ShipperID = ShipperID;
// Create the info class
ShippersInfo data = new ShippersInfo();
SqlDataAdapter adapter = new SqlDataAdapter(cmd);
// Set the connection string
cmd.Connection = _cn;
try
{
cmd.Parameters.Add(new SqlParameter("@ShipperID", SqlDbType.Int , 4 ,ParameterDirection.Input, false,10 ,0 , "", DataRowVersion.Proposed, _ShipperID ));
cmd.Parameters.Add(new SqlParameter("@ErrorCode", SqlDbType.Int, 4, ParameterDirection.Output, false, 10, 0, "", DataRowVersion.Proposed, errorCode));
// Open connection.
_cn.Open();
// Execute query.
adapter.Fill(dt);
if(dt.Rows.Count > 0)
{
if ( dt.Rows[0]["Phone"] == System.DBNull.Value )
data.SetPhoneNull();
else
data.Phone = (string)dt.Rows[0]["Phone"];
data.ShipperID = (int)dt.Rows[0]["ShipperID"];
data.CompanyName = (string)dt.Rows[0]["CompanyName"];
}
// Get the error code
errorCode = (Int32)cmd.Parameters["@ErrorCode"].Value;
if( errorCode != 0)
{
// Throw error.
throw new Exception("Stored Procedure 'dbo.[Shippers_SelectByID]' reported the ErrorCode: " + errorCode);
}
// Return the data
return data;
}
catch(Exception ex)
{
// Throw the error
throw new Exception("An exception has been raised in YellowbridgeSoftwareInc.PersistBase Shippers::SelectOne.", ex);
}
finally
{
// Close connection.
_cn.Close();
cmd.Dispose();
adapter.Dispose();
}
}
public void SelectOneInfo( ref ShippersInfo data, int ShipperID )
{
SqlCommand cmd = new SqlCommand();
DataTable dt = new DataTable("Shippers");
cmd.CommandText = "dbo.[yb_Shippers_SelectByID]";
cmd.CommandType = CommandType.StoredProcedure;
int errorCode = 0;
SqlInt32 _ShipperID = ShipperID;
SqlDataAdapter adapter = new SqlDataAdapter(cmd);
// Set the connection string
cmd.Connection = _cn;
try
{
cmd.Parameters.Add(new SqlParameter("@ShipperID", SqlDbType.Int , 4 ,ParameterDirection.Input, false,10 ,0 , "", DataRowVersion.Proposed, _ShipperID ));
cmd.Parameters.Add(new SqlParameter("@ErrorCode", SqlDbType.Int, 4, ParameterDirection.Output, false, 10, 0, "", DataRowVersion.Proposed, errorCode));
// Open connection.
_cn.Open();
// Execute query.
adapter.Fill(dt);
if(dt.Rows.Count > 0)
{
if ( dt.Rows[0]["Phone"] == System.DBNull.Value )
data.SetPhoneNull();
else
data.Phone = (string)dt.Rows[0]["Phone"];
data.ShipperID = (int)dt.Rows[0]["ShipperID"];
data.CompanyName = (string)dt.Rows[0]["CompanyName"];
}
// Get the error code
errorCode = (Int32)cmd.Parameters["@ErrorCode"].Value;
if( errorCode != 0)
{
// Throw error.
throw new Exception("Stored Procedure 'dbo.[Shippers_SelectByID]' reported the ErrorCode: " + errorCode);
}
}
catch(Exception ex)
{
// Throw the error
throw new Exception("An exception has been raised in YellowbridgeSoftwareInc.PersistBase Shippers::SelectOne.", ex);
}
finally
{
// Close connection.
_cn.Close();
cmd.Dispose();
adapter.Dispose();
}
}
public DataTable SelectOneDataTable( int ShipperID )
{
SqlCommand cmd = new SqlCommand();
DataTable dt = new DataTable("Shippers");
cmd.CommandText = "dbo.[yb_Shippers_SelectByID]";
cmd.CommandType = CommandType.StoredProcedure;
int errorCode = 0;
SqlInt32 _ShipperID = ShipperID;
SqlDataAdapter adapter = new SqlDataAdapter(cmd);
// Set the connection string
cmd.Connection = _cn;
try
{
cmd.Parameters.Add(new SqlParameter("@ShipperID", SqlDbType.Int , 4 ,ParameterDirection.Input, false,10 ,0 , "", DataRowVersion.Proposed, _ShipperID ));
cmd.Parameters.Add(new SqlParameter("@ErrorCode", SqlDbType.Int, 4, ParameterDirection.Output, false, 10, 0, "", DataRowVersion.Proposed, errorCode));
// Open connection.
_cn.Open();
// Execute query.
adapter.Fill(dt);
// Get the error code
errorCode = (Int32)cmd.Parameters["@ErrorCode"].Value;
if( errorCode != 0)
{
// Throw error.
throw new Exception("Stored Procedure 'dbo.[Shippers_SelectByID]' reported the ErrorCode: " + errorCode);
}
return dt;
}
catch(Exception ex)
{
// Throw the error
throw new Exception("An exception has been raised in YellowbridgeSoftwareInc.PersistBase Shippers::SelectOne_DataTable.", ex);
}
finally
{
// Close connection.
_cn.Close();
cmd.Dispose();
adapter.Dispose();
}
}
public SqlDataReader SelectOneDataReader( int ShipperID )
{
SqlCommand cmd = new SqlCommand();
SqlDataReader dr;
cmd.CommandText = "dbo.[yb_Shippers_SelectByID]";
cmd.CommandType = CommandType.StoredProcedure;
int errorCode = 0;
SqlInt32 _ShipperID = ShipperID;
// Set the connection string
cmd.Connection = _cn;
try
{
cmd.Parameters.Add(new SqlParameter("@ShipperID", SqlDbType.Int , 4 ,ParameterDirection.Input, false,10 ,0 , "", DataRowVersion.Proposed, _ShipperID ));
cmd.Parameters.Add(new SqlParameter("@ErrorCode", SqlDbType.Int, 4, ParameterDirection.Output, false, 10, 0, "", DataRowVersion.Proposed, errorCode));
// Open connection if needed.
if ( _cn.State == ConnectionState.Closed )
{
_cn.Open();
}
dr = cmd.ExecuteReader();
return dr;
}
catch(Exception ex)
{
// Throw the error
throw new Exception("An exception has been raised in YellowbridgeSoftwareInc.PersistBase Shippers::SelectOne_DataReader.", ex);
}
finally
{
// Clean up.
cmd.Dispose();
}
}
#endregion
#region Select All Methods
public ShippersInfoCollection SelectAllInfoCollection()
{
SqlCommand cmd = new SqlCommand();
DataTable dt = new DataTable("Shippers");
cmd.CommandText = "dbo.[yb_Shippers_SelectAll]";
cmd.CommandType = CommandType.StoredProcedure;
int errorCode = 0;
//Create a collection object
ShippersInfoCollection dataCollection = new ShippersInfoCollection();
SqlDataAdapter adapter = new SqlDataAdapter(cmd);
// Set the connection string
cmd.Connection = _cn;
try
{
// Open connection.
_cn.Open();
cmd.Parameters.Add(new SqlParameter("@ErrorCode", SqlDbType.Int, 4, ParameterDirection.Output, false, 10, 0, "", DataRowVersion.Proposed, errorCode));
// Execute query.
adapter.Fill(dt);
foreach ( DataRow dr in dt.Rows )
{
ShippersInfo data = new ShippersInfo();
if ( dr["Phone"] == System.DBNull.Value )
data.SetPhoneNull();
else
data.Phone = (string)dr["Phone"];
data.ShipperID = (int)dr["ShipperID"];
data.CompanyName = (string)dr["CompanyName"];
// Return the data
dataCollection.Add( data );
}
// Get the error code
errorCode = (Int32)cmd.Parameters["@ErrorCode"].Value;
if( errorCode != 0)
{
// Throw error.
throw new Exception("Stored Procedure 'dbo.[Shippers_SelectAll]' reported the ErrorCode: " + errorCode);
}
return dataCollection;
}
catch(Exception ex)
{
// Throw the error
throw new Exception("An exception has been raised in YellowbridgeSoftwareInc.PersistBase Shippers::SelectAll.", ex);
}
finally
{
// Close connection.
_cn.Close();
cmd.Dispose();
adapter.Dispose();
}
}
public void SelectAllInfoCollection( ref ShippersInfoCollection dataCollection )
{
SqlCommand cmd = new SqlCommand();
DataTable dt = new DataTable("Shippers");
cmd.CommandText = "dbo.[yb_Shippers_SelectAll]";
cmd.CommandType = CommandType.StoredProcedure;
int errorCode = 0;
SqlDataAdapter adapter = new SqlDataAdapter(cmd);
// Set the connection string
cmd.Connection = _cn;
try
{
// Open connection.
_cn.Open();
cmd.Parameters.Add(new SqlParameter("@ErrorCode", SqlDbType.Int, 4, ParameterDirection.Output, false, 10, 0, "", DataRowVersion.Proposed, errorCode));
// Execute query.
adapter.Fill(dt);
foreach ( DataRow dr in dt.Rows )
{
ShippersInfo data = new ShippersInfo();
if ( dr["Phone"] == System.DBNull.Value )
data.SetPhoneNull();
else
data.Phone = (string)dr["Phone"];
data.ShipperID = (int)dr["ShipperID"];
data.CompanyName = (string)dr["CompanyName"];
dataCollection.Add( data );
}
// Get the error code
errorCode = (Int32)cmd.Parameters["@ErrorCode"].Value;
if( errorCode != 0)
{
// Throw error.
throw new Exception("Stored Procedure 'dbo.[Shippers_SelectAll]' reported the ErrorCode: " + errorCode);
}
}
catch(Exception ex)
{
// Throw the error
throw new Exception("An exception has been raised in YellowbridgeSoftwareInc.PersistBase Shippers::SelectAll", ex);
}
finally
{
// Close connection.
_cn.Close();
cmd.Dispose();
adapter.Dispose();
}
}
public DataTable SelectAllDataTable()
{
SqlCommand cmd = new SqlCommand();
DataTable dt = new DataTable("Shippers");
cmd.CommandText = "dbo.[yb_Shippers_SelectAll]";
cmd.CommandType = CommandType.StoredProcedure;
int errorCode = 0;
SqlDataAdapter adapter = new SqlDataAdapter(cmd);
// Set the connection string
cmd.Connection = _cn;
try
{
// Open connection.
_cn.Open();
// Add paramter to capture the error code
cmd.Parameters.Add(new SqlParameter("@ErrorCode", SqlDbType.Int, 4, ParameterDirection.Output, false, 10, 0, "", DataRowVersion.Proposed, errorCode));
// Execute query.
adapter.Fill(dt);
// Get the error code
errorCode = (Int32)cmd.Parameters["@ErrorCode"].Value;
if( errorCode != 0)
{
// Throw error.
throw new Exception("Stored Procedure 'dbo.[Shippers_SelectAll]' reported the ErrorCode: " + errorCode);
}
return dt;
}
catch(Exception ex)
{
// Throw the error
throw new Exception("An exception has been raised in YellowbridgeSoftwareInc.PersistBase Shippers::SelectAll_DataTable", ex);
}
finally
{
// Close connection.
_cn.Close();
cmd.Dispose();
adapter.Dispose();
}
}
public SqlDataReader SelectAllDataReader()
{
SqlCommand cmd = new SqlCommand();
SqlDataReader dr;
cmd.CommandText = "dbo.[yb_Shippers_SelectAll]";
cmd.CommandType = CommandType.StoredProcedure;
int errorCode = 0;
// Set the connection string
cmd.Connection = _cn;
try
{
// Open connection if needed.
if ( _cn.State == ConnectionState.Closed )
{
_cn.Open();
}
// Add paramter to capture the error code
cmd.Parameters.Add(new SqlParameter("@ErrorCode", SqlDbType.Int, 4, ParameterDirection.Output, false, 10, 0, "", DataRowVersion.Proposed, errorCode));
dr = cmd.ExecuteReader();
return dr;
}
catch(Exception ex)
{
// Throw the error
throw new Exception("An exception has been raised in YellowbridgeSoftwareInc.PersistBase Shippers::SelectAll_DataReader", ex);
}
finally
{
// Clean up
cmd.Dispose();
}
}
#endregion
#region Select Where Methods
public ShippersInfoCollection SelectWhereInfoCollection( string whereClause )
{
SqlCommand cmd = new SqlCommand();
DataTable dt = new DataTable("Shippers");
cmd.CommandText = "dbo.[yb_Shippers_SelectWhere]";
cmd.CommandType = CommandType.StoredProcedure;
int errorCode = 0;
//Create a collection object
ShippersInfoCollection dataCollection = new ShippersInfoCollection();
SqlDataAdapter adapter = new SqlDataAdapter(cmd);
// Set the connection string
cmd.Connection = _cn;
try
{
// Add the parameter
cmd.Parameters.Add(new SqlParameter("@WhereClause", SqlDbType.VarChar , 500 ,ParameterDirection.Input, false ,0 ,0 , "", DataRowVersion.Proposed, whereClause.ToString() ));
// Open connection.
_cn.Open();
// Add paramter to capture the error code
cmd.Parameters.Add(new SqlParameter("@ErrorCode", SqlDbType.Int, 4, ParameterDirection.Output, false, 10, 0, "", DataRowVersion.Proposed, errorCode));
// Execute query.
adapter.Fill(dt);
foreach ( DataRow dr in dt.Rows )
{
ShippersInfo data = new ShippersInfo();
if ( dr["Phone"] == System.DBNull.Value )
data.SetPhoneNull();
else
data.Phone = (string)dr["Phone"];
data.ShipperID = (int)dr["ShipperID"];
data.CompanyName = (string)dr["CompanyName"];
dataCollection.Add( data );
}
// Get the error code
errorCode = (Int32)cmd.Parameters["@ErrorCode"].Value;
if( errorCode != 0)
{
// Throw error.
throw new Exception("Stored Procedure 'dbo.[Shippers_SelectWhere]' reported the ErrorCode: " + errorCode);
}
// Return the data
return dataCollection;
}
catch(Exception ex)
{
// Throw the error
throw new Exception("An exception has been raised in YellowbridgeSoftwareInc.PersistBase Shippers::SelectWhere.", ex);
}
finally
{
// Close connection.
_cn.Close();
cmd.Dispose();
adapter.Dispose();
}
}
public void SelectWhereInfoCollection( ref ShippersInfoCollection dataCollection, string whereClause )
{
SqlCommand cmd = new SqlCommand();
DataTable dt = new DataTable("Shippers");
cmd.CommandText = "dbo.[yb_Shippers_SelectWhere]";
cmd.CommandType = CommandType.StoredProcedure;
int errorCode = 0;
SqlDataAdapter adapter = new SqlDataAdapter(cmd);
// Set the connection string
cmd.Connection = _cn;
try
{
// Add the parameter
cmd.Parameters.Add(new SqlParameter("@WhereClause", SqlDbType.VarChar , 500 ,ParameterDirection.Input, false ,0 ,0 , "", DataRowVersion.Proposed, whereClause.ToString() ));
// Open connection.
_cn.Open();
// Add paramter to capture the error code
cmd.Parameters.Add(new SqlParameter("@ErrorCode", SqlDbType.Int, 4, ParameterDirection.Output, false, 10, 0, "", DataRowVersion.Proposed, errorCode));
// Execute query.
adapter.Fill(dt);
foreach ( DataRow dr in dt.Rows )
{
ShippersInfo data = new ShippersInfo();
if ( dr["Phone"] == System.DBNull.Value )
data.SetPhoneNull();
else
data.Phone = (string)dr["Phone"];
data.ShipperID = (int)dr["ShipperID"];
data.CompanyName = (string)dr["CompanyName"];
dataCollection.Add( data );
}
// Get the error code
errorCode = (Int32)cmd.Parameters["@ErrorCode"].Value;
if( errorCode != 0)
{
// Throw error.
throw new Exception("Stored Procedure 'dbo.[Shippers_SelectWhere]' reported the ErrorCode: " + errorCode);
}
}
catch(Exception ex)
{
// Throw the error
throw new Exception("An exception has been raised in YellowbridgeSoftwareInc.PersistBase Shippers::SelectWhere.", ex);
}
finally
{
// Close connection.
_cn.Close();
cmd.Dispose();
adapter.Dispose();
}
}
public DataTable SelectWhereDataTable( string whereClause )
{
SqlCommand