Click here to Skip to main content
Click here to Skip to main content
Add your own
alternative version

Developing Next Generation Smart Clients using .NET 2.0 working with Existing .NET 1.1 SOA-based XML Web Services

, 16 Aug 2005
Comprehensive guide to development of .NET 2.0 Smart Clients working with existing Service Oriented Architecture based XML web services, fully utilizing the Enterprise Library
smartclientsoa_src.zip
SmartClient
Client
SMI.App
Controls
Forms
Modules
Properties
app.manifest
Settings.settings
Resources
240.png
Bottom.png
BuilderDialog_delete.bmp
DarkBlue.bmp
download-xp.gif
Earth.png
fldropen.png
iSync.gif
Leonardo_da_Vinci_My_Computer.png
LightBlue.bmp
LoginBox.jpg
LoginButton.jpg
LoginButton1.jpg
LoginButton2.jpg
Logo1.png
LogoPic.jpg
Middle.png
Refresh.bmp
refresh.ico
refresh1.ico
RightArrow.bmp
SuccessComplete.bmp
Task.bmp
Tasks.png
Top.png
TurnOffButton.bmp
wi0062-32.ico
wi0063-32.ico
wi0064-16.ico
wi0064-32.ico
SmartInstitute.App.csproj.user
wi0064-32.ico
SMI.Automation
Commands
Course
Framework
Security
Students
UI
Controls
Documents
MiscDocuments
StudentDocuments
Factories
Forms
Helpers
Misc
Properties
Settings.settings
Resources
BuilderDialog_delete.bmp
LogoSmall.bmp
Misho.jpg
My Pic 7.jpg
table.ico
SmartInstitute.Automation.csproj.user
Web References
SmartInstituteServices.AccountService
Account.datasource
AccountService.disco
AccountService.wsdl
Reference.map
SmartInstituteServices.CourseService
Course.datasource
CourseService.disco
CourseService.wsdl
Reference.map
SmartInstituteServices.SecurityService
Reference.map
SecurityService.disco
SecurityService.wsdl
SmartInstituteServices.StudentService
Reference.map
Student.datasource
StudentService.disco
StudentService.wsdl
SMI.ObjectModel.Enhanced
Base
Models
Properties
Settings.settings
Settings
SmartInstitute.ObjectModel.csproj.user
UMS.ObjectModel.Enhanced.csproj.user
SMI.Objects
SmartInstitute.csproj.user
CodeSmith
Tier
BusinessLogicLayer
Entity.cst
EntityBase.cst
EntityCollection.cst
EntityCollectionBase.cst
Enum.cst
IEntity.cst
DataAccessLayer
App.config.cst
CommonSql.cst
Configuration.cst
DBConcurrencyException.cst
DBException.cst
Factories
EntityRepositoryFactory.cst
IEntityRepository.cst
SqlClient
CVS
Entries
Entries.Extra
Entries.Extra.Old
Entries.Old
Repository
Root
TortoiseCVS.Status
SqlEntityRepository.cst
SqlEntityRepositoryBase.cst
TransactionManager.cst
UnitTests
EntityRepositoryTest.cst
WebServiceClient
WsEntityRepository.cst
WsEntityRepositoryBase.cst
Main.cst
nant.cst
References
GotDotNet.ApplicationBlocks.Data.dll
Microsoft.ApplicationBlocks.Data.dll
nunit.framework.dll
StoredProcedures.cst
vsnet2003.project.cst
vsnet2003.solution.cst
vsnet2005.project.cst
vsnet2005.solution.cst
WebService
Web.config.cst
WebService.cst
Database
SmartInstitute.bak
Library
Microsoft.Practices.EnterpriseLibrary.Caching.dll
Microsoft.Practices.EnterpriseLibrary.Common.dll
Microsoft.Practices.EnterpriseLibrary.Configuration.dll
Microsoft.Practices.EnterpriseLibrary.Data.dll
Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.dll
Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging.dll
Microsoft.Practices.EnterpriseLibrary.Logging.dll
Microsoft.Practices.EnterpriseLibrary.Security.ActiveDirectory.dll
Microsoft.Practices.EnterpriseLibrary.Security.Cache.CachingStore.dll
Microsoft.Practices.EnterpriseLibrary.Security.Cryptography.dll
Microsoft.Practices.EnterpriseLibrary.Security.Database.Authentication.dll
Microsoft.Practices.EnterpriseLibrary.Security.Database.dll
Microsoft.Practices.EnterpriseLibrary.Security.dll
nunit.core.dll
nunit.framework.dll
Server
BLL
SmartInstitute.csproj.user
DAL
Factories
SmartInstitute.DataAccessLayer.csproj.user
SqlClient
Utilities
GotDotNet.ApplicationBlocks.Data.dll
Microsoft.ApplicationBlocks.Data.dll
nunit.framework.dll
UnitTests
SmartInstitute.build
SmartInstitute.Facade
FacadeTest
SmartInstitute.Facade.csproj.user
SmartInstitute.Test
App.ico
SmartInstitute.Test.csproj.user
SmartInstituteServices
Global.asax
log
SmartInstituteServices.csproj.webinfo
SQL
Setup
SecurityDatabase
SecurityDatabaseConsole
App.ico
SecurityDatabaseConsole.exe.manifest
SR.strings
Tests
Tools.SecurityDatabaseConsole.csproj.user
	 
#region "Using directives"

using System;
using System.Data;
using System.Data.SqlClient;
//using Microsoft.ApplicationBlocks.Data;
using System.Collections;
using System.Diagnostics;
using SmartInstitute;

#endregion

namespace SmartInstitute.DataAccessLayer.SqlClient
{

/// <summary>
///	This class is the base repository for the CRUD operations on the Course objects.
/// </summary>
public class CourseRepositoryBase : ICourseRepository
{
	#region "Declarations"	
	
	/// <summary>
	/// Connection String.
	/// </summary>
	protected string connectionString = string.Empty;
	
	
	/// <summary>
	/// <see cref="TransactionManager"/> object.
	/// </summary>
	protected TransactionManager transactionManager;
	
	private static volatile CourseRepositoryBase current;
   	private static object syncRoot = new Object();
	
	#endregion "Declarations"
	
	
	#region "Constructors"
		
	/// <summary>
	/// Creates a new <see cref="CourseRepositoryBase"/> instance.
	/// Uses connection string to connect to datasource.
	/// </summary>
	/// <param name="connectionString">Connection string.</param>
	protected CourseRepositoryBase(string connectionString)
	{
		this.connectionString = connectionString;
	}
	
	/// <summary>
	///	Creates a new <see cref="CourseRepositoryBase"/> instance.
	/// Uses connection string to connect to datasource.
	/// If a transaction is open, it will use the transaction, otherwise it will use the connection string from the transaction manager object.
	/// </summary>
	/// <param name="transactionManager"><see cref="TransactionManager"/> object.</param>
	protected CourseRepositoryBase(TransactionManager transactionManager)
	{
		this.transactionManager = transactionManager;
		this.connectionString = this.transactionManager.ConnectionString;
	}
	
