236 lines
7.6 KiB
C#
236 lines
7.6 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
|
|
{
|
|
[Serializable]
|
|
public class SurveyCategoryService:ServiceTemplate,ISurveyCategoryService
|
|
{
|
|
#region Private functions and declaration
|
|
Cache _cache = new Cache(typeof(SurveyCategory));
|
|
|
|
#endregion
|
|
public SurveyCategoryService() { }
|
|
|
|
private void MapObject(SurveyCategory oSurveyCategory, DataReader oReader)
|
|
{
|
|
base.SetObjectID(oSurveyCategory, oReader.GetID("CategoryID"));
|
|
oSurveyCategory.Code = oReader.GetString("Code");
|
|
oSurveyCategory.Description = oReader.GetString("Description");
|
|
oSurveyCategory.Status = (EnumStatus)oReader.GetInt32("Status").Value;
|
|
oSurveyCategory.CreatedBy = oReader.GetID("CreatedBy");
|
|
oSurveyCategory.CreatedDate = oReader.GetDateTime("CreationDate").Value;
|
|
oSurveyCategory.ModifiedBy = oReader.GetID("ModifiedBy");
|
|
oSurveyCategory.ModifiedDate = oReader.GetDateTime("ModifiedDate");
|
|
this.SetObjectState(oSurveyCategory, Ease.CoreV35.ObjectState.Saved);
|
|
}
|
|
protected override T CreateObject<T>(DataReader oReader)
|
|
{
|
|
SurveyCategory oSurveyCategory = new SurveyCategory();
|
|
MapObject(oSurveyCategory, oReader);
|
|
return oSurveyCategory as T;
|
|
}
|
|
protected SurveyCategory CreateObject(DataReader oReader)
|
|
{
|
|
SurveyCategory oSurveyCategory = new SurveyCategory();
|
|
MapObject(oSurveyCategory, oReader);
|
|
return oSurveyCategory;
|
|
}
|
|
#region Service implementation
|
|
|
|
public string GetNextCode()
|
|
{
|
|
TransactionContext tc = null;
|
|
string _code = "";
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin();
|
|
_code = GlobalFunctionService.GetMaxCode(tc, "SurveyCategory", "codeautogenerate", "SurveyCategory", "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 SurveyCategory Get(ID id)
|
|
{
|
|
SurveyCategory oSurveyCategory = new SurveyCategory();
|
|
#region Cache Header
|
|
oSurveyCategory = _cache["Get", id] as SurveyCategory;
|
|
if (oSurveyCategory != null)
|
|
return oSurveyCategory;
|
|
#endregion
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin();
|
|
DataReader oreader = new DataReader(SurveyCategoryDA.Get(tc, id));
|
|
if (oreader.Read())
|
|
{
|
|
oSurveyCategory = this.CreateObject<SurveyCategory>(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(oSurveyCategory, "Get", id);
|
|
#endregion
|
|
return oSurveyCategory;
|
|
}
|
|
|
|
public SurveyCategory Get(string sCode)
|
|
{
|
|
SurveyCategory oSurveyCategory = new SurveyCategory();
|
|
#region Cache Header
|
|
oSurveyCategory = _cache["Get", sCode] as SurveyCategory;
|
|
if (oSurveyCategory != null)
|
|
return oSurveyCategory;
|
|
#endregion
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin();
|
|
DataReader oreader = new DataReader(SurveyCategoryDA.Get(tc, sCode));
|
|
if (oreader.Read())
|
|
{
|
|
oSurveyCategory = this.CreateObject<SurveyCategory>(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(oSurveyCategory, "Get", sCode);
|
|
#endregion
|
|
return oSurveyCategory;
|
|
}
|
|
|
|
public ObjectsTemplate<SurveyCategory> Get(EnumStatus status)
|
|
{
|
|
#region Cache Header
|
|
|
|
ObjectsTemplate<SurveyCategory> SurveyCategorys = _cache["Get"] as ObjectsTemplate<SurveyCategory>;
|
|
if (SurveyCategorys != null)
|
|
return SurveyCategorys;
|
|
|
|
#endregion
|
|
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin();
|
|
|
|
DataReader dr = new DataReader(SurveyCategoryDA.Get(tc, status));
|
|
SurveyCategorys = this.CreateObjects<SurveyCategory>(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(SurveyCategorys, "Get",status);
|
|
|
|
#endregion
|
|
|
|
return SurveyCategorys;
|
|
}
|
|
|
|
public ID Save(SurveyCategory oSurveyCategory)
|
|
{
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin(true);
|
|
if (oSurveyCategory.IsNew)
|
|
{
|
|
int id = tc.GenerateID("SurveyCategory", "CategoryID");
|
|
//int seqID = tc.GenerateID("SurveyCategory", "SequenceNO");
|
|
base.SetObjectID(oSurveyCategory, ID.FromInteger(id));
|
|
// oSurveyCategory.Sequence = seqID;
|
|
SurveyCategoryDA.Insert(tc, oSurveyCategory);
|
|
}
|
|
else
|
|
{
|
|
SurveyCategoryDA.Update(tc, oSurveyCategory);
|
|
}
|
|
tc.End();
|
|
return oSurveyCategory.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);
|
|
SurveyCategoryDA.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
|
|
}
|
|
}
|