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

387 lines
10 KiB
C#
Raw Permalink 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
{
[Serializable]
public class TrustyInfoService : ServiceTemplate
{
string ss = string.Empty;
#region Private Function And Declaration
public TrustyInfoService()
{
}
private void MapObject(TrustyInfo oTrustyInfo, DataReader dr)
{
ss = "Map object error";
base.SetObjectID(oTrustyInfo, dr.GetInt32("TrustyID").Value);
oTrustyInfo.ProjectID = dr.GetInt32("ProjectID").Value;
oTrustyInfo.Code = dr.GetString("Code");
oTrustyInfo.Name = dr.GetString("Name");
oTrustyInfo.Email = dr.GetString("Email");
oTrustyInfo.Contacts = dr.GetString("Contacts");
oTrustyInfo.Status = (EnumTrustyStatus)dr.GetInt32("Status").Value;
oTrustyInfo.CreatedBy = dr.GetInt32("CreatedBy").Value;
oTrustyInfo.CreatedDate = dr.GetDateTime("CreatedDate").Value;
oTrustyInfo.ModifiedBy = dr.GetInt32("ModifiedBy").Value;
oTrustyInfo.ModifiedDate = dr.GetDateTime("ModifiedDate");
base.SetObjectState(oTrustyInfo, ObjectState.Saved);
}
protected override T CreateObject<T>(DataReader dr)
{
TrustyInfo item = new TrustyInfo();
MapObject(item, dr);
return item as T;
}
private TrustyInfo CreateObject(DataReader dr)
{
TrustyInfo oTrustyInfo = new TrustyInfo();
MapObject(oTrustyInfo, dr);
return oTrustyInfo;
}
private List<TrustyInfo> CreateObjects(IDataReader dr)
{
List<TrustyInfo> oTrustyInfos = new List<TrustyInfo>();
DataReader oreader = new DataReader(dr);
while (dr.Read())
{
TrustyInfo Item = CreateObject(oreader);
oTrustyInfos.Add(Item);
}
return oTrustyInfos;
}
#endregion
public TrustyInfo Get(int id)
{
TrustyInfo oTrustyInfo = new TrustyInfo();
#region Cache Header
oTrustyInfo = new TrustyInfo();
if (oTrustyInfo != null)
return oTrustyInfo;
#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
IDataReader oreader = TrustyInfoDA.Get(tc, id);
DataReader dr = new DataReader(oreader);
if (oreader.Read())
{
oTrustyInfo = CreateObject<TrustyInfo>(dr);
}
oreader.Close();
tc.End();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException("Failed to Get TrustyInfo", e);
#endregion
}
#region Cache Footer
#endregion
return oTrustyInfo;
}
public List<TrustyInfo> GetByProjectID(int projectID)
{
List<TrustyInfo> TrustyInfos = new List<TrustyInfo>();
ss = "service exception user generate before get";
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
IDataReader dr = TrustyInfoDA.GetByProjectID(tc, projectID);
ss = "service exception in create objects";
TrustyInfos = CreateObjects(dr);
dr.Close();
tc.End();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException("Failed to Get TrustyInfo " + ss, e);
#endregion
}
return TrustyInfos;
}
public List<TrustyInfo> GetByStatusAndProjectID(int projectID, EnumTrustyStatus status)
{
List<TrustyInfo> TrustyInfos = new List<TrustyInfo>();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
IDataReader dr = TrustyInfoDA.GetByStatusAndProjectID(tc, projectID, status);
TrustyInfos = CreateObjects(dr);
dr.Close();
tc.End();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException("Failed to Get TrustyInfo ", e);
#endregion
}
return TrustyInfos;
}
public List<TrustyInfo> GetbyFundtype(int fundtypeid)
{
List<TrustyInfo> TrustyInfos = new List<TrustyInfo>();
#region Cache Header
if (TrustyInfos != null)
return TrustyInfos;
#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
IDataReader dr = TrustyInfoDA.Getbyfundtype(tc, fundtypeid);
TrustyInfos = CreateObjects(dr);
dr.Close();
tc.End();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException("Failed to Get TrustyInfo ", e);
#endregion
}
#region Cache Footer
#endregion
return TrustyInfos;
}
#region GetbyStatus(By Type)
public List<TrustyInfo> GetbyStatus(int type, int fundtypeid)
{
List<TrustyInfo> TrustyInfos = new List<TrustyInfo>();
#region Cache Header
if (TrustyInfos != null)
return TrustyInfos;
#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
IDataReader dr = TrustyInfoDA.GetbyStatus(tc, type, fundtypeid);
TrustyInfos = CreateObjects(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 TrustyInfos;
}
#endregion
public bool IsExist(string code, int fundtypeid)
{
bool exists = false;
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
exists = TrustyInfoDA.IsExist(tc, code, fundtypeid);
tc.End();
}
catch (Exception e)
{
throw new ServiceException("Failed to Check by code" + e.Message, e);
}
return exists;
}
public bool IsInMinutes(int trusteeID)
{
bool isInMinutes = false;
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
isInMinutes = TrustyInfoDA.IsInMinutes(tc, trusteeID);
tc.End();
}
catch (Exception e)
{
throw new ServiceException("Failed to Check by trusteeID" + e.Message, e);
}
return isInMinutes;
}
public void Delete(int id)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
TrustyInfoDA.Delete(tc, id);
tc.End();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException("Failed to Delete TrustyInfo", e);
#endregion
}
}
#region Insert
public void Save(TrustyInfo TrustyInfo)
{
TrustyInfo oTrustyInfo = new TrustyInfo();
oTrustyInfo = TrustyInfo;
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
if (oTrustyInfo.IsNew)
{
int id = tc.GenerateID("TrustyInfo", "TrustyID");
base.SetObjectID(oTrustyInfo, (id));
TrustyInfoDA.Insert(tc, oTrustyInfo);
}
else
{
TrustyInfoDA.Update(tc, oTrustyInfo);
}
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 DataTable GetTable(int fundtypeid)
{
DataTable dTbl = new DataTable("TrustyInfo");
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
IDataReader ir = TrustyInfoDA.Get(tc, fundtypeid);
dTbl.Load(ir);
ir.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 dTbl;
}
}
}