212 lines
7.1 KiB
C#
212 lines
7.1 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using Ease.CoreV35.Model;
|
|
using Payroll.BO;
|
|
using Ease.CoreV35.Caching;
|
|
using Ease.CoreV35.DataAccess;
|
|
using Payroll.Service.Attendence.DA;
|
|
using Payroll.BO;
|
|
|
|
namespace Payroll.Service.Attendence.Service
|
|
{
|
|
#region BuyerSetup Service
|
|
[Serializable]
|
|
public class BuyerSetupService : ServiceTemplate, IBuyerSetupService
|
|
{
|
|
#region Private functions and declaration
|
|
Cache _cache = new Cache(typeof(BuyerSetup));
|
|
|
|
#endregion
|
|
public BuyerSetupService() { }
|
|
|
|
private void MapObject(BuyerSetup oBuyerSetup, DataReader oReader)
|
|
{
|
|
base.SetObjectID(oBuyerSetup, oReader.GetID("BuyerSetupID"));
|
|
|
|
oBuyerSetup.Name = oReader.GetString("Name");
|
|
oBuyerSetup.AcceptHour = oReader.GetDouble("AcceptHour").HasValue ? oReader.GetDouble("AcceptHour").Value : 0;
|
|
oBuyerSetup.IsCurrent = oReader.GetBoolean("IsCurrent").Value;
|
|
oBuyerSetup.IsHolidayOTAllowed = oReader.GetBoolean("IsHolidayOTAllowed").Value;
|
|
oBuyerSetup.MaxHolidayOTHour = oReader.GetDouble("MaxHolidayOTHour").HasValue ? oReader.GetDouble("MaxHolidayOTHour").Value : 0;
|
|
oBuyerSetup.MaxHDInMonth = oReader.GetInt32("MaxHDInMonth").Value;
|
|
oBuyerSetup.Sequence = oReader.GetInt32("SequenceNo").Value;
|
|
oBuyerSetup.Status = (EnumStatus)oReader.GetInt32("Status").Value;
|
|
oBuyerSetup.CreatedBy = oReader.GetID("CreatedBy");
|
|
oBuyerSetup.CreatedDate = oReader.GetDateTime("CreatedDate").Value;
|
|
oBuyerSetup.ModifiedBy = oReader.GetID("ModifiedBy");
|
|
oBuyerSetup.ModifiedDate = oReader.GetDateTime("ModifiedDate");
|
|
|
|
this.SetObjectState(oBuyerSetup, Ease.CoreV35.ObjectState.Saved);
|
|
}
|
|
protected override T CreateObject<T>(DataReader oReader)
|
|
{
|
|
BuyerSetup oBuyerSetup = new BuyerSetup();
|
|
MapObject(oBuyerSetup, oReader);
|
|
return oBuyerSetup as T;
|
|
}
|
|
protected BuyerSetup CreateObject(DataReader oReader)
|
|
{
|
|
BuyerSetup oBuyerSetup = new BuyerSetup();
|
|
MapObject(oBuyerSetup, oReader);
|
|
return oBuyerSetup;
|
|
}
|
|
#region Service implementation
|
|
|
|
public BuyerSetup Get(ID id)
|
|
{
|
|
BuyerSetup oBuyerSetup = new BuyerSetup();
|
|
#region Cache Header
|
|
oBuyerSetup = _cache["Get", id] as BuyerSetup;
|
|
if (oBuyerSetup != null)
|
|
return oBuyerSetup;
|
|
#endregion
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin();
|
|
DataReader oreader = new DataReader(BuyerSetupDA.Get(tc, id));
|
|
if (oreader.Read())
|
|
{
|
|
oBuyerSetup = this.CreateObject<BuyerSetup>(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(oBuyerSetup, "Get", id);
|
|
#endregion
|
|
return oBuyerSetup;
|
|
}
|
|
|
|
public BuyerSetup GetCurrentBuyer()
|
|
{
|
|
BuyerSetup oBuyerSetup = new BuyerSetup();
|
|
#region Cache Header
|
|
oBuyerSetup = _cache["Get"] as BuyerSetup;
|
|
if (oBuyerSetup != null)
|
|
return oBuyerSetup;
|
|
#endregion
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin();
|
|
DataReader oreader = new DataReader(BuyerSetupDA.GetCurrentBuyer(tc));
|
|
if (oreader.Read())
|
|
{
|
|
oBuyerSetup = this.CreateObject<BuyerSetup>(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(oBuyerSetup, "Get");
|
|
#endregion
|
|
return oBuyerSetup;
|
|
}
|
|
|
|
public ObjectsTemplate<BuyerSetup> Get()
|
|
{
|
|
#region Cache Header
|
|
ObjectsTemplate<BuyerSetup> buyerSetups = _cache["Get"] as ObjectsTemplate<BuyerSetup>;
|
|
if (buyerSetups != null)
|
|
return buyerSetups;
|
|
#endregion
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin();
|
|
DataReader dr = new DataReader(BuyerSetupDA.Get(tc));
|
|
buyerSetups = this.CreateObjects<BuyerSetup>(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(buyerSetups, "Get");
|
|
#endregion
|
|
return buyerSetups;
|
|
}
|
|
|
|
public ID Save(BuyerSetup oBuyerSetup)
|
|
{
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin(true);
|
|
if (oBuyerSetup.IsNew)
|
|
{
|
|
int id = tc.GenerateID("BuyerSetup", "BuyerSetupID");
|
|
base.SetObjectID(oBuyerSetup, ID.FromInteger(id));
|
|
BuyerSetupDA.Insert(tc, oBuyerSetup);
|
|
}
|
|
else
|
|
{
|
|
BuyerSetupDA.Update(tc, oBuyerSetup);
|
|
}
|
|
tc.End();
|
|
return oBuyerSetup.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);
|
|
BuyerSetupDA.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
|
|
}
|