CEL_Payroll/Payroll.Service/HRequests/Service/HRRequestService.cs
2024-09-17 14:30:13 +06:00

1350 lines
48 KiB
C#

using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using Ease.CoreV35.Caching;
using Ease.CoreV35.DataAccess;
using Ease.CoreV35.Model;
using Payroll.BO;
namespace Payroll.Service
{
[Serializable]
public class HRRequestService : ServiceTemplate, IHRRequestService
{
#region Cache
Cache _cache = new Cache(typeof(HRRequest));
#endregion
#region Map Objects
#region Map Parent
private void MapObject(HRRequest oHRRequest, DataReader oReader)
{
base.SetObjectID(oHRRequest, oReader.GetID("HRRequestID"));
oHRRequest.EmployeeID = oReader.GetID("EmployeeID");
oHRRequest.ClaimNumber = oReader.GetString("ClaimNumber");
oHRRequest.Description = oReader.GetString("Description");
oHRRequest.Amount = oReader.GetDouble("Amount").GetValueOrDefault(0);
oHRRequest.Taxable = oReader.GetDouble("Taxable").GetValueOrDefault(0);
oHRRequest.NonTaxable = oReader.GetDouble("NonTaxable").GetValueOrDefault(0);
oHRRequest.TaxAmount = oReader.GetDouble("TaxAmount").GetValueOrDefault(0);
oHRRequest.RequestType = (EnumRequestType) oReader.GetInt32("RequestType").GetValueOrDefault();
oHRRequest.Remarks = oReader.GetString("Remarks");
oHRRequest.RequestDate = oReader.GetDateTime("RequestDate").GetValueOrDefault();
oHRRequest.SubmittedOriginalPaper = oReader.GetBoolean("SubmittedOriginalPaper").GetValueOrDefault();
oHRRequest.WfStatus = (enumwfStatus)oReader.GetInt32("WfStatus").GetValueOrDefault();
oHRRequest.LetterTypeID = oReader.GetID("LetterTypeID").IsUnassigned ? ID.FromInteger(0) : oReader.GetID("LetterTypeID");
oHRRequest.IssuerAddress = oReader.GetString("IssuerAddress");
oHRRequest.FromDate = oReader.GetDateTime("FromDate").GetValueOrDefault();
oHRRequest.ToDate = oReader.GetDateTime("ToDate").GetValueOrDefault();
oHRRequest.IsOfficial = oReader.GetBoolean("IsOfficial").GetValueOrDefault();
oHRRequest.IsWithFamily = oReader.GetBoolean("IsWithFamily").GetValueOrDefault();
oHRRequest.RequestComplted = oReader.GetBoolean("RequestCompleted").GetValueOrDefault();
oHRRequest.LoanID = oReader.GetID("LoanID");
oHRRequest.Justification = oReader.GetString("Justification");
oHRRequest.Purpose = oReader.GetString("Purpose");
oHRRequest.TypeOfProperty = oReader.GetString("TypeOfProperty");
oHRRequest.Land = oReader.GetString("Land");
oHRRequest.ValueofProperty = oReader.GetDouble("ValueofProperty").GetValueOrDefault(0);
oHRRequest.ExoectedDateofCompletion = oReader.GetDateTime("ExoectedDateofCompletion").GetValueOrDefault();
oHRRequest.NameofVendor = oReader.GetString("NameofVendor");
oHRRequest.AddressofVendor = oReader.GetString("AddressofVendor");
oHRRequest.Teleohone = oReader.GetString("Teleohone");
oHRRequest.Dependency = oReader.GetString("Dependency");
oHRRequest.DependencyAges = oReader.GetString("DependencyAges");
oHRRequest.ExceptionReason = oReader.GetString("ExceptionReason");
oHRRequest.InsuranceDate = oReader.GetDateTime("InsuranceDate").GetValueOrDefault();
oHRRequest.InsuranceVendor = oReader.GetString("InsuranceVendor");
oHRRequest.CostEstimate = oReader.GetDouble("CostEstimate").GetValueOrDefault(0);
oHRRequest.ExpectedDateofRegistration = oReader.GetDateTime("ExpectedDateofRegistration").GetValueOrDefault();
oHRRequest.CountryID = oReader.GetID("CountryID").IsUnassigned ? ID.FromInteger(0) : oReader.GetID("CountryID");
oHRRequest.IsPaymentRequested = oReader.GetBoolean("PaymentRequestCompleted").GetValueOrDefault();
oHRRequest.BankID = oReader.GetID("BankID");
oHRRequest.PaymentMode = (EnumPaymentMode)oReader.GetInt32("PaymentMode").GetValueOrDefault();
oHRRequest.AccountNo = oReader.GetString("AccountNo");
oHRRequest.PaidDate = oReader.GetDateTime("PayRequestDate").GetValueOrDefault();
oHRRequest.PaidRemarks = oReader.GetString("PayRemarks");
oHRRequest.LocationofProperty = oReader.GetString("LocationofProperty");
oHRRequest.MailingAddress = oReader.GetString("MailingAddress");
oHRRequest.EmbassyName = oReader.GetString("EmbassyName");
oHRRequest.EmbassyAddress = oReader.GetString("EmbassyAddress");
this.SetObjectState(oHRRequest, Ease.CoreV35.ObjectState.Saved);
}
protected override T CreateObject<T>(DataReader oReader)
{
HRRequest oHRRequest = new HRRequest();
MapObject(oHRRequest, oReader);
return oHRRequest as T;
}
#endregion
#region Map HRRequestDetails
private void MapHRRequestDetailObject(HRRequestDetail oHRRequestDetail, DataReader oReader)
{
base.SetObjectID(oHRRequestDetail, oReader.GetID("HRRequestDetailID"));
oHRRequestDetail.EmployeeID = oReader.GetID("EmployeeID");
oHRRequestDetail.HRRequestID = oReader.GetID("HRRequestID");
oHRRequestDetail.CourierID = oReader.GetID("CourierID").IsUnassigned ? ID.FromInteger(0) : oReader.GetID("CourierID");
oHRRequestDetail.CourierName = oReader.GetID("CourierID").IsUnassigned ? string.Empty : oReader.GetString("CourierName");
oHRRequestDetail.TokenNumber = oReader.GetString("TokenNumber");
oHRRequestDetail.CourierDate = oReader.GetDateTime("CourierDate").GetValueOrDefault(DateTime.MinValue);
oHRRequestDetail.IsHR = oReader.GetBoolean("IsHR").GetValueOrDefault();
oHRRequestDetail.IsRead = oReader.GetBoolean("IsRead").GetValueOrDefault();
oHRRequestDetail.Remarks = oReader.GetString("Remarks");
oHRRequestDetail.RemarksDate = oReader.GetDateTime("RemarksDate").GetValueOrDefault();
this.SetObjectState(oHRRequestDetail, Ease.CoreV35.ObjectState.Saved);
}
private void MapHRRequestPassportObject(HRRequestPassport oHRRequestPassport, DataReader oReader)
{
base.SetObjectID(oHRRequestPassport, oReader.GetID("HRRequestPassportID"));
oHRRequestPassport.HRRequestID = oReader.GetID("HRRequestID");
oHRRequestPassport.Name = oReader.GetString("Name");
oHRRequestPassport.Relation = oReader.GetString("Relation");
oHRRequestPassport.PassportNo = oReader.GetString("PassportNo");
oHRRequestPassport.ObjectID = oReader.GetID("ObjectID");
this.SetObjectState(oHRRequestPassport, Ease.CoreV35.ObjectState.Saved);
}
private void MapHRRequestLoanObject(HRRequestLoan oHRRequestLoan, DataReader oReader)
{
base.SetObjectID(oHRRequestLoan, oReader.GetID("HRRequestPassportID"));
oHRRequestLoan.HRRequestID = oReader.GetID("HRRequestID");
oHRRequestLoan.Name = oReader.GetString("Name");
oHRRequestLoan.Code = oReader.GetString("Code");
this.SetObjectState(oHRRequestLoan, Ease.CoreV35.ObjectState.Saved);
}
private void MapHRRequestLoanDetailObject(HRRequestLoanDetail oHRRequestLoan, DataReader oReader)
{
base.SetObjectID(oHRRequestLoan, oReader.GetID("HRRequestLoanDetailID"));
oHRRequestLoan.HRRequestID = oReader.GetID("HRRequestID");
oHRRequestLoan.Description = oReader.GetString("Description");
oHRRequestLoan.DescriptionValue = oReader.GetString("DescriptionValue");
oHRRequestLoan.SerialNo = oReader.GetInt16("SerialNo").GetValueOrDefault();
this.SetObjectState(oHRRequestLoan, Ease.CoreV35.ObjectState.Saved);
}
private void MapHRRequestPaymentScheduleObject(HRRequestPaymentSchedule oHRRequestLoan, DataReader oReader)
{
base.SetObjectID(oHRRequestLoan, oReader.GetID("HRRequestPaymentScheduleID"));
oHRRequestLoan.HRRequestID = oReader.GetID("HRRequestID");
oHRRequestLoan.PaymentDescription = oReader.GetString("PaymentDescription");
oHRRequestLoan.PaymentDate = oReader.GetDateTime("PaymentDate").GetValueOrDefault(DateTime.MinValue);
oHRRequestLoan.Amount = oReader.GetDouble("Amount").GetValueOrDefault();
oHRRequestLoan.IsPaymentRequested = oReader.GetBoolean("IsPaymentRequested").GetValueOrDefault();
//oHRRequestLoan.IsPaymentRequested = oReader.GetBoolean("PaymentRequestCompleted").GetValueOrDefault();
oHRRequestLoan.PaymentMode = (EnumPaymentMode)oReader.GetInt32("PaymentMode").GetValueOrDefault();
oHRRequestLoan.BankID = oReader.GetID("BankID");
oHRRequestLoan.AccountNo = oReader.GetString("AccountNo");
oHRRequestLoan.PaidDate = oReader.GetDateTime("PayRequestDate").GetValueOrDefault();
oHRRequestLoan.Remarks = oReader.GetString("PayRemarks");
oHRRequestLoan.LoanIssueID = oReader.GetID("LoanIssueID");
this.SetObjectState(oHRRequestLoan, Ease.CoreV35.ObjectState.Saved);
}
private HRRequestDetail CreateHRRequestDetail(DataReader oReader)
{
HRRequestDetail oHRRequestDetail = new HRRequestDetail();
MapHRRequestDetailObject(oHRRequestDetail, oReader);
return oHRRequestDetail;
}
private HRRequestPassport CreateHRRequestPassport(DataReader oReader)
{
HRRequestPassport oHRRequestPassport = new HRRequestPassport();
MapHRRequestPassportObject(oHRRequestPassport, oReader);
return oHRRequestPassport;
}
private HRRequestLoan CreateHRRequestLoan(DataReader oReader)
{
HRRequestLoan oHRRequestLoan = new HRRequestLoan();
MapHRRequestLoanObject(oHRRequestLoan, oReader);
return oHRRequestLoan;
}
private HRRequestLoanDetail CreateHRRequestLoanDetail(DataReader oReader)
{
HRRequestLoanDetail oHRRequestLoan = new HRRequestLoanDetail();
MapHRRequestLoanDetailObject(oHRRequestLoan, oReader);
return oHRRequestLoan;
}
private HRRequestPaymentSchedule CreateHRRequestPaymentSchedule(DataReader oReader)
{
HRRequestPaymentSchedule oHRRequestLoan = new HRRequestPaymentSchedule();
MapHRRequestPaymentScheduleObject(oHRRequestLoan, oReader);
return oHRRequestLoan;
}
private ObjectsTemplate<HRRequestDetail> CreateHRRequestDetails(DataReader oReader)
{
ObjectsTemplate<HRRequestDetail> oHRRequestDetails = new ObjectsTemplate<HRRequestDetail>();
HRRequestDetail oHRRequestDetail;
while (oReader.Read())
{
oHRRequestDetail = new HRRequestDetail();
oHRRequestDetail = CreateHRRequestDetail(oReader);
oHRRequestDetails.Add(oHRRequestDetail);
}
return oHRRequestDetails;
}
private ObjectsTemplate<HRRequestPassport> CreateHRRequestPassports(DataReader oReader)
{
ObjectsTemplate<HRRequestPassport> oHRRequestPassports = new ObjectsTemplate<HRRequestPassport>();
HRRequestPassport oHRRequestPassport;
while (oReader.Read())
{
oHRRequestPassport = new HRRequestPassport();
oHRRequestPassport = CreateHRRequestPassport(oReader);
oHRRequestPassports.Add(oHRRequestPassport);
}
return oHRRequestPassports;
}
private ObjectsTemplate<HRRequestLoan> CreateHRRequestLoans(DataReader oReader)
{
ObjectsTemplate<HRRequestLoan> oHRRequestLoans = new ObjectsTemplate<HRRequestLoan>();
HRRequestLoan oHRRequestLoan;
while (oReader.Read())
{
oHRRequestLoan = new HRRequestLoan();
oHRRequestLoan = CreateHRRequestLoan(oReader);
oHRRequestLoans.Add(oHRRequestLoan);
}
return oHRRequestLoans;
}
private ObjectsTemplate<HRRequestLoanDetail> CreateHRRequestLoanDetails(DataReader oReader)
{
ObjectsTemplate<HRRequestLoanDetail> oHRRequestLoans = new ObjectsTemplate<HRRequestLoanDetail>();
while (oReader.Read())
{
HRRequestLoanDetail oHRRequestLoan = new HRRequestLoanDetail();
oHRRequestLoan = CreateHRRequestLoanDetail(oReader);
oHRRequestLoans.Add(oHRRequestLoan);
}
return oHRRequestLoans;
}
private ObjectsTemplate<HRRequestPaymentSchedule> CreateHRRequestPaymentSchedules(DataReader oReader)
{
ObjectsTemplate<HRRequestPaymentSchedule> oHRRequestLoans = new ObjectsTemplate<HRRequestPaymentSchedule>();
while (oReader.Read())
{
HRRequestPaymentSchedule oHRRequestLoan = new HRRequestPaymentSchedule();
oHRRequestLoan = CreateHRRequestPaymentSchedule(oReader);
oHRRequestLoans.Add(oHRRequestLoan);
}
return oHRRequestLoans;
}
#endregion
#endregion
public ObjectsTemplate<HRRequestDetail> GetHRequestDetails(ID iD)
{
ObjectsTemplate<HRRequestDetail> oHRRequestDetail = new ObjectsTemplate<HRRequestDetail>();
#region Cache Header
oHRRequestDetail = _cache["Get", iD] as ObjectsTemplate<HRRequestDetail>;
if (oHRRequestDetail != null)
return oHRRequestDetail;
#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader oreader = new DataReader(HRRequestDA.GetHRequestDetails(tc,iD));
oHRRequestDetail = CreateHRRequestDetails(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
}
#region Cache Footer
_cache.Add(oHRRequestDetail, "Get", iD);
#endregion
return oHRRequestDetail;
}
// ObjectsTemplate<HRRequestPassport> GetHRRequestPassports(ID iD);
public ObjectsTemplate<HRRequestPassport> GetHRRequestPassports(ID iD)
{
ObjectsTemplate<HRRequestPassport> oHRRequestPassport = new ObjectsTemplate<HRRequestPassport>();
#region Cache Header
oHRRequestPassport = _cache["Get", iD] as ObjectsTemplate<HRRequestPassport>;
if (oHRRequestPassport != null)
return oHRRequestPassport;
#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader oreader = new DataReader(HRRequestDA.GetHRRequestPassports(tc, iD));
oHRRequestPassport = CreateHRRequestPassports(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
}
#region Cache Footer
_cache.Add(oHRRequestPassport, "Get", iD);
#endregion
return oHRRequestPassport;
}
public ObjectsTemplate<HRRequestLoan> GetHRRequestLoans(ID iD)
{
ObjectsTemplate<HRRequestLoan> oHRRequestLoan = new ObjectsTemplate<HRRequestLoan>();
#region Cache Header
oHRRequestLoan = _cache["Get", iD] as ObjectsTemplate<HRRequestLoan>;
if (oHRRequestLoan != null)
return oHRRequestLoan;
#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader oreader = new DataReader(HRRequestDA.GetHRRequestLoans(tc, iD));
oHRRequestLoan = CreateHRRequestLoans(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
}
#region Cache Footer
_cache.Add(oHRRequestLoan, "Get", iD);
#endregion
return oHRRequestLoan;
}
public ObjectsTemplate<HRRequestLoanDetail> GetHRRequestLoanDetails(ID iD)
{
ObjectsTemplate<HRRequestLoanDetail> oHRRequestLoanDetail = new ObjectsTemplate<HRRequestLoanDetail>();
#region Cache Header
oHRRequestLoanDetail = _cache["GetHRRequestLoanDetails", iD] as ObjectsTemplate<HRRequestLoanDetail>;
if (oHRRequestLoanDetail != null)
return oHRRequestLoanDetail;
#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader oreader = new DataReader(HRRequestDA.GetHRRequestLoanDetails(tc, iD));
oHRRequestLoanDetail = CreateHRRequestLoanDetails(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
}
#region Cache Footer
_cache.Add(oHRRequestLoanDetail, "GetHRRequestLoanDetails", iD);
#endregion
return oHRRequestLoanDetail;
}
public ObjectsTemplate<HRRequestPaymentSchedule> GetHRRequestPaymentSchedules(ID iD)
{
ObjectsTemplate<HRRequestPaymentSchedule> oHRRequestLoanDetail = new ObjectsTemplate<HRRequestPaymentSchedule>();
#region Cache Header
oHRRequestLoanDetail = _cache["GetHRRequestPaymentSchedules", iD] as ObjectsTemplate<HRRequestPaymentSchedule>;
if (oHRRequestLoanDetail != null)
return oHRRequestLoanDetail;
#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader oreader = new DataReader(HRRequestDA.GetHRRequestPaymentSchedules(tc, iD));
oHRRequestLoanDetail = CreateHRRequestPaymentSchedules(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
}
#region Cache Footer
_cache.Add(oHRRequestLoanDetail, "GetHRRequestPaymentSchedules", iD);
#endregion
return oHRRequestLoanDetail;
}
public void UpdatePaymentRequest(HRRequest hRRequest)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
HRRequestDA.UpdatePaymentRequest(tc, hRRequest);
tc.End();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
}
public void UpdateLoanShedulePaymentRequest(HRRequestPaymentSchedule LoanPaymentSchedule)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
HRRequestDA.UpdateLoanShedulePaymentRequest(tc, LoanPaymentSchedule);
tc.End();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
}
public void UpdateLoanSheduleLoanIssueID(HRRequestPaymentSchedule LoanPaymentSchedule)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
HRRequestDA.UpdateLoanSheduleLoanIssueID(tc, LoanPaymentSchedule);
tc.End();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
}
public ID Save(HRRequest hRRequest)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
if (hRRequest.IsNew)
{
int id = tc.GenerateID("HRREQUEST", "HRREQUESTID");
hRRequest.ClaimNumber = GenerateClaimNumber(tc,hRRequest);
this.SetObjectID(hRRequest, ID.FromInteger(id));
HRRequestDA.Insert(tc, hRRequest);
}
else
{
HRRequestDA.Update(tc, hRRequest);
}
return hRRequest.ID;
}
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();
}
}
}
private string GenerateClaimNumber(TransactionContext tc, HRRequest hRRequest)
{
string sClaimNumber = string.Empty;
int number = 0;
number = HRRequestDA.GetMaxClaimNumber(tc,hRRequest.RequestDate.Year.ToString()+"%");
sClaimNumber = hRRequest.RequestDate.Year.ToString() + GetConvertedClaimNumber(number+1);
return sClaimNumber;
}
private static string GetConvertedClaimNumber(int number)
{
string strSubNo = string.Empty;
if (number / 1000 != 0)
return number.ToString();
else if (number / 100 != 0)
return "0" + number.ToString();
else if (number / 10 != 0)
return "00" + number.ToString();
else
return "000" + number.ToString();
}
public void SaveLetterRequest(HRRequest hRRequest)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
if (hRRequest.IsNew)
{
int id = tc.GenerateID("HRREQUEST", "HRREQUESTID");
this.SetObjectID(hRRequest, ID.FromInteger(id));
hRRequest.ClaimNumber = GenerateClaimNumber(tc, hRRequest);
HRRequestDA.InsertLetterRequest(tc, hRRequest);
if (hRRequest.IsWithFamily)
{
HRRequestPassport oHRReqPassport;
foreach (var item in hRRequest.HRRequestPassports)
{
oHRReqPassport = new HRRequestPassport();
oHRReqPassport = item;
this.SetObjectID(oHRReqPassport, ID.FromInteger(tc.GenerateID("HRREQUESTPASSPORT", "HRRequestPassportID")));
oHRReqPassport.HRRequestID = ID.FromInteger(id);
HRRequestDA.InsertHRPassport(tc, oHRReqPassport);
}
}
}
else
{
HRRequestDA.UpdateLetterRequest(tc, hRRequest);
}
// return hRRequest.ID;
}
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 void SaveDetail(HRRequestDetail oHrrequestDetails)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
if (oHrrequestDetails.IsNew)
{
int id = tc.GenerateID("HRRequestDetail", "HRRequestDetailID");
this.SetObjectID(oHrrequestDetails, ID.FromInteger(id));
HRRequestDA.InsertDetails(tc, oHrrequestDetails);
}
else
{
HRRequestDA.UpdateDetails(tc, oHrrequestDetails);
}
}
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 void SaveLoan(HRRequest hRRequest)
{
TransactionContext tc = null;
ID parentID;
try
{
tc = TransactionContext.Begin(true);
if (hRRequest.IsNew)
{
parentID = ID.FromInteger(tc.GenerateID("HRREQUEST", "HRREQUESTID"));
this.SetObjectID(hRRequest, parentID);
hRRequest.ClaimNumber = GenerateClaimNumber(tc, hRRequest);
HRRequestDA.Insert(tc, hRRequest);
}
else
{
parentID = hRRequest.ID;
HRRequestDA.Update(tc, hRRequest);
HRRequestDA.DeleteHRRequestLoan(tc,hRRequest.ID);
}
foreach (var item in hRRequest.HRRequestLoans)
{
this.SetObjectID(item, ID.FromInteger(tc.GenerateID("HRRequestLoan", "HRRequestLoanID")));
item.HRRequestID = parentID;
HRRequestDA.InsertLoan(tc, item);
}
// return hRRequest.ID;
}
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 void SaveLoanandPaymentDetail(HRRequest hRRequest)
{
TransactionContext tc = null;
ID parentID;
try
{
tc = TransactionContext.Begin(true);
if (hRRequest.IsNew)
{
parentID = ID.FromInteger(tc.GenerateID("HRREQUEST", "HRREQUESTID"));
this.SetObjectID(hRRequest, parentID);
hRRequest.ClaimNumber = GenerateClaimNumber(tc, hRRequest);
HRRequestDA.Insert(tc, hRRequest);
}
else
{
parentID = hRRequest.ID;
HRRequestDA.Update(tc, hRRequest);
HRRequestDA.DeleteHRRequestLoan(tc, hRRequest.ID);
HRRequestDA.DeleteHRRequestLoanDetail(tc, hRRequest.ID);
HRRequestDA.DeleteHRRequestPaymentSchedule(tc, hRRequest.ID);
}
foreach (var item in hRRequest.HRRequestLoans)
{
this.SetObjectID(item, ID.FromInteger(tc.GenerateID("HRRequestLoan", "HRRequestLoanID")));
item.HRRequestID = parentID;
HRRequestDA.InsertLoan(tc, item);
}
foreach (var item in hRRequest.HRRequestLoanDetails)
{
this.SetObjectID(item, ID.FromInteger(tc.GenerateID("HRRequestLoanDetail", "HRRequestLoanDetailID")));
item.HRRequestID = parentID;
HRRequestDA.InsertLoanDetail(tc, item);
}
foreach (var item in hRRequest.HRRequestPaymentSchedules)
{
this.SetObjectID(item, ID.FromInteger(tc.GenerateID("HRRequestPaymentSchedule", "HRRequestPaymentScheduleID")));
item.HRRequestID = parentID;
HRRequestDA.InsertPaymentSchedule(tc, item);
}
// return hRRequest.ID;
}
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 void SavePaymentSchedules(ObjectsTemplate<HRRequestPaymentSchedule> oItems)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
HRRequestDA.DeleteHRRequestPaymentSchedule(tc, oItems[0].HRRequestID);
foreach (var item in oItems)
{
this.SetObjectID(item, ID.FromInteger(tc.GenerateID("HRRequestPaymentSchedule", "HRRequestPaymentScheduleID")));
HRRequestDA.InsertPaymentSchedule(tc, item);
}
}
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 HRRequest Get(ID id)
{
HRRequest oHRequest = new HRRequest();
#region Cache Header
oHRequest = _cache["Get", id] as HRRequest;
if (oHRequest != null)
return oHRequest;
#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader oreader = new DataReader(HRRequestDA.Get(tc, id));
if (oreader.Read())
{
oHRequest = this.CreateObject<HRRequest>(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
}
#region Cache Footer
_cache.Add(oHRequest, "Get", id);
#endregion
return oHRequest;
}
public ObjectsTemplate<HRRequest> GetLFAMedicalClaimByEmpID(ID id)
{
ObjectsTemplate<HRRequest> oHRRequests = new ObjectsTemplate<HRRequest>();
#region Cache Header
oHRRequests = _cache["Get", id] as ObjectsTemplate<HRRequest>;
if (oHRRequests != null)
return oHRRequests;
#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader oreader = new DataReader(HRRequestDA.GetLFAMedicalClaimByEmpID(tc,id));
oHRRequests = this.CreateObjects<HRRequest>(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
{
if (tc != null)
{
tc.End();
}
}
#region Cache Footer
_cache.Add(oHRRequests, "Get", id);
#endregion
return oHRRequests;
}
public ObjectsTemplate<HRRequest> GetInsuranceClaimByEmpID(ID id)
{
ObjectsTemplate<HRRequest> oHRRequests = new ObjectsTemplate<HRRequest>();
#region Cache Header
oHRRequests = _cache["Get", id] as ObjectsTemplate<HRRequest>;
if (oHRRequests != null)
return oHRRequests;
#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader oreader = new DataReader(HRRequestDA.GetInsuranceClaimByEmpID(tc, id));
oHRRequests = this.CreateObjects<HRRequest>(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
{
if (tc != null)
{
tc.End();
}
}
#region Cache Footer
_cache.Add(oHRRequests, "Get", id);
#endregion
return oHRRequests;
}
public ObjectsTemplate<HRRequest> GetLetterClaimByEmpID(ID id)
{
ObjectsTemplate<HRRequest> oHRRequests = new ObjectsTemplate<HRRequest>();
#region Cache Header
oHRRequests = _cache["Get", id] as ObjectsTemplate<HRRequest>;
if (oHRRequests != null)
return oHRRequests;
#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader oreader = new DataReader(HRRequestDA.GetLetterClaimByEmpID(tc, id));
oHRRequests = this.CreateObjects<HRRequest>(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
{
if (tc != null)
{
tc.End();
}
}
#region Cache Footer
_cache.Add(oHRRequests, "Get", id);
#endregion
return oHRRequests;
}
public ObjectsTemplate<HRRequest> GetHRRequetByWFStatus(enumwfStatus status)
{
ObjectsTemplate<HRRequest> oHRRequests = new ObjectsTemplate<HRRequest>();
#region Cache Header
oHRRequests = _cache["Get", status] as ObjectsTemplate<HRRequest>;
if (oHRRequests != null)
return oHRRequests;
#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader oreader = new DataReader(HRRequestDA.GetHRRequetByWFStatus(tc, status));
oHRRequests = this.CreateObjects<HRRequest>(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
{
if (tc != null)
{
tc.End();
}
}
#region Cache Footer
_cache.Add(oHRRequests, "Get", status);
#endregion
return oHRRequests;
}
public DataTable GetInsuranceDetailByReqID(int hRrequstId)
{
DataSet dataSet = new DataSet();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
dataSet = HRRequestDA.GetInshuranceDetailByReqID(tc, hRrequstId);
if (dataSet.Tables.Count > 0)
return dataSet.Tables[0];
return null;
}
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 DataTable GetPaymentRequestedItems()
{
DataSet dataSet = new DataSet();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
dataSet = HRRequestDA.GetPaymentRequestedItems(tc);
if (dataSet.Tables.Count > 0)
return dataSet.Tables[0];
return null;
tc.End();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
}
public void ReadHRRequestDetail(ID HRRequestDetailID)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
HRRequestDA.ReadHRRequestDetail(tc, HRRequestDetailID);
}
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 ObjectsTemplate<HRRequest> GetLoanCalimbyScheduleDate(DateTime fromdate, DateTime toDate)
{
ObjectsTemplate<HRRequest> oHRRequests = new ObjectsTemplate<HRRequest>();
#region Cache Header
oHRRequests = _cache["Get", fromdate,toDate] as ObjectsTemplate<HRRequest>;
if (oHRRequests != null)
return oHRRequests;
#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader oreader = new DataReader(HRRequestDA.GetLoanCalimbyScheduleDate(tc, fromdate, toDate));
oHRRequests = this.CreateObjects<HRRequest>(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
{
if (tc != null)
{
tc.End();
}
}
#region Cache Footer
_cache.Add(oHRRequests, "Get", fromdate,toDate);
#endregion
return oHRRequests;
}
public ObjectsTemplate<HRRequest> GetLFAMedicalClaim(ID id, DateTime dateTime1, DateTime dateTime2)
{
ObjectsTemplate<HRRequest> oHRRequests = new ObjectsTemplate<HRRequest>();
#region Cache Header
oHRRequests = _cache["Get", id] as ObjectsTemplate<HRRequest>;
if (oHRRequests != null)
return oHRRequests;
#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader oreader = new DataReader(HRRequestDA.GetLFAMedicalClaim(tc, id,dateTime1,dateTime2));
oHRRequests = this.CreateObjects<HRRequest>(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
{
if (tc != null)
{
tc.End();
}
}
#region Cache Footer
_cache.Add(oHRRequests, "Get", id);
#endregion
return oHRRequests;
}
public ObjectsTemplate<HRRequest> GetInsuranceClaim(ID id, DateTime dateTime1, DateTime dateTime2)
{
ObjectsTemplate<HRRequest> oHRRequests = new ObjectsTemplate<HRRequest>();
#region Cache Header
oHRRequests = _cache["Get", id] as ObjectsTemplate<HRRequest>;
if (oHRRequests != null)
return oHRRequests;
#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader oreader = new DataReader(HRRequestDA.GetInsuranceClaim(tc, id, dateTime1, dateTime2));
oHRRequests = this.CreateObjects<HRRequest>(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
{
if (tc != null)
{
tc.End();
}
}
#region Cache Footer
_cache.Add(oHRRequests, "Get", id);
#endregion
return oHRRequests;
}
public ObjectsTemplate<HRRequest> GetLetterClaim(ID id, DateTime dateTime1, DateTime dateTime2)
{
ObjectsTemplate<HRRequest> oHRRequests = new ObjectsTemplate<HRRequest>();
#region Cache Header
oHRRequests = _cache["Get", id] as ObjectsTemplate<HRRequest>;
if (oHRRequests != null)
return oHRRequests;
#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader oreader = new DataReader(HRRequestDA.GetLetterClaim(tc, id, dateTime1, dateTime2));
oHRRequests = this.CreateObjects<HRRequest>(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
{
if (tc != null)
{
tc.End();
}
}
#region Cache Footer
_cache.Add(oHRRequests, "Get", id);
#endregion
return oHRRequests;
}
public ObjectsTemplate<HRRequest> GetLoanApplicationByEmpID(ID empID)
{
ObjectsTemplate<HRRequest> oHRRequests = new ObjectsTemplate<HRRequest>();
#region Cache Header
oHRRequests = _cache["GetLoanApplicationByEmpID", empID] as ObjectsTemplate<HRRequest>;
if (oHRRequests != null)
return oHRRequests;
#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader oreader = new DataReader(HRRequestDA.GetLoanApplicationByEmpID(tc, empID));
oHRRequests = this.CreateObjects<HRRequest>(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
{
if (tc != null)
{
tc.End();
}
}
#region Cache Footer
_cache.Add(oHRRequests, "GetLoanApplicationByEmpID", empID);
#endregion
return oHRRequests;
}
public ObjectsTemplate<HRRequest> GetLoanApplicationByDateRange(ID empID, DateTime startDate, DateTime endDate)
{
ObjectsTemplate<HRRequest> oHRRequests = new ObjectsTemplate<HRRequest>();
#region Cache Header
oHRRequests = _cache["GetLoanApplicationByDateRange", empID, startDate, endDate] as ObjectsTemplate<HRRequest>;
if (oHRRequests != null)
return oHRRequests;
#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader oreader = new DataReader(HRRequestDA.GetLoanApplicationByDateRange(tc, empID, startDate, endDate));
oHRRequests = this.CreateObjects<HRRequest>(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
{
if (tc != null)
{
tc.End();
}
}
#region Cache Footer
_cache.Add(oHRRequests, "GetLoanApplicationByDateRange", empID, startDate, endDate);
#endregion
return oHRRequests;
}
}
}