	#endregion "Constructors"
	
	#region Public properties
	
	///<summary>
	/// The current CourseRepositoryBase instance.
	///</summary>
	///<value></value>
	public static CourseRepositoryBase Current
	{
	  get 
	  {
	     if (current == null) 
	     {
	        lock (syncRoot) 
	        {
	           if (current == null)
	           {
			   		current = new CourseRepositoryBase(string.Empty);
			   }
	        }
	     }
	     return current;
	  }
	}
	
	///<summary>
	/// Gets or sets the connectionstring to the database.
	///</summary>
	///<value></value>
	public string ConnectionString
	{
		get {return this.connectionString;}
		set {this.connectionString = value;}
	}
	
	
	///<summary>
	/// Gets or sets the TransactionManager instance.
	///</summary>
	///<value></value>
	public TransactionManager TransactionManager
	{
		get {return this.transactionManager;}
		set {this.transactionManager = value;}
	}
	
	#endregion
	
	#region "Get from  Many To Many Relationship Functions"
	#endregion
	
	#region "Delete Functions"
	
	/// <summary>
	/// 	Deletes a row from the DataSource.
	/// </summary>
	/// <param name="ID">. Primary Key.</param>	
    /// <param name="ChangeStamp">Concurrency Parameter. </param>
	/// <returns>Returns true if operation suceeded.</returns>
	public bool Delete(System.Int32 ID, DateTime ChangeStamp)
	{
		if(UseTransaction())
		{
			return Delete(this.transactionManager, ID, ChangeStamp);
		}
		else
		{
			return Delete(this.connectionString, ID, ChangeStamp);
		}
	}//end Delete
	
	/// <summary>
	/// 	Deletes a row from the DataSource.
	/// </summary>
	/// <param name="entity">Course object containing data.</param>
	/// <remarks>Deletes based on primary key(s).</remarks>
	/// <returns>Returns true if operation suceeded.</returns>
	public bool Delete(Course entity)
	{
		if(UseTransaction())
		{
			return Delete(this.transactionManager, entity.ID, entity.ChangeStamp);	
		}
		else
		{
			return Delete(this.connectionString, entity.ID, entity.ChangeStamp);	
		}
	}//end Delete
	/// <summary>
	/// 	Deletes rows from the DataSource.
	/// </summary>
	/// <param name="entityCollection">CourseCollection containing data.</param>
	/// <remarks>Deletes Courses only when IsDeleted equals true.</remarks>
	/// <returns>Returns the number of successful delete.</returns>
	public int Delete(CourseCollection entityCollection)
	{
		if(UseTransaction())
			return Delete(this.transactionManager, entityCollection);
		else
			return Delete(this.connectionString, entityCollection);
	}
	
	
	/// <summary>
	/// 	Deletes a rows from the DataSource.
	/// </summary>
	/// <param name="entityCollection">CourseCollection containing data.</param>
	/// <param name="connectionString">Connection string to datasource.</param>
	/// <remarks>Deletes Courses only when IsDeleted equals true.</remarks>
	/// <returns>Returns the number of successful delete.</returns>
	public int Delete(string connectionString, CourseCollection entityCollection)
	{
		int number = 0;
		foreach (Course entity in entityCollection)
		{
			if ( Delete(connectionString, entity) )
			{
				number++;
			}
		}
		return number;
	}
	
	/// <summary>
	/// 	Deletes a rows from the DataSource.
	/// </summary>
	/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
	/// <param name="entityCollection">CourseCollection containing data.</param>
	/// <remarks>Deletes Courses only when IsDeleted equals true.</remarks>
	/// <returns>Returns the number of successful delete.</returns>
	public int Delete(TransactionManager transactionManager, CourseCollection entityCollection)
	{
		int number = 0;
		foreach (Course entity in entityCollection)
		{
			if ( Delete(transactionManager, entity) )
			{
				number++;
			}
		}
		return number;
	}
	
	
	/// <summary>
	/// 	Deletes a row from the DataSource.
	/// </summary>
	/// <param name="entity">Course object containing data.</param>
	/// <param name="connectionString">Connection string to datasource.</param>
	/// <remarks>Deletes based on primary key(s).</remarks>
	/// <returns>Returns true if operation suceeded.</returns>
	public bool Delete(string connectionString, Course entity)
	{
		return Delete(null, connectionString,entity.ID, entity.ChangeStamp);	
	}
	
	
	/// <summary>
	/// 	Deletes a row from the DataSource.
	/// </summary>
	/// <param name="ID">. Primary Key.</param>	
	/// <param name="connectionString">Connection string to datasource.</param>
    /// <param name="ChangeStamp">Concurrency Parameter. </param>
	/// <remarks>Deletes based on primary key(s).</remarks>
	/// <returns>Returns true if operation suceeded.</returns>
	public bool Delete(string connectionString, System.Int32 ID, DateTime ChangeStamp)
	{
		return Delete(null, connectionString,ID, ChangeStamp);
	}
	
	
	/// <summary>
	/// 	Deletes a row from the DataSource.
	/// </summary>
	/// <param name="entity">Course object containing data.</param>
	/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
	/// <remarks>Deletes based on primary key(s).</remarks>
	/// <returns>Returns true if operation suceeded.</returns>
	public bool Delete(TransactionManager transactionManager, Course entity)
	{
		if (transactionManager.IsOpen)
			return Delete(transactionManager, null, entity.ID, entity.ChangeStamp);	
		else
			return Delete(null, transactionManager.ConnectionString, entity.ID, entity.ChangeStamp);	
	}
	
	
	/// <summary>
	/// 	Deletes a row from the DataSource.
	/// </summary>
	/// <param name="ID">. Primary Key.</param>	
	/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
    /// <param name="ChangeStamp">Concurrency Parameter. </param>
	/// <remarks>Deletes based on primary key(s).</remarks>
	/// <returns>Returns true if operation suceeded.</returns>
	public bool Delete(TransactionManager transactionManager, System.Int32 ID, DateTime ChangeStamp)
	{
		if (transactionManager.IsOpen)
			return Delete(transactionManager, null, ID, ChangeStamp);
		else
			return Delete(null, transactionManager.ConnectionString, ID, ChangeStamp);
	}
	
	
	
