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 GradeSegment Service [Serializable] public class GradeSegmentService : ServiceTemplate, IGradeSegmentService { #region Private functions and declaration Cache _cache = new Cache(typeof(GradeSegment)); #endregion public GradeSegmentService() { } private void MapObject(GradeSegment oGradeSegment, DataReader oReader) { base.SetObjectID(oGradeSegment, oReader.GetID("GradeSegmentID")); oGradeSegment.Code = oReader.GetString("code"); oGradeSegment.Name = oReader.GetString("description"); oGradeSegment.BasicPer = oReader.GetDouble("BasicPer").Value; oGradeSegment.Sequence = oReader.GetInt32("SequenceNo").Value; oGradeSegment.Status = (EnumStatus)oReader.GetInt32("Status").Value; oGradeSegment.CreatedBy = oReader.GetID("CreatedBy"); oGradeSegment.CreatedDate = oReader.GetDateTime("CreationDate").Value; oGradeSegment.ModifiedBy = oReader.GetID("ModifiedBy"); oGradeSegment.ModifiedDate = oReader.GetDateTime("ModifiedDate"); this.SetObjectState(oGradeSegment, Ease.CoreV35.ObjectState.Saved); } protected override T CreateObject(DataReader oReader) { GradeSegment oGradeSegment = new GradeSegment(); MapObject(oGradeSegment, oReader); return oGradeSegment as T; } protected GradeSegment CreateObject(DataReader oReader) { GradeSegment oGradeSegment = new GradeSegment(); MapObject(oGradeSegment, oReader); return oGradeSegment; } #region Service implementation public string GetNextCode() { TransactionContext tc = null; string _code = ""; try { tc = TransactionContext.Begin(); _code = GlobalFunctionService.GetMaxCode(tc, "gradesegment", "codeautogenerate", "GradeSegment", "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 GradeSegment Get(ID id) { GradeSegment oGradeSegment = new GradeSegment(); #region Cache Header oGradeSegment = _cache["Get", id] as GradeSegment; if (oGradeSegment != null) return oGradeSegment; #endregion TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader oreader = new DataReader(GradeSegmentDA.Get(tc, id)); if (oreader.Read()) { oGradeSegment = 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(oGradeSegment, "Get", id); #endregion return oGradeSegment; } public GradeSegment Get(string sCode) { GradeSegment oGradeSegment = new GradeSegment(); #region Cache Header oGradeSegment = _cache["Get", sCode] as GradeSegment; if (oGradeSegment != null) return oGradeSegment; #endregion TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader oreader = new DataReader(GradeSegmentDA.Get(tc, sCode)); if (oreader.Read()) { oGradeSegment = 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(oGradeSegment, "Get", sCode); #endregion return oGradeSegment; } public ObjectsTemplate Get(EnumStatus status) { #region Cache Header ObjectsTemplate gradeSegments = _cache["Get",status] as ObjectsTemplate; if (gradeSegments != null) return gradeSegments; #endregion TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(GradeSegmentDA.Get(tc, status)); gradeSegments = 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(gradeSegments, "Get",status); #endregion return gradeSegments; } public ID Save(GradeSegment oGradeSegment) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); if (oGradeSegment.IsNew) { int id = tc.GenerateID("GradeSegment", "GradeSegmentID"); base.SetObjectID(oGradeSegment, ID.FromInteger(id)); int seqNo = tc.GenerateID("GradeSegment", "SequenceNO"); oGradeSegment.Sequence = seqNo; GradeSegmentDA.Insert(tc, oGradeSegment); } else { GradeSegmentDA.Update(tc, oGradeSegment); } tc.End(); return oGradeSegment.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); GradeSegmentDA.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 } #endregion }