using Ease.Core.DataAccess; using Ease.Core.Model; using Ease.Core.Utility; using HRM.BO; using NPOI.SS.Formula.Functions; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace HRM.DA { public class FundBankService : ServiceTemplate, IFundBankService { public FundBankService() { } private void MapObject(FundBank oFundBank, DataReader oReader) { base.SetObjectID(oFundBank, oReader.GetInt32("BANKID").Value); oFundBank.Code = oReader.GetString("BankCode"); oFundBank.Name = oReader.GetString("Name"); oFundBank.GLID = oReader.GetInt32("GLID")==null? 0 : oReader.GetInt32("GLID").Value; oFundBank.Rating =(EnumBankRating) oReader.GetInt32("RATINGID").Value; oFundBank.Type = (EnumGLType) oReader.GetInt32("Type").Value; oFundBank.Ratio = (double)(oReader.GetDouble("RATIO") == null ? 0 : oReader.GetDouble("RATIO")); oFundBank.ThreeMonthInterest = (double)(oReader.GetDouble("THREEMONTHINTEREST")==null? 0 : oReader.GetDouble("THREEMONTHINTEREST")); oFundBank.SixMonthInterest = (double)(oReader.GetDouble("SIXMONTHINTEREST") == null? 0 : oReader.GetDouble("SIXMONTHINTEREST")); oFundBank.OneYearInterest = (double)(oReader.GetDouble("ONEYEARINTEREST") == null ? 0 : oReader.GetDouble("ONEYEARINTEREST")); oFundBank.FiveYearInterest = (double)(oReader.GetDouble("FIVEYEARINTEREST")==null? 0 : oReader.GetDouble("FIVEYEARINTEREST")); oFundBank.Address = oReader.GetString("ADDRESS")==null ? "": oReader.GetString("ADDRESS"); oFundBank.WebAddress = oReader.GetString("WEBADDRESS") == null ? "" : oReader.GetString("WEBADDRESS"); oFundBank.FundTypeID = oReader.GetInt32("FundTypeID").Value; } protected override T CreateObject(DataReader oReader) { FundBank oFundBank = new FundBank(); MapObject(oFundBank, oReader); return oFundBank as T; } public void Delete(int id) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); FundBankDA.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 FundBank Get(int id) { FundBank oFundBank = null; TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader oreader = new DataReader(FundBankDA.Get(tc, id)); if (oreader.Read()) { oFundBank = 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 } return oFundBank; } public List Get(int id, int payrollTypeID) { List fundBanks = new List(); TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(FundBankDA.Get(tc, id, payrollTypeID)); fundBanks = 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 fundBanks; } public List GetByFundTypeID(int fundTypeID) { List fundBanks = new List(); TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(FundBankDA.GetByFundTypeID(tc, fundTypeID)); fundBanks = 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 fundBanks; } public List Get() { List fundBanks = new List(); TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(FundBankDA.Get(tc)); fundBanks = 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 fundBanks; } public string GetNextCode() { throw new NotImplementedException(); } public int Save(FundBank oFundBank) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); if (oFundBank.IsNew) { int id = tc.GenerateID("FM_BANK", "BankID"); base.SetObjectID(oFundBank, id); FundBankDA.Insert(tc, oFundBank); } else { FundBankDA.Update(tc, oFundBank); } tc.End(); return oFundBank.ID; } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } } } }