EchoTex_Payroll/HRM.DA/Service/Assets/AssetCategoryService.cs
2024-10-14 10:01:49 +06:00

590 lines
16 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 AssetCategoryService : ServiceTemplate, IAssetCategoryService
{
public AssetCategoryService()
{
}
private void MapObject(AssetCategory oAssetCategory, DataReader oReader)
{
base.SetObjectID(oAssetCategory, oReader.GetInt32("ASSETCATEGORYID").Value);
oAssetCategory.Code = oReader.GetString("code");
oAssetCategory.Name = oReader.GetString("description");
oAssetCategory.ParentID = oReader.GetInt32("parentID");
oAssetCategory.Status = (EnumStatus)oReader.GetInt32("Status").Value;
oAssetCategory.Tier = oReader.GetInt32("TIRE").Value;
oAssetCategory.CreatedBy = oReader.GetInt32("CreatedBy").Value;
oAssetCategory.CreatedDate = oReader.GetDateTime("CreationDate").Value;
oAssetCategory.ModifiedBy = oReader.GetInt32("ModifiedBy");
oAssetCategory.ModifiedDate = oReader.GetDateTime("ModifiedDate");
this.SetObjectState(oAssetCategory, Ease.Core.ObjectState.Saved);
oAssetCategory.PayrollTypeID = oReader.GetInt32("PayrollTypeID").Value;
}
protected override T CreateObject<T>(DataReader oReader)
{
AssetCategory oAssetCategory = new AssetCategory();
MapObject(oAssetCategory, oReader);
return oAssetCategory as T;
}
#region Service implementation
public AssetCategory Get(TransactionContext tc, int id)
{
AssetCategory oAssetCategory = null;
try
{
DataReader oreader = new DataReader(AssetCategoryDA.Get(tc, id));
if (oreader.Read())
{
oAssetCategory = this.CreateObject<AssetCategory>(oreader);
}
oreader.Close();
}
catch (Exception e)
{
#region Handle Exception
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
return oAssetCategory;
}
public AssetCategory Get(int id)
{
AssetCategory oAssetCategory = null;
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader oreader = new DataReader(AssetCategoryDA.Get(tc, id));
if (oreader.Read())
{
oAssetCategory = this.CreateObject<AssetCategory>(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 oAssetCategory;
}
public string GetNextCode(int tier)
{
TransactionContext tc = null;
string _code = "";
try
{
tc = TransactionContext.Begin();
_code = GlobalFunctionService.GetMaxCode(tc, "location", "codeautogenerate", "location", "Code", tier);
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 List<AssetCategory> GetAssetCategories()
{
List<AssetCategory> assetCategories = null;
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(AssetCategoryDA.Get(tc));
assetCategories = this.CreateObjects<AssetCategory>(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(locations, "Get");
//#endregion
return assetCategories;
}
public List<AssetCategory> GetAllAssetCategories(int payrollTypeID, EnumStatus status, string code, string name)
{
List<AssetCategory> assetCategories = new List<AssetCategory>();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(AssetCategoryDA.GetAllAssetCategories(tc, payrollTypeID, status, code, name));
assetCategories = this.CreateObjects<AssetCategory>(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 assetCategories;
}
public List<AssetCategory> GetAllAssetCategory(string code, string name)
{
List<AssetCategory> assetCategories = new List<AssetCategory>();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(AssetCategoryDA.GetAllAssetCategory(tc, code, name));
assetCategories = this.CreateObjects<AssetCategory>(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 assetCategories;
}
public string GetNextCode(int _tier, string _parentCode)
{
TransactionContext tc = null;
string _code = "";
try
{
tc = TransactionContext.Begin();
//#### _code = GlobalFunctionService.GetMaxCodeofTree(tc, "location", "codeautogenerate", "location", "Code","LocationID","ParentID", _parentCode, _tier);
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 string GetNextCode(int _tier, int parentid)
{
TransactionContext tc = null;
string _code = "";
string parentCode = string.Empty;
try
{
if (parentid != -1)
{
AssetCategory parent = this.Get((int)parentid);
if (parent != null)
parentCode = parent.Code;
}
tc = TransactionContext.Begin();
_code = GlobalFunctionService.GetMaxCodeofTree(tc, "AssetCategory", "codeautogenerate", "AssetCategory", "Code",
"AssetCategoryID", "ParentID", parentCode, _tier);
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 AssetCategory Get(string code)
{
AssetCategory oLocation = null;
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader oreader = new DataReader(AssetCategoryDA.Get(tc, code));
if (oreader.Read())
{
oLocation = this.CreateObject<AssetCategory>(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 oLocation;
}
public List<AssetCategory> Get(EnumStatus sts)
{
List<AssetCategory> allLocations = new List<AssetCategory>();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader oreader = new DataReader(AssetCategoryDA.Get(tc, sts));
if (oreader.Read())
{
allLocations = this.CreateObjects<AssetCategory>(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 allLocations;
}
public List<AssetCategory> Get()
{
List<AssetCategory> locations = new List<AssetCategory>();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(AssetCategoryDA.Get(tc));
locations = this.CreateObjects<AssetCategory>(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 locations;
}
public List<AssetCategory> GetChield(int parentID)
{
List<AssetCategory> locations = new List<AssetCategory>();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(AssetCategoryDA.GetChilds(tc, parentID));
locations = this.CreateObjects<AssetCategory>(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 locations;
}
public List<AssetCategory> GetParents(EnumStatus status, int payrollTypeID)
{
List<AssetCategory> locations = new List<AssetCategory>();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(AssetCategoryDA.GetParent(tc, status, payrollTypeID));
locations = this.CreateObjects<AssetCategory>(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 locations;
}
public List<AssetCategory> Get(EnumStatus status, int payrollTypeID)
{
List<AssetCategory> locations = new List<AssetCategory>();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(AssetCategoryDA.Get(tc, status, payrollTypeID));
locations = this.CreateObjects<AssetCategory>(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 locations;
}
public List<AssetCategory> GetByTier(int tier)
{
List<AssetCategory> locations = new List<AssetCategory>();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(AssetCategoryDA.GetByTier(tc, tier));
locations = this.CreateObjects<AssetCategory>(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 locations;
}
public int Save(AssetCategory oAssetCategory)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
if (oAssetCategory.IsNew)
{
int id = tc.GenerateID("AssetCategory", "ASSETCATEGORYID");
//int sequenceId = tc.GenerateID("oAssetCategory", "SequenceNO");
//oLocation.Sequence = sequenceId;
base.SetObjectID(oAssetCategory, id);
AssetCategoryDA.Insert(tc, oAssetCategory);
}
else
{
AssetCategoryDA.Update(tc, oAssetCategory);
}
tc.End();
return oAssetCategory.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, int UserID)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
AssetCategoryDA.Delete(tc, id, UserID);
tc.End();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
}
#endregion
public void Delete(int id)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
AssetCategoryDA.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
}
}
}
}