291 lines
8.6 KiB
C#
291 lines
8.6 KiB
C#
|
using System;
|
|||
|
using System.Data;
|
|||
|
using Ease.Core.Model;
|
|||
|
using Ease.Core.DataAccess;
|
|||
|
using Ease.Core;
|
|||
|
using System.Collections.Generic;
|
|||
|
using Ease.Core.Utility;
|
|||
|
using HRM.BO;
|
|||
|
using HRM.DA;
|
|||
|
|
|||
|
namespace HRM.DA
|
|||
|
{
|
|||
|
#region FSHead Service
|
|||
|
|
|||
|
public class FSHeadService : ServiceTemplate, IFSHeadService
|
|||
|
{
|
|||
|
#region Private functions and declaration
|
|||
|
|
|||
|
#endregion
|
|||
|
|
|||
|
public FSHeadService()
|
|||
|
{
|
|||
|
}
|
|||
|
|
|||
|
private void MapObject(FSHead oFSHead, DataReader oReader)
|
|||
|
{
|
|||
|
base.SetObjectID(oFSHead, (oReader.GetInt32("FSHeadID").Value));
|
|||
|
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.GetInt32("CreatedBy", 0);
|
|||
|
oFSHead.CreatedDate = oReader.GetDateTime("CREATIONDATE").HasValue
|
|||
|
? oReader.GetDateTime("CREATIONDATE").Value
|
|||
|
: DateTime.MinValue;
|
|||
|
oFSHead.ModifiedBy = oReader.GetInt32("ModifiedBy", 0);
|
|||
|
oFSHead.ModifiedDate = oReader.GetDateTime("ModifiedDate").HasValue
|
|||
|
? oReader.GetDateTime("ModifiedDate").Value
|
|||
|
: (DateTime?)null;
|
|||
|
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");
|
|||
|
oFSHead.IsFinal = oReader.GetBoolean("IsFinal").HasValue ? oReader.GetBoolean("IsFinal").Value : false;
|
|||
|
oFSHead.Type = (EnumFSItemCode)oReader.GetInt16("Type").Value;
|
|||
|
oFSHead.EmpID = oReader.GetInt32("EMPID", 0);
|
|||
|
oFSHead.EmpIDTwo = oReader.GetInt32("EMPIDTwo", 0);
|
|||
|
this.SetObjectState(oFSHead, Ease.Core.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(int id)
|
|||
|
{
|
|||
|
FSHead oFSHead = new FSHead();
|
|||
|
|
|||
|
|
|||
|
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
|
|||
|
}
|
|||
|
|
|||
|
return oFSHead;
|
|||
|
}
|
|||
|
|
|||
|
public List<FSHead> Get()
|
|||
|
{
|
|||
|
List<FSHead> FSHeads = new List<FSHead>();
|
|||
|
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
|
|||
|
}
|
|||
|
|
|||
|
return FSHeads;
|
|||
|
}
|
|||
|
|
|||
|
public List<FSHead> Get(EnumStatus status)
|
|||
|
{
|
|||
|
List<FSHead> FSHeads = new List<FSHead>();
|
|||
|
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
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
return FSHeads;
|
|||
|
}
|
|||
|
|
|||
|
public int Save(FSHead oFSHead)
|
|||
|
{
|
|||
|
TransactionContext tc = null;
|
|||
|
try
|
|||
|
{
|
|||
|
tc = TransactionContext.Begin(true);
|
|||
|
if (oFSHead.IsNew)
|
|||
|
{
|
|||
|
int id = tc.GenerateID("FSHead", "FSHeadID");
|
|||
|
base.SetObjectID(oFSHead, (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(int 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, List<FSHead> FSHeads)
|
|||
|
{
|
|||
|
try
|
|||
|
{
|
|||
|
foreach (FSHead oFSHead in FSHeads)
|
|||
|
{
|
|||
|
if (oFSHead.IsNew)
|
|||
|
{
|
|||
|
int seqNo = tc.GenerateID("FSHeads", "SequenceNO");
|
|||
|
oFSHead.Sequence = seqNo;
|
|||
|
bool isAutoGenerated = new SystemConfigarationService().GetconfigBooleanValue(EnumConfigurationType.Logic, "FSHead", "codeautogenerate");
|
|||
|
if (isAutoGenerated == true)
|
|||
|
//#### oFSHead.Code = GlobalFunctionService.GetMaxCode(tc, "FSHead", "codeautogenerate", "FSHead", "Code");
|
|||
|
|
|||
|
oFSHead.CreatedBy = oFSHead.CreatedBy;
|
|||
|
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
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
public List<FSHead> GetByEmpId(int currentEmployeeId)
|
|||
|
{
|
|||
|
List<FSHead> FSHeads = new List<FSHead>();
|
|||
|
TransactionContext tc = null;
|
|||
|
try
|
|||
|
{
|
|||
|
tc = TransactionContext.Begin();
|
|||
|
|
|||
|
DataReader dr = new DataReader(FSHeadDA.GetByEmpId(tc, currentEmployeeId));
|
|||
|
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
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
return FSHeads;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
#endregion
|
|||
|
}
|