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 SetupDetail Service [Serializable] public class SetupDetailService : ServiceTemplate, ISetupDetailService { #region Private functions and declaration Cache _cache = new Cache(typeof(SetupDetail)); #endregion public SetupDetailService() { } private void MapObject(SetupDetail oSetupDetail, DataReader oReader) { base.SetObjectID(oSetupDetail, oReader.GetID("DetailID")); oSetupDetail.SetupID = oReader.GetID("SetupID"); oSetupDetail.TranID = oReader.GetID("tranID"); oSetupDetail.TranType = (EnmSetupManagerTranType)oReader.GetInt32("tranType").Value; this.SetObjectState(oSetupDetail, Ease.CoreV35.ObjectState.Saved); } protected override T CreateObject(DataReader oReader) { SetupDetail oSetupDetail = new SetupDetail(); MapObject(oSetupDetail, oReader); return oSetupDetail as T; } protected SetupDetail CreateObject(DataReader oReader) { SetupDetail oSetupDetail = new SetupDetail(); MapObject(oSetupDetail, oReader); return oSetupDetail; } #region Service implementation public ObjectsTemplate GetParameters(EnumParameterSetup setup) { ObjectsTemplate setupDetails = null; TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(SetupDetailDA.GetParameters(tc, setup)); setupDetails = 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 setupDetails; } public DataSet GetParameters(EnumParameterSetup setup, List sqlRelation, string InEmpSQL) { TransactionContext tc = null; DataSet odataset; try { tc = TransactionContext.Begin(); EmployeeSetupParameter empsetup = new EmployeeSetupParameter(setup); odataset = SetupDetailDA.GetParameters(tc, setup, sqlRelation,InEmpSQL); tc.End(); } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } return odataset; } public ObjectsTemplate GetParameters( EnumParameterSetup setup, int setupID) { ObjectsTemplate setupDetails = null; TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(SetupDetailDA.GetParameters(tc, setupID, setup)); setupDetails = 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 setupDetails; } public ObjectsTemplate GetUsedParameters( EnumParameterSetup setup, int setupID, int parameterID) { ObjectsTemplate setupDetails = null; TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(SetupDetailDA.GetUsedParameters(tc, setup, setupID, parameterID)); setupDetails = 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 setupDetails; } public ObjectsTemplate GetOTDetail(EnumParameterSetup setup, EnmSetupManagerTranType enmSetupManagerTranType) { ObjectsTemplate setupDetails = null; TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(SetupDetailDA.GetOTDetail(tc, setup, enmSetupManagerTranType)); setupDetails = 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 setupDetails; } public List GetTypes( EnumParameterSetup setup) { List types = null; TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataSet dataset = SetupDetailDA.GetTypes(tc, setup); types = new List(); foreach (DataRow orow in dataset.Tables[0].Rows) { types.Add((EnmSetupManagerTranType)Convert.ToInt32(orow[0])); } tc.End(); } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } return types; } public List GetParameterID( EnumParameterSetup setup, EnmSetupManagerTranType type, ID TranID) { List parameters = null; TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataSet dataset = SetupDetailDA.GetParameters(tc, setup, type, TranID); parameters = new List(); foreach (DataRow orow in dataset.Tables[0].Rows) { parameters.Add(Convert.ToInt32(orow[0])); } tc.End(); } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } return parameters; } public ObjectsTemplate GetUsedParameters( EnumParameterSetup setup, int parameterID) { ObjectsTemplate setupDetails = null; TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(SetupDetailDA.GetUsedParameters(tc, setup, parameterID)); setupDetails = 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 setupDetails; } public void Save(TransactionContext tc, EnumParameterSetup setup, ObjectsTemplate Details, ID SetupID) { try { this.Delete(tc, setup, SetupID); foreach (SetupDetail item in Details) { item.SetupID = SetupID; this.Save(tc, setup, item); } } catch (Exception Ex) { throw new ServiceException(Ex.Message); } } public ID Save(TransactionContext tc, EnumParameterSetup setup, SetupDetail oSetupDetail) { try { //tc = TransactionContext.Begin(true); if (oSetupDetail.IsNew) { int id = SetupDetailDA.GenerateID( tc, setup); base.SetObjectID(oSetupDetail, ID.FromInteger(id)); SetupDetailDA.Insert(tc, oSetupDetail,setup); } else { SetupDetailDA.Update(tc, oSetupDetail,setup); } // tc.End(); return oSetupDetail.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(TransactionContext tc, EnumParameterSetup setup, ID setupID) { try { SetupDetailDA.Delete(tc, setup, setupID); } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } } #endregion } #endregion }