289 lines
8.5 KiB
C#
289 lines
8.5 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 OpiItem Service
|
|
[Serializable]
|
|
public class OpiItemService : ServiceTemplate, IOpiItemService
|
|
{
|
|
#region Private functions and declaration
|
|
Cache _cache = new Cache(typeof(OpiItem));
|
|
|
|
public OpiItemService() { }
|
|
|
|
private void MapObject(OpiItem oOpiItem, DataReader oReader)
|
|
{
|
|
base.SetObjectID(oOpiItem, oReader.GetID("OpiItemID"));
|
|
oOpiItem.Code = oReader.GetString("Code");
|
|
oOpiItem.Name = oReader.GetString("Name");
|
|
oOpiItem.OpiType = (EnumOpiType)oReader.GetInt32("OpiType").Value;
|
|
oOpiItem.Sequence = oReader.GetInt32("SequenceNO").HasValue ? oReader.GetInt32("SequenceNo").Value : 0;
|
|
oOpiItem.Status = (EnumStatus)oReader.GetInt32("Status").Value;
|
|
oOpiItem.CreatedBy = oReader.GetID("CreatedBy");
|
|
oOpiItem.CreatedDate = oReader.GetDateTime("CreationDate").Value;
|
|
oOpiItem.ModifiedBy = oReader.GetID("ModifiedBy");
|
|
oOpiItem.ModifiedDate = oReader.GetDateTime("ModifiedDate");
|
|
this.SetObjectState(oOpiItem, Ease.CoreV35.ObjectState.Saved);
|
|
}
|
|
protected override T CreateObject<T>(DataReader oReader)
|
|
{
|
|
OpiItem oOpiItem = new OpiItem();
|
|
MapObject(oOpiItem, oReader);
|
|
return oOpiItem as T;
|
|
}
|
|
protected OpiItem CreateObject(DataReader oReader)
|
|
{
|
|
OpiItem oOpiItem = new OpiItem();
|
|
MapObject(oOpiItem, oReader);
|
|
return oOpiItem;
|
|
}
|
|
#endregion
|
|
|
|
#region Service implementation
|
|
public OpiItem Get(ID id)
|
|
{
|
|
OpiItem oOpiItem = new OpiItem();
|
|
#region Cache Header
|
|
oOpiItem = (OpiItem)_cache["Get", id] as OpiItem;
|
|
if (oOpiItem != null)
|
|
return oOpiItem;
|
|
#endregion
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin();
|
|
DataReader oReader = new DataReader(OpiItemDA.Get(tc, id));
|
|
if (oReader.Read())
|
|
{
|
|
oOpiItem = 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
|
|
}
|
|
#region Cache Footer
|
|
_cache.Add(oOpiItem, "Get", id);
|
|
#endregion
|
|
return oOpiItem;
|
|
}
|
|
|
|
public string GetNextCode()
|
|
{
|
|
TransactionContext tc = null;
|
|
string _code = "";
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin();
|
|
_code = GlobalFunctionService.GetMaxCode(tc, "opiprovisionitem", "codeautogenerate", "OpiItem", "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 ObjectsTemplate<OpiItem> Get()
|
|
{
|
|
#region Cache Header
|
|
ObjectsTemplate<OpiItem> oOpiItems = _cache["Get"] as ObjectsTemplate<OpiItem>;
|
|
if (oOpiItems != null)
|
|
return oOpiItems;
|
|
#endregion
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin();
|
|
DataReader oreader = new DataReader(OpiItemDA.Get(tc));
|
|
oOpiItems = this.CreateObjects<OpiItem>(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(oOpiItems, "Get");
|
|
#endregion
|
|
return oOpiItems;
|
|
}
|
|
public ObjectsTemplate<OpiItem> Get(EnumStatus status)
|
|
{
|
|
#region Cache Header
|
|
|
|
ObjectsTemplate<OpiItem> opiitems = _cache["Get", status] as ObjectsTemplate<OpiItem>;
|
|
if (opiitems != null)
|
|
return opiitems;
|
|
|
|
#endregion
|
|
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin();
|
|
|
|
DataReader dr = new DataReader(OpiItemDA.Get(tc, status));
|
|
opiitems = this.CreateObjects<OpiItem>(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(opiitems, "Get", status);
|
|
|
|
#endregion
|
|
|
|
return opiitems;
|
|
}
|
|
public ObjectsTemplate<OpiItem> Get(string opiID)
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
|
|
public ObjectsTemplate<OpiItem> Get(EnumOpiType opiType, EnumStatus status)
|
|
{
|
|
#region Cache Header
|
|
|
|
ObjectsTemplate<OpiItem> opiitems = _cache["Get", opiType, status] as ObjectsTemplate<OpiItem>;
|
|
if (opiitems != null)
|
|
return opiitems;
|
|
|
|
#endregion
|
|
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin();
|
|
|
|
DataReader dr = new DataReader(OpiItemDA.Get(tc, opiType, status));
|
|
opiitems = this.CreateObjects<OpiItem>(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(opiitems, "Get", opiType, status);
|
|
|
|
#endregion
|
|
|
|
return opiitems;
|
|
}
|
|
public ID Save(OpiItem oOpiItem)
|
|
{
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin(true);
|
|
if (oOpiItem.IsNew)
|
|
{
|
|
int id = tc.GenerateID("OpiItem", "OpiItemID");
|
|
base.SetObjectID(oOpiItem, ID.FromInteger(id));
|
|
|
|
int seqNo = tc.GenerateID("OpiItem", "SequenceNo");
|
|
oOpiItem.Sequence = seqNo;
|
|
|
|
OpiItemDA.Insert(tc, oOpiItem);
|
|
}
|
|
else
|
|
{
|
|
OpiItemDA.Update(tc, oOpiItem);
|
|
}
|
|
tc.End();
|
|
return oOpiItem.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);
|
|
OpiItemDA.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
|
|
|
|
#region IOpiItemService Members
|
|
|
|
|
|
|
|
#endregion
|
|
}
|
|
#endregion
|
|
}
|