234 lines
8.1 KiB
C#
234 lines
8.1 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 CarFuelPayment Service
|
|
[Serializable]
|
|
public class CarFuelPaymentService : ServiceTemplate, ICarFuelPaymentService
|
|
{
|
|
#region Private functions and declaration
|
|
Cache _cache = new Cache(typeof(CarFuelPayment));
|
|
|
|
public CarFuelPaymentService() { }
|
|
|
|
private void MapObject(CarFuelPayment oCarFuelPayment, DataReader oReader)
|
|
{
|
|
base.SetObjectID(oCarFuelPayment, oReader.GetID("CarFuelPaymentID"));
|
|
oCarFuelPayment.CarFuelItemID = oReader.GetID("CarFuelItemID");
|
|
oCarFuelPayment.EmployeeID = oReader.GetID("EmployeeID");
|
|
oCarFuelPayment.PaymentDate = oReader.GetDateTime("PaymentDate").Value;
|
|
oCarFuelPayment.Amount = oReader.GetDouble("Amount").Value;
|
|
oCarFuelPayment.TaxAmount = oReader.GetDouble("TaxAmount").Value;
|
|
oCarFuelPayment.Remarks = oReader.GetString("Remarks");
|
|
oCarFuelPayment.CreatedBy = oReader.GetID("CreatedBy");
|
|
oCarFuelPayment.CreatedDate = oReader.GetDateTime("CreationDate").Value;
|
|
oCarFuelPayment.ModifiedBy = oReader.GetID("ModifiedBy");
|
|
oCarFuelPayment.ModifiedDate = oReader.GetDateTime("ModifiedDate");
|
|
this.SetObjectState(oCarFuelPayment, Ease.CoreV35.ObjectState.Saved);
|
|
}
|
|
protected override T CreateObject<T>(DataReader oReader)
|
|
{
|
|
CarFuelPayment oCarFuelPayment = new CarFuelPayment();
|
|
MapObject(oCarFuelPayment, oReader);
|
|
return oCarFuelPayment as T;
|
|
}
|
|
protected CarFuelPayment CreateObject(DataReader oReader)
|
|
{
|
|
CarFuelPayment oCarFuelPayment = new CarFuelPayment();
|
|
MapObject(oCarFuelPayment, oReader);
|
|
return oCarFuelPayment;
|
|
}
|
|
#endregion
|
|
|
|
#region Service implementation
|
|
public CarFuelPayment Get(ID id)
|
|
{
|
|
CarFuelPayment oCarFuelPayment = new CarFuelPayment();
|
|
#region Cache Header
|
|
oCarFuelPayment = (CarFuelPayment)_cache["Get", id] as CarFuelPayment;
|
|
if (oCarFuelPayment != null)
|
|
return oCarFuelPayment;
|
|
#endregion
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin();
|
|
DataReader oReader = new DataReader(CarFuelPaymentDA.Get(tc, id));
|
|
if (oReader.Read())
|
|
{
|
|
oCarFuelPayment = 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(oCarFuelPayment, "Get", id);
|
|
#endregion
|
|
return oCarFuelPayment;
|
|
}
|
|
|
|
public string GetNextCode()
|
|
{
|
|
TransactionContext tc = null;
|
|
string _code = "";
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin();
|
|
_code = GlobalFunctionService.GetMaxCode(tc, "CarFuelpaymentitem", "codeautogenerate", "CarFuelPayment", "Code");
|
|
tc.End();
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
#region Handle Exception
|
|
if (tc != null)
|
|
tc.HandleError();
|
|
ExceptionLog.Write(e);
|
|
throw new ServiceException(e.Message, e);
|
|
#endregion
|
|
}
|
|
return _code;
|
|
}
|
|
public ObjectsTemplate<CarFuelPayment> Get()
|
|
{
|
|
#region Cache Header
|
|
ObjectsTemplate<CarFuelPayment> oCarFuelPayments = _cache["Get"] as ObjectsTemplate<CarFuelPayment>;
|
|
if (oCarFuelPayments != null)
|
|
return oCarFuelPayments;
|
|
#endregion
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin();
|
|
DataReader oreader = new DataReader(CarFuelPaymentDA.Get(tc));
|
|
oCarFuelPayments = this.CreateObjects<CarFuelPayment>(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(oCarFuelPayments, "Get");
|
|
#endregion
|
|
return oCarFuelPayments;
|
|
}
|
|
public DataSet GetDataSetOfPaymentEmployees(ID nCarFuelItemID, EnumCarFuelType nCarFuelType)
|
|
{
|
|
DataSet dsEmployees = new DataSet();
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin(true);
|
|
dsEmployees = CarFuelPaymentDA.GetDataSetOfPaymentEmployees(tc, nCarFuelItemID, nCarFuelType);
|
|
tc.End();
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
throw new ServiceException("Failed to Get Employee ", e);
|
|
}
|
|
|
|
return dsEmployees;
|
|
}
|
|
|
|
public ID Save(CarFuelPayment oCarFuelPayment)
|
|
{
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin(true);
|
|
if (oCarFuelPayment.IsNew)
|
|
{
|
|
int id = tc.GenerateID("CarFuelPayment", "CarFuelPaymentID");
|
|
base.SetObjectID(oCarFuelPayment, ID.FromInteger(id));
|
|
CarFuelPaymentDA.Insert(tc, oCarFuelPayment);
|
|
}
|
|
else
|
|
{
|
|
CarFuelPaymentDA.Update(tc, oCarFuelPayment);
|
|
}
|
|
tc.End();
|
|
return oCarFuelPayment.ID;
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
#region Handle Exception
|
|
if (tc != null)
|
|
tc.HandleError();
|
|
ExceptionLog.Write(e);
|
|
throw new ServiceException(e.Message, e);
|
|
#endregion
|
|
}
|
|
}
|
|
public void Save(ObjectsTemplate<CarFuelPayment> CarFuelPayments)
|
|
{
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin(true);
|
|
foreach (CarFuelPayment oPayment in CarFuelPayments)
|
|
{
|
|
int id = tc.GenerateID("CarFuelPayment", "CarFuelPaymentID");
|
|
base.SetObjectID(oPayment, ID.FromInteger(id));
|
|
oPayment.CreatedBy = User.CurrentUser.ID;
|
|
oPayment.CreatedDate = DateTime.Now;
|
|
CarFuelPaymentDA.Insert(tc, oPayment);
|
|
}
|
|
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)
|
|
{
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin(true);
|
|
CarFuelPaymentDA.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
|
|
}
|
|
#endregion
|
|
}
|