CEL_Payroll/Payroll.Service/Attendence/Service/MonthlyWorkPlanService.cs

608 lines
21 KiB
C#
Raw Permalink 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.Service.Attendence.DA;
using Payroll.BO;
using System.Data;
namespace Payroll.Service.Attendence.Service
{
#region MonthlyWorkPlan Service
[Serializable]
public class MonthlyWorkPlanService : ServiceTemplate, IMonthlyWorkPlanService
{
#region Private functions and declaration
Cache _cache = new Cache(typeof(MonthlyWorkPlan));
#endregion
public MonthlyWorkPlanService() { }
private void MapObject(MonthlyWorkPlan oMonthlyWorkPlan, DataReader oReader)
{
base.SetObjectID(oMonthlyWorkPlan, oReader.GetID("MonthlyWorkPlanID"));
oMonthlyWorkPlan.EmployeeID = oReader.GetID("EmployeeID");
oMonthlyWorkPlan.WorkDate = oReader.GetDateTime("WorkDate").Value;
oMonthlyWorkPlan.ShiftID = oReader.GetID("ShiftID");
oMonthlyWorkPlan.HolidayID = oReader.GetID("HolidayID");
oMonthlyWorkPlan.WorkPlanGroupID = oReader.GetID("WorkPlanGroupID");
oMonthlyWorkPlan.Type = (EnumWorkPlanDayType)oReader.GetInt32("Type").Value;
oMonthlyWorkPlan.CreatedBy = oReader.GetID("CreatedBy");
oMonthlyWorkPlan.CreatedDate = oReader.GetDateTime("CreatedDate").Value;
oMonthlyWorkPlan.ModifiedBy = oReader.GetID("ModifiedBy");
oMonthlyWorkPlan.ModifiedDate = oReader.GetDateTime("ModifiedDate");
this.SetObjectState(oMonthlyWorkPlan, Ease.CoreV35.ObjectState.Saved);
}
protected override T CreateObject<T>(DataReader oReader)
{
MonthlyWorkPlan oMonthlyWorkPlan = new MonthlyWorkPlan();
MapObject(oMonthlyWorkPlan, oReader);
return oMonthlyWorkPlan as T;
}
protected MonthlyWorkPlan CreateObject(DataReader oReader)
{
MonthlyWorkPlan oMonthlyWorkPlan = new MonthlyWorkPlan();
MapObject(oMonthlyWorkPlan, oReader);
return oMonthlyWorkPlan;
}
#region Service implementation
public MonthlyWorkPlan Get(ID id)
{
MonthlyWorkPlan oMonthlyWorkPlan = new MonthlyWorkPlan();
#region Cache Header
oMonthlyWorkPlan = _cache["Get", id] as MonthlyWorkPlan;
if (oMonthlyWorkPlan != null)
return oMonthlyWorkPlan;
#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader oreader = new DataReader(MonthlyWorkPlanDA.Get(tc, id));
if (oreader.Read())
{
oMonthlyWorkPlan = this.CreateObject<MonthlyWorkPlan>(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(oMonthlyWorkPlan, "Get", id);
#endregion
return oMonthlyWorkPlan;
}
public MonthlyWorkPlan GetByEmpID(ID nEmpID, DateTime assDate, EnumWorkPlanGroup type)
{
MonthlyWorkPlan oMonthlyWorkPlan = new MonthlyWorkPlan();
#region Cache Header
oMonthlyWorkPlan = _cache["GetByEmpID", nEmpID, assDate, type] as MonthlyWorkPlan;
if (oMonthlyWorkPlan != null)
return oMonthlyWorkPlan;
#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader oreader = new DataReader(MonthlyWorkPlanDA.GetByEmpID(tc, nEmpID, assDate, type));
if (oreader.Read())
{
oMonthlyWorkPlan = this.CreateObject<MonthlyWorkPlan>(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(oMonthlyWorkPlan, "GetByEmpID", nEmpID, assDate, type);
#endregion
return oMonthlyWorkPlan;
}
public MonthlyWorkPlan GetByEmpID(ID nEmpID, DateTime workDate)
{
MonthlyWorkPlan oMonthlyWorkPlan = new MonthlyWorkPlan();
#region Cache Header
oMonthlyWorkPlan = _cache["GetByEmpID", nEmpID, workDate] as MonthlyWorkPlan;
if (oMonthlyWorkPlan != null)
return oMonthlyWorkPlan;
#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader oreader = new DataReader(MonthlyWorkPlanDA.GetByEmpID(tc, nEmpID, workDate));
if (oreader.Read())
{
oMonthlyWorkPlan = this.CreateObject<MonthlyWorkPlan>(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(oMonthlyWorkPlan, "GetByEmpID", nEmpID, workDate);
#endregion
return oMonthlyWorkPlan;
}
public ObjectsTemplate<MonthlyWorkPlan> Get()
{
#region Cache Header
ObjectsTemplate<MonthlyWorkPlan> monthlyWorkPlans = _cache["Get"] as ObjectsTemplate<MonthlyWorkPlan>;
if (monthlyWorkPlans != null)
return monthlyWorkPlans;
#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(MonthlyWorkPlanDA.Get(tc));
monthlyWorkPlans = this.CreateObjects<MonthlyWorkPlan>(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(monthlyWorkPlans, "Get");
#endregion
return monthlyWorkPlans;
}
public ObjectsTemplate<MonthlyWorkPlan> Get(DateTime attnDate)
{
#region Cache Header
ObjectsTemplate<MonthlyWorkPlan> monthlyWorkPlans = _cache["Get", attnDate] as ObjectsTemplate<MonthlyWorkPlan>;
if (monthlyWorkPlans != null)
return monthlyWorkPlans;
#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(MonthlyWorkPlanDA.Get(tc, attnDate));
monthlyWorkPlans = this.CreateObjects<MonthlyWorkPlan>(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(monthlyWorkPlans, "Get", attnDate);
#endregion
return monthlyWorkPlans;
}
public ObjectsTemplate<MonthlyWorkPlan> GetByType(EnumWorkPlanGroup type)
{
#region Cache Header
ObjectsTemplate<MonthlyWorkPlan> monthlyWorkPlans = _cache["GetByType", type] as ObjectsTemplate<MonthlyWorkPlan>;
if (monthlyWorkPlans != null)
return monthlyWorkPlans;
#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(MonthlyWorkPlanDA.GetByType(tc, type));
monthlyWorkPlans = this.CreateObjects<MonthlyWorkPlan>(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(monthlyWorkPlans, "GetByType");
#endregion
return monthlyWorkPlans;
}
public ObjectsTemplate<MonthlyWorkPlan> GetByDateAndWPGType(DateTime dAssDate, EnumWorkPlanGroup type)
{
#region Cache Header
ObjectsTemplate<MonthlyWorkPlan> monthlyWorkPlans = _cache["GetByDateAndWPGType", dAssDate, type] as ObjectsTemplate<MonthlyWorkPlan>;
if (monthlyWorkPlans != null)
return monthlyWorkPlans;
#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(MonthlyWorkPlanDA.GetByDateAndWPGType(tc, dAssDate, type));
monthlyWorkPlans = this.CreateObjects<MonthlyWorkPlan>(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(monthlyWorkPlans, "GetByDateAndWPGType");
#endregion
return monthlyWorkPlans;
}
public ObjectsTemplate<MonthlyWorkPlan> GetByDateAndGroupID(DateTime dAssDate, ID groupID)
{
#region Cache Header
ObjectsTemplate<MonthlyWorkPlan> monthlyWorkPlans = _cache["GetByDateAndGroupID", dAssDate, groupID] as ObjectsTemplate<MonthlyWorkPlan>;
if (monthlyWorkPlans != null)
return monthlyWorkPlans;
#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(MonthlyWorkPlanDA.GetByDateAndGroupID(tc, dAssDate, groupID));
monthlyWorkPlans = this.CreateObjects<MonthlyWorkPlan>(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(monthlyWorkPlans, "GetByDateAndGroupID");
#endregion
return monthlyWorkPlans;
}
public ObjectsTemplate<MonthlyWorkPlan> GetMonthlyDataByEmp(DateTime dAssDate, EnumWorkPlanGroup type, ID nEmpID)
{
#region Cache Header
ObjectsTemplate<MonthlyWorkPlan> monthlyWorkPlans = _cache["GetMonthlyDataByEmp", dAssDate, type, nEmpID] as ObjectsTemplate<MonthlyWorkPlan>;
if (monthlyWorkPlans != null)
return monthlyWorkPlans;
#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(MonthlyWorkPlanDA.GetMonthlyDataByEmp(tc, dAssDate, type, nEmpID));
monthlyWorkPlans = this.CreateObjects<MonthlyWorkPlan>(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(monthlyWorkPlans, "GetMonthlyDataByEmp");
#endregion
return monthlyWorkPlans;
}
public ID Save(MonthlyWorkPlan oMonthlyWorkPlan)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
if (oMonthlyWorkPlan.IsNew)
{
int id = tc.GenerateID("MonthlyWorkPlan", "MonthlyWorkPlanID");
base.SetObjectID(oMonthlyWorkPlan, ID.FromInteger(id));
MonthlyWorkPlanDA.Insert(tc, oMonthlyWorkPlan);
}
else
{
MonthlyWorkPlanDA.Update(tc, oMonthlyWorkPlan);
}
tc.End();
return oMonthlyWorkPlan.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(ObjectsTemplate<MonthlyWorkPlan> oMWPlans)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
foreach (MonthlyWorkPlan oMWPlan in oMWPlans)
{
if (oMWPlan.IsNew)
{
int id = tc.GenerateID("MonthlyWorkPlan", "MonthlyWorkPlanID");
base.SetObjectID(oMWPlan, ID.FromInteger(id));
MonthlyWorkPlanDA.Insert(tc, oMWPlan);
}
else
{
MonthlyWorkPlanDA.Update(tc, oMWPlan);
}
}
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(ID id)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
MonthlyWorkPlanDA.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 Delete(DateTime dFromDate, DateTime dToDate, EnumWorkPlanGroup type)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
MonthlyWorkPlanDA.Delete(tc, dFromDate, dToDate, type);
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(DateTime dFromDate, DateTime dToDate, ID wpGroupID)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
MonthlyWorkPlanDA.Delete(tc, dFromDate, dToDate, wpGroupID);
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(DateTime dFromDate, DateTime dToDate)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
MonthlyWorkPlanDA.Delete(tc, dFromDate, dToDate);
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(DateTime assignDate, string empIDs)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
MonthlyWorkPlanDA.Delete(tc, assignDate, empIDs);
tc.End();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
}
public int DayCount(EnumWorkPlanGroup type)
{
int count;
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
count = MonthlyWorkPlanDA.DayCount(tc, type);
tc.End();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
return count;
}
public DataSet GetMissingEmp(ID groupID, DateTime assignDate)
{
DataSet missingEmp = null;
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
missingEmp = MonthlyWorkPlanDA.GetMissingEmp(tc, groupID, assignDate);
tc.End();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
return missingEmp;
}
public DataSet GetEmpNotInMonthlyWorkPlan(DateTime assignDate)
{
DataSet missingEmp = null;
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
missingEmp = MonthlyWorkPlanDA.GetEmpNotInMonthlyWorkPlan(tc, assignDate);
tc.End();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
return missingEmp;
}
public bool IsExist(DateTime dAssDate, ID groupID)
{
bool isExist = false;
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
isExist = MonthlyWorkPlanDA.IsExist(tc, dAssDate, groupID);
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;
}
#endregion
}
#endregion
}