307 lines
9.1 KiB
C#
307 lines
9.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
|
|||
|
{
|
|||
|
[Serializable]
|
|||
|
public class CapitalizationService : ServiceTemplate, ICapitalizationService
|
|||
|
{
|
|||
|
#region Private functions and declaration
|
|||
|
Cache _cache = new Cache(typeof(Capitalization));
|
|||
|
|
|||
|
#endregion
|
|||
|
public CapitalizationService() { }
|
|||
|
|
|||
|
private void MapObject(Capitalization oCapitalization, DataReader oReader)
|
|||
|
{
|
|||
|
base.SetObjectID(oCapitalization, oReader.GetID("CapitalizationID"));
|
|||
|
oCapitalization.SalaryMonth = oReader.GetDateTime("SalaryMonth").Value;
|
|||
|
oCapitalization.DepartmentID = oReader.GetID("DepartmentID");
|
|||
|
oCapitalization.Percent = oReader.GetDouble("Percentage").Value;
|
|||
|
oCapitalization.CreatedBy = oReader.GetID("CreatedBy");
|
|||
|
oCapitalization.CreatedDate = oReader.GetDateTime("CreationDate").Value;
|
|||
|
oCapitalization.ModifiedBy = oReader.GetID("ModifiedBy");
|
|||
|
oCapitalization.ModifiedDate = oReader.GetDateTime("ModifiedDate");
|
|||
|
this.SetObjectState(oCapitalization, Ease.CoreV35.ObjectState.Saved);
|
|||
|
}
|
|||
|
protected override T CreateObject<T>(DataReader oReader)
|
|||
|
{
|
|||
|
Capitalization oCapitalization = new Capitalization();
|
|||
|
MapObject(oCapitalization, oReader);
|
|||
|
return oCapitalization as T;
|
|||
|
}
|
|||
|
protected Capitalization CreateObject(DataReader oReader)
|
|||
|
{
|
|||
|
Capitalization oCapitalization = new Capitalization();
|
|||
|
MapObject(oCapitalization, oReader);
|
|||
|
return oCapitalization;
|
|||
|
}
|
|||
|
|
|||
|
#region Service implementation
|
|||
|
|
|||
|
|
|||
|
public Capitalization Get(ID id, DateTime salaryMonth)
|
|||
|
{
|
|||
|
Capitalization oCapitalization = new Capitalization();
|
|||
|
#region Cache Header
|
|||
|
oCapitalization = _cache["Get", id] as Capitalization;
|
|||
|
if (oCapitalization != null)
|
|||
|
return oCapitalization;
|
|||
|
#endregion
|
|||
|
TransactionContext tc = null;
|
|||
|
try
|
|||
|
{
|
|||
|
tc = TransactionContext.Begin();
|
|||
|
DataReader oreader = new DataReader(CapitalizationDA.Get(tc, id));
|
|||
|
if (oreader.Read())
|
|||
|
{
|
|||
|
oCapitalization = this.CreateObject<Capitalization>(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(oCapitalization, "Get", id);
|
|||
|
#endregion
|
|||
|
return oCapitalization;
|
|||
|
}
|
|||
|
|
|||
|
public ObjectsTemplate<Capitalization> Get()
|
|||
|
{
|
|||
|
#region Cache Header
|
|||
|
|
|||
|
ObjectsTemplate<Capitalization> oCapitalizations = _cache["Get"] as ObjectsTemplate<Capitalization>;
|
|||
|
if (oCapitalizations != null)
|
|||
|
return oCapitalizations;
|
|||
|
|
|||
|
#endregion
|
|||
|
|
|||
|
TransactionContext tc = null;
|
|||
|
try
|
|||
|
{
|
|||
|
tc = TransactionContext.Begin();
|
|||
|
|
|||
|
DataReader dr = new DataReader(CapitalizationDA.Get(tc));
|
|||
|
oCapitalizations = this.CreateObjects<Capitalization>(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(oCapitalizations, "Get");
|
|||
|
|
|||
|
#endregion
|
|||
|
|
|||
|
return oCapitalizations;
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
public ObjectsTemplate<Capitalization> Get(ID departmentID)
|
|||
|
{
|
|||
|
#region Cache Header
|
|||
|
|
|||
|
ObjectsTemplate<Capitalization> oCapitalizations = _cache["Get", departmentID] as ObjectsTemplate<Capitalization>;
|
|||
|
if (oCapitalizations != null)
|
|||
|
return oCapitalizations;
|
|||
|
|
|||
|
#endregion
|
|||
|
|
|||
|
TransactionContext tc = null;
|
|||
|
try
|
|||
|
{
|
|||
|
tc = TransactionContext.Begin();
|
|||
|
|
|||
|
DataReader dr = new DataReader(CapitalizationDA.Get(tc, departmentID));
|
|||
|
oCapitalizations = this.CreateObjects<Capitalization>(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(oCapitalizations, "Get", departmentID);
|
|||
|
|
|||
|
#endregion
|
|||
|
|
|||
|
return oCapitalizations;
|
|||
|
}
|
|||
|
|
|||
|
public ObjectsTemplate<Capitalization> Get(DateTime salaryMonth)
|
|||
|
{
|
|||
|
#region Cache Header
|
|||
|
|
|||
|
ObjectsTemplate<Capitalization> oCapitalizations = _cache["Get", salaryMonth] as ObjectsTemplate<Capitalization>;
|
|||
|
if (oCapitalizations != null)
|
|||
|
return oCapitalizations;
|
|||
|
|
|||
|
#endregion
|
|||
|
|
|||
|
TransactionContext tc = null;
|
|||
|
try
|
|||
|
{
|
|||
|
tc = TransactionContext.Begin();
|
|||
|
|
|||
|
DataReader dr = new DataReader(CapitalizationDA.Get(tc, salaryMonth));
|
|||
|
oCapitalizations = this.CreateObjects<Capitalization>(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(oCapitalizations, "Get", salaryMonth);
|
|||
|
|
|||
|
#endregion
|
|||
|
|
|||
|
return oCapitalizations;
|
|||
|
}
|
|||
|
|
|||
|
public DateTime? GetMaxDate()
|
|||
|
{
|
|||
|
TransactionContext tc = null;
|
|||
|
DateTime? maxDate = null;
|
|||
|
try
|
|||
|
{
|
|||
|
tc = TransactionContext.Begin(true);
|
|||
|
DataReader dr = new DataReader(CapitalizationDA.GetMaxDate(tc));
|
|||
|
if (dr.Read())
|
|||
|
{
|
|||
|
maxDate = dr.GetDateTime("MaximumSalaryMonth") == null ? DateTime.MinValue : dr.GetDateTime("MaximumSalaryMonth");
|
|||
|
}
|
|||
|
}
|
|||
|
catch (Exception e)
|
|||
|
{
|
|||
|
#region Handle Exception
|
|||
|
|
|||
|
if (tc != null)
|
|||
|
tc.HandleError();
|
|||
|
ExceptionLog.Write(e);
|
|||
|
|
|||
|
throw new ServiceException(e.Message, e);
|
|||
|
|
|||
|
#endregion
|
|||
|
}
|
|||
|
|
|||
|
return maxDate;
|
|||
|
}
|
|||
|
|
|||
|
public void Save(ObjectsTemplate<Capitalization> oCapitalizations)
|
|||
|
{
|
|||
|
TransactionContext tc = null;
|
|||
|
try
|
|||
|
{
|
|||
|
tc = TransactionContext.Begin(true);
|
|||
|
int id = tc.GenerateID("Capitalization", "CapitalizationID");
|
|||
|
foreach (Capitalization capital in oCapitalizations)
|
|||
|
{
|
|||
|
|
|||
|
base.SetObjectID(capital, ID.FromInteger(id));
|
|||
|
if (CapitalizationDA.IsExist(tc, capital.DepartmentID, capital.SalaryMonth))
|
|||
|
{
|
|||
|
CapitalizationDA.Delete(tc, capital.DepartmentID);
|
|||
|
//capital.ModifiedBy = User.CurrentUser.ID;
|
|||
|
//capital.ModifiedDate = DateTime.Today;
|
|||
|
CapitalizationDA.Insert(tc, capital);
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
CapitalizationDA.Insert(tc, capital);
|
|||
|
|
|||
|
}
|
|||
|
id++;
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
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 deptID)
|
|||
|
{
|
|||
|
TransactionContext tc = null;
|
|||
|
try
|
|||
|
{
|
|||
|
tc = TransactionContext.Begin(true);
|
|||
|
CapitalizationDA.Delete(tc, deptID);
|
|||
|
tc.End();
|
|||
|
}
|
|||
|
catch (Exception e)
|
|||
|
{
|
|||
|
#region Handle Exception
|
|||
|
if (tc != null)
|
|||
|
tc.HandleError();
|
|||
|
ExceptionLog.Write(e);
|
|||
|
throw new ServiceException(e.Message, e);
|
|||
|
#endregion
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
#endregion
|
|||
|
}
|
|||
|
}
|