CEL_Payroll/Payroll.Service/Attendence/Service/AttnNationalHolidayService.cs
2024-09-17 14:30:13 +06:00

341 lines
12 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Ease.CoreV35.Model;
using Payroll.BO;
using Payroll.BO;
using Ease.CoreV35.Caching;
using Ease.CoreV35.DataAccess;
using Payroll.Service.Attendence.DA;
namespace Payroll.Service.Attendence.Service
{
#region AttnNationalHoliday Service
[Serializable]
public class AttnNationalHolidayService : ServiceTemplate, IAttnNationalHolidayService
{
#region Private functions and declaration
Cache _cache = new Cache(typeof(AttnNationalHoliday));
#endregion
public AttnNationalHolidayService() { }
private void MapObject(AttnNationalHoliday oAttnNationalHoliday, DataReader oReader)
{
base.SetObjectID(oAttnNationalHoliday, oReader.GetID("AttnNationalHolidayID"));
oAttnNationalHoliday.Description = oReader.GetString("Description");
oAttnNationalHoliday.FromDate = oReader.GetDateTime("FromDate").Value;
oAttnNationalHoliday.ToDate = oReader.GetDateTime("ToDate").Value;
//oAttnNationalHoliday.LocationID = oReader.GetID("LocationID");
oAttnNationalHoliday.Sequence = oReader.GetInt32("SequenceNo").Value;
oAttnNationalHoliday.Status = (EnumStatus)oReader.GetInt32("Status").Value;
oAttnNationalHoliday.CreatedBy = oReader.GetID("CreatedBy");
oAttnNationalHoliday.CreatedDate = oReader.GetDateTime("CreatedDate").Value;
oAttnNationalHoliday.ModifiedBy = oReader.GetID("ModifiedBy");
oAttnNationalHoliday.ModifiedDate = oReader.GetDateTime("ModifiedDate");
this.SetObjectState(oAttnNationalHoliday, Ease.CoreV35.ObjectState.Saved);
}
protected override T CreateObject<T>(DataReader oReader)
{
AttnNationalHoliday oAttnNationalHoliday = new AttnNationalHoliday();
MapObject(oAttnNationalHoliday, oReader);
return oAttnNationalHoliday as T;
}
protected AttnNationalHoliday CreateObject(DataReader oReader)
{
AttnNationalHoliday oAttnNationalHoliday = new AttnNationalHoliday();
MapObject(oAttnNationalHoliday, oReader);
return oAttnNationalHoliday;
}
#region Service implementation
public AttnNationalHoliday Get(ID id)
{
AttnNationalHoliday oAttnNationalHoliday = new AttnNationalHoliday();
#region Cache Header
oAttnNationalHoliday = _cache["Get", id] as AttnNationalHoliday;
if (oAttnNationalHoliday != null)
return oAttnNationalHoliday;
#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader oreader = new DataReader(AttnNationalHolidayDA.Get(tc, id));
if (oreader.Read())
{
oAttnNationalHoliday = this.CreateObject<AttnNationalHoliday>(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(oAttnNationalHoliday, "Get", id);
#endregion
return oAttnNationalHoliday;
}
public ObjectsTemplate<AttnNationalHoliday> Get(DateTime fromDate, DateTime todate)
{
ObjectsTemplate<AttnNationalHoliday> attnNationalHolidays = null;
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(AttnNationalHolidayDA.Get(tc, fromDate, todate));
attnNationalHolidays = this.CreateObjects<AttnNationalHoliday>(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 attnNationalHolidays;
}
public ObjectsTemplate<AttnNationalHoliday> Get(EnumStatus status)
{
#region Cache Header
ObjectsTemplate<AttnNationalHoliday> attnNationalHolidays = _cache["Get"] as ObjectsTemplate<AttnNationalHoliday>;
if (attnNationalHolidays != null)
return attnNationalHolidays;
#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(AttnNationalHolidayDA.Get(tc, status));
attnNationalHolidays = this.CreateObjects<AttnNationalHoliday>(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(attnNationalHolidays, "Get");
#endregion
return attnNationalHolidays;
}
public ID Save(AttnNationalHoliday oAttnNationalHoliday)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
if (oAttnNationalHoliday.IsNew)
{
int id = tc.GenerateID("AttnNationalHoliday", "AttnNationalHolidayID");
base.SetObjectID(oAttnNationalHoliday, ID.FromInteger(id));
int seqNo = tc.GenerateID("AttnNationalHoliday", "SequenceNo");
oAttnNationalHoliday.Sequence = seqNo;
AttnNationalHolidayDA.Insert(tc, oAttnNationalHoliday);
}
else
{
AttnNationalHolidayDA.Update(tc, oAttnNationalHoliday);
}
tc.End();
return oAttnNationalHoliday.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);
AttnNationalHolidayDA.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 ObjectsTemplate<AttnNationalHoliday> Get(EnumCardStatus status)
//{
// #region Cache Header
// ObjectsTemplate<AttnNationalHoliday> attnNationalHolidays = _cache["Get"] as ObjectsTemplate<AttnNationalHoliday>;
// if (attnNationalHolidays != null)
// return attnNationalHolidays;
// #endregion
// TransactionContext tc = null;
// try
// {
// tc = TransactionContext.Begin();
// DataReader dr = new DataReader(AttnNationalHolidayDA.Get(tc, status));
// attnNationalHolidays = this.CreateObjects<AttnNationalHoliday>(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(attnNationalHolidays, "Get");
// #endregion
// return attnNationalHolidays;
//}
//public void Save(ObjectsTemplate<AttnNationalHoliday> oAttnNationalHolidays)
//{
// TransactionContext tc = null;
// try
// {
// tc = TransactionContext.Begin(true);
// foreach (AttnNationalHoliday ac in oAttnNationalHolidays)
// {
// if (ac.IsNew)
// {
// ac.Status = EnumCardStatus.Free;
// int id = tc.GenerateID("AttnNationalHoliday", "AttnNationalHolidayID");
// base.SetObjectID(ac, ID.FromInteger(id));
// AttnNationalHolidayDA.Insert(tc, ac);
// }
// else
// {
// AttnNationalHolidayDA.Update(tc, ac);
// }
// }
// tc.End();
// }
// catch (Exception e)
// {
// #region Handle Exception
// if (tc != null)
// tc.HandleError();
// ExceptionLog.Write(e);
// throw new ServiceException(e.Message, e);
// #endregion
// }
//}
//public ObjectsTemplate<AttnNationalHoliday> Get(params EnumCardStatus[] status)
//{
// #region Cache Header
// ObjectsTemplate<AttnNationalHoliday> accessCards = _cache["Get"] as ObjectsTemplate<AttnNationalHoliday>;
// if (accessCards != null)
// return accessCards;
// #endregion
// TransactionContext tc = null;
// try
// {
// tc = TransactionContext.Begin();
// DataReader dr = new DataReader(AttnNationalHolidayDA.Get(tc, status));
// accessCards = this.CreateObjects<AttnNationalHoliday>(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(accessCards, "Get");
// #endregion
// return accessCards;
//}
//public bool IsExist(string CardNumber)
//{
// bool isExist = false;
// TransactionContext tc = null;
// try
// {
// tc = TransactionContext.Begin();
// isExist = AttnNationalHolidayDA.IsExist(tc, CardNumber);
// //accessCards = this.CreateObjects<AttnNationalHoliday>(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 isExist;
//}
//public void UpdateStatus(ID cardID, EnumCardStatus status)
//{
// TransactionContext tc = null;
// try
// {
// tc = TransactionContext.Begin(true);
// AttnNationalHolidayDA.UpdateStatus(tc, cardID, status);
// 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
}