CEL_Payroll/Payroll.Service/Attendence/Service/CardOperationService.cs

355 lines
12 KiB
C#
Raw Normal View History

2024-09-17 14:30:13 +06:00
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Ease.CoreV35.Model;
using Payroll.BO;
using Ease.CoreV35.Caching;
using Payroll.Service.Attendence.DA;
using Ease.CoreV35.DataAccess;
using Payroll.BO;
namespace Payroll.Service.Attendence.Service
{
#region CardOperation Service
[Serializable]
public class CardOperationService : ServiceTemplate, ICardOperationService
{
#region Private functions and declaration
Cache _cache = new Cache(typeof(CardOperation));
#endregion
public CardOperationService() { }
private void MapObject(CardOperation oCardOperation, DataReader oReader)
{
base.SetObjectID(oCardOperation, oReader.GetID("CardOperationID"));
oCardOperation.CardID = oReader.GetID("CardID");
oCardOperation.CardNumber = oReader.GetString("CardNumber");
oCardOperation.Status = (EnumCardStatus)oReader.GetInt32("CardStatus").Value;
oCardOperation.EmployeeID = oReader.GetID("EmployeeID");
oCardOperation.Comments = oReader.GetString("Comments");
oCardOperation.AssignDate = oReader.GetDateTime("AssignDate").Value;
oCardOperation.CreatedBy = oReader.GetID("CreatedBy");
oCardOperation.CreatedDate = oReader.GetDateTime("CreatedDate").Value;
oCardOperation.ModifiedBy = oReader.GetID("ModifiedBy");
oCardOperation.ModifiedDate = oReader.GetDateTime("ModifiedDate");
this.SetObjectState(oCardOperation, Ease.CoreV35.ObjectState.Saved);
}
protected override T CreateObject<T>(DataReader oReader)
{
CardOperation oCardOperation = new CardOperation();
MapObject(oCardOperation, oReader);
return oCardOperation as T;
}
protected CardOperation CreateObject(DataReader oReader)
{
CardOperation oCardOperation = new CardOperation();
MapObject(oCardOperation, oReader);
return oCardOperation;
}
#region Service implementation
public CardOperation Get(ID id)
{
CardOperation oCardOperation = new CardOperation();
#region Cache Header
oCardOperation = _cache["Get", id] as CardOperation;
if (oCardOperation != null)
return oCardOperation;
#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader oreader = new DataReader(CardOperationDA.Get(tc, id));
if (oreader.Read())
{
oCardOperation = this.CreateObject<CardOperation>(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(oCardOperation, "Get", id);
#endregion
return oCardOperation;
}
public CardOperation GetByCardID(ID id)
{
CardOperation oCardOperation = new CardOperation();
#region Cache Header
oCardOperation = _cache["GetByCardID", id] as CardOperation;
if (oCardOperation != null)
return oCardOperation;
#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader oreader = new DataReader(CardOperationDA.GetByCardID(tc, id));
if (oreader.Read())
{
oCardOperation = this.CreateObject<CardOperation>(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(oCardOperation, "GetByCardID", id);
#endregion
return oCardOperation;
}
public CardOperation GetByEmpIDAndCardID(ID EmpID, ID CardID)
{
CardOperation oCardOperation = new CardOperation();
#region Cache Header
oCardOperation = _cache["GetByEmpIDAndCardID", EmpID, CardID] as CardOperation;
if (oCardOperation != null)
return oCardOperation;
#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader oreader = new DataReader(CardOperationDA.GetByEmpIDAndCardID(tc, EmpID.Integer, CardID.Integer));
if (oreader.Read())
{
oCardOperation = this.CreateObject<CardOperation>(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(oCardOperation, "GetByEmpIDAndCardID", EmpID, CardID);
#endregion
return oCardOperation;
}
public CardOperation Get(string CardNumber)
{
CardOperation oCardOperation = new CardOperation();
#region Cache Header
oCardOperation = _cache["Get", CardNumber] as CardOperation;
if (oCardOperation != null)
return oCardOperation;
#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader oreader = new DataReader(CardOperationDA.Get(tc, CardNumber));
if (oreader.Read())
{
oCardOperation = this.CreateObject<CardOperation>(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(oCardOperation, "Get", CardNumber);
#endregion
return oCardOperation;
}
public ObjectsTemplate<CardOperation> Get()
{
#region Cache Header
ObjectsTemplate<CardOperation> cardOperations = _cache["Get"] as ObjectsTemplate<CardOperation>;
if (cardOperations != null)
return cardOperations;
#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(CardOperationDA.Get(tc));
cardOperations = this.CreateObjects<CardOperation>(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(cardOperations, "Get");
#endregion
return cardOperations;
}
public ID Save(CardOperation oCardOperation)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
if (oCardOperation.IsNew)
{
int id = tc.GenerateID("CardOperation", "CardOperationID");
base.SetObjectID(oCardOperation, ID.FromInteger(id));
CardOperationDA.Insert(tc, oCardOperation);
}
else
{
CardOperationDA.Update(tc, oCardOperation);
}
tc.End();
return oCardOperation.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<CardOperation> ocardOperations)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
AccessCardService ac = new AccessCardService();
EmployeeService emp = new EmployeeService();
foreach (CardOperation CardOP in ocardOperations)
{
if (CardOP.IsNew)
{
int id = tc.GenerateID("CardOperation", "CardOperationID");
base.SetObjectID(CardOP, ID.FromInteger(id));
CardOperationDA.Insert(tc, CardOP);
ac.UpdateStatus(tc, CardOP.CardID, CardOP.Status);
emp.UpdateCardInformation(tc, CardOP.EmployeeID, CardOP.CardID, true);
}
else
{
CardOperationDA.Update(tc, CardOP);
ac.UpdateStatus(tc, CardOP.CardID, CardOP.Status);
emp.UpdateCardInformation(tc, CardOP.EmployeeID, CardOP.CardID, true);
}
}
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);
CardOperationDA.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
}
}
//for Excel Upload
public void Save(TransactionContext tc, ObjectsTemplate<CardOperation> ocardOperations)
{
try
{
EmployeeService emp = new EmployeeService();
foreach (CardOperation CardOP in ocardOperations)
{
if (CardOP.IsNew)
{
int id = tc.GenerateID("CardOperation", "CardOperationID");
base.SetObjectID(CardOP, ID.FromInteger(id));
//Payroll.BO.AuditTrailBase audit = new Payroll.BO.AuditTrailBase();
CardOP.CreatedBy = User.CurrentUser.ID;
CardOP.CreatedDate = DateTime.Now;
CardOperationDA.Insert(tc, CardOP);
emp.UpdateCardInformation(tc, CardOP.EmployeeID, CardOP.CardID, true);
}
else
{
CardOperationDA.Update(tc, CardOP);
emp.UpdateCardInformation(tc, CardOP.EmployeeID, CardOP.CardID, true);
}
}
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
}
//
#endregion
}
#endregion
}