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

430 lines
12 KiB
C#

using System;
using System.Data;
using Ease.Core.Model;
using Ease.Core.DataAccess;
using HRM.BO;
using System.Collections.Generic;
using Ease.Core.Utility;
namespace HRM.DA
{
public class EducationLevelService : ServiceTemplate, IEducationLevelService
{
#region constructor
public EducationLevelService()
{
}
#endregion
#region Object
private void MapObject(EducationLevel oEducationLevel, DataReader oReader)
{
base.SetObjectID(oEducationLevel, oReader.GetInt32("EDUCATIONLEVELID").Value);
oEducationLevel.Code = oReader.GetString("CODE");
oEducationLevel.Description = oReader.GetString("DESCRIPTION");
oEducationLevel.EducationTypeID = oReader.GetInt32("EDUCATIONTYPEID", 0);
oEducationLevel.Sequence = oReader.GetInt32("SequenceNo").Value;
oEducationLevel.Status = (EnumStatus)oReader.GetInt32("Status").Value;
oEducationLevel.CreatedBy = oReader.GetInt32("CreatedBy", 0);
oEducationLevel.CreatedDate = oReader.GetDateTime("CreationDate").Value;
oEducationLevel.ModifiedBy = oReader.GetInt32("ModifiedBy", 0);
oEducationLevel.ModifiedDate = oReader.GetDateTime("ModifiedDate");
this.SetObjectState(oEducationLevel, Ease.Core.ObjectState.Saved);
}
protected override T CreateObject<T>(DataReader oReader)
{
EducationLevel oEducationLevel = new EducationLevel();
MapObject(oEducationLevel, oReader);
return oEducationLevel as T;
}
#endregion
#region Service implementation
public EducationLevel Get(int id)
{
EducationLevel oEducationLevel = null;
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader oreader = new DataReader(EducationLevelDA.Get(tc, id));
if (oreader.Read())
{
oEducationLevel = this.CreateObject<EducationLevel>(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 oEducationLevel;
}
public EducationLevel Get(string sCode)
{
EducationLevel oEducationLevels = null;
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader oreader = new DataReader(EducationLevelDA.Get(tc, sCode));
if (oreader.Read())
{
oEducationLevels = this.CreateObject<EducationLevel>(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 oEducationLevels;
}
public List<EducationLevel> Get()
{
List<EducationLevel> educationLevels = new List<EducationLevel>();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(EducationLevelDA.Get(tc));
educationLevels = this.CreateObjects<EducationLevel>(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 educationLevels;
}
public List<EducationLevel> Get(EnumStatus status)
{
List<EducationLevel> oEducationLevels = new List<EducationLevel>();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(EducationLevelDA.Get(tc, status));
oEducationLevels = this.CreateObjects<EducationLevel>(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 oEducationLevels;
}
public List<EducationLevel> Get(EnumStatus status, int payrolltypeid)
{
List<EducationLevel> oEducationLevels = new List<EducationLevel>();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(EducationLevelDA.Get(tc, status));
oEducationLevels = this.CreateObjects<EducationLevel>(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 oEducationLevels;
}
public List<EducationLevel> GetByType(int typeID)
{
List<EducationLevel> oEducationLevels = new List<EducationLevel>();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(EducationLevelDA.GetByType(tc, typeID));
oEducationLevels = this.CreateObjects<EducationLevel>(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 oEducationLevels;
}
public EducationLevel GetByLevelID(int nLevelID)
{
EducationLevel oEducationLevel = null;
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader oreader = new DataReader(EducationLevelDA.GetByLevelID(tc, nLevelID));
if (oreader.Read())
{
oEducationLevel = this.CreateObject<EducationLevel>(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 oEducationLevel;
}
public string GetNextCode()
{
TransactionContext tc = null;
string _code = "";
try
{
tc = TransactionContext.Begin();
_code = GlobalFunctionService.GetMaxCode(tc, "EDUCATIONLEVEL", "Code");
tc.End();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
return _code;
}
public int Save(EducationLevel oEducationLevel)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
if (oEducationLevel.IsNew)
{
int id = tc.GenerateID("EDUCATIONLEVEL", "EDUCATIONLEVELID");
base.SetObjectID(oEducationLevel, id);
oEducationLevel.Code = GlobalFunctionService.GetMaxCode(tc, "EDUCATIONLEVEL", "Code");
EducationLevelDA.Insert(tc, oEducationLevel);
}
else
{
EducationLevelDA.Update(tc, oEducationLevel);
}
tc.End();
return oEducationLevel.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);
EducationLevelDA.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 DataSet GetManpower(string sparam)
{
DataSet oManpowers = new DataSet();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
oManpowers = EducationLevelDA.GetManpower(tc, sparam);
tc.End();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
return oManpowers;
}
internal List<EducationLevel> GetByID(TransactionContext tc, int id)
{
List<EducationLevel> oEducationLevels = new List<EducationLevel>();
try
{
DataReader dr = new DataReader(EducationLevelDA.GetByID(tc, id));
oEducationLevels = this.CreateObjects<EducationLevel>(dr);
dr.Close();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
return oEducationLevels;
}
public List<EducationLevel> GetByLevelIDs(string ids)
{
List<EducationLevel> oEducationLevels = new List<EducationLevel>();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(EducationLevelDA.GetByLevelIDs(tc, ids));
oEducationLevels = this.CreateObjects<EducationLevel>(dr);
dr.Close();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
return oEducationLevels;
}
#endregion
}
}