368 lines
12 KiB
C#
368 lines
12 KiB
C#
|
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 Leave Year Service
|
||
|
[Serializable]
|
||
|
class LeaveYearService : ServiceTemplate, ILeaveYearService
|
||
|
{
|
||
|
#region Private functions and declaration
|
||
|
Cache _cache = new Cache(typeof(LeaveYear));
|
||
|
public LeaveYearService() { }
|
||
|
|
||
|
private void MapObject(LeaveYear oLeaveYear, DataReader oReader)
|
||
|
{
|
||
|
base.SetObjectID(oLeaveYear, oReader.GetID("LeaveYearID"));
|
||
|
oLeaveYear.Name = oReader.GetString("Name");
|
||
|
oLeaveYear.StartDate = oReader.GetDateTime("StartDate").Value;
|
||
|
oLeaveYear.EndDate = oReader.GetDateTime("EndDate").Value;
|
||
|
//oLeaveYear.BenYearStartDate = oReader.GetDateTime("BenYearStartDate");
|
||
|
//oLeaveYear.BenYearEndDate = oReader.GetDateTime("BenYearEndtDate");
|
||
|
oLeaveYear.IsCurrent = oReader.GetBoolean("IsCurrent").Value;
|
||
|
oLeaveYear.IsEnded = oReader.GetBoolean("IsEnded").Value;
|
||
|
oLeaveYear.Status = (EnumStatus)oReader.GetInt32("Status").Value;
|
||
|
oLeaveYear.Sequence = oReader.GetInt32("SequenceNo").Value;
|
||
|
oLeaveYear.CreatedBy = oReader.GetID("CreatedBy");
|
||
|
oLeaveYear.CreatedDate = oReader.GetDateTime("CreatedDate").Value;
|
||
|
oLeaveYear.ModifiedBy = oReader.GetID("ModifiedBy");
|
||
|
oLeaveYear.ModifiedDate = oReader.GetDateTime("ModifiedDate");
|
||
|
|
||
|
this.SetObjectState(oLeaveYear, Ease.CoreV35.ObjectState.Saved);
|
||
|
|
||
|
}
|
||
|
protected override T CreateObject<T>(DataReader oReader)
|
||
|
{
|
||
|
LeaveYear oLeaveYear = new LeaveYear();
|
||
|
MapObject(oLeaveYear, oReader);
|
||
|
return oLeaveYear as T;
|
||
|
|
||
|
}
|
||
|
LeaveYear CreateObject(DataReader oReader)
|
||
|
{
|
||
|
LeaveYear oLeaveYear = new LeaveYear();
|
||
|
MapObject(oLeaveYear, oReader);
|
||
|
return oLeaveYear;
|
||
|
}
|
||
|
|
||
|
#endregion
|
||
|
|
||
|
#region Service Implementation
|
||
|
public LeaveYear Get(ID id)
|
||
|
{
|
||
|
LeaveYear oLeaveYear = new LeaveYear();
|
||
|
#region Cache Header
|
||
|
oLeaveYear = (LeaveYear)_cache["Get", id.Integer];
|
||
|
if (oLeaveYear != null)
|
||
|
{
|
||
|
return oLeaveYear;
|
||
|
}
|
||
|
#endregion
|
||
|
TransactionContext tc = null;
|
||
|
try
|
||
|
{
|
||
|
tc = TransactionContext.Begin();
|
||
|
DataReader oreader = new DataReader(LeaveYearDA.Get(tc, id.Integer));
|
||
|
if (oreader.Read())
|
||
|
{
|
||
|
oLeaveYear = this.CreateObject<LeaveYear>(oreader);
|
||
|
}
|
||
|
oreader.Close();
|
||
|
tc.End();
|
||
|
}
|
||
|
catch (Exception ex)
|
||
|
{
|
||
|
#region Handle Exception
|
||
|
if (tc != null)
|
||
|
tc.HandleError();
|
||
|
ExceptionLog.Write(ex);
|
||
|
throw new ServiceException("Failed to Get Leave Year: " + ex.Message, ex);
|
||
|
#endregion
|
||
|
}
|
||
|
#region Cache Footer
|
||
|
_cache.Add(oLeaveYear, "Get", id.Integer);
|
||
|
#endregion
|
||
|
return oLeaveYear;
|
||
|
}
|
||
|
public ObjectsTemplate<LeaveYear> Get()
|
||
|
{
|
||
|
#region Cache Header
|
||
|
|
||
|
ObjectsTemplate<LeaveYear> oLeaveYears = _cache["Get"] as ObjectsTemplate<LeaveYear>;
|
||
|
if (oLeaveYears != null)
|
||
|
return oLeaveYears;
|
||
|
|
||
|
#endregion
|
||
|
TransactionContext tc = null;
|
||
|
try
|
||
|
{
|
||
|
tc = TransactionContext.Begin();
|
||
|
DataReader dr = new DataReader(LeaveYearDA.Get(tc));
|
||
|
oLeaveYears = this.CreateObjects<LeaveYear>(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(oLeaveYears, "Get");
|
||
|
#endregion
|
||
|
return oLeaveYears;
|
||
|
}
|
||
|
public ObjectsTemplate<LeaveYear> Get(EnumStatus status)
|
||
|
{
|
||
|
#region Cache Header
|
||
|
|
||
|
ObjectsTemplate<LeaveYear> leaveYears = _cache["Get", status] as ObjectsTemplate<LeaveYear>;
|
||
|
if (leaveYears != null)
|
||
|
return leaveYears;
|
||
|
|
||
|
#endregion
|
||
|
|
||
|
TransactionContext tc = null;
|
||
|
try
|
||
|
{
|
||
|
tc = TransactionContext.Begin();
|
||
|
|
||
|
DataReader dr = new DataReader(LeaveYearDA.Get(tc, status));
|
||
|
leaveYears = this.CreateObjects<LeaveYear>(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(leaveYears, "Get", status);
|
||
|
|
||
|
#endregion
|
||
|
|
||
|
return leaveYears;
|
||
|
}
|
||
|
public LeaveYear GetIDByName(string sLeaveYear)
|
||
|
{
|
||
|
LeaveYear oLeaveYear = new LeaveYear();
|
||
|
#region Cache Header
|
||
|
oLeaveYear = (LeaveYear)_cache["Get", sLeaveYear];
|
||
|
if (oLeaveYear != null)
|
||
|
return oLeaveYear;
|
||
|
#endregion
|
||
|
TransactionContext tc = null;
|
||
|
try
|
||
|
{
|
||
|
tc = TransactionContext.Begin();
|
||
|
DataReader oreader = new DataReader(LeaveYearDA.GetIDByName(tc, sLeaveYear));
|
||
|
if (oreader.Read())
|
||
|
{
|
||
|
oLeaveYear = this.CreateObject<LeaveYear>(oreader);
|
||
|
}
|
||
|
oreader.Close();
|
||
|
tc.End();
|
||
|
}
|
||
|
catch (Exception e)
|
||
|
{
|
||
|
#region Handle Exception
|
||
|
if (tc != null)
|
||
|
tc.HandleError();
|
||
|
ExceptionLog.Write(e);
|
||
|
throw new ServiceException("Failed to Get Leave: " + e.Message, e);
|
||
|
#endregion
|
||
|
}
|
||
|
#region Cache Footer
|
||
|
_cache.Add(oLeaveYear, "Get", sLeaveYear);
|
||
|
#endregion
|
||
|
return oLeaveYear;
|
||
|
}
|
||
|
public LeaveYear GetCurrentYear()
|
||
|
{
|
||
|
|
||
|
LeaveYear oLeaveYear = null;
|
||
|
TransactionContext tc = null;
|
||
|
try
|
||
|
{
|
||
|
tc = TransactionContext.Begin();
|
||
|
DataReader oreader = new DataReader(LeaveYearDA.GetCurrentYear(tc));
|
||
|
if (oreader.Read())
|
||
|
{
|
||
|
oLeaveYear = this.CreateObject<LeaveYear>(oreader);
|
||
|
}
|
||
|
oreader.Close();
|
||
|
tc.End();
|
||
|
}
|
||
|
catch (Exception e)
|
||
|
{
|
||
|
#region Handle Exception
|
||
|
if (tc != null)
|
||
|
tc.HandleError();
|
||
|
ExceptionLog.Write(e);
|
||
|
throw new ServiceException("Failed to Get Leave Year: " + e.Message, e);
|
||
|
#endregion
|
||
|
}
|
||
|
return oLeaveYear;
|
||
|
}
|
||
|
public LeaveYear GetCurrentYear(string year)
|
||
|
{
|
||
|
|
||
|
LeaveYear oLeaveYear = null;
|
||
|
TransactionContext tc = null;
|
||
|
try
|
||
|
{
|
||
|
tc = TransactionContext.Begin();
|
||
|
DataReader oreader = new DataReader(LeaveYearDA.GetCurrentYear(tc, year));
|
||
|
if (oreader.Read())
|
||
|
{
|
||
|
oLeaveYear = this.CreateObject<LeaveYear>(oreader);
|
||
|
}
|
||
|
oreader.Close();
|
||
|
tc.End();
|
||
|
}
|
||
|
catch (Exception e)
|
||
|
{
|
||
|
#region Handle Exception
|
||
|
if (tc != null)
|
||
|
tc.HandleError();
|
||
|
ExceptionLog.Write(e);
|
||
|
throw new ServiceException("Failed to Get Leave Year: " + e.Message, e);
|
||
|
#endregion
|
||
|
}
|
||
|
return oLeaveYear;
|
||
|
}
|
||
|
public void UpdateYearEndValue(TransactionContext tc, LeaveYear leaveYear)
|
||
|
{
|
||
|
|
||
|
try
|
||
|
{
|
||
|
LeaveYearDA.UpdateYearEndStatus(tc, leaveYear);
|
||
|
}
|
||
|
catch (Exception e)
|
||
|
{
|
||
|
#region Handle Exception
|
||
|
if (tc != null)
|
||
|
tc.HandleError();
|
||
|
ExceptionLog.Write(e);
|
||
|
throw new ServiceException("Failed to Save Leave Year: " + e.Message, e);
|
||
|
#endregion
|
||
|
}
|
||
|
}
|
||
|
|
||
|
public void UpdateCurrYearStatus(TransactionContext tc, LeaveYear leaveYear)
|
||
|
{
|
||
|
try
|
||
|
{
|
||
|
LeaveYearDA.UpdateCurrYearStatus(tc, leaveYear);
|
||
|
}
|
||
|
catch (Exception e)
|
||
|
{
|
||
|
#region Handle Exception
|
||
|
if (tc != null)
|
||
|
tc.HandleError();
|
||
|
ExceptionLog.Write(e);
|
||
|
throw new ServiceException("Failed to update current year status; reason:" + e.Message, e);
|
||
|
#endregion
|
||
|
}
|
||
|
}
|
||
|
|
||
|
public ID Save(LeaveYear oLeaveYear)
|
||
|
{
|
||
|
TransactionContext tc = null;
|
||
|
try
|
||
|
{
|
||
|
tc = TransactionContext.Begin(true);
|
||
|
if (oLeaveYear.IsNew)
|
||
|
{
|
||
|
int id = tc.GenerateID("LeaveYear", "LeaveYearID");
|
||
|
base.SetObjectID(oLeaveYear, ID.FromInteger(id));
|
||
|
int seqNo = tc.GenerateID("LeaveYear", "SequenceNO");
|
||
|
oLeaveYear.Sequence = seqNo;
|
||
|
LeaveYearDA.Insert(tc, oLeaveYear);
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
LeaveYearDA.Update(tc, oLeaveYear);
|
||
|
}
|
||
|
tc.End();
|
||
|
return oLeaveYear.ID;
|
||
|
|
||
|
}
|
||
|
catch (Exception e)
|
||
|
{
|
||
|
#region Handle Exception
|
||
|
if (tc != null)
|
||
|
tc.HandleError();
|
||
|
ExceptionLog.Write(e);
|
||
|
throw new ServiceException("Failed to Save Leave Year: " + e.Message, e);
|
||
|
#endregion
|
||
|
}
|
||
|
}
|
||
|
public void Delete(ID id)
|
||
|
{
|
||
|
TransactionContext tc = null;
|
||
|
try
|
||
|
{
|
||
|
tc = TransactionContext.Begin(true);
|
||
|
LeaveYearDA.Delete(tc, id.Integer);
|
||
|
tc.End();
|
||
|
}
|
||
|
catch (Exception e)
|
||
|
{
|
||
|
#region Handle Exception
|
||
|
if (tc != null)
|
||
|
tc.HandleError();
|
||
|
ExceptionLog.Write(e);
|
||
|
throw new ServiceException("Failed to Delete Leave Year: " + e.Message, e);
|
||
|
#endregion
|
||
|
}
|
||
|
}
|
||
|
public int CountCurrentYear()
|
||
|
{
|
||
|
int res = 0;
|
||
|
TransactionContext tc = null;
|
||
|
try
|
||
|
{
|
||
|
tc = TransactionContext.Begin(true);
|
||
|
res = LeaveYearDA.CountCurrentYear(tc);
|
||
|
tc.End();
|
||
|
}
|
||
|
catch (Exception e)
|
||
|
{
|
||
|
#region Handle Exception
|
||
|
if (tc != null)
|
||
|
tc.HandleError();
|
||
|
ExceptionLog.Write(e);
|
||
|
throw new ServiceException("Failed to Get Leave Process Information: " + e.Message, e);
|
||
|
#endregion
|
||
|
}
|
||
|
return res;
|
||
|
|
||
|
}
|
||
|
#endregion
|
||
|
}
|
||
|
#endregion
|
||
|
}
|