447 lines
12 KiB
C#
447 lines
12 KiB
C#
|
using HRM.BO;
|
|||
|
using HRM.DA;
|
|||
|
using Ease.Core.DataAccess;
|
|||
|
using Ease.Core.Model;
|
|||
|
using Ease.Core.Utility;
|
|||
|
using System;
|
|||
|
using System.Collections.Generic;
|
|||
|
using System.Data;
|
|||
|
|
|||
|
namespace HRM.DA
|
|||
|
{
|
|||
|
public class CategoryService : ServiceTemplate, ICategoryService
|
|||
|
{
|
|||
|
public CategoryService()
|
|||
|
{
|
|||
|
}
|
|||
|
|
|||
|
private void MapObject(Category oCategory, DataReader oReader)
|
|||
|
{
|
|||
|
base.SetObjectID(oCategory, oReader.GetInt32("CategoryID").Value);
|
|||
|
oCategory.Code = oReader.GetString("code");
|
|||
|
oCategory.Name = oReader.GetString("description");
|
|||
|
oCategory.Sequence = oReader.GetInt32("SequenceNo").Value;
|
|||
|
oCategory.Status = (EnumStatus)oReader.GetInt32("Status").Value;
|
|||
|
oCategory.WagesType = oReader.GetInt32("WagesType") == null ? null : (EnumWagesType)oReader.GetInt32("WagesType").Value;
|
|||
|
oCategory.CreatedBy = oReader.GetInt32("CreatedBy", 0);
|
|||
|
oCategory.CreatedDate = oReader.GetDateTime("CreationDate").Value;
|
|||
|
oCategory.ModifiedBy = oReader.GetInt32("ModifiedBy", 0);
|
|||
|
oCategory.ModifiedDate = oReader.GetDateTime("ModifiedDate");
|
|||
|
oCategory.PayrollTypeID = oReader.GetInt32("PayrollTypeID", 0);
|
|||
|
oCategory.NameInBangla = oReader.GetString("descriptioninbangla", true, null);
|
|||
|
this.SetObjectState(oCategory, Ease.Core.ObjectState.Saved);
|
|||
|
}
|
|||
|
|
|||
|
protected override T CreateObject<T>(DataReader oReader)
|
|||
|
{
|
|||
|
Category oCategory = new Category();
|
|||
|
MapObject(oCategory, oReader);
|
|||
|
return oCategory as T;
|
|||
|
}
|
|||
|
|
|||
|
#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(int id)
|
|||
|
{
|
|||
|
Category oCategory = new Category();
|
|||
|
|
|||
|
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
|
|||
|
}
|
|||
|
|
|||
|
return oCategory;
|
|||
|
}
|
|||
|
|
|||
|
public Category Get(TransactionContext tc, int id)
|
|||
|
{
|
|||
|
Category oCategory = null;
|
|||
|
|
|||
|
try
|
|||
|
{
|
|||
|
DataReader oreader = new DataReader(CategoryDA.Get(tc, id));
|
|||
|
if (oreader.Read())
|
|||
|
{
|
|||
|
oCategory = this.CreateObject<Category>(oreader);
|
|||
|
}
|
|||
|
|
|||
|
oreader.Close();
|
|||
|
}
|
|||
|
catch (Exception e)
|
|||
|
{
|
|||
|
#region Handle Exception
|
|||
|
|
|||
|
ExceptionLog.Write(e);
|
|||
|
throw new ServiceException(e.Message, e);
|
|||
|
|
|||
|
#endregion
|
|||
|
}
|
|||
|
|
|||
|
return oCategory;
|
|||
|
}
|
|||
|
|
|||
|
public List<Category> GetByPayrollTypeID(int payrollTypeID)
|
|||
|
{
|
|||
|
List<Category> categorys = new List<Category>();
|
|||
|
TransactionContext tc = null;
|
|||
|
try
|
|||
|
{
|
|||
|
tc = TransactionContext.Begin();
|
|||
|
|
|||
|
DataReader dr = new DataReader(CategoryDA.Get(tc, payrollTypeID));
|
|||
|
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
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
return categorys;
|
|||
|
}
|
|||
|
|
|||
|
public List<Category> GetAll()
|
|||
|
{
|
|||
|
List<Category> categorys = new List<Category>();
|
|||
|
|
|||
|
TransactionContext tc = null;
|
|||
|
try
|
|||
|
{
|
|||
|
tc = TransactionContext.Begin();
|
|||
|
|
|||
|
DataReader dr = new DataReader(CategoryDA.GetAll(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
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
return categorys;
|
|||
|
}
|
|||
|
|
|||
|
public List<Category> Get(EnumStatus status, int payrollTypeID)
|
|||
|
{
|
|||
|
List<Category> categorys = new List<Category>();
|
|||
|
|
|||
|
TransactionContext tc = null;
|
|||
|
try
|
|||
|
{
|
|||
|
tc = TransactionContext.Begin();
|
|||
|
|
|||
|
DataReader dr = new DataReader(CategoryDA.Get(tc, status, payrollTypeID));
|
|||
|
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
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
return categorys;
|
|||
|
}
|
|||
|
|
|||
|
public List<Category> Get(EnumWagesType wageType, EnumStatus status, int payrollTypeID)
|
|||
|
{
|
|||
|
List<Category> categorys = new List<Category>();
|
|||
|
TransactionContext tc = null;
|
|||
|
try
|
|||
|
{
|
|||
|
tc = TransactionContext.Begin();
|
|||
|
|
|||
|
DataReader dr = new DataReader(CategoryDA.Get(tc, wageType, status, payrollTypeID));
|
|||
|
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
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
return categorys;
|
|||
|
}
|
|||
|
|
|||
|
public int 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);
|
|||
|
|
|||
|
int seqNo = tc.GenerateID("Category", "SequenceNo");
|
|||
|
oCategory.Sequence = seqNo;
|
|||
|
if (oCategory.Code == "")
|
|||
|
oCategory.Code = oCategory.ID.ToString();
|
|||
|
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(int 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, List<Category> categories, List<Category> saveItems)
|
|||
|
{
|
|||
|
try
|
|||
|
{
|
|||
|
foreach (Category oCategory in categories)
|
|||
|
{
|
|||
|
|
|||
|
if (saveItems.FindIndex(x => x.ID == oCategory.ID) <0)
|
|||
|
{
|
|||
|
|
|||
|
int seqNo = tc.GenerateID("Category", "SequenceNo");
|
|||
|
oCategory.Sequence = seqNo;
|
|||
|
if(oCategory.Code == string.Empty)
|
|||
|
oCategory.Code = GlobalFunctionService.GetMaxCode(tc, "Category", "Code");
|
|||
|
oCategory.CreatedBy = oCategory.CreatedBy;
|
|||
|
oCategory.CreatedDate = DateTime.Now;
|
|||
|
CategoryDA.Insert(tc, oCategory);
|
|||
|
}
|
|||
|
//else
|
|||
|
//{
|
|||
|
// oCategory.ModifiedBy = oCategory.ModifiedBy;
|
|||
|
// 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
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
public int GetMaxID()
|
|||
|
{
|
|||
|
TransactionContext tc = null;
|
|||
|
|
|||
|
try
|
|||
|
{
|
|||
|
tc = TransactionContext.Begin();
|
|||
|
return tc.GenerateID("Category", "CategoryID") - 1;
|
|||
|
}
|
|||
|
catch (Exception e)
|
|||
|
{
|
|||
|
#region Handle Exception
|
|||
|
|
|||
|
if (tc != null)
|
|||
|
tc.HandleError();
|
|||
|
ExceptionLog.Write(e);
|
|||
|
throw new ServiceException(e.Message, e);
|
|||
|
|
|||
|
#endregion
|
|||
|
}
|
|||
|
finally
|
|||
|
{
|
|||
|
if (tc != null)
|
|||
|
{
|
|||
|
tc.End();
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
|
|||
|
public List<Category> GetAllCategory(int payrollTypeID, EnumStatus status, string code, string name)
|
|||
|
{
|
|||
|
List<Category> categories = new List<Category>();
|
|||
|
|
|||
|
TransactionContext tc = null;
|
|||
|
try
|
|||
|
{
|
|||
|
tc = TransactionContext.Begin();
|
|||
|
|
|||
|
DataReader dr = new DataReader(CategoryDA.GetAllCategory(tc, payrollTypeID, status, code, name));
|
|||
|
categories = 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
|
|||
|
}
|
|||
|
|
|||
|
return categories;
|
|||
|
}
|
|||
|
}
|
|||
|
}
|