324 lines
9.0 KiB
C#
324 lines
9.0 KiB
C#
using HRM.BO;
|
|
using HRM.DA;
|
|
using Ease.Core.DataAccess;
|
|
using Ease.Core.Model;
|
|
using Ease.Core.Utility;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
|
|
namespace HRM.DA
|
|
{
|
|
public class BranchService : ServiceTemplate, IBranchService
|
|
{
|
|
public BranchService()
|
|
{
|
|
}
|
|
|
|
private void MapObject(Branch oBranch, DataReader oReader)
|
|
{
|
|
//oBranch.ID = oReader.GetID("BranchID");
|
|
base.SetObjectID(oBranch, oReader.GetInt32("BranchID").Value);
|
|
oBranch.Code = oReader.GetString("Code");
|
|
oBranch.RoutingNo = oReader.GetString("RoutingNo");
|
|
oBranch.Name = oReader.GetString("Name");
|
|
oBranch.Address = oReader.GetString("Address");
|
|
oBranch.Telephone = oReader.GetString("Telephone");
|
|
oBranch.BankID = oReader.GetInt32("BankID", 0);
|
|
oBranch.Sequence = oReader.GetInt32("SequenceNO").Value;
|
|
oBranch.Status = (EnumStatus)oReader.GetInt32("Status").Value;
|
|
oBranch.CreatedBy = oReader.GetInt32("CreatedBy", 0);
|
|
oBranch.CreatedDate = oReader.GetDateTime("CreationDate").Value;
|
|
oBranch.ModifiedBy = oReader.GetInt32("ModifiedBy", 0);
|
|
oBranch.ModifiedDate = oReader.GetDateTime("ModifiedDate");
|
|
this.SetObjectState(oBranch, Ease.Core.ObjectState.Saved);
|
|
}
|
|
|
|
protected override T CreateObject<T>(DataReader oReader)
|
|
{
|
|
Branch oBranch = new Branch();
|
|
MapObject(oBranch, oReader);
|
|
return oBranch as T;
|
|
}
|
|
|
|
protected Branch CreateObject(DataReader oReader)
|
|
{
|
|
Branch oBranch = new Branch();
|
|
MapObject(oBranch, oReader);
|
|
return oBranch;
|
|
}
|
|
|
|
#region Service implementation
|
|
|
|
public string GetNextCode()
|
|
{
|
|
TransactionContext tc = null;
|
|
string _code = "";
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin();
|
|
_code = GlobalFunctionService.GetMaxCode(tc, "branch", "codeautogenerate", "BRANCHES", "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 Branch Get(int id)
|
|
{
|
|
Branch oBranch = null;
|
|
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin();
|
|
DataReader oreader = new DataReader(BranchDA.Get(tc, id));
|
|
if (oreader.Read())
|
|
{
|
|
oBranch = this.CreateObject<Branch>(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 oBranch;
|
|
}
|
|
|
|
public Branch Get(int id, TransactionContext tc)
|
|
{
|
|
Branch oBranch = null;
|
|
try
|
|
{
|
|
DataReader oreader = new DataReader(BranchDA.Get(tc, id));
|
|
if (oreader.Read())
|
|
{
|
|
oBranch = this.CreateObject<Branch>(oreader);
|
|
}
|
|
|
|
oreader.Close();
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
#region Handle Exception
|
|
|
|
ExceptionLog.Write(e);
|
|
throw new ServiceException(e.Message, e);
|
|
|
|
#endregion
|
|
}
|
|
|
|
return oBranch;
|
|
}
|
|
|
|
public List<Branch> GetChild(int bankID)
|
|
{
|
|
List<Branch> branchs = new List<Branch>();
|
|
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin();
|
|
DataReader dr = new DataReader(BranchDA.GetChild(tc, bankID));
|
|
branchs = this.CreateObjects<Branch>(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 branchs;
|
|
}
|
|
|
|
|
|
//public List<Branch> Get(EnumStatus status)
|
|
//{
|
|
// List<Branch> branchs = new List<Branch>();
|
|
// TransactionContext tc = null;
|
|
// try
|
|
// {
|
|
// tc = TransactionContext.Begin();
|
|
|
|
// DataReader dr = new DataReader(BranchDA.Get(tc, status,1));
|
|
// branchs = this.CreateObjects<Branch>(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 branchs;
|
|
//}
|
|
|
|
public List<Branch> Get(EnumStatus status, int payrolltypeid)
|
|
{
|
|
List<Branch> branchs = new List<Branch>();
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin();
|
|
|
|
DataReader dr = new DataReader(BranchDA.Get(tc, status, payrolltypeid));
|
|
branchs = this.CreateObjects<Branch>(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 branchs;
|
|
}
|
|
|
|
|
|
public int Save(Branch oBranch)
|
|
{
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
int nID = oBranch.BankID;
|
|
tc = TransactionContext.Begin(true);
|
|
if (oBranch.IsNew)
|
|
{
|
|
int id = tc.GenerateID("Branches", "BranchID");
|
|
|
|
base.SetObjectID(oBranch, id);
|
|
int seqNo = tc.GenerateID("Branches", "SequenceNO");
|
|
oBranch.Sequence = seqNo;
|
|
BranchDA.Insert(tc, oBranch);
|
|
}
|
|
else
|
|
{
|
|
BranchDA.Update(tc, oBranch);
|
|
}
|
|
|
|
tc.End();
|
|
return oBranch.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(int id)
|
|
{
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin(true);
|
|
BranchDA.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
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
//For Excel Upload
|
|
public static void SaveForUpload(TransactionContext tc, List<Branch> branches, List<Branch> saveItems)
|
|
{
|
|
try
|
|
{
|
|
foreach (Branch oBranch in branches)
|
|
{
|
|
if (saveItems.FindIndex(x => x.ID == oBranch.ID) < 0)
|
|
{
|
|
int seqNo = tc.GenerateID("Branches", "SequenceNO");
|
|
oBranch.Sequence = seqNo;
|
|
|
|
if (oBranch.Code == string.Empty)
|
|
oBranch.Code = GlobalFunctionService.GetMaxCode(tc, "Branches", "Code");
|
|
|
|
BranchDA.Insert(tc, oBranch);
|
|
}
|
|
else
|
|
{
|
|
BranchDA.Update(tc, oBranch);
|
|
}
|
|
}
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
#region Handle Exception
|
|
|
|
if (tc != null)
|
|
tc.HandleError();
|
|
ExceptionLog.Write(e);
|
|
throw new ServiceException(e.Message, e);
|
|
|
|
#endregion
|
|
}
|
|
}
|
|
}
|
|
} |