310 lines
9.0 KiB
C#
310 lines
9.0 KiB
C#
using HRM.BO;
|
|
using Ease.Core.DataAccess;
|
|
using Ease.Core.Model;
|
|
using Ease.Core.Utility;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
namespace HRM.DA
|
|
{
|
|
#region WeeklyHoliday Service
|
|
|
|
public class WeeklyHolidayService : ServiceTemplate, IWeeklyHolidayService
|
|
{
|
|
public WeeklyHolidayService()
|
|
{
|
|
}
|
|
|
|
private void MapObject(WeeklyHoliday oWeeklyHoliday, DataReader oReader)
|
|
{
|
|
base.SetObjectID(oWeeklyHoliday, oReader.GetInt32("WeeklyHolidayID").Value);
|
|
oWeeklyHoliday.DateType = oReader.GetInt16("DateType").Value;
|
|
oWeeklyHoliday.LocationID = oReader.GetInt32("LocationID");
|
|
oWeeklyHoliday.Sequence = oReader.GetInt32("SequenceNo").Value;
|
|
oWeeklyHoliday.Status = (EnumStatus)oReader.GetInt32("Status").Value;
|
|
oWeeklyHoliday.HolidayMonth = oReader.GetInt32("HolidayMonth").GetValueOrDefault();
|
|
oWeeklyHoliday.IsAlternative = oReader.GetBoolean("IsAlternative").GetValueOrDefault();
|
|
oWeeklyHoliday.IsHalfDay = oReader.GetBoolean("IsHalfDay").GetValueOrDefault();
|
|
oWeeklyHoliday.CreatedBy = oReader.GetInt32("CreatedBy", 0);
|
|
oWeeklyHoliday.CreatedDate = oReader.GetDateTime("CreatedDate").Value;
|
|
oWeeklyHoliday.ModifiedBy = oReader.GetInt32("ModifiedBy", 0);
|
|
oWeeklyHoliday.ModifiedDate = oReader.GetDateTime("ModifiedDate");
|
|
this.SetObjectState(oWeeklyHoliday, Ease.Core.ObjectState.Saved);
|
|
}
|
|
|
|
protected override T CreateObject<T>(DataReader oReader)
|
|
{
|
|
WeeklyHoliday oWeeklyHoliday = new WeeklyHoliday();
|
|
MapObject(oWeeklyHoliday, oReader);
|
|
return oWeeklyHoliday as T;
|
|
}
|
|
|
|
#region Service implementation
|
|
|
|
public WeeklyHoliday Get(int id)
|
|
{
|
|
WeeklyHoliday oWeeklyHoliday = null;
|
|
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin();
|
|
DataReader oreader = new DataReader(WeeklyHolidayDA.Get(tc, id));
|
|
if (oreader.Read())
|
|
{
|
|
oWeeklyHoliday = this.CreateObject<WeeklyHoliday>(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
|
|
}
|
|
|
|
return oWeeklyHoliday;
|
|
}
|
|
|
|
public List<WeeklyHoliday> Get(EnumStatus status)
|
|
{
|
|
List<WeeklyHoliday> WeeklyHolidays = new List<WeeklyHoliday>();
|
|
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin();
|
|
|
|
DataReader dr = new DataReader(WeeklyHolidayDA.Get(tc, status));
|
|
WeeklyHolidays = this.CreateObjects<WeeklyHoliday>(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 WeeklyHolidays;
|
|
}
|
|
|
|
public List<WeeklyHoliday> GetCompanyEntireHolidays()
|
|
{
|
|
List<WeeklyHoliday> WeeklyHolidays = new List<WeeklyHoliday>();
|
|
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin();
|
|
|
|
DataReader dr = new DataReader(WeeklyHolidayDA.GetCompanyEntireHolidays(tc));
|
|
WeeklyHolidays = this.CreateObjects<WeeklyHoliday>(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 WeeklyHolidays;
|
|
}
|
|
|
|
public List<WeeklyHoliday> GetByLocation(int LocID)
|
|
{
|
|
List<WeeklyHoliday> WeeklyHolidays = new List<WeeklyHoliday>();
|
|
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin();
|
|
|
|
DataReader dr = new DataReader(WeeklyHolidayDA.GetByLocation(tc, LocID));
|
|
WeeklyHolidays = this.CreateObjects<WeeklyHoliday>(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 WeeklyHolidays;
|
|
}
|
|
|
|
public List<WeeklyHoliday> GetByEmployee(int EmpID)
|
|
{
|
|
List<WeeklyHoliday> WeeklyHolidays = new List<WeeklyHoliday>();
|
|
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin();
|
|
|
|
DataReader dr = new DataReader(WeeklyHolidayDA.GetByEmployee(tc, EmpID));
|
|
WeeklyHolidays = this.CreateObjects<WeeklyHoliday>(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 WeeklyHolidays;
|
|
}
|
|
|
|
public int Save(WeeklyHoliday oWeeklyHoliday)
|
|
{
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin(true);
|
|
if (oWeeklyHoliday.IsNew)
|
|
{
|
|
int id = tc.GenerateID("WeeklyHoliday", "WeeklyHolidayID");
|
|
base.SetObjectID(oWeeklyHoliday, id);
|
|
int seqNo = tc.GenerateID("WeeklyHoliday", "SequenceNo");
|
|
oWeeklyHoliday.Sequence = seqNo;
|
|
WeeklyHolidayDA.Insert(tc, oWeeklyHoliday);
|
|
}
|
|
else
|
|
{
|
|
WeeklyHolidayDA.Update(tc, oWeeklyHoliday);
|
|
}
|
|
|
|
tc.End();
|
|
return oWeeklyHoliday.ID;
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
#region Handle Exception
|
|
|
|
if (tc != null)
|
|
tc.HandleError();
|
|
ExceptionLog.Write(e);
|
|
throw new ServiceException(e.Message, e);
|
|
|
|
#endregion
|
|
}
|
|
}
|
|
|
|
public void Save(List<WeeklyHoliday> oWeeklyHolidays)
|
|
{
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin(true);
|
|
int id = tc.GenerateID("WeeklyHoliday", "WeeklyHolidayID");
|
|
|
|
foreach (WeeklyHoliday item in oWeeklyHolidays)
|
|
{
|
|
if (item.IsNew)
|
|
{
|
|
base.SetObjectID(item, id);
|
|
int seqNo = tc.GenerateID("WeeklyHoliday", "SequenceNo");
|
|
item.Sequence = seqNo;
|
|
item.CreatedBy = item.CreatedBy;
|
|
item.CreatedDate = DateTime.Now;
|
|
WeeklyHolidayDA.Insert(tc, item);
|
|
|
|
id++;
|
|
}
|
|
else
|
|
{
|
|
item.ModifiedBy = item.ModifiedBy;
|
|
item.ModifiedDate = DateTime.Now;
|
|
WeeklyHolidayDA.Update(tc, item);
|
|
}
|
|
}
|
|
|
|
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 Delete(int id)
|
|
{
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin(true);
|
|
WeeklyHolidayDA.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
|
|
} |