using System; using System.Data; using System.Linq; using System.Collections.Generic; using HRM.BO; using HRM.DA; using Ease.Core.Model; using Ease.Core.DataAccess; using Ease.Core.Utility; using Ease.Core; namespace HRM.DA { public class BankService : ServiceTemplate, IBankService { public BankService() { } private void MapObject(Bank oBank, DataReader oReader) { //oBank.ID = oReader.GetID("BankID"); base.SetObjectID(oBank, oReader.GetInt32("BankID").Value); oBank.Code = oReader.GetString("Code"); oBank.Name = oReader.GetString("Name"); oBank.Accountingformat = oReader.GetString("ACCOUNTNOFORMAT"); oBank.AccountNo = oReader.GetString("AccountNo"); oBank.Sequence = oReader.GetInt32("SequenceNO").Value; oBank.Status = (EnumStatus)oReader.GetInt32("Status").Value; oBank.CreatedBy = oReader.GetInt32("CreatedBy", 0); oBank.CreatedDate = oReader.GetDateTime("CreationDate").Value; oBank.ModifiedBy = oReader.GetInt32("ModifiedBy", 0); oBank.ModifiedDate = oReader.GetDateTime("ModifiedDate"); oBank.BankAddress = oReader.GetString("BankAddress", true, null); oBank.ContactPerson = oReader.GetString("ContactPerson", true, null); oBank.ContactNo = oReader.GetString("ContactNo", true, null); this.SetObjectState(oBank, ObjectState.Saved); } protected override T CreateObject(DataReader oReader) { Bank oBank = new Bank(); MapObject(oBank, oReader); return oBank as T; } protected Bank CreateObject(DataReader oReader) { Bank oBank = new Bank(); MapObject(oBank, oReader); return oBank; } public string GetNextCode() { TransactionContext tc = null; string _code = ""; try { tc = TransactionContext.Begin(); _code = GlobalFunctionService.GetMaxCode(tc, "bank", "codeautogenerate", "Banks", "Code"); tc.End(); } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } return _code; } public Bank Get(int id) { Bank oBank = null; TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader oreader = new DataReader(BankDA.Get(tc, id)); if (oreader.Read()) { oBank = 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 oBank; } public List Get(EnumStatus status, int payrollTypeID) { List Banks = new List(); TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(BankDA.Get(tc, status, payrollTypeID)); Banks = 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 Banks; } public Bank GetByBrancID(int id) { Bank oBank = null; TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader oreader = new DataReader(BankDA.GetByBrancID(tc, id)); if (oreader.Read()) { oBank = 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 oBank; } public List Get() { List banks = new List(); TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(BankDA.Get(tc)); banks = 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 banks; } public DataTable GetDataTable() { TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataSet ds = BankDA.GetDataSet(tc); tc.End(); return ds.Tables[0]; } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } } //public List Get(EnumStatus status) //{ // List banks = new List(); // TransactionContext tc = null; // try // { // tc = TransactionContext.Begin(); // DataReader dr = new DataReader(BankDA.Get(tc, status)); // banks = 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 banks; //} public int Save(Bank oBank) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); if (oBank.IsNew) { int id = tc.GenerateID("Banks", "BankID"); base.SetObjectID(oBank, id); int seqNo = tc.GenerateID("Banks", "SequenceNO"); oBank.Sequence = seqNo; BankDA.Insert(tc, oBank); } else { BankDA.Update(tc, oBank); } tc.End(); return oBank.ID; } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } } public void ExecutePLSQL() { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); BankDA.ExecutePLSQL(tc); tc.End(); } catch (Exception e) { } } public void Delete(int id) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); BankDA.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 } } //for Excel Upload public static void SaveForUpload(TransactionContext tc, List banks, List saveItems) { try { foreach (Bank oBank in banks) { if (saveItems.FindIndex(x => x.ID == oBank.ID) < 0) { int seqNo = tc.GenerateID("Banks", "SequenceNO"); oBank.Sequence = seqNo; if (oBank.Code ==string.Empty) oBank.Code = GlobalFunctionService.GetMaxCode(tc, "banks", "Code"); oBank.CreatedBy = 1; oBank.CreatedDate = DateTime.Now; BankDA.Insert(tc, oBank); } else { oBank.ModifiedBy = 1; oBank.ModifiedDate = DateTime.Now; BankDA.Update(tc, oBank); } } } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } } } }