using System; using System.Data; using System.Linq; using Ease.Core.Model; using Ease.Core.DataAccess; using HRM.BO; using System.Collections.Generic; using Ease.Core.Utility; using Payroll.Service; namespace HRM.DA { #region ESBDefinition Service public class ESBDefinitionService : ServiceTemplate { public ESBDefinitionService() { } #region Mapping ESBDefinitionObject private void MapESBDefinitionObject(ESBDefinition oESBDefinition, DataReader oReader) { base.SetObjectID(oESBDefinition, oReader.GetInt32("ESBID").Value); oESBDefinition.Description = oReader.GetString("Description"); oESBDefinition.MaxServiceLength = oReader.GetDouble("ServiceLength").Value; oESBDefinition.PayrollTypeID = oReader.GetInt32("PayrollTypeID").Value; oESBDefinition.Trading = oReader.GetDouble("Trading").Value; oESBDefinition.UserID = oReader.GetInt32("UserID").Value; oESBDefinition.Sequence = oReader.GetInt32("SequenceNo").Value; oESBDefinition.Status = (EnumStatus)oReader.GetInt32("Status").Value; oESBDefinition.CreatedBy = oReader.GetInt32("CreatedBy").Value; oESBDefinition.CreatedDate = oReader.GetDateTime("CreatedDate").Value; oESBDefinition.ModifiedBy = oReader.GetInt32("ModifiedBy", 0); oESBDefinition.ModifiedDate = oReader.GetDateTime("ModifiedDate"); this.SetObjectState(oESBDefinition, Ease.Core.ObjectState.Saved); } protected override T CreateObject(DataReader oReader) { ESBDefinition oESBDefinition = new ESBDefinition(); return oESBDefinition as T; } protected List CreateESBDefinitionObjects(DataReader oReader) { List oESBDefinitions = new List(); 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.GetInt32("ESBID").Value; oESBElement.ElementID = oReader.GetInt32("ElementID").Value; oESBElement.ElementType = (EnumSalaryComponent)oReader.GetInt16("ElmentType").Value; this.SetObjectState(oESBElement, Ease.Core.ObjectState.Saved); } protected List CreateESBElementObjects(DataReader oReader) { List oESBElements = new List(); 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.GetInt32("GradeID").Value; oGrade.ESBID = oReader.GetInt32("ESBID").Value; this.SetObjectState(oGrade, Ease.Core.ObjectState.Saved); } protected List CreateESBGRadeObjects(DataReader oReader) { List oESBGrades = new List(); 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.GetInt32("ESBID").Value; oESBSlab.CalculateNo = oReader.GetDouble("CalculNo").Value; oESBSlab.DaysToConsider = oReader.GetDouble("DaysToConsider").Value; oESBSlab.ServiceYear = oReader.GetDouble("ServiceYear").Value; this.SetObjectState(oESBSlab, Ease.Core.ObjectState.Saved); } protected List CreateESBSlabObjects(DataReader oReader) { List oESBSlabs = new List(); 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(int id) { ESBDefinition oESBDefinition = new ESBDefinition(); 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 } return oESBDefinition; } public ESBDefinition GetByPayrollID(int id) { ESBDefinition oESBDefinition = new ESBDefinition(); 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 } return oESBDefinition; } public List Get() { List ESBDefinitions = new List(); 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 } return ESBDefinitions; } public List GetByPayrollType(int nPayrollTypeID) { List ESBDefinitions = new List(); 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 } return ESBDefinitions; } public int Save(ESBDefinition oESBDefinition) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); if (oESBDefinition.ID != 0) { 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); 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(int 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 List GetESBElement(int nESBID) { List oESBElements = new List(); 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 } return oESBElements; } public int SaveESBElement(ESBElement oESBElement) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); if (oESBElement.IsNew) { 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(int 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 List GetESBGrade(int nESBID) { List oESBGrade = new List(); TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(ESBDefinitionDA.GetESBGradeByEsbid(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 } return oESBGrade; } public int 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(int 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 List GetSlabs(int nESBID) { List ESBDefinitions = new List(); 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 } return ESBDefinitions; } public int SaveESBSlab(ESBSlab oESBSlab) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); if (oESBSlab.IsNew) { int id = tc.GenerateID("ESBSlab", "ESBSlabID"); base.SetObjectID(oESBSlab, 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(int 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 }