EchoTex_Payroll/HRM.DA/Service/Employee/EmployeeHistoryService.cs
2024-10-14 10:01:49 +06:00

513 lines
17 KiB
C#

using Ease.Core.DataAccess;
using Ease.Core.Model;
using Ease.Core.Utility;
using System;
using System.Collections.Generic;
using System.Data;
using HRM.BO;
namespace HRM.DA
{
public class EmployeeHistoryService : ServiceTemplate, IEmployeeHistoryService
{
public EmployeeHistoryService()
{
}
private void MapObject(EmployeeHistory oEmployeeHistory, DataReader oReader)
{
base.SetObjectID(oEmployeeHistory, oReader.GetInt32("ID").Value);
oEmployeeHistory.EmployeeID = oReader.GetInt32("EmployeeID", 0);
oEmployeeHistory.EffectDate = oReader.GetDateTime("effectDate").Value;
oEmployeeHistory.EndDate = oReader.GetDateTime("EndDate").HasValue
? oReader.GetDateTime("EndDate").Value
: DateTime.Now;
oEmployeeHistory.EmployeeStatus = (EnumEmployeeStatus)oReader.GetInt32("paramID").Value;
oEmployeeHistory.Remarks = oReader.GetString("remarks");
oEmployeeHistory.CreatedBy = oReader.GetInt32("CreatedBy", 0);
oEmployeeHistory.CreatedDate = oReader.GetDateTime("CreationDate").Value;
oEmployeeHistory.ModifiedBy = oReader.GetInt32("ModifiedBy", 0);
oEmployeeHistory.ModifiedDate = oReader.GetDateTime("ModifiedDate");
this.SetObjectState(oEmployeeHistory, Ease.Core.ObjectState.Saved);
}
protected override T CreateObject<T>(DataReader oReader)
{
EmployeeHistory oEmployeeHistory = new EmployeeHistory();
MapObject(oEmployeeHistory, oReader);
return oEmployeeHistory as T;
}
#region Service implementation
public EmployeeHistory Get(int id)
{
EmployeeHistory oEmployeeHistory = null;
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader oreader = new DataReader(EmployeeHistoryDA.Get(tc, id));
if (oreader.Read())
{
oEmployeeHistory = this.CreateObject<EmployeeHistory>(oreader);
}
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 oEmployeeHistory;
}
public EmployeeHistory GetByEmpID(int nEmpID)
{
EmployeeHistory oEmployeeHistory = null;
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader oreader = new DataReader(EmployeeHistoryDA.GetByEmpID(tc, nEmpID));
if (oreader.Read())
{
oEmployeeHistory = this.CreateObject<EmployeeHistory>(oreader);
}
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 oEmployeeHistory;
}
public EmployeeHistory GetEmpLastHistory(int nEmpID)
{
EmployeeHistory oEmployeeHistory = null;
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader oreader = new DataReader(EmployeeHistoryDA.GetEmpLastHistory(tc, nEmpID));
if (oreader.Read())
{
oEmployeeHistory = this.CreateObject<EmployeeHistory>(oreader);
}
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 oEmployeeHistory;
}
public List<EmployeeHistory> Get()
{
List<EmployeeHistory> employeeHistorys = new List<EmployeeHistory>();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(EmployeeHistoryDA.Get(tc));
employeeHistorys = this.CreateObjects<EmployeeHistory>(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 employeeHistorys;
}
public int DoContinue(TransactionContext tc, EmployeeHistory oEmployeeHistory, bool continuePF)
{
try
{
if (oEmployeeHistory.IsNew)
{
int id = tc.GenerateID("EmployeeHistory", "ID");
base.SetObjectID(oEmployeeHistory, id);
EmployeeHistoryDA.Insert(tc, oEmployeeHistory);
EmployeeDA.DoContinue(tc, oEmployeeHistory.EmployeeID);
}
else
{
EmployeeHistoryDA.Update(tc, oEmployeeHistory);
EmployeeDA.DoContinue(tc, oEmployeeHistory.EmployeeID);
}
if (continuePF == false)
{
EmployeeDA.UpdatePFMemship(tc, oEmployeeHistory.EmployeeID,
EnumPFMembershipType.DiscontinuedfromPayroll, oEmployeeHistory.EffectDate);
}
else
{
EmployeeDA.UpdatePFMemship(tc, oEmployeeHistory.EmployeeID,
EnumPFMembershipType.Live, oEmployeeHistory.EffectDate);
}
return oEmployeeHistory.ID;
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
}
public int Save(EmployeeHistory oEmployeeHistory, bool disAfterCurrmonth, bool continuePF)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
if (oEmployeeHistory.IsNew)
{
int id = tc.GenerateID("EmployeeHistory", "ID");
base.SetObjectID(oEmployeeHistory, id);
EmployeeHistoryDA.Insert(tc, oEmployeeHistory);
EmployeeDA.UpdateStatus(tc, oEmployeeHistory.EmployeeID, oEmployeeHistory.ID,
oEmployeeHistory.EffectDate, oEmployeeHistory.EmployeeStatus);
}
else
{
EmployeeHistoryDA.Update(tc, oEmployeeHistory);
EmployeeDA.UpdateStatus(tc, oEmployeeHistory.EmployeeID, oEmployeeHistory.ID,
oEmployeeHistory.EffectDate, oEmployeeHistory.EmployeeStatus);
}
if (disAfterCurrmonth == true)
{
EmployeeDA.UpdatemiddleOfMonthDiscontinue(tc,
oEmployeeHistory.EmployeeID, oEmployeeHistory.EmployeeStatus, oEmployeeHistory.EffectDate);
}
else
{
if (continuePF == false)
EmployeeDA.UpdatePFMemship(tc, oEmployeeHistory.EmployeeID,
EnumPFMembershipType.DiscontinuedfromPayroll, oEmployeeHistory.EffectDate);
if (continuePF == true)
EmployeeDA.UpdatePFMemship(tc, oEmployeeHistory.EmployeeID,
EnumPFMembershipType.Live, oEmployeeHistory.EffectDate);
//if (oEmployeeHistory.EmployeeStatus == EnumEmployeeStatus.Live)
// EmployeeDA.UpdateConfirmation(tc, oEmployeeHistory.EmployeeID, oEmployeeHistory.EmployeeStatus, oEmployeeHistory.EffectDate);
}
tc.End();
return oEmployeeHistory.ID;
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
}
public void Save(TransactionContext tc, EmployeeHistory oEmployeeHistory, bool disAfterCurrmonth)
{
try
{
if (oEmployeeHistory.IsNew)
{
int id = tc.GenerateID("EmployeeHistory", "ID");
base.SetObjectID(oEmployeeHistory, id);
oEmployeeHistory.CreatedBy = oEmployeeHistory.CreatedBy;
oEmployeeHistory.CreatedDate = DateTime.Now;
EmployeeHistoryDA.Insert(tc, oEmployeeHistory);
HREmployeeDA.UpdateStatus(tc, oEmployeeHistory.EmployeeID, oEmployeeHistory.EmployeeStatus);
}
else
{
oEmployeeHistory.ModifiedBy = oEmployeeHistory.ModifiedBy;
oEmployeeHistory.ModifiedDate = DateTime.Now;
EmployeeHistoryDA.Update(tc, oEmployeeHistory);
HREmployeeDA.UpdateStatus(tc, oEmployeeHistory.EmployeeID, oEmployeeHistory.EmployeeStatus);
}
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
}
public int DoContinue(EmployeeHistory oEmployeeHistory, bool continuePF)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
if (oEmployeeHistory.IsNew)
{
int id = tc.GenerateID("EmployeeHistory", "ID");
base.SetObjectID(oEmployeeHistory, id);
EmployeeHistoryDA.Insert(tc, oEmployeeHistory);
EmployeeDA.DoContinue(tc, oEmployeeHistory.EmployeeID);
}
else
{
EmployeeHistoryDA.Update(tc, oEmployeeHistory);
EmployeeDA.DoContinue(tc, oEmployeeHistory.EmployeeID);
}
if (continuePF == false)
{
EmployeeDA.UpdatePFMemship(tc, oEmployeeHistory.EmployeeID,
EnumPFMembershipType.DiscontinuedfromPayroll, oEmployeeHistory.EffectDate);
}
else
{
EmployeeDA.UpdatePFMemship(tc, oEmployeeHistory.EmployeeID,
EnumPFMembershipType.Live, oEmployeeHistory.EffectDate);
}
tc.End();
return oEmployeeHistory.ID;
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
}
public DataSet GetEmpHistory(DateTime dEffectDate, DateTime dEffectDate2, int payrollTypeID)
{
DataSet oEmpPostings = new DataSet();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
oEmpPostings = EmployeeHistoryDA.GetEmpHistory(tc, dEffectDate, dEffectDate2, 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 oEmpPostings;
}
public DateTime GetDate(int empID, EnumEmployeeStatus ParamID)
{
DateTime dt;
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
dt = EmployeeHistoryDA.GetByEmpIDandParam(tc, empID, ParamID);
tc.End();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
return dt;
}
//public void SaveConfirm(EmployeeHistory oEmployeeHistory, bool confirmEmpPF,EnumEmployeeOtherStatus IsConfirm)
//{
// TransactionContext tc = null;
// try
// {
// tc = TransactionContext.Begin(true);
// //if (oEmployeeHistory.IsNew)
// //{
// // int id = tc.GenerateID("EmployeeHistory", "ID");
// // base.SetObjectID(oEmployeeHistory, ID.FromInteger(id));
// // EmployeeHistoryDA.Insert(tc, oEmployeeHistory);
// //}
// //else
// //{
// // EmployeeHistoryDA.Update(tc, oEmployeeHistory);
// //}
// if (oEmployeeHistory.EmployeeStatus == EnumEmployeeStatus.Live)
// EmployeeDA.UpdateConfirmation(tc, oEmployeeHistory.EmployeeID, IsConfirm, oEmployeeHistory.EffectDate,confirmEmpPF);
// tc.End();
// }
// catch (Exception e)
// {
// #region Handle Exception
// if (tc != null)
// tc.HandleError();
// ExceptionLog.Write(e);
// throw new ServiceException(e.Message, e);
// #endregion
// }
//}
//public void SaveContinue(EmployeeHistory oEmployeeHistory, bool continuePF)
//{
// TransactionContext tc = null;
// try
// {
// tc = TransactionContext.Begin(true);
// if (oEmployeeHistory.IsNew)
// {
// int id = tc.GenerateID("EmployeeHistory", "ID");
// base.SetObjectID(oEmployeeHistory, ID.FromInteger(id));
// EmployeeHistoryDA.Insert(tc, oEmployeeHistory);
// EmployeeDA.UpdateStatus(tc, oEmployeeHistory.EmployeeID, oEmployeeHistory.EmployeeStatus);
// }
// else
// {
// EmployeeHistoryDA.Update(tc, oEmployeeHistory);
// EmployeeDA.UpdateStatus(tc, oEmployeeHistory.EmployeeID, oEmployeeHistory.EmployeeStatus);
// }
// if (continuePF == true)
// EmployeeDA.UpdatePFMemship(tc, oEmployeeHistory.EmployeeID,
// EnumPFMembershipType.Live, oEmployeeHistory.EffectDate);
// //oEmployeeHistory.ID = ID.FromInteger(0);
// EmployeeDA.UpdateEmpContinue(tc, oEmployeeHistory.EmployeeID, oEmployeeHistory.EmployeeStatus);
// tc.End();
// }
// 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
{
tc = TransactionContext.Begin(true);
EmployeeHistoryDA.Delete(tc, id);
tc.End();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
}
public void DeleteByEmpID(int nEmpID)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
EmployeeHistoryDA.DeleteByEmpID(tc, nEmpID);
tc.End();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
}
#endregion
}
}