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 Grade Service [Serializable] public class GradeService : ServiceTemplate, IGradeService { #region Private functions and declaration Cache _cache = new Cache(typeof(Grade)); #endregion public GradeService() { } private void MapObject(Grade oGrade, DataReader oReader) { base.SetObjectID(oGrade, oReader.GetID("GradeID")); oGrade.Code = oReader.GetString("code"); oGrade.Name = oReader.GetString("description"); oGrade.ColorCode = oReader.GetString("ColorCode"); oGrade.MaxBasic = oReader.GetInt32("maxbasic").Value; oGrade.MinBasic = oReader.GetInt32("minbasic").Value; oGrade.IsTransport = oReader.GetBoolean("isfreetransport").Value; oGrade.HasGrossConcept = oReader.GetBoolean("hasGrossConcept").Value; oGrade.BasicPercentofGross = oReader.GetDouble("basicPercentofGross").Value; oGrade.HasPayscale = oReader.GetBoolean("hasPayscale").Value; oGrade.ConfirmMonthDuration = oReader.GetInt32("confirmMonthDuration").Value; oGrade.GradeSegmentID = oReader.GetID("gradeSegmentID"); oGrade.RequiredDays = oReader.GetInt32("RequiredDays").Value; oGrade.Sequence = oReader.GetInt32("SequenceNo").Value; oGrade.Status = (EnumStatus)oReader.GetInt32("Status").Value; oGrade.CreatedBy = oReader.GetID("CreatedBy"); oGrade.CreatedDate = oReader.GetDateTime("CreationDate").Value; oGrade.ModifiedBy = oReader.GetID("ModifiedBy"); oGrade.ModifiedDate = oReader.GetDateTime("ModifiedDate"); oGrade.PayrollTypeID = oReader.GetID("PAYROLLTYPEID"); this.SetObjectState(oGrade, Ease.CoreV35.ObjectState.Saved); } protected override T CreateObject(DataReader oReader) { Grade oGrade = new Grade(); MapObject(oGrade, oReader); return oGrade as T; } protected Grade CreateObject(DataReader oReader) { Grade oGrade = new Grade(); MapObject(oGrade, oReader); return oGrade; } #region Service implementation public Grade Get(ID id) { Grade oGrade = new Grade(); #region Cache Header oGrade = _cache["Get", id] as Grade; if (oGrade != null) return oGrade; #endregion TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader oreader = new DataReader(GradeDA.Get(tc, id)); if (oreader.Read()) { oGrade = 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(oGrade, "Get", id); #endregion return oGrade; } public ObjectsTemplate GetAllPayrollTypes(EnumStatus status) { #region Cache Header ObjectsTemplate grades = _cache["Get"] as ObjectsTemplate; if (grades != null) return grades; #endregion TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(GradeDA.GetAllPayrollTypes(tc, status)); grades = 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(grades, "Get", status); #endregion return grades; } public string GetNextCode() { TransactionContext tc = null; string _code = ""; try { tc = TransactionContext.Begin(); _code = GlobalFunctionService.GetMaxCode(tc, "empgrade", "codeautogenerate", "GRADES", "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 Grade Get(string sCode, int payrollTypeID) { Grade oGrade = new Grade(); #region Cache Header oGrade = _cache["Get", sCode] as Grade; if (oGrade != null) return oGrade; #endregion TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader oreader = new DataReader(GradeDA.Get(tc, sCode, payrollTypeID)); if (oreader.Read()) { oGrade = 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(oGrade, "Get", sCode); #endregion return oGrade; } public ObjectsTemplate GetRegardlessPayrollType(EnumStatus status, int payrollTypeID) { #region Cache Header ObjectsTemplate grades = _cache["Get"] as ObjectsTemplate; if (grades != null) return grades; #endregion TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(GradeDA.GetRegardlessPayrollType(tc, status, payrollTypeID)); grades = 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(grades, "Get",status); #endregion return grades; } public ObjectsTemplate Get(EnumStatus status, int payrollTypeID) { #region Cache Header ObjectsTemplate grades = _cache["Get"] as ObjectsTemplate; if (grades != null) return grades; #endregion TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(GradeDA.Get(tc, status, payrollTypeID)); grades = 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(grades, "Get",status); #endregion return grades; } public ObjectsTemplate GetAddableGrades(ID nAllowDeductID, ID nADParamID, int payrollTypeID) { #region Cache Header ObjectsTemplate grades = _cache["Get", nAllowDeductID, nADParamID] as ObjectsTemplate; if (grades != null) return grades; #endregion TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = null; if (nADParamID.IsUnassigned) { dr = new DataReader(GradeDA.GetAddableGrades(tc, nAllowDeductID.Integer, 0, payrollTypeID)); } else { dr = new DataReader(GradeDA.GetAddableGrades(tc, nAllowDeductID.Integer, nADParamID.Integer, payrollTypeID)); } grades = 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(grades, "Get", nAllowDeductID, nADParamID); #endregion return grades; } public ObjectsTemplate GetAddableGradesForLoanParameter(ID LoaniD, ID LoanParameterId, int payrollTypeID) { #region Cache Header ObjectsTemplate grades = _cache["Get", LoaniD] as ObjectsTemplate; if (grades != null) return grades; #endregion TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = null; if (LoanParameterId.IsUnassigned) { dr = new DataReader(GradeDA.GetAddableGradesForLoanParameter(tc, LoaniD.Integer,0, payrollTypeID)); } else { dr = new DataReader(GradeDA.GetAddableGradesForLoanParameter(tc, LoaniD.Integer,LoanParameterId.Integer, payrollTypeID)); } grades = 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(grades, "Get", LoaniD); #endregion return grades; } public ObjectsTemplate GetAddableGradesForOT(ID nTermID, ID nTermParameterID, int payrollTypeID) { #region Cache Header ObjectsTemplate grades = _cache["Get", nTermID, nTermParameterID] as ObjectsTemplate; if (grades != null) return grades; #endregion TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = null; if (nTermParameterID.IsUnassigned) { dr = new DataReader(GradeDA.GetAddableGradesForOT(tc, nTermID.Integer, 0, payrollTypeID)); } else { dr = new DataReader(GradeDA.GetAddableGradesForOT(tc, nTermID.Integer, nTermParameterID.Integer, payrollTypeID)); } grades = 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(grades, "Get", nTermID, nTermParameterID); #endregion return grades; } public ObjectsTemplate GetAddableGradesForBonus(ID nBonusID, int payrollTypeID) { #region Cache Header ObjectsTemplate grades = _cache["Get", nBonusID] as ObjectsTemplate; if (grades != null) return grades; #endregion TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = null; if (nBonusID.IsUnassigned) { dr = new DataReader(GradeDA.GetAddableGradesForBonus(tc,0, payrollTypeID)); } else { dr = new DataReader(GradeDA.GetAddableGradesForBonus(tc, nBonusID.Integer, payrollTypeID)); } grades = 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(grades, "Get", nBonusID); #endregion return grades; } public ID Save(Grade oGrade) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); if (oGrade.IsNew) { int id = tc.GenerateID("GRADES", "GRADEID"); base.SetObjectID(oGrade, ID.FromInteger(id)); GradeDA.Insert(tc, oGrade); } else { GradeDA.Update(tc, oGrade); } tc.End(); return oGrade.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); GradeDA.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 ObjectsTemplate GetAllowableGrades(ID nOpiItmeID, ID nOpiParamID, int payrollTypeID) { #region Cache Header ObjectsTemplate grades = _cache["GetAllowableGrades", nOpiItmeID, nOpiParamID] as ObjectsTemplate; if (grades != null) return grades; #endregion TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = null; if (nOpiParamID.IsUnassigned) { dr = new DataReader(GradeDA.GetAllowableGrades(tc, nOpiItmeID.Integer, 0, payrollTypeID)); } else { dr = new DataReader(GradeDA.GetAllowableGrades(tc, nOpiItmeID.Integer, nOpiParamID.Integer, payrollTypeID)); } grades = 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(grades, "GetAllowableGrades", nOpiItmeID, nOpiParamID); #endregion return grades; } #endregion //For excel Upload public static void SaveForUpload(TransactionContext tc, ObjectsTemplate grades) { try { foreach (Grade oGrade in grades) { oGrade.PayrollTypeID = SystemInformation.CurrentSysInfo.PayrollTypeID; if (oGrade.IsNew) { int seqNo = tc.GenerateID("GRADES", "SequenceNo"); oGrade.Sequence = seqNo; bool isAutoGenerated = ConfigurationManager.GetBoolValue("grade", "codeautogenerate", EnumConfigurationType.Logic); if (isAutoGenerated == true) oGrade.Code = GlobalFunctionService.GetMaxCode(tc, "grade", "codeautogenerate", "Grades", "Code"); oGrade.CreatedBy = User.CurrentUser.ID; oGrade.CreatedDate = DateTime.Now; GradeDA.Insert(tc, oGrade); } else { oGrade.ModifiedBy = User.CurrentUser.ID; oGrade.ModifiedDate = DateTime.Now; GradeDA.Update(tc, oGrade); } } } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } } } #endregion }