292 lines
9.9 KiB
C#
292 lines
9.9 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Data;
|
|
using Ease.Core;
|
|
using Ease.Core.DataAccess;
|
|
using Ease.Core.Model;
|
|
using Ease.Core.Utility;
|
|
using HRM.BO;
|
|
using HRM.DA;
|
|
|
|
|
|
namespace HRM.DA
|
|
{
|
|
public class CalibrationService: ServiceTemplate, ICalibrationService
|
|
{
|
|
private void MapObject(Calibration calibration, DataReader dataReader)
|
|
{
|
|
SetObjectID(calibration, dataReader.GetInt32("CalibrationId", 0));
|
|
calibration.EmployeeId = dataReader.GetInt32("EmployeeId", 0);
|
|
calibration.PmpYearId = dataReader.GetInt32("PmpYearId", 0);
|
|
calibration.CalibrationDate = dataReader.GetDateTime("CalibrationDate", DateTime.MinValue);
|
|
calibration.Description = dataReader.GetString("Description", true, string.Empty);
|
|
calibration.Strength = dataReader.GetString("Strength", true, string.Empty);
|
|
calibration.Opportunity = dataReader.GetString("Opportunity", true, string.Empty);
|
|
calibration.KeyPerformance = dataReader.GetString("KeyPerformance", true, string.Empty);
|
|
calibration.PostCalibrationRating = dataReader.GetDouble("PostCalibrationRating", true, 0);
|
|
calibration.CalibrationStatus = (EnumCalibrationStatus)dataReader.GetInt32("CalibrationStatus").GetValueOrDefault();
|
|
this.SetObjectState(calibration, ObjectState.Saved);
|
|
}
|
|
private void MapObjectChild(CalibrationAudiance calibrationAudiance, DataReader dataReader)
|
|
{
|
|
SetObjectID(calibrationAudiance, dataReader.GetInt32("CalibrationAudianceId", 0));
|
|
calibrationAudiance.CalibrationId = dataReader.GetInt32("CalibrationId", 0);
|
|
calibrationAudiance.EmployeeId = dataReader.GetInt32("EmployeeId", 0);
|
|
|
|
this.SetObjectState(calibrationAudiance, ObjectState.Saved);
|
|
}
|
|
private CalibrationAudiance CreateCalibrationAudiance(DataReader oReader)
|
|
{
|
|
CalibrationAudiance cld = new CalibrationAudiance();
|
|
MapObjectChild(cld, oReader);
|
|
return cld;
|
|
}
|
|
protected List<CalibrationAudiance> CreateCalibrationAudiances(DataReader oReader)
|
|
{
|
|
List<CalibrationAudiance> items = new List<CalibrationAudiance>();
|
|
while (oReader.Read())
|
|
{
|
|
CalibrationAudiance item = CreateCalibrationAudiance(oReader);
|
|
items.Add(item);
|
|
}
|
|
|
|
return items;
|
|
}
|
|
|
|
protected override T CreateObject<T>(DataReader dr)
|
|
{
|
|
Calibration calibration = new Calibration();
|
|
MapObject(calibration, dr);
|
|
return calibration as T;
|
|
}
|
|
|
|
public Calibration GetByEmpIdAndPmpYearId(int employeeId, int pmpYearId)
|
|
{
|
|
TransactionContext tc = null;
|
|
Calibration calibration = new Calibration();
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin();
|
|
DataReader dataReader = new DataReader(CalibrationDA.GetByEmpIdAndPmpYearId(tc, employeeId, pmpYearId));
|
|
if (dataReader.Read())
|
|
{
|
|
calibration = this.CreateObject<Calibration>(dataReader);
|
|
}
|
|
|
|
dataReader.Close();
|
|
if (calibration != null)
|
|
{
|
|
dataReader = new DataReader(CalibrationAudianceDA.GetByCalibrationID(tc, calibration.ID));
|
|
calibration.CalibrationAudiances = this.CreateCalibrationAudiances(dataReader);
|
|
}
|
|
tc.End();
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
#region Handle Exception
|
|
|
|
if (tc != null)
|
|
tc.HandleError();
|
|
ExceptionLog.Write(e);
|
|
throw new ServiceException(e.Message, e);
|
|
|
|
#endregion
|
|
}
|
|
|
|
return calibration;
|
|
}
|
|
|
|
public List<Calibration> GetByPmpYearId(int pmpYearId)
|
|
{
|
|
TransactionContext tc = null;
|
|
List<Calibration> items = new List<Calibration>();
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin();
|
|
DataReader dataReader = new DataReader(CalibrationDA.GetCalibrationListByPmpYearId(tc, pmpYearId));
|
|
items = this.CreateObjects<Calibration>(dataReader);
|
|
dataReader.Close();
|
|
if (items != null)
|
|
{
|
|
foreach (Calibration item in items) {
|
|
dataReader = new DataReader(CalibrationAudianceDA.GetByCalibrationID(tc, item.ID));
|
|
item.CalibrationAudiances = this.CreateCalibrationAudiances(dataReader);
|
|
dataReader.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 items;
|
|
}
|
|
|
|
public List<Calibration> GetSubordinatesCalibration(int pmpYearId, int employeeId)
|
|
{
|
|
TransactionContext tc = null;
|
|
List<Calibration> items = new List<Calibration>();
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin();
|
|
DataReader dataReader = new DataReader(CalibrationDA.GetSubordinatesCalibration(tc, pmpYearId, employeeId));
|
|
items = this.CreateObjects<Calibration>(dataReader);
|
|
dataReader.Close();
|
|
|
|
foreach (Calibration item in items)
|
|
{
|
|
dataReader = new DataReader(CalibrationAudianceDA.GetByCalibrationID(tc, item.ID));
|
|
item.CalibrationAudiances = this.CreateCalibrationAudiances(dataReader);
|
|
dataReader.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 items;
|
|
}
|
|
|
|
public DataSet GetEmployeeWithRatings(int pmpYearId, string ratingStr)
|
|
{
|
|
TransactionContext tc = null;
|
|
DataSet ds = new DataSet();
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin();
|
|
ds = CalibrationDA.GetEmployeeWithRatings(tc, pmpYearId, ratingStr);
|
|
tc.End();
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
#region Handle Exception
|
|
|
|
if (tc != null)
|
|
tc.HandleError();
|
|
ExceptionLog.Write(e);
|
|
throw new ServiceException(e.Message, e);
|
|
|
|
#endregion
|
|
}
|
|
|
|
return ds;
|
|
}
|
|
|
|
public void Save(Calibration calibration)
|
|
{
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin();
|
|
if (calibration.IsNew)
|
|
{
|
|
int id = tc.GenerateID("Calibration", "CalibrationId");
|
|
base.SetObjectID(calibration, id);
|
|
CalibrationDA.Insert(tc, calibration);
|
|
}
|
|
else
|
|
{
|
|
CalibrationDA.Update(tc, calibration);
|
|
}
|
|
CalibrationAudianceDA.DeleteByCalibrationId(tc, calibration.ID);
|
|
foreach (CalibrationAudiance item in calibration.CalibrationAudiances)
|
|
{
|
|
item.CalibrationId = calibration.ID;
|
|
int id = tc.GenerateID("CalibrationAudiance", "CalibrationAudianceId");
|
|
base.SetObjectID(item, id);
|
|
CalibrationAudianceDA.Insert(tc, item); CalibrationAudianceDA.Update(tc, item);
|
|
}
|
|
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 SaveCalibrationEss(Calibration calibration)
|
|
{
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin();
|
|
if (calibration.IsNew)
|
|
{
|
|
int id = tc.GenerateID("Calibration", "CalibrationId");
|
|
base.SetObjectID(calibration, id);
|
|
CalibrationDA.Insert(tc, calibration);
|
|
}
|
|
else
|
|
{
|
|
CalibrationDA.Update(tc, calibration);
|
|
}
|
|
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(int id)
|
|
{
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin();
|
|
CalibrationAudianceDA.DeleteByCalibrationId(tc, id);
|
|
CalibrationDA.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
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
} |