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

403 lines
14 KiB
C#

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.Service.Attendence.DA;
using Payroll.BO;
namespace Payroll.Service.Attendence.Service
{
#region HolidayCalendar Service
[Serializable]
public class HolidayCalendarService : ServiceTemplate, IHolidayCalendarService
{
#region Private functions and declaration
Cache _cache = new Cache(typeof(HolidayCalendar));
#endregion
public HolidayCalendarService() { }
private void MapObject(HolidayCalendar oHolidayCalendar, DataReader oReader)
{
base.SetObjectID(oHolidayCalendar, oReader.GetID("HolidayCalendarID"));
oHolidayCalendar.Type = (EnumHolidayType)oReader.GetInt32("Type").Value;
oHolidayCalendar.Description = oReader.GetString("Description");
oHolidayCalendar.HolidayDate = oReader.GetDateTime("HolidayDate").Value;
oHolidayCalendar.LocationID = oReader.GetID("LocationID");
oHolidayCalendar.CreatedBy = oReader.GetID("CreatedBy");
oHolidayCalendar.CreatedDate = oReader.GetDateTime("CreatedDate").Value;
oHolidayCalendar.ModifiedBy = oReader.GetID("ModifiedBy");
oHolidayCalendar.ModifiedDate = oReader.GetDateTime("ModifiedDate");
this.SetObjectState(oHolidayCalendar, Ease.CoreV35.ObjectState.Saved);
}
protected override T CreateObject<T>(DataReader oReader)
{
HolidayCalendar oHolidayCalendar = new HolidayCalendar();
MapObject(oHolidayCalendar, oReader);
return oHolidayCalendar as T;
}
protected HolidayCalendar CreateObject(DataReader oReader)
{
HolidayCalendar oHolidayCalendar = new HolidayCalendar();
MapObject(oHolidayCalendar, oReader);
return oHolidayCalendar;
}
#region Service implementation
public HolidayCalendar Get(ID id)
{
HolidayCalendar oHolidayCalendar = new HolidayCalendar();
#region Cache Header
oHolidayCalendar = _cache["Get", id] as HolidayCalendar;
if (oHolidayCalendar != null)
return oHolidayCalendar;
#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader oreader = new DataReader(HolidayCalendarDA.Get(tc, id));
if (oreader.Read())
{
oHolidayCalendar = this.CreateObject<HolidayCalendar>(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(oHolidayCalendar, "Get", id);
#endregion
return oHolidayCalendar;
}
public ObjectsTemplate<HolidayCalendar> Get()
{
#region Cache Header
ObjectsTemplate<HolidayCalendar> holidayCalendars = _cache["Get"] as ObjectsTemplate<HolidayCalendar>;
if (holidayCalendars != null)
return holidayCalendars;
#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(HolidayCalendarDA.Get(tc));
holidayCalendars = this.CreateObjects<HolidayCalendar>(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(holidayCalendars, "Get");
#endregion
return holidayCalendars;
}
public ObjectsTemplate<HolidayCalendar> GetWeeklyHoliDay()
{
#region Cache Header
ObjectsTemplate<HolidayCalendar> holidayCalendars = _cache["GetWeeklyHoliDay"] as ObjectsTemplate<HolidayCalendar>;
if (holidayCalendars != null)
return holidayCalendars;
#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(HolidayCalendarDA.GetWeeklyHoliDay(tc));
holidayCalendars = this.CreateObjects<HolidayCalendar>(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(holidayCalendars, "GetWeeklyHoliDay");
#endregion
return holidayCalendars;
}
public ObjectsTemplate<HolidayCalendar> GetHoliDayByLocation(ID nLocID)
{
#region Cache Header
ObjectsTemplate<HolidayCalendar> holidayCalendars = _cache["GetHoliDayByLocation", nLocID] as ObjectsTemplate<HolidayCalendar>;
if (holidayCalendars != null)
return holidayCalendars;
#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(HolidayCalendarDA.GetHoliDayByLocation(tc, nLocID));
holidayCalendars = this.CreateObjects<HolidayCalendar>(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(holidayCalendars, "GetHoliDayByLocation", nLocID);
#endregion
return holidayCalendars;
}
public ObjectsTemplate<HolidayCalendar> GetWeeklyAndLocHoliday(ID nLocID)
{
#region Cache Header
ObjectsTemplate<HolidayCalendar> holidayCalendars = _cache["GetWeeklyAndLocHoliday", nLocID] as ObjectsTemplate<HolidayCalendar>;
if (holidayCalendars != null)
return holidayCalendars;
#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(HolidayCalendarDA.GetWeeklyAndLocHoliday(tc, nLocID));
holidayCalendars = this.CreateObjects<HolidayCalendar>(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(holidayCalendars, "GetWeeklyAndLocHoliday", nLocID);
#endregion
return holidayCalendars;
}
public int GetTotalMonthlyHolidays(int loactionNumber, DateTime firstDateOfMonth, DateTime lastDateOfMonth)
{
int totalMonthlyHolidays = 0;
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
totalMonthlyHolidays = HolidayCalendarDA.GetTotalMonthlyHolidays(tc, loactionNumber, firstDateOfMonth, lastDateOfMonth);
tc.End();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
return totalMonthlyHolidays;
}
public double GetNoofHoliday()
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
double amount = HolidayCalendarDA.GetNoofHoliday(tc);
tc.End();
return amount;
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException("Failed" + e.Message, e);
#endregion
}
}
public ObjectsTemplate<HolidayCalendar> GetbyMonthRange(int nLocationID , DateTime dStartDate , DateTime dEndDate)
{
#region Cache Header
ObjectsTemplate<HolidayCalendar> holidayCalendars = _cache["GetHoliDayByLocation" , nLocationID , dStartDate , dEndDate] as ObjectsTemplate<HolidayCalendar>;
if (holidayCalendars != null)
return holidayCalendars;
#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(HolidayCalendarDA.GetbyMonthRange(tc , nLocationID , dStartDate , dEndDate));
holidayCalendars = this.CreateObjects<HolidayCalendar>(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(holidayCalendars , "GetHoliDayByLocation" , nLocationID , dStartDate , dEndDate);
#endregion
return holidayCalendars;
}
public ObjectsTemplate<HolidayCalendar> GetbyDateRange(DateTime dStartDate , DateTime dEndDate)
{
#region Cache Header
ObjectsTemplate<HolidayCalendar> holidayCalendars = _cache["GetHoliDayByLocation" , dStartDate , dEndDate] as ObjectsTemplate<HolidayCalendar>;
if (holidayCalendars != null)
return holidayCalendars;
#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(HolidayCalendarDA.GetbyDateRange(tc , dStartDate , dEndDate));
holidayCalendars = this.CreateObjects<HolidayCalendar>(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(holidayCalendars , "GetHoliDayByLocation" , dStartDate , dEndDate);
#endregion
return holidayCalendars;
}
public ID Save(HolidayCalendar oHolidayCalendar)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
if (oHolidayCalendar.IsNew)
{
int id = tc.GenerateID("HolidayCalendar", "HolidayCalendarID");
base.SetObjectID(oHolidayCalendar, ID.FromInteger(id));
HolidayCalendarDA.Insert(tc, oHolidayCalendar);
}
else
{
HolidayCalendarDA.Update(tc, oHolidayCalendar);
}
tc.End();
return oHolidayCalendar.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);
HolidayCalendarDA.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 DeleteAll()
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
HolidayCalendarDA.DeleteAll(tc);
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 DeleteAll(int nYear)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
HolidayCalendarDA.DeleteAll(tc,nYear);
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
}