CEL_Payroll/Payroll.Service/Employee/Service/EmployeeStatusService.cs

456 lines
16 KiB
C#
Raw 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 EmployeeStatus Service
[Serializable]
public class EmployeeStatusService : ServiceTemplate, IEmployeeStatusService
{
#region Private functions and declaration
Cache _cache = new Cache(typeof(EmployeeStatus));
#endregion
public EmployeeStatusService() { }
private void MapComponentObject(EmployeeStatus.EmpStatusComponent oEmployeeStatusComponent, DataReader oReader)
{
base.SetObjectID(oEmployeeStatusComponent, oReader.GetID("EmployeeStatusComponentID"));
oEmployeeStatusComponent.ComponentType = oReader.GetInt32("EmployeeStatusComponent").Value;
oEmployeeStatusComponent.StatusID = oReader.GetID("StatusID");
this.SetObjectState(oEmployeeStatusComponent, Ease.CoreV35.ObjectState.Saved);
}
private EmployeeStatus.EmpStatusComponent CreateComponentObject(DataReader oReader)
{
EmployeeStatus.EmpStatusComponent item = new EmployeeStatus.EmpStatusComponent();
MapComponentObject(item, oReader);
return item;
}
private ObjectsTemplate<EmployeeStatus.EmpStatusComponent> CreateComponent(DataReader dr)
{
ObjectsTemplate<EmployeeStatus.EmpStatusComponent> oEmpSpouses = new ObjectsTemplate<EmployeeStatus.EmpStatusComponent>();
while (dr.Read())
{
EmployeeStatus.EmpStatusComponent item = CreateComponentObject(dr);
oEmpSpouses.Add(item);
}
return oEmpSpouses;
}
private void MapObject(EmployeeStatus oEmployeeStatus, DataReader oReader)
{
base.SetObjectID(oEmployeeStatus, oReader.GetID("StatusID"));
oEmployeeStatus.EmpStatus = (EnumEmployeeStatus)oReader.GetInt32("EmpStatus").Value;
oEmployeeStatus.Description = oReader.GetString("Description");
oEmployeeStatus.ContinueOwnPartPF = oReader.GetBoolean("ContinueOwnPartPF").Value;
oEmployeeStatus.ContinueCmpPartPF = oReader.GetBoolean("ContinueCmpPartPF").Value;
oEmployeeStatus.ContinueGratuity = oReader.GetBoolean("ContinueGratuity").Value;
oEmployeeStatus.Sequence = oReader.GetInt32("SequenceNo").Value;
oEmployeeStatus.Status = (EnumStatus)oReader.GetInt32("Status").Value;
oEmployeeStatus.CreatedBy = oReader.GetID("CreatedBy").IsUnassigned ? ID.FromInteger(0) : oReader.GetID("CreatedBy");
oEmployeeStatus.CreatedDate = oReader.GetDateTime("CreatedDate").HasValue ? oReader.GetDateTime("CreatedDate").Value : DateTime.Now;
//oEmployeeStatus.ModifiedBy = oReader.GetID("ModifiedBy").IsUnassigned ? ID.FromInteger(0) : oReader.GetID("ModifiedBy");
//oEmployeeStatus.ModifiedDate = oReader.GetDateTime("ModifiedDate").HasValue ? oReader.GetDateTime("ModifiedDate").Value : DateTime.Now;
this.SetObjectState(oEmployeeStatus, Ease.CoreV35.ObjectState.Saved);
}
protected override T CreateObject<T>(DataReader oReader)
{
EmployeeStatus oEmployeeStatus = new EmployeeStatus();
MapObject(oEmployeeStatus, oReader);
return oEmployeeStatus as T;
}
protected EmployeeStatus CreateObject(DataReader oReader)
{
EmployeeStatus oEmployeeStatus = new EmployeeStatus();
MapObject(oEmployeeStatus, oReader);
return oEmployeeStatus;
}
#region Service implementation
public EmployeeStatus Get(ID id)
{
EmployeeStatus oEmployeeStatus = new EmployeeStatus();
#region Cache Header
oEmployeeStatus = _cache["Get", id] as EmployeeStatus;
if (oEmployeeStatus != null)
return oEmployeeStatus;
#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader oreader = new DataReader(EmployeeStatusDA.Get(tc, id));
if (oreader.Read())
{
oEmployeeStatus = this.CreateObject<EmployeeStatus>(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
}
#region Cache Footer
_cache.Add(oEmployeeStatus, "Get", id);
#endregion
return oEmployeeStatus;
}
public EmployeeStatus Get(ID id, TransactionContext tc)
{
EmployeeStatus oEmployeeStatus = new EmployeeStatus();
#region Cache Header
oEmployeeStatus = _cache["Get_tc", id] as EmployeeStatus;
if (oEmployeeStatus != null)
return oEmployeeStatus;
#endregion
try
{
DataReader oreader = new DataReader(EmployeeStatusDA.Get(tc, id));
if (oreader.Read())
{
oEmployeeStatus = this.CreateObject<EmployeeStatus>(oreader);
}
oreader.Close();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
#region Cache Footer
_cache.Add(oEmployeeStatus, "Get_tc", id);
#endregion
return oEmployeeStatus;
}
public ObjectsTemplate<EmployeeStatus> Get(EnumStatus status)
{
#region Cache Header
ObjectsTemplate<EmployeeStatus> employeeStatuses = _cache["Get",status] as ObjectsTemplate<EmployeeStatus>;
if (employeeStatuses != null)
return employeeStatuses;
#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(EmployeeStatusDA.Get(tc, status));
employeeStatuses = this.CreateObjects<EmployeeStatus>(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
}
#region Cache Footer
_cache.Add(employeeStatuses, "Get", status);
#endregion
return employeeStatuses;
}
public ObjectsTemplate<EmployeeStatus> GetByEmpStatus(EnumStatus status,EnumEmployeeStatus empStatus)
{
#region Cache Header
ObjectsTemplate<EmployeeStatus> employeeStatuses = _cache["Get", status,empStatus] as ObjectsTemplate<EmployeeStatus>;
if (employeeStatuses != null)
return employeeStatuses;
#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(EmployeeStatusDA.GetByEmpStatus(tc, status,empStatus));
employeeStatuses = this.CreateObjects<EmployeeStatus>(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
}
#region Cache Footer
_cache.Add(employeeStatuses, "Get", status,empStatus);
#endregion
return employeeStatuses;
}
public ObjectsTemplate<EmployeeStatus> Get()
{
#region Cache Header
ObjectsTemplate<EmployeeStatus> employeeStatuses = _cache["Get"] as ObjectsTemplate<EmployeeStatus>;
if (employeeStatuses != null)
return employeeStatuses;
#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(EmployeeStatusDA.Get(tc));
employeeStatuses = this.CreateObjects<EmployeeStatus>(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
}
#region Cache Footer
_cache.Add(employeeStatuses,"Get");
#endregion
return employeeStatuses;
}
public ObjectsTemplate<EmployeeStatus.EmpStatusComponent> GetChild(ID parentID)
{
#region Cache Header
ObjectsTemplate<EmployeeStatus.EmpStatusComponent> employeeStatusCopms = _cache["Get", parentID] as ObjectsTemplate<EmployeeStatus.EmpStatusComponent>;
if (employeeStatusCopms != null)
return employeeStatusCopms;
#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dataReader = new DataReader(EmployeeStatusDA.GetChild(tc, parentID));
employeeStatusCopms = this.CreateComponent(dataReader);
dataReader.Close();
tc.End();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
#region Cache Footer
_cache.Add(employeeStatusCopms, "Get",parentID);
#endregion
return employeeStatusCopms;
}
public ObjectsTemplate<EmployeeStatus.EmpStatusComponent> GetChild(ID parentID, TransactionContext tc)
{
#region Cache Header
ObjectsTemplate<EmployeeStatus.EmpStatusComponent> employeeStatusCopms = _cache["Get", parentID] as ObjectsTemplate<EmployeeStatus.EmpStatusComponent>;
if (employeeStatusCopms != null)
return employeeStatusCopms;
#endregion
try
{
DataReader dataReader = new DataReader(EmployeeStatusDA.GetChild(tc, parentID));
employeeStatusCopms = this.CreateComponent(dataReader);
dataReader.Close();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
#region Cache Footer
_cache.Add(employeeStatusCopms, "Get", parentID);
#endregion
return employeeStatusCopms;
}
public ID Save(EmployeeStatus oEmployeeStatus)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
if (oEmployeeStatus.IsNew)
{
int id = tc.GenerateID("EmployeeStatus", "StatusID");
base.SetObjectID(oEmployeeStatus, ID.FromInteger(id));
EmployeeStatusDA.Insert(tc, oEmployeeStatus);
GradeSalaryChangeTypeService oItem = new GradeSalaryChangeTypeService();
}
else
{
EmployeeStatusDA.Update(tc, oEmployeeStatus);
}
tc.End();
return oEmployeeStatus.ID;
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
}
public void SaveStatus(EmployeeStatus oEmployeeStatus)
{
TransactionContext tc = null;
try
{
int Id=0;
tc = TransactionContext.Begin(true);
if (oEmployeeStatus.IsNew)
{
Id = tc.GenerateID("EmployeeStatus", "StatusID");
base.SetObjectID(oEmployeeStatus, ID.FromInteger(Id));
EmployeeStatusDA.Insert(tc, oEmployeeStatus);
}
else
{
Id = oEmployeeStatus.ID.Integer;
EmployeeStatusDA.Update(tc, oEmployeeStatus);
EmployeeStatusDA.DeleteChild(tc, oEmployeeStatus.ID);
}
if (oEmployeeStatus.GradeSalaryChangeType != null)
{
GradeSalaryChangeTypeService oItem = new GradeSalaryChangeTypeService();
int seqNo = tc.GenerateID("GradeSalaryChangeType", "SequenceNO");
//oItem.Delete(tc,oEmployeeStatus.ID);
oItem.Save(tc, oEmployeeStatus.GradeSalaryChangeType, oEmployeeStatus.ID, seqNo);
}
foreach (EmployeeStatus.EmpStatusComponent statusComponent in oEmployeeStatus.EmployeeStatusComponents)
{
int cId = tc.GenerateID("EmployeeStatusComponent", "EmployeeStatusComponentID");
base.SetObjectID(statusComponent, ID.FromInteger(cId));
statusComponent.StatusID = ID.FromInteger(Id);
EmployeeStatusDA.Insert(tc, statusComponent);
}
tc.End();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
}
private void UpdateParent(ID oldId, ID currentID, ObjectsTemplate<Configaration> configurations)
{
foreach (Configaration config in configurations)
{
if (config.ParentID == oldId)
{
config.ParentID = currentID;
}
}
}
public void Delete(ID id)
{
TransactionContext tc = null;
try
{
EmployeeStatus oest = EmployeeStatus.Get(id);
oest.GradeSalaryChangeType = GradeSalaryChangeType.Get(id);
tc = TransactionContext.Begin(true);
EmployeeStatusDA.DeleteChild(tc, id);
EmployeeStatusDA.Delete(tc, id);
if (oest.GradeSalaryChangeType != null)
{
GradeSalaryChangeTypeService oItem = new GradeSalaryChangeTypeService();
oItem.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
}
}
#endregion
}
#endregion
}