290 lines
8.3 KiB
C#
290 lines
8.3 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 SkilLevelService
|
|||
|
[Serializable]
|
|||
|
|
|||
|
public class SkillLevelService : ServiceTemplate,ISkillLevelService
|
|||
|
{
|
|||
|
#region Private functions and declaration
|
|||
|
Cache _cache = new Cache(typeof(SkillLevel));
|
|||
|
|
|||
|
#endregion
|
|||
|
|
|||
|
public SkillLevelService()
|
|||
|
{ }
|
|||
|
|
|||
|
private void MapObject(SkillLevel oSkilLevel, DataReader oReader)
|
|||
|
{
|
|||
|
base.SetObjectID(oSkilLevel, oReader.GetID("SkillLevelID"));
|
|||
|
oSkilLevel.Code = oReader.GetString("Code");
|
|||
|
oSkilLevel.Name = oReader.GetString("Name");
|
|||
|
//oSkilLevel.SkillPoint = oReader.GetInt32("SkillPoint").Value;
|
|||
|
|
|||
|
oSkilLevel.Sequence = oReader.GetInt32("SequenceNO").Value;
|
|||
|
oSkilLevel.Status = (EnumStatus)oReader.GetInt32("Status").Value;
|
|||
|
oSkilLevel.CreatedBy = oReader.GetID("CreatedBy");
|
|||
|
oSkilLevel.CreatedDate = oReader.GetDateTime("CreationDate").Value;
|
|||
|
oSkilLevel.ModifiedBy = oReader.GetID("ModifiedBy");
|
|||
|
oSkilLevel.ModifiedDate = oReader.GetDateTime("ModifiedDate");
|
|||
|
this.SetObjectState(oSkilLevel, Ease.CoreV35.ObjectState.Saved);
|
|||
|
}
|
|||
|
|
|||
|
protected override T CreateObject<T>(DataReader oReader)
|
|||
|
{
|
|||
|
SkillLevel oSkilLevel = new SkillLevel();
|
|||
|
MapObject(oSkilLevel, oReader);
|
|||
|
return oSkilLevel as T;
|
|||
|
}
|
|||
|
|
|||
|
protected SkillLevel CreateObject(DataReader oReader)
|
|||
|
{
|
|||
|
SkillLevel oSkilLevel = new SkillLevel();
|
|||
|
MapObject(oSkilLevel, oReader);
|
|||
|
return oSkilLevel;
|
|||
|
}
|
|||
|
|
|||
|
#region Service implementation
|
|||
|
|
|||
|
public ID Save(SkillLevel oSkilLevel)
|
|||
|
{
|
|||
|
TransactionContext tc = null;
|
|||
|
try
|
|||
|
{
|
|||
|
tc = TransactionContext.Begin(true);
|
|||
|
if (oSkilLevel.IsNew)
|
|||
|
{
|
|||
|
int id = tc.GenerateID("SkillLevel", "SkillLevelID");
|
|||
|
base.SetObjectID(oSkilLevel, ID.FromInteger(id));
|
|||
|
SkillLevelDA.Insert(tc, oSkilLevel);
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
SkillLevelDA.Update(tc, oSkilLevel);
|
|||
|
}
|
|||
|
tc.End();
|
|||
|
|
|||
|
return oSkilLevel.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);
|
|||
|
SkillLevelDA.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 SkillLevel Get(ID id)
|
|||
|
{
|
|||
|
SkillLevel oSkilLevel = new SkillLevel();
|
|||
|
#region Cache Header
|
|||
|
oSkilLevel = _cache["Get", id] as SkillLevel;
|
|||
|
if (oSkilLevel != null)
|
|||
|
return oSkilLevel;
|
|||
|
#endregion
|
|||
|
TransactionContext tc = null;
|
|||
|
try
|
|||
|
{
|
|||
|
tc = TransactionContext.Begin();
|
|||
|
DataReader oreader = new DataReader(SkillLevelDA.Get(tc, id));
|
|||
|
if (oreader.Read())
|
|||
|
{
|
|||
|
oSkilLevel = this.CreateObject<SkillLevel>(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(oSkilLevel, "Get", id);
|
|||
|
#endregion
|
|||
|
return oSkilLevel;
|
|||
|
}
|
|||
|
|
|||
|
public ObjectsTemplate<SkillLevel> Get()
|
|||
|
{
|
|||
|
#region Cache Header
|
|||
|
ObjectsTemplate<SkillLevel> oSkilLevel = _cache["Get"] as ObjectsTemplate<SkillLevel>;
|
|||
|
if (oSkilLevel != null)
|
|||
|
return oSkilLevel;
|
|||
|
#endregion
|
|||
|
TransactionContext tc = null;
|
|||
|
try
|
|||
|
{
|
|||
|
tc = TransactionContext.Begin();
|
|||
|
DataReader dr = new DataReader(SkillLevelDA.Get(tc));
|
|||
|
oSkilLevel = this.CreateObjects<SkillLevel>(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(oSkilLevel, "Get");
|
|||
|
#endregion
|
|||
|
return oSkilLevel;
|
|||
|
}
|
|||
|
|
|||
|
public ObjectsTemplate<SkillLevel> Get(EnumStatus status)
|
|||
|
{
|
|||
|
#region Cache Header
|
|||
|
|
|||
|
ObjectsTemplate<SkillLevel> skills = _cache["Get", status] as ObjectsTemplate<SkillLevel>;
|
|||
|
if (skills != null)
|
|||
|
return skills;
|
|||
|
|
|||
|
#endregion
|
|||
|
|
|||
|
TransactionContext tc = null;
|
|||
|
try
|
|||
|
{
|
|||
|
tc = TransactionContext.Begin();
|
|||
|
|
|||
|
DataReader dr = new DataReader(SkillLevelDA.Get(tc, status));
|
|||
|
skills = this.CreateObjects<SkillLevel>(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(skills, "Get", status);
|
|||
|
|
|||
|
#endregion
|
|||
|
|
|||
|
return skills;
|
|||
|
}
|
|||
|
|
|||
|
public bool IsExists(string Code)
|
|||
|
{
|
|||
|
TransactionContext tc = null;
|
|||
|
bool isExists = false;
|
|||
|
try
|
|||
|
{
|
|||
|
tc = TransactionContext.Begin(true);
|
|||
|
isExists = SkillLevelDA.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 SkillLevel due to " + e.Message, e);
|
|||
|
|
|||
|
#endregion
|
|||
|
}
|
|||
|
return isExists;
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
//public ObjectsTemplate<SkillLevel> GetChilds(ID parentID)
|
|||
|
//{
|
|||
|
// #region Cache Header
|
|||
|
|
|||
|
// ObjectsTemplate<SkillLevel> skills = _cache["GetChilds"] as ObjectsTemplate<SkillLevel>;
|
|||
|
// if (skills != null)
|
|||
|
// return skills;
|
|||
|
|
|||
|
// #endregion
|
|||
|
|
|||
|
// TransactionContext tc = null;
|
|||
|
// try
|
|||
|
// {
|
|||
|
// tc = TransactionContext.Begin();
|
|||
|
|
|||
|
// DataReader dr = new DataReader(SkillLevelDA.GetChilds(tc, parentID));
|
|||
|
// skills = this.CreateObjects<SkillLevel>(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(skills, "GetChilds");
|
|||
|
|
|||
|
// #endregion
|
|||
|
|
|||
|
// return skills;
|
|||
|
//}
|
|||
|
|
|||
|
#endregion
|
|||
|
}
|
|||
|
#endregion
|
|||
|
}
|