	/// <summary>
	/// 	Deletes a row from the DataSource.
	/// </summary>
	/// <param name="ID">. Primary Key.</param>	
	/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
	/// <param name="connectionString">Connection string to datasource.</param>
	/// <remarks>Deletes based on primary key(s).</remarks>
	/// <returns>Returns true if operation suceeded.</returns>
	protected bool Delete(TransactionManager transactionManager, string connectionString, System.Int32 ID, DateTime ChangeStamp)
	{
		int result = 0;
		if (transactionManager != null)
			result = SqlHelper.ExecuteNonQuery(transactionManager.TransactionObject, "prc_Course_Delete", ID, ChangeStamp);
		else
			result = SqlHelper.ExecuteNonQuery(connectionString, "prc_Course_Delete", ID, ChangeStamp);
			
		Debug.WriteLine("CourseRepository.Delete Affected " + result + " records.");
		if (result == 0) {
			ThrowDeleteConcurrencyException( ID, ChangeStamp);
		} 
		return Convert.ToBoolean(result);
	}//end Delete
	
	
	/// <summary>
	/// Throws the delete concurrency exception.
	/// </summary>
	/// <param name="ID">. Primary Key.</param>	
	protected void ThrowDeleteConcurrencyException(System.Int32 ID, DateTime ChangeStamp)
	{
		DBConcurrencyException conflict = new DBConcurrencyException("Concurrency exception: Cannot delete entity as it does not exist.");
		//conflict.ModifiedRecord = entity;
		throw conflict;
	}
	
	
	#endregion

		
	#region "GetList Functions"
	
	
	/// <summary>
	/// 	Gets All rows from the DataSource.
	/// </summary>
	/// <remarks>Uses connection string object was created with.</remarks>
	/// <returns>Returns a typed collection of Course objects.</returns>
	public CourseCollection GetAll()
	{	
		if(UseTransaction())
		{
			return GetAll(this.transactionManager);
		}
		else
		{
			return GetAll(this.connectionString);
		}
	}
	
	/// <summary>
	/// 	Gets All rows from the DataSource.
	/// </summary>
	/// <param name="start">Row number at which to start reading.</param>
	/// <param name="pagelen">Number of rows to return.</param>
	/// <remarks>Uses connection string object was created with.</remarks>
	/// <returns>Returns a typed collection of Course objects.</returns>
	public CourseCollection GetAll(int start, int pagelen)
	{	
		if(UseTransaction())
		{
			return GetAll(this.transactionManager, start, pagelen);
		}
		else
		{
			return GetAll(this.connectionString, start, pagelen);
		}
	}
	
	
	/// <summary>
	/// 	Gets All rows from the DataSource.
	/// </summary>
	/// <param name="connectionString">Connection string to datasource.</param>
	/// <remarks></remarks>
	/// <returns>Returns a typed collection of Course objects.</returns>
	public CourseCollection GetAll(string connectionString)
	{
		return GetAll(null, connectionString,0,int.MaxValue);
	}
	
	/// <summary>
	/// 	Gets All rows from the DataSource.
	/// </summary>
	/// <param name="start">Row number at which to start reading.</param>
	/// <param name="pagelen">Number of rows to return.</param>
	/// <param name="connectionString">Connection string to datasource.</param>
	/// <remarks></remarks>
	/// <returns>Returns a typed collection of Course objects.</returns>
	public CourseCollection GetAll(string connectionString, int start, int pagelen)
	{
		return GetAll(null, connectionString, start, pagelen);
	}//end getall
	
	
	/// <summary>
	/// 	Gets All rows from the DataSource.
	/// </summary>
	/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
	/// <remarks></remarks>
	/// <returns>Returns a typed collection of Course objects.</returns>
	public CourseCollection GetAll(TransactionManager transactionManager)
	{
		if (transactionManager.IsOpen)
			return GetAll(transactionManager, null, 0,int.MaxValue);
		else
			return GetAll(null, transactionManager.ConnectionString, 0,int.MaxValue);
	}
	
	
	/// <summary>
	/// 	Gets All rows from the DataSource.
	/// </summary>
	/// <param name="start">Row number at which to start reading.</param>
	/// <param name="pagelen">Number of rows to return.</param>
	/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
	/// <remarks></remarks>
	/// <returns>Returns a typed collection of Course objects.</returns>
	public CourseCollection GetAll(TransactionManager transactionManager, int start, int pagelen)
	{
		if (transactionManager.IsOpen)
			return GetAll(transactionManager, null, start, pagelen);
		else
			return GetAll(null, transactionManager.ConnectionString, start, pagelen);
	}//end getall
	
	/// <summary>
	/// 	Gets All rows from the DataSource.
	/// </summary>
	/// <param name="start">Row number at which to start reading.</param>
	/// <param name="pagelen">Number of rows to return.</param>
	/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
	/// <param name="connectionString">Connection string to datasource.</param>
	/// <remarks></remarks>
	/// <returns>Returns a typed collection of Course objects.</returns>
	protected CourseCollection GetAll(TransactionManager transactionManager, string connectionString, int start, int pagelen)
	{
		//Declare Varibles
		SqlDataReader reader;
		if (transactionManager != null)
			reader = SqlHelper.ExecuteReader(transactionManager.TransactionObject, "prc_Course_Get_List");
		else
			reader = SqlHelper.ExecuteReader(connectionString, "prc_Course_Get_List");
		//Create Collection
		CourseCollection rows = new CourseCollection();
		Fill(reader, rows, start, pagelen);
		reader.Close();
		return rows;
	}//end getall
	
	#endregion
	
	#region Paged Recordset
			
	/// <summary>
	/// Gets a page of rows from the DataSource.
	/// </summary>
	/// <param name="start">Row number at which to start reading.</param>
	/// <param name="pagelen">Number of rows to return.</param>
	/// <param name="count">Number of rows in the DataSource.</param>
	/// <remarks></remarks>
	/// <returns>Returns a typed collection of Course objects.</returns>
	public CourseCollection GetPaged(int start, int pagelen, out int count)
	{
		if(UseTransaction())
		{
			return GetPaged(this.transactionManager, start, pagelen, out count);
		}
		else
		{
			return GetPaged(this.connectionString, start, pagelen, out count);
		}
	}
	
	/// <summary>
	/// Gets a page of rows from the DataSource.
	/// </summary>
	/// <param name="start">Row number at which to start reading.</param>
	/// <param name="pagelen">Number of rows to return.</param>
	/// <param name="count">Number of rows in the DataSource.</param>
	/// <param name="whereClause">Specifies the condition for the rows returned by a query (Name='John Doe', Name='John Doe' AND Id='1', Name='John Doe' OR Id='1').</param>
	/// <param name="orderBy">Specifies the sort criteria for the rows in the DataSource (Name ASC; BirthDay DESC, Name ASC);</param>
	/// <remarks></remarks>
	/// <returns>Returns a typed collection of Course objects.</returns>
	public CourseCollection GetPaged(string whereClause, string orderBy, int start, int pagelen, out int count)
	{
		if(UseTransaction())
		{
			return GetPaged(this.transactionManager, whereClause, orderBy, start, pagelen, out count);
		}
		else
		{
			return GetPaged(this.connectionString, whereClause, orderBy, start, pagelen, out count);
		}
	}
	
