CEL_Payroll/Payroll.Service/Attendence/Service/WorkPlanGroupService.cs

262 lines
8.7 KiB
C#
Raw Normal View History

2024-09-17 14:30:13 +06:00
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Ease.CoreV35.Model;
using Payroll.BO;
using Ease.CoreV35.Caching;
using Ease.CoreV35.DataAccess;
using Payroll.BO;
using Payroll.Service.Attendence.DA;
namespace Payroll.Service.Attendence.Service
{
#region WorkPlanGroup Service
[Serializable]
public class WorkPlanGroupService : ServiceTemplate, IWorkPlanGroupService
{
#region Private functions and declaration
Cache _cache = new Cache(typeof(WorkPlanGroup));
#endregion
public WorkPlanGroupService() { }
private void MapObject(WorkPlanGroup oWorkPlanGroup, DataReader oReader)
{
base.SetObjectID(oWorkPlanGroup, oReader.GetID("WorkPlanGroupID"));
oWorkPlanGroup.Name = oReader.GetString("Name");
oWorkPlanGroup.FromTime = oReader.GetDateTime("FromTime").HasValue ? oReader.GetDateTime("FromTime").Value : DateTime.MinValue;
oWorkPlanGroup.ToTime = oReader.GetDateTime("ToTime").HasValue ? oReader.GetDateTime("ToTime").Value : DateTime.MinValue;
//oWorkPlanGroup.FromTime = oReader.GetDateTime("FromTime").Value;
//oWorkPlanGroup.ToTime = oReader.GetDateTime("ToTime").Value;
oWorkPlanGroup.Type = (EnumWorkPlanGroup)oReader.GetInt32("Type").Value;
oWorkPlanGroup.Sequence = oReader.GetInt32("SequenceNo").Value;
oWorkPlanGroup.Status = (EnumStatus)oReader.GetInt32("Status").Value;
oWorkPlanGroup.CreatedBy = oReader.GetID("CreatedBy");
oWorkPlanGroup.CreatedDate = oReader.GetDateTime("CreatedDate").Value;
oWorkPlanGroup.ModifiedBy = oReader.GetID("ModifiedBy");
oWorkPlanGroup.ModifiedDate = oReader.GetDateTime("ModifiedDate");
oWorkPlanGroup.PayrollTypeID = oReader.GetID("PayrollTypeID");
this.SetObjectState(oWorkPlanGroup, Ease.CoreV35.ObjectState.Saved);
}
protected override T CreateObject<T>(DataReader oReader)
{
WorkPlanGroup oWorkPlanGroup = new WorkPlanGroup();
MapObject(oWorkPlanGroup, oReader);
return oWorkPlanGroup as T;
}
protected WorkPlanGroup CreateObject(DataReader oReader)
{
WorkPlanGroup oWorkPlanGroup = new WorkPlanGroup();
MapObject(oWorkPlanGroup, oReader);
return oWorkPlanGroup;
}
#region Service implementation
public WorkPlanGroup GetByID(ID id,ID PayrollTypeID)
{
WorkPlanGroup oWorkPlanGroup = new WorkPlanGroup();
#region Cache Header
oWorkPlanGroup = _cache["Get", id] as WorkPlanGroup;
if (oWorkPlanGroup != null)
return oWorkPlanGroup;
#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader oreader = new DataReader(WorkPlanGroupDA.Get(tc, id, PayrollTypeID));
if (oreader.Read())
{
oWorkPlanGroup = this.CreateObject<WorkPlanGroup>(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(oWorkPlanGroup, "Get", id);
#endregion
return oWorkPlanGroup;
}
public ObjectsTemplate<WorkPlanGroup> Get(ID PayrolltypeID)
{
#region Cache Header
ObjectsTemplate<WorkPlanGroup> workPlanGroups = _cache["Get"] as ObjectsTemplate<WorkPlanGroup>;
if (workPlanGroups != null)
return workPlanGroups;
#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(WorkPlanGroupDA.Get(tc, PayrolltypeID));
workPlanGroups = this.CreateObjects<WorkPlanGroup>(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(workPlanGroups, "Get");
#endregion
return workPlanGroups;
}
public ObjectsTemplate<WorkPlanGroup> Get(EnumStatus status, ID PayrolltypeID)
{
#region Cache Header
ObjectsTemplate<WorkPlanGroup> workPlanGroups = _cache["Get", status] as ObjectsTemplate<WorkPlanGroup>;
if (workPlanGroups != null)
return workPlanGroups;
#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(WorkPlanGroupDA.Get(tc, status, PayrolltypeID));
workPlanGroups = this.CreateObjects<WorkPlanGroup>(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(workPlanGroups, "Get", status);
#endregion
return workPlanGroups;
}
public ObjectsTemplate<WorkPlanGroup> Get(EnumWorkPlanGroup wpg, ID PayrolltypeID)
{
#region Cache Header
ObjectsTemplate<WorkPlanGroup> workPlanGroups = _cache["Get", wpg] as ObjectsTemplate<WorkPlanGroup>;
if (workPlanGroups != null)
return workPlanGroups;
#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(WorkPlanGroupDA.Get(tc, wpg, PayrolltypeID));
workPlanGroups = this.CreateObjects<WorkPlanGroup>(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(workPlanGroups, "Get", wpg);
#endregion
return workPlanGroups;
}
public ID Save(WorkPlanGroup oWorkPlanGroup, ID PayrolltypeID)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
if (oWorkPlanGroup.IsNew)
{
int id = tc.GenerateID("WorkPlanGroup", "WorkPlanGroupID");
base.SetObjectID(oWorkPlanGroup, ID.FromInteger(id));
int seqNo = tc.GenerateID("WorkPlanGroup", "SequenceNO");
oWorkPlanGroup.Sequence = seqNo;
WorkPlanGroupDA.Insert(tc, oWorkPlanGroup, PayrolltypeID);
}
else
{
WorkPlanGroupDA.Update(tc, oWorkPlanGroup, PayrolltypeID);
}
tc.End();
return oWorkPlanGroup.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(ID id)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
WorkPlanGroupDA.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
}