Thursday, July 12, 2007

C#.NET 2.0 class example for data acess layer using microsoft enterpise library

here is the data layer class example.....

///here is the enum


public enum OprationType
{
Add = 1,
Update = 2,
Delete = 3
}


//here is the Interfae
public interface IDataStatndard
{
void Operation(OperationType enumOperationType);
}



//here is the user data class
public class UserData : IDataStatndard
{
#region PrivateMemeber
private DashBoardCollection.UserCollection _objUserCol;
private Database _db;
private string _commandName;
private DbCommand _dbCommand;
#endregion
#region Constructors
public UserData()
{
}
public UserData(DashBoardCollection.UserCollection obj)
{
_objUserCol = obj;
}
#endregion
#region Methods
public void Operation(OpertaionType enumOperationType)
{
switch (enumOperationType)
{
case OperationType.Add:
this.Add();
break;
case OperationType.Update:
this.Update();
break;
case OperationType.Delete:
this.Delete();
break;
}
}
private void Add()
{
}
private void Update()
{
}
private void Delete()
{
}
public bool CheckUserLogin()
{
_db = DatabaseFactory.CreateDatabase("SopraConnect");
_commandName = "usp_CheckUserLogin";
_dbCommand = _db.GetStoredProcCommand(_commandName);
_db.AddInParameter(_dbCommand, "username", DbType.String, this._objUserCol.UserName);
_db.AddInParameter(_dbCommand, "password", DbType.String, this._objUserCol.Password);
_db.AddOutParameter(_dbCommand, "isvalid", DbType.Byte, 1);
_db.ExecuteNonQuery(_dbCommand);
Byte isValid = Convert.ToByte( _db.GetParameterValue(_dbCommand, "isvalid"));
if (isValid == 1)
return true;
else
return false;
}
#endregion
}
Share:

0 comments:

Post a Comment

Your feedback is very important to me. Please provide your feedback via putting comments.

Support this blog-Buy me a coffee

Buy me a coffeeBuy me a coffee
Search This Blog
Subscribe to my blog

  

My Mvp Profile
Follow us on facebook
Blog Archive
Total Pageviews