	/// <summary>
	/// Gets a page of rows from the DataSource.
	/// </summary>
	/// <param name="start">Row number at which to start reading.</param>
	/// <param name="pagelen">Number of rows to return.</param>
	/// <param name="count">Number of rows in the DataSource.</param>
	/// <param name="connectionString">The connection string to the datasource</param>
	/// <remarks></remarks>
	/// <returns>Returns a typed collection of Course objects.</returns>
	public CourseCollection GetPaged(string connectionString, int start, int pagelen, out int count)
	{
		return GetPaged(null, connectionString, null, null, start, pagelen, out count);
	}

	/// <summary>
	/// Gets a page of rows from the DataSource.
	/// </summary>
	/// <param name="whereClause">Specifies the condition for the rows returned by a query (Name='John Doe', Name='John Doe' AND Id='1', Name='John Doe' OR Id='1').</param>
	/// <param name="orderBy">Specifies the sort criteria for the rows in the DataSource (Name ASC; BirthDay DESC, Name ASC);</param>
	/// <param name="start">Row number at which to start reading.</param>
	/// <param name="pagelen">Number of rows to return.</param>
	/// <param name="count">Number of rows in the DataSource.</param>
	/// <param name="connectionString">The connection string to the datasource</param>
	/// <remarks></remarks>
	/// <returns>Returns a typed collection of Course objects.</returns>
	public CourseCollection GetPaged(string connectionString, string whereClause, string orderBy, int start, int pagelen, out int count)
	{
		return GetPaged(null, connectionString, whereClause, orderBy, start, pagelen, out count);
	}
	
	/// <summary>
	/// Gets a page of rows from the DataSource.
	/// </summary>
	/// <param name="start">Row number at which to start reading.</param>
	/// <param name="pagelen">Number of rows to return.</param>
	/// <param name="count">Number of rows in the DataSource.</param>
	/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
	/// <remarks></remarks>
	/// <returns>Returns a typed collection of Course objects.</returns>
	public CourseCollection GetPaged(TransactionManager transactionManager, int start, int pagelen, out int count)
	{
		if (transactionManager.IsOpen)
			return GetPaged(transactionManager, null, null, null, start, pagelen, out count);
		else
			return GetPaged(null, transactionManager.ConnectionString, null, null, start, pagelen, out count);
	}
	
		/// <summary>
	/// Gets a page of rows from the DataSource.
	/// </summary>
	/// <param name="whereClause">Specifies the condition for the rows returned by a query (Name='John Doe', Name='John Doe' AND Id='1', Name='John Doe' OR Id='1').</param>
	/// <param name="orderBy">Specifies the sort criteria for the rows in the DataSource (Name ASC; BirthDay DESC, Name ASC);</param>
	/// <param name="start">Row number at which to start reading.</param>
	/// <param name="pagelen">Number of rows to return.</param>
	/// <param name="count">Number of rows in the DataSource.</param>
	/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
	/// <remarks></remarks>
	/// <returns>Returns a typed collection of Course objects.</returns>
	public CourseCollection GetPaged(TransactionManager transactionManager, string whereClause, string orderBy, int start, int pagelen, out int count)
	{
		if (transactionManager.IsOpen)
			return GetPaged(transactionManager, null, whereClause, orderBy, start, pagelen, out count);
		else
			return GetPaged(null, transactionManager.ConnectionString, whereClause, orderBy, start, pagelen, out count);
	}
	
	/// <summary>
	/// Gets a page of rows from the DataSource.
	/// </summary>
	/// <param name="start">Row number at which to start reading.</param>
	/// <param name="pagelen">Number of rows to return.</param>
	/// <param name="count">Number of rows in the DataSource.</param>
	/// <param name="whereClause">Specifies the condition for the rows returned by a query (Name='John Doe', Name='John Doe' AND Id='1', Name='John Doe' OR Id='1').</param>
	/// <param name="orderBy">Specifies the sort criteria for the rows in the DataSource (Name ASC; BirthDay DESC, Name ASC);</param>
	/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
	/// <param name="connectionString">Connection string to datasource.</param>
	/// <remarks></remarks>
	/// <returns>Returns a typed collection of Course objects.</returns>
	protected CourseCollection GetPaged(TransactionManager transactionManager, string connectionString, string whereClause, string orderBy, int start, int pagelen, out int count)
	{
		
		//Declare Varibles
		SqlDataReader reader;
		if (transactionManager != null)
			reader = SqlHelper.ExecuteReader(transactionManager.TransactionObject, "prc_Course_GetPaged", whereClause, orderBy, start, pagelen);
		else
			reader = SqlHelper.ExecuteReader(connectionString, "prc_Course_GetPaged", whereClause, orderBy, start, pagelen);
		
		reader.Read();
		count = reader.GetInt32(0);
		reader.NextResult();

		//Create Collection
		CourseCollection rows = new CourseCollection();
		Fill(reader, rows, 0, int.MaxValue);
		reader.Close();
		return rows;
	}
	
	#endregion
	
	#region "Get By Foreign Key Functions"
	#endregion
	
