303 lines
8.2 KiB
C#
303 lines
8.2 KiB
C#
using System;
|
|
using System.Data;
|
|
using Ease.Core.Model;
|
|
using Ease.Core.DataAccess;
|
|
using Ease.Core;
|
|
using System.Collections.Generic;
|
|
using Ease.Core.Utility;
|
|
using HRM.BO;
|
|
using HRM.DA;
|
|
|
|
namespace HRM.DA.Fund
|
|
{
|
|
public class ESBDefinitionService : ServiceTemplate //, IESBDefinitionService
|
|
{
|
|
public ESBDefinitionService()
|
|
{
|
|
}
|
|
|
|
private void MapObject(ESBDefinition def, DataReader dr)
|
|
{
|
|
base.SetObjectID(def, dr.GetInt32("ESBID").Value);
|
|
def.Description = dr.GetString("Description");
|
|
//def.ESBID = dr.GetID("ESBID");
|
|
// def.IsConfirmedRequired = dr.GetBoolean("IsConfirmedRequired").Value;
|
|
def.UserID = dr.GetInt32("UserID").Value;
|
|
def.MaxServiceLength = dr.GetDouble("ServiceLength").Value;
|
|
def.Trading = dr.GetDouble("Trading").Value;
|
|
def.CreatedBy = dr.GetInt32("CreatedBy").Value;
|
|
def.CreatedDate = dr.GetDateTime("CreatedDate").Value;
|
|
def.ModifiedBy = dr.GetInt32("ModifiedBy");
|
|
def.ModifiedDate = dr.GetDateTime("ModifiedDate");
|
|
//def.ProjectID = dr.GetInt32("ProjectID");
|
|
base.SetObjectState(def, Ease.Core.ObjectState.Saved);
|
|
}
|
|
|
|
protected override T CreateObject<T>(DataReader dr)
|
|
{
|
|
ESBDefinition def = new ESBDefinition();
|
|
|
|
MapObject(def, dr);
|
|
|
|
return def as T;
|
|
}
|
|
|
|
#region ChildFunction
|
|
|
|
private void MapESBSlab(ESBSlab slab, DataReader dr)
|
|
{
|
|
base.SetObjectID(slab, dr.GetInt32("SlabID").Value);
|
|
slab.CalculateNo = dr.GetDouble("CalCulNo").Value;
|
|
slab.DaysToConsider = dr.GetDouble("DaysToConsider").Value;
|
|
slab.ESBID = dr.GetInt32("ESBID").Value;
|
|
//slab.ServiceDay = dr.GetInt32("ServiceDay").Value;
|
|
//slab.ServiceMonth = dr.GetInt32("ServiceMonth").Value;
|
|
slab.ServiceYear = dr.GetInt32("ServiceYear").Value;
|
|
slab.UptoServiceYear = dr.GetInt32("UptoServiceYear").Value;
|
|
slab.CreatedBy = dr.GetInt32("CreatedBy").Value;
|
|
slab.CreatedDate = dr.GetDateTime("CreatedDate").Value;
|
|
slab.ModifiedBy = dr.GetInt32("ModifiedBy");
|
|
slab.ModifiedDate = dr.GetDateTime("ModifiedDate");
|
|
// slab.ProjectID = dr.GetInt32("ProjectID");
|
|
base.SetObjectState(slab, ObjectState.Saved);
|
|
}
|
|
|
|
private ESBSlab CreateESBSlab(DataReader dr)
|
|
{
|
|
ESBSlab slab = new ESBSlab();
|
|
MapESBSlab(slab, dr);
|
|
return slab;
|
|
}
|
|
|
|
private void FillESBSlab(ESBDefinition parent, DataReader dr)
|
|
{
|
|
while (dr.Read())
|
|
{
|
|
ESBSlab item = this.CreateESBSlab(dr);
|
|
parent.ESBSlabs.Add(item);
|
|
}
|
|
}
|
|
|
|
internal void loadChildren(TransactionContext tc, ESBDefinition def)
|
|
{
|
|
try
|
|
{
|
|
if (def != null && def.ID != null && def.ID != 0)
|
|
{
|
|
//Get Child
|
|
DataReader dr = new DataReader(ESBSlabDA.Get(tc, def.ID));
|
|
FillESBSlab(def, dr);
|
|
dr.Close();
|
|
}
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
throw e;
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
internal void SaveChild(TransactionContext tc, ESBDefinition def)
|
|
{
|
|
try
|
|
{
|
|
ESBSlabDA.Delete(tc, def.ID);
|
|
tc = TransactionContext.Begin(true);
|
|
foreach (ESBSlab item in def.ESBSlabs)
|
|
{
|
|
item.CreatedBy = def.CreatedBy;
|
|
item.CreatedDate = def.CreatedDate;
|
|
item.ESBID = def.ID;
|
|
int id = tc.GenerateID("ESBSlab", "SlabID");
|
|
base.SetObjectID(def, id);
|
|
ESBSlabDA.Insert(tc, item);
|
|
}
|
|
// tc.End();
|
|
// return def.ID;
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
throw e;
|
|
}
|
|
}
|
|
|
|
internal ESBDefinition Get(TransactionContext tc, int esbID)
|
|
{
|
|
ESBDefinition def = new ESBDefinition();
|
|
|
|
try
|
|
{
|
|
DataReader dr = new DataReader(ESBDefinitionDA.Get(tc, esbID));
|
|
if (dr.Read())
|
|
{
|
|
def = this.CreateObject<ESBDefinition>(dr);
|
|
}
|
|
|
|
dr.Close();
|
|
|
|
loadChildren(tc, def);
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
throw e;
|
|
}
|
|
|
|
return def;
|
|
}
|
|
|
|
#region Service Implementation
|
|
|
|
#region Insert
|
|
|
|
public void Save(ESBDefinition def)
|
|
{
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin(true);
|
|
if (def.IsNew)
|
|
{
|
|
int id = tc.GenerateID("ESBDefinition", "ESBID");
|
|
base.SetObjectID(def, id);
|
|
ESBDefinitionDA.Insert(tc, def);
|
|
}
|
|
else
|
|
{
|
|
ESBDefinitionDA.Update(tc, def);
|
|
}
|
|
|
|
SaveChild(tc, def);
|
|
tc.End();
|
|
// return def.ID;
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
#region Handle Exception
|
|
|
|
if (tc != null)
|
|
tc.HandleError();
|
|
ExceptionLog.Write(e);
|
|
throw new ServiceException(e.Message, e);
|
|
|
|
#endregion
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Delete
|
|
|
|
public void Delete(int id)
|
|
{
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin(true);
|
|
ESBDefinitionDA.Delete(tc, id);
|
|
tc.End();
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
#region Handle Exception
|
|
|
|
if (tc != null)
|
|
tc.HandleError();
|
|
ExceptionLog.Write(e);
|
|
throw new ServiceException("Failed to Delete " + e.Message);
|
|
|
|
#endregion
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Get(By ESBDefinitionID)
|
|
|
|
public ESBDefinition Get(int defID)
|
|
{
|
|
ESBDefinition def = null;
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin();
|
|
|
|
DataReader dr = new DataReader(ESBDefinitionDA.Get(tc, defID));
|
|
if (dr.Read())
|
|
{
|
|
def = this.CreateObject<ESBDefinition>(dr);
|
|
}
|
|
|
|
dr.Close();
|
|
|
|
loadChildren(tc, def);
|
|
|
|
tc.End();
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
#region Handle Exception
|
|
|
|
if (tc != null)
|
|
tc.HandleError();
|
|
ExceptionLog.Write(e);
|
|
|
|
throw new ServiceException(e.Message, e);
|
|
|
|
#endregion
|
|
}
|
|
|
|
return def;
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Get()
|
|
|
|
public List<ESBDefinition> Get()
|
|
{
|
|
List<ESBDefinition> defs;
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin();
|
|
|
|
DataReader dr = new DataReader(ESBDefinitionDA.Get(tc));
|
|
defs = this.CreateObjects<ESBDefinition>(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 defs;
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region GetTable
|
|
|
|
public DataTable GetTable()
|
|
{
|
|
DataTable dTbl = new DataTable("ESBDefinition");
|
|
|
|
|
|
return dTbl;
|
|
}
|
|
|
|
#endregion
|
|
|
|
#endregion
|
|
}
|
|
} |