CEL_Payroll/Payroll.Service/OverTime/Service/TermService.cs

250 lines
7.3 KiB
C#
Raw Permalink 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 Term Service
[Serializable]
public class TermService : ServiceTemplate, ITermService
{
#region Private functions and declaration
Cache _cache = new Cache(typeof(Term));
#endregion
public TermService() { }
private void MapObject(Term oTerm, DataReader oReader)
{
base.SetObjectID(oTerm, oReader.GetID("termID"));
oTerm.Code = oReader.GetString("code");
oTerm.Name = oReader.GetString("name");
oTerm.TermType = (EnumTermType)oReader.GetInt32("TermType").Value;
oTerm.Sequence = oReader.GetInt32("SequenceNo").Value;
oTerm.Status = (EnumStatus)oReader.GetInt32("Status").Value;
oTerm.CreatedBy = oReader.GetID("CreatedBy");
oTerm.CreatedDate = oReader.GetDateTime("CreationDate").Value;
oTerm.ModifiedBy = oReader.GetID("ModifiedBy");
oTerm.ModifiedDate = oReader.GetDateTime("ModifiedDate");
oTerm.EntityMode = (EnumEntityMode)oReader.GetInt32("EntityMode").Value;
oTerm.MaxValue = oReader.GetDouble("MaxValue").Value;
oTerm.ItemCode = oReader.GetString("ItemCode");
oTerm.IsFestival = oReader.GetBoolean("IsFestival").Value;
this.SetObjectState(oTerm, Ease.CoreV35.ObjectState.Saved);
}
protected override T CreateObject<T>(DataReader oReader)
{
Term oTerm = new Term();
MapObject(oTerm, oReader);
return oTerm as T;
}
protected Term CreateObject(DataReader oReader)
{
Term oTerm = new Term();
MapObject(oTerm, oReader);
return oTerm;
}
#region Service implementation
public Term Get(ID id)
{
Term oTerm = new Term();
#region Cache Header
oTerm = _cache["Get", id] as Term;
if (oTerm != null)
return oTerm;
#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader oreader = new DataReader(TermDA.Get(tc, id));
if (oreader.Read())
{
oTerm = this.CreateObject<Term>(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(oTerm, "Get", id);
#endregion
return oTerm;
}
public string GetNextCode()
{
TransactionContext tc = null;
string _code = "";
try
{
tc = TransactionContext.Begin();
_code = GlobalFunctionService.GetMaxCode(tc, "term", "codeautogenerate", "Term", "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 ObjectsTemplate<Term> Get(EnumStatus status)
{
#region Cache Header
ObjectsTemplate<Term> terms = _cache["Get",status] as ObjectsTemplate<Term>;
if (terms != null)
return terms;
#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(TermDA.Get(tc,status));
terms = this.CreateObjects<Term>(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(terms, "Get",status);
#endregion
return terms;
}
public ObjectsTemplate<Term> GetBySlabTerm(EnumTermType slabType)
{
#region Cache Header
ObjectsTemplate<Term> terms = _cache["Get",slabType] as ObjectsTemplate<Term>;
if (terms != null)
return terms;
#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(TermDA.GetBySlabTerm(tc,slabType));
terms = this.CreateObjects<Term>(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(terms, "Get",slabType);
#endregion
return terms;
}
public ID Save(Term oTerm)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
if (oTerm.IsNew)
{
int id = tc.GenerateID("Term", "TermID");
base.SetObjectID(oTerm, ID.FromInteger(id));
int seqNo = tc.GenerateID("Term", "SequenceNO");
oTerm.Sequence = seqNo;
TermDA.Insert(tc, oTerm);
}
else
{
TermDA.Update(tc, oTerm);
}
tc.End();
return oTerm.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);
TermDA.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
}
}
#endregion
}
#endregion
}