- Entity
using System;
using System.Collections.Generic;
using System.Text;
namespace TesoLibrary
{
public class Employee
{
private string _empId;
private string _name;
private string _role;
private string _roleApp;
private string _userName;
private string _password;
public string EmpId
{
get { return _empId; }
set { _empId = value; }
}
public string Name
{
get { return _name; }
set { _name = value; }
}
public string Role
{
get { return _role; }
set { _role = value; }
}
public string RoleApp
{
get { return _roleApp; }
set { _roleApp = value; }
}
public string UserName
{
get { return _userName; }
set { _userName = value; }
}
public string Password
{
get { return _password; }
set { _password = value; }
}
public Employee(string empId, string name, string role, string roleApp, string userName, string password)
{
this._empId = empId;
this._name = name;
this._role = role;
this._roleApp = roleApp;
this._userName = userName;
this._password = password;
}
public Employee()
{
this._empId = string.Empty;
this._name = string.Empty; ;
this._role = string.Empty; ;
this._roleApp = string.Empty; ;
this._userName = string.Empty; ;
this._password = string.Empty; ;
}
}
} - Data Access
using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlClient;
namespace TesoLibrary
{
public class EmployeeDataAccess: DataAccessAbstract
{
protected override SqlCommand GetInsertCommand(Employee item)
{
SqlCommand command = new SqlCommand();
command.CommandText = "insert into employee(empid, name, role, roleapp, username, password) values(" + "'" + item.EmpId + "','" + item.Name + "','" + item.Role + "','" + item.RoleApp + "','" + item.UserName + "','" + item.Password + "')";
return command;
}
protected override SqlCommand GetUpdateCommand(Employee item)
{
SqlCommand command = new SqlCommand();
command.CommandText = "update employee set name = '" + item.Name + "'" + ", role = '" + item.Role + "'" + ", roleapp = '" + item.RoleApp + "'" + ", username = '" + item.UserName + "'" + ", password = '" + item.Password + "'" + " where empid = '" + item.EmpId + "'";
return command;
}
protected override SqlCommand GetDeleteCommand(Employee item)
{
SqlCommand command = new SqlCommand();
command.CommandText = "delete from employee where empid = '" + item.EmpId + "'" ;
return command;
}
protected override SqlCommand GetObjectCommand(K criteria)
{
SqlCommand command = new SqlCommand();
command.CommandText = "select empid, name, role, roleapp, username, password from employee where empid = " + criteria;
return command;
}
protected override SqlCommand GetObjectsCommand()
{
SqlCommand command = new SqlCommand();
command.CommandText = "select empid, name, role, roleapp, username, password from employee";
return command;
}
protected override Employee MapObject(SqlDataReader reader)
{
Employee item = new Employee(reader["empid"].ToString(), reader["name"].ToString(), reader["role"].ToString(), reader["roleapp"].ToString(), reader["username"].ToString(), reader["password"].ToString());
return item;
}
}
} - Logic
using System;
using System.Collections.Generic;
using System.Text;
namespace TesoLibrary
{
public class EmployeeLogic
{
public EmployeeDataAccess _dataAccess = new EmployeeDataAccess();
public void Insert(Employee item)
{
this._dataAccess.Insert(item);
}
public void Update(Employee item)
{
this._dataAccess.Update(item);
}
public void Delete(Employee item)
{
this._dataAccess.Delete(item);
}
public Employee GetObject(string criteria)
{
return this._dataAccess.GetObject(criteria);
}
public ListGetObjects()
{
return this._dataAccess.GetObjects();
}
public Employee AuthenticateUser(string userName, string password)
{
string criteria = " where Username='" + userName + "' and Password='" + password + "'";
return this._dataAccess.GetSpecificObject(criteria);
}
}
}
Friday, July 11, 2008
Using MVC Concept in .NET
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment