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 ESBDefinition Service [Serializable] public class ESBDefinitionService : ServiceTemplate, IESBDefinitionService { #region Private functions and declaration Cache _cache = new Cache(typeof(ESBDefinition)); #endregion public ESBDefinitionService() { } #region Mapping ESBDefinitionObject private void MapESBDefinitionObject(ESBDefinition oESBDefinition, DataReader oReader) { base.SetObjectID(oESBDefinition, oReader.GetID("ESBID")); oESBDefinition.Description = oReader.GetString("Description"); oESBDefinition.MaxServiceLength = oReader.GetDouble("ServiceLength").Value; oESBDefinition.PayrollTypeID = oReader.GetID("PayrollTypeID"); oESBDefinition.Trading = oReader.GetDouble("Trading").Value; oESBDefinition.UserID = oReader.GetID("UserID"); oESBDefinition.Sequence = oReader.GetInt32("SequenceNo").Value; oESBDefinition.Status = (EnumStatus)oReader.GetInt32("Status").Value; oESBDefinition.CreatedBy = oReader.GetID("CreatedBy"); oESBDefinition.CreatedDate = oReader.GetDateTime("CreatedDate").Value; oESBDefinition.ModifiedBy = oReader.GetID("ModifiedBy"); oESBDefinition.ModifiedDate = oReader.GetDateTime("ModifiedDate"); this.SetObjectState(oESBDefinition, Ease.CoreV35.ObjectState.Saved); } protected override T CreateObject(DataReader oReader) { ESBDefinition oESBDefinition = new ESBDefinition(); return oESBDefinition as T; } protected ObjectsTemplate CreateESBDefinitionObjects(DataReader oReader) { ObjectsTemplate oESBDefinitions = new ObjectsTemplate(); while (oReader.Read()) { ESBDefinition oESBDefinition = new ESBDefinition(); MapESBDefinitionObject(oESBDefinition, oReader); oESBDefinitions.Add(oESBDefinition); } return oESBDefinitions; } protected ESBDefinition CreateESBDefinitionObject(DataReader oReader) { ESBDefinition oESBDefinition = new ESBDefinition(); MapESBDefinitionObject(oESBDefinition, oReader); return oESBDefinition; } #endregion #region Mapping ESBElementObject private void MapESBElementObject(ESBElement oESBElement, DataReader oReader) { oESBElement.ESBID = oReader.GetID("ESBID"); oESBElement.ElementID = oReader.GetID("ElementID"); oESBElement.ElementType =(EnumSalaryComponent) oReader.GetInt16("ElmentType").Value; this.SetObjectState(oESBElement, Ease.CoreV35.ObjectState.Saved); } protected ObjectsTemplate CreateESBElementObjects(DataReader oReader) { ObjectsTemplate oESBElements = new ObjectsTemplate(); while (oReader.Read()) { ESBElement oESBElement = new ESBElement(); MapESBElementObject(oESBElement, oReader); oESBElements.Add(oESBElement); } return oESBElements; } protected ESBElement CreateESBElementObject(DataReader oReader) { ESBElement oESBElement = new ESBElement(); MapESBElementObject(oESBElement, oReader); return oESBElement; } #endregion #region Mapping ESBGradeObject private void MapESBGradeObject(ESBGrade oGrade, DataReader oReader) { oGrade.GradeID = oReader.GetID("GradeID"); oGrade.ESBID = oReader.GetID("ESBID"); this.SetObjectState(oGrade, Ease.CoreV35.ObjectState.Saved); } protected ObjectsTemplate CreateESBGRadeObjects(DataReader oReader) { ObjectsTemplate oESBGrades = new ObjectsTemplate(); while (oReader.Read()) { ESBGrade oESBGrade = new ESBGrade(); MapESBGradeObject(oESBGrade, oReader); oESBGrades.Add(oESBGrade); } return oESBGrades; } protected ESBGrade CreateESBGRadeObject(DataReader oReader) { ESBGrade oGrade = new ESBGrade(); MapESBGradeObject(oGrade, oReader); return oGrade; } #endregion #region Mapping ESBSlabObject private void MapESBSlabObject(ESBSlab oESBSlab, DataReader oReader) { oESBSlab.ESBID = oReader.GetID("ESBID"); oESBSlab.CalculateNo = oReader.GetDouble("CalculNo").Value; oESBSlab.DaysToConsider = oReader.GetDouble("DaysToConsider").Value; oESBSlab.ServiceYear = oReader.GetDouble("ServiceYear").Value; this.SetObjectState(oESBSlab, Ease.CoreV35.ObjectState.Saved); } protected ObjectsTemplate CreateESBSlabObjects(DataReader oReader) { ObjectsTemplate oESBSlabs = new ObjectsTemplate(); while (oReader.Read()) { ESBSlab oESBSlab = new ESBSlab(); MapESBSlabObject(oESBSlab, oReader); oESBSlabs.Add(oESBSlab); } return oESBSlabs; } protected ESBSlab CreateESBSlabObject(DataReader oReader) { ESBSlab oESBSlab = new ESBSlab(); MapESBSlabObject(oESBSlab, oReader); return oESBSlab; } #endregion #region Service implementation ESBDefinition public ESBDefinition Get(ID id) { ESBDefinition oESBDefinition = new ESBDefinition(); #region Cache Header oESBDefinition = _cache["Get", id] as ESBDefinition; if (oESBDefinition != null) return oESBDefinition; #endregion TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader oreader = new DataReader(ESBDefinitionDA.Get(tc, id)); if (oreader.Read()) { oESBDefinition = this.CreateESBDefinitionObject(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(oESBDefinition, "Get", id); #endregion return oESBDefinition; } public ESBDefinition Get(int id) { ESBDefinition oESBDefinition = new ESBDefinition(); #region Cache Header oESBDefinition = _cache["Get", id] as ESBDefinition; if (oESBDefinition != null) return oESBDefinition; #endregion TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader oreader = new DataReader(ESBDefinitionDA.Get(tc, id)); if (oreader.Read()) { oESBDefinition = this.CreateESBDefinitionObject(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(oESBDefinition, "Get", id); #endregion return oESBDefinition; } public ESBDefinition GetByPayrollID(int id) { ESBDefinition oESBDefinition = new ESBDefinition(); #region Cache Header oESBDefinition = _cache["GetByPayrollID", id] as ESBDefinition; if (oESBDefinition != null) return oESBDefinition; #endregion TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader oreader = new DataReader(ESBDefinitionDA.GetByPayrollID(tc, id)); if (oreader.Read()) { oESBDefinition = this.CreateESBDefinitionObject(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(oESBDefinition, "GetByPayrollID", id); #endregion return oESBDefinition; } public ObjectsTemplate Get() { #region Cache Header ObjectsTemplate ESBDefinitions = _cache["Get"] as ObjectsTemplate; if (ESBDefinitions != null) return ESBDefinitions; #endregion TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(ESBDefinitionDA.Get(tc)); ESBDefinitions = this.CreateESBDefinitionObjects(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(ESBDefinitions, "Get"); #endregion return ESBDefinitions; } public ObjectsTemplate GetByPayrollType(int nPayrollTypeID) { #region Cache Header ObjectsTemplate ESBDefinitions = _cache["GetByPayrollType", nPayrollTypeID] as ObjectsTemplate; if (ESBDefinitions != null) return ESBDefinitions; #endregion TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(ESBDefinitionDA.GetByPayrollType(tc, nPayrollTypeID)); ESBDefinitions = this.CreateESBDefinitionObjects(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(ESBDefinitions, "GetByPayrollType", nPayrollTypeID); #endregion return ESBDefinitions; } public ID Save(ESBDefinition oESBDefinition) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); if (!oESBDefinition.ID.IsUnassigned) { ESBDefinitionDA.DeleteESBGrade(tc, oESBDefinition.ID); ESBDefinitionDA.DeleteESBElement(tc, oESBDefinition.ID); ESBDefinitionDA.DeleteESBSlab(tc, oESBDefinition.ID); ESBDefinitionDA.Delete(tc, oESBDefinition.ID); } int id = tc.GenerateID("ESBDefinition", "ESBID"); base.SetObjectID(oESBDefinition, ID.FromInteger(id)); int seqNo = tc.GenerateID("ESBDefinition", "SequenceNo"); oESBDefinition.Sequence = seqNo; ESBDefinitionDA.Insert(tc, oESBDefinition); foreach (ESBGrade oESBGrade in oESBDefinition.ESBGrades) { oESBGrade.ESBID = oESBDefinition.ID; ESBDefinitionDA.InsertESBGrade(tc, oESBGrade); } foreach (ESBElement oESBElement in oESBDefinition.ESBElements) { oESBElement.ESBID = oESBDefinition.ID; ESBDefinitionDA.InsertESBElement(tc, oESBElement); } foreach (ESBSlab oESBSlab in oESBDefinition.ESBSlabs) { oESBSlab.ESBID = oESBDefinition.ID; ESBDefinitionDA.InsertESBSlab(tc, oESBSlab); } tc.End(); return oESBDefinition.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); ESBDefinitionDA.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 Service implementation ESBElement public ObjectsTemplate GetESBElement(int nESBID) { #region Cache Header ObjectsTemplate oESBElements = _cache["Get", nESBID] as ObjectsTemplate; if (oESBElements != null) return oESBElements; #endregion TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(ESBDefinitionDA.GetESBElement(tc, nESBID)); oESBElements = this.CreateESBElementObjects(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(oESBElements, "Get", nESBID); #endregion return oESBElements; } public ID SaveESBElement(ESBElement oESBElement) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); if (oESBElement.IsNew) { //int id = tc.GenerateID("ESBElement", "ESBElementID"); //base.SetObjectID(oESBElement, ID.FromInteger(id)); //int seqNo = tc.GenerateID("ESBElement", "SequenceNo"); //oESBElement.Sequence = seqNo; ESBDefinitionDA.InsertESBElement(tc, oESBElement); } else { ESBDefinitionDA.UpdateESBElement(tc, oESBElement); } tc.End(); return oESBElement.ID; } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } } public void DeleteESBElement(ID id) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); ESBDefinitionDA.DeleteESBElement(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 Service implementation ESBGrade public ObjectsTemplate GetESBGrade(int nESBID) { #region Cache Header ObjectsTemplate oESBGrade = _cache["GetESBGrade", nESBID] as ObjectsTemplate; if (oESBGrade != null) return oESBGrade; #endregion TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(ESBDefinitionDA.GetESBGrade(tc, nESBID)); oESBGrade = this.CreateESBGRadeObjects(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(oESBGrade, "GetESBGrade", nESBID); #endregion return oESBGrade; } public ID SaveESBGrade(ESBGrade oESBGrade) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); if (oESBGrade.IsNew) { //int id = tc.GenerateID("ESBGrade", "ESBGradeID"); //base.SetObjectID(oBonus, ID.FromInteger(id)); //int seqNo = tc.GenerateID("ESBGrade", "SequenceNo"); //oBonus.Sequence = seqNo; ESBDefinitionDA.InsertESBGrade(tc, oESBGrade); } else { ESBDefinitionDA.UpdateESBGrade(tc, oESBGrade); } tc.End(); return oESBGrade.ID; } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } } public void DeleteESBGrade(ID id) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); ESBDefinitionDA.DeleteESBGrade(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 Service implementation ESBSlab public ObjectsTemplate GetSlabs(int nESBID) { #region Cache Header ObjectsTemplate ESBDefinitions = _cache["GetSlabs", nESBID] as ObjectsTemplate; if (ESBDefinitions != null) return ESBDefinitions; #endregion TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(ESBDefinitionDA.GetSlabs(tc, nESBID)); ESBDefinitions = this.CreateESBSlabObjects(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(ESBDefinitions, "GetSlabs", nESBID); #endregion return ESBDefinitions; } public ID SaveESBSlab(ESBSlab oESBSlab) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); if (oESBSlab.IsNew) { int id = tc.GenerateID("ESBSlab", "ESBSlabID"); base.SetObjectID(oESBSlab, ID.FromInteger(id)); int seqNo = tc.GenerateID("ESBSlab", "SequenceNo"); oESBSlab.Sequence = seqNo; ESBDefinitionDA.InsertESBSlab(tc, oESBSlab); } else { ESBDefinitionDA.UpdateESBSlab(tc, oESBSlab); } tc.End(); return oESBSlab.ID; } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } } public void DeleteESBSlab(ID id) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); ESBDefinitionDA.DeleteESBSlab(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 }