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 CarFuelParameterIndividual Service [Serializable] public class CarFuelParameterIndividualService : ServiceTemplate, ICarFuelParameterIndividualService { #region Private functions and declaration Cache _cache = new Cache(typeof(CarFuelParameterIndividual)); public CarFuelParameterIndividualService() { } private void MapObject(CarFuelParameterIndividual oCarFuelIndividual, DataReader oReader) { base.SetObjectID(oCarFuelIndividual, oReader.GetID("CarFuelParameterIndividualID")); oCarFuelIndividual.ArrearType = (EnumArrearType)oReader.GetInt32("ArrearType"); oCarFuelIndividual.EmployeeId = oReader.GetID("EmployeeId"); oCarFuelIndividual.FromDate = oReader.GetDateTime("FromDate").Value; oCarFuelIndividual.ToDate = oReader.GetDateTime("ToDate"); oCarFuelIndividual.IndividualType = (EnumCarFuelIndivdualType)oReader.GetInt32("IndividualType"); oCarFuelIndividual.CarFuelItemId = oReader.GetID("CarFuelItemId"); oCarFuelIndividual.CarFuelParameterID = oReader.GetID("CarFuelParameterId"); oCarFuelIndividual.CarFuelPeriodicity = (EnumCarFuelPeriodicity)oReader.GetInt32("CarFuelPeriodicity"); oCarFuelIndividual.Value = oReader.GetDouble("Value").Value; oCarFuelIndividual.ValueType = (EnumValueType)oReader.GetInt32("ValueType"); oCarFuelIndividual.CreatedBy = oReader.GetID("CreatedBy"); oCarFuelIndividual.CreatedDate = oReader.GetDateTime("CreationDate").Value; oCarFuelIndividual.ModifiedBy = oReader.GetID("ModifiedBy"); oCarFuelIndividual.ModifiedDate = oReader.GetDateTime("ModifiedDate"); this.SetObjectState(oCarFuelIndividual, Ease.CoreV35.ObjectState.Saved); } protected override T CreateObject(DataReader oReader) { CarFuelParameterIndividual oCarFuelIndividual = new CarFuelParameterIndividual(); MapObject(oCarFuelIndividual, oReader); return oCarFuelIndividual as T; } protected CarFuelParameterIndividual CreateObject(DataReader oReader) { CarFuelParameterIndividual oCarFuelIndividual = new CarFuelParameterIndividual(); MapObject(oCarFuelIndividual, oReader); return oCarFuelIndividual; } #endregion #region Service implementation public CarFuelParameterIndividual Get(ID id) { CarFuelParameterIndividual oCarFuelIndividual = new CarFuelParameterIndividual(); #region Cache Header oCarFuelIndividual = (CarFuelParameterIndividual)_cache["Get", id]; if (oCarFuelIndividual != null) return oCarFuelIndividual; #endregion TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader oreader = new DataReader(CarFuelParameterIndividualDA.Get(tc, id)); if (oreader.Read()) { oCarFuelIndividual = 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(oCarFuelIndividual, "Get", id); #endregion return oCarFuelIndividual; } public ObjectsTemplate Get() { #region Cache Header ObjectsTemplate oCarFuelIndividuals = _cache["Get"] as ObjectsTemplate; if (oCarFuelIndividuals != null) return oCarFuelIndividuals; #endregion TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader oreader = new DataReader(CarFuelParameterIndividualDA.Get(tc)); oCarFuelIndividuals = 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(oCarFuelIndividuals, "Get"); #endregion return oCarFuelIndividuals; } public ObjectsTemplate GetByParameterID(ID nParamaterID) { #region Cache Header ObjectsTemplate oCarFuelIndividuals = _cache["GetByParameterID"] as ObjectsTemplate; if (oCarFuelIndividuals != null) return oCarFuelIndividuals; #endregion TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader oreader = new DataReader(CarFuelParameterIndividualDA.GetByParameterID(tc, nParamaterID)); oCarFuelIndividuals = 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(oCarFuelIndividuals, "GetByParameterID"); #endregion return oCarFuelIndividuals; } public ObjectsTemplate Get(DateTime fromDate, DateTime toDate) { ObjectsTemplate CarFuelParameterIndividuals = null; TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(CarFuelParameterIndividualDA.Get(tc, fromDate, toDate)); CarFuelParameterIndividuals = 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 } return CarFuelParameterIndividuals; } public ObjectsTemplate GetIndividuals(ID nCarFuelPAramID, EnumCarFuelIndivdualType type) { #region Cache Header ObjectsTemplate CarFuelParamIndividuals = _cache["GetIndividuals", nCarFuelPAramID, type] as ObjectsTemplate; if (CarFuelParamIndividuals != null) return CarFuelParamIndividuals; #endregion TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(CarFuelParameterIndividualDA.GetIndividuals(tc, nCarFuelPAramID, type)); CarFuelParamIndividuals = 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(CarFuelParamIndividuals, "GetIndividuals", nCarFuelPAramID, type); #endregion return CarFuelParamIndividuals; } public ID Save(CarFuelParameterIndividual oCarFuelIndividual) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); if (oCarFuelIndividual.IsNew) { int id = tc.GenerateID("CarFuelParameterIndividual", "CarFuelParameterIndividualID"); base.SetObjectID(oCarFuelIndividual, ID.FromInteger(id)); CarFuelParameterIndividualDA.Insert(tc, oCarFuelIndividual); } else { CarFuelParameterIndividualDA.Update(tc, oCarFuelIndividual); } return oCarFuelIndividual.ID; tc.End(); } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException("Failed to GetCarFuelParameterIndividual", e); #endregion } } public void BulkSave(ObjectsTemplate oParamIndvdls) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); foreach (var oCarFuelIndividual in oParamIndvdls) { if (oCarFuelIndividual.IsNew) { int id = tc.GenerateID("CarFuelParameterIndividual", "CarFuelParameterIndividualID"); base.SetObjectID(oCarFuelIndividual, ID.FromInteger(id)); CarFuelParameterIndividualDA.Insert(tc, oCarFuelIndividual); } else { CarFuelParameterIndividualDA.Update(tc, oCarFuelIndividual); } } tc.End(); } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException("Failed to GetCarFuelParameterIndividual", e); #endregion } } public void Delete(ID id) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); CarFuelParameterIndividualDA.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 ICarFuelParameterIndividualService Members #endregion } #endregion }