353 lines
11 KiB
C#
353 lines
11 KiB
C#
|
using Ease.Core.DataAccess;
|
|||
|
using Ease.Core.Model;
|
|||
|
using Ease.Core.Utility;
|
|||
|
using System;
|
|||
|
using System.Collections.Generic;
|
|||
|
using System.Data;
|
|||
|
using System.Linq;
|
|||
|
using HRM.BO;
|
|||
|
|
|||
|
namespace HRM.DA
|
|||
|
{
|
|||
|
public class EmployeePostingService : ServiceTemplate, IEmployeePostingService
|
|||
|
{
|
|||
|
public EmployeePostingService()
|
|||
|
{
|
|||
|
}
|
|||
|
|
|||
|
private void MapObject(EmployeePosting oEmployeePosting, DataReader oReader)
|
|||
|
{
|
|||
|
base.SetObjectID(oEmployeePosting, oReader.GetInt32("HREmpPostingID").Value);
|
|||
|
oEmployeePosting.EmployeeID = oReader.GetInt32("EmployeeID", 0);
|
|||
|
oEmployeePosting.EffectDate = oReader.GetDateTime("postingDate").Value;
|
|||
|
oEmployeePosting.DepartmentID = oReader.GetInt32("departmentID", 0);
|
|||
|
oEmployeePosting.LocationID = oReader.GetInt32("locationID", 0);
|
|||
|
oEmployeePosting.DesignationID = oReader.GetInt32("designationID", 0);
|
|||
|
oEmployeePosting.CreatedBy = oReader.GetInt32("CreatedBy", 0);
|
|||
|
oEmployeePosting.CreatedDate = oReader.GetDateTime("CreationDate").Value;
|
|||
|
oEmployeePosting.ModifiedBy = oReader.GetInt32("ModifiedBy", 0);
|
|||
|
oEmployeePosting.ModifiedDate = oReader.GetDateTime("ModifiedDate");
|
|||
|
this.SetObjectState(oEmployeePosting, Ease.Core.ObjectState.Saved);
|
|||
|
}
|
|||
|
|
|||
|
protected override T CreateObject<T>(DataReader oReader)
|
|||
|
{
|
|||
|
EmployeePosting oEmployeePosting = new EmployeePosting();
|
|||
|
MapObject(oEmployeePosting, oReader);
|
|||
|
return oEmployeePosting as T;
|
|||
|
}
|
|||
|
|
|||
|
#region Service implementation
|
|||
|
|
|||
|
public EmployeePosting GetRelatedData(EmployeePosting oEmployeePosting, TransactionContext tc)
|
|||
|
{
|
|||
|
//oEmployeePosting.Employee = (new EmployeeService()).Get(tc, oEmployeePosting.EmployeeID);
|
|||
|
//oEmployeePosting.Department = (new DepartmentService()).Get(tc, oEmployeePosting.DepartmentID);
|
|||
|
//oEmployeePosting.Designation = (new DesignationService()).Get(tc, oEmployeePosting.DesignationID, SystemInformation.CurrentSysInfo.PayrollTypeID);
|
|||
|
return oEmployeePosting;
|
|||
|
}
|
|||
|
|
|||
|
public EmployeePosting Get(int id)
|
|||
|
{
|
|||
|
EmployeePosting oEmployeePosting = null;
|
|||
|
|
|||
|
TransactionContext tc = null;
|
|||
|
try
|
|||
|
{
|
|||
|
tc = TransactionContext.Begin();
|
|||
|
DataReader oreader = new DataReader(EmployeePostingDA.Get(tc, id));
|
|||
|
if (oreader.Read())
|
|||
|
{
|
|||
|
oEmployeePosting = this.CreateObject<EmployeePosting>(oreader);
|
|||
|
oEmployeePosting = GetRelatedData(oEmployeePosting, tc);
|
|||
|
}
|
|||
|
|
|||
|
oreader.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 oEmployeePosting;
|
|||
|
}
|
|||
|
|
|||
|
public EmployeePosting Get(int nEmpID, DateTime dEffectDate, int payrollTypeID)
|
|||
|
{
|
|||
|
EmployeePosting oEmployeePosting = null;
|
|||
|
|
|||
|
TransactionContext tc = null;
|
|||
|
try
|
|||
|
{
|
|||
|
tc = TransactionContext.Begin();
|
|||
|
DataReader oreader = new DataReader(EmployeePostingDA.Get(tc, nEmpID, dEffectDate, payrollTypeID));
|
|||
|
if (oreader.Read())
|
|||
|
{
|
|||
|
oEmployeePosting = this.CreateObject<EmployeePosting>(oreader);
|
|||
|
oEmployeePosting = GetRelatedData(oEmployeePosting, tc);
|
|||
|
}
|
|||
|
|
|||
|
oreader.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 oEmployeePosting;
|
|||
|
}
|
|||
|
|
|||
|
public List<EmployeePosting> GetByEmpID(int nID)
|
|||
|
{
|
|||
|
List<EmployeePosting> employeePostings = new List<EmployeePosting>();
|
|||
|
|
|||
|
TransactionContext tc = null;
|
|||
|
try
|
|||
|
{
|
|||
|
tc = TransactionContext.Begin();
|
|||
|
DataReader dr = new DataReader(EmployeePostingDA.GetEmpid(tc, nID));
|
|||
|
employeePostings = this.CreateObjects<EmployeePosting>(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 employeePostings;
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
public List<EmployeePosting> Get()
|
|||
|
{
|
|||
|
List<EmployeePosting> employeePostings = new List<EmployeePosting>();
|
|||
|
|
|||
|
TransactionContext tc = null;
|
|||
|
try
|
|||
|
{
|
|||
|
tc = TransactionContext.Begin();
|
|||
|
DataReader dr = new DataReader(EmployeePostingDA.Get(tc));
|
|||
|
employeePostings = this.CreateObjects<EmployeePosting>(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 employeePostings;
|
|||
|
}
|
|||
|
|
|||
|
public int Save(EmployeePosting oEmployeePosting)
|
|||
|
{
|
|||
|
TransactionContext tc = null;
|
|||
|
try
|
|||
|
{
|
|||
|
tc = TransactionContext.Begin(true);
|
|||
|
if (oEmployeePosting.IsNew)
|
|||
|
{
|
|||
|
int id = tc.GenerateID("employeeposting", "hremppostingid");
|
|||
|
base.SetObjectID(oEmployeePosting, id);
|
|||
|
EmployeePostingDA.DeleteByPostingDate(tc, oEmployeePosting.EffectDate, oEmployeePosting.EmployeeID);
|
|||
|
EmployeePostingDA.Insert(tc, oEmployeePosting);
|
|||
|
EmployeeDA.UpdateEmpPosting(tc, oEmployeePosting);
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
EmployeePostingDA.Update(tc, oEmployeePosting);
|
|||
|
EmployeeDA.UpdateEmpPosting(tc, oEmployeePosting);
|
|||
|
}
|
|||
|
|
|||
|
tc.End();
|
|||
|
|
|||
|
return oEmployeePosting.ID;
|
|||
|
}
|
|||
|
catch (Exception e)
|
|||
|
{
|
|||
|
#region Handle Exception
|
|||
|
|
|||
|
if (tc != null)
|
|||
|
tc.HandleError();
|
|||
|
ExceptionLog.Write(e);
|
|||
|
throw new ServiceException(e.Message, e);
|
|||
|
|
|||
|
#endregion
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
public void Delete(int id)
|
|||
|
{
|
|||
|
TransactionContext tc = null;
|
|||
|
try
|
|||
|
{
|
|||
|
EmployeePostingService osvr = new EmployeePostingService();
|
|||
|
EmployeePosting oposing = osvr.Get(id);
|
|||
|
tc = TransactionContext.Begin(true);
|
|||
|
|
|||
|
EmployeePostingDA.Delete(tc, id);
|
|||
|
List<EmployeePosting> employeePostings = this.GetByEmpID(tc, oposing.EmployeeID);
|
|||
|
if (employeePostings == null || employeePostings.Count == 0)
|
|||
|
{
|
|||
|
EmployeePosting oEmployeePosting = new EmployeePosting();
|
|||
|
oEmployeePosting.DepartmentID = 0;
|
|||
|
oEmployeePosting.DesignationID = 0;
|
|||
|
oEmployeePosting.LocationID = 0;
|
|||
|
oEmployeePosting.EmployeeID = oposing.EmployeeID;
|
|||
|
EmployeeDA.UpdateEmpPosting(tc, oEmployeePosting);
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
EmployeeDA.UpdateEmpPosting(tc, employeePostings[0]);
|
|||
|
}
|
|||
|
|
|||
|
tc.End();
|
|||
|
}
|
|||
|
catch (Exception e)
|
|||
|
{
|
|||
|
#region Handle Exception
|
|||
|
|
|||
|
if (tc != null)
|
|||
|
tc.HandleError();
|
|||
|
ExceptionLog.Write(e);
|
|||
|
throw new ServiceException(e.Message, e);
|
|||
|
|
|||
|
#endregion
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
public List<EmployeePosting> GetByEmpID(TransactionContext tc, int nID)
|
|||
|
{
|
|||
|
List<EmployeePosting> employeePostings = new List<EmployeePosting>();
|
|||
|
try
|
|||
|
{
|
|||
|
DataReader dr = new DataReader(EmployeePostingDA.GetEmpid(tc, nID));
|
|||
|
employeePostings = this.CreateObjects<EmployeePosting>(dr);
|
|||
|
dr.Close();
|
|||
|
}
|
|||
|
catch (Exception e)
|
|||
|
{
|
|||
|
#region Handle Exception
|
|||
|
|
|||
|
if (tc != null)
|
|||
|
tc.HandleError();
|
|||
|
ExceptionLog.Write(e);
|
|||
|
|
|||
|
throw new ServiceException(e.Message, e);
|
|||
|
|
|||
|
#endregion
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
return employeePostings;
|
|||
|
}
|
|||
|
|
|||
|
public void DeleteAll()
|
|||
|
{
|
|||
|
TransactionContext tc = null;
|
|||
|
try
|
|||
|
{
|
|||
|
tc = TransactionContext.Begin(true);
|
|||
|
EmployeePostingDA.DeleteAll(tc);
|
|||
|
tc.End();
|
|||
|
}
|
|||
|
catch (Exception e)
|
|||
|
{
|
|||
|
#region Handle Exception
|
|||
|
|
|||
|
if (tc != null)
|
|||
|
tc.HandleError();
|
|||
|
ExceptionLog.Write(e);
|
|||
|
throw new ServiceException(e.Message, e);
|
|||
|
|
|||
|
#endregion
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
public DataSet GetEmpCurrentPosting(DateTime EffectDate, int payrollTypeID)
|
|||
|
{
|
|||
|
DataSet oEmpPosting = new DataSet();
|
|||
|
TransactionContext tc = null;
|
|||
|
try
|
|||
|
{
|
|||
|
tc = TransactionContext.Begin();
|
|||
|
oEmpPosting = EmployeePostingDA.GetEmpCurrentPosting(tc, EffectDate, payrollTypeID);
|
|||
|
tc.End();
|
|||
|
}
|
|||
|
catch (Exception e)
|
|||
|
{
|
|||
|
#region Handle Exception
|
|||
|
|
|||
|
if (tc != null)
|
|||
|
tc.HandleError();
|
|||
|
ExceptionLog.Write(e);
|
|||
|
throw new ServiceException(e.Message, e);
|
|||
|
|
|||
|
#endregion
|
|||
|
}
|
|||
|
|
|||
|
return oEmpPosting;
|
|||
|
}
|
|||
|
|
|||
|
public DataSet GetEmpPrvPosting(DateTime EffectDate, int payrollTypeID)
|
|||
|
{
|
|||
|
DataSet oEmpPosting = new DataSet();
|
|||
|
TransactionContext tc = null;
|
|||
|
try
|
|||
|
{
|
|||
|
tc = TransactionContext.Begin();
|
|||
|
oEmpPosting = EmployeePostingDA.GetEmpPrvPosting(tc, EffectDate, payrollTypeID);
|
|||
|
tc.End();
|
|||
|
}
|
|||
|
catch (Exception e)
|
|||
|
{
|
|||
|
#region Handle Exception
|
|||
|
|
|||
|
if (tc != null)
|
|||
|
tc.HandleError();
|
|||
|
ExceptionLog.Write(e);
|
|||
|
throw new ServiceException(e.Message, e);
|
|||
|
|
|||
|
#endregion
|
|||
|
}
|
|||
|
|
|||
|
return oEmpPosting;
|
|||
|
}
|
|||
|
|
|||
|
#endregion
|
|||
|
}
|
|||
|
}
|