EchoTex_Payroll/HRM.DA/Service/FundManagement/FndMngmentWFService.cs

481 lines
17 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 System.Linq;
using HRM.BO;
namespace HRM.DA
{
public class FndMngmentWFService : ServiceTemplate
{
#region Cache
#endregion
#region Map Objects
#region Map Parent
private void MapObject(FndMngmentWF oFndMngment, DataReader oReader)
{
base.SetObjectID(oFndMngment, (oReader.GetInt32("FndMngmentWFID").Value));
oFndMngment.PurchaseType = oReader.GetString("PurchaseType");
oFndMngment.PurchaseAmount = oReader.GetDouble("PurchaseAmount").HasValue
? oReader.GetDouble("PurchaseAmount").Value
: 0.0;
oFndMngment.Description = oReader.GetString("Description");
oFndMngment.EmployeeID = oReader.GetInt32("EmployeeID", 0);
oFndMngment.PFAmount = oReader.GetDouble("PFAmount").HasValue ? oReader.GetDouble("PFAmount").Value : 0.0;
oFndMngment.CFAmount = oReader.GetDouble("CFAmount").HasValue ? oReader.GetDouble("CFAmount").Value : 0.0;
oFndMngment.PFInterest =
oReader.GetDouble("PFInterest").HasValue ? oReader.GetDouble("PFInterest").Value : 0.0;
oFndMngment.CFInterest =
oReader.GetDouble("CFInterest").HasValue ? oReader.GetDouble("CFInterest").Value : 0.0;
oFndMngment.Gratuity = oReader.GetDouble("Gratuity").HasValue ? oReader.GetDouble("Gratuity").Value : 0.0;
oFndMngment.Status = (EnumStatus)oReader.GetInt32("Status").Value;
oFndMngment.CreatedBy = oReader.GetInt32("CreatedBy", 0);
oFndMngment.CreatedDate = oReader.GetDateTime("CreatedDate").HasValue
? oReader.GetDateTime("CreatedDate").Value
: DateTime.MinValue;
oFndMngment.ModifiedBy = oReader.GetInt32("ModifiedBy", 0);
oFndMngment.ModifiedDate = oReader.GetDateTime("ModifiedDate").HasValue
? oReader.GetDateTime("ModifiedDate").Value
: (DateTime?)null;
this.SetObjectState(oFndMngment, Ease.Core.ObjectState.Saved);
}
protected override T CreateObject<T>(DataReader oReader)
{
FndMngmentWF oFndMngment = new FndMngmentWF();
MapObject(oFndMngment, oReader);
return oFndMngment as T;
}
#endregion
#region Map FndMngmentEmps
private void MapFndMngmentEmpObject(FndMngmentEmp oFndMngmentEmp, DataReader oReader)
{
base.SetObjectID(oFndMngmentEmp, (oReader.GetInt32("FndMngmentEmpID").Value));
oFndMngmentEmp.FndMngmentWFID = (oReader.GetInt32("FndMngmentWFID").Value);
oFndMngmentEmp.EmployeeID = (oReader.GetInt32("EmployeeID").Value);
oFndMngmentEmp.EmployeeNo = oReader.GetString("EmployeeNo");
oFndMngmentEmp.EmployeeName = oReader.GetString("EmployeeName");
oFndMngmentEmp.DesigName = oReader.GetString("DesigName");
oFndMngmentEmp.EmailSent = oReader.GetBoolean("EmailSent").Value;
oFndMngmentEmp.WebSent = oReader.GetBoolean("WebSent").Value;
oFndMngmentEmp.SentDate = oReader.GetDateTime("SendDate").Value;
this.SetObjectState(oFndMngmentEmp, Ease.Core.ObjectState.Saved);
}
private FndMngmentEmp CreateFndMngmentEmp(DataReader oReader)
{
FndMngmentEmp oFndMngmentEmp = new FndMngmentEmp();
MapFndMngmentEmpObject(oFndMngmentEmp, oReader);
return oFndMngmentEmp;
}
private List<FndMngmentEmp> CreateFndMngmentEmps(DataReader oReader)
{
List<FndMngmentEmp> oFndMngmentEmps = new List<FndMngmentEmp>();
FndMngmentEmp oFndMngmentEmp;
while (oReader.Read())
{
oFndMngmentEmp = new FndMngmentEmp();
oFndMngmentEmp = CreateFndMngmentEmp(oReader);
oFndMngmentEmps.Add(oFndMngmentEmp);
}
return oFndMngmentEmps;
}
#endregion
#region Map FndMngmentEmpRemarks
private void MapFndMngmentEmpRemarksObject(FndMngmentEmpRemarks oFndMngmentEmpRemarks, DataReader oReader)
{
base.SetObjectID(oFndMngmentEmpRemarks, (oReader.GetInt32("FndMngmentEmpRemarksID").Value));
oFndMngmentEmpRemarks.FndMngmentEmpID = (oReader.GetInt32("FndMngmentEmpID").Value);
oFndMngmentEmpRemarks.FndMngmentWFID = (oReader.GetInt32("FndMngmentWFID").Value);
oFndMngmentEmpRemarks.RemarksDateTime = oReader.GetDateTime("RemarksDateTime").Value;
oFndMngmentEmpRemarks.Remarks = oReader.GetString("Remarks");
oFndMngmentEmpRemarks.IsHR = oReader.GetBoolean("IsHR").Value;
this.SetObjectState(oFndMngmentEmpRemarks, Ease.Core.ObjectState.Saved);
}
private FndMngmentEmpRemarks CreateFndMngmentEmpRemarks(DataReader oReader)
{
FndMngmentEmpRemarks oFndMngmentEmpRemarks = new FndMngmentEmpRemarks();
MapFndMngmentEmpRemarksObject(oFndMngmentEmpRemarks, oReader);
return oFndMngmentEmpRemarks;
}
private List<FndMngmentEmpRemarks> CreateFndMngmentEmpRemarkses(DataReader oReader)
{
List<FndMngmentEmpRemarks> oFndMngmentEmpRemarkses = new List<FndMngmentEmpRemarks>();
FndMngmentEmpRemarks oFndMngmentEmpRemarks;
while (oReader.Read())
{
oFndMngmentEmpRemarks = CreateFndMngmentEmpRemarks(oReader);
oFndMngmentEmpRemarkses.Add(oFndMngmentEmpRemarks);
}
return oFndMngmentEmpRemarkses;
}
#endregion
#endregion
#region IFndMngmentWFService Members
#region Get Functions
public FndMngmentWF Get(int id)
{
FndMngmentWF oFndMngmentWF = null;
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader oreader = new DataReader(FndMngmentWFDA.Get(tc, id));
if (oreader.Read())
{
oFndMngmentWF = CreateObject<FndMngmentWF>(oreader);
}
oreader.Close();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
finally
{
tc.End();
}
return oFndMngmentWF;
}
public List<FndMngmentWF> Get(EnumStatus status)
{
List<FndMngmentWF> oFndMngmentWFs = new List<FndMngmentWF>();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader oreader = new DataReader(FndMngmentWFDA.Get(tc, status));
oFndMngmentWFs = CreateObjects<FndMngmentWF>(oreader);
oreader.Close();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
finally
{
tc.End();
}
return oFndMngmentWFs;
}
#region Insert Function
public int Save(FndMngmentWF oFndMngment)
{
int id = 0;
TransactionContext tc = null;
try
{
int startingBatchNo;
int previousBatchNo = 0;
if (oFndMngment.IsNew)
{
tc = TransactionContext.Begin(true);
id = (tc.GenerateID("FndMngmentWF", "FndMngmentWFID"));
base.SetObjectID(oFndMngment, id);
FndMngmentWFDA.Insert(tc, oFndMngment);
oFndMngment.FndMngmentEmps.ForEach(o => o.FndMngmentWFID = id);
if (oFndMngment.AllFndMngEmpRemarks != null)
oFndMngment.AllFndMngEmpRemarks.ForEach(o => o.FndMngmentWFID = id);
}
else
{
id = oFndMngment.ID;
oFndMngment.AllFndMngEmpRemarks.ForEach(o => o.FndMngmentWFID = oFndMngment.ID);
foreach (FndMngmentEmp item in oFndMngment.FndMngmentEmps)
{
List<FndMngmentEmpRemarks> fndRemarks = new List<FndMngmentEmpRemarks>();
oFndMngment.AllFndMngEmpRemarks
.Where(o => o.FndMngmentEmpID != 0 && o.FndMngmentEmpID == item.ID)
.ToList()
.ForEach(oo => fndRemarks.Add(oo));
item.FndMngmentEmpRmrkses = fndRemarks;
}
tc = TransactionContext.Begin(true);
FndMngmentWFDA.Update(tc, oFndMngment);
FndMngmentWFDA.DeleteFndMngmentEmpRemarkses(tc, id);
FndMngmentWFDA.DeleteFndMngmentEmps(tc, id);
}
foreach (FndMngmentEmp item in oFndMngment.FndMngmentEmps)
{
int fnEmpid = (tc.GenerateID("FndMngmentEmp", "FndMngmentEmpID"));
base.SetObjectID(item, fnEmpid);
item.FndMngmentWFID = id;
FndMngmentWFDA.InsertFndMngmentEmp(tc, item);
foreach (FndMngmentEmpRemarks childItem in item.FndMngmentEmpRmrkses)
{
int fnEmpRemid = (tc.GenerateID("FndMngmentEmpRemarks", "FndMngmentEmpRemarksID"));
base.SetObjectID(childItem, fnEmpRemid);
childItem.FndMngmentWFID = id;
childItem.FndMngmentEmpID = fnEmpid;
FndMngmentWFDA.InsertFndMngmentEmpRemarks(tc, childItem);
}
}
foreach (FndMngmentEmpRemarks item in oFndMngment.AllFndMngEmpRemarks.Where(obj => obj.IsHR))
{
int fnEmpRemid = (tc.GenerateID("FndMngmentEmpRemarks", "FndMngmentEmpRemarksID"));
base.SetObjectID(item, fnEmpRemid);
item.FndMngmentWFID = id;
FndMngmentWFDA.InsertFndMngmentEmpRemarks(tc, item);
}
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
finally
{
tc.End();
}
return oFndMngment.ID;
}
//public int Insert(FndMngmentWF oFndMngment)
//{
// ID id = null;
// TransactionContext tc = null;
// try
// {
// int startingBatchNo;
// int previousBatchNo = 0;
// if (oFndMngment.IsNew)
// {
// tc = TransactionContext.Begin(true);
// id = (tc.GenerateID("FndMngmentWF", "FndMngmentWFID"));
// base.SetObjectID(oFndMngment, id);
// FndMngmentWFDA.Insert(tc, oFndMngment);
// oFndMngment.FndMngmentEmps.ForEach(o => o.FndMngmentWFID = id);
// if (oFndMngment.AllFndMngEmpRemarks != null)
// oFndMngment.AllFndMngEmpRemarks.ForEach(o => o.FndMngmentWFID = id);
// }
// else
// {
// id = oFndMngment.ID;
// oFndMngment.AllFndMngEmpRemarks.ForEach(o => o.FndMngmentWFID = oFndMngment.ID);
// foreach (FndMngmentEmp item in oFndMngment.FndMngmentEmps)
// {
// List<FndMngmentEmpRemarks> fndRemarks = new List<FndMngmentEmpRemarks>();
// oFndMngment.AllFndMngEmpRemarks
// .Where(o => o.FndMngmentEmpID != null && !o.FndMngmentEmpID.IsUnassigned && o.FndMngmentEmpID == item.ID)
// .ToList()
// .ForEach(oo => fndRemarks.Add(oo));
// item.FndMngmentEmpRmrkses = fndRemarks;
// }
// tc = TransactionContext.Begin(true);
// FndMngmentWFDA.Update(tc, oFndMngment);
// FndMngmentWFDA.DeleteFndMngmentEmpRemarkses(tc, id);
// FndMngmentWFDA.DeleteFndMngmentEmps(tc, id);
// }
// foreach (FndMngmentEmp item in oFndMngment.FndMngmentEmps)
// {
// ID fnEmpid = (tc.GenerateID("FndMngmentEmp", "FndMngmentEmpID"));
// base.SetObjectID(item, fnEmpid);
// item.FndMngmentWFID = id;
// FndMngmentWFDA.InsertFndMngmentEmp(tc, item);
// foreach (FndMngmentEmpRemarks childItem in item.FndMngmentEmpRmrkses)
// {
// ID fnEmpRemid = (tc.GenerateID("FndMngmentEmpRemarks", "FndMngmentEmpRemarksID"));
// base.SetObjectID(childItem, fnEmpRemid);
// childItem.FndMngmentWFID = id;
// childItem.FndMngmentEmpID = fnEmpid;
// FndMngmentWFDA.InsertFndMngmentEmpRemarks(tc, childItem);
// }
// }
// foreach (FndMngmentEmpRemarks item in oFndMngment.AllFndMngEmpRemarks.Where(obj => obj.IsHR))
// {
// ID fnEmpRemid = (tc.GenerateID("FndMngmentEmpRemarks", "FndMngmentEmpRemarksID"));
// base.SetObjectID(item, fnEmpRemid);
// item.FndMngmentWFID = id;
// FndMngmentWFDA.InsertFndMngmentEmpRemarks(tc, item);
// }
// }
// catch (Exception e)
// {
// #region Handle Exception
// if (tc != null)
// tc.HandleError();
// ExceptionLog.Write(e);
// throw new ServiceException(e.Message, e);
// #endregion
// }
// finally
// {
// tc.End();
// }
// return oFndMngment.ID;
//}
public void Save(FndMngmentEmpRemarks oFndMngEmpRemarks)
{
int id = 0;
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
id = (tc.GenerateID("FndMngmentEmpRemarks", "FndMngmentEmpRemarksID"));
base.SetObjectID(oFndMngEmpRemarks, id);
FndMngmentWFDA.InsertFndMngmentEmpRemarks(tc, oFndMngEmpRemarks);
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
finally
{
tc.End();
}
}
public void Deactivate(FndMngmentWF oFndMngment)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
oFndMngment.Status = EnumStatus.Inactive;
FndMngmentWFDA.Update(tc, oFndMngment);
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
finally
{
tc.End();
}
}
#endregion
#region Delete Function
public void Delete(int id)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
FndMngmentWFDA.DeleteFndMngmentEmpRemarkses(tc, id);
FndMngmentWFDA.DeleteFndMngmentEmps(tc, id);
FndMngmentWFDA.Delete(tc, id);
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
finally
{
tc.End();
}
}
#endregion
#endregion
#endregion
}
}