	#region "Get By Index Functions"

	
	/// <summary>
	/// 	Gets rows from the datasource based on the PK_Course_1 index.
	/// </summary>
	/// <param name="ID"></param>
	/// <returns>Returns a typed collection of Course objects.</returns>
	public CourseCollection GetByID(System.Int32 ID)
	{
		if(UseTransaction())
		{
			return GetByID(this.transactionManager, ID, 0, int.MaxValue);
		}
		else
		{
			return GetByID(this.connectionString, ID, 0, int.MaxValue);
		}
	}
	
	
	/// <summary>
	/// 	Gets rows from the datasource based on the PK_Course_1 index.
	/// </summary>
	/// <param name="start">Row number at which to start reading.</param>
	/// <param name="pagelen">Number of rows to return.</param>
	/// <param name="ID"></param>
	/// <remarks></remarks>
	/// <returns>Returns a typed collection of Course objects.</returns>
	public CourseCollection GetByID(System.Int32 ID, int start, int pagelen)
	{
		if(UseTransaction())
		{
			return GetByID(this.transactionManager, ID, start, pagelen);
		}
		else
		{
			return GetByID(this.connectionString, ID, start, pagelen);
		}
	}

	
	/// <summary>
	/// 	Gets rows from the datasource based on the PK_Course_1 index.
	/// </summary>
	/// <param name="ID"></param>
	/// <param name="connectionString">Connection string to datasource.</param>
	/// <remarks></remarks>
	/// <returns>Returns a typed collection of Course objects.</returns>
	public CourseCollection GetByID(string connectionString, System.Int32 ID)
	{
		return GetByID(null, connectionString, ID, 0, int.MaxValue);
	}
	
	
	/// <summary>
	/// 	Gets rows from the datasource based on the PK_Course_1 index.
	/// </summary>
	/// <param name="start">Row number at which to start reading.</param>
	/// <param name="pagelen">Number of rows to return.</param>
	/// <param name="ID"></param>
	/// <param name="connectionString">Connection string to datasource.</param>
	/// <remarks></remarks>
	/// <returns>Returns a typed collection of Course objects.</returns>
	public CourseCollection GetByID(string connectionString, System.Int32 ID, int start, int pagelen)
	{
		return GetByID(null, connectionString, ID, start, pagelen);
	}

	
	/// <summary>
	/// 	Gets rows from the datasource based on the PK_Course_1 index.
	/// </summary>
	/// <param name="ID"></param>
	/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
	/// <remarks></remarks>
	/// <returns>Returns a typed collection of Course objects.</returns>
	public CourseCollection GetByID(TransactionManager transactionManager, System.Int32 ID)
	{
		if (transactionManager.IsOpen)
			return GetByID(transactionManager, null, ID, 0, int.MaxValue);
		else
			return GetByID(null, transactionManager.ConnectionString, ID, 0, int.MaxValue);
	}
	
	
	/// <summary>
	/// 	Gets rows from the datasource based on the PK_Course_1 index.
	/// </summary>
	/// <param name="start">Row number at which to start reading.</param>
	/// <param name="pagelen">Number of rows to return.</param>
	/// <param name="ID"></param>
	/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
	/// <remarks></remarks>
	/// <returns>Returns a typed collection of Course objects.</returns>
	public CourseCollection GetByID(TransactionManager transactionManager, System.Int32 ID, int start, int pagelen)
	{
		if (transactionManager.IsOpen)
			return GetByID(transactionManager, null, ID, start, pagelen);
		else
			return GetByID(null, transactionManager.ConnectionString, ID, start, pagelen);
	}
	
	
	/// <summary>
	/// 	Gets rows from the datasource based on the PK_Course_1 index.
	/// </summary>
	/// <param name="start">Row number at which to start reading.</param>
	/// <param name="pagelen">Number of rows to return.</param>
	/// <param name="ID"></param>
	/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
	/// <param name="connectionString">Connection string to datasource.</param>
	/// <remarks></remarks>
	/// <returns>Returns a typed collection of Course objects.</returns>
	protected CourseCollection GetByID(TransactionManager transactionManager, string connectionString, System.Int32 ID, int start, int pagelen)
	{
		//Declare Varibles
		SqlDataReader reader;
		if (transactionManager != null)
			reader = SqlHelper.ExecuteReader(transactionManager.TransactionObject, "prc_Course_GetByID", ID);
		else
			reader = SqlHelper.ExecuteReader(connectionString, "prc_Course_GetByID", ID);
		//Create collection and fill
		CourseCollection rows = new CourseCollection();
		Fill(reader, rows, start, pagelen);
		reader.Close();
		return rows;
	}
	

	#endregion "Get By Index Functions"

	#region "Insert Functions"

	/// <summary>
	/// 	Inserts a Course object into the datasource.
	/// </summary>
	/// <param name="entity">Course object to insert.</param>
	/// <remarks>After inserting into the datasource, the Course object will be updated
	/// to refelect any changes made by the datasource. (ie: identity columns)</remarks>
	/// <returns>Returns true if operation is successful.</returns>
	public bool Insert(Course entity)
	{
		if(UseTransaction())
		{
			return Insert(this.transactionManager, entity);
		}
		else
		{
			return Insert(this.connectionString, entity);
		}
	}
	
	/// <summary>
	/// 	Insert rows in the datasource.
	/// </summary>
	/// <param name="entityCollection"><c>Course</c> objects in a <c>CourseCollection</c> object to insert.</param>
	/// <remarks>
	///		This function will only insert entity objects marked as dirty
	///		and have an identity field equal to zero.
	///		Upon inserting the objects, each dirty object will have the public
	///		method <c>Object.AcceptChanges()</c> called to make it clean.
	/// 	After inserting into the datasource, the <c>Course</c> objects will be updated
	/// 	to refelect any changes made by the datasource. (ie: identity columns)</remarks>
	/// <returns>Returns the number of successful insert.</returns>
	public int Insert(CourseCollection entityCollection)
	{
			if(UseTransaction())
		{
			return Insert(this.transactionManager, entityCollection);
		}
		else
		{
			return Insert(this.connectionString, entityCollection);
		}		
	}

		
	/// <summary>
	/// 	Insert rows in the datasource.
	/// </summary>
	/// <param name="connectionString">Connection string to datasource.</param>
	/// <param name="entityCollection"><c>Course</c> objects in a <c>CourseCollection</c> object to insert.</param>
	/// <remarks>
	///		This function will only insert entity objects marked as dirty
	///		and have an identity field equal to zero.
	///		Upon inserting the objects, each dirty object will have the public
	///		method <c>Object.AcceptChanges()</c> called to make it clean.
	/// 	After inserting into the datasource, the <c>Course</c> objects will be updated
	/// 	to refelect any changes made by the datasource. (ie: identity columns)</remarks>
	/// <returns>Returns the number of successful insert.</returns>
	public int Insert(string connectionString, CourseCollection entityCollection)
	{
		int number = 0;
		foreach (Course entity in entityCollection)
		{
			if (entity.IsNew)
			{
				if (Insert(connectionString, entity) )
				{
					number++;
				}
			}
		}
		return number;
	}
	
	/// <summary>
	/// 	Insert rows in the datasource.
	/// </summary>
	/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
	/// <param name="entityCollection"><c>Course</c> objects in a <c>CourseCollection</c> object to insert.</param>
	/// <remarks>
	///		This function will only insert entity objects marked as dirty
	///		and have an identity field equal to zero.
	///		Upon inserting the objects, each dirty object will have the public
	///		method <c>Object.AcceptChanges()</c> called to make it clean.
	/// 	After inserting into the datasource, the <c>Course</c> objects will be updated
	/// 	to refelect any changes made by the datasource. (ie: identity columns)</remarks>
	/// <returns>Returns the number of successful insert.</returns>
	public int Insert(TransactionManager transactionManager, CourseCollection entityCollection)
	{
		int number = 0;
		foreach (Course entity in entityCollection)
		{
			if (entity.IsNew)
			{
				if (Insert(transactionManager, entity) )
				{
					number++;
				}
			}
		}
		return number;
	}
	
