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 LeaveParameter Service [Serializable] public class LeaveParameterService : ServiceTemplate, ILeaveParameterService { #region Leave Process #region Private functions and declaration Cache _cache = new Cache(typeof(LeaveParameter)); public LeaveParameterService() { } private void MapObject(LeaveParameter oLeaveParameter, DataReader oReader) { LeaveParameterDetail oDetail; oDetail = new LeaveParameterDetail(); base.SetObjectID(oLeaveParameter, oReader.GetID("LeaveParamId")); oLeaveParameter.LeaveId = oReader.GetInt32("LeaveId").Value ; oLeaveParameter.MaxAccumulatedDays = oReader.GetDouble("AccumulatedLeave").Value ; oLeaveParameter.IsActive = oReader.GetBoolean("IsActive").Value ; oLeaveParameter.ApplicableFor = (LeaveApplicableType)oReader.GetInt32("ApplicableFor").Value ; //oLeaveParameter.SetupDate = oReader.GetDateTime("SetupDate").Value ; //oLeaveParameter.LastUpdate = oReader.GetDateTime("LastUpdate").Value; //oLeaveParameter.DeActiveDate = oReader.GetDateTime("DeActiveDate").Value; oLeaveParameter.ForfitedMonth = oReader.GetInt32("FortifiedMonth").Value; //oLeaveParameter.UserId = oReader.GetInt32("UserId"); oLeaveParameter.AllowAdvance = oReader.GetBoolean("AllowAdvance").Value; oLeaveParameter.IgnoreHoliday = oReader.GetBoolean("IgnoreHolidays").Value; oLeaveParameter.CalculationType = (EnumLeaveCalculationType)oReader.GetInt32("MonthlyBalance").Value; oLeaveParameter.IsForfited = oReader.GetBoolean("IsForfited").Value; oLeaveParameter.CreatedBy = oReader.GetID("CreatedBy"); oLeaveParameter.CreatedDate = oReader.GetDateTime("CreationDate").GetValueOrDefault(); oLeaveParameter.ModifiedBy = oReader.GetID("ModifiedBy"); oLeaveParameter.ModifiedDate = oReader.GetDateTime("ModifiedDate").GetValueOrDefault(); oLeaveParameter.PayrollTypeID = oReader.GetInt32("PayrollTypeID").Value; //this.SetObjectState(oLeaveParameter, ObjectState.Saved); this.SetObjectState(oLeaveParameter, Ease.CoreV35.ObjectState.Saved); } protected override T CreateObject(DataReader oReader) { LeaveParameter oLeaveParameter = new LeaveParameter(); MapObject(oLeaveParameter, oReader); return oLeaveParameter as T; } private LeaveParameter CreateObject(DataReader oReader) { LeaveParameter oLeaveParameter = new LeaveParameter(); MapObject(oLeaveParameter, oReader); return oLeaveParameter; } //private void MapLeaveSBU(LeaveSBU oLeaveSBU, DataReader oReader) //{ // oLeaveSBU.LeaveParamId = oReader.GetInt32("LeaveParamId"); // oLeaveSBU.SBUId = oReader.GetInt32("SBUId"); // this.SetObjectState(oLeaveSBU, Ease.CoreV35.ObjectState.Saved); //} //private void MapLeaveLocation(LeaveLocation oLeaveLocation, DataReader oReader) //{ // oLeaveLocation.LeaveParamId = oReader.GetInt32("LeaveParamId"); // oLeaveLocation.LocationId = oReader.GetInt32("LocationId"); // this.SetObjectState(oLeaveLocation, Ease.CoreV35.ObjectState.Saved); //} //private void MapLeaveFunction(LeaveFunction oLeaveFunction, DataReader oReader) //{ // oLeaveFunction.LeaveParamId = oReader.GetInt32("LeaveParamId"); // oLeaveFunction.FunctionId = oReader.GetInt32("FunctionId"); // this.SetObjectState(oLeaveFunction, Ease.CoreV35.ObjectState.Saved); //} private void MapDetailObject(LeaveParameterDetail oLeaveParameterDetail, DataReader oReader) { base.SetObjectID(oLeaveParameterDetail, oReader.GetID ("ID")); oLeaveParameterDetail.LeaveParamId = oReader.GetInt32("LeaveParamId").Value; oLeaveParameterDetail.MaxDays = oReader.GetDouble("MaxDays").Value; oLeaveParameterDetail.MaxCF = oReader.GetDouble("MaxCF").Value; oLeaveParameterDetail.MaxEncash = oReader.GetDouble("MaxEncash").Value; oLeaveParameterDetail.Year = oReader.GetInt32("Year").Value; this.SetObjectState(oLeaveParameterDetail, Ease.CoreV35.ObjectState.Saved); } protected ObjectsTemplate CreateDetailObjects(DataReader oReader) { //LeaveParameterDetail oLeaveParameterDetail = new LeaveParameterDetail(); //MapDetailObject(oLeaveParameterDetail, oReader); //return oLeaveParameterDetail as T; ObjectsTemplate oLeaveParameterDetails = new ObjectsTemplate(); while (oReader.Read()) { LeaveParameterDetail oLeaveParameterDetail = new LeaveParameterDetail(); MapDetailObject(oLeaveParameterDetail, oReader); oLeaveParameterDetails.Add(oLeaveParameterDetail); } return oLeaveParameterDetails; } private LeaveParameterDetail CreateDetailObject(DataReader oReader) { LeaveParameterDetail oLeaveParameterDetail = new LeaveParameterDetail(); MapDetailObject(oLeaveParameterDetail, oReader); return oLeaveParameterDetail; } #endregion #region Service implementation public LeaveParameter Get(ID id) { LeaveParameter oLeaveParameter = new LeaveParameter(); #region Cache Header oLeaveParameter = (LeaveParameter)_cache["Get", id]; if (oLeaveParameter != null) return oLeaveParameter; #endregion TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr =new DataReader(LeaveParameterDA.Get(tc, id.Integer)); if (dr.Read()) { oLeaveParameter = CreateObject(dr); } dr.Close(); tc.End(); } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException("Failed to Get Leave Parameter :" + e.Message, e); #endregion } #region Cache Footer _cache.Add(oLeaveParameter, "Get", id); #endregion return oLeaveParameter; } public LeaveParameterDetail GetLeaveDetail(int leaveID) { LeaveParameterDetail oLeaveDetail = new LeaveParameterDetail(); #region Cache Header oLeaveDetail = (LeaveParameterDetail)_cache["Get", leaveID]; if (oLeaveDetail != null) return oLeaveDetail; #endregion TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr =new DataReader(LeaveParameterDA.GetLeaveDetail(tc, leaveID)); if (dr.Read()) { oLeaveDetail = CreateDetailObject(dr); } dr.Close(); tc.End(); } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException("Failed to Get Leave Parameter :" + e.Message, e); #endregion } #region Cache Footer _cache.Add(oLeaveDetail, "Get", leaveID); #endregion return oLeaveDetail; } //public LeaveParameterDetail GetDetail(int paramID) //{ // LeaveParameterDetail oLeaveDetail = new LeaveParameterDetail(); // #region Cache Header // oLeaveDetail = (LeaveParameterDetail)_cache["Get", paramID]; // if (oLeaveDetail != null) // return oLeaveDetail; // #endregion // TransactionContext tc = null; // try // { // tc = TransactionContext.Begin(); // DataReader dr =new DataReader(LeaveParameterDA.GetDetail(tc, paramID)); // if (dr.Read()) // { // oLeaveDetail = CreateDetailObject(dr); // } // dr.Close(); // tc.End(); // } // catch (Exception e) // { // #region Handle Exception // if (tc != null) // tc.HandleError(); // ExceptionLog.Write(e); // throw new ServiceException("Failed to Get Leave Parameter: " + e.Message, e); // #endregion // } // #region Cache Footer // _cache.Add(oLeaveDetail, "Get", paramID); // #endregion // return oLeaveDetail; //} public LeaveParameter GetByLeaveID(int leaveID) { LeaveParameter oLeaveDetail = new LeaveParameter(); #region Cache Header oLeaveDetail = (LeaveParameter)_cache["GetByLeaveID", leaveID]; if (oLeaveDetail != null) return oLeaveDetail; #endregion TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(LeaveParameterDA.GetByLeaveID(tc, leaveID)); if (dr.Read()) { oLeaveDetail = CreateObject(dr); } dr.Close(); tc.End(); } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException("Failed to Get Leave Parameter", e); #endregion } #region Cache Footer _cache.Add(oLeaveDetail, "GetByLeaveID", leaveID); #endregion return oLeaveDetail; } public ObjectsTemplate Get() { #region Cache Header ObjectsTemplate oLeaveParameters = _cache["Get"] as ObjectsTemplate; if (oLeaveParameters != null) return oLeaveParameters; #endregion TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader oreader =new DataReader( LeaveParameterDA.Get(tc)); oLeaveParameters =this.CreateObjects(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(oLeaveParameters, "Get"); #endregion return oLeaveParameters; } public ObjectsTemplate GetByParamId(int paramId) { #region Cache Header ObjectsTemplate oLeaveParameters = _cache["Get"] as ObjectsTemplate; if (oLeaveParameters != null) return oLeaveParameters; #endregion TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader oreader =new DataReader(LeaveParameterDA.GetByParamId(tc, paramId)); oLeaveParameters = this.CreateObjects(oreader); oreader.Close(); tc.End(); } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException("Failed to Get Leave Parameter : " + e.Message, e); #endregion } #region Cache Footer _cache.Add(oLeaveParameters, "Get"); #endregion return oLeaveParameters; } public ObjectsTemplate GetbyLeaveID(ID leaveId) { ObjectsTemplate oLeaveParameters = new ObjectsTemplate(); TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr =new DataReader(LeaveParameterDA.GetByLeaveID (tc, leaveId.Integer )); oLeaveParameters = this.CreateObjects(dr); dr.Close(); tc.End(); } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException("Failed to Get Leave Parameter: " + e.Message, e); #endregion } return oLeaveParameters; } public ObjectsTemplate Get(bool isActive, ID PayrolltypeID) { #region Cache Header ObjectsTemplate oLeaveParameters = _cache["Get"] as ObjectsTemplate; if (oLeaveParameters != null) return oLeaveParameters; #endregion TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader oreader =new DataReader(LeaveParameterDA.Get(tc, isActive, PayrolltypeID)); oLeaveParameters = this.CreateObjects(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(oLeaveParameters, "Get", isActive); #endregion return oLeaveParameters; } public ObjectsTemplate Get(ID sbuId, ID locationId, ID functionId, bool IsActive) { ObjectsTemplate oLeaveParameters = null; TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader oreader =new DataReader(LeaveParameterDA.Get(tc, sbuId.Integer, locationId.Integer, functionId.Integer, IsActive)); oLeaveParameters = this.CreateObjects(oreader); oreader.Close(); tc.End(); } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException("Failed to Get Leave Parameter :" + e.Message , e); #endregion } return oLeaveParameters; } public ObjectsTemplate Get(ID sbuId, ID locationId, ID functionId) { ObjectsTemplate oLeaveParameters = null; TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader oreader =new DataReader(LeaveParameterDA.Get(tc, sbuId.Integer, locationId.Integer, functionId.Integer)); oLeaveParameters = this.CreateObjects(oreader); oreader.Close(); tc.End(); } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException("Failed to Get Leave Parameter: " + e.Message , e); #endregion } return oLeaveParameters; } public ObjectsTemplate Get(ID sbuId, ID locationId, ID functionId, int leaveID) { ObjectsTemplate oLeaveParameters = null; TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader oreader =new DataReader(LeaveParameterDA.Get(tc, sbuId.Integer, locationId.Integer, functionId.Integer, leaveID)); oLeaveParameters = this.CreateObjects(oreader); oreader.Close(); tc.End(); } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException("Failed to Get Leave Parameter: " + e.Message, e); #endregion } return oLeaveParameters; } public LeaveParameter GetParameter(ID sbuId, ID locationId, ID functionId, int nLeaveID) { LeaveParameter oLeaveParameter = null; TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader oreader =new DataReader(LeaveParameterDA.GetParameter(tc, sbuId.Integer, locationId.Integer, functionId.Integer, nLeaveID)); if (oreader.Read()) { oLeaveParameter = this.CreateObject(oreader); } oreader.Close(); tc.End(); } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException("Failed to Get Leave Parameter: " + e.Message, e); #endregion } return oLeaveParameter; } //public ObjectsTemplate GetSBUs(ID leaveParamId) //{ // ObjectsTemplate oLeaveSBUs = null; // TransactionContext tc = null; // try // { // tc = TransactionContext.Begin(UtilityDA.Contex); // IDataReader oreader = LeaveParameterDA.GetLeaveSBUs(tc, leaveParamId.Integer); // oLeaveSBUs = CreateLeaveSBUs(oreader); // oreader.Close(); // tc.End(); // } // catch (Exception e) // { // #region Handle Exception // if (tc != null) // tc.HandleError(); // ExceptionLog.Write(e); // throw new ServiceException("Failed to Get Leave SBUs", e); // #endregion // } // return oLeaveSBUs; //} //public ObjectsTemplate GetLocations(ID leaveParamId) //{ // ObjectsTemplate oLeaveLocations = null; // TransactionContext tc = null; // try // { // tc = TransactionContext.Begin(UtilityDA.Contex); // IDataReader oreader = LeaveParameterDA.GetLeaveLocations(tc, leaveParamId.Integer); // oLeaveLocations = CreateLeaveLocations(oreader); // oreader.Close(); // tc.End(); // } // catch (Exception e) // { // #region Handle Exception // if (tc != null) // tc.HandleError(); // ExceptionLog.Write(e); // throw new ServiceException("Failed to Get Leave Locations", e); // #endregion // } // return oLeaveLocations; //} //public ObjectsTemplate GetFunctions(ID leaveParamId) //{ // ObjectsTemplate oLeaveFunctions = null; // TransactionContext tc = null; // try // { // tc = TransactionContext.Begin(UtilityDA.Contex); // IDataReader oreader = LeaveParameterDA.GetLeaveFunctions(tc, leaveParamId.Integer); // oLeaveFunctions = CreateLeaveFunctions(oreader); // oreader.Close(); // tc.End(); // } // catch (Exception e) // { // #region Handle Exception // if (tc != null) // tc.HandleError(); // ExceptionLog.Write(e); // throw new ServiceException("Failed to Get Leave Functions", e); // #endregion // } // return oLeaveFunctions; //} public ObjectsTemplate GetDetails(ID leaveParamId) { #region Cache Header ObjectsTemplate oDetails = _cache["Get"] as ObjectsTemplate; if (oDetails != null) return oDetails; #endregion TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader oreader =new DataReader(LeaveParameterDA.GetDetails(tc, leaveParamId.Integer)); oDetails = this.CreateDetailObjects(oreader); oreader.Close(); } catch (Exception ex) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(ex); throw new ServiceException("Failed to Get Leave Details: " + ex.Message, ex); #endregion } #region Cache Footer _cache.Add(oDetails, "GetDetails", leaveParamId); #endregion return oDetails; } public ObjectsTemplate GetDetails() { #region Cache Header ObjectsTemplate oDetails = _cache["Get"] as ObjectsTemplate; if (oDetails != null) return oDetails; #endregion TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader oreader = new DataReader(LeaveParameterDA.GetDetails(tc)); oDetails = this.CreateDetailObjects(oreader); oreader.Close(); } catch (Exception ex) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(ex); throw new ServiceException("Failed to Get Leave Details: " + ex.Message, ex); #endregion } #region Cache Footer _cache.Add(oDetails, "GetDetails"); #endregion return oDetails; } //public ID Save(LeaveParameter oLeaveParameter) //{ // TransactionContext tc = null; // try // { // tc = TransactionContext.Begin(true, UtilityDA.Contex); // if (oLeaveParameter.IsNew) // { // this.SetObjectID(oLeaveParameter, ID.FromInteger(LeaveParameterDA.GetNewID(tc))); // LeaveParameterDA.Insert(tc, oLeaveParameter); // } // else // { // LeaveParameterDA.Update(tc, oLeaveParameter); // } // LeaveParameterDA.DeleteLeaveSBU(tc, oLeaveParameter.ID.Integer); // foreach (LeaveSBU oSBU in oLeaveParameter.SBUs) // { // oSBU.LeaveParamId = oLeaveParameter.ID.Integer; // LeaveParameterDA.InsertLeaveSBU(tc, oSBU); // } // LeaveParameterDA.DeleteLeaveLocation(tc, oLeaveParameter.ID.Integer); // foreach (LeaveLocation oLoc in oLeaveParameter.Locations) // { // oLoc.LeaveParamId = oLeaveParameter.ID.Integer; // LeaveParameterDA.InsertLeaveLocation(tc, oLoc); // } // LeaveParameterDA.DeleteLeaveFunction(tc, oLeaveParameter.ID.Integer); // foreach (LeaveFunction oFun in oLeaveParameter.Functions) // { // oFun.LeaveParamId = oLeaveParameter.ID.Integer; // LeaveParameterDA.InsertLeaveFunction(tc, oFun); // } // LeaveParameterDA.DeleteDetails(tc, oLeaveParameter.ID.Integer); // foreach (LeaveParameterDetail oDetail in oLeaveParameter.Details) // { // oDetail.LeaveParamId = oLeaveParameter.ID.Integer; // LeaveParameterDA.InsertChildren(tc, oLeaveParameter.ID.Integer, oDetail); // } // tc.End(); // } // catch (Exception e) // { // #region Handle Exception // if (tc != null) // tc.HandleError(); // ExceptionLog.Write(e); // throw new ServiceException("Failed to Save Leave Parameter :" + e.Message, e); // #endregion // } // return oLeaveParameter.ID; //} public LeaveParameterDetail GetDetail(int paramID) { LeaveParameterDetail oLeaveDetail = new LeaveParameterDetail(); #region Cache Header oLeaveDetail = (LeaveParameterDetail)_cache["Get", paramID]; if (oLeaveDetail != null) return oLeaveDetail; #endregion TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(LeaveParameterDA.GetDetail(tc, paramID)); if (dr.Read()) { oLeaveDetail = CreateDetailObject(dr); } dr.Close(); tc.End(); } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException("Failed to Get Leave Parameter: " + e.Message, e); #endregion } #region Cache Footer _cache.Add(oLeaveDetail, "Get", paramID); #endregion return oLeaveDetail; } public ID Save(LeaveParameter oLeaveParameter) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); if (oLeaveParameter.IsNew) { int id = tc.GenerateID("LeaveParameter", "LEAVEPARAMID"); base.SetObjectID(oLeaveParameter, ID.FromInteger(id)); LeaveParameterDA.Insert(tc, oLeaveParameter); } else { LeaveParameterDA.Update(tc, oLeaveParameter); } LeaveParameterDA.DeleteDetails(tc, oLeaveParameter.ID.Integer); foreach (LeaveParameterDetail oDetail in oLeaveParameter.Details) { oDetail.LeaveParamId = oLeaveParameter.ID.Integer; this.SetObjectID(oDetail, ID.FromInteger(LeaveParameterDA.GetNewDetailID(tc))); LeaveParameterDA.InsertChildren(tc, oDetail); } SetupDetailService sdetailService = new SetupDetailService(); sdetailService.Save(tc, EnumParameterSetup.Leave, oLeaveParameter.SetupDetails, oLeaveParameter.ID); tc.End(); } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException("Failed to Save Leave Parameter :" + e.Message, e); #endregion } return oLeaveParameter.ID; } public void Delete(ID id) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); SetupDetailService sd = new SetupDetailService(); sd.Delete(tc, EnumParameterSetup.Leave , id); LeaveParameterDA.DeleteDetails(tc, id.Integer); //LeaveParameterDA.DeleteLeaveGrades(tc, id.Integer); //LeaveParameterDA.DeleteLeavePayItems(tc, id.Integer); //LeaveParameterDA.DeleteLeaveSBU(tc, id.Integer); //LeaveParameterDA.DeleteLeaveLocation(tc, id.Integer); //LeaveParameterDA.DeleteLeaveFunction(tc, id.Integer); //tc.End(); //tc = TransactionContext.Begin(true, UtilityDA.Contex); LeaveParameterDA.Delete(tc, id.Integer); tc.End(); } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException("Failed to Delete Leave Parameter: " + e.Message, e); #endregion } } #endregion #endregion } #endregion }