using System; using System.Data; using Ease.Core.Model; using Ease.Core.DataAccess; using Ease.Core; using System.Collections.Generic; using Ease.Core.Utility; using HRM.BO; namespace HRM.DA { public class UnAuthorizeLeaveParamService : ServiceTemplate, IUnAuthorizeLeaveParamService { public UnAuthorizeLeaveParamService() { } private void MapObject(UnAuthorizeLeaveParam oUnAuthorizeLeaveParam, DataReader oReader) { base.SetObjectID(oUnAuthorizeLeaveParam, (oReader.GetInt32("UaLeaveParamID").Value)); oUnAuthorizeLeaveParam.UnAhuthorizeLeaveID = oReader.GetInt32("UaLeaveID", 0); this.SetObjectState(oUnAuthorizeLeaveParam, Ease.Core.ObjectState.Saved); } protected override T CreateObject(DataReader oReader) { UnAuthorizeLeaveParam oUnAuthorizeLeave = new UnAuthorizeLeaveParam(); MapObject(oUnAuthorizeLeave, oReader); return oUnAuthorizeLeave as T; } protected UnAuthorizeLeaveParam CreateObject(DataReader oReader) { UnAuthorizeLeaveParam oUnAuthorizeLeave = new UnAuthorizeLeaveParam(); MapObject(oUnAuthorizeLeave, oReader); return oUnAuthorizeLeave; } private void MapObjectGrade(UnAuthorizeLeaveParam.UnAuthorizeLeaveParamGrade ograde, DataReader oReader) { ograde.id = oReader.GetInt32("UaLeaveParamIDGradeID").Value; ograde.paramID = oReader.GetInt32("UaLeaveParamID").Value; ograde.gradeID = oReader.GetInt32("GradeID").Value; ograde.gradeNameview = oReader.GetString("GradeName", true, string.Empty); } protected List CreateObjectGrades(DataReader dr) { List olist = new List(); while (dr.Read()) { UnAuthorizeLeaveParam.UnAuthorizeLeaveParamGrade ot = new UnAuthorizeLeaveParam.UnAuthorizeLeaveParamGrade(); this.MapObjectGrade(ot, dr); olist.Add(ot); } return olist; } private void MapDetailObject(UnAuthorizeLeaveParamDetail oUnAuthorizeLeaveParameter, DataReader oReader) { base.SetObjectID(oUnAuthorizeLeaveParameter, (oReader.GetInt32("ParamDetailID").Value)); oUnAuthorizeLeaveParameter.LeaveID = oReader.GetInt32("LeaveID", 0); oUnAuthorizeLeaveParameter.AllowanceID = oReader.GetInt32("ALLOWANCEID", 0); oUnAuthorizeLeaveParameter.UNLeaveParamID = oReader.GetInt32("UaLeaveParamID", 0); oUnAuthorizeLeaveParameter.ValueInPercent = oReader.GetDouble("VALUEINPERCENT").Value; oUnAuthorizeLeaveParameter.Type = (EnumSalaryComponent)oReader.GetInt32("Type").Value; this.SetObjectState(oUnAuthorizeLeaveParameter, Ease.Core.ObjectState.Saved); } protected List CreateObjectDetails(DataReader dr) { List olist = new List(); while (dr.Read()) { UnAuthorizeLeaveParamDetail ot = new UnAuthorizeLeaveParamDetail(); this.MapDetailObject(ot, dr); olist.Add(ot); } return olist; } #region Service implementation public UnAuthorizeLeaveParam Get(int id) { UnAuthorizeLeaveParam oUnAuthorizeLeave = new UnAuthorizeLeaveParam(); TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader oreader = new DataReader(UnAuthorizeLeaveParameterDA.Get(tc, id)); if (oreader.Read()) { oUnAuthorizeLeave = this.CreateObject(oreader); } oreader.Close(); if (oUnAuthorizeLeave != null) { oreader = new DataReader(UnAuthorizeLeaveParameterDA.GetDetail(tc, id)); oUnAuthorizeLeave.Details = this.CreateObjectDetails(oreader); oreader.Close(); oreader = new DataReader(UnAuthorizeLeaveParameterDA.GetGrades(tc, id)); oUnAuthorizeLeave.paramGrades = this.CreateObjectGrades(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 oUnAuthorizeLeave; } public List Get(int payrollTypeid, bool withDetail) { List unAuthorizeLeaves = null; TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(UnAuthorizeLeaveParameterDA.GetbyPayrollType(tc,payrollTypeid)); unAuthorizeLeaves = this.CreateObjects(dr); dr.Close(); if (unAuthorizeLeaves != null && withDetail==true) { dr = new DataReader(UnAuthorizeLeaveParameterDA.GetAllGrades(tc)); List ogrades = this.CreateObjectGrades(dr); dr.Close(); if(ogrades!=null) { unAuthorizeLeaves.ForEach(x => { x.paramGrades = ogrades.FindAll(g => g.paramID == x.ID); }); } dr = new DataReader(UnAuthorizeLeaveParameterDA.GetAllDetail(tc)); List dtls = this.CreateObjectDetails(dr); dr.Close(); if (dtls != null) { unAuthorizeLeaves.ForEach(x => { x.Details = dtls.FindAll(g => g.UNLeaveParamID == x.ID); }); } } tc.End(); } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } return unAuthorizeLeaves; } public List GetByGrade(int gradeID) { List unAuthorizeLeaves = null; TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(UnAuthorizeLeaveParameterDA.GetbygradeID(tc, gradeID)); unAuthorizeLeaves = this.CreateObjects(dr); dr.Close(); if (unAuthorizeLeaves != null ) { dr = new DataReader(UnAuthorizeLeaveParameterDA.GetAllGrades(tc)); List ogrades = this.CreateObjectGrades(dr); dr.Close(); if (ogrades != null) { unAuthorizeLeaves.ForEach(x => { x.paramGrades = ogrades.FindAll(g => g.paramID == x.ID); }); } dr = new DataReader(UnAuthorizeLeaveParameterDA.GetAllDetail(tc)); List dtls = this.CreateObjectDetails(dr); dr.Close(); if (dtls != null) { unAuthorizeLeaves.ForEach(x => { x.Details = dtls.FindAll(g => g.UNLeaveParamID == x.ID); }); } } tc.End(); } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } return unAuthorizeLeaves; } public List GetUsedGrades(int UaLeaveID) { List ogrades = new List(); TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(UnAuthorizeLeaveParameterDA.GetUsedGrades(tc, UaLeaveID)); ogrades = this.CreateObjectGrades(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 ogrades; } public List GetByLeaveID(int nLeaveID) { List unAuthorizeLeaves = null; TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(UnAuthorizeLeaveParameterDA.GetByLeaveID(tc, nLeaveID)); unAuthorizeLeaves = 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 unAuthorizeLeaves; } //public List ApplicableParameters(List employees) //{ // SetupDetailService oSetupDetailsService = new SetupDetailService(); // List details = oSetupDetailsService.GetParameters(EnumParameterSetup.SalaryDeduct); // List types = oSetupDetailsService.GetTypes(EnumParameterSetup.SalaryDeduct); // List empParametes = new List(); // foreach (Employee emp in employees) // { // EmployeeSetupParameter empparameter = new EmployeeSetupParameter(EnumParameterSetup.SalaryDeduct); // empparameter.Employee = emp; // empparameter.ParameterIDs = SetupManager.ApplicableParameters(emp, EnumParameterSetup.SalaryDeduct, types, details); // empParametes.Add(empparameter); // } // return empParametes; //} public int Save(UnAuthorizeLeaveParam oUnAuthorizeLeaveParam) { TransactionContext tc = null; int id = 0; try { tc = TransactionContext.Begin(true); if (oUnAuthorizeLeaveParam.IsNew) { id = tc.GenerateID("UALeaveParam", "UaLeaveParamID"); base.SetObjectID(oUnAuthorizeLeaveParam, (id)); UnAuthorizeLeaveParameterDA.Insert(tc, oUnAuthorizeLeaveParam); } else { UnAuthorizeLeaveParameterDA.Update(tc, oUnAuthorizeLeaveParam); UnAuthorizeLeaveParameterDA.DeleteDetail(tc, oUnAuthorizeLeaveParam.ID); UnAuthorizeLeaveParameterDA.DeleteGrade(tc, oUnAuthorizeLeaveParam.ID); } foreach (UnAuthorizeLeaveParamDetail detail in oUnAuthorizeLeaveParam.Details) { id = tc.GenerateID("LEAVESUSPENSEDEDUCT", "ParamDetailID"); base.SetObjectID(detail, (id)); detail.UNLeaveParamID = oUnAuthorizeLeaveParam.ID; detail.LeaveID = oUnAuthorizeLeaveParam.UnAhuthorizeLeaveID; UnAuthorizeLeaveParameterDA.Insert(tc, detail); } foreach (UnAuthorizeLeaveParam.UnAuthorizeLeaveParamGrade item in oUnAuthorizeLeaveParam.paramGrades) { item.id = tc.GenerateID("UALeaveParamGrade", "UaLeaveParamIDGradeID"); item.paramID = oUnAuthorizeLeaveParam.ID; UnAuthorizeLeaveParameterDA.InsertGrade(tc, item); } //SetupDetailService sdetailService = new SetupDetailService(); //sdetailService.Insert(tc, EnumParameterSetup.SalaryDeduct, // oUnAuthorizeLeaveParam.SetupDetails, oUnAuthorizeLeaveParam.ID); tc.End(); return oUnAuthorizeLeaveParam.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); UnAuthorizeLeaveParameterDA.Delete(tc, id); UnAuthorizeLeaveParameterDA.DeleteGrade(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 } }