267 lines
7.1 KiB
C#
267 lines
7.1 KiB
C#
using System;
|
|
using Ease.Core.Model;
|
|
using Ease.Core.DataAccess;
|
|
using HRM.BO;
|
|
using System.Collections.Generic;
|
|
using Ease.Core.Utility;
|
|
|
|
namespace HRM.DA
|
|
{
|
|
public class DistrictService : ServiceTemplate, IDistrictService
|
|
{
|
|
#region constructor
|
|
|
|
public DistrictService()
|
|
{
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region object
|
|
|
|
private void MapObject(District oDistrict, DataReader oReader)
|
|
{
|
|
base.SetObjectID(oDistrict, oReader.GetInt32("DISTRICTID").Value);
|
|
oDistrict.Code = oReader.GetString("CODE");
|
|
oDistrict.Name = oReader.GetString("NAME");
|
|
oDistrict.DivisionID = oReader.GetInt32("DIVISIONID", 0);
|
|
oDistrict.Sequence = oReader.GetInt32("SequenceNo").Value;
|
|
oDistrict.Status = (EnumStatus)oReader.GetInt32("Status").Value;
|
|
oDistrict.CreatedBy = oReader.GetInt32("CreatedBy", 0);
|
|
oDistrict.CreatedDate = oReader.GetDateTime("CreationDate").Value;
|
|
oDistrict.ModifiedBy = oReader.GetInt32("ModifiedBy", 0);
|
|
oDistrict.ModifiedDate = oReader.GetDateTime("ModifiedDate");
|
|
|
|
this.SetObjectState(oDistrict, Ease.Core.ObjectState.Saved);
|
|
}
|
|
|
|
protected override T CreateObject<T>(DataReader oReader)
|
|
{
|
|
District oDistrict = new District();
|
|
MapObject(oDistrict, oReader);
|
|
return oDistrict as T;
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Service implementation
|
|
|
|
public District Get(int id)
|
|
{
|
|
District oDistrict = null;
|
|
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin();
|
|
DataReader oreader = new DataReader(DistrictDA.Get(tc, id));
|
|
if (oreader.Read())
|
|
{
|
|
oDistrict = this.CreateObject<District>(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 oDistrict;
|
|
}
|
|
|
|
public District Get(string sCode)
|
|
{
|
|
District oDistrict = null;
|
|
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin();
|
|
DataReader oreader = new DataReader(DistrictDA.Get(tc, sCode));
|
|
if (oreader.Read())
|
|
{
|
|
oDistrict = this.CreateObject<District>(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 oDistrict;
|
|
}
|
|
|
|
public List<District> Get()
|
|
{
|
|
List<District> districts = new List<District>();
|
|
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin();
|
|
|
|
DataReader dr = new DataReader(DistrictDA.Get(tc));
|
|
districts = this.CreateObjects<District>(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 districts;
|
|
}
|
|
|
|
public List<District> Get(EnumStatus status)
|
|
{
|
|
List<District> districts = new List<District>();
|
|
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin();
|
|
|
|
DataReader dr = new DataReader(DistrictDA.Get(tc, status));
|
|
districts = this.CreateObjects<District>(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 districts;
|
|
}
|
|
|
|
public List<District> Get(EnumStatus status, int payrollTypeId)
|
|
{
|
|
List<District> districts = new List<District>();
|
|
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin();
|
|
|
|
DataReader dr = new DataReader(DistrictDA.Get(tc, status));
|
|
districts = this.CreateObjects<District>(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 districts;
|
|
}
|
|
|
|
public int Save(District oDistrict)
|
|
{
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin(true);
|
|
if (oDistrict.IsNew)
|
|
{
|
|
int id = tc.GenerateID("DISTRICT", "DISTRICTID");
|
|
base.SetObjectID(oDistrict, id);
|
|
if (oDistrict.Code == "")
|
|
oDistrict.Code = oDistrict.ID.ToString();
|
|
if (oDistrict.DivisionID == 0)
|
|
oDistrict.DivisionID = 1;
|
|
DistrictDA.Insert(tc, oDistrict);
|
|
}
|
|
else
|
|
{
|
|
DistrictDA.Update(tc, oDistrict);
|
|
}
|
|
|
|
tc.End();
|
|
return oDistrict.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);
|
|
DistrictDA.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
|
|
}
|
|
} |