183 lines
5.8 KiB
C#
183 lines
5.8 KiB
C#
|
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 TaxInvestment Service
|
|||
|
[Serializable]
|
|||
|
public class TaxInvestmentService : ServiceTemplate, ITaxInvestmentService
|
|||
|
{
|
|||
|
#region Private functions and declaration
|
|||
|
Cache _cache = new Cache(typeof(TaxInvestment));
|
|||
|
|
|||
|
#endregion
|
|||
|
public TaxInvestmentService() { }
|
|||
|
|
|||
|
private void MapObject(TaxInvestment oTaxInvestment, DataReader oReader)
|
|||
|
{
|
|||
|
base.SetObjectID(oTaxInvestment, oReader.GetID("TypeID"));
|
|||
|
oTaxInvestment.Code = oReader.GetString("typeCode");
|
|||
|
oTaxInvestment.Name = oReader.GetString("typeName");
|
|||
|
oTaxInvestment.Sequence = oReader.GetInt32("SequenceNo").Value;
|
|||
|
oTaxInvestment.Status = (EnumStatus)oReader.GetInt32("Status").Value;
|
|||
|
oTaxInvestment.CreatedBy = oReader.GetID("CreatedBy");
|
|||
|
oTaxInvestment.CreatedDate = oReader.GetDateTime("CreationDate").Value;
|
|||
|
oTaxInvestment.ModifiedBy = oReader.GetID("ModifiedBy");
|
|||
|
oTaxInvestment.ModifiedDate = oReader.GetDateTime("ModifiedDate");
|
|||
|
this.SetObjectState(oTaxInvestment, Ease.CoreV35.ObjectState.Saved);
|
|||
|
}
|
|||
|
protected override T CreateObject<T>(DataReader oReader)
|
|||
|
{
|
|||
|
TaxInvestment oTaxInvestment = new TaxInvestment();
|
|||
|
MapObject(oTaxInvestment, oReader);
|
|||
|
return oTaxInvestment as T;
|
|||
|
}
|
|||
|
protected TaxInvestment CreateObject(DataReader oReader)
|
|||
|
{
|
|||
|
TaxInvestment oTaxInvestment = new TaxInvestment();
|
|||
|
MapObject(oTaxInvestment, oReader);
|
|||
|
return oTaxInvestment;
|
|||
|
}
|
|||
|
#region Service implementation
|
|||
|
public TaxInvestment Get(ID id)
|
|||
|
{
|
|||
|
TaxInvestment oTaxInvestment = new TaxInvestment();
|
|||
|
#region Cache Header
|
|||
|
oTaxInvestment = _cache["Get", id] as TaxInvestment;
|
|||
|
if (oTaxInvestment != null)
|
|||
|
return oTaxInvestment;
|
|||
|
#endregion
|
|||
|
TransactionContext tc = null;
|
|||
|
try
|
|||
|
{
|
|||
|
tc = TransactionContext.Begin();
|
|||
|
DataReader oreader = new DataReader(TaxInvestmentDA.Get(tc, id));
|
|||
|
if (oreader.Read())
|
|||
|
{
|
|||
|
oTaxInvestment = this.CreateObject<TaxInvestment>(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(oTaxInvestment, "Get", id);
|
|||
|
#endregion
|
|||
|
return oTaxInvestment;
|
|||
|
}
|
|||
|
|
|||
|
public ObjectsTemplate<TaxInvestment> Get(EnumStatus status)
|
|||
|
{
|
|||
|
#region Cache Header
|
|||
|
|
|||
|
ObjectsTemplate<TaxInvestment> taxInvestments = _cache["Get",status] as ObjectsTemplate<TaxInvestment>;
|
|||
|
if (taxInvestments != null)
|
|||
|
return taxInvestments;
|
|||
|
|
|||
|
#endregion
|
|||
|
|
|||
|
TransactionContext tc = null;
|
|||
|
try
|
|||
|
{
|
|||
|
tc = TransactionContext.Begin();
|
|||
|
|
|||
|
DataReader dr = new DataReader(TaxInvestmentDA.Get(tc,status));
|
|||
|
taxInvestments = this.CreateObjects<TaxInvestment>(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(taxInvestments, "Get",status);
|
|||
|
|
|||
|
#endregion
|
|||
|
|
|||
|
return taxInvestments;
|
|||
|
}
|
|||
|
|
|||
|
public ID Save(TaxInvestment oTaxInvestment)
|
|||
|
{
|
|||
|
TransactionContext tc = null;
|
|||
|
try
|
|||
|
{
|
|||
|
tc = TransactionContext.Begin(true);
|
|||
|
if (oTaxInvestment.IsNew)
|
|||
|
{
|
|||
|
int id = tc.GenerateID("INVTYPE", "TypeID");
|
|||
|
base.SetObjectID(oTaxInvestment, ID.FromInteger(id));
|
|||
|
|
|||
|
int seqNo = tc.GenerateID("INVTYPE", "SequenceNo");
|
|||
|
oTaxInvestment.Sequence = seqNo;
|
|||
|
TaxInvestmentDA.Insert(tc, oTaxInvestment);
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
TaxInvestmentDA.Update(tc, oTaxInvestment);
|
|||
|
}
|
|||
|
tc.End();
|
|||
|
return oTaxInvestment.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);
|
|||
|
TaxInvestmentDA.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
|
|||
|
}
|