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.

About Me
My Photo

Full Stack Developer,Blogger,Microsoft Mvp, Mentor, Life long learner, 10+ Years of Experience for JavaScript, web and Microsoft technologies. ASP.NET MVC,Web Forms,C#,AngularJs,Golang
Mvp profile
Subscribe to my blog

Enter your email address:

Follow us on facebook
Blog Archive
Total Pageviews