562 lines
20 KiB
C#
562 lines
20 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using Ease.CoreV35.Caching;
|
|
using Ease.CoreV35.Model;
|
|
using Payroll.BO;
|
|
using Ease.CoreV35.DataAccess;
|
|
using Payroll.BO;
|
|
using Payroll.Service.Attendence.DA;
|
|
using System.Data;
|
|
|
|
namespace Payroll.Service.Attendence.Service
|
|
{
|
|
#region EmployeeWorkPlanSetup Service
|
|
|
|
[Serializable]
|
|
public class EmployeeWorkPlanSetupService : ServiceTemplate, IEmployeeWorkPlanSetupService
|
|
{
|
|
#region Declaration
|
|
|
|
Cache _cache = new Cache(typeof(EmployeeWorkPlanSetup));
|
|
|
|
#endregion
|
|
|
|
#region Object Mapping
|
|
|
|
private void MapObject(EmployeeWorkPlanSetup oEmployeeWorkPlanSetup, DataReader oReader)
|
|
{
|
|
base.SetObjectID(oEmployeeWorkPlanSetup, oReader.GetID("EmployeeWorkPlanSetupID"));
|
|
oEmployeeWorkPlanSetup.EmployeeID = oReader.GetID("EmployeeID");
|
|
oEmployeeWorkPlanSetup.ShiftID = oReader.GetID("ShiftID");
|
|
oEmployeeWorkPlanSetup.StartDate = oReader.GetDateTime("StartDate").Value;
|
|
oEmployeeWorkPlanSetup.WorkPlanGroupID = oReader.GetID("WorkPlanGroupID");
|
|
|
|
object ovalue = oReader.GetInt32("WeekEndOn");
|
|
if (ovalue != null) oEmployeeWorkPlanSetup.WeekEndOn = (DayOfWeek)ovalue;
|
|
|
|
if (oReader.GetInt32("WeekEndOn").HasValue)
|
|
oEmployeeWorkPlanSetup.WeekEndOn = (DayOfWeek)oReader.GetInt32("WeekEndOn").Value;
|
|
|
|
if (oReader.GetInt32("WeekEndOn2").HasValue)
|
|
oEmployeeWorkPlanSetup.WeekEndOn2 = (DayOfWeek)oReader.GetInt32("WeekEndOn2").Value;
|
|
|
|
if (oReader.GetInt32("SaturdayShift").HasValue)
|
|
oEmployeeWorkPlanSetup.SaturdayShiftID = oReader.GetInt32("SaturdayShift").Value;
|
|
|
|
if (oReader.GetInt32("SundayShift").HasValue)
|
|
oEmployeeWorkPlanSetup.SundayShiftID = oReader.GetInt32("SundayShift").Value;
|
|
|
|
if (oReader.GetInt32("MondayShift").HasValue)
|
|
oEmployeeWorkPlanSetup.MondayShiftID = oReader.GetInt32("MondayShift").Value;
|
|
|
|
if (oReader.GetInt32("TuesdayShift").HasValue)
|
|
oEmployeeWorkPlanSetup.TuesdayShiftID = oReader.GetInt32("TuesdayShift").Value;
|
|
|
|
if (oReader.GetInt32("WednesdayShift").HasValue)
|
|
oEmployeeWorkPlanSetup.WednesdayShiftID = oReader.GetInt32("WednesdayShift").Value;
|
|
|
|
if (oReader.GetInt32("ThursdayShift").HasValue)
|
|
oEmployeeWorkPlanSetup.ThursdayShiftID = oReader.GetInt32("ThursdayShift").Value;
|
|
|
|
if (oReader.GetInt32("FridayShift").HasValue)
|
|
oEmployeeWorkPlanSetup.FridayShiftID = oReader.GetInt32("FridayShift").Value;
|
|
|
|
oEmployeeWorkPlanSetup.CreatedBy = oReader.GetID("CreatedBy");
|
|
oEmployeeWorkPlanSetup.CreatedDate = oReader.GetDateTime("CreatedDate").Value;
|
|
oEmployeeWorkPlanSetup.ModifiedBy = oReader.GetID("ModifiedBy");
|
|
oEmployeeWorkPlanSetup.ModifiedDate = oReader.GetDateTime("ModifiedDate");
|
|
this.SetObjectState(oEmployeeWorkPlanSetup, Ease.CoreV35.ObjectState.Saved);
|
|
}
|
|
protected override T CreateObject<T>(DataReader oReader)
|
|
{
|
|
EmployeeWorkPlanSetup oEmployeeWorkPlanSetup = new EmployeeWorkPlanSetup();
|
|
MapObject(oEmployeeWorkPlanSetup, oReader);
|
|
return oEmployeeWorkPlanSetup as T;
|
|
}
|
|
protected EmployeeWorkPlanSetup CreateObject(DataReader oReader)
|
|
{
|
|
EmployeeWorkPlanSetup oEmployeeWorkPlanSetup = new EmployeeWorkPlanSetup();
|
|
MapObject(oEmployeeWorkPlanSetup, oReader);
|
|
return oEmployeeWorkPlanSetup;
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Service implementation
|
|
|
|
public EmployeeWorkPlanSetup Get(ID id)
|
|
{
|
|
EmployeeWorkPlanSetup oEmployeeWorkPlanSetup = new EmployeeWorkPlanSetup();
|
|
#region Cache Header
|
|
oEmployeeWorkPlanSetup = _cache["Get", id] as EmployeeWorkPlanSetup;
|
|
if (oEmployeeWorkPlanSetup != null)
|
|
return oEmployeeWorkPlanSetup;
|
|
#endregion
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin();
|
|
DataReader oreader = new DataReader(EmployeeWorkPlanSetupDA.Get(tc, id));
|
|
if (oreader.Read())
|
|
{
|
|
oEmployeeWorkPlanSetup = this.CreateObject<EmployeeWorkPlanSetup>(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(oEmployeeWorkPlanSetup, "Get", id);
|
|
#endregion
|
|
return oEmployeeWorkPlanSetup;
|
|
}
|
|
|
|
//public EmployeeWorkPlanSetup Get(ID empID, DateTime attnDate)
|
|
//{
|
|
// EmployeeWorkPlanSetup oEmployeeWorkPlanSetup = new EmployeeWorkPlanSetup();
|
|
// #region Cache Header
|
|
// oEmployeeWorkPlanSetup = _cache["Get", empID, attnDate] as EmployeeWorkPlanSetup;
|
|
// if (oEmployeeWorkPlanSetup != null)
|
|
// return oEmployeeWorkPlanSetup;
|
|
// #endregion
|
|
// TransactionContext tc = null;
|
|
// try
|
|
// {
|
|
// tc = TransactionContext.Begin();
|
|
// DataReader oreader = new DataReader(EmployeeWorkPlanSetupDA.Get(tc, empID, attnDate));
|
|
// if (oreader.Read())
|
|
// {
|
|
// oEmployeeWorkPlanSetup = this.CreateObject<EmployeeWorkPlanSetup>(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(oEmployeeWorkPlanSetup, "Get", empID, attnDate);
|
|
// #endregion
|
|
// return oEmployeeWorkPlanSetup;
|
|
//}
|
|
|
|
public EmployeeWorkPlanSetup GetByEmpID(ID nEmpID)
|
|
{
|
|
EmployeeWorkPlanSetup oEmployeeWorkPlanSetup = new EmployeeWorkPlanSetup();
|
|
#region Cache Header
|
|
oEmployeeWorkPlanSetup = _cache["GetByEmpID", nEmpID] as EmployeeWorkPlanSetup;
|
|
if (oEmployeeWorkPlanSetup != null)
|
|
return oEmployeeWorkPlanSetup;
|
|
#endregion
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin();
|
|
DataReader oreader = new DataReader(EmployeeWorkPlanSetupDA.GetByEmpID(tc, nEmpID));
|
|
if (oreader.Read())
|
|
{
|
|
oEmployeeWorkPlanSetup = this.CreateObject<EmployeeWorkPlanSetup>(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(oEmployeeWorkPlanSetup, "GetByEmpID", nEmpID);
|
|
#endregion
|
|
return oEmployeeWorkPlanSetup;
|
|
}
|
|
|
|
public ObjectsTemplate<EmployeeWorkPlanSetup> Get()
|
|
{
|
|
#region Cache Header
|
|
ObjectsTemplate<EmployeeWorkPlanSetup> employeeWorkPlanSetups = _cache["Get"] as ObjectsTemplate<EmployeeWorkPlanSetup>;
|
|
if (employeeWorkPlanSetups != null)
|
|
return employeeWorkPlanSetups;
|
|
#endregion
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin();
|
|
DataReader dr = new DataReader(EmployeeWorkPlanSetupDA.Get(tc));
|
|
employeeWorkPlanSetups = this.CreateObjects<EmployeeWorkPlanSetup>(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(employeeWorkPlanSetups, "Get");
|
|
#endregion
|
|
return employeeWorkPlanSetups;
|
|
}
|
|
|
|
public ObjectsTemplate<EmployeeWorkPlanSetup> GetByWPGroupID(ID wpGroupID)
|
|
{
|
|
#region Cache Header
|
|
ObjectsTemplate<EmployeeWorkPlanSetup> employeeWorkPlanSetups = _cache["GetByWPGroupID", wpGroupID] as ObjectsTemplate<EmployeeWorkPlanSetup>;
|
|
if (employeeWorkPlanSetups != null)
|
|
return employeeWorkPlanSetups;
|
|
#endregion
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin();
|
|
DataReader dr = new DataReader(EmployeeWorkPlanSetupDA.GetByWPGroupID(tc, wpGroupID));
|
|
employeeWorkPlanSetups = this.CreateObjects<EmployeeWorkPlanSetup>(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(employeeWorkPlanSetups, "GetByWPGroupID", wpGroupID);
|
|
#endregion
|
|
return employeeWorkPlanSetups;
|
|
}
|
|
|
|
public ObjectsTemplate<EmployeeWorkPlanSetup> GetForFixedWP(ID groupID, DayOfWeek holiday)
|
|
{
|
|
#region Cache Header
|
|
|
|
ObjectsTemplate<EmployeeWorkPlanSetup> employeeWorkPlanSetups = _cache["GetForFixedWP", groupID, holiday] as ObjectsTemplate<EmployeeWorkPlanSetup>;
|
|
if (employeeWorkPlanSetups != null)
|
|
return employeeWorkPlanSetups;
|
|
|
|
#endregion
|
|
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin();
|
|
|
|
DataReader dr = new DataReader(EmployeeWorkPlanSetupDA.GetForFixedWP(tc, groupID, holiday));
|
|
employeeWorkPlanSetups = this.CreateObjects<EmployeeWorkPlanSetup>(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(employeeWorkPlanSetups, "GetForFixedWP", groupID, holiday);
|
|
|
|
#endregion
|
|
|
|
return employeeWorkPlanSetups;
|
|
}
|
|
|
|
public ObjectsTemplate<EmployeeWorkPlanSetup> Get(EnumWorkPlanGroup type)
|
|
{
|
|
#region Cache Header
|
|
|
|
ObjectsTemplate<EmployeeWorkPlanSetup> employeeWorkPlanSetups = _cache["Get", type] as ObjectsTemplate<EmployeeWorkPlanSetup>;
|
|
if (employeeWorkPlanSetups != null)
|
|
return employeeWorkPlanSetups;
|
|
|
|
#endregion
|
|
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin();
|
|
|
|
DataReader dr = new DataReader(EmployeeWorkPlanSetupDA.Get(tc, type));
|
|
employeeWorkPlanSetups = this.CreateObjects<EmployeeWorkPlanSetup>(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(employeeWorkPlanSetups, "Get", type);
|
|
|
|
#endregion
|
|
|
|
return employeeWorkPlanSetups;
|
|
}
|
|
|
|
public ObjectsTemplate<EmployeeWorkPlanSetup> GetMissingEmps(ID wpGroupID, DateTime assignDate)
|
|
{
|
|
#region Cache Header
|
|
|
|
ObjectsTemplate<EmployeeWorkPlanSetup> employeeWorkPlanSetups = _cache["GetMissingEmps", wpGroupID, assignDate] as ObjectsTemplate<EmployeeWorkPlanSetup>;
|
|
if (employeeWorkPlanSetups != null)
|
|
return employeeWorkPlanSetups;
|
|
|
|
#endregion
|
|
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin();
|
|
|
|
DataReader dr = new DataReader(EmployeeWorkPlanSetupDA.GetMissingEmps(tc, wpGroupID, assignDate));
|
|
employeeWorkPlanSetups = this.CreateObjects<EmployeeWorkPlanSetup>(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(employeeWorkPlanSetups, "GetMissingEmps", wpGroupID, assignDate);
|
|
|
|
#endregion
|
|
|
|
return employeeWorkPlanSetups;
|
|
}
|
|
|
|
public DataSet GetEmpNotInWorkPlan(int payrollTypeID)
|
|
{
|
|
DataSet empInfo = null;
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin();
|
|
empInfo = EmployeeWorkPlanSetupDA.GetEmpNotInWorkPlan(tc, payrollTypeID);
|
|
tc.End();
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
#region Handle Exception
|
|
|
|
if (tc != null)
|
|
tc.HandleError();
|
|
ExceptionLog.Write(e);
|
|
|
|
throw new ServiceException(e.Message, e);
|
|
|
|
#endregion
|
|
}
|
|
return empInfo;
|
|
}
|
|
|
|
public ID Save(EmployeeWorkPlanSetup oEmployeeWorkPlanSetup)
|
|
{
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin(true);
|
|
if (oEmployeeWorkPlanSetup.IsNew)
|
|
{
|
|
EmployeeWorkPlanSetupDA.DeleteExistingData(tc, oEmployeeWorkPlanSetup.EmployeeID);
|
|
int id = tc.GenerateID("EmployeeWorkPlanSetup", "EmployeeWorkPlanSetupID");
|
|
base.SetObjectID(oEmployeeWorkPlanSetup, ID.FromInteger(id));
|
|
EmployeeWorkPlanSetupDA.Insert(tc, oEmployeeWorkPlanSetup);
|
|
}
|
|
else
|
|
{
|
|
EmployeeWorkPlanSetupDA.Update(tc, oEmployeeWorkPlanSetup);
|
|
}
|
|
tc.End();
|
|
return oEmployeeWorkPlanSetup.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<EmployeeWorkPlanSetup> oEmpWPSetups)
|
|
{
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin(true);
|
|
|
|
//EmployeeWorkPlanSetupDA.Delete(oEmpWPSetups[0].WorkPlanGroupID,tc);
|
|
foreach (EmployeeWorkPlanSetup oEMpSetup in oEmpWPSetups)
|
|
{
|
|
EmployeeWorkPlanSetupDA.DeleteExistingData(tc, oEMpSetup.EmployeeID);
|
|
int id = tc.GenerateID("EmployeeWorkPlanSetup", "EmployeeWorkPlanSetupID");
|
|
base.SetObjectID(oEMpSetup, ID.FromInteger(id));
|
|
EmployeeWorkPlanSetupDA.Insert(tc, oEMpSetup);
|
|
}
|
|
|
|
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);
|
|
EmployeeWorkPlanSetupDA.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(ID groupID, DayOfWeek weekEndOn)
|
|
{
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin(true);
|
|
EmployeeWorkPlanSetupDA.Delete(tc, groupID, weekEndOn);
|
|
tc.End();
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
#region Handle Exception
|
|
if (tc != null)
|
|
tc.HandleError();
|
|
ExceptionLog.Write(e);
|
|
throw new ServiceException(e.Message, e);
|
|
#endregion
|
|
}
|
|
}
|
|
|
|
public bool IsExist(ID groupID, DayOfWeek weekEndOn)
|
|
{
|
|
bool isExist = false;
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin();
|
|
isExist = EmployeeWorkPlanSetupDA.IsExist(tc, groupID, weekEndOn);
|
|
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;
|
|
}
|
|
|
|
//for excel Upload
|
|
public void Save(TransactionContext tc, ObjectsTemplate<EmployeeWorkPlanSetup> oEmpWPSetups)
|
|
{
|
|
try
|
|
{
|
|
foreach (EmployeeWorkPlanSetup oEMpSetup in oEmpWPSetups)
|
|
{
|
|
int id = tc.GenerateID("EmployeeWorkPlanSetup", "EmployeeWorkPlanSetupID");
|
|
base.SetObjectID(oEMpSetup, ID.FromInteger(id));
|
|
oEMpSetup.CreatedBy = User.CurrentUser.ID;
|
|
oEMpSetup.CreatedDate = DateTime.Now;
|
|
EmployeeWorkPlanSetupDA.Insert(tc, oEMpSetup);
|
|
}
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
#region Handle Exception
|
|
if (tc != null)
|
|
tc.HandleError();
|
|
ExceptionLog.Write(e);
|
|
throw new ServiceException(e.Message, e);
|
|
#endregion
|
|
}
|
|
}
|
|
//
|
|
#endregion
|
|
}
|
|
|
|
#endregion
|
|
}
|