325 lines
10 KiB
C#
325 lines
10 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 Designation Service
|
|||
|
[Serializable]
|
|||
|
public class DesignationService : ServiceTemplate, IDesignationService
|
|||
|
{
|
|||
|
#region Private functions and declaration
|
|||
|
Cache _cache = new Cache(typeof(Designation));
|
|||
|
|
|||
|
#endregion
|
|||
|
public DesignationService() { }
|
|||
|
|
|||
|
private void MapObject(Designation oDesignation, DataReader oReader)
|
|||
|
{
|
|||
|
base.SetObjectID(oDesignation, oReader.GetID("DesignationID"));
|
|||
|
oDesignation.Code = oReader.GetString("Code");
|
|||
|
oDesignation.Name = oReader.GetString("Name");
|
|||
|
oDesignation.GradeID = oReader.GetID("GradeID");
|
|||
|
oDesignation.Sequence = oReader.GetInt32("SequenceNo").Value;
|
|||
|
oDesignation.Status = (EnumStatus)oReader.GetInt32("Status").Value;
|
|||
|
oDesignation.CreatedBy =oReader.GetID("CreatedBy");
|
|||
|
oDesignation.CreatedDate = oReader.GetDateTime("CreationDate")==null?DateTime.Today: oReader.GetDateTime("CreationDate").Value;
|
|||
|
oDesignation.ModifiedBy = oReader.GetID("ModifiedBy");
|
|||
|
oDesignation.ModifiedDate = oReader.GetDateTime("ModifiedDate");
|
|||
|
this.SetObjectState(oDesignation, Ease.CoreV35.ObjectState.Saved);
|
|||
|
}
|
|||
|
protected override T CreateObject<T>(DataReader oReader)
|
|||
|
{
|
|||
|
Designation oDesignation = new Designation();
|
|||
|
MapObject(oDesignation, oReader);
|
|||
|
return oDesignation as T;
|
|||
|
}
|
|||
|
protected Designation CreateObject(DataReader oReader)
|
|||
|
{
|
|||
|
Designation oDesignation = new Designation();
|
|||
|
MapObject(oDesignation, oReader);
|
|||
|
return oDesignation;
|
|||
|
}
|
|||
|
#region Service implementation
|
|||
|
|
|||
|
public string GetNextCode()
|
|||
|
{
|
|||
|
TransactionContext tc = null;
|
|||
|
string _code = "";
|
|||
|
try
|
|||
|
{
|
|||
|
tc = TransactionContext.Begin();
|
|||
|
_code = GlobalFunctionService.GetMaxCode(tc, "designation", "codeautogenerate", "Designation", "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 Designation Get(ID id)
|
|||
|
{
|
|||
|
Designation oDesignation = new Designation();
|
|||
|
#region Cache Header
|
|||
|
oDesignation = _cache["Get", id] as Designation;
|
|||
|
if (oDesignation != null)
|
|||
|
return oDesignation;
|
|||
|
#endregion
|
|||
|
TransactionContext tc = null;
|
|||
|
try
|
|||
|
{
|
|||
|
tc = TransactionContext.Begin();
|
|||
|
DataReader oreader = new DataReader(DesignationDA.Get(tc, id));
|
|||
|
if (oreader.Read())
|
|||
|
{
|
|||
|
oDesignation = this.CreateObject<Designation>(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(oDesignation, "Get", id);
|
|||
|
#endregion
|
|||
|
return oDesignation;
|
|||
|
}
|
|||
|
|
|||
|
public Designation Get(string sCode)
|
|||
|
{
|
|||
|
Designation oDesignation = new Designation();
|
|||
|
#region Cache Header
|
|||
|
oDesignation = _cache["Get", sCode] as Designation;
|
|||
|
if (oDesignation != null)
|
|||
|
return oDesignation;
|
|||
|
#endregion
|
|||
|
TransactionContext tc = null;
|
|||
|
try
|
|||
|
{
|
|||
|
tc = TransactionContext.Begin();
|
|||
|
DataReader oreader = new DataReader(DesignationDA.Get(tc, sCode));
|
|||
|
if (oreader.Read())
|
|||
|
{
|
|||
|
oDesignation = this.CreateObject<Designation>(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(oDesignation, "Get", sCode);
|
|||
|
#endregion
|
|||
|
return oDesignation;
|
|||
|
}
|
|||
|
|
|||
|
public ObjectsTemplate<Designation> Get(EnumStatus status)
|
|||
|
{
|
|||
|
#region Cache Header
|
|||
|
|
|||
|
ObjectsTemplate<Designation> designations = _cache["Get"] as ObjectsTemplate<Designation>;
|
|||
|
if (designations != null)
|
|||
|
return designations;
|
|||
|
|
|||
|
#endregion
|
|||
|
|
|||
|
TransactionContext tc = null;
|
|||
|
try
|
|||
|
{
|
|||
|
tc = TransactionContext.Begin();
|
|||
|
|
|||
|
DataReader dr = new DataReader(DesignationDA.Get(tc, status));
|
|||
|
designations = this.CreateObjects<Designation>(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(designations, "Get",status);
|
|||
|
|
|||
|
#endregion
|
|||
|
|
|||
|
return designations;
|
|||
|
}
|
|||
|
|
|||
|
public ObjectsTemplate<Designation> GetWithSapCodes(EnumStatus status)
|
|||
|
{
|
|||
|
#region Cache Header
|
|||
|
|
|||
|
ObjectsTemplate<Designation> designations = _cache["Get"] as ObjectsTemplate<Designation>;
|
|||
|
if (designations != null)
|
|||
|
return designations;
|
|||
|
|
|||
|
#endregion
|
|||
|
|
|||
|
TransactionContext tc = null;
|
|||
|
try
|
|||
|
{
|
|||
|
tc = TransactionContext.Begin();
|
|||
|
|
|||
|
DataReader dr = new DataReader(DesignationDA.Get(tc, status));
|
|||
|
designations = this.CreateObjects<Designation>(dr);
|
|||
|
dr.Close();
|
|||
|
|
|||
|
foreach (Designation desg in designations)
|
|||
|
{
|
|||
|
desg.SapDesCodes = (new SAPDesignationCodeService()).Get(tc, desg.ID);
|
|||
|
}
|
|||
|
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(designations, "Get", status);
|
|||
|
|
|||
|
#endregion
|
|||
|
|
|||
|
return designations;
|
|||
|
}
|
|||
|
public ID Save(Designation oDesignation)
|
|||
|
{
|
|||
|
TransactionContext tc = null;
|
|||
|
try
|
|||
|
{
|
|||
|
tc = TransactionContext.Begin(true);
|
|||
|
if (oDesignation.IsNew)
|
|||
|
{
|
|||
|
int id = tc.GenerateID("Designation", "DesignationID");
|
|||
|
int seqID = tc.GenerateID("Designation", "SequenceNO");
|
|||
|
base.SetObjectID(oDesignation, ID.FromInteger(id));
|
|||
|
oDesignation.Sequence = seqID;
|
|||
|
DesignationDA.Insert(tc, oDesignation);
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
DesignationDA.Update(tc, oDesignation);
|
|||
|
}
|
|||
|
tc.End();
|
|||
|
return oDesignation.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);
|
|||
|
DesignationDA.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<Designation> designations)
|
|||
|
{
|
|||
|
try
|
|||
|
{
|
|||
|
foreach (Designation oDesignation in designations)
|
|||
|
{
|
|||
|
if (oDesignation.IsNew)
|
|||
|
{
|
|||
|
int seqNo = tc.GenerateID("Designation", "SequenceNO");
|
|||
|
oDesignation.Sequence = seqNo;
|
|||
|
|
|||
|
bool isAutoGenerated = ConfigurationManager.GetBoolValue("designation", "codeautogenerate", EnumConfigurationType.Logic);
|
|||
|
if (isAutoGenerated == true)
|
|||
|
oDesignation.Code = GlobalFunctionService.GetMaxCode(tc, "designation", "codeautogenerate", "Designation", "Code");
|
|||
|
|
|||
|
oDesignation.CreatedBy = User.CurrentUser.ID;
|
|||
|
oDesignation.CreatedDate = DateTime.Now;
|
|||
|
DesignationDA.Insert(tc, oDesignation);
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
oDesignation.ModifiedBy = User.CurrentUser.ID;
|
|||
|
oDesignation.ModifiedDate = DateTime.Now;
|
|||
|
DesignationDA.Update(tc, oDesignation);
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
catch (Exception e)
|
|||
|
{
|
|||
|
#region Handle Exception
|
|||
|
if (tc != null)
|
|||
|
tc.HandleError();
|
|||
|
ExceptionLog.Write(e);
|
|||
|
throw new ServiceException(e.Message, e);
|
|||
|
#endregion
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
#endregion
|
|||
|
}
|