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 Bonus Service [Serializable] public class BonusService : ServiceTemplate, IBonusService { #region Private functions and declaration Cache _cache = new Cache(typeof(Bonus)); #endregion public BonusService() { } private void MapObject(Bonus oBonus, DataReader oReader) { base.SetObjectID(oBonus, oReader.GetID("BonusID")); oBonus.Code = oReader.GetString("code"); oBonus.Name = oReader.GetString("name"); oBonus.Sequence = oReader.GetInt32("SequenceNo").Value; oBonus.Status = (EnumStatus)oReader.GetInt32("Status").Value; oBonus.CreatedBy = oReader.GetID("CreatedBy"); oBonus.CreatedDate = oReader.GetDateTime("CreatedDate").Value; oBonus.ModifiedBy = oReader.GetID("ModifiedBy"); oBonus.ModifiedDate = oReader.GetDateTime("ModifiedDate"); this.SetObjectState(oBonus, Ease.CoreV35.ObjectState.Saved); } protected override T CreateObject(DataReader oReader) { Bonus oBonus = new Bonus(); MapObject(oBonus, oReader); return oBonus as T; } protected Bonus CreateObject(DataReader oReader) { Bonus oBonus = new Bonus(); MapObject(oBonus, oReader); return oBonus; } #region Service implementation public Bonus Get(ID id) { Bonus oBonus = new Bonus(); #region Cache Header oBonus = _cache["Get", id] as Bonus; if (oBonus != null) return oBonus; #endregion TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader oreader = new DataReader(BonusDA.Get(tc, id)); if (oreader.Read()) { oBonus = 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(oBonus, "Get", id); #endregion return oBonus; } public string GetNextCode() { TransactionContext tc = null; string _code = ""; try { tc = TransactionContext.Begin(); _code = GlobalFunctionService.GetMaxCode(tc, "bonus", "codeautogenerate", "Bonus", "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 ObjectsTemplate Get(EnumStatus status) { #region Cache Header ObjectsTemplate bonuss = _cache["Get", status] as ObjectsTemplate; if (bonuss != null) return bonuss; #endregion TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(BonusDA.Get(tc, status)); bonuss = 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(bonuss, "Get", status); #endregion return bonuss; } public DataTable GetOldBonus(ID payrollTypeID) { #region Cache Header DataTable dtBonuses = _cache["GetOldBonus"] as DataTable; if (dtBonuses != null) return dtBonuses; #endregion TransactionContext tc = null; try { tc = TransactionContext.Begin(); dtBonuses = BonusDA.GetOldBonus(tc, payrollTypeID.Integer).Tables[0]; 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(dtBonuses, "GetOldBonus"); #endregion return dtBonuses; } public ObjectsTemplate GetActiveProccessedBonus(int payrollTypeID, DateTime bonusMonth) { ObjectsTemplate bonuses = new ObjectsTemplate(); TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr; dr = new DataReader(BonusDA.GetActiveProccessedBonus(tc, payrollTypeID, bonusMonth)); bonuses = 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 bonuses; } public DataTable GetOldActiveProccessedBonus(int payrollTypeID, DateTime bonusMonth) { DataTable dtbonuses = new DataTable(); TransactionContext tc = null; try { tc = TransactionContext.Begin(); dtbonuses = BonusDA.GetOldActiveProccessedBonus(tc, payrollTypeID, bonusMonth).Tables[0]; tc.End(); } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } return dtbonuses; } public ID Save(Bonus oBonus) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); if (oBonus.IsNew) { int id = tc.GenerateID("Bonus", "BonusID"); base.SetObjectID(oBonus, ID.FromInteger(id)); int seqNo = tc.GenerateID("Bonus", "SequenceNo"); oBonus.Sequence = seqNo; BonusDA.Insert(tc, oBonus); } else { BonusDA.Update(tc, oBonus); } tc.End(); return oBonus.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); BonusDA.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 }