182 lines
5.4 KiB
C#
182 lines
5.4 KiB
C#
using System;
|
|
using System.Data;
|
|
using System.Linq;
|
|
using Ease.CoreV35;
|
|
using Ease.CoreV35.Model;
|
|
using Ease.CoreV35.DataAccess;
|
|
using System.Collections.Generic;
|
|
using Payroll.BO;
|
|
using Ease.CoreV35.Caching;
|
|
|
|
namespace Payroll.Service
|
|
{
|
|
#region Company Service
|
|
[Serializable]
|
|
public class CompanyService : ServiceTemplate, ICompanyService
|
|
{
|
|
#region Private functions and declaration
|
|
Cache _cache = new Cache(typeof(Company));
|
|
|
|
#endregion
|
|
public CompanyService() { }
|
|
|
|
private void MapObject(Company oCompany, DataReader oReader)
|
|
{
|
|
base.SetObjectID(oCompany, oReader.GetID("CompanyID"));
|
|
oCompany.Code = oReader.GetString("code");
|
|
oCompany.Name = oReader.GetString("description");
|
|
oCompany.Sequence = oReader.GetInt32("SequenceNo").Value;
|
|
oCompany.Status = (EnumStatus)oReader.GetInt32("Status").Value;
|
|
oCompany.CreatedBy = oReader.GetID("CreatedBy");
|
|
oCompany.CreatedDate = oReader.GetDateTime("CreatedDate").Value;
|
|
oCompany.ModifiedBy = oReader.GetID("ModifiedBy");
|
|
oCompany.ModifiedDate = oReader.GetDateTime("ModifiedDate");
|
|
this.SetObjectState(oCompany, Ease.CoreV35.ObjectState.Saved);
|
|
}
|
|
protected override T CreateObject<T>(DataReader oReader)
|
|
{
|
|
Company oCompany = new Company();
|
|
MapObject(oCompany, oReader);
|
|
return oCompany as T;
|
|
}
|
|
protected Company CreateObject(DataReader oReader)
|
|
{
|
|
Company oCompany = new Company();
|
|
MapObject(oCompany, oReader);
|
|
return oCompany;
|
|
}
|
|
#region Service implementation
|
|
public Company Get(ID id)
|
|
{
|
|
Company oCompany = new Company();
|
|
#region Cache Header
|
|
oCompany = _cache["Get", id] as Company;
|
|
if (oCompany != null)
|
|
return oCompany;
|
|
#endregion
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin();
|
|
DataReader oreader = new DataReader(CompanyDA.Get(tc, id));
|
|
if (oreader.Read())
|
|
{
|
|
oCompany = this.CreateObject<Company>(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
|
|
}
|
|
#region Cache Footer
|
|
_cache.Add(oCompany, "Get", id);
|
|
#endregion
|
|
return oCompany;
|
|
}
|
|
|
|
public ObjectsTemplate<Company> Get(EnumStatus status)
|
|
{
|
|
#region Cache Header
|
|
|
|
ObjectsTemplate<Company> Companys = _cache["Get", status] as ObjectsTemplate<Company>;
|
|
if (Companys != null)
|
|
return Companys;
|
|
|
|
#endregion
|
|
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin();
|
|
|
|
DataReader dr = new DataReader(CompanyDA.Get(tc, status));
|
|
Companys = this.CreateObjects<Company>(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
|
|
}
|
|
|
|
#region Cache Footer
|
|
|
|
_cache.Add(Companys, "Get", status);
|
|
|
|
#endregion
|
|
|
|
return Companys;
|
|
}
|
|
public ID Save(Company oCompany)
|
|
{
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin(true);
|
|
if (oCompany.IsNew)
|
|
{
|
|
|
|
int id = tc.GenerateID("Company", "CompanyID");
|
|
base.SetObjectID(oCompany, ID.FromInteger(id));
|
|
int seqNo = tc.GenerateID("Company", "SequenceNo");
|
|
oCompany.Sequence = seqNo;
|
|
CompanyDA.Insert(tc, oCompany);
|
|
}
|
|
else
|
|
{
|
|
CompanyDA.Update(tc, oCompany);
|
|
}
|
|
tc.End();
|
|
return oCompany.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(ID id)
|
|
{
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin(true);
|
|
CompanyDA.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
|
|
}
|
|
#endregion
|
|
}
|