275 lines
8.8 KiB
C#
275 lines
8.8 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 FSHead Service
|
|
[Serializable]
|
|
public class FSHeadService : ServiceTemplate, IFSHeadService
|
|
{
|
|
#region Private functions and declaration
|
|
Cache _cache = new Cache(typeof(FSHead));
|
|
|
|
#endregion
|
|
public FSHeadService() { }
|
|
|
|
private void MapObject(FSHead oFSHead, DataReader oReader)
|
|
{
|
|
base.SetObjectID(oFSHead, oReader.GetID("FSHeadID"));
|
|
oFSHead.Code = oReader.GetString("Code");
|
|
oFSHead.Name = oReader.GetString("Name");
|
|
oFSHead.IsTaxable = oReader.GetBoolean("IsTaxable").Value;
|
|
oFSHead.Sequence = oReader.GetInt32("SequenceNO").Value;
|
|
oFSHead.Status = (EnumStatus)oReader.GetInt32("Status").Value;
|
|
oFSHead.CreatedBy = oReader.GetID("CreatedBy");
|
|
oFSHead.CreatedDate = oReader.GetDateTime("CreationDate").Value;
|
|
oFSHead.ModifiedBy = oReader.GetID("ModifiedBy");
|
|
oFSHead.ModifiedDate = oReader.GetDateTime("ModifiedDate");
|
|
oFSHead.IsLoan =oReader.GetBoolean("IsLoan").HasValue?oReader.GetBoolean("IsLoan").Value:false;
|
|
oFSHead.IsPaymenttoVendor = oReader.GetBoolean("IsPaymenttoVendor").HasValue ? oReader.GetBoolean("IsPaymenttoVendor").Value : false;
|
|
oFSHead.Remarks = oReader.GetString("Remarks");
|
|
this.SetObjectState(oFSHead, Ease.CoreV35.ObjectState.Saved);
|
|
}
|
|
protected override T CreateObject<T>(DataReader oReader)
|
|
{
|
|
FSHead oFSHead = new FSHead();
|
|
MapObject(oFSHead, oReader);
|
|
return oFSHead as T;
|
|
}
|
|
protected FSHead CreateObject(DataReader oReader)
|
|
{
|
|
FSHead oFSHead = new FSHead();
|
|
MapObject(oFSHead, oReader);
|
|
return oFSHead;
|
|
}
|
|
#region Service implementation
|
|
public FSHead Get(ID id)
|
|
{
|
|
FSHead oFSHead = new FSHead();
|
|
#region Cache Header
|
|
oFSHead = _cache["Get", id] as FSHead;
|
|
if (oFSHead != null)
|
|
return oFSHead;
|
|
#endregion
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin();
|
|
DataReader oreader = new DataReader(FSHeadDA.Get(tc, id));
|
|
if (oreader.Read())
|
|
{
|
|
oFSHead = this.CreateObject<FSHead>(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(oFSHead, "Get", id);
|
|
#endregion
|
|
return oFSHead;
|
|
}
|
|
|
|
public string GetNextCode()
|
|
{
|
|
TransactionContext tc = null;
|
|
string _code = "";
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin();
|
|
_code = GlobalFunctionService.GetMaxCode(tc, "fshead", "codeautogenerate", "FSHead", "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<FSHead> Get()
|
|
{
|
|
#region Cache Header
|
|
ObjectsTemplate<FSHead> FSHeads = _cache["Get"] as ObjectsTemplate<FSHead>;
|
|
if (FSHeads != null)
|
|
return FSHeads;
|
|
#endregion
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin();
|
|
DataReader dr = new DataReader(FSHeadDA.Get(tc));
|
|
FSHeads = this.CreateObjects<FSHead>(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(FSHeads, "Get");
|
|
#endregion
|
|
return FSHeads;
|
|
}
|
|
|
|
public ObjectsTemplate<FSHead> Get(EnumStatus status)
|
|
{
|
|
#region Cache Header
|
|
|
|
ObjectsTemplate<FSHead> FSHeads = _cache["Get", status] as ObjectsTemplate<FSHead>;
|
|
if (FSHeads != null)
|
|
return FSHeads;
|
|
|
|
#endregion
|
|
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin();
|
|
|
|
DataReader dr = new DataReader(FSHeadDA.Get(tc, status));
|
|
FSHeads = this.CreateObjects<FSHead>(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(FSHeads, "Get", status);
|
|
|
|
#endregion
|
|
|
|
return FSHeads;
|
|
}
|
|
|
|
public ID Save(FSHead oFSHead)
|
|
{
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin(true);
|
|
if (oFSHead.IsNew)
|
|
{
|
|
int id = tc.GenerateID("FSHead", "FSHeadID");
|
|
base.SetObjectID(oFSHead, ID.FromInteger(id));
|
|
int seqNo = tc.GenerateID("FSHead", "SequenceNO");
|
|
oFSHead.Sequence = seqNo;
|
|
FSHeadDA.Insert(tc, oFSHead);
|
|
}
|
|
else
|
|
{
|
|
FSHeadDA.Update(tc, oFSHead);
|
|
}
|
|
tc.End();
|
|
return oFSHead.ID;
|
|
}
|
|
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);
|
|
FSHeadDA.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
|
|
|
|
//for Excel Upload
|
|
public static void SaveForUpload(TransactionContext tc, ObjectsTemplate<FSHead> FSHeads)
|
|
{
|
|
try
|
|
{
|
|
foreach (FSHead oFSHead in FSHeads)
|
|
{
|
|
if (oFSHead.IsNew)
|
|
{
|
|
int seqNo = tc.GenerateID("FSHeads", "SequenceNO");
|
|
oFSHead.Sequence = seqNo;
|
|
bool isAutoGenerated = ConfigurationManager.GetBoolValue("FSHead", "codeautogenerate", EnumConfigurationType.Logic);
|
|
if (isAutoGenerated == true)
|
|
oFSHead.Code = GlobalFunctionService.GetMaxCode(tc, "FSHead", "codeautogenerate", "FSHead", "Code");
|
|
|
|
oFSHead.CreatedBy = User.CurrentUser.ID;
|
|
oFSHead.CreatedDate = DateTime.Now;
|
|
FSHeadDA.Insert(tc, oFSHead);
|
|
}
|
|
else
|
|
{
|
|
FSHeadDA.Update(tc, oFSHead);
|
|
}
|
|
}
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
#region Handle Exception
|
|
if (tc != null)
|
|
tc.HandleError();
|
|
ExceptionLog.Write(e);
|
|
throw new ServiceException(e.Message, e);
|
|
#endregion
|
|
}
|
|
}
|
|
}
|
|
#endregion
|
|
}
|