CEL_Payroll/Payroll.Service/EmpRequisition/Service/EmployeeRequisitionService.cs
2024-09-17 14:30:13 +06:00

517 lines
18 KiB
C#

using System;
using Ease.CoreV35.Caching;
using Ease.CoreV35.DataAccess;
using Ease.CoreV35.Model;
using Payroll.BO;
using System.Data;
namespace Payroll.Service
{
#region EmployeeRequisition Service
[Serializable]
class EmployeeRequisitionService : ServiceTemplate, IEmployeeRequisitionService
{
#region Private functions and declaration
Cache _cache = new Cache(typeof(EmployeeRequisition));
#region base Object Functions
private void MapObject(EmployeeRequisition oEmployeeRequisition, DataReader oReader)
{
base.SetObjectID(oEmployeeRequisition, oReader.GetID("EmpRequisitionID"));
oEmployeeRequisition.DepartmentID = oReader.GetID("DepartmentID");
oEmployeeRequisition.RequisitionDate = oReader.GetDateTime("RequisitionDate").Value;
oEmployeeRequisition.Position = oReader.GetString("Position");
oEmployeeRequisition.GradeID = oReader.GetID("GradeID");
oEmployeeRequisition.MaxEmployee = oReader.GetDecimal("MaxEmployee").Value;
oEmployeeRequisition.BasicPay = oReader.GetString("BasicPay");
oEmployeeRequisition.JobDescription = oReader.GetString("JobDescription");
oEmployeeRequisition.Justification = oReader.GetString("Justification");
oEmployeeRequisition.Academic = oReader.GetString("Academic");
oEmployeeRequisition.Technical = oReader.GetString("Technical");
oEmployeeRequisition.Age = oReader.GetString("Age");
oEmployeeRequisition.Experience = oReader.GetString("Experience");
oEmployeeRequisition.Gender = (EnumGender)oReader.GetInt32("Gender");
oEmployeeRequisition.Areas = oReader.GetString("Areas");
oEmployeeRequisition.OtherRequirements = oReader.GetString("OtherRequirements");
oEmployeeRequisition.Status = (EnumEmpReqStatus)oReader.GetInt32("Status");
oEmployeeRequisition.IsCompleted = oReader.GetBoolean("IsCompleted").Value;
oEmployeeRequisition.IsHeadCount = oReader.GetBoolean("IsHeadCount").Value;
oEmployeeRequisition.CreatedBy = oReader.GetID("CreatedBy");
oEmployeeRequisition.CreatedDate = oReader.GetDateTime("CreationDate").Value;
this.SetObjectState(oEmployeeRequisition, Ease.CoreV35.ObjectState.Saved);
}
protected override T CreateObject<T>(DataReader oReader)
{
EmployeeRequisition oEmployeeRequisition = new EmployeeRequisition();
MapObject(oEmployeeRequisition, oReader);
return oEmployeeRequisition as T;
}
#endregion
#region Child Object Functions
private void MapObject(RequisitionUser oRequisitionUser, DataReader oReader)
{
base.SetObjectID(oRequisitionUser, oReader.GetID("RequisitionUserID"));
oRequisitionUser.EmpRequisitionID = oReader.GetID("EmpRequisitionID");
oRequisitionUser.EmployeeID = oReader.GetID("EmployeeID");
oRequisitionUser.Status = (EnumEmpReqStatus)oReader.GetInt32("ProposedByID");
oRequisitionUser.ChangeDate = oReader.GetDateTime("ChangeDate").GetValueOrDefault();
oRequisitionUser.ChangeString = oReader.GetString("ChangeString");
oRequisitionUser.Remarks = oReader.GetString("Remarks");
this.SetObjectState(oRequisitionUser, Ease.CoreV35.ObjectState.Saved);
}
private RequisitionUser CreateChildObject(DataReader oReader)
{
RequisitionUser oRequisitionUser = new RequisitionUser();
MapObject(oRequisitionUser, oReader);
return oRequisitionUser;
}
private ObjectsTemplate<RequisitionUser> CreateChildObjects(DataReader oReader)
{
ObjectsTemplate<RequisitionUser> requisitionUsers = new ObjectsTemplate<RequisitionUser>();
while (oReader.Read())
{
RequisitionUser oRequisitionUser = new RequisitionUser();
oRequisitionUser = CreateChildObject(oReader);
requisitionUsers.Add(oRequisitionUser);
}
return requisitionUsers;
}
#endregion
#endregion
#region IEmployeeRequisitionService Members
public EmployeeRequisition Get(int empReqID)
{
EmployeeRequisition oEmployeeRequisition = null;
#region CacheHeader
oEmployeeRequisition = (EmployeeRequisition)_cache["Get", empReqID];
if (oEmployeeRequisition != null)
return oEmployeeRequisition;
#endregion
TransactionContext tc = null;
try
{
#region Retrieving data
tc = TransactionContext.Begin();
DataReader oreader = new DataReader(EmployeeRequisitionDA.Get(tc, empReqID));
if (oreader.Read())
{
oEmployeeRequisition = CreateObject<EmployeeRequisition>(oreader);
}
tc.End();
#endregion
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
throw new ServiceException(e.Message, e);
#endregion
}
#region CacheFooter
_cache.Add(oEmployeeRequisition, "Get", empReqID);
#endregion
return oEmployeeRequisition;
}
public ObjectsTemplate<EmployeeRequisition> Get()
{
ObjectsTemplate<EmployeeRequisition> oEmployeeRequisitions = null;
#region CacheHeader
oEmployeeRequisitions = (ObjectsTemplate<EmployeeRequisition>)_cache["Get"];
if (oEmployeeRequisitions != null)
return oEmployeeRequisitions;
#endregion
TransactionContext tc = null;
try
{
#region Retrieving data
tc = TransactionContext.Begin();
DataReader oreader = new DataReader(EmployeeRequisitionDA.Get(tc));
oEmployeeRequisitions = CreateObjects<EmployeeRequisition>(oreader);
tc.End();
#endregion
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
throw new ServiceException(e.Message, e);
#endregion
}
#region CacheFooter
_cache.Add(oEmployeeRequisitions, "Get");
#endregion
return oEmployeeRequisitions;
}
public ObjectsTemplate<EmployeeRequisition> GetByDepartment(int departmentID)
{
ObjectsTemplate<EmployeeRequisition> oEmployeeRequisitions = null;
#region CacheHeader
oEmployeeRequisitions = (ObjectsTemplate<EmployeeRequisition>)_cache["GetByDepartment", departmentID];
if (oEmployeeRequisitions != null)
return oEmployeeRequisitions;
#endregion
TransactionContext tc = null;
try
{
#region Retrieving data
tc = TransactionContext.Begin();
DataReader oreader = new DataReader(EmployeeRequisitionDA.GetByDepartmentID(tc, departmentID));
oEmployeeRequisitions = CreateObjects<EmployeeRequisition>(oreader);
tc.End();
#endregion
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
throw new ServiceException(e.Message, e);
#endregion
}
#region CacheFooter
_cache.Add(oEmployeeRequisitions, "GetByDepartment", departmentID);
#endregion
return oEmployeeRequisitions;
}
public ObjectsTemplate<RequisitionUser> GetRequisitionUserByEmpRequisitionID(int reqID)
{
ObjectsTemplate<RequisitionUser> requisitionUsers = null;
#region CacheHeader
requisitionUsers = (ObjectsTemplate<RequisitionUser>)_cache["GetRequisitionUserByEmpRequisitionID", reqID];
if (requisitionUsers != null)
return requisitionUsers;
#endregion
TransactionContext tc = null;
try
{
#region Retrieving data
tc = TransactionContext.Begin();
DataReader oreader = new DataReader(EmployeeRequisitionDA.GetRequisitionUserByReqID(tc, reqID));
requisitionUsers = CreateChildObjects(oreader);
tc.End();
#endregion
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
throw new ServiceException(e.Message, e);
#endregion
}
#region CacheFooter
_cache.Add(requisitionUsers, "GetRequisitionUserByEmpRequisitionID", reqID);
#endregion
return requisitionUsers;
}
public DataTable GetEmployeeRequisitionsByDepartmentID(ID departmentID, EnumEmpReqStatus reqStatus)
{
DataSet employeeRequisitionDS = new DataSet();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
employeeRequisitionDS = EmployeeRequisitionDA.GetEmployeeRequisitionsByDepartmentID(tc, departmentID.Integer,reqStatus);
tc.End();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
return employeeRequisitionDS.Tables[0];
}
public DataTable GetEmployeeRequisitionsForCEO()
{
DataSet employeeRequisitionDS = new DataSet();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
employeeRequisitionDS = EmployeeRequisitionDA.GetEmployeeRequisitionsForCEO(tc);
tc.End();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
return employeeRequisitionDS.Tables[0];
}
public void RequisitionDeclinedByCEO(EmployeeRequisition employeeRequisition)
{
DataSet employeeRequisitionDS = new DataSet();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
EmployeeRequisitionDA.RequisitionDeclinedByCEO(tc,employeeRequisition);
tc.End();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
}
public DataTable GetEmployeeRequisitionsForHR()
{
DataSet employeeRequisitionDS = new DataSet();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
employeeRequisitionDS = EmployeeRequisitionDA.GetEmployeeRequisitionsForHR(tc);
tc.End();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
return employeeRequisitionDS.Tables[0];
}
public void RequisitionDeclinedByHR(EmployeeRequisition employeeRequisition)
{
DataSet employeeRequisitionDS = new DataSet();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
EmployeeRequisitionDA.RequisitionDeclinedByHR(tc,employeeRequisition);
tc.End();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
}
public ID Save(EmployeeRequisition oEmployeeRequisition)
{
try
{
TransactionContext tc = null;
try
{
#region Saving data
tc = TransactionContext.Begin(true);
if (oEmployeeRequisition.IsNew)
{
int newID = tc.GenerateID("EmployeeRequisition", "EmpRequisitionID");
base.SetObjectID(oEmployeeRequisition, ID.FromInteger(newID));
EmployeeRequisitionDA.Insert(tc, oEmployeeRequisition);
}
else
{
EmployeeRequisitionDA.Update(tc, oEmployeeRequisition);
// At present No RequisitionUsers needs updating so we'll only add new RequisitionUser
// EmployeeRequisitionDA.DeleteRequisitionUsers(tc, oEmployeeRequisition.ID.Integer);
}
foreach (RequisitionUser oReqUser in oEmployeeRequisition.RequisitionUsers)
{
oReqUser.EmpRequisitionID = oEmployeeRequisition.ID;
base.SetObjectID(oReqUser, ID.FromInteger(tc.GenerateID("RequisitionUser", "RequisitionUserID")));
EmployeeRequisitionDA.InsertRequisitionUser(tc, oReqUser);
}
tc.End();
#endregion
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
throw new ServiceException(e.Message, e);
#endregion
}
}
catch (Exception e)
{
throw new Exception(e.Message, e);
}
return oEmployeeRequisition.ID;
}
public void Delete(int ID)
{
try
{
TransactionContext tc = null;
try
{
#region Deleting data
tc = TransactionContext.Begin(true);
EmployeeRequisitionDA.DeleteRequisitionUsers(tc, ID);
EmployeeRequisitionDA.Delete(tc, ID);
tc.End();
#endregion
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
throw new ServiceException(e.Message, e);
#endregion
}
}
catch (Exception e)
{
throw new Exception(e.Message, e);
}
}
public void ChangeStatus(EmployeeRequisition employeeRequisition, int empID, EnumEmpReqStatus enumEmpReqStatus)
{
try
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
EmployeeRequisitionDA.ChangeStatus(tc,employeeRequisition.ID.Integer,enumEmpReqStatus);
RequisitionUser oReqUser = new RequisitionUser()
{
EmpRequisitionID = ID.FromInteger(employeeRequisition.ID.Integer),
EmployeeID = ID.FromInteger(empID),
Status = enumEmpReqStatus,
ChangeDate = DateTime.Now,
ChangeString = "Status Changed",
Remarks = string.Empty
};
base.SetObjectID(oReqUser, ID.FromInteger(tc.GenerateID("RequisitionUser", "RequisitionUserID")));
EmployeeRequisitionDA.InsertRequisitionUser(tc, oReqUser);
tc.End();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
throw new ServiceException(e.Message, e);
#endregion
}
}
catch (Exception e)
{
throw new Exception(e.Message, e);
}
}
#endregion
}
#endregion
}