CEL_Payroll/Payroll.Service/Bonus/Service/DolarRateService.cs

241 lines
7.9 KiB
C#
Raw Permalink Normal View History

2024-09-17 14:30:13 +06:00
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Ease.CoreV35;
using Ease.CoreV35.Model;
using Ease.CoreV35.DataAccess;
using Payroll.BO;
using Ease.CoreV35.Caching;
namespace Payroll.Service
{
[Serializable]
public class DolarRateService : ServiceTemplate, IDolarRateService
{
#region Private functions and declaration
Cache _cache = new Cache(typeof(DolarRate));
#endregion
public DolarRateService() { }
private void MapObject(DolarRate oDolarRate, DataReader oReader)
{
//base.SetObjectID(oDolarRate, oReader.GetID("DolarRateID"));
oDolarRate.MonthDate = oReader.GetDateTime("MonthDate").Value;
oDolarRate.Rate = oReader.GetDouble("Rate").GetValueOrDefault();
oDolarRate.Amount = oReader.GetDouble("Amount").GetValueOrDefault();
oDolarRate.DAPACode = oReader.GetString("DAPACode");
oDolarRate.DDescription = oReader.GetString("DDescription");
oDolarRate.DAccountNo = oReader.GetString("DAccountNo");
oDolarRate.CAPACode = oReader.GetString("CAPACode");
oDolarRate.CDescription = oReader.GetString("CDescription");
oDolarRate.CAccountNo = oReader.GetString("CAccountNo");
oDolarRate.HBInterestRate = oReader.GetDouble("HBInterestRate").GetValueOrDefault();
oDolarRate.PersonalInterestRate = oReader.GetDouble("PersonalInterestRate").GetValueOrDefault();
oDolarRate.VehicleInterestRate = oReader.GetDouble("VehicleInterestRate").GetValueOrDefault();
//oDolarRate.CreatedBy = oReader.GetID("CreatedBy");
//oDolarRate.CreatedDate = oReader.GetDateTime("CreatedDate").Value;
//oDolarRate.ModifiedBy = oReader.GetID("ModifiedBy");
//oDolarRate.ModifiedDate = oReader.GetDateTime("ModifiedDate");
this.SetObjectState(oDolarRate, Ease.CoreV35.ObjectState.Saved);
}
protected override T CreateObject<T>(DataReader oReader)
{
DolarRate oDolarRate = new DolarRate();
MapObject(oDolarRate, oReader);
return oDolarRate as T;
}
protected DolarRate CreateObject(DataReader oReader)
{
DolarRate oDolarRate = new DolarRate();
MapObject(oDolarRate, oReader);
return oDolarRate;
}
#region Service implementation
public DolarRate Get(DateTime dMonthDate)
{
DolarRate oDolarRate = new DolarRate();
#region Cache Header
oDolarRate = (DolarRate)_cache["Get", dMonthDate];
if (oDolarRate != null)
return oDolarRate;
#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader oreader = new DataReader(DolarRateDA.Get(tc, dMonthDate));
if (oreader.Read())
{
oDolarRate = this.CreateObject<DolarRate>(oreader);
}
oreader.Close();
tc.End();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException("Failed to Get DolarRate", e);
#endregion
}
#region Cache Footer
_cache.Add(oDolarRate, "Get", dMonthDate);
#endregion
return oDolarRate;
}
public ObjectsTemplate<DolarRate> Get()
{
#region Cache Header
ObjectsTemplate<DolarRate> oDolarRates = _cache["Get"] as ObjectsTemplate<DolarRate>;
if (oDolarRates != null)
return oDolarRates;
#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(DolarRateDA.Get(tc));
oDolarRates = this.CreateObjects<DolarRate>(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(oDolarRates, "Get");
#endregion
return oDolarRates;
}
public ObjectsTemplate<DolarRate> GetLastSixMonth()
{
#region Cache Header
ObjectsTemplate<DolarRate> oDolarRates = _cache["GetLastSixMonth"] as ObjectsTemplate<DolarRate>;
if (oDolarRates != null)
return oDolarRates;
#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(DolarRateDA.GetLastSixMonth(tc));
oDolarRates = this.CreateObjects<DolarRate>(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(oDolarRates, "GetLastSixMonth");
#endregion
return oDolarRates;
}
public void Save(DolarRate oDolarRate)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
int codeLength = 3;
if (oDolarRate.IsNew)
{
//int id = tc.GenerateID("DolarRate", "DolarRateID");
//base.SetObjectID(oDolarRate, ID.FromInteger(id));
DolarRateDA.Insert(tc, oDolarRate);
}
else
{
DolarRateDA.Update(tc, oDolarRate);
}
tc.End();
//return oDolarRate.MonthDate;
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
}
public void Delete(DateTime dMonthDate)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
DolarRateDA.Delete(tc, dMonthDate);
tc.End();
}
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);
DolarRateDA.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
}
}