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

1108 lines
38 KiB
C#

using System;
using System.Data;
using System.Linq;
using Ease.CoreV35;
using Ease.CoreV35.Model;
using Ease.CoreV35.DataAccess;
using System.Collections.Generic;
using Payroll.BO;
using Ease.CoreV35.Caching;
namespace Payroll.Service
{
#region CarFuelProcess Service
[Serializable]
public class CarFuelProcessService : ServiceTemplate, ICarFuelProcessService
{
#region Private functions and declaration
Cache _cache = new Cache(typeof(CarFuelProcess));
public CarFuelProcessService() { }
#region CarFuelProcess
private void MapObject(CarFuelProcess oCarFuelProcess, DataReader oReader)
{
base.SetObjectID(oCarFuelProcess, oReader.GetID("CarFuelProcessID"));
oCarFuelProcess.CarFuelMonth = oReader.GetDateTime("CarFuelMonth").Value;
oCarFuelProcess.ProcessDate = oReader.GetDateTime("ProcessDate").Value;
oCarFuelProcess.CreatedBy = oReader.GetID("CreatedBy");
oCarFuelProcess.CreatedDate = oReader.GetDateTime("CreationDate").Value;
oCarFuelProcess.ModifiedBy = oReader.GetID("ModifiedBy");
oCarFuelProcess.ModifiedDate = oReader.GetDateTime("ModifiedDate");
oCarFuelProcess.IsApproved = oReader.GetBoolean("IsApproved").Value;
this.SetObjectState(oCarFuelProcess, Ease.CoreV35.ObjectState.Saved);
}
protected override T CreateObject<T>(DataReader oReader)
{
CarFuelProcess oCarFuelProcess = new CarFuelProcess();
MapObject(oCarFuelProcess, oReader);
return oCarFuelProcess as T;
}
protected CarFuelProcess CreateObject(DataReader oReader)
{
CarFuelProcess oCarFuelProcess = new CarFuelProcess();
MapObject(oCarFuelProcess, oReader);
return oCarFuelProcess;
}
#endregion
#region CarFuelProcessDetail
private void MapProcessDetailObject(CarFuelProcessDetail oProcessDetail, DataReader oReader)
{
base.SetObjectID(oProcessDetail, oReader.GetID("CarFuelProcessDetailID"));
oProcessDetail.AccountNo = oReader.GetString("AccountNo");
oProcessDetail.BankID = oReader.GetID("BankID");
oProcessDetail.BranchID = oReader.GetID("BranchID");
oProcessDetail.CategoryID = oReader.GetID("CategoryID");
oProcessDetail.DepartmentID = oReader.GetID("DepartmentID");
oProcessDetail.DesignationID = oReader.GetID("DesignationID");
oProcessDetail.EmployeeID = oReader.GetID("EmployeeID");
oProcessDetail.Gender = (EnumGender)oReader.GetInt32("Gender");
oProcessDetail.GradeID = oReader.GetID("GradeID");
oProcessDetail.IsConfirmed = oReader.GetBoolean("IsConfirmed").Value;
oProcessDetail.IsFinalize = oReader.GetBoolean("IsFinalize").Value;
oProcessDetail.LocationID = oReader.GetID("LocationID");
oProcessDetail.CarFuelProcessID = oReader.GetID("CarFuelProcessID");
oProcessDetail.PayrollTypeID = oReader.GetID("PayrollTypeID");
oProcessDetail.PFMemberType = (EnumPFMembershipType)oReader.GetInt32("PFMemberType");
oProcessDetail.ReligionID = oReader.GetID("ReligionID");
oProcessDetail.Remarks = oReader.GetString("Remarks");
this.SetObjectState(oProcessDetail, Ease.CoreV35.ObjectState.Saved);
}
protected ObjectsTemplate<CarFuelProcessDetail> CreateProcessDetailObject(DataReader oReader)
{
ObjectsTemplate<CarFuelProcessDetail> oProcessDetails = new ObjectsTemplate<CarFuelProcessDetail>();
while (oReader.Read())
{
CarFuelProcessDetail oProcessDetail = new CarFuelProcessDetail();
MapProcessDetailObject(oProcessDetail, oReader);
oProcessDetails.Add(oProcessDetail);
}
return oProcessDetails;
}
#endregion
#region CarFuelProcessDetailItem
private void MapProcessDetailItemObject(CarFuelProcessDetailItem oCarFuelProcessDetailItem, DataReader oReader)
{
base.SetObjectID(oCarFuelProcessDetailItem, oReader.GetID("CarFuelProcessDetailItemID"));
oCarFuelProcessDetailItem.ChangeNetAmount = oReader.GetDouble("ChangeNetAmount").Value;
oCarFuelProcessDetailItem.Description = oReader.GetString("Description");
oCarFuelProcessDetailItem.NetAmount = oReader.GetDouble("NetAmount").Value;
oCarFuelProcessDetailItem.TaxAmount = oReader.GetDouble("TaxAmount").Value;
oCarFuelProcessDetailItem.CarFuelItemID = oReader.GetID("CarFuelItemID");
oCarFuelProcessDetailItem.CarFuelProcessDetailID = oReader.GetID("CarFuelProcessDetailID");
oCarFuelProcessDetailItem.CarFuelType = (EnumCarFuelType)oReader.GetInt32("CarFuelType").Value;
oCarFuelProcessDetailItem.CreatedBy = oReader.GetID("CreatedBy");
oCarFuelProcessDetailItem.CreatedDate = oReader.GetDateTime("CreationDate").Value;
oCarFuelProcessDetailItem.ModifiedBy = oReader.GetID("ModifiedBy");
oCarFuelProcessDetailItem.ModifiedDate = oReader.GetDateTime("ModifiedDate");
this.SetObjectState(oCarFuelProcessDetailItem, Ease.CoreV35.ObjectState.Saved);
}
protected ObjectsTemplate<CarFuelProcessDetailItem> CreateProcessDetailItemObject(DataReader oReader)
{
ObjectsTemplate<CarFuelProcessDetailItem> oProcessDetailItems = new ObjectsTemplate<CarFuelProcessDetailItem>();
while (oReader.Read())
{
CarFuelProcessDetailItem oProcessDetailItem = new CarFuelProcessDetailItem();
MapProcessDetailItemObject(oProcessDetailItem, oReader);
oProcessDetailItems.Add(oProcessDetailItem);
}
return oProcessDetailItems;
}
#endregion
#endregion
#region Service implementation
public CarFuelProcess Get(ID id, int payrollTypeID)
{
CarFuelProcess oCarFuelProcess = new CarFuelProcess();
#region Cache Header
oCarFuelProcess = (CarFuelProcess)_cache["Get", id] as CarFuelProcess;
if (oCarFuelProcess != null)
return oCarFuelProcess;
#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader oReader = new DataReader(CarFuelProcessDA.Get(tc, id, payrollTypeID));
if (oReader.Read())
{
oCarFuelProcess = this.CreateObject(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(oCarFuelProcess, "Get", id);
#endregion
return oCarFuelProcess;
}
public CarFuelProcess Get(DateTime fromdate, ID empiD)
{
CarFuelProcess oCarFuelProcess = new CarFuelProcess();
#region Cache Header
oCarFuelProcess = (CarFuelProcess)_cache["Get", fromdate, empiD] as CarFuelProcess;
if (oCarFuelProcess != null)
return oCarFuelProcess;
#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader oReader = new DataReader(CarFuelProcessDA.Get(tc, fromdate, empiD));
if (oReader.Read())
{
oCarFuelProcess = this.CreateObject(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(oCarFuelProcess, "Get", fromdate, empiD);
#endregion
return oCarFuelProcess;
}
public ObjectsTemplate<CarFuelProcess> Get(int payrollTypeID)
{
#region Cache Header
ObjectsTemplate<CarFuelProcess> oCarFuelProcesss = _cache["Get"] as ObjectsTemplate<CarFuelProcess>;
if (oCarFuelProcesss != null)
return oCarFuelProcesss;
#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader oreader = new DataReader(CarFuelProcessDA.Get(tc, payrollTypeID));
oCarFuelProcesss = this.CreateObjects<CarFuelProcess>(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(oCarFuelProcesss, "Get");
#endregion
return oCarFuelProcesss;
}
public ObjectsTemplate<CarFuelProcess> Get(DateTime dCarFuelMonth, int payrollTypeID)
{
#region Cache Header
ObjectsTemplate<CarFuelProcess> oProcesss = _cache["Get", dCarFuelMonth] as ObjectsTemplate<CarFuelProcess>;
if (oProcesss != null)
return oProcesss;
#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(CarFuelProcessDA.Get(tc, dCarFuelMonth, payrollTypeID));
oProcesss = this.CreateObjects<CarFuelProcess>(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(oProcesss, "Get", dCarFuelMonth);
#endregion
return oProcesss;
}
public ObjectsTemplate<CarFuelProcessDetail> GetProcessDetails(ID CarFuelProcessID, int payrollTypeID)
{
#region Cache Header
ObjectsTemplate<CarFuelProcessDetail> oProcessDetails = _cache["GetProcessDetails", CarFuelProcessID] as ObjectsTemplate<CarFuelProcessDetail>;
if (oProcessDetails != null)
return oProcessDetails;
#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(CarFuelProcessDA.GetProcessDetails(tc, CarFuelProcessID, payrollTypeID));
oProcessDetails = this.CreateProcessDetailObject(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(oProcessDetails, "GetProcessDetails", CarFuelProcessID);
#endregion
return oProcessDetails;
}
public ObjectsTemplate<CarFuelProcessDetail> GetDetail(DateTime processMonth)
{
#region Cache Header
ObjectsTemplate<CarFuelProcessDetail> oProcessDetails = _cache["GetDetail", processMonth] as ObjectsTemplate<CarFuelProcessDetail>;
if (oProcessDetails != null)
return oProcessDetails;
#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(CarFuelProcessDA.GetDetail(tc, processMonth));
oProcessDetails = this.CreateProcessDetailObject(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(oProcessDetails, "GetDetail", processMonth);
#endregion
return oProcessDetails;
}
public CarFuelProcessDetail GetDetail(ID employeeID, DateTime processMonth, int payrollTypeID)
{
ObjectsTemplate<CarFuelProcessDetail> oDetails = null;
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader oReader = new DataReader(CarFuelProcessDA.GetDetails(tc, employeeID, processMonth, payrollTypeID));
oDetails = this.CreateProcessDetailObject(oReader);
oReader.Close();
tc.End();
foreach (CarFuelProcessDetail oDetail in oDetails)
{
ObjectsTemplate<CarFuelProcessDetailItem> oItems = new ObjectsTemplate<CarFuelProcessDetailItem>();
oItems = GetProcessDetailItems(oDetail.ID, payrollTypeID);
oDetail.CarFuelProcessDetailItems = oItems;
}
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
if (oDetails.Count > 0) return oDetails[0];
else return null;
}
public DataSet GetCarFuelRegister(string sCarFuelItemID, DateTime dCarFuelMonth, DateTime dCarFuelMonth2, string sEmpID)
{
DataSet oCarFuelRegisters = new DataSet();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
oCarFuelRegisters = CarFuelProcessDA.GetCarFuelRegister(tc, sCarFuelItemID, dCarFuelMonth, dCarFuelMonth2, sEmpID);
tc.End();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
return oCarFuelRegisters;
}
public ObjectsTemplate<CarFuelProcessDetail> GetProcessDetails(DateTime processMonth, int payrollTypeID)
{
ObjectsTemplate<CarFuelProcessDetail> oProcessDetails;
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(CarFuelProcessDA.GetProcessDetails(tc, processMonth, payrollTypeID));
oProcessDetails = this.CreateProcessDetailObject(dr);
dr.Close();
DataReader drItems = new DataReader(CarFuelProcessDA.GetProcessDetailsItems(tc, processMonth, payrollTypeID));
ObjectsTemplate<CarFuelProcessDetailItem> detialItems = this.CreateProcessDetailItemObject(drItems);
dr.Close();
int check = 0;
foreach (CarFuelProcessDetail pro in oProcessDetails)
{
check = 0;
foreach (CarFuelProcessDetailItem detail in detialItems)
{
if (pro.ID.Integer == detail.CarFuelProcessDetailID.Integer)
{
pro.CarFuelProcessDetailItems.Add(detail);
//check = 1;
}
// else
// {
// if (check == 1) break;
// }
}
}
tc.End();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
return oProcessDetails;
}
public ObjectsTemplate<CarFuelProcessDetail> GetProcessDetailWithItems(ID CarFuelProcessID, int payrollTypeID)
{
#region Cache Header
ObjectsTemplate<CarFuelProcessDetail> oProcessDetails = _cache["GetProcessDetails", CarFuelProcessID] as ObjectsTemplate<CarFuelProcessDetail>;
if (oProcessDetails != null)
return oProcessDetails;
#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(CarFuelProcessDA.GetProcessDetails(tc, CarFuelProcessID, payrollTypeID));
oProcessDetails = this.CreateProcessDetailObject(dr);
dr.Close();
tc.End();
foreach (CarFuelProcessDetail oDetail in oProcessDetails)
{
ObjectsTemplate<CarFuelProcessDetailItem> oItems = new ObjectsTemplate<CarFuelProcessDetailItem>();
oItems = GetProcessDetailItems(oDetail.ID, payrollTypeID);
oDetail.CarFuelProcessDetailItems = oItems;
}
}
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(oProcessDetails, "GetProcessDetails", CarFuelProcessID);
#endregion
return oProcessDetails;
}
public ObjectsTemplate<CarFuelProcessDetailItem> GetProcessDetailItems(ID nProcessDetailID, int payrollTypeID)
{
#region Cache Header
ObjectsTemplate<CarFuelProcessDetailItem> oProcessDetailItems = _cache["GetProcessDetailItems", nProcessDetailID] as ObjectsTemplate<CarFuelProcessDetailItem>;
if (oProcessDetailItems != null)
return oProcessDetailItems;
#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(CarFuelProcessDA.GetProcessDetailItems(tc, nProcessDetailID, payrollTypeID));
oProcessDetailItems = this.CreateProcessDetailItemObject(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(oProcessDetailItems, "GetProcessDetailItems", nProcessDetailID);
#endregion
return oProcessDetailItems;
}
public ObjectsTemplate<CarFuelProcessDetailItem> GetCarFuelProcessItems(DateTime dateTime, int payrollTypeID)
{
#region Cache Header
ObjectsTemplate<CarFuelProcessDetailItem> oProcessDetailItems = _cache["GetCarFuelProcessItems", dateTime] as ObjectsTemplate<CarFuelProcessDetailItem>;
if (oProcessDetailItems != null)
return oProcessDetailItems;
#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(CarFuelProcessDA.GetProcessDetailsItems(tc, dateTime, payrollTypeID));
oProcessDetailItems = this.CreateProcessDetailItemObject(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(oProcessDetailItems, "GetCarFuelProcessItems", dateTime);
#endregion
return oProcessDetailItems;
}
public double GetProvisionAmountByEmpID(ID nEmpID)
{
double nAmount = 0;
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
nAmount = CarFuelProcessDA.GetProvisionAmountByEmpID(tc, nEmpID);
tc.End();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
return nAmount;
}
public double GetPrevMonthAmount(ID nEmpID, ID nCarFuelItemID, DateTime dFromCarFuelMonth, DateTime dToCarFuelMonth)
{
double nAmount = 0;
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
nAmount = CarFuelProcessDA.GetPrevMonthAmount(tc, nEmpID, nCarFuelItemID, dFromCarFuelMonth, dToCarFuelMonth);
tc.End();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
return nAmount;
}
public DataSet GetDataSetOfCarFuelRegister(string sSearch)
{
DataSet dsCarFuelRegister = new DataSet();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
dsCarFuelRegister = CarFuelProcessDA.GetDataSetOfCarFuelRegister(tc, sSearch);
tc.End();
}
catch (Exception e)
{
throw new ServiceException("Failed to get CarFuel Register data due to " + e.Message);
}
return dsCarFuelRegister;
}
public DataSet GetCarFuelRegister(string sCarFuelItemID, DateTime dCarFuelMonth, string sEmpID)
{
DataSet oCarFuelRegisters = new DataSet();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
oCarFuelRegisters = CarFuelProcessDA.GetCarFuelRegister(tc, sCarFuelItemID, dCarFuelMonth, sEmpID);
tc.End();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
return oCarFuelRegisters;
}
public DataSet GetIDLCCarFuelRegister(DateTime dCarFuelMonth, string sEmpID)
{
DataSet oCarFuelRegisters = new DataSet();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
oCarFuelRegisters = CarFuelProcessDA.GetIDLCCarFuelRegister(tc, dCarFuelMonth, sEmpID);
tc.End();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
return oCarFuelRegisters;
}
public DataSet GetDetailOtherPayrollItems(string sCarFuelItemID, DateTime dCarFuelMonth, string sEmpID)
{
DataSet oCarFuelRegisters = new DataSet();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
oCarFuelRegisters = CarFuelProcessDA.GetDetailOtherPayrollItems(tc, sCarFuelItemID, dCarFuelMonth, sEmpID);
tc.End();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
return oCarFuelRegisters;
}
public DataSet GetCarFuelTotalValueRegister(DateTime dFromCarFuelMonth, DateTime dToCarFuelMonth, int nCarFuelItemID, string sEmpID)
{
DataSet oCarFuelRegisters = new DataSet();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
oCarFuelRegisters = CarFuelProcessDA.GetCarFuelTotalValueRegister(tc, dFromCarFuelMonth, dToCarFuelMonth, nCarFuelItemID, sEmpID);
tc.End();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
return oCarFuelRegisters;
}
private void SaveProcessDetail(TransactionContext tc, CarFuelProcessDetail oPDetail, int payrollTypeID)
{
string tableName = "CarFuelProcessDetail";
try
{
//inserting CarFuelProcessDetail
int id = tc.GenerateID("CarFuelProcessDetail", "CarFuelProcessDetailID");
int itemID = tc.GenerateID("CarFuelProcessDetailItem", "CarFuelProcessDetailItemID");
if (oPDetail.IsNew)
{
base.SetObjectID(oPDetail, ID.FromInteger(id));
oPDetail.CreatedBy = User.CurrentUser.ID;
oPDetail.CreatedDate = DateTime.Now;
oPDetail.DesignationID = oPDetail.Employee.DesignationID;
CarFuelProcessDA.InsertProcessDetail(tc, oPDetail);
}
else
{
CarFuelProcessDA.UpdateProcessDetail(tc, oPDetail);
CarFuelProcessDA.DeleteProcessDetailItem(tc, oPDetail.ID, payrollTypeID);
}
//inserting CarFuelProcessDetailItem
tableName = "CarFuelProcessDetailItem";
foreach (CarFuelProcessDetailItem oPDItem in oPDetail.CarFuelProcessDetailItems)
{
oPDItem.CarFuelProcessDetailID = oPDetail.ID;
base.SetObjectID(oPDItem, ID.FromInteger(itemID));
oPDItem.CreatedBy = User.CurrentUser.ID;
oPDItem.CreatedDate = DateTime.Now;
CarFuelProcessDA.InsertProcessDetailItem(tc, oPDItem);
itemID++;
}
}
catch (Exception e)
{
#region Handle Exception
ExceptionLog.Write(e);
string smessage = "Faliled to save CarFuel process (table:" + tableName
+ " for employee (" + oPDetail.Employee.EmployeeNo + " - " + oPDetail.Employee.Name + " ) due to :";
throw new ServiceException(smessage + e.Message, e);
#endregion
}
}
public ID Save(CarFuelProcess oProcess)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
if (oProcess.IsNew)
{
int id = tc.GenerateID("CarFuelProcess", "CarFuelProcessID");
base.SetObjectID(oProcess, ID.FromInteger(id));
CarFuelProcessDA.InsertProcess(tc, oProcess);
}
else
{
CarFuelProcessDA.UpdateProcess(tc, oProcess);
}
tc.End();
return oProcess.ID;
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
}
public ID SaveProcess(TransactionContext tc, CarFuelProcess oCarFuelProcess)
{
string tableName = "CarFuelProcess";
try
{
if (oCarFuelProcess.IsNew)
{
int id = tc.GenerateID("CarFuelProcess", "CarFuelProcessID");
base.SetObjectID(oCarFuelProcess, ID.FromInteger(id));
CarFuelProcessDA.InsertProcess(tc, oCarFuelProcess);
}
else
{
CarFuelProcessDA.UpdateProcess(tc, oCarFuelProcess);
}
return oCarFuelProcess.ID;
}
catch (Exception e)
{
#region Handle Exception
ExceptionLog.Write(e);
string smessage = "Faliled to save CarFuel process (table:" + tableName + ") due to : ";
throw new ServiceException(smessage + e.Message, e);
#endregion
}
}
public void Save(CarFuelProcess oProcess, ObjectsTemplate<CarFuelProcessDetail> oPDetails, int payrollTypeID)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
ID processId = this.SaveProcess(tc, oProcess);
foreach (CarFuelProcessDetail oPDetail in oPDetails)
{
oPDetail.CarFuelProcessID = processId;
this.SaveProcessDetail(tc, oPDetail, payrollTypeID);
}
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 Delete(ID id, int payrollTypeID)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
CarFuelProcessDA.DeleteProcess(tc, id, payrollTypeID);
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 Undo(DateTime CarFuelMonth, int payrollTypeID)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
CarFuelProcessDA.Undo(tc, CarFuelMonth, payrollTypeID);
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 UpdateDetail(ObjectsTemplate<CarFuelProcessDetailItem> oCarFuelDetails)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
foreach (CarFuelProcessDetailItem odetail in oCarFuelDetails)
{
CarFuelProcessDA.UpdateSalaryDetail(tc, odetail);
}
tc.End();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
}
public ObjectsTemplate<CarFuelProcessDetailItem> GetLastMonthItems(int nID, int payrollTypeID)
{
#region Cache Header
ObjectsTemplate<CarFuelProcessDetailItem> oProcessDetailItems = _cache["GetLastMonthItems", nID] as ObjectsTemplate<CarFuelProcessDetailItem>;
if (oProcessDetailItems != null)
return oProcessDetailItems;
#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(CarFuelProcessDA.GetLastMonthItems(tc, nID, payrollTypeID));
oProcessDetailItems = this.CreateProcessDetailItemObject(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(oProcessDetailItems, "GetLastMonthItems", nID);
#endregion
return oProcessDetailItems;
}
public DataSet GetEmpCarFuelPaySlip(DateTime dateTime, string sEmpID)
{
DataSet oCarFuelProcesses = new DataSet();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
oCarFuelProcesses = CarFuelProcessDA.GetEmpCarFuelPaySlip(tc, dateTime, sEmpID);
tc.End();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
return oCarFuelProcesses;
}
public DataSet GetItemWiseCarFuel(DateTime dFromCarFuelMonth, int CarFuelItemID, string sEmpID)
{
DataSet oCarFuelRegisters = new DataSet();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
oCarFuelRegisters = CarFuelProcessDA.GetItemWiseCarFuel(tc, dFromCarFuelMonth, CarFuelItemID, sEmpID);
tc.End();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
return oCarFuelRegisters;
}
public DataSet GetManagersCarFuel(DateTime dtFromCarFuel, DateTime dtToCarFuel, int CarFuelItemID, string sEmpID)
{
DataSet oCarFuelRegisters = new DataSet();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
oCarFuelRegisters = CarFuelProcessDA.GetManagersCarFuel(tc, dtFromCarFuel, dtToCarFuel, CarFuelItemID, sEmpID);
tc.End();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
return oCarFuelRegisters;
}
public DateTime? GetLastPaidCarFuelMonth(int nEmpID)
{
DateTime? dt;
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
dt = CarFuelProcessDA.GetLastPaidCarFuelMonth(tc, nEmpID);
tc.End();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
return dt;
}
#endregion
#region ICarFuelProcessService Members
public ID UpdateOnlyProcess(CarFuelProcess oProcess)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
if (!oProcess.IsNew)
{
CarFuelProcessDA.UpdateProcess(tc, oProcess);
}
tc.End();
return oProcess.ID;
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
}
#endregion
}
#endregion
}