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(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 Get() { #region Cache Header ObjectsTemplate oCarFuelItems = _cache["Get"] as ObjectsTemplate; if (oCarFuelItems != null) return oCarFuelItems; #endregion TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader oreader = new DataReader(CarFuelItemDA.Get(tc)); oCarFuelItems = this.CreateObjects(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 Get(EnumStatus status) { #region Cache Header ObjectsTemplate CarFuelitems = _cache["Get", status] as ObjectsTemplate; if (CarFuelitems != null) return CarFuelitems; #endregion TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(CarFuelItemDA.Get(tc, status)); CarFuelitems = this.CreateObjects(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 Get(string CarFuelID) { throw new NotImplementedException(); } public ObjectsTemplate Get(EnumCarFuelType CarFuelType, EnumStatus status) { #region Cache Header ObjectsTemplate CarFuelitems = _cache["Get", CarFuelType, status] as ObjectsTemplate; 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(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 }