315 lines
9.7 KiB
C#
315 lines
9.7 KiB
C#
using System;
|
|
using System.Data;
|
|
using System.Linq;
|
|
using Ease.CoreV35;
|
|
using Ease.CoreV35.Model;
|
|
using Ease.CoreV35.DataAccess;
|
|
using System.Collections.Generic;
|
|
using Payroll.BO;
|
|
using Ease.CoreV35.Caching;
|
|
|
|
namespace Payroll.Service
|
|
{
|
|
public class EmployeeShortLeaveService : ServiceTemplate, IEmployeeShortLeaveService
|
|
{
|
|
#region Private functions and declaration
|
|
Cache _cache = new Cache(typeof(EmployeeShortLeave));
|
|
|
|
public EmployeeShortLeaveService() { }
|
|
|
|
private void MapObject(EmployeeShortLeave sLeave, DataReader oReader)
|
|
{
|
|
base.SetObjectID(sLeave, oReader.GetID("ShortLeaveID"));
|
|
sLeave.EmployeeID = oReader.GetInt32("EmployeeID").Value;
|
|
sLeave.Description = oReader.GetString("Description");
|
|
sLeave.FromDate = oReader.GetDateTime("FromDate").Value;
|
|
sLeave.ToDate = oReader.GetDateTime("ToDate").Value;
|
|
sLeave.ShortLeaveType = (EnumShortLeaveType)oReader.GetInt32("ShortLeaveType");
|
|
sLeave.WillReturn = oReader.GetBoolean("WillReturn").Value;
|
|
this.SetObjectState(sLeave, Ease.CoreV35.ObjectState.Saved);
|
|
|
|
|
|
}
|
|
protected override T CreateObject<T>(DataReader oReader)
|
|
{
|
|
EmployeeShortLeave sLeave = new EmployeeShortLeave();
|
|
MapObject(sLeave, oReader);
|
|
return sLeave as T;
|
|
}
|
|
private EmployeeShortLeave CreateObject(DataReader oReader)
|
|
{
|
|
EmployeeShortLeave sLeave = new EmployeeShortLeave();
|
|
MapObject(sLeave, oReader);
|
|
return sLeave;
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Service implementation
|
|
|
|
public EmployeeShortLeave Get()
|
|
{
|
|
EmployeeShortLeave sLeave = new EmployeeShortLeave();
|
|
#region Cache Header
|
|
sLeave = (EmployeeShortLeave)_cache["Get"];
|
|
if (sLeave != null)
|
|
return sLeave;
|
|
#endregion
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin();
|
|
DataReader oreader = new DataReader(EmployeeShortLeaveDA.Get(tc));
|
|
if (oreader.Read())
|
|
{
|
|
sLeave = this.CreateObject<EmployeeShortLeave>(oreader);
|
|
}
|
|
oreader.Close();
|
|
tc.End();
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
#region Handle Exception
|
|
if (tc != null)
|
|
tc.HandleError();
|
|
ExceptionLog.Write(e);
|
|
throw new ServiceException("Failed to Get ShortLeave", e);
|
|
#endregion
|
|
}
|
|
#region Cache Footer
|
|
_cache.Add(sLeave, "Get");
|
|
#endregion
|
|
return sLeave;
|
|
}
|
|
|
|
public EmployeeShortLeave Get(ID id)
|
|
{
|
|
EmployeeShortLeave sLeave = new EmployeeShortLeave();
|
|
#region Cache Header
|
|
sLeave = (EmployeeShortLeave)_cache["Get", id.Integer];
|
|
if (sLeave != null)
|
|
return sLeave;
|
|
#endregion
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin();
|
|
DataReader oreader = new DataReader(EmployeeShortLeaveDA.Get(tc, id.Integer));
|
|
if (oreader.Read())
|
|
{
|
|
sLeave = this.CreateObject<EmployeeShortLeave>(oreader);
|
|
}
|
|
oreader.Close();
|
|
tc.End();
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
#region Handle Exception
|
|
if (tc != null)
|
|
tc.HandleError();
|
|
ExceptionLog.Write(e);
|
|
throw new ServiceException("Failed to Get ShortLeave", e);
|
|
#endregion
|
|
}
|
|
#region Cache Footer
|
|
_cache.Add(sLeave, "Get", id.Integer);
|
|
#endregion
|
|
return sLeave;
|
|
}
|
|
|
|
public EmployeeShortLeave GetByType(int sLType)
|
|
{
|
|
EmployeeShortLeave sLeave = new EmployeeShortLeave();
|
|
#region Cache Header
|
|
sLeave = (EmployeeShortLeave)_cache["Get", sLType];
|
|
if (sLeave != null)
|
|
return sLeave;
|
|
#endregion
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin();
|
|
DataReader oreader = new DataReader(EmployeeShortLeaveDA.Get(tc, sLType));
|
|
if (oreader.Read())
|
|
{
|
|
sLeave = this.CreateObject<EmployeeShortLeave>(oreader);
|
|
}
|
|
oreader.Close();
|
|
tc.End();
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
#region Handle Exception
|
|
if (tc != null)
|
|
tc.HandleError();
|
|
ExceptionLog.Write(e);
|
|
throw new ServiceException("Failed to Get ShortLeave", e);
|
|
#endregion
|
|
}
|
|
#region Cache Footer
|
|
_cache.Add(sLeave, "Get", sLType);
|
|
#endregion
|
|
return sLeave;
|
|
}
|
|
|
|
|
|
public EmployeeShortLeave GetByEmpID(int employeeID)
|
|
{
|
|
EmployeeShortLeave sLeave = new EmployeeShortLeave();
|
|
#region Cache Header
|
|
sLeave = (EmployeeShortLeave)_cache["Get", employeeID];
|
|
if (sLeave != null)
|
|
return sLeave;
|
|
#endregion
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin();
|
|
DataReader oreader = new DataReader(EmployeeShortLeaveDA.Get(tc, employeeID));
|
|
if (oreader.Read())
|
|
{
|
|
sLeave = this.CreateObject<EmployeeShortLeave>(oreader);
|
|
}
|
|
oreader.Close();
|
|
tc.End();
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
#region Handle Exception
|
|
if (tc != null)
|
|
tc.HandleError();
|
|
ExceptionLog.Write(e);
|
|
throw new ServiceException("Failed to Get ShortLeave", e);
|
|
#endregion
|
|
}
|
|
#region Cache Footer
|
|
_cache.Add(sLeave, "Get", employeeID);
|
|
#endregion
|
|
return sLeave;
|
|
}
|
|
|
|
public ObjectsTemplate<EmployeeShortLeave> GetByEmp(int employeeID)
|
|
{
|
|
#region Cache Header
|
|
|
|
ObjectsTemplate<EmployeeShortLeave> leaves = _cache["Get", employeeID] as ObjectsTemplate<EmployeeShortLeave>;
|
|
if (leaves != null)
|
|
return leaves;
|
|
|
|
#endregion
|
|
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin();
|
|
|
|
DataReader dr = new DataReader(EmployeeShortLeaveDA.GetByEmp(tc, employeeID));
|
|
leaves = this.CreateObjects<EmployeeShortLeave>(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(leaves, "Get", employeeID);
|
|
|
|
#endregion
|
|
|
|
return leaves;
|
|
}
|
|
|
|
|
|
public DataSet GetEmployeeWiseShortLeaveReport(int empId)
|
|
{
|
|
DataSet oSet;
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin();
|
|
oSet = EmployeeShortLeaveDA.GetEmployeeWiseShortLeaveReport(tc, empId);
|
|
tc.End();
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
#region Handle Exception
|
|
if (tc != null)
|
|
tc.HandleError();
|
|
|
|
ExceptionLog.Write(e);
|
|
throw new ServiceException("Failed to Get Report" + e.Message, e);
|
|
#endregion
|
|
}
|
|
return oSet;
|
|
}
|
|
|
|
|
|
public ID Save(EmployeeShortLeave sLeave)
|
|
{
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin(true);
|
|
if (sLeave.IsNew)
|
|
{
|
|
int id = tc.GenerateID("ShortLeave", "ShortLeaveID");
|
|
base.SetObjectID(sLeave, ID.FromInteger(id));
|
|
|
|
EmployeeShortLeaveDA.Insert(tc, sLeave);
|
|
}
|
|
else
|
|
{
|
|
EmployeeShortLeaveDA.Update(tc, sLeave);
|
|
}
|
|
tc.End();
|
|
return sLeave.ID;
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
#region Handle Exception
|
|
if (tc != null)
|
|
tc.HandleError();
|
|
ExceptionLog.Write(e);
|
|
throw new Exception("Failed to Save Short Leave. Because " + e.Message, e);
|
|
#endregion
|
|
}
|
|
|
|
}
|
|
|
|
public void Delete(ID id)
|
|
{
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin(true);
|
|
EmployeeShortLeaveDA.Delete(tc, id.Integer);
|
|
tc.End();
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
#region Handle Exception
|
|
if (tc != null)
|
|
tc.HandleError();
|
|
ExceptionLog.Write(e);
|
|
throw new ServiceException(e.Message, e);
|
|
#endregion
|
|
}
|
|
}
|
|
|
|
|
|
#endregion
|
|
}
|
|
}
|