EchoTex_Payroll/HRM.DA/Service/Attendance/EmployeeOutsideDutyService.cs

306 lines
11 KiB
C#
Raw Permalink Normal View History

2024-10-14 10:01:49 +06:00
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Ease.Core.DataAccess;
using Ease.Core.Model;
using Ease.Core.Utility;
using HRM.BO;
namespace HRM.DA
{
#region EmployeeOutsideDuty Service
[Serializable]
public class EmployeeOutsideDutyService : ServiceTemplate, IEmployeeOutsideDutyService
{
public EmployeeOutsideDutyService()
{
}
private void MapObject(EmployeeOutsideDuty oEmployeeOutsideDuty, DataReader oReader)
{
base.SetObjectID(oEmployeeOutsideDuty, oReader.GetInt32("EmployeeOutsideDutyID").Value);
oEmployeeOutsideDuty.EmployeeID = oReader.GetInt32("EmployeeID", 0);
oEmployeeOutsideDuty.EntryDate = oReader.GetDateTime("EntryDate").Value;
oEmployeeOutsideDuty.StartDate = oReader.GetDateTime("StartDate").Value;
oEmployeeOutsideDuty.EndDate = oReader.GetDateTime("EndDate").Value;
oEmployeeOutsideDuty.Comments = oReader.GetString("Comments");
//oEmployeeOutsideDuty.ShiftID = oReader.GetID("ShiftID");
oEmployeeOutsideDuty.OutsideDutyID = oReader.GetInt32("OutsideDutyID", 0);
oEmployeeOutsideDuty.CreatedBy = oReader.GetInt32("CreatedBy", 0);
oEmployeeOutsideDuty.CreatedDate = oReader.GetDateTime("CreatedDate").Value;
oEmployeeOutsideDuty.ModifiedBy = oReader.GetInt32("ModifiedBy");
oEmployeeOutsideDuty.ModifiedDate = oReader.GetDateTime("ModifiedDate");
this.SetObjectState(oEmployeeOutsideDuty, Ease.Core.ObjectState.Saved);
}
private void MapObject(EmployeeOutsideDutyDetails oEmployeeOutsideDutyDetails, DataReader oReader)
{
base.SetObjectID(oEmployeeOutsideDutyDetails, oReader.GetInt32("EmployeeOutsideDutyID").Value);
oEmployeeOutsideDutyDetails.EmployeeID = oReader.GetInt32("EmployeeID", 0);
oEmployeeOutsideDutyDetails.EmployeeNo = oReader.GetString("EmployeeNo", string.Empty);
oEmployeeOutsideDutyDetails.EmployeeName = oReader.GetString("EmployeeName", string.Empty);
oEmployeeOutsideDutyDetails.EntryDate = oReader.GetDateTime("EntryDate", DateTime.MinValue);
oEmployeeOutsideDutyDetails.StartDate = oReader.GetDateTime("StartDate", DateTime.MinValue);
oEmployeeOutsideDutyDetails.EndDate = oReader.GetDateTime("EndDate", DateTime.MinValue);
oEmployeeOutsideDutyDetails.Comments = oReader.GetString("Comments", string.Empty);
oEmployeeOutsideDutyDetails.OutsideDutyID = oReader.GetInt32("OutsideDutyID", 0);
oEmployeeOutsideDutyDetails.CreatedBy = oReader.GetInt32("CreatedBy", 0);
oEmployeeOutsideDutyDetails.CreatedDate = oReader.GetDateTime("CreatedDate", DateTime.MinValue);
oEmployeeOutsideDutyDetails.ModifiedBy = oReader.GetInt32("ModifiedBy", 0);
oEmployeeOutsideDutyDetails.ModifiedDate = oReader.GetDateTime("ModifiedDate", DateTime.MinValue);
this.SetObjectState(oEmployeeOutsideDutyDetails, Ease.Core.ObjectState.Saved);
}
protected EmployeeOutsideDutyDetails CreateObjectDetails(DataReader oReader)
{
EmployeeOutsideDutyDetails oEmployeeOutsideDutyDetails = new EmployeeOutsideDutyDetails();
MapObject(oEmployeeOutsideDutyDetails, oReader);
return oEmployeeOutsideDutyDetails;
}
protected override T CreateObject<T>(DataReader oReader)
{
EmployeeOutsideDuty oEmployeeOutsideDuty = new EmployeeOutsideDuty();
MapObject(oEmployeeOutsideDuty, oReader);
return oEmployeeOutsideDuty as T;
}
protected EmployeeOutsideDuty CreateObject(DataReader oReader)
{
EmployeeOutsideDuty oEmployeeOutsideDuty = new EmployeeOutsideDuty();
MapObject(oEmployeeOutsideDuty, oReader);
return oEmployeeOutsideDuty;
}
#region Service implementation
public EmployeeOutsideDuty Get(int id)
{
EmployeeOutsideDuty oEmployeeOutsideDuty = new EmployeeOutsideDuty();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader oreader = new DataReader(EmployeeOutsideDutyDA.Get(tc, id));
if (oreader.Read())
{
oEmployeeOutsideDuty = this.CreateObject<EmployeeOutsideDuty>(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 oEmployeeOutsideDuty;
}
public List<EmployeeOutsideDuty> Get()
{
List<EmployeeOutsideDuty> items = new List<EmployeeOutsideDuty>();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
DataReader dr = new DataReader(EmployeeOutsideDutyDA.Get(tc));
items = this.CreateObjects<EmployeeOutsideDuty>(dr);
dr.Close();
EmployeeService employeeService = new EmployeeService();
foreach (EmployeeOutsideDuty item in items)
{
Employee employee = new Employee();
employee = employeeService.Get(tc, item.EmployeeID);
item.Employee = employee;
}
tc.End();
return items;
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
}
public List<EmployeeOutsideDuty> GetByEmpID(int empID)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(EmployeeOutsideDutyDA.GetByEmpID(tc, empID));
var employeeOutsideDutys = this.CreateObjects<EmployeeOutsideDuty>(dr);
dr.Close();
tc.End();
return employeeOutsideDutys;
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
}
public List<EmployeeOutsideDutyDetails> GetByEmpIdDetails(int empID)
{
List<EmployeeOutsideDutyDetails> tempEmployeeOutsideDutyDetails = new List<EmployeeOutsideDutyDetails>();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(EmployeeOutsideDutyDA.GetByEmpIdDetails(tc, empID));
while (dr.Read())
{
tempEmployeeOutsideDutyDetails.Add(this.CreateObjectDetails(dr));
}
dr.Close();
tc.End();
return tempEmployeeOutsideDutyDetails;
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
}
public List<EmployeeOutsideDuty> Get(DateTime attnDate)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(EmployeeOutsideDutyDA.Get(tc, attnDate));
var employeeOutsideDutys = this.CreateObjects<EmployeeOutsideDuty>(dr);
dr.Close();
tc.End();
return employeeOutsideDutys;
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
}
public int Save(EmployeeOutsideDuty oEmployeeOutsideDuty)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
if (oEmployeeOutsideDuty.IsNew)
{
int id = tc.GenerateID("EmployeeOutsideDuty", "EmployeeOutsideDutyID");
base.SetObjectID(oEmployeeOutsideDuty, (id));
EmployeeOutsideDutyDA.Insert(tc, oEmployeeOutsideDuty);
}
else
{
EmployeeOutsideDutyDA.Update(tc, oEmployeeOutsideDuty);
}
tc.End();
return oEmployeeOutsideDuty.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(int id)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
EmployeeOutsideDutyDA.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 bool IsOutsideDutyAvailable(DateTime startDate, DateTime endDate, int empID)
{
bool isExist = false;
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
isExist = EmployeeOutsideDutyDA.IsOutsideDutyAvailable(tc, startDate, endDate, empID);
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
}