314 lines
9.5 KiB
C#
314 lines
9.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 Category Service
|
|||
|
[Serializable]
|
|||
|
public class CategoryService : ServiceTemplate, ICategoryService
|
|||
|
{
|
|||
|
#region Private functions and declaration
|
|||
|
Cache _cache = new Cache(typeof(Category));
|
|||
|
|
|||
|
#endregion
|
|||
|
public CategoryService() { }
|
|||
|
|
|||
|
private void MapObject(Category oCategory, DataReader oReader)
|
|||
|
{
|
|||
|
base.SetObjectID(oCategory, oReader.GetID("CategoryID"));
|
|||
|
oCategory.Code = oReader.GetString("code");
|
|||
|
oCategory.Name = oReader.GetString("description");
|
|||
|
oCategory.Sequence = oReader.GetInt32("SequenceNo").Value;
|
|||
|
oCategory.Status = (EnumStatus)oReader.GetInt32("Status").Value;
|
|||
|
oCategory.CreatedBy = oReader.GetID("CreatedBy");
|
|||
|
oCategory.CreatedDate = oReader.GetDateTime("CreationDate").Value;
|
|||
|
oCategory.ModifiedBy = oReader.GetID("ModifiedBy");
|
|||
|
oCategory.ModifiedDate = oReader.GetDateTime("ModifiedDate");
|
|||
|
oCategory.WagesType = (EnumWagesType)oReader.GetInt32("WagesType").Value;
|
|||
|
this.SetObjectState(oCategory, Ease.CoreV35.ObjectState.Saved);
|
|||
|
}
|
|||
|
protected override T CreateObject<T>(DataReader oReader)
|
|||
|
{
|
|||
|
Category oCategory = new Category();
|
|||
|
MapObject(oCategory, oReader);
|
|||
|
return oCategory as T;
|
|||
|
}
|
|||
|
protected Category CreateObject(DataReader oReader)
|
|||
|
{
|
|||
|
Category oCategory = new Category();
|
|||
|
MapObject(oCategory, oReader);
|
|||
|
return oCategory;
|
|||
|
}
|
|||
|
#region Service implementation
|
|||
|
|
|||
|
public string GetNextCode()
|
|||
|
{
|
|||
|
TransactionContext tc = null;
|
|||
|
string _code = "";
|
|||
|
try
|
|||
|
{
|
|||
|
tc = TransactionContext.Begin();
|
|||
|
_code = GlobalFunctionService.GetMaxCode(tc, "category", "codeautogenerate", "Category", "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 Category Get(ID id)
|
|||
|
{
|
|||
|
Category oCategory = new Category();
|
|||
|
#region Cache Header
|
|||
|
oCategory = _cache["Get", id] as Category;
|
|||
|
if (oCategory != null)
|
|||
|
return oCategory;
|
|||
|
#endregion
|
|||
|
TransactionContext tc = null;
|
|||
|
try
|
|||
|
{
|
|||
|
tc = TransactionContext.Begin();
|
|||
|
DataReader oreader = new DataReader(CategoryDA.Get(tc, id));
|
|||
|
if (oreader.Read())
|
|||
|
{
|
|||
|
oCategory = this.CreateObject<Category>(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(oCategory, "Get", id);
|
|||
|
#endregion
|
|||
|
return oCategory;
|
|||
|
}
|
|||
|
|
|||
|
public ObjectsTemplate<Category> Get()
|
|||
|
{
|
|||
|
#region Cache Header
|
|||
|
|
|||
|
ObjectsTemplate<Category> categorys = _cache["Get"] as ObjectsTemplate<Category>;
|
|||
|
if (categorys != null)
|
|||
|
return categorys;
|
|||
|
|
|||
|
#endregion
|
|||
|
|
|||
|
TransactionContext tc = null;
|
|||
|
try
|
|||
|
{
|
|||
|
tc = TransactionContext.Begin();
|
|||
|
|
|||
|
DataReader dr = new DataReader(CategoryDA.Get(tc));
|
|||
|
categorys = this.CreateObjects<Category>(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(categorys, "Get");
|
|||
|
|
|||
|
#endregion
|
|||
|
|
|||
|
return categorys;
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
public ObjectsTemplate<Category> Get(EnumStatus status)
|
|||
|
{
|
|||
|
#region Cache Header
|
|||
|
|
|||
|
ObjectsTemplate<Category> categorys = _cache["Get",status] as ObjectsTemplate<Category>;
|
|||
|
if (categorys != null)
|
|||
|
return categorys;
|
|||
|
|
|||
|
#endregion
|
|||
|
|
|||
|
TransactionContext tc = null;
|
|||
|
try
|
|||
|
{
|
|||
|
tc = TransactionContext.Begin();
|
|||
|
|
|||
|
DataReader dr = new DataReader(CategoryDA.Get(tc, status));
|
|||
|
categorys = this.CreateObjects<Category>(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(categorys, "Get",status);
|
|||
|
|
|||
|
#endregion
|
|||
|
|
|||
|
return categorys;
|
|||
|
}
|
|||
|
public ID Save(Category oCategory)
|
|||
|
{
|
|||
|
TransactionContext tc = null;
|
|||
|
try
|
|||
|
{
|
|||
|
tc = TransactionContext.Begin(true);
|
|||
|
int codeLength = 3;
|
|||
|
if (oCategory.IsNew)
|
|||
|
{
|
|||
|
|
|||
|
int id = tc.GenerateID("Category", "CategoryID");
|
|||
|
base.SetObjectID(oCategory, ID.FromInteger(id));
|
|||
|
|
|||
|
int seqNo = tc.GenerateID("Category", "SequenceNo");
|
|||
|
oCategory.Sequence = seqNo;
|
|||
|
CategoryDA.Insert(tc, oCategory);
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
CategoryDA.Update(tc, oCategory);
|
|||
|
}
|
|||
|
tc.End();
|
|||
|
return oCategory.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);
|
|||
|
CategoryDA.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 DataSet GetAgeRange(int fromyear, int toyear)
|
|||
|
{
|
|||
|
DataSet oAgeRanges = new DataSet();
|
|||
|
|
|||
|
TransactionContext tc = null;
|
|||
|
try
|
|||
|
{
|
|||
|
tc = TransactionContext.Begin();
|
|||
|
oAgeRanges = CategoryDA.GetAgeRange(tc,fromyear,toyear);
|
|||
|
tc.End();
|
|||
|
}
|
|||
|
catch (Exception e)
|
|||
|
{
|
|||
|
#region Handle Exception
|
|||
|
if (tc != null)
|
|||
|
tc.HandleError();
|
|||
|
ExceptionLog.Write(e);
|
|||
|
throw new ServiceException(e.Message, e);
|
|||
|
#endregion
|
|||
|
}
|
|||
|
return oAgeRanges;
|
|||
|
}
|
|||
|
#endregion
|
|||
|
|
|||
|
//For excel Upload
|
|||
|
public static void SaveForUpload(TransactionContext tc, ObjectsTemplate<Category> categories)
|
|||
|
{
|
|||
|
try
|
|||
|
{
|
|||
|
foreach (Category oCategory in categories)
|
|||
|
{
|
|||
|
if (oCategory.IsNew)
|
|||
|
{
|
|||
|
int seqNo = tc.GenerateID("Category", "SequenceNo");
|
|||
|
oCategory.Sequence = seqNo;
|
|||
|
bool isAutoGenerated = ConfigurationManager.GetBoolValue("category", "codeautogenerate", EnumConfigurationType.Logic);
|
|||
|
if (isAutoGenerated == true)
|
|||
|
oCategory.Code = GlobalFunctionService.GetMaxCode(tc, "category", "codeautogenerate", "Category", "Code");
|
|||
|
oCategory.CreatedBy = User.CurrentUser.ID;
|
|||
|
oCategory.CreatedDate = DateTime.Now;
|
|||
|
CategoryDA.Insert(tc, oCategory);
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
oCategory.ModifiedBy = User.CurrentUser.ID;
|
|||
|
oCategory.ModifiedDate = DateTime.Now;
|
|||
|
CategoryDA.Update(tc, oCategory);
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
catch (Exception e)
|
|||
|
{
|
|||
|
#region Handle Exception
|
|||
|
if (tc != null)
|
|||
|
tc.HandleError();
|
|||
|
ExceptionLog.Write(e);
|
|||
|
throw new ServiceException(e.Message, e);
|
|||
|
#endregion
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
#endregion
|
|||
|
}
|