using System; using System.Data; using Ease.Core.Model; using Ease.Core.DataAccess; using HRM.BO; using System.Collections.Generic; using Ease.Core.Utility; namespace HRM.DA { public class EducationLevelService : ServiceTemplate, IEducationLevelService { #region constructor public EducationLevelService() { } #endregion #region Object private void MapObject(EducationLevel oEducationLevel, DataReader oReader) { base.SetObjectID(oEducationLevel, oReader.GetInt32("EDUCATIONLEVELID").Value); oEducationLevel.Code = oReader.GetString("CODE"); oEducationLevel.Description = oReader.GetString("DESCRIPTION"); oEducationLevel.EducationTypeID = oReader.GetInt32("EDUCATIONTYPEID", 0); oEducationLevel.Sequence = oReader.GetInt32("SequenceNo").Value; oEducationLevel.Status = (EnumStatus)oReader.GetInt32("Status").Value; oEducationLevel.CreatedBy = oReader.GetInt32("CreatedBy", 0); oEducationLevel.CreatedDate = oReader.GetDateTime("CreationDate").Value; oEducationLevel.ModifiedBy = oReader.GetInt32("ModifiedBy", 0); oEducationLevel.ModifiedDate = oReader.GetDateTime("ModifiedDate"); this.SetObjectState(oEducationLevel, Ease.Core.ObjectState.Saved); } protected override T CreateObject(DataReader oReader) { EducationLevel oEducationLevel = new EducationLevel(); MapObject(oEducationLevel, oReader); return oEducationLevel as T; } #endregion #region Service implementation public EducationLevel Get(int id) { EducationLevel oEducationLevel = null; TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader oreader = new DataReader(EducationLevelDA.Get(tc, id)); if (oreader.Read()) { oEducationLevel = 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 } return oEducationLevel; } public EducationLevel Get(string sCode) { EducationLevel oEducationLevels = null; TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader oreader = new DataReader(EducationLevelDA.Get(tc, sCode)); if (oreader.Read()) { oEducationLevels = 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 } return oEducationLevels; } public List Get() { List educationLevels = new List(); TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(EducationLevelDA.Get(tc)); educationLevels = 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 educationLevels; } public List Get(EnumStatus status) { List oEducationLevels = new List(); TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(EducationLevelDA.Get(tc, status)); oEducationLevels = 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 oEducationLevels; } public List Get(EnumStatus status, int payrolltypeid) { List oEducationLevels = new List(); TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(EducationLevelDA.Get(tc, status)); oEducationLevels = 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 oEducationLevels; } public List GetByType(int typeID) { List oEducationLevels = new List(); TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(EducationLevelDA.GetByType(tc, typeID)); oEducationLevels = 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 oEducationLevels; } public EducationLevel GetByLevelID(int nLevelID) { EducationLevel oEducationLevel = null; TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader oreader = new DataReader(EducationLevelDA.GetByLevelID(tc, nLevelID)); if (oreader.Read()) { oEducationLevel = 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 } return oEducationLevel; } public string GetNextCode() { TransactionContext tc = null; string _code = ""; try { tc = TransactionContext.Begin(); _code = GlobalFunctionService.GetMaxCode(tc, "EDUCATIONLEVEL", "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 int Save(EducationLevel oEducationLevel) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); if (oEducationLevel.IsNew) { int id = tc.GenerateID("EDUCATIONLEVEL", "EDUCATIONLEVELID"); base.SetObjectID(oEducationLevel, id); oEducationLevel.Code = GlobalFunctionService.GetMaxCode(tc, "EDUCATIONLEVEL", "Code"); EducationLevelDA.Insert(tc, oEducationLevel); } else { EducationLevelDA.Update(tc, oEducationLevel); } tc.End(); return oEducationLevel.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); EducationLevelDA.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 } } public DataSet GetManpower(string sparam) { DataSet oManpowers = new DataSet(); TransactionContext tc = null; try { tc = TransactionContext.Begin(); oManpowers = EducationLevelDA.GetManpower(tc, sparam); tc.End(); } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } return oManpowers; } internal List GetByID(TransactionContext tc, int id) { List oEducationLevels = new List(); try { DataReader dr = new DataReader(EducationLevelDA.GetByID(tc, id)); oEducationLevels = this.CreateObjects(dr); dr.Close(); } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } return oEducationLevels; } public List GetByLevelIDs(string ids) { List oEducationLevels = new List(); TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(EducationLevelDA.GetByLevelIDs(tc, ids)); oEducationLevels = this.CreateObjects(dr); dr.Close(); } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } return oEducationLevels; } #endregion } }