	/// <summary>
	/// 	Inserts a Course object into the datasource.
	/// </summary>
	/// <param name="connectionString">Connection string to datasource.</param>
	/// <param name="entity">Course object to insert.</param>
	/// <remarks>After inserting into the datasource, the Course object will be updated
	/// to refelect any changes made by the datasource. (ie: identity columns)</remarks>
	/// <returns>Returns true if operation is successful.</returns>
	public bool Insert(string connectionString, Course entity)
	{
		return Insert(null, connectionString, entity);
	}
	
	
	/// <summary>
	/// 	Inserts a Course object into the datasource using a transaction.
	/// </summary>
	/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
	/// <param name="entity">Course object to insert.</param>
	/// <remarks>After inserting into the datasource, the Course object will be updated
	/// to refelect any changes made by the datasource. (ie: identity columns)</remarks>
	/// <returns>Returns true if operation is successful.</returns>
	public bool Insert(TransactionManager transactionManager,  Course entity)
	{
		if (transactionManager.IsOpen)
			return Insert(transactionManager, null, entity);
		else
			return Insert(null, transactionManager.ConnectionString, entity);
	}
	
	
	/// <summary>
	/// 	Inserts a Course object into the datasource using a transaction.
	/// </summary>
	/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
	/// <param name="connectionString">Connection string to datasource.</param>
	/// <param name="entity">Course object to insert.</param>
	/// <remarks>After inserting into the datasource, the Course object will be updated
	/// to refelect any changes made by the datasource. (ie: identity columns)</remarks>
	/// <returns>Returns true if operation is successful.</returns>
	protected bool Insert(TransactionManager transactionManager, string connectionString, Course entity)
	{
		//Declare variables			
		//IDataParameterCollection parameters;
		SqlDataReader reader;
		int result = 0;
		//Get Parameters
		//if (transactionManager != null)
		//	parameters = SqlHelperParameterCache.GetSpParameterSet(transactionManager.ConnectionString, "prc_Course_Insert");
		//else
		//	parameters = SqlHelperParameterCache.GetSpParameterSet(connectionString, "prc_Course_Insert");
		//Assign values to parameters
		//AssignInsertParameters(parameters, entity);
		
		
		if (transactionManager != null)
			reader = SqlHelper.ExecuteReader(transactionManager.TransactionObject, "prc_Course_Insert", 
			entity.ChangeStamp,entity.CompCredit,entity.CourseCode,entity.LecCredit,entity.SciCredit,entity.Title);
		else
			reader = SqlHelper.ExecuteReader(connectionString, "prc_Course_Insert", 
			entity.ChangeStamp,entity.CompCredit,entity.CourseCode,entity.LecCredit,entity.SciCredit,entity.Title );
			
		Debug.WriteLine("CourseRepository-Insert Affected " + reader.RecordsAffected + " records.");
		if (reader.RecordsAffected > 0)
		{
			//RefreshEntity closes the connection
			RefreshEntity(reader, entity);
			result = 1;
		}
		else
		{
			//must always close the connection
			reader.Close();
		}
		return Convert.ToBoolean(result);
	}
	
	
	
	
	/// <summary>
	/// Assigns the insert parameters from the Course instance to the SqlParameter array.
	/// </summary>
	/// <param name="parameters">The <see cref="SqlParameter"/> array to fill.</param>
	/// <param name="entity">The <see cref="Course"/> instance to read from.</param>
	/* protected void AssignInsertParameters(IDataParameterCollection paramCollection, Course entity)
	{
		SqlParameter[] parameters = new SqlParameter[ paramCollection.Count ];
		paramCollection.CopyTo( parameters, 0 );
		
					parameters[0].Value = entity.ChangeStamp;
					parameters[1].Value = entity.CompCredit;
					parameters[2].Value = entity.CourseCode;
					parameters[3].Value = entity.LecCredit;
					parameters[4].Value = entity.SciCredit;
					parameters[5].Value = entity.Title;
	} */
	
	#endregion

	#region "Update Functions"
	
	
	/// <summary>
	/// 	Update an existing row in the datasource.
	/// </summary>
	/// <param name="entity">The <see cref="Course"/> instance to update.</param>
	/// <remarks>After updating the datasource, the Course object will be updated
	/// to refelect any changes made by the datasource. (ie: identity columns)</remarks>
	/// <returns>Returns true if operation is successful.</returns>
	public bool Update(Course entity)
	{
		if(UseTransaction())
		{
			return Update(this.transactionManager, entity);
		}
		else
		{
			return Update(this.connectionString, entity);
		}		
	}		
	
	/// <summary>
	/// 	Update existing rows in the datasource.
	/// </summary>
	/// <param name="entityCollection"><c>Course</c> objects in a <c>CourseCollection</c> object to update.</param>
	/// <remarks>
	///		This function will only update entity objects marked as dirty
	///		and do not have an primary key value of 0.
	///		Upon updating the objects, each dirty object will have the public
	///		method <c>Object.AcceptChanges()</c> called to make it clean.
	/// 	After updating the datasource, the <c>Course</c> objects will be updated
	/// 	to refelect any changes made by the datasource. (ie: identity columns)</remarks>
	/// <returns>Returns the number of successful update .</returns>
	public int Update(CourseCollection entityCollection)
	{
		if(UseTransaction())
		{
			return Update(this.transactionManager, entityCollection);
		}
		else
		{
			return Update(this.connectionString, entityCollection);
		}	
	}

	
	/// <summary>
	/// 	Update existing rows in the datasource.
	/// </summary>
	/// <param name="connectionString">Connection string to datasource.</param>
	/// <param name="entityCollection"><c>Course</c> objects in a <c>CourseCollection</c> object to update.</param>
	/// <remarks>
	///		This function will only update entity objects marked as dirty
	///		and do not have an primary key value of 0.
	///		Upon updating the objects, each dirty object will have the public
	///		method <c>Object.AcceptChanges()</c> called to make it clean.
	/// 	After updating the datasource, the <c>Course</c> objects will be updated
	/// 	to refelect any changes made by the datasource. (ie: identity columns)</remarks>
	/// <returns>Returns the number of successful update .</returns>
	public int Update(string connectionString, CourseCollection entityCollection)
	{	
		int number = 0;
		foreach (Course entity in entityCollection)
		{
			if ((entity.IsDirty) && !(entity.IsNew))
			{
				if ( Update(connectionString, entity) )
				{
					number++;
				}
			}
		}
		return number;
	}
	
	
	/// <summary>
	/// 	Update existing rows in the datasource.
	/// </summary>
	/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
	/// <param name="entityCollection"><c>Course</c> objects in a <c>CourseCollection</c> object to update.</param>
	/// <remarks>
	///		This function will only update entity objects marked as dirty
	///		and do not have an primary key value of 0.
	///		Upon updating the objects, each dirty object will have the public
	///		method <c>Object.AcceptChanges()</c> called to make it clean.
	/// 	After updating the datasource, the <c>Course</c> objects will be updated
	/// 	to refelect any changes made by the datasource. (ie: identity columns)</remarks>
	/// <returns>Returns the number of successful update .</returns>
	public int Update(TransactionManager transactionManager, CourseCollection entityCollection)
	{
		int number = 0;
		foreach (Course entity in entityCollection)
		{
			if ((entity.IsDirty) && !(entity.IsNew))
			{
				if ( Update(transactionManager, entity) )
				{
					number++;
				}
			}
		}
		return number;
	}

