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

230 lines
6.8 KiB
C#

using System;
using System.Data;
using Ease.Core.Model;
using Ease.Core.DataAccess;
using Ease.Core;
using System.Collections.Generic;
using Ease.Core.Utility;
using HRM.BO;
namespace HRM.DA
{
public class DolarRateService : ServiceTemplate
{
#region Private functions and declaration
#endregion
public DolarRateService()
{
}
private void MapObject(DolarRate oDolarRate, DataReader oReader)
{
base.SetObjectID(oDolarRate, (oReader.GetInt32("DolarRateID").Value));
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.GetInt32("CreatedBy");
//oDolarRate.CreatedDate = oReader.GetDateTime("CreatedDate").Value;
//oDolarRate.ModifiedBy = oReader.GetInt32("ModifiedBy");
//oDolarRate.ModifiedDate = oReader.GetDateTime("ModifiedDate");
this.SetObjectState(oDolarRate, Ease.Core.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 = null;
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
}
return oDolarRate;
}
public List<DolarRate> Get()
{
List<DolarRate> oDolarRates = null;
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
}
return oDolarRates;
}
public List<DolarRate> GetLastSixMonth()
{
List<DolarRate> oDolarRates = null;
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
}
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));
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(int 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
}
}