EchoTex_Payroll/HRM.DA/Service/UnAuthLeave/UnAuthorizeLeaveParamService.cs
2024-10-14 10:01:49 +06:00

419 lines
14 KiB
C#

using System;
using System.Data;
using Ease.Core.Model;
using Ease.Core.DataAccess;
using Ease.Core;
using System.Collections.Generic;
using Ease.Core.Utility;
using HRM.BO;
namespace HRM.DA
{
public class UnAuthorizeLeaveParamService : ServiceTemplate, IUnAuthorizeLeaveParamService
{
public UnAuthorizeLeaveParamService()
{
}
private void MapObject(UnAuthorizeLeaveParam oUnAuthorizeLeaveParam, DataReader oReader)
{
base.SetObjectID(oUnAuthorizeLeaveParam, (oReader.GetInt32("UaLeaveParamID").Value));
oUnAuthorizeLeaveParam.UnAhuthorizeLeaveID = oReader.GetInt32("UaLeaveID", 0);
this.SetObjectState(oUnAuthorizeLeaveParam, Ease.Core.ObjectState.Saved);
}
protected override T CreateObject<T>(DataReader oReader)
{
UnAuthorizeLeaveParam oUnAuthorizeLeave = new UnAuthorizeLeaveParam();
MapObject(oUnAuthorizeLeave, oReader);
return oUnAuthorizeLeave as T;
}
protected UnAuthorizeLeaveParam CreateObject(DataReader oReader)
{
UnAuthorizeLeaveParam oUnAuthorizeLeave = new UnAuthorizeLeaveParam();
MapObject(oUnAuthorizeLeave, oReader);
return oUnAuthorizeLeave;
}
private void MapObjectGrade(UnAuthorizeLeaveParam.UnAuthorizeLeaveParamGrade ograde, DataReader oReader)
{
ograde.id = oReader.GetInt32("UaLeaveParamIDGradeID").Value;
ograde.paramID = oReader.GetInt32("UaLeaveParamID").Value;
ograde.gradeID = oReader.GetInt32("GradeID").Value;
ograde.gradeNameview = oReader.GetString("GradeName", true, string.Empty);
}
protected List<UnAuthorizeLeaveParam.UnAuthorizeLeaveParamGrade> CreateObjectGrades(DataReader dr)
{
List<UnAuthorizeLeaveParam.UnAuthorizeLeaveParamGrade> olist =
new List<UnAuthorizeLeaveParam.UnAuthorizeLeaveParamGrade>();
while (dr.Read())
{
UnAuthorizeLeaveParam.UnAuthorizeLeaveParamGrade ot =
new UnAuthorizeLeaveParam.UnAuthorizeLeaveParamGrade();
this.MapObjectGrade(ot, dr);
olist.Add(ot);
}
return olist;
}
private void MapDetailObject(UnAuthorizeLeaveParamDetail oUnAuthorizeLeaveParameter, DataReader oReader)
{
base.SetObjectID(oUnAuthorizeLeaveParameter, (oReader.GetInt32("ParamDetailID").Value));
oUnAuthorizeLeaveParameter.LeaveID = oReader.GetInt32("LeaveID", 0);
oUnAuthorizeLeaveParameter.AllowanceID = oReader.GetInt32("ALLOWANCEID", 0);
oUnAuthorizeLeaveParameter.UNLeaveParamID = oReader.GetInt32("UaLeaveParamID", 0);
oUnAuthorizeLeaveParameter.ValueInPercent = oReader.GetDouble("VALUEINPERCENT").Value;
oUnAuthorizeLeaveParameter.Type = (EnumSalaryComponent)oReader.GetInt32("Type").Value;
this.SetObjectState(oUnAuthorizeLeaveParameter, Ease.Core.ObjectState.Saved);
}
protected List<UnAuthorizeLeaveParamDetail> CreateObjectDetails(DataReader dr)
{
List<UnAuthorizeLeaveParamDetail> olist = new List<UnAuthorizeLeaveParamDetail>();
while (dr.Read())
{
UnAuthorizeLeaveParamDetail ot = new UnAuthorizeLeaveParamDetail();
this.MapDetailObject(ot, dr);
olist.Add(ot);
}
return olist;
}
#region Service implementation
public UnAuthorizeLeaveParam Get(int id)
{
UnAuthorizeLeaveParam oUnAuthorizeLeave = new UnAuthorizeLeaveParam();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader oreader = new DataReader(UnAuthorizeLeaveParameterDA.Get(tc, id));
if (oreader.Read())
{
oUnAuthorizeLeave = this.CreateObject<UnAuthorizeLeaveParam>(oreader);
}
oreader.Close();
if (oUnAuthorizeLeave != null)
{
oreader = new DataReader(UnAuthorizeLeaveParameterDA.GetDetail(tc, id));
oUnAuthorizeLeave.Details = this.CreateObjectDetails(oreader);
oreader.Close();
oreader = new DataReader(UnAuthorizeLeaveParameterDA.GetGrades(tc, id));
oUnAuthorizeLeave.paramGrades = this.CreateObjectGrades(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 oUnAuthorizeLeave;
}
public List<UnAuthorizeLeaveParam> Get(int payrollTypeid, bool withDetail)
{
List<UnAuthorizeLeaveParam> unAuthorizeLeaves = null;
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(UnAuthorizeLeaveParameterDA.GetbyPayrollType(tc,payrollTypeid));
unAuthorizeLeaves = this.CreateObjects<UnAuthorizeLeaveParam>(dr);
dr.Close();
if (unAuthorizeLeaves != null && withDetail==true)
{
dr = new DataReader(UnAuthorizeLeaveParameterDA.GetAllGrades(tc));
List<UnAuthorizeLeaveParam.UnAuthorizeLeaveParamGrade> ogrades = this.CreateObjectGrades(dr);
dr.Close();
if(ogrades!=null)
{
unAuthorizeLeaves.ForEach(x =>
{
x.paramGrades = ogrades.FindAll(g => g.paramID == x.ID);
});
}
dr = new DataReader(UnAuthorizeLeaveParameterDA.GetAllDetail(tc));
List<UnAuthorizeLeaveParamDetail> dtls = this.CreateObjectDetails(dr);
dr.Close();
if (dtls != null)
{
unAuthorizeLeaves.ForEach(x =>
{
x.Details = dtls.FindAll(g => g.UNLeaveParamID == x.ID);
});
}
}
tc.End();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
return unAuthorizeLeaves;
}
public List<UnAuthorizeLeaveParam> GetByGrade(int gradeID)
{
List<UnAuthorizeLeaveParam> unAuthorizeLeaves = null;
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(UnAuthorizeLeaveParameterDA.GetbygradeID(tc, gradeID));
unAuthorizeLeaves = this.CreateObjects<UnAuthorizeLeaveParam>(dr);
dr.Close();
if (unAuthorizeLeaves != null )
{
dr = new DataReader(UnAuthorizeLeaveParameterDA.GetAllGrades(tc));
List<UnAuthorizeLeaveParam.UnAuthorizeLeaveParamGrade> ogrades = this.CreateObjectGrades(dr);
dr.Close();
if (ogrades != null)
{
unAuthorizeLeaves.ForEach(x =>
{
x.paramGrades = ogrades.FindAll(g => g.paramID == x.ID);
});
}
dr = new DataReader(UnAuthorizeLeaveParameterDA.GetAllDetail(tc));
List<UnAuthorizeLeaveParamDetail> dtls = this.CreateObjectDetails(dr);
dr.Close();
if (dtls != null)
{
unAuthorizeLeaves.ForEach(x =>
{
x.Details = dtls.FindAll(g => g.UNLeaveParamID == x.ID);
});
}
}
tc.End();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
return unAuthorizeLeaves;
}
public List<UnAuthorizeLeaveParam.UnAuthorizeLeaveParamGrade> GetUsedGrades(int UaLeaveID)
{
List<UnAuthorizeLeaveParam.UnAuthorizeLeaveParamGrade> ogrades =
new List<UnAuthorizeLeaveParam.UnAuthorizeLeaveParamGrade>();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(UnAuthorizeLeaveParameterDA.GetUsedGrades(tc, UaLeaveID));
ogrades = this.CreateObjectGrades(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 ogrades;
}
public List<UnAuthorizeLeaveParam> GetByLeaveID(int nLeaveID)
{
List<UnAuthorizeLeaveParam> unAuthorizeLeaves = null;
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(UnAuthorizeLeaveParameterDA.GetByLeaveID(tc, nLeaveID));
unAuthorizeLeaves = this.CreateObjects<UnAuthorizeLeaveParam>(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 unAuthorizeLeaves;
}
//public List<EmployeeSetupParameter> ApplicableParameters(List<Employee> employees)
//{
// SetupDetailService oSetupDetailsService = new SetupDetailService();
// List<SetupDetail> details = oSetupDetailsService.GetParameters(EnumParameterSetup.SalaryDeduct);
// List<EnmSetupManagerTranType> types = oSetupDetailsService.GetTypes(EnumParameterSetup.SalaryDeduct);
// List<EmployeeSetupParameter> empParametes = new List<EmployeeSetupParameter>();
// foreach (Employee emp in employees)
// {
// EmployeeSetupParameter empparameter = new EmployeeSetupParameter(EnumParameterSetup.SalaryDeduct);
// empparameter.Employee = emp;
// empparameter.ParameterIDs = SetupManager.ApplicableParameters(emp, EnumParameterSetup.SalaryDeduct, types, details);
// empParametes.Add(empparameter);
// }
// return empParametes;
//}
public int Save(UnAuthorizeLeaveParam oUnAuthorizeLeaveParam)
{
TransactionContext tc = null;
int id = 0;
try
{
tc = TransactionContext.Begin(true);
if (oUnAuthorizeLeaveParam.IsNew)
{
id = tc.GenerateID("UALeaveParam", "UaLeaveParamID");
base.SetObjectID(oUnAuthorizeLeaveParam, (id));
UnAuthorizeLeaveParameterDA.Insert(tc, oUnAuthorizeLeaveParam);
}
else
{
UnAuthorizeLeaveParameterDA.Update(tc, oUnAuthorizeLeaveParam);
UnAuthorizeLeaveParameterDA.DeleteDetail(tc, oUnAuthorizeLeaveParam.ID);
UnAuthorizeLeaveParameterDA.DeleteGrade(tc, oUnAuthorizeLeaveParam.ID);
}
foreach (UnAuthorizeLeaveParamDetail detail in oUnAuthorizeLeaveParam.Details)
{
id = tc.GenerateID("LEAVESUSPENSEDEDUCT", "ParamDetailID");
base.SetObjectID(detail, (id));
detail.UNLeaveParamID = oUnAuthorizeLeaveParam.ID;
detail.LeaveID = oUnAuthorizeLeaveParam.UnAhuthorizeLeaveID;
UnAuthorizeLeaveParameterDA.Insert(tc, detail);
}
foreach (UnAuthorizeLeaveParam.UnAuthorizeLeaveParamGrade item in oUnAuthorizeLeaveParam.paramGrades)
{
item.id = tc.GenerateID("UALeaveParamGrade", "UaLeaveParamIDGradeID");
item.paramID = oUnAuthorizeLeaveParam.ID;
UnAuthorizeLeaveParameterDA.InsertGrade(tc, item);
}
//SetupDetailService sdetailService = new SetupDetailService();
//sdetailService.Insert(tc, EnumParameterSetup.SalaryDeduct,
// oUnAuthorizeLeaveParam.SetupDetails, oUnAuthorizeLeaveParam.ID);
tc.End();
return oUnAuthorizeLeaveParam.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);
UnAuthorizeLeaveParameterDA.Delete(tc, id);
UnAuthorizeLeaveParameterDA.DeleteGrade(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
}
}