CEL_Payroll/Payroll.Service/HRBasic/Service/EducationLevelService.cs

370 lines
11 KiB
C#
Raw Normal View History

2024-09-17 14:30:13 +06:00
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
{
#region class EducationLevelService
[Serializable]
public class EducationLevelService : ServiceTemplate, IEducationLevelService
{
#region Private functions and declaration
Cache _cache = new Cache(typeof(EducationLevel));
#endregion
#region constructor
public EducationLevelService() { }
#endregion
#region Object
private void MapObject(EducationLevel oEducationLevel, DataReader oReader)
{
base.SetObjectID(oEducationLevel, oReader.GetID("EDUCATIONLEVELID"));
oEducationLevel.Code = oReader.GetString("CODE");
oEducationLevel.Description = oReader.GetString("DESCRIPTION");
oEducationLevel.EducationTypeID = oReader.GetID("EDUCATIONTYPEID");
oEducationLevel.Sequence = oReader.GetInt32("SequenceNo").Value;
oEducationLevel.Status = (EnumStatus)oReader.GetInt32("Status").Value;
oEducationLevel.CreatedBy = oReader.GetID("CreatedBy");
oEducationLevel.CreatedDate = oReader.GetDateTime("CreationDate").Value;
oEducationLevel.ModifiedBy = oReader.GetID("ModifiedBy");
oEducationLevel.ModifiedDate = oReader.GetDateTime("ModifiedDate");
this.SetObjectState(oEducationLevel, Ease.CoreV35.ObjectState.Saved);
}
protected override T CreateObject<T>(DataReader oReader)
{
EducationLevel oEducationLevel = new EducationLevel();
MapObject(oEducationLevel, oReader);
return oEducationLevel as T;
}
protected EducationLevel CreateObject(DataReader oReader)
{
EducationLevel oEducationLevel = new EducationLevel();
MapObject(oEducationLevel, oReader);
return oEducationLevel;
}
#endregion
#region Service implementation
public EducationLevel Get(ID id)
{
EducationLevel oEducationLevel = new EducationLevel();
#region Cache Header
oEducationLevel = _cache["Get", id] as EducationLevel;
if (oEducationLevel != null)
return oEducationLevel;
#endregion
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
}
#region Cache Footer
_cache.Add(oEducationLevel, "Get", id);
#endregion
return oEducationLevel;
}
public EducationLevel Get(string sCode)
{
EducationLevel oEducationLevels = new EducationLevel();
#region Cache Header
oEducationLevels = _cache["Get", sCode] as EducationLevel;
if (oEducationLevels != null)
return oEducationLevels;
#endregion
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
}
#region Cache Footer
_cache.Add(oEducationLevels, "Get", sCode);
#endregion
return oEducationLevels;
}
public ObjectsTemplate<EducationLevel> Get()
{
#region Cache Header
ObjectsTemplate<EducationLevel> educationLevels = _cache["Get"] as ObjectsTemplate<EducationLevel>;
if (educationLevels != null)
return educationLevels;
#endregion
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
}
#region Cache Footer
_cache.Add(educationLevels, "Get");
#endregion
return educationLevels;
}
public ObjectsTemplate<EducationLevel> Get(EnumStatus status)
{
#region Cache Header
ObjectsTemplate<EducationLevel> oEducationLevels = _cache["Get"] as ObjectsTemplate<EducationLevel>;
if (oEducationLevels != null)
return oEducationLevels;
#endregion
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
}
#region Cache Footer
_cache.Add(oEducationLevels, "Get", status);
#endregion
return oEducationLevels;
}
public ObjectsTemplate<EducationLevel> GetByType(ID typeID)
{
#region Cache Header
ObjectsTemplate<EducationLevel> oEducationLevels = _cache["GetByType"] as ObjectsTemplate<EducationLevel>;
if (oEducationLevels != null)
return oEducationLevels;
#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(EducationLevelDA.GetByType(tc, typeID.Integer));
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
}
#region Cache Footer
_cache.Add(oEducationLevels, "GetByType", typeID);
#endregion
return oEducationLevels;
}
public EducationLevel GetByLevelID(ID nLevelID)
{
EducationLevel oEducationLevel = new EducationLevel();
#region Cache Header
oEducationLevel = _cache["GetByLevelID", nLevelID] as EducationLevel;
if (oEducationLevel != null)
return oEducationLevel;
#endregion
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
}
#region Cache Footer
_cache.Add(oEducationLevel, "GetByLevelID", nLevelID);
#endregion
return oEducationLevel;
}
public ID Save(EducationLevel oEducationLevel)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
if (oEducationLevel.IsNew)
{
int id = tc.GenerateID("EDUCATIONLEVEL", "EDUCATIONLEVELID");
base.SetObjectID(oEducationLevel, ID.FromInteger(id));
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(ID 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;
}
#endregion
}
#endregion
}