376 lines
13 KiB
C#
376 lines
13 KiB
C#
|
using System;
|
|||
|
using System.Collections.Generic;
|
|||
|
using System.Linq;
|
|||
|
using System.Text;
|
|||
|
using Ease.CoreV35;
|
|||
|
using Ease.CoreV35.Model;
|
|||
|
using Ease.CoreV35.DataAccess;
|
|||
|
using Payroll.BO;
|
|||
|
using Ease.CoreV35.Caching;
|
|||
|
using System.Data;
|
|||
|
|
|||
|
namespace Payroll.Service
|
|||
|
{
|
|||
|
[Serializable]
|
|||
|
public class SurveyResultService : ServiceTemplate, ISurveyResultService
|
|||
|
{
|
|||
|
#region Private functions and declaration
|
|||
|
Cache _cache = new Cache(typeof(SurveyResult));
|
|||
|
|
|||
|
#endregion
|
|||
|
public SurveyResultService() { }
|
|||
|
|
|||
|
private void MapObject(SurveyResult oSurveyResult, DataReader oReader)
|
|||
|
{
|
|||
|
//base.SetObjectID(oSurveyResult, oReader.GetID("SurveyResultID"));
|
|||
|
oSurveyResult.SurveyID = oReader.GetID("SurveyID");
|
|||
|
oSurveyResult.AnswerID = oReader.GetInt32("AnswerID").GetValueOrDefault();
|
|||
|
oSurveyResult.EmployeeID = oReader.GetInt32("EmployeeID").GetValueOrDefault();
|
|||
|
oSurveyResult.QuestionID = oReader.GetInt32("QuestionID").GetValueOrDefault();
|
|||
|
oSurveyResult.IsCorrect = oReader.GetBoolean("IsCorrect").GetValueOrDefault();
|
|||
|
oSurveyResult.ForEmployeeID = oReader.GetInt32("ForEmployeeID").GetValueOrDefault();
|
|||
|
oSurveyResult.Weight = oReader.GetDouble("Weight").GetValueOrDefault();
|
|||
|
this.SetObjectState(oSurveyResult, Ease.CoreV35.ObjectState.Saved);
|
|||
|
}
|
|||
|
protected override T CreateObject<T>(DataReader oReader)
|
|||
|
{
|
|||
|
SurveyResult oSurveyResult = new SurveyResult();
|
|||
|
MapObject(oSurveyResult, oReader);
|
|||
|
return oSurveyResult as T;
|
|||
|
}
|
|||
|
protected SurveyResult CreateObject(DataReader oReader)
|
|||
|
{
|
|||
|
SurveyResult oSurveyResult = new SurveyResult();
|
|||
|
MapObject(oSurveyResult, oReader);
|
|||
|
return oSurveyResult;
|
|||
|
}
|
|||
|
#region Service implementation
|
|||
|
|
|||
|
public ObjectsTemplate<SurveyResult> GetSurveyResult(ID surveyId)
|
|||
|
{
|
|||
|
|
|||
|
#region Cache Header
|
|||
|
|
|||
|
ObjectsTemplate<SurveyResult> oSurveyResults = _cache["GetSurveyResult",surveyId] as ObjectsTemplate<SurveyResult>;
|
|||
|
if (oSurveyResults != null)
|
|||
|
return oSurveyResults;
|
|||
|
|
|||
|
#endregion
|
|||
|
|
|||
|
TransactionContext tc = null;
|
|||
|
try
|
|||
|
{
|
|||
|
tc = TransactionContext.Begin();
|
|||
|
DataReader dr = new DataReader(SurveyResultDA.GetSurveyResult(tc, surveyId.Integer));
|
|||
|
oSurveyResults = this.CreateObjects<SurveyResult>(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(oSurveyResults, "GetSurveyResult",surveyId);
|
|||
|
#endregion
|
|||
|
return oSurveyResults;
|
|||
|
|
|||
|
}
|
|||
|
public ObjectsTemplate<SurveyResult> GetSurveyResult()
|
|||
|
{
|
|||
|
#region Cache Header
|
|||
|
|
|||
|
ObjectsTemplate<SurveyResult> oSurveyResults = _cache["GetSurveyResult"] as ObjectsTemplate<SurveyResult>;
|
|||
|
if (oSurveyResults != null)
|
|||
|
return oSurveyResults;
|
|||
|
|
|||
|
#endregion
|
|||
|
|
|||
|
TransactionContext tc = null;
|
|||
|
try
|
|||
|
{
|
|||
|
tc = TransactionContext.Begin();
|
|||
|
DataReader dr = new DataReader(SurveyResultDA.GetSurveyResult(tc));
|
|||
|
oSurveyResults = this.CreateObjects<SurveyResult>(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(oSurveyResults, "GetSurveyResult");
|
|||
|
#endregion
|
|||
|
return oSurveyResults;
|
|||
|
}
|
|||
|
public ObjectsTemplate<SurveyResult> GetSurveyResult(int surveyId, string employeeIds)
|
|||
|
{
|
|||
|
#region Cache Header
|
|||
|
|
|||
|
ObjectsTemplate<SurveyResult> oSurveyResults = _cache["GetSurveyResult",surveyId, employeeIds] as ObjectsTemplate<SurveyResult>;
|
|||
|
if (oSurveyResults != null)
|
|||
|
return oSurveyResults;
|
|||
|
|
|||
|
#endregion
|
|||
|
|
|||
|
TransactionContext tc = null;
|
|||
|
try
|
|||
|
{
|
|||
|
tc = TransactionContext.Begin();
|
|||
|
DataReader dr = new DataReader(SurveyResultDA.GetSurveyResult(tc, surveyId, employeeIds));
|
|||
|
oSurveyResults = this.CreateObjects<SurveyResult>(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(oSurveyResults, "GetSurveyResult", surveyId, employeeIds);
|
|||
|
#endregion
|
|||
|
return oSurveyResults;
|
|||
|
}
|
|||
|
|
|||
|
public ObjectsTemplate<SurveyResult> GetSurveyResult(int surveyId, int employeeId, int questionID)
|
|||
|
{
|
|||
|
#region Cache Header
|
|||
|
|
|||
|
ObjectsTemplate<SurveyResult> oSurveyResults = _cache["GetSurveyResult", surveyId, questionID] as ObjectsTemplate<SurveyResult>;
|
|||
|
if (oSurveyResults != null)
|
|||
|
return oSurveyResults;
|
|||
|
|
|||
|
#endregion
|
|||
|
|
|||
|
TransactionContext tc = null;
|
|||
|
try
|
|||
|
{
|
|||
|
tc = TransactionContext.Begin();
|
|||
|
DataReader dr = new DataReader(SurveyResultDA.GetSurveyResult(tc, surveyId,employeeId, questionID));
|
|||
|
oSurveyResults = this.CreateObjects<SurveyResult>(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(oSurveyResults, "GetSurveyResult", surveyId, questionID);
|
|||
|
#endregion
|
|||
|
return oSurveyResults;
|
|||
|
}
|
|||
|
|
|||
|
public void Save(ObjectsTemplate<SurveyResult> oSurveyResults)
|
|||
|
{
|
|||
|
TransactionContext tc = null;
|
|||
|
try
|
|||
|
{
|
|||
|
tc = TransactionContext.Begin(true);
|
|||
|
|
|||
|
foreach (SurveyResult oSurveyResult in oSurveyResults)
|
|||
|
{
|
|||
|
SurveyResultDA.DeleteSurveyResult(tc, oSurveyResult.SurveyID.Integer, oSurveyResult.EmployeeID,oSurveyResult.QuestionID);
|
|||
|
}
|
|||
|
foreach (SurveyResult oSurveyResult in oSurveyResults)
|
|||
|
{
|
|||
|
//if (oSurveyResult.IsNew)
|
|||
|
//{
|
|||
|
|
|||
|
//int id = tc.GenerateID("SurveyResult", "SurveyResultID");
|
|||
|
//base.SetObjectID(oSurveyResult, ID.FromInteger(id));
|
|||
|
|
|||
|
|
|||
|
SurveyResultDA.Insert(tc, oSurveyResult);
|
|||
|
//}
|
|||
|
//else
|
|||
|
//{
|
|||
|
// SurveyResultDA.Update(tc, oSurveyResult);
|
|||
|
//}
|
|||
|
}
|
|||
|
tc.End();
|
|||
|
|
|||
|
}
|
|||
|
catch (Exception e)
|
|||
|
{
|
|||
|
#region Handle Exception
|
|||
|
if (tc != null)
|
|||
|
tc.HandleError();
|
|||
|
ExceptionLog.Write(e);
|
|||
|
throw new ServiceException(e.Message, e);
|
|||
|
#endregion
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
public ID Save(SurveyResult oSurveyResult)
|
|||
|
{
|
|||
|
TransactionContext tc = null;
|
|||
|
try
|
|||
|
{
|
|||
|
tc = TransactionContext.Begin(true);
|
|||
|
|
|||
|
if (oSurveyResult.IsNew)
|
|||
|
{
|
|||
|
|
|||
|
//int id = tc.GenerateID("SurveyResult", "SurveyResultID");
|
|||
|
//base.SetObjectID(oSurveyResult, ID.FromInteger(id));
|
|||
|
|
|||
|
|
|||
|
SurveyResultDA.Insert(tc, oSurveyResult);
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
SurveyResultDA.Update(tc, oSurveyResult);
|
|||
|
}
|
|||
|
tc.End();
|
|||
|
return oSurveyResult.SurveyID;
|
|||
|
}
|
|||
|
catch (Exception e)
|
|||
|
{
|
|||
|
#region Handle Exception
|
|||
|
if (tc != null)
|
|||
|
tc.HandleError();
|
|||
|
ExceptionLog.Write(e);
|
|||
|
throw new ServiceException(e.Message, e);
|
|||
|
#endregion
|
|||
|
}
|
|||
|
}
|
|||
|
internal int getHitCount(TransactionContext tc, int surveyID, int questionID, int answerID)
|
|||
|
{
|
|||
|
return SurveyAnswerCountDA.GetSurveyAnswerHitCount(tc, surveyID, questionID, answerID);
|
|||
|
}
|
|||
|
public void SaveSurveyResult(SurveyResult oSurveyResult, SurveyEmployee surEmp, bool IsAnnonymous, int GeneralNoticeID)
|
|||
|
{
|
|||
|
TransactionContext tc = null;
|
|||
|
|
|||
|
try
|
|||
|
{
|
|||
|
tc = TransactionContext.Begin(true);
|
|||
|
SurveyEmployeeDA.UpdateSurveyEmployee(tc, surEmp);
|
|||
|
|
|||
|
if (IsAnnonymous)
|
|||
|
SurveyResultDA.Insert(tc, oSurveyResult);
|
|||
|
|
|||
|
if (getHitCount(tc, oSurveyResult.SurveyID.Integer, oSurveyResult.QuestionID, oSurveyResult.AnswerID) > 0)
|
|||
|
SurveyAnswerCountDA.UpdateSurveyAnswerCount(tc, oSurveyResult.SurveyID.Integer, oSurveyResult.QuestionID, oSurveyResult.AnswerID);
|
|||
|
else
|
|||
|
SurveyAnswerCountDA.InsertSurveyAnswerCount(tc, oSurveyResult.SurveyID.Integer, oSurveyResult.QuestionID, oSurveyResult.AnswerID);
|
|||
|
//GeneralNoticeDA.Delete(tc, GeneralNoticeID);
|
|||
|
tc.End();
|
|||
|
|
|||
|
}
|
|||
|
catch (Exception e)
|
|||
|
{
|
|||
|
#region Handle Exception
|
|||
|
if (tc != null)
|
|||
|
tc.HandleError();
|
|||
|
ExceptionLog.Write(e);
|
|||
|
throw new ServiceException("Failed to Save Survey Result.", e);
|
|||
|
#endregion
|
|||
|
}
|
|||
|
}
|
|||
|
public void SaveSurveyResult(ObjectsTemplate<SurveyResult> oSurveyResults, SurveyEmployee surEmp, bool IsAnnonymous, int GeneralNoticeID)
|
|||
|
{
|
|||
|
TransactionContext tc = null;
|
|||
|
|
|||
|
try
|
|||
|
{
|
|||
|
tc = TransactionContext.Begin(true);
|
|||
|
|
|||
|
//update the assessment date of the employee or manager.
|
|||
|
SurveyEmployeeDA.UpdateSurveyEmployee(tc, surEmp);
|
|||
|
foreach (SurveyResult oSurveyResult in oSurveyResults)
|
|||
|
{
|
|||
|
|
|||
|
if (!IsAnnonymous)
|
|||
|
{
|
|||
|
SurveyResultDA.DeleteSurveyResult(tc, oSurveyResult.SurveyID.Integer, oSurveyResult.EmployeeID, oSurveyResult.QuestionID);
|
|||
|
SurveyResultDA.InsertSurveyResult(tc, oSurveyResult);
|
|||
|
}
|
|||
|
|
|||
|
if (getHitCount(tc, oSurveyResult.SurveyID.Integer, oSurveyResult.QuestionID, oSurveyResult.AnswerID) > 0)
|
|||
|
SurveyAnswerCountDA.UpdateSurveyAnswerCount(tc, oSurveyResult.SurveyID.Integer, oSurveyResult.QuestionID, oSurveyResult.AnswerID);
|
|||
|
else
|
|||
|
SurveyAnswerCountDA.InsertSurveyAnswerCount(tc, oSurveyResult.SurveyID.Integer, oSurveyResult.QuestionID, oSurveyResult.AnswerID);
|
|||
|
}
|
|||
|
//GeneralNoticeDA.Delete(tc, GeneralNoticeID);
|
|||
|
tc.End();
|
|||
|
|
|||
|
}
|
|||
|
catch (Exception e)
|
|||
|
{
|
|||
|
#region Handle Exception
|
|||
|
if (tc != null)
|
|||
|
tc.HandleError();
|
|||
|
ExceptionLog.Write(e);
|
|||
|
throw new ServiceException("Failed to Save Survey Result.", e);
|
|||
|
#endregion
|
|||
|
}
|
|||
|
}
|
|||
|
public DataSet GetSurveyResultReport(ID surveyID)
|
|||
|
{
|
|||
|
DataSet ds = new DataSet();
|
|||
|
TransactionContext tc = null;
|
|||
|
try
|
|||
|
{
|
|||
|
tc = TransactionContext.Begin();
|
|||
|
ds = SurveyResultDA.GetSurveyResultReport(tc, surveyID.Integer);
|
|||
|
tc.End();
|
|||
|
}
|
|||
|
catch (Exception e)
|
|||
|
{
|
|||
|
#region Handle Exception
|
|||
|
if (tc != null)
|
|||
|
tc.HandleError();
|
|||
|
|
|||
|
ExceptionLog.Write(e);
|
|||
|
throw new ServiceException("Failed to Get Report", e);
|
|||
|
#endregion
|
|||
|
}
|
|||
|
return ds;
|
|||
|
|
|||
|
}
|
|||
|
public void Delete(ID id)
|
|||
|
{
|
|||
|
//TransactionContext tc = null;
|
|||
|
//try
|
|||
|
//{
|
|||
|
// tc = TransactionContext.Begin(true);
|
|||
|
// SurveyResultDA.DeleteSurveyResult(tc, id.Integer);
|
|||
|
// tc.End();
|
|||
|
//}
|
|||
|
//catch (Exception e)
|
|||
|
//{
|
|||
|
// #region Handle Exception
|
|||
|
// if (tc != null)
|
|||
|
// tc.HandleError();
|
|||
|
// ExceptionLog.Write(e);
|
|||
|
// throw new ServiceException(e.Message, e);
|
|||
|
// #endregion
|
|||
|
//}
|
|||
|
}
|
|||
|
#endregion
|
|||
|
}
|
|||
|
}
|