EchoTex_Payroll/HRM.DA/Service/Fund/Basic/MonthEndProcessService.cs

317 lines
7.4 KiB
C#
Raw Normal View History

2024-10-14 10:01:49 +06:00
using System;
using System.Data;
using Ease.Core.Model;
using Ease.Core.DataAccess;
using Ease.Core;
using System.Collections.Generic;
using Ease.Core.Utility;
using HRM.BO;
using HRM.DA;
namespace HRM.DA.Fund
{
public class MonthEndProcessService : ServiceTemplate
{
public MonthEndProcessService()
{
}
private void MapObject(MonthEndProcess item, DataReader dr)
{
base.SetObjectID(item, dr.GetInt32("MonthEndProcessID").Value);
item.Month = dr.GetInt32("Month").Value;
item.Year = dr.GetInt32("Year").Value;
item.CreatedBy = dr.GetInt32("CreatedBy").Value;
item.CreatedDate = dr.GetDateTime("CreatedDate").Value;
item.ModifiedBy = dr.GetInt32("ModifiedBy").Value;
item.ModifiedDate = dr.GetDateTime("ModifiedDate");
item.ProjectID = dr.GetInt32("ProjectID").Value;
base.SetObjectState(item, ObjectState.Saved);
}
protected override T CreateObject<T>(DataReader dr)
{
MonthEndProcess item = new MonthEndProcess();
MapObject(item, dr);
return item as T;
}
#region Service Implementation
#region Insert
public void Save(MonthEndProcess item)
{
MonthEndProcess oItem = new MonthEndProcess();
oItem = item;
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
if (oItem.IsNew)
{
int id = tc.GenerateID("MonthEndProcess", "MonthEndProcessID");
base.SetObjectID(oItem, (id));
MonthEndProcessDA.Insert(tc, oItem);
}
else
{
MonthEndProcessDA.Update(tc, oItem);
}
tc.End();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
}
#endregion
#region Delete
public void Delete(int id)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
MonthEndProcessDA.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
#region Get(By MonthEndProcessID)
public MonthEndProcess Get(int monthEndProcessID)
{
#region Cache Header
MonthEndProcess item = new MonthEndProcess();
if (item != null)
return item;
#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(MonthEndProcessDA.Get(tc, monthEndProcessID));
if (dr.Read())
{
item = this.CreateObject<MonthEndProcess>(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
#endregion
return item;
}
#endregion
#region Get()
public List<MonthEndProcess> Get()
{
#region Cache Header
List<MonthEndProcess> items = new List<MonthEndProcess>();
if (items != null)
return items;
#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(MonthEndProcessDA.Get(tc));
items = this.CreateObjects<MonthEndProcess>(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
#endregion
return items;
}
#endregion
#region GetBy ProjectID
public List<MonthEndProcess> GetByProjectID(int projectID)
{
#region Cache Header
List<MonthEndProcess> items = new List<MonthEndProcess>();
if (items != null)
return items;
#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(MonthEndProcessDA.GetByProjectID(tc, projectID));
items = this.CreateObjects<MonthEndProcess>(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
#endregion
return items;
}
#endregion
#region Updating by MonthEnd
public void UpdateDueMonthEnd(MonthEndProcess item)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
MonthEndProcessDA.UpdateDueMonthEnd(tc, item);
tc.End();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException("Failed to Update", e);
#endregion
}
}
#endregion
public void Delete(int month, int year)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
MonthEndProcessDA.Delete(tc, month, year);
tc.End();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException("Failed to Delete MonthEndProcess", e);
#endregion
}
}
#region GetTable
public DataTable GetTable()
{
DataTable dTbl = new DataTable("MonthEndProcess");
return dTbl;
}
#endregion
#endregion
}
}