	/// <summary>
	/// 	Update an existing row in the datasource.
	/// </summary>
	/// <param name="connectionString">Connection string to datasource.</param>
	/// <param name="entity">Course object to update.</param>
	/// <remarks>After updating the datasource, the Course object will be updated
	/// to refelect any changes made by the datasource. (ie: identity columns)</remarks>
	/// <returns>Returns true if operation is successful.</returns>
	public bool Update(string connectionString, Course entity)
	{	
		return Update(null, connectionString, entity);
	}
	
	
	/// <summary>
	/// 	Update an existing row in the datasource.
	/// </summary>
	/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
	/// <param name="entity">Course object to update.</param>
	/// <remarks>After updating the datasource, the Course object will be updated
	/// to refelect any changes made by the datasource. (ie: identity columns)</remarks>
	/// <returns>Returns true if operation is successful.</returns>
	public bool Update(TransactionManager transactionManager, Course entity)
	{
		if (transactionManager.IsOpen)
			return Update(transactionManager, null, entity);
		else
			return Update(null, transactionManager.ConnectionString, entity);
	}
	
	
	/// <summary>
	/// 	Update an existing row in the datasource.
	/// </summary>
	/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
	/// <param name="connectionString">Connection string to datasource.</param>
	/// <param name="entity">Course object to update.</param>
	/// <remarks>After updating the datasource, the Course object will be updated
	/// to refelect any changes made by the datasource. (ie: identity columns)</remarks>
	/// <returns>Returns true if operation is successful.</returns>
	protected bool Update(TransactionManager transactionManager, string connectionString, Course entity)
	{
		//Declare variables
		//IDataParameterCollection parameters;
		SqlDataReader reader;
		int result = 0;
		//Get Parameters
		//if (transactionManager != null)
		//	parameters = SqlHelperParameterCache.GetSpParameterSet(transactionManager.ConnectionString, "prc_Course_Update");
		//else
		//	parameters = SqlHelperParameterCache.GetSpParameterSet(connectionString, "prc_Course_Update");
		//Assign parameters values to corresponding entity values
		//AssignUpdateParameters(parameters, entity);
		
		
		//Get Reader
		if (transactionManager != null)
			reader = SqlHelper.ExecuteReader(transactionManager.TransactionObject, "prc_Course_Update",
				entity.ID,entity.ChangeStamp,entity.CompCredit,entity.CourseCode,entity.LecCredit,entity.SciCredit,entity.Title);
		else
			reader = SqlHelper.ExecuteReader(connectionString, "prc_Course_Update", 
				entity.ID,entity.ChangeStamp,entity.CompCredit,entity.CourseCode,entity.LecCredit,entity.SciCredit,entity.Title);
			
		Debug.WriteLine("CourseRepository-Update Affected " + reader.RecordsAffected + " records.");
		if (reader.RecordsAffected > 0)
		{
			RefreshEntity(reader, entity);
			result = reader.RecordsAffected;
		}
		else
		{
			//must always close the connection
			reader.Close();
			DBConcurrencyException conflict = new DBConcurrencyException("Concurrency exception");
			conflict.ModifiedRecord = entity;
			CourseCollection dsrecord;
			//Get record from Datasource
			if (transactionManager != null)
				dsrecord = CourseRepository.Current.GetByID(this.transactionManager, entity.ID);
			else
				dsrecord = CourseRepository.Current.GetByID(connectionString, entity.ID);
			if(dsrecord.Count > 0)
				conflict.DatasourceRecord = dsrecord[0];
			throw conflict;
		}
		return Convert.ToBoolean(result);
	}

	
	
	/// <summary>
	/// Assigns the update parameters from an to a <see cref="Course"/> instance to an <see cref="SqlParameter"/> array.
	/// </summary>
	/// <param name="parameters">The <see cref="SqlParameter"/> array.</param>
	/// <param name="entity">The <see cref="Course"/> instance.</param>
	//protected void AssignUpdateParameters(IDataParameterCollection paramCollection, Course entity)
	//{
	//}
	
	#endregion
	
	
	#region "Save Functions"
	
	/// <summary>
	/// 	Updates, Inserts rows in the datasource.
	/// </summary>
	/// <param name="entityCollection"><c>Course</c> objects in a <c>CourseCollection</c> object to update.</param>
	/// <remarks>
	/// 	After updating the datasource, the <c>Course</c> objects will be updated or inserted
	/// 	to refelect any changes made by the datasource. (ie: identity columns)</remarks>
	/// <returns>Returns true if operation is successful.</returns>
	public void Save(CourseCollection entityCollection)
	{
		if(UseTransaction())
		{
			Save(this.transactionManager, entityCollection);
		}
		else
		{
			Save(this.connectionString, entityCollection);
		}
	}
	

		
	
	/// <summary>
	/// 	Updates, Inserts rows in the datasource.
	/// </summary>
	/// <param name="connectionString">Connection String to Datasource.</param>
	/// <param name="entity">Course object to update.</param>
	/// <remarks>
	/// 	After updating the datasource, the <c>Course</c> objects will be updated or inserted
	/// 	to refelect any changes made by the datasource. (ie: identity columns)</remarks>
	/// <returns>Returns true if operation is successful.</returns>
	public void Save(string connectionString, Course entity)
	{		
		if (entity.IsDeleted)
			Delete(connectionString, entity);
		else if ((entity.IsDirty) && !(entity.IsNew))
			Update(connectionString, entity);
		else if (entity.IsNew)
			Insert(connectionString, entity);
	}



	/// <summary>
	/// 	Updates, Inserts rows in the datasource.
	/// </summary>
	/// <param name="connectionString">Connection String to Datasource.</param>
	/// <param name="entityCollection"><c>Course</c> objects in a <c>CourseCollection</c> object to update.</param>
	/// <remarks>
	/// 	After updating the datasource, the <c>Course</c> objects will be updated or inserted
	/// 	to refelect any changes made by the datasource. (ie: identity columns)</remarks>
	/// <returns>Returns true if operation is successful.</returns>
	public void Save(string connectionString, CourseCollection entityCollection)
	{
		foreach (Course entity in entityCollection)
		{			
			Save(connectionString, entity);
		}
	}
	
	
	
	
	/// <summary>
	/// 	Updates, Inserts rows in the datasource.
	/// </summary>
	/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
	/// <param name="entity"><c>Course</c> objects in a <c>CourseCollection</c> object to update.</param>
	/// <remarks>
	/// 	After updating the datasource, the <c>Course</c> objects will be updated or inserted
	/// 	to refelect any changes made by the datasource. (ie: identity columns)</remarks>
	/// <returns>Returns true if operation is successful.</returns>
	public void Save(TransactionManager transactionManager, Course entity)
	{		
		if (entity.IsDeleted)
		{
			Delete(transactionManager, entity);
		}
		if ((entity.IsDirty) && !(entity.IsNew))
		{
			Update(transactionManager, entity);
		}
		else if (entity.IsNew)
		{
			Insert(transactionManager, entity);
		}
	}
	
	
	/// <summary>
	/// 	Updates, Inserts rows in the datasource.
	/// </summary>
	/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
	/// <param name="entityCollection"><c>Course</c> objects in a <c>CourseCollection</c> object to update.</param>
	/// <remarks>
	/// 	After updating the datasource, the <c>Course</c> objects will be updated or inserted
	/// 	to refelect any changes made by the datasource. (ie: identity columns)</remarks>
	/// <returns>Returns true if operation is successful.</returns>
	public void Save(TransactionManager transactionManager, CourseCollection entityCollection)
	{
		foreach (Course entity in entityCollection)
		{
			Save(transactionManager, entity);
		}
	}
	#endregion
	

