CEL_Payroll/Payroll.Service/CarFuel/Service/CarFuelItemService.cs

289 lines
8.9 KiB
C#
Raw 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 CarFuelItem Service
[Serializable]
public class CarFuelItemService : ServiceTemplate, ICarFuelItemService
{
#region Private functions and declaration
Cache _cache = new Cache(typeof(CarFuelItem));
public CarFuelItemService() { }
private void MapObject(CarFuelItem oCarFuelItem, DataReader oReader)
{
base.SetObjectID(oCarFuelItem, oReader.GetID("CarFuelItemID"));
oCarFuelItem.Code = oReader.GetString("Code");
oCarFuelItem.Name = oReader.GetString("Name");
oCarFuelItem.CarFuelType = (EnumCarFuelType)oReader.GetInt32("CarFuelType").Value;
oCarFuelItem.Sequence = oReader.GetInt32("SequenceNO").HasValue ? oReader.GetInt32("SequenceNo").Value : 0;
oCarFuelItem.Status = (EnumStatus)oReader.GetInt32("Status").Value;
oCarFuelItem.CreatedBy = oReader.GetID("CreatedBy");
oCarFuelItem.CreatedDate = oReader.GetDateTime("CreationDate").Value;
oCarFuelItem.ModifiedBy = oReader.GetID("ModifiedBy");
oCarFuelItem.ModifiedDate = oReader.GetDateTime("ModifiedDate");
this.SetObjectState(oCarFuelItem, Ease.CoreV35.ObjectState.Saved);
}
protected override T CreateObject<T>(DataReader oReader)
{
CarFuelItem oCarFuelItem = new CarFuelItem();
MapObject(oCarFuelItem, oReader);
return oCarFuelItem as T;
}
protected CarFuelItem CreateObject(DataReader oReader)
{
CarFuelItem oCarFuelItem = new CarFuelItem();
MapObject(oCarFuelItem, oReader);
return oCarFuelItem;
}
#endregion
#region Service implementation
public CarFuelItem Get(ID id)
{
CarFuelItem oCarFuelItem = new CarFuelItem();
#region Cache Header
oCarFuelItem = (CarFuelItem)_cache["Get", id] as CarFuelItem;
if (oCarFuelItem != null)
return oCarFuelItem;
#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader oReader = new DataReader(CarFuelItemDA.Get(tc, id));
if (oReader.Read())
{
oCarFuelItem = this.CreateObject(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(oCarFuelItem, "Get", id);
#endregion
return oCarFuelItem;
}
public string GetNextCode()
{
TransactionContext tc = null;
string _code = "";
try
{
tc = TransactionContext.Begin();
_code = GlobalFunctionService.GetMaxCode(tc, "CarFuelprovisionitem", "codeautogenerate", "CarFuelItem", "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<CarFuelItem> Get()
{
#region Cache Header
ObjectsTemplate<CarFuelItem> oCarFuelItems = _cache["Get"] as ObjectsTemplate<CarFuelItem>;
if (oCarFuelItems != null)
return oCarFuelItems;
#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader oreader = new DataReader(CarFuelItemDA.Get(tc));
oCarFuelItems = this.CreateObjects<CarFuelItem>(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(oCarFuelItems, "Get");
#endregion
return oCarFuelItems;
}
public ObjectsTemplate<CarFuelItem> Get(EnumStatus status)
{
#region Cache Header
ObjectsTemplate<CarFuelItem> CarFuelitems = _cache["Get", status] as ObjectsTemplate<CarFuelItem>;
if (CarFuelitems != null)
return CarFuelitems;
#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(CarFuelItemDA.Get(tc, status));
CarFuelitems = this.CreateObjects<CarFuelItem>(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(CarFuelitems, "Get", status);
#endregion
return CarFuelitems;
}
public ObjectsTemplate<CarFuelItem> Get(string CarFuelID)
{
throw new NotImplementedException();
}
public ObjectsTemplate<CarFuelItem> Get(EnumCarFuelType CarFuelType, EnumStatus status)
{
#region Cache Header
ObjectsTemplate<CarFuelItem> CarFuelitems = _cache["Get", CarFuelType, status] as ObjectsTemplate<CarFuelItem>;
if (CarFuelitems != null)
return CarFuelitems;
#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(CarFuelItemDA.Get(tc, CarFuelType, status));
CarFuelitems = this.CreateObjects<CarFuelItem>(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(CarFuelitems, "Get", CarFuelType, status);
#endregion
return CarFuelitems;
}
public ID Save(CarFuelItem oCarFuelItem)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
if (oCarFuelItem.IsNew)
{
int id = tc.GenerateID("CarFuelItem", "CarFuelItemID");
base.SetObjectID(oCarFuelItem, ID.FromInteger(id));
int seqNo = tc.GenerateID("CarFuelItem", "SequenceNo");
oCarFuelItem.Sequence = seqNo;
CarFuelItemDA.Insert(tc, oCarFuelItem);
}
else
{
CarFuelItemDA.Update(tc, oCarFuelItem);
}
tc.End();
return oCarFuelItem.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);
CarFuelItemDA.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
#region ICarFuelItemService Members
#endregion
}
#endregion
}