340 lines
11 KiB
C#
340 lines
11 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;
|
|||
|
|
|||
|
namespace HRM.DA
|
|||
|
{
|
|||
|
public class ObjectiveCategoryService : ServiceTemplate, IObjectiveCategoryService
|
|||
|
{
|
|||
|
#region Object Mapping
|
|||
|
|
|||
|
private void MapObject(ObjectiveCategory oObjectiveCategory, DataReader oReader)
|
|||
|
{
|
|||
|
base.SetObjectID(oObjectiveCategory, oReader.GetInt32("ObjectiveCategoryID", 0));
|
|||
|
oObjectiveCategory.Description = oReader.GetString("Description");
|
|||
|
oObjectiveCategory.Category = (EnumObjectiveCategory)oReader.GetInt32("Category").Value;
|
|||
|
oObjectiveCategory.PMPYearID = oReader.GetInt32("PMPYearID", 0);
|
|||
|
oObjectiveCategory.ObjectiveTypeID = oReader.GetInt32("ObjectiveTypeID", 0);
|
|||
|
oObjectiveCategory.CreatedBy = oReader.GetInt32("CreatedBy", 0);
|
|||
|
oObjectiveCategory.CreatedDate = oReader.GetDateTime("CreatedDate").HasValue
|
|||
|
? oReader.GetDateTime("CreatedDate").Value
|
|||
|
: DateTime.MinValue;
|
|||
|
oObjectiveCategory.ModifiedBy = oReader.GetInt32("ModifiedBy", 0);
|
|||
|
oObjectiveCategory.ModifiedDate = oReader.GetDateTime("ModifiedDate").HasValue
|
|||
|
? oReader.GetDateTime("ModifiedDate").Value
|
|||
|
: (DateTime?)null;
|
|||
|
oObjectiveCategory.Status = (EnumStatus)oReader.GetInt32("Status").Value;
|
|||
|
|
|||
|
this.SetObjectState(oObjectiveCategory, ObjectState.Saved);
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
protected override T CreateObject<T>(DataReader oReader)
|
|||
|
{
|
|||
|
ObjectiveCategory oObjectiveCategory = new ObjectiveCategory();
|
|||
|
MapObject(oObjectiveCategory, oReader);
|
|||
|
return oObjectiveCategory as T;
|
|||
|
}
|
|||
|
|
|||
|
private void MapObjectiveCategoryGradesObject(ObjectiveCategoryGrades oObjectiveCategoryGrades,
|
|||
|
DataReader oReader)
|
|||
|
{
|
|||
|
SetObjectID(oObjectiveCategoryGrades, oReader.GetInt32("ObjectiveCategoryGradesID", 0));
|
|||
|
oObjectiveCategoryGrades.ObjectiveType = oReader.GetInt32("ObjectiveType", 0);
|
|||
|
oObjectiveCategoryGrades.ObjectiveCategoryID = oReader.GetInt32("ObjectiveCategoryID", 0);
|
|||
|
oObjectiveCategoryGrades.GradeID = oReader.GetInt32("GradeID", 0);
|
|||
|
oObjectiveCategoryGrades.Percent =
|
|||
|
oReader.GetDouble("Percent").Value == 0.0 ? 0.0 : oReader.GetDouble("Percent").Value;
|
|||
|
oObjectiveCategoryGrades.OBMOSRequired = oReader.GetBoolean("OBMOSRequired").Value;
|
|||
|
oObjectiveCategoryGrades.DPMOSRequired = oReader.GetBoolean("DPMOSRequired").Value;
|
|||
|
this.SetObjectState(oObjectiveCategoryGrades, ObjectState.Saved);
|
|||
|
}
|
|||
|
|
|||
|
private ObjectiveCategoryGrades CreateObjectiveCategoryGradesObject(DataReader oReader)
|
|||
|
{
|
|||
|
ObjectiveCategoryGrades item = new ObjectiveCategoryGrades();
|
|||
|
MapObjectiveCategoryGradesObject(item, oReader);
|
|||
|
return item;
|
|||
|
}
|
|||
|
|
|||
|
protected List<ObjectiveCategoryGrades> CreateObjectiveCategoryGradesObjects(DataReader oReader)
|
|||
|
{
|
|||
|
List<ObjectiveCategoryGrades> oItems = new List<ObjectiveCategoryGrades>();
|
|||
|
while (oReader.Read())
|
|||
|
{
|
|||
|
ObjectiveCategoryGrades item = CreateObjectiveCategoryGradesObject(oReader);
|
|||
|
oItems.Add(item);
|
|||
|
}
|
|||
|
|
|||
|
return oItems;
|
|||
|
}
|
|||
|
|
|||
|
#endregion
|
|||
|
|
|||
|
#region Service Implementation
|
|||
|
|
|||
|
#region Get All
|
|||
|
|
|||
|
public List<ObjectiveCategory> Get()
|
|||
|
{
|
|||
|
List<ObjectiveCategory> oObjectiveCategory = null;
|
|||
|
TransactionContext tc = null;
|
|||
|
try
|
|||
|
{
|
|||
|
tc = TransactionContext.Begin();
|
|||
|
DataReader oreader = new DataReader(ObjectiveCategoryDA.Get(tc));
|
|||
|
oObjectiveCategory = this.CreateObjects<ObjectiveCategory>(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 oObjectiveCategory;
|
|||
|
}
|
|||
|
|
|||
|
#endregion
|
|||
|
|
|||
|
#region Get All
|
|||
|
|
|||
|
public List<ObjectiveCategory> Get(EnumStatus status)
|
|||
|
{
|
|||
|
List<ObjectiveCategory> oObjectiveCategory = null;
|
|||
|
TransactionContext tc = null;
|
|||
|
try
|
|||
|
{
|
|||
|
tc = TransactionContext.Begin();
|
|||
|
DataReader oreader = new DataReader(ObjectiveCategoryDA.Get(tc, status));
|
|||
|
oObjectiveCategory = this.CreateObjects<ObjectiveCategory>(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 oObjectiveCategory;
|
|||
|
}
|
|||
|
|
|||
|
public List<ObjectiveCategory> GetByPMPyear(int nID)
|
|||
|
{
|
|||
|
List<ObjectiveCategory> oObjectiveCategory = null;
|
|||
|
TransactionContext tc = null;
|
|||
|
try
|
|||
|
{
|
|||
|
tc = TransactionContext.Begin();
|
|||
|
DataReader oreader = new DataReader(ObjectiveCategoryDA.GetByPMPyear(tc, nID));
|
|||
|
oObjectiveCategory = this.CreateObjects<ObjectiveCategory>(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 oObjectiveCategory;
|
|||
|
}
|
|||
|
|
|||
|
#endregion
|
|||
|
|
|||
|
#region Get By ID
|
|||
|
|
|||
|
public ObjectiveCategory Get(int id)
|
|||
|
{
|
|||
|
ObjectiveCategory oObjectiveCategory = null;
|
|||
|
TransactionContext tc = null;
|
|||
|
try
|
|||
|
{
|
|||
|
tc = TransactionContext.Begin();
|
|||
|
DataReader oreader = new DataReader(ObjectiveCategoryDA.Get(tc, id));
|
|||
|
oObjectiveCategory = this.CreateObject<ObjectiveCategory>(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 oObjectiveCategory;
|
|||
|
}
|
|||
|
|
|||
|
#endregion
|
|||
|
|
|||
|
#region Get Objective Category Grades
|
|||
|
|
|||
|
public List<ObjectiveCategoryGrades> GetObjectiveCategoryGrades(int iD)
|
|||
|
{
|
|||
|
List<ObjectiveCategoryGrades> oObjectiveCategoryGrades = null;
|
|||
|
TransactionContext tc = null;
|
|||
|
try
|
|||
|
{
|
|||
|
tc = TransactionContext.Begin();
|
|||
|
DataReader oreader = new DataReader(ObjectiveCategoryGradesDA.GetObjectiveCategoryGrades(tc, iD));
|
|||
|
oObjectiveCategoryGrades = this.CreateObjectiveCategoryGradesObjects(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 oObjectiveCategoryGrades;
|
|||
|
}
|
|||
|
|
|||
|
#endregion
|
|||
|
|
|||
|
#region Insert
|
|||
|
|
|||
|
public void Save(List<ObjectiveCategory> items)
|
|||
|
{
|
|||
|
TransactionContext tc = null;
|
|||
|
try
|
|||
|
{
|
|||
|
tc = TransactionContext.Begin(true);
|
|||
|
if (items.Count > 0)
|
|||
|
ObjectiveCategoryGradesDA.DeleteByPMPYearID(tc, items[0].PMPYearID, items[0].Category,
|
|||
|
items[0].ObjectiveCategoryGrades[0].ObjectiveType);
|
|||
|
foreach (ObjectiveCategory item in items)
|
|||
|
{
|
|||
|
int id = tc.GenerateID("ObjectiveCategory", "ObjectiveCategoryID");
|
|||
|
base.SetObjectID(item, (id));
|
|||
|
ObjectiveCategoryDA.Save(tc, item);
|
|||
|
foreach (ObjectiveCategoryGrades og in item.ObjectiveCategoryGrades)
|
|||
|
{
|
|||
|
int id1 = tc.GenerateID("ObjectiveCategoryGrades", "ObjectiveCategoryGradesID");
|
|||
|
base.SetObjectID(og, (id1));
|
|||
|
og.ObjectiveCategoryID = item.ID;
|
|||
|
ObjectiveCategoryGradesDA.Save(tc, og);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
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 Save(ObjectiveCategory item)
|
|||
|
{
|
|||
|
TransactionContext tc = null;
|
|||
|
try
|
|||
|
{
|
|||
|
tc = TransactionContext.Begin(true);
|
|||
|
ObjectiveCategoryGradesDA.DeleteByPMPYearID(tc, item.PMPYearID, item.Category,
|
|||
|
item.ObjectiveCategoryGrades[0].ObjectiveType);
|
|||
|
int id = tc.GenerateID("ObjectiveCategory", "ObjectiveCategoryID");
|
|||
|
base.SetObjectID(item, (id));
|
|||
|
ObjectiveCategoryDA.Save(tc, item);
|
|||
|
foreach (ObjectiveCategoryGrades og in item.ObjectiveCategoryGrades)
|
|||
|
{
|
|||
|
og.ObjectiveType = item.ObjectiveTypeID;
|
|||
|
int id1 = tc.GenerateID("ObjectiveCategoryGrades", "ObjectiveCategoryGradesID");
|
|||
|
base.SetObjectID(og, (id1));
|
|||
|
og.ObjectiveCategoryID = item.ID;
|
|||
|
ObjectiveCategoryGradesDA.Save(tc, og);
|
|||
|
}
|
|||
|
tc.End();
|
|||
|
}
|
|||
|
catch (Exception e)
|
|||
|
{
|
|||
|
#region Handle Exception
|
|||
|
|
|||
|
if (tc != null)
|
|||
|
tc.HandleError();
|
|||
|
ExceptionLog.Write(e);
|
|||
|
throw new ServiceException(e.Message, e);
|
|||
|
|
|||
|
#endregion
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
#endregion
|
|||
|
|
|||
|
#region Delete
|
|||
|
|
|||
|
public void Delete(int id)
|
|||
|
{
|
|||
|
TransactionContext tc = null;
|
|||
|
try
|
|||
|
{
|
|||
|
tc = TransactionContext.Begin(true);
|
|||
|
ObjectiveCategoryDA.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
|
|||
|
|
|||
|
#endregion
|
|||
|
}
|
|||
|
}
|