	#region "Helper Functions"

	///<summary>
	/// Fill an CourseCollection From a DataSet
	///</summary>
	/// <param name="dataSet">the DataSet</param>
	/// <param name="rows">The collection to fill</param>
	/// <param name="start">Start row</param>
	/// <param name="pagelen">number of row.</param>
	///<returns>A <see chref="CourseCollection"/> object.</returns>
	protected CourseCollection Fill(DataSet dataSet, CourseCollection rows, int start, int pagelen)
	{
		int recordnum = 0;
		
		System.Collections.IEnumerator dataRows =  dataSet.Tables[0].Rows.GetEnumerator();
		
		while (dataRows.MoveNext() && (pagelen != 0))
		{
			if(recordnum >= start)
			{
				DataRow row = (DataRow)dataRows.Current;
			
				Course c = new Course();
				c.ID = (Convert.IsDBNull(row["ID"]))?(int)0:(System.Int32)row["ID"];
				c.CourseCode = (Convert.IsDBNull(row["CourseCode"]))?string.Empty:(System.String)row["CourseCode"];
				c.Title = (Convert.IsDBNull(row["Title"]))?string.Empty:(System.String)row["Title"];
				c.SciCredit = (Convert.IsDBNull(row["SciCredit"]))?(int)0:(System.Int32)row["SciCredit"];
				c.CompCredit = (Convert.IsDBNull(row["CompCredit"]))?(int)0:(System.Int32)row["CompCredit"];
				c.LecCredit = (Convert.IsDBNull(row["LecCredit"]))?(int)0:(System.Int32)row["LecCredit"];
				c.ChangeStamp = (Convert.IsDBNull(row["ChangeStamp"]))?DateTime.MinValue:(System.DateTime)row["ChangeStamp"];
				rows.Add(c);
				pagelen -= 1;
			}
			recordnum += 1;
		}
		return rows;
	}

	
	///<summary>
	/// Fill an CourseCollection From a DataReader.
	///</summary>
	/// <param name="reader">Datareader</param>
	/// <param name="rows">The collection to fill</param>
	/// <param name="start">Start row</param>
	/// <param name="pagelen">number of row.</param>
	///<returns>a <see cref="CourseCollection"/></returns>
	protected CourseCollection Fill(SqlDataReader reader, CourseCollection rows, int start, int pagelen)
	{
		int recordnum = 0;
		while (reader.Read() && (pagelen != 0))
		{
			if(recordnum >= start)
			{
				Course c = new Course();
				c.ID = (Convert.IsDBNull(reader["ID"]))?(int)0:(System.Int32)reader["ID"];
				c.CourseCode = (Convert.IsDBNull(reader["CourseCode"]))?string.Empty:(System.String)reader["CourseCode"];
				c.Title = (Convert.IsDBNull(reader["Title"]))?string.Empty:(System.String)reader["Title"];
				c.SciCredit = (Convert.IsDBNull(reader["SciCredit"]))?(int)0:(System.Int32)reader["SciCredit"];
				c.CompCredit = (Convert.IsDBNull(reader["CompCredit"]))?(int)0:(System.Int32)reader["CompCredit"];
				c.LecCredit = (Convert.IsDBNull(reader["LecCredit"]))?(int)0:(System.Int32)reader["LecCredit"];
				c.ChangeStamp = (Convert.IsDBNull(reader["ChangeStamp"]))?DateTime.MinValue:(System.DateTime)reader["ChangeStamp"];
				c.AcceptChanges();
				rows.Add(c);
				pagelen -= 1;
			}
			recordnum += 1;
		}
		return rows;
	}
	
	
	/// <summary>
	/// Refreshes the <see cref="Course"/> object from the <see cref="SqlDataReader"/>.
	/// </summary>
	/// <param name="reader">The <see cref="SqlDataReader"/> to read from.</param>
	/// <param name="entity">The <see cref="Course"/> object.</param>
	protected void RefreshEntity(SqlDataReader reader, Course entity)
	{
		reader.Read();
		entity.ID = (Convert.IsDBNull(reader["ID"]))?(int)0:(System.Int32)reader["ID"];
		entity.CourseCode = (Convert.IsDBNull(reader["CourseCode"]))?string.Empty:(System.String)reader["CourseCode"];
		entity.Title = (Convert.IsDBNull(reader["Title"]))?string.Empty:(System.String)reader["Title"];
		entity.SciCredit = (Convert.IsDBNull(reader["SciCredit"]))?(int)0:(System.Int32)reader["SciCredit"];
		entity.CompCredit = (Convert.IsDBNull(reader["CompCredit"]))?(int)0:(System.Int32)reader["CompCredit"];
		entity.LecCredit = (Convert.IsDBNull(reader["LecCredit"]))?(int)0:(System.Int32)reader["LecCredit"];
		entity.ChangeStamp = (Convert.IsDBNull(reader["ChangeStamp"]))?DateTime.MinValue:(System.DateTime)reader["ChangeStamp"];
		reader.Close();

		entity.AcceptChanges();
	}
	
	
	/// <summary>
	/// Indicates if a transaction is currently used.
	/// </summary>
	/// <returns></returns>
	protected bool UseTransaction()
	{
		return UseTransaction(this.transactionManager);
	}
	
	
	
	/// <summary>
	/// Indicates if a transaction is currently used.
	/// </summary>
	/// <param name="transactionManager"><see cref="TransactionManager"/> object.</param>
	/// <returns></returns>
	protected bool UseTransaction(TransactionManager transactionManager)
	{
		if (transactionManager != null)
		{
			if (transactionManager.IsOpen)
				return true;
		}
		return false;
	}
	#endregion "Helper Functions"
	
	}//end class
} // end namespace

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author


| Advertise | Privacy | Mobile
Web01 | 2.8.140721.1 | Last Updated 17 Aug 2005
Article Copyright 2005 by Omar Al Zabir
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid