CEL_Payroll/Payroll.Service/SearchReport/Service/SearchEmployeeService.cs

83 lines
2.8 KiB
C#
Raw Permalink Normal View History

2024-09-17 14:30:13 +06:00
using System;
using System.Data;
using System.Linq;
using Ease.CoreV35;
using Ease.CoreV35.Model;
using Ease.CoreV35.DataAccess;
using System.Collections.Generic;
using Payroll.BO;
using Ease.CoreV35.Caching;
namespace Payroll.Service
{
#region SearchEmployee Service
[Serializable]
public class SearchEmployeeService : ServiceTemplate, ISearchEmployeeService
{
#region Private functions and declaration
Cache _cache = new Cache(typeof(SearchEmployee));
private int _serial;
#endregion
public SearchEmployeeService() { _serial = 0; }
private void MapObject(SearchEmployee oSearchEmployee, DataReader oReader)
{
_serial = _serial +1;
base.SetObjectID(oSearchEmployee, ID.FromInteger(_serial));
oSearchEmployee.EmployeeID = oReader.GetID("employeeID");
oSearchEmployee.Name = oReader.GetString("name");
oSearchEmployee.EmployeeNo = oReader.GetString("employeeNo");
oSearchEmployee.LocationID = oReader.GetID("locationID");
oSearchEmployee.CategoryID = oReader.GetID("categoryID");
oSearchEmployee.DepartmentID = oReader.GetID("departmentID");
oSearchEmployee.GradeID = oReader.GetID("gradeID");
oSearchEmployee.Email = oReader.GetString("emailaddress");
this.SetObjectState(oSearchEmployee, Ease.CoreV35.ObjectState.Saved);
}
protected override T CreateObject<T>(DataReader oReader)
{
SearchEmployee oSearchEmployee = new SearchEmployee();
MapObject(oSearchEmployee, oReader);
return oSearchEmployee as T;
}
protected SearchEmployee CreateObject(DataReader oReader)
{
SearchEmployee oSearchEmployee = new SearchEmployee();
MapObject(oSearchEmployee, oReader);
return oSearchEmployee;
}
#region Service implementation
public ObjectsTemplate<SearchEmployee> Search(string sql)
{
ObjectsTemplate<SearchEmployee> searchEmployees = null;
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(SearchEmployeeDA.Search(tc, sql));
searchEmployees = this.CreateObjects<SearchEmployee>(dr);
dr.Close();
tc.End();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
return searchEmployees;
}
#endregion
}
#endregion
}