using System; using Ease.Core.Model; using Ease.Core.DataAccess; using System.Collections.Generic; using Ease.Core.Utility; using HRM.BO; using System.Data; namespace HRM.DA { public class ComponentUploadSetupService : ServiceTemplate, IComponentUploadSetupService { #region Private functions and declaration public ComponentUploadSetupService() { } private void MapObject(ComponentUploadSetup componentSetup, DataReader oReader) { base.SetObjectID(componentSetup, oReader.GetInt32("ComponentUploadSetupID", true, 0)); componentSetup.EmployeeID = oReader.GetInt32("EmployeeID", true, 0); componentSetup.ApproverID = oReader.GetInt32("ApproverID", true, 0); componentSetup.ItemID = oReader.GetInt32("ItemID", true, 0); componentSetup.ComponentType = (EnumComponentType)oReader.GetInt32("ComponentType", true, 0); componentSetup.Description = oReader.GetString("Description", true, null); componentSetup.IsDamageManagement = oReader.GetBoolean("IsDamageManagement", true, false); this.SetObjectState(componentSetup, Ease.Core.ObjectState.Saved); } protected override T CreateObject(DataReader oReader) { ComponentUploadSetup componentSetup = new ComponentUploadSetup(); MapObject(componentSetup, oReader); return componentSetup as T; } private ComponentUploadSetup CreateObject(DataReader oReader) { ComponentUploadSetup componentSetup = new ComponentUploadSetup(); MapObject(componentSetup, oReader); return componentSetup; } #endregion #region Service implementation public List Get() { List componentSetups = new List(); TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(ComponentUploadSetupDA.Get(tc)); componentSetups = 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 componentSetups; } public DataTable GetUploadedComponent(DateTime uploadMonth) { DataTable dtUploadedComponent = new DataTable(); List componentSetups = new List(); TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataSet ds = ComponentUploadSetupDA.GetUploadedComponent(tc, uploadMonth); dtUploadedComponent = (ds != null && (ds.Tables != null && ds.Tables.Count > 0)) ? ds.Tables[0] : new DataTable(); tc.End(); } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } return dtUploadedComponent; } public List Get(int empid) { List componentSetups = new List(); TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(ComponentUploadSetupDA.Get(tc, empid)); componentSetups = 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 componentSetups; } public List GetByEmpIDandItemID(int empId, int itemId) { List componentSetups = new List(); TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(ComponentUploadSetupDA.GetByEmpIDandItemID(tc, empId, itemId)); componentSetups = 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 componentSetups; } public List GetByApproverID(int apprvrID) { List componentSetups = new List(); TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(ComponentUploadSetupDA.GetByApproverID(tc, apprvrID)); componentSetups = 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 componentSetups; } public DataTable GetUploadedComponentReportData(DateTime fromDate, DateTime toDate) { TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataSet ds = ComponentUploadSetupDA.GetUploadedComponentReportData(tc, fromDate, toDate); tc.End(); if (ds != null && ds.Tables.Count > 0) return ds.Tables[0].Copy(); return new DataTable(); } catch (Exception e) { if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); } } public DataTable GetUploadedComponentEmpReportData(DateTime salaryMonth, int componentId, string empIds) { DataTable dtComponentSetups = new DataTable(); TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataSet ds = ComponentUploadSetupDA.GetUploadedComponentEmpReportData(tc, salaryMonth, componentId, empIds); dtComponentSetups = (ds != null && (ds.Tables != null && ds.Tables.Count > 0)) ? ds.Tables[0] : new DataTable(); tc.End(); } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } return dtComponentSetups; } public DataTable GetUploadedComponentEmpReportData(DateTime salaryMonth, string empIds) { DataTable dtComponentSetups = new DataTable(); TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataSet ds = ComponentUploadSetupDA.GetUploadedComponentEmpReportData(tc, salaryMonth, empIds); dtComponentSetups = (ds != null && (ds.Tables != null && ds.Tables.Count > 0)) ? ds.Tables[0] : new DataTable(); tc.End(); } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } return dtComponentSetups; } public void Save(List componentSetups) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); int id; foreach (ComponentUploadSetup componentSetup in componentSetups) { if (componentSetup.IsNew) { id = tc.GenerateID("ComponentUploadSetup", "ComponentUploadSetupID"); base.SetObjectID(componentSetup, id); ComponentUploadSetupDA.Insert(tc, componentSetup); } else { ComponentUploadSetupDA.Update(tc, componentSetup); } } tc.End(); } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new Exception("Failed to Component Upload Setup. Because " + e.Message, e); #endregion } } public void Delete(int id) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); ComponentUploadSetupDA.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 void DeleteSingleComponent(ComponentUploadSetup oComponentUploadSetup) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); ComponentUploadSetupDA.DeleteSingleComponent(tc, oComponentUploadSetup.EmployeeID, oComponentUploadSetup.ApproverID, oComponentUploadSetup.ComponentType, oComponentUploadSetup.ItemID); tc.End(); } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } } public bool IsExist(int empId, int apprvrId, EnumComponentType componentType, int itemId) { bool exist = false; TransactionContext tc = null; try { tc = TransactionContext.Begin(); exist = ComponentUploadSetupDA.IsExist(tc, empId, apprvrId, componentType, itemId); tc.End(); } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } return exist; } /// The employee is the approver of at least one component upload setup. public bool HasApproverSetup(int approverId) { bool exist = false; TransactionContext tc = null; try { tc = TransactionContext.Begin(); exist = ComponentUploadSetupDA.HasApproverSetup(tc, approverId); tc.End(); } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } return exist; } /// The employee has at least one component upload setup (may upload components). public bool HasUploaderSetup(int employeeId) { bool exist = false; TransactionContext tc = null; try { tc = TransactionContext.Begin(); exist = ComponentUploadSetupDA.HasUploaderSetup(tc, employeeId); tc.End(); } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } return exist; } public List LoadComponentType(int payrollTypeID) { List oComponentUploadSetups = new List(); ComponentUploadSetup oallance = null; ComponentUploadSetup odeduction = null; ComponentUploadSetup oterm = null; ComponentUploadSetup obonus = null; ComponentUploadSetup oloan = null; ComponentUploadSetup opiItem = null; ComponentUploadSetup opf = null; List allowances = new AllowanceDeductionService().GetAllowance(EnumStatus.Regardless, payrollTypeID); foreach (AllowanceDeduction item in allowances) { oallance = new ComponentUploadSetup(); oallance.ComponentType = EnumComponentType.Allowance; oallance.Description = item.Name; oallance.ItemID = item.ID; oComponentUploadSetups.Add(oallance); } List deductions = new AllowanceDeductionService().GetDeduction(EnumStatus.Regardless, payrollTypeID); foreach (AllowanceDeduction item in deductions) { odeduction = new ComponentUploadSetup(); odeduction.ComponentType = EnumComponentType.Deduction; odeduction.Description = item.Name; odeduction.ItemID = item.ID; oComponentUploadSetups.Add(odeduction); } List terms = new TermService().Get(EnumStatus.Regardless, payrollTypeID); foreach (Term item in terms) { oterm = new ComponentUploadSetup(); oterm.ComponentType = EnumComponentType.OverTime; oterm.Description = item.Name; oterm.ItemID = item.ID; oComponentUploadSetups.Add(oterm); } List bonuss = new BonusService().Get(EnumStatus.Regardless, payrollTypeID); foreach (Bonus item in bonuss) { obonus = new ComponentUploadSetup(); obonus.ComponentType = EnumComponentType.Bonus; obonus.Description = item.Name; obonus.ItemID = item.ID; oComponentUploadSetups.Add(obonus); } List loans = new LoanService().Get(EnumStatus.Regardless); foreach (Loan item in loans) { oloan = new ComponentUploadSetup(); oloan.ComponentType = EnumComponentType.Loan; oloan.Description = item.Name; oloan.ItemID = item.ID; oComponentUploadSetups.Add(oloan); } List opiItems = new OpiItemService().Get(EnumStatus.Regardless, payrollTypeID); foreach (OpiItem item in opiItems) { opiItem = new ComponentUploadSetup(); opiItem.ComponentType = EnumComponentType.OPI; opiItem.Description = item.Name; opiItem.ItemID = item.ID; oComponentUploadSetups.Add(opiItem); } opf = new ComponentUploadSetup(); opf.ComponentType = EnumComponentType.PF; opf.Description = "PF"; opf.ItemID = (int)EnumComponentType.PF; oComponentUploadSetups.Add(opf); return oComponentUploadSetups; } #endregion } }