298 lines
8.0 KiB
C#
298 lines
8.0 KiB
C#
|
using System;
|
|||
|
using System.Collections.Generic;
|
|||
|
using System.Linq;
|
|||
|
using System.Text;
|
|||
|
using Ease.CoreV35;
|
|||
|
using Ease.CoreV35.Model;
|
|||
|
using Ease.CoreV35.DataAccess;
|
|||
|
using Payroll.BO;
|
|||
|
using Ease.CoreV35.Caching;
|
|||
|
|
|||
|
namespace Payroll.Service
|
|||
|
{
|
|||
|
#region HRDoc Service
|
|||
|
[Serializable]
|
|||
|
public class HRDocService : ServiceTemplate, IHRDocService
|
|||
|
{
|
|||
|
#region Private functions and declaration
|
|||
|
Cache _cache = new Cache(typeof(HRDoc));
|
|||
|
#endregion
|
|||
|
|
|||
|
public HRDocService() { }
|
|||
|
|
|||
|
#region MapObject For HRDoc
|
|||
|
private void MapObject(HRDoc ohrDoc, DataReader oReader)
|
|||
|
{
|
|||
|
base.SetObjectID(ohrDoc, oReader.GetID("HRDocID"));
|
|||
|
ohrDoc.Code = oReader.GetString("Code");
|
|||
|
ohrDoc.Name = oReader.GetString("Name");
|
|||
|
ohrDoc.Description = oReader.GetString("Description");
|
|||
|
ohrDoc.ParentID = oReader.GetID("ParentID");
|
|||
|
ohrDoc.Status = (EnumStatus)oReader.GetInt32("Status").Value;
|
|||
|
ohrDoc.CreatedBy = oReader.GetID("CreatedBy");
|
|||
|
ohrDoc.CreatedDate = oReader.GetDateTime("CreationDate").Value;
|
|||
|
ohrDoc.ModifiedBy = oReader.GetID("ModifiedBy");
|
|||
|
ohrDoc.ModifiedDate = oReader.GetDateTime("ModifiedDate");
|
|||
|
|
|||
|
this.SetObjectState(ohrDoc, Ease.CoreV35.ObjectState.Saved);
|
|||
|
}
|
|||
|
protected override T CreateObject<T>(DataReader oReader)
|
|||
|
{
|
|||
|
HRDoc ohrDoc = new HRDoc();
|
|||
|
MapObject(ohrDoc, oReader);
|
|||
|
return ohrDoc as T;
|
|||
|
}
|
|||
|
protected HRDoc CreateObject(DataReader oReader)
|
|||
|
{
|
|||
|
HRDoc ohrDoc = new HRDoc();
|
|||
|
MapObject(ohrDoc, oReader);
|
|||
|
return ohrDoc;
|
|||
|
}
|
|||
|
#endregion
|
|||
|
|
|||
|
#region Service Implementation of HRDocs
|
|||
|
public HRDoc Get(ID id)
|
|||
|
{
|
|||
|
HRDoc oHRDoc = new HRDoc();
|
|||
|
#region Cache Header
|
|||
|
oHRDoc = _cache["Get", id] as HRDoc;
|
|||
|
if (oHRDoc != null)
|
|||
|
return oHRDoc;
|
|||
|
#endregion
|
|||
|
TransactionContext tc = null;
|
|||
|
try
|
|||
|
{
|
|||
|
tc = TransactionContext.Begin();
|
|||
|
DataReader oreader = new DataReader(HRDocDA.Get(tc, id));
|
|||
|
if (oreader.Read())
|
|||
|
{
|
|||
|
oHRDoc = this.CreateObject<HRDoc>(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(oHRDoc, "Get", id);
|
|||
|
#endregion
|
|||
|
return oHRDoc;
|
|||
|
}
|
|||
|
|
|||
|
public ObjectsTemplate<HRDoc> Get()
|
|||
|
{
|
|||
|
#region Cache Header
|
|||
|
|
|||
|
ObjectsTemplate<HRDoc> HRDocs = _cache["Get"] as ObjectsTemplate<HRDoc>;
|
|||
|
if (HRDocs != null)
|
|||
|
return HRDocs;
|
|||
|
|
|||
|
#endregion
|
|||
|
|
|||
|
TransactionContext tc = null;
|
|||
|
try
|
|||
|
{
|
|||
|
tc = TransactionContext.Begin();
|
|||
|
|
|||
|
DataReader dr = new DataReader(HRDocDA.Get(tc));
|
|||
|
HRDocs = this.CreateObjects<HRDoc>(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(HRDocs, "Get");
|
|||
|
|
|||
|
#endregion
|
|||
|
|
|||
|
return HRDocs;
|
|||
|
}
|
|||
|
|
|||
|
public ObjectsTemplate<HRDoc> GetParent(EnumStatus status)
|
|||
|
{
|
|||
|
#region Cache Header
|
|||
|
|
|||
|
ObjectsTemplate<HRDoc> HRDocs = _cache["Get"] as ObjectsTemplate<HRDoc>;
|
|||
|
if (HRDocs != null)
|
|||
|
return HRDocs;
|
|||
|
|
|||
|
#endregion
|
|||
|
|
|||
|
TransactionContext tc = null;
|
|||
|
try
|
|||
|
{
|
|||
|
tc = TransactionContext.Begin();
|
|||
|
|
|||
|
DataReader dr = new DataReader(HRDocDA.GetParent(tc, status));
|
|||
|
HRDocs = this.CreateObjects<HRDoc>(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(HRDocs, "Get");
|
|||
|
|
|||
|
#endregion
|
|||
|
|
|||
|
return HRDocs;
|
|||
|
}
|
|||
|
|
|||
|
public ObjectsTemplate<HRDoc> GetChilds(ID parentID)
|
|||
|
{
|
|||
|
#region Cache Header
|
|||
|
|
|||
|
ObjectsTemplate<HRDoc> HRDocs = _cache["GetChilds"] as ObjectsTemplate<HRDoc>;
|
|||
|
if (HRDocs != null)
|
|||
|
return HRDocs;
|
|||
|
|
|||
|
#endregion
|
|||
|
|
|||
|
TransactionContext tc = null;
|
|||
|
try
|
|||
|
{
|
|||
|
tc = TransactionContext.Begin();
|
|||
|
|
|||
|
DataReader dr = new DataReader(HRDocDA.GetChilds(tc, parentID));
|
|||
|
HRDocs = this.CreateObjects<HRDoc>(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(HRDocs, "GetChilds");
|
|||
|
|
|||
|
#endregion
|
|||
|
|
|||
|
return HRDocs;
|
|||
|
}
|
|||
|
|
|||
|
public ID Save(HRDoc oHRDoc)
|
|||
|
{
|
|||
|
TransactionContext tc = null;
|
|||
|
try
|
|||
|
{
|
|||
|
tc = TransactionContext.Begin(true);
|
|||
|
if (oHRDoc.IsNew)
|
|||
|
{
|
|||
|
int id = tc.GenerateID("HRDoc", "HRDocID");
|
|||
|
base.SetObjectID(oHRDoc, ID.FromInteger(id));
|
|||
|
HRDocDA.Insert(tc, oHRDoc);
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
HRDocDA.Update(tc, oHRDoc);
|
|||
|
}
|
|||
|
|
|||
|
return oHRDoc.ID;
|
|||
|
}
|
|||
|
catch (Exception e)
|
|||
|
{
|
|||
|
#region Handle Exception
|
|||
|
if (tc != null)
|
|||
|
tc.HandleError();
|
|||
|
ExceptionLog.Write(e);
|
|||
|
throw new ServiceException(e.Message, e);
|
|||
|
#endregion
|
|||
|
}
|
|||
|
finally
|
|||
|
{
|
|||
|
tc.End();
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
public void Delete(ID id)
|
|||
|
{
|
|||
|
TransactionContext tc = null;
|
|||
|
try
|
|||
|
{
|
|||
|
tc = TransactionContext.Begin(true);
|
|||
|
HRDocDA.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
|
|||
|
}
|
|||
|
}
|
|||
|
public bool IsExists(string Code)
|
|||
|
{
|
|||
|
TransactionContext tc = null;
|
|||
|
bool isExists = false;
|
|||
|
try
|
|||
|
{
|
|||
|
tc = TransactionContext.Begin(true);
|
|||
|
isExists = HRDocDA.IsExists(tc, Code);
|
|||
|
tc.End();
|
|||
|
}
|
|||
|
catch (Exception e)
|
|||
|
{
|
|||
|
#region Handle Exception
|
|||
|
|
|||
|
if (tc != null)
|
|||
|
tc.HandleError();
|
|||
|
ExceptionLog.Write(e);
|
|||
|
throw new ServiceException("Failed to get Skill due to " + e.Message, e);
|
|||
|
|
|||
|
#endregion
|
|||
|
}
|
|||
|
return isExists;
|
|||
|
}
|
|||
|
#endregion
|
|||
|
}
|
|||
|
#endregion
|
|||
|
}
|