using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
namespace DALBlueWhale.Entities
{
public class Employee
{
DBWrapper _db;
DataTable _table;
private string cmdStr = "";
public int EmpID { get; set; }
public string Name { get; set; }
public string Address { get; set; }
public string Contact { get; set; }
public string Email { get; set; }
public int DeptID { get; set; }
public string Departments { get; set; }
public int DesgID { get; set; }
public string Designation { get; set; }
public DataTable GetAllEmployees()
{
try
{
cmdStr = @"SELECT tblEmployee.EMPID, tblEmployee.Name, tblEmployee.Address, tblEmployee.Email, tblEmployee.DeptID,
tblDepartment.Departments, tblEmployee.DesgID, tblDesignations.Designation
FROM tblDepartment INNER JOIN
tblEmployee ON tblDepartment.DeptID = tblEmployee.DeptID INNER JOIN
tblDesignations ON tblEmployee.DesgID = tblDesignations.DesgID ";
_db = new DBWrapper();
_table = _db.GetDataSet(cmdStr).Tables[0];
}
catch
{
throw;
}
return _table;
}
public Employee GetEmployee(int empid)
{
try
{
cmdStr = @"SELECT tblEmployee.EMPID, tblEmployee.Name, tblEmployee.Address, tblEmployee.Email, tblEmployee.DeptID,
tblDepartment.Departments, tblEmployee.DesgID, tblDesignations.Designation
FROM tblDepartment INNER JOIN
tblEmployee ON tblDepartment.DeptID = tblEmployee.DeptID INNER JOIN
tblDesignations ON tblEmployee.DesgID = tblDesignations.DesgID
WHERE tblEmployee.EmpID =" + empid;
_db = new DBWrapper();
_table = _db.GetDataSet(cmdStr).Tables[0];
EmpID = int.Parse(_table.Rows[0]["EmpID"].ToString());
Name = _table.Rows[0]["Name"].ToString();
Address = _table.Rows[0]["Address"].ToString();
//Contact = _table.Rows[0]["Contact"].ToString();
Email = _table.Rows[0]["Email"].ToString();
DeptID = int.Parse(_table.Rows[0]["DeptID"].ToString());
Departments = _table.Rows[0]["Departments"].ToString();
DesgID = int.Parse(_table.Rows[0]["DesgID"].ToString());
Designation = _table.Rows[0]["Designation"].ToString();
}
catch
{
throw;
}
return this;
}
public int Insert()
{
int noRowsRet = 0;
try
{
cmdStr = @"INSERT INTO [tblEmployee]
([Name]
,[Address]
,[Email]
,[DeptID]
,[DesgID])
VALUES
('" + Name + "', '" +
Address + "', '" +
Email + "', " +
DeptID + ", " +
DesgID + ")";
_db = new DBWrapper();
noRowsRet = _db.ExicuteQuery(cmdStr);
}
catch
{
throw;
}
return noRowsRet;
}
public int Update()
{
int noRowsRet = 0;
try
{
cmdStr = @"UPDATE [tblEmployee]
SET [Name] = '{0}'
,[Address] = '{1}'
,[Email] = '{2}'
,[DeptID] = {3}
,[DesgID] = {4}
WHERE EmpID= " + EmpID;
cmdStr = string.Format(cmdStr, Name, Address, Email, DeptID, DesgID);
_db = new DBWrapper();
noRowsRet = _db.ExicuteQuery(cmdStr);
}
catch
{
throw;
}
return noRowsRet;
}
public int Delete()
{
int noRowsRet = 0;
try
{
cmdStr = @"Delete from tblEmployee where EmpID = " + EmpID;
_db = new DBWrapper();
noRowsRet = _db.ExicuteQuery(cmdStr);
}
catch
{
throw;
}
return noRowsRet;
}
}
}
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
namespace DALBlueWhale.Entities
{
public class Employee
{
DBWrapper _db;
DataTable _table;
private string cmdStr = "";
public int EmpID { get; set; }
public string Name { get; set; }
public string Address { get; set; }
public string Contact { get; set; }
public string Email { get; set; }
public int DeptID { get; set; }
public string Departments { get; set; }
public int DesgID { get; set; }
public string Designation { get; set; }
public DataTable GetAllEmployees()
{
try
{
cmdStr = @"SELECT tblEmployee.EMPID, tblEmployee.Name, tblEmployee.Address, tblEmployee.Email, tblEmployee.DeptID,
tblDepartment.Departments, tblEmployee.DesgID, tblDesignations.Designation
FROM tblDepartment INNER JOIN
tblEmployee ON tblDepartment.DeptID = tblEmployee.DeptID INNER JOIN
tblDesignations ON tblEmployee.DesgID = tblDesignations.DesgID ";
_db = new DBWrapper();
_table = _db.GetDataSet(cmdStr).Tables[0];
}
catch
{
throw;
}
return _table;
}
public Employee GetEmployee(int empid)
{
try
{
cmdStr = @"SELECT tblEmployee.EMPID, tblEmployee.Name, tblEmployee.Address, tblEmployee.Email, tblEmployee.DeptID,
tblDepartment.Departments, tblEmployee.DesgID, tblDesignations.Designation
FROM tblDepartment INNER JOIN
tblEmployee ON tblDepartment.DeptID = tblEmployee.DeptID INNER JOIN
tblDesignations ON tblEmployee.DesgID = tblDesignations.DesgID
WHERE tblEmployee.EmpID =" + empid;
_db = new DBWrapper();
_table = _db.GetDataSet(cmdStr).Tables[0];
EmpID = int.Parse(_table.Rows[0]["EmpID"].ToString());
Name = _table.Rows[0]["Name"].ToString();
Address = _table.Rows[0]["Address"].ToString();
//Contact = _table.Rows[0]["Contact"].ToString();
Email = _table.Rows[0]["Email"].ToString();
DeptID = int.Parse(_table.Rows[0]["DeptID"].ToString());
Departments = _table.Rows[0]["Departments"].ToString();
DesgID = int.Parse(_table.Rows[0]["DesgID"].ToString());
Designation = _table.Rows[0]["Designation"].ToString();
}
catch
{
throw;
}
return this;
}
public int Insert()
{
int noRowsRet = 0;
try
{
cmdStr = @"INSERT INTO [tblEmployee]
([Name]
,[Address]
,[Email]
,[DeptID]
,[DesgID])
VALUES
('" + Name + "', '" +
Address + "', '" +
Email + "', " +
DeptID + ", " +
DesgID + ")";
_db = new DBWrapper();
noRowsRet = _db.ExicuteQuery(cmdStr);
}
catch
{
throw;
}
return noRowsRet;
}
public int Update()
{
int noRowsRet = 0;
try
{
cmdStr = @"UPDATE [tblEmployee]
SET [Name] = '{0}'
,[Address] = '{1}'
,[Email] = '{2}'
,[DeptID] = {3}
,[DesgID] = {4}
WHERE EmpID= " + EmpID;
cmdStr = string.Format(cmdStr, Name, Address, Email, DeptID, DesgID);
_db = new DBWrapper();
noRowsRet = _db.ExicuteQuery(cmdStr);
}
catch
{
throw;
}
return noRowsRet;
}
public int Delete()
{
int noRowsRet = 0;
try
{
cmdStr = @"Delete from tblEmployee where EmpID = " + EmpID;
_db = new DBWrapper();
noRowsRet = _db.ExicuteQuery(cmdStr);
}
catch
{
throw;
}
return noRowsRet;
}
}
}
0 comments:
Post a Comment