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 ADParameterEmployee Service [Serializable] public class ADParameterEmployeeService : ServiceTemplate, IADParameterEmployeeService { #region Private functions and declaration Cache _cache = new Cache(typeof(ADParameterEmployee)); #endregion public ADParameterEmployeeService() { } private void MapObject(ADParameterEmployee oADParameterEmployee, DataReader oReader) { base.SetObjectID(oADParameterEmployee, oReader.GetID("ADPARAMETEREMPID")); oADParameterEmployee.ADParameterID = oReader.GetID("aDParameterID"); oADParameterEmployee.AllowDeductID = oReader.GetID("allowDeductID"); oADParameterEmployee.Periodicity = (EnumPeriodicity)oReader.GetInt32("periodicity").Value; oADParameterEmployee.EmployeeID = oReader.GetID("employeeID"); oADParameterEmployee.FormDate = oReader.GetDateTime("fromDate").Value; oADParameterEmployee.TillDate = oReader.GetDateTime("TILLDATE"); oADParameterEmployee.MonthlyAmount = oReader.GetDouble("monthlyAmount").Value; //oADParameterEmployee.EuroAmount = oReader.GetDouble("EuroAmount").Value; //oADParameterEmployee.IsEuro = oReader.GetBoolean("IsEuro").Value; oADParameterEmployee.TotalAmount = oReader.GetDouble("totalAmount").Value; oADParameterEmployee.Arreartype = (EnumArrearType)oReader.GetInt32("ARREARINFO").Value; oADParameterEmployee.ADEmpType = (EnumADEmpType)oReader.GetInt32("ADEMPTYPE").Value; oADParameterEmployee.ValueType = (EnumValueType)oReader.GetInt32("ValueType").Value; oADParameterEmployee.TracNo = oReader.GetString("TracNo"); oADParameterEmployee.CreatedBy = oReader.GetID("CreatedBy"); oADParameterEmployee.CreatedDate = oReader.GetDateTime("CreatedDate").Value; oADParameterEmployee.ModifiedBy = oReader.GetID("ModifiedBy"); oADParameterEmployee.ModifiedDate = oReader.GetDateTime("ModifiedDate"); this.SetObjectState(oADParameterEmployee, Ease.CoreV35.ObjectState.Saved); } protected override T CreateObject(DataReader oReader) { ADParameterEmployee oADParameterEmployee = new ADParameterEmployee(); MapObject(oADParameterEmployee, oReader); return oADParameterEmployee as T; } protected ADParameterEmployee CreateObject(DataReader oReader) { ADParameterEmployee oADParameterEmployee = new ADParameterEmployee(); MapObject(oADParameterEmployee, oReader); return oADParameterEmployee; } #region Service implementation public ADParameterEmployee Get(ID id) { ADParameterEmployee oADParameterEmployee = new ADParameterEmployee(); #region Cache Header oADParameterEmployee = _cache["Get", id] as ADParameterEmployee; if (oADParameterEmployee != null) return oADParameterEmployee; #endregion TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader oreader = new DataReader(ADParameterEmployeeDA.Get(tc, id)); if (oreader.Read()) { oADParameterEmployee = 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(oADParameterEmployee, "Get", id); #endregion return oADParameterEmployee; } public ADParameterEmployee Get(ID nEmpID, ID nAllowDeductID, ID nADParamID) { ADParameterEmployee oADParameterEmployee = new ADParameterEmployee(); #region Cache Header oADParameterEmployee = _cache["Get", nEmpID, nAllowDeductID,nADParamID] as ADParameterEmployee; if (oADParameterEmployee != null) return oADParameterEmployee; #endregion TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader oreader = new DataReader(ADParameterEmployeeDA.Get(tc, nEmpID, nAllowDeductID, nADParamID)); if (oreader.Read()) { oADParameterEmployee = 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(oADParameterEmployee, "Get", nEmpID, nAllowDeductID, nADParamID); #endregion return oADParameterEmployee; } public ADParameterEmployee Get(ID nEmpID, ID nAllowDeductID, ID nADParamID,EnumArrearType nArrearType) { ADParameterEmployee oADParameterEmployee = new ADParameterEmployee(); #region Cache Header oADParameterEmployee = _cache["Get", nEmpID, nAllowDeductID, nADParamID,nArrearType] as ADParameterEmployee; if (oADParameterEmployee != null) return oADParameterEmployee; #endregion TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader oreader = new DataReader(ADParameterEmployeeDA.Get(tc, nEmpID, nAllowDeductID, nADParamID,nArrearType)); if (oreader.Read()) { oADParameterEmployee = 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(oADParameterEmployee, "Get", nEmpID, nAllowDeductID, nADParamID,nArrearType); #endregion return oADParameterEmployee; } public ObjectsTemplate GetbyParameter(ID nADPAramID, EnumADEmpType type) { #region Cache Header ObjectsTemplate aDParameterEmployees = _cache["GetByEmployee", nADPAramID, type] as ObjectsTemplate; if (aDParameterEmployees != null) return aDParameterEmployees; #endregion TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(ADParameterEmployeeDA.GetbyParameter(tc, nADPAramID, type)); aDParameterEmployees = 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(aDParameterEmployees, "GetByEmployee", nADPAramID, type); #endregion return aDParameterEmployees; } //public ObjectsTemplate GetByEmployee(ID nEmpID, EnumAllowOrDeduct adType, string sTypes) //{ // #region Cache Header // ObjectsTemplate aDParameterEmployees = _cache["GetByEmployee", nEmpID, adType, sTypes] as ObjectsTemplate; // if (aDParameterEmployees != null) // return aDParameterEmployees; // #endregion // TransactionContext tc = null; // try // { // tc = TransactionContext.Begin(); // DataReader dr = new DataReader(ADParameterEmployeeDA.GetByEmployee(tc, nEmpID, adType, sTypes)); // aDParameterEmployees = 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(aDParameterEmployees, "GetByEmployee", nEmpID, adType, sTypes); // #endregion // return aDParameterEmployees; //} public ObjectsTemplate Get(ID AllowDeductID, DateTime fromDate, DateTime toDate, ID PayrolltypeID) { ObjectsTemplate aDParameterEmployees = null; TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(ADParameterEmployeeDA.Get(tc,AllowDeductID, fromDate, toDate, PayrolltypeID)); aDParameterEmployees = 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 aDParameterEmployees; } public ObjectsTemplate GetForApproval(ID AllowDeductID, DateTime fromDate, DateTime toDate, ID PayrolltypeID) { ObjectsTemplate aDParameterEmployees = null; TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(ADParameterEmployeeDA.GetForApproval(tc, AllowDeductID, fromDate, toDate, PayrolltypeID)); aDParameterEmployees = 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 aDParameterEmployees; } public ObjectsTemplate Get(ID nEmpID,ID AllowDeductID,DateTime fromDate, DateTime toDate) { ObjectsTemplate aDParameterEmployees = null; TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(ADParameterEmployeeDA.Get(tc, nEmpID,AllowDeductID,fromDate, toDate)); aDParameterEmployees = 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 aDParameterEmployees; } public ObjectsTemplate Get(DateTime fromDate, DateTime toDate, ID PayrolltypeID) { ObjectsTemplate aDParameterEmployees = null; TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(ADParameterEmployeeDA.Get(tc,fromDate, toDate, PayrolltypeID)); aDParameterEmployees = 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 aDParameterEmployees; } public ObjectsTemplate GetByEmployee(ID nEmpID, EnumAllowOrDeduct adType, EnumADEmpType adEmpType, DateTime nextPayProcessDate, ID PayrolltypeID) { #region Cache Header ObjectsTemplate aDParameterEmployees = _cache["GetByEmployee", nEmpID, adType, adEmpType] as ObjectsTemplate; if (aDParameterEmployees != null) return aDParameterEmployees; #endregion TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(ADParameterEmployeeDA.GetByEmployee(tc, nEmpID, adType, adEmpType, nextPayProcessDate, PayrolltypeID)); aDParameterEmployees = 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(aDParameterEmployees, "GetByEmployee", nEmpID, adType, adEmpType); #endregion return aDParameterEmployees; } public ObjectsTemplate GetByEmployee(ID nEmpID,ID nAllowDeductID,ID PayrolltypeID) { #region Cache Header ObjectsTemplate aDParameterEmployees = _cache["GetByEmployee", nEmpID, nAllowDeductID] as ObjectsTemplate; if (aDParameterEmployees != null) return aDParameterEmployees; #endregion TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(ADParameterEmployeeDA.GetByEmployee(tc, nEmpID, nAllowDeductID, PayrolltypeID)); aDParameterEmployees = 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(aDParameterEmployees, "GetByEmployee", nEmpID, nAllowDeductID); #endregion return aDParameterEmployees; } public ObjectsTemplate Get(EnumStatus status) { #region Cache Header ObjectsTemplate aDParameterEmployees = _cache["Get"] as ObjectsTemplate; if (aDParameterEmployees != null) return aDParameterEmployees; #endregion TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(ADParameterEmployeeDA.Get(tc, status)); aDParameterEmployees = 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(aDParameterEmployees, "Get",status); #endregion return aDParameterEmployees; } public ObjectsTemplate GetbyParameter(ID nADParamID, DateTime nextPayProcessDate) { #region Cache Header ObjectsTemplate aDParameterEmployees = _cache["Get", nADParamID] as ObjectsTemplate; if (aDParameterEmployees != null) return aDParameterEmployees; #endregion TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(ADParameterEmployeeDA.GetbyParameter(tc, nADParamID, nextPayProcessDate)); aDParameterEmployees = 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(aDParameterEmployees, "Get", nADParamID); #endregion return aDParameterEmployees; } public ObjectsTemplate GetByAllow(ID nAllowdeductID) { #region Cache Header ObjectsTemplate aDParameterEmployees = _cache["Get", nAllowdeductID] as ObjectsTemplate; if (aDParameterEmployees != null) return aDParameterEmployees; #endregion TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(ADParameterEmployeeDA.GetByAllow(tc, nAllowdeductID)); aDParameterEmployees = 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(aDParameterEmployees, "Get", nAllowdeductID); #endregion return aDParameterEmployees; } public ObjectsTemplate GetByAllowForApproval(ID nAllowdeductID, ID PayrolltypeID) { #region Cache Header ObjectsTemplate aDParameterEmployees = _cache["GetByAllowForApproval", nAllowdeductID] as ObjectsTemplate; if (aDParameterEmployees != null) return aDParameterEmployees; #endregion TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(ADParameterEmployeeDA.GetByAllowForApproval(tc, nAllowdeductID, PayrolltypeID)); aDParameterEmployees = 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(aDParameterEmployees, "GetByAllowForApproval", nAllowdeductID); #endregion return aDParameterEmployees; } public ObjectsTemplate GetByCreatedBy(ID createdByID, DateTime nextPayProcessDate) { ObjectsTemplate aDParameterEmployees = new ObjectsTemplate(); TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(ADParameterEmployeeDA.GetByCreatedBy(tc, createdByID, nextPayProcessDate)); aDParameterEmployees = 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 aDParameterEmployees; } public ID Save2(ADParameterEmployee oADParameterEmployee, TransactionContext tc) { int id = 0; try { if (oADParameterEmployee.IsNew) { id = tc.GenerateID("ADParameterEmployee", "ADPARAMETEREMPID"); base.SetObjectID(oADParameterEmployee, ID.FromInteger(id)); ADParameterEmployeeDA.Insert(tc, oADParameterEmployee); } else { ADParameterEmployeeDA.Update(tc, oADParameterEmployee); } return oADParameterEmployee.ID; } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } } public ID Save(ADParameterEmployee oADParameterEmployee) { TransactionContext tc = null; ADParameterEmployee adEmpArrear = null; int id = 0; try { tc = TransactionContext.Begin(true); if (oADParameterEmployee.IsNew) { //if(oADParameterEmployee.AllowDeductID.Integer==14) //{ // id = tc.GenerateID("ADParameterEmployee", "ADPARAMETEREMPID"); // base.SetObjectID(oADParameterEmployee, ID.FromInteger(id)); // ADParameterEmployeeDA.Insert(tc, oADParameterEmployee); //} // else //{ if (oADParameterEmployee.FormDate <= SystemInformation.CurrentSysInfo.LastPayProcessDate) { adEmpArrear = oADParameterEmployee.Clone(); adEmpArrear.Arreartype = EnumArrearType.ToCalculate; adEmpArrear.TillDate = SystemInformation.CurrentSysInfo.LastPayProcessDate; adEmpArrear.CreatedBy = User.CurrentUser.ID; adEmpArrear.CreatedDate = DateTime.Today ; adEmpArrear.ModifiedBy = User.CurrentUser.ID; adEmpArrear.ModifiedDate = DateTime.Today; id = tc.GenerateID("ADParameterEmployee", "ADPARAMETEREMPID"); base.SetObjectID(adEmpArrear, ID.FromInteger(id)); ADParameterEmployeeDA.Insert(tc, adEmpArrear); oADParameterEmployee.FormDate = SystemInformation.CurrentSysInfo.LastPayProcessDate.AddDays(1); } id = tc.GenerateID("ADParameterEmployee", "ADPARAMETEREMPID"); base.SetObjectID(oADParameterEmployee, ID.FromInteger(id)); //ADParameterEmployeeDA.DeleteByAllowDeductMonth(tc, oADParameterEmployee.EmployeeID, oADParameterEmployee.AllowDeductID, oADParameterEmployee.FormDate); ADParameterEmployeeDA.Insert(tc, oADParameterEmployee); } //} else { ADParameterEmployeeDA.Update(tc, oADParameterEmployee); } tc.End(); return oADParameterEmployee.ID; } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } } public void Save(ObjectsTemplate items,ID allowDeducID) { TransactionContext tc = null; int id = 0; try { tc = TransactionContext.Begin(true); //this.DeleteByAllo(tc,allowDeducID); foreach (ADParameterEmployee item in items) { //this.DeleteByEmpID(tc,item.EmployeeID, item.ADParameterID); id = tc.GenerateID("ADParameterEmployee", "ADPARAMETEREMPID"); base.SetObjectID(item, ID.FromInteger(id)); ADParameterEmployeeDA.Insert(tc, item); } 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 Save(ObjectsTemplate items, ID allowDeducID, ID createdBy) { TransactionContext tc = null; int id = 0; try { tc = TransactionContext.Begin(true); foreach (ADParameterEmployee item in items) { id = tc.GenerateID("ADParameterEmployee", "ADPARAMETEREMPID"); base.SetObjectID(item, ID.FromInteger(id)); item.AllowDeductID = allowDeducID; item.CreatedBy = createdBy; item.CreatedDate = DateTime.Today; ADParameterEmployeeDA.Insert(tc, item); } 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 Delete(ID id) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); ADParameterEmployeeDA.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 Delete(ADParameterEmployee adParamEmployee) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); ADParameterEmployeeDA.Delete(tc, adParamEmployee); 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 DeleteByAllowDeductMonth(ID nEmpID, ID nAllowDeductID, DateTime dAllowDeductMonht) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); ADParameterEmployeeDA.DeleteByAllowDeductMonth(tc, nEmpID, nAllowDeductID, dAllowDeductMonht); tc.End(); } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } } //internal void DeleteByAllo(TransactionContext tc, ID allowDeductID) //{ // //TransactionContext tc = null; // try // { // //tc = TransactionContext.Begin(true); // ADParameterEmployeeDA.DeleteByAllo(tc, allowDeductID); // //tc.End(); // } // catch (Exception e) // { // #region Handle Exception // //if (tc != null) // // tc.HandleError(); // ExceptionLog.Write(e); // throw new ServiceException(e.Message, e); // #endregion // } //} //internal void DeleteByEmpID(TransactionContext tc,ID nEmpID, ID nADParameterID) //{ // try // { // ADParameterEmployeeDA.DeleteByEmpID(tc, nEmpID, nADParameterID); // } // catch (Exception e) // { // #region Handle Exception // ExceptionLog.Write(e); // throw new ServiceException(e.Message, e); // #endregion // } //} //public void DeleteByEmpID(ID nEmpID, ID nADParameterID) //{ // TransactionContext tc = null; // try // { // tc = TransactionContext.Begin(true); // this.DeleteByEmpID(tc, nEmpID, nADParameterID); // 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 DeleteByAllo(ID nAllowDeducID) //{ // TransactionContext tc = null; // try // { // tc = TransactionContext.Begin(true); // this.DeleteByAllo(tc, nAllowDeducID); // 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 }