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 Account objects.
/// </summary>
public class AccountRepositoryBase : IAccountRepository
{
	#region "Declarations"	
	
	/// <summary>
	/// Connection String.
	/// </summary>
	protected string connectionString = string.Empty;
	
	
	/// <summary>
	/// <see cref="TransactionManager"/> object.
	/// </summary>
	protected TransactionManager transactionManager;
	
	private static volatile AccountRepositoryBase current;
   	private static object syncRoot = new Object();
	
	#endregion "Declarations"
	
	
	#region "Constructors"
		
	/// <summary>
	/// Creates a new <see cref="AccountRepositoryBase"/> instance.
	/// Uses connection string to connect to datasource.
	/// </summary>
	/// <param name="connectionString">Connection string.</param>
	protected AccountRepositoryBase(string connectionString)
	{
		this.connectionString = connectionString;
	}
	
	/// <summary>
	///	Creates a new <see cref="AccountRepositoryBase"/> 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 AccountRepositoryBase(TransactionManager transactionManager)
	{
		this.transactionManager = transactionManager;
		this.connectionString = this.transactionManager.ConnectionString;
	}
	
	#endregion "Constructors"
	
	#region Public properties
	
	///<summary>
	/// The current AccountRepositoryBase instance.
	///</summary>
	///<value></value>
	public static AccountRepositoryBase Current
	{
	  get 
	  {
	     if (current == null) 
	     {
	        lock (syncRoot) 
	        {
	           if (current == null)
	           {
			   		current = new AccountRepositoryBase(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">Account object containing data.</param>
	/// <remarks>Deletes based on primary key(s).</remarks>
	/// <returns>Returns true if operation suceeded.</returns>
	public bool Delete(Account 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">AccountCollection containing data.</param>
	/// <remarks>Deletes Accounts only when IsDeleted equals true.</remarks>
	/// <returns>Returns the number of successful delete.</returns>
	public int Delete(AccountCollection 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">AccountCollection containing data.</param>
	/// <param name="connectionString">Connection string to datasource.</param>
	/// <remarks>Deletes Accounts only when IsDeleted equals true.</remarks>
	/// <returns>Returns the number of successful delete.</returns>
	public int Delete(string connectionString, AccountCollection entityCollection)
	{
		int number = 0;
		foreach (Account 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">AccountCollection containing data.</param>
	/// <remarks>Deletes Accounts only when IsDeleted equals true.</remarks>
	/// <returns>Returns the number of successful delete.</returns>
	public int Delete(TransactionManager transactionManager, AccountCollection entityCollection)
	{
		int number = 0;
		foreach (Account entity in entityCollection)
		{
			if ( Delete(transactionManager, entity) )
			{
				number++;
			}
		}
		return number;
	}
	
	
	/// <summary>
	/// 	Deletes a row from the DataSource.
	/// </summary>
	/// <param name="entity">Account 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, Account 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">Account 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, Account 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_Account_Delete", ID, ChangeStamp);
		else
			result = SqlHelper.ExecuteNonQuery(connectionString, "prc_Account_Delete", ID, ChangeStamp);
			
		Debug.WriteLine("AccountRepository.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 Account objects.</returns>
	public AccountCollection 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 Account objects.</returns>
	public AccountCollection 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 Account objects.</returns>
	public AccountCollection 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 Account objects.</returns>
	public AccountCollection 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 Account objects.</returns>
	public AccountCollection 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 Account objects.</returns>
	public AccountCollection 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 Account objects.</returns>
	protected AccountCollection GetAll(TransactionManager transactionManager, string connectionString, int start, int pagelen)
	{
		//Declare Varibles
		SqlDataReader reader;
		if (transactionManager != null)
			reader = SqlHelper.ExecuteReader(transactionManager.TransactionObject, "prc_Account_Get_List");
		else
			reader = SqlHelper.ExecuteReader(connectionString, "prc_Account_Get_List");
		//Create Collection
		AccountCollection rows = new AccountCollection();
		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 Account objects.</returns>
	public AccountCollection 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 Account objects.</returns>
	public AccountCollection 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 Account objects.</returns>
	public AccountCollection 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 Account objects.</returns>
	public AccountCollection 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 Account objects.</returns>
	public AccountCollection 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 Account objects.</returns>
	public AccountCollection 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 Account objects.</returns>
	protected AccountCollection 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_Account_GetPaged", whereClause, orderBy, start, pagelen);
		else
			reader = SqlHelper.ExecuteReader(connectionString, "prc_Account_GetPaged", whereClause, orderBy, start, pagelen);
		
		reader.Read();
		count = reader.GetInt32(0);
		reader.NextResult();

		//Create Collection
		AccountCollection rows = new AccountCollection();
		Fill(reader, rows, 0, int.MaxValue);
		reader.Close();
		return rows;
	}
	
	#endregion
	
	#region "Get By Foreign Key Functions"
	
	/// <summary>
	/// 	Gets rows from the datasource based on the FK_Account_Student key.
	///		FK_Account_Student Description: 
	/// </summary>
	/// <param name="StudentID"></param>
	/// <remarks></remarks>
	/// <returns>Returns a typed collection of Account objects.</returns>
	public AccountCollection GetByStudentID(System.Int32 StudentID)
	{
		if(UseTransaction())
		{
			return GetByStudentID(this.transactionManager, StudentID, 0, int.MaxValue);;
		}
		else
		{
			return GetByStudentID(this.connectionString, StudentID, 0, int.MaxValue);
		}
	}
	
	/// <summary>
	/// 	Gets rows from the datasource based on the FK_Account_Student key.
	///		FK_Account_Student Description: 
	/// </summary>
	/// <param name="start">Row number at which to start reading.</param>
	/// <param name="pagelen">Number of rows to return.</param>
	/// <param name="StudentID"></param>
	/// <remarks></remarks>
	/// <returns>Returns a typed collection of Account objects.</returns>
	public AccountCollection GetByStudentID(System.Int32 StudentID, int start, int pagelen)
	{
		if(UseTransaction())
		{
			return GetByStudentID(this.transactionManager, StudentID, start, pagelen);
		}
		else
		{
			return GetByStudentID(this.connectionString, StudentID, start, pagelen);
		}	
	}

	/// <summary>
	/// 	Gets rows from the datasource based on the FK_Account_Student key.
	///		FK_Account_Student Description: 
	/// </summary>
	/// <param name="StudentID"></param>
	/// <param name="connectionString">Connection string to datasource.</param>
	/// <remarks></remarks>
	/// <returns>Returns a typed collection of Account objects.</returns>
	public AccountCollection GetByStudentID(string connectionString, System.Int32 StudentID)
	{
		return GetByStudentID(null, connectionString, StudentID, 0,int.MaxValue);
	}
	
	
	/// <summary>
	/// 	Gets rows from the datasource based on the FK_Account_Student key.
	///		FK_Account_Student Description: 
	/// </summary>
	/// <param name="start">Row number at which to start reading.</param>
	/// <param name="pagelen">Number of rows to return.</param>
	/// <param name="StudentID"></param>
	/// <param name="connectionString">Connection string to datasource.</param>
	/// <remarks></remarks>
	/// <returns>Returns a typed collection of Account objects.</returns>
	public AccountCollection GetByStudentID(string connectionString, System.Int32 StudentID, int start, int pagelen)
	{
		return GetByStudentID(null, connectionString, StudentID, start, pagelen);
	}
	
	
	/// <summary>
	/// 	Gets rows from the datasource based on the FK_Account_Student key.
	///		FK_Account_Student Description: 
	/// </summary>
	/// <param name="StudentID"></param>
	/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
	/// <remarks></remarks>
	/// <returns>Returns a typed collection of Account objects.</returns>
	public AccountCollection GetByStudentID(TransactionManager transactionManager, System.Int32 StudentID)
	{
		if (transactionManager.IsOpen)
			return GetByStudentID(transactionManager, null, StudentID, 0,int.MaxValue);
		else
			return GetByStudentID(null, transactionManager.ConnectionString, StudentID, 0,int.MaxValue);
	}
	
	/// <summary>
	/// 	Gets rows from the datasource based on the FK_Account_Student key.
	///		FK_Account_Student Description: 
	/// </summary>
	/// <param name="start">Row number at which to start reading.</param>
	/// <param name="pagelen">Number of rows to return.</param>
	/// <param name="StudentID"></param>
	/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
	/// <remarks></remarks>
	/// <returns>Returns a typed collection of Account objects.</returns>
	public AccountCollection GetByStudentID(TransactionManager transactionManager, System.Int32 StudentID, int start, int pagelen)
	{
		if (transactionManager.IsOpen)
			return GetByStudentID(transactionManager, null, StudentID, start, pagelen);
		else
			return GetByStudentID(null, transactionManager.ConnectionString, StudentID, start, pagelen);
	}
	
	/// <summary>
	/// 	Gets rows from the datasource based on the FK_Account_Student key.
	///		FK_Account_Student Description: 
	/// </summary>
	/// <param name="start">Row number at which to start reading.</param>
	/// <param name="pagelen">Number of rows to return.</param>
	/// <param name="StudentID"></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 Account objects.</returns>
	protected AccountCollection GetByStudentID(TransactionManager transactionManager, string connectionString, System.Int32 StudentID, int start, int pagelen)
	{
		//Declare varibles
		SqlDataReader reader;
		if (transactionManager != null)
			reader = SqlHelper.ExecuteReader(transactionManager.TransactionObject, "prc_Account_GetByStudentID", StudentID);
		else
			reader = SqlHelper.ExecuteReader(connectionString, "prc_Account_GetByStudentID", StudentID);
		//Create Collection
		AccountCollection rows = new AccountCollection();
		Fill(reader, rows, start, pagelen);
		reader.Close();
		return rows;
	}
	
	#endregion
	
	#region "Get By Index Functions"

	
	/// <summary>
	/// 	Gets rows from the datasource based on the PK_Account index.
	/// </summary>
	/// <param name="ID"></param>
	/// <returns>Returns a typed collection of Account objects.</returns>
	public AccountCollection 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_Account 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 Account objects.</returns>
	public AccountCollection 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_Account index.
	/// </summary>
	/// <param name="ID"></param>
	/// <param name="connectionString">Connection string to datasource.</param>
	/// <remarks></remarks>
	/// <returns>Returns a typed collection of Account objects.</returns>
	public AccountCollection GetByID(string connectionString, System.Int32 ID)
	{
		return GetByID(null, connectionString, ID, 0, int.MaxValue);
	}
	
	
	/// <summary>
	/// 	Gets rows from the datasource based on the PK_Account 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 Account objects.</returns>
	public AccountCollection 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_Account index.
	/// </summary>
	/// <param name="ID"></param>
	/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
	/// <remarks></remarks>
	/// <returns>Returns a typed collection of Account objects.</returns>
	public AccountCollection 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_Account 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 Account objects.</returns>
	public AccountCollection 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_Account 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 Account objects.</returns>
	protected AccountCollection 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_Account_GetByID", ID);
		else
			reader = SqlHelper.ExecuteReader(connectionString, "prc_Account_GetByID", ID);
		//Create collection and fill
		AccountCollection rows = new AccountCollection();
		Fill(reader, rows, start, pagelen);
		reader.Close();
		return rows;
	}
	

	#endregion "Get By Index Functions"

	#region "Insert Functions"

	/// <summary>
	/// 	Inserts a Account object into the datasource.
	/// </summary>
	/// <param name="entity">Account object to insert.</param>
	/// <remarks>After inserting into the datasource, the Account 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(Account 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>Account</c> objects in a <c>AccountCollection</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>Account</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(AccountCollection 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>Account</c> objects in a <c>AccountCollection</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>Account</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, AccountCollection entityCollection)
	{
		int number = 0;
		foreach (Account 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>Account</c> objects in a <c>AccountCollection</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>Account</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, AccountCollection entityCollection)
	{
		int number = 0;
		foreach (Account entity in entityCollection)
		{
			if (entity.IsNew)
			{
				if (Insert(transactionManager, entity) )
				{
					number++;
				}
			}
		}
		return number;
	}
	
	/// <summary>
	/// 	Inserts a Account object into the datasource.
	/// </summary>
	/// <param name="connectionString">Connection string to datasource.</param>
	/// <param name="entity">Account object to insert.</param>
	/// <remarks>After inserting into the datasource, the Account 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, Account entity)
	{
		return Insert(null, connectionString, entity);
	}
	
	
	/// <summary>
	/// 	Inserts a Account object into the datasource using a transaction.
	/// </summary>
	/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
	/// <param name="entity">Account object to insert.</param>
	/// <remarks>After inserting into the datasource, the Account 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,  Account entity)
	{
		if (transactionManager.IsOpen)
			return Insert(transactionManager, null, entity);
		else
			return Insert(null, transactionManager.ConnectionString, entity);
	}
	
	
	/// <summary>
	/// 	Inserts a Account 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">Account object to insert.</param>
	/// <remarks>After inserting into the datasource, the Account 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, Account entity)
	{
		//Declare variables			
		//IDataParameterCollection parameters;
		SqlDataReader reader;
		int result = 0;
		//Get Parameters
		//if (transactionManager != null)
		//	parameters = SqlHelperParameterCache.GetSpParameterSet(transactionManager.ConnectionString, "prc_Account_Insert");
		//else
		//	parameters = SqlHelperParameterCache.GetSpParameterSet(connectionString, "prc_Account_Insert");
		//Assign values to parameters
		//AssignInsertParameters(parameters, entity);
		
		
		if (transactionManager != null)
			reader = SqlHelper.ExecuteReader(transactionManager.TransactionObject, "prc_Account_Insert", 
			entity.Balance,entity.BankName,entity.ChangeStamp,entity.CheckNumber,entity.CreditAmount,entity.DebitAmount,entity.ORNumber,entity.StudentID,entity.TransactionDate,entity.TransactionDescription,entity.Type);
		else
			reader = SqlHelper.ExecuteReader(connectionString, "prc_Account_Insert", 
			entity.Balance,entity.BankName,entity.ChangeStamp,entity.CheckNumber,entity.CreditAmount,entity.DebitAmount,entity.ORNumber,entity.StudentID,entity.TransactionDate,entity.TransactionDescription,entity.Type );
			
		Debug.WriteLine("AccountRepository-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 Account instance to the SqlParameter array.
	/// </summary>
	/// <param name="parameters">The <see cref="SqlParameter"/> array to fill.</param>
	/// <param name="entity">The <see cref="Account"/> instance to read from.</param>
	/* protected void AssignInsertParameters(IDataParameterCollection paramCollection, Account entity)
	{
		SqlParameter[] parameters = new SqlParameter[ paramCollection.Count ];
		paramCollection.CopyTo( parameters, 0 );
		
					parameters[0].Value = entity.Balance;
					parameters[1].Value = entity.BankName;
					parameters[2].Value = entity.ChangeStamp;
					parameters[3].Value = entity.CheckNumber;
					parameters[4].Value = entity.CreditAmount;
					parameters[5].Value = entity.DebitAmount;
					parameters[6].Value = entity.ORNumber;
					parameters[7].Value = entity.StudentID;
					parameters[8].Value = entity.TransactionDate;
					parameters[9].Value = entity.TransactionDescription;
					parameters[10].Value = entity.Type;
	} */
	
	#endregion

	#region "Update Functions"
	
	
	/// <summary>
	/// 	Update an existing row in the datasource.
	/// </summary>
	/// <param name="entity">The <see cref="Account"/> instance to update.</param>
	/// <remarks>After updating the datasource, the Account 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(Account 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>Account</c> objects in a <c>AccountCollection</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>Account</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(AccountCollection 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>Account</c> objects in a <c>AccountCollection</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>Account</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, AccountCollection entityCollection)
	{	
		int number = 0;
		foreach (Account 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>Account</c> objects in a <c>AccountCollection</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>Account</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, AccountCollection entityCollection)
	{
		int number = 0;
		foreach (Account 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">Account object to update.</param>
	/// <remarks>After updating the datasource, the Account 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, Account 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">Account object to update.</param>
	/// <remarks>After updating the datasource, the Account 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, Account 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">Account object to update.</param>
	/// <remarks>After updating the datasource, the Account 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, Account entity)
	{
		//Declare variables
		//IDataParameterCollection parameters;
		SqlDataReader reader;
		int result = 0;
		//Get Parameters
		//if (transactionManager != null)
		//	parameters = SqlHelperParameterCache.GetSpParameterSet(transactionManager.ConnectionString, "prc_Account_Update");
		//else
		//	parameters = SqlHelperParameterCache.GetSpParameterSet(connectionString, "prc_Account_Update");
		//Assign parameters values to corresponding entity values
		//AssignUpdateParameters(parameters, entity);
		
		
		//Get Reader
		if (transactionManager != null)
			reader = SqlHelper.ExecuteReader(transactionManager.TransactionObject, "prc_Account_Update",
				entity.ID,entity.Balance,entity.BankName,entity.ChangeStamp,entity.CheckNumber,entity.CreditAmount,entity.DebitAmount,entity.ORNumber,entity.StudentID,entity.TransactionDate,entity.TransactionDescription,entity.Type);
		else
			reader = SqlHelper.ExecuteReader(connectionString, "prc_Account_Update", 
				entity.ID,entity.Balance,entity.BankName,entity.ChangeStamp,entity.CheckNumber,entity.CreditAmount,entity.DebitAmount,entity.ORNumber,entity.StudentID,entity.TransactionDate,entity.TransactionDescription,entity.Type);
			
		Debug.WriteLine("AccountRepository-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;
			AccountCollection dsrecord;
			//Get record from Datasource
			if (transactionManager != null)
				dsrecord = AccountRepository.Current.GetByID(this.transactionManager, entity.ID);
			else
				dsrecord = AccountRepository.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="Account"/> instance to an <see cref="SqlParameter"/> array.
	/// </summary>
	/// <param name="parameters">The <see cref="SqlParameter"/> array.</param>
	/// <param name="entity">The <see cref="Account"/> instance.</param>
	//protected void AssignUpdateParameters(IDataParameterCollection paramCollection, Account entity)
	//{
	//}
	
	#endregion
	
	
	#region "Save Functions"
	
	/// <summary>
	/// 	Updates, Inserts rows in the datasource.
	/// </summary>
	/// <param name="entityCollection"><c>Account</c> objects in a <c>AccountCollection</c> object to update.</param>
	/// <remarks>
	/// 	After updating the datasource, the <c>Account</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(AccountCollection 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">Account object to update.</param>
	/// <remarks>
	/// 	After updating the datasource, the <c>Account</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, Account 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>Account</c> objects in a <c>AccountCollection</c> object to update.</param>
	/// <remarks>
	/// 	After updating the datasource, the <c>Account</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, AccountCollection entityCollection)
	{
		foreach (Account 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>Account</c> objects in a <c>AccountCollection</c> object to update.</param>
	/// <remarks>
	/// 	After updating the datasource, the <c>Account</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, Account 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>Account</c> objects in a <c>AccountCollection</c> object to update.</param>
	/// <remarks>
	/// 	After updating the datasource, the <c>Account</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, AccountCollection entityCollection)
	{
		foreach (Account entity in entityCollection)
		{
			Save(transactionManager, entity);
		}
	}
	#endregion
	

	#region "Helper Functions"

	///<summary>
	/// Fill an AccountCollection 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="AccountCollection"/> object.</returns>
	protected AccountCollection Fill(DataSet dataSet, AccountCollection 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;
			
				Account c = new Account();
				c.ID = (Convert.IsDBNull(row["ID"]))?(int)0:(System.Int32)row["ID"];
				c.StudentID = (Convert.IsDBNull(row["StudentID"]))?(int)0:(System.Int32)row["StudentID"];
				c.TransactionDescription = (Convert.IsDBNull(row["TransactionDescription"]))?string.Empty:(System.String)row["TransactionDescription"];
				c.TransactionDate = (Convert.IsDBNull(row["TransactionDate"]))?DateTime.MinValue:(System.DateTime)row["TransactionDate"];
				c.DebitAmount = (Convert.IsDBNull(row["DebitAmount"]))?0:(System.Decimal)row["DebitAmount"];
				c.CreditAmount = (Convert.IsDBNull(row["CreditAmount"]))?0:(System.Decimal)row["CreditAmount"];
				c.Balance = (Convert.IsDBNull(row["Balance"]))?0:(System.Decimal)row["Balance"];
				c.ChangeStamp = (Convert.IsDBNull(row["ChangeStamp"]))?DateTime.MinValue:(System.DateTime)row["ChangeStamp"];
				c.Type = (Convert.IsDBNull(row["Type"]))?(int)0:(System.Int32)row["Type"];
				c.BankName = (Convert.IsDBNull(row["BankName"]))?string.Empty:(System.String)row["BankName"];
				c.CheckNumber = (Convert.IsDBNull(row["CheckNumber"]))?string.Empty:(System.String)row["CheckNumber"];
				c.ORNumber = (Convert.IsDBNull(row["ORNumber"]))?string.Empty:(System.String)row["ORNumber"];
				rows.Add(c);
				pagelen -= 1;
			}
			recordnum += 1;
		}
		return rows;
	}

	
	///<summary>
	/// Fill an AccountCollection 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="AccountCollection"/></returns>
	protected AccountCollection Fill(SqlDataReader reader, AccountCollection rows, int start, int pagelen)
	{
		int recordnum = 0;
		while (reader.Read() && (pagelen != 0))
		{
			if(recordnum >= start)
			{
				Account c = new Account();
				c.ID = (Convert.IsDBNull(reader["ID"]))?(int)0:(System.Int32)reader["ID"];
				c.StudentID = (Convert.IsDBNull(reader["StudentID"]))?(int)0:(System.Int32)reader["StudentID"];
				c.TransactionDescription = (Convert.IsDBNull(reader["TransactionDescription"]))?string.Empty:(System.String)reader["TransactionDescription"];
				c.TransactionDate = (Convert.IsDBNull(reader["TransactionDate"]))?DateTime.MinValue:(System.DateTime)reader["TransactionDate"];
				c.DebitAmount = (Convert.IsDBNull(reader["DebitAmount"]))?0:(System.Decimal)reader["DebitAmount"];
				c.CreditAmount = (Convert.IsDBNull(reader["CreditAmount"]))?0:(System.Decimal)reader["CreditAmount"];
				c.Balance = (Convert.IsDBNull(reader["Balance"]))?0:(System.Decimal)reader["Balance"];
				c.ChangeStamp = (Convert.IsDBNull(reader["ChangeStamp"]))?DateTime.MinValue:(System.DateTime)reader["ChangeStamp"];
				c.Type = (Convert.IsDBNull(reader["Type"]))?(int)0:(System.Int32)reader["Type"];
				c.BankName = (Convert.IsDBNull(reader["BankName"]))?string.Empty:(System.String)reader["BankName"];
				c.CheckNumber = (Convert.IsDBNull(reader["CheckNumber"]))?string.Empty:(System.String)reader["CheckNumber"];
				c.ORNumber = (Convert.IsDBNull(reader["ORNumber"]))?string.Empty:(System.String)reader["ORNumber"];
				c.AcceptChanges();
				rows.Add(c);
				pagelen -= 1;
			}
			recordnum += 1;
		}
		return rows;
	}
	
	
	/// <summary>
	/// Refreshes the <see cref="Account"/> object from the <see cref="SqlDataReader"/>.
	/// </summary>
	/// <param name="reader">The <see cref="SqlDataReader"/> to read from.</param>
	/// <param name="entity">The <see cref="Account"/> object.</param>
	protected void RefreshEntity(SqlDataReader reader, Account entity)
	{
		reader.Read();
		entity.ID = (Convert.IsDBNull(reader["ID"]))?(int)0:(System.Int32)reader["ID"];
		entity.StudentID = (Convert.IsDBNull(reader["StudentID"]))?(int)0:(System.Int32)reader["StudentID"];
		entity.TransactionDescription = (Convert.IsDBNull(reader["TransactionDescription"]))?string.Empty:(System.String)reader["TransactionDescription"];
		entity.TransactionDate = (Convert.IsDBNull(reader["TransactionDate"]))?DateTime.MinValue:(System.DateTime)reader["TransactionDate"];
		entity.DebitAmount = (Convert.IsDBNull(reader["DebitAmount"]))?0:(System.Decimal)reader["DebitAmount"];
		entity.CreditAmount = (Convert.IsDBNull(reader["CreditAmount"]))?0:(System.Decimal)reader["CreditAmount"];
		entity.Balance = (Convert.IsDBNull(reader["Balance"]))?0:(System.Decimal)reader["Balance"];
		entity.ChangeStamp = (Convert.IsDBNull(reader["ChangeStamp"]))?DateTime.MinValue:(System.DateTime)reader["ChangeStamp"];
		entity.Type = (Convert.IsDBNull(reader["Type"]))?(int)0:(System.Int32)reader["Type"];
		entity.BankName = (Convert.IsDBNull(reader["BankName"]))?string.Empty:(System.String)reader["BankName"];
		entity.CheckNumber = (Convert.IsDBNull(reader["CheckNumber"]))?string.Empty:(System.String)reader["CheckNumber"];
		entity.ORNumber = (Convert.IsDBNull(reader["ORNumber"]))?string.Empty:(System.String)reader["ORNumber"];
		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

Share

About the Author

Omar Al Zabir
Architect BT, UK (ex British Telecom)
United Kingdom United Kingdom

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