EchoTex_Payroll/HRM.DA/Service/Basic/JobDefinitionService.cs

447 lines
17 KiB
C#
Raw Normal View History

2024-10-14 10:01:49 +06:00
using System;
using System.Collections.Generic;
using System.Text;
using Ease.Core.DataAccess;
using Ease.Core.Model;
using Ease.Core.Utility;
using HRM.BO;
using HRM.BO.Basic;
namespace HRM.DA
{
public class JobDefinitionService : ServiceTemplate, IJobDefinitionService
{
public JobDefinitionService()
{
}
private void MapObject(JobDefinition item, DataReader dataReader)
{
base.SetObjectID(item, dataReader.GetInt32("JdId").Value);
item.JdName = dataReader.GetString("JdName");
item.JdNo = dataReader.GetInt32("JdNo").Value;
item.RevisionDate = dataReader.GetString("RevisionDate") != null ? dataReader.GetDateTime("RevisionDate").Value: DateTime.MinValue;
item.DepartmentId = dataReader.GetInt32("DepartmentId");
item.UnitID = dataReader.GetInt32("UnitID");
item.DesignationId = dataReader.GetInt32("DesignationId");
item.GradeId = dataReader.GetInt32("GradeId");
item.Purpose = dataReader.GetString("Purpose");
item.FinancialInformation = dataReader.GetString("FinancialInformation");
item.TeamInformation = dataReader.GetString("TeamInformation");
item.InternalComm = dataReader.GetString("InternalComm");
item.ExternalComm = dataReader.GetString("ExternalComm");
item.ExperienceMinYear = dataReader.GetDouble("ExperienceMinYear");
item.ExperienceMaxYear = dataReader.GetDouble("ExperienceMaxYear");
item.KnowledgeUnderstanding = dataReader.GetString("KnowledgeUnderstanding");
item.AdherenceToCompany = dataReader.GetString("AdherenceToCompany");
item.ApprovedBy =dataReader.GetInt32("ApprovedBy");
item.ApproveDate = dataReader.GetDateTime("ApprovedDate");
item.ApprovarRemarks = dataReader.GetString("ApprovarRemarks");
item.WfStatus = dataReader.GetInt32("WFStatus") != 0 ? (EnumwfStatus)dataReader.GetInt32("WFStatus").Value : EnumwfStatus.End;
item.Requirement = dataReader.GetString("Requirement",null);
this.SetObjectState(item, Ease.Core.ObjectState.Saved);
}
protected override T CreateObject<T>(DataReader dr)
{
JobDefinition item = new JobDefinition();
MapObject(item, dr);
return item as T;
}
protected JobDefinition CreateObject(DataReader dataReader)
{
JobDefinition item = new JobDefinition();
MapObject(item, dataReader);
return item;
}
private void MapJdEducation(JDEducation item, DataReader dataReader)
{
base.SetObjectID(item, dataReader.GetInt32("JdEducationId").Value);
item.JdId = dataReader.GetInt32("JdId").Value;
item.ReferenceId = dataReader.GetInt32("ReferenceId").Value;
// item.JdEducationType = (EnumJdEducation) dataReader.GetInt32("JdEducationType").Value;
item.JdEducationName = dataReader.GetString("JdEducationName");
item.Remarks = dataReader.GetString("Remarks");
this.SetObjectState(item, Ease.Core.ObjectState.Saved);
}
private void MapJdCertification(JDCertification item, DataReader dataReader)
{
base.SetObjectID(item, dataReader.GetInt32("JdCertificationID").Value);
item.JdId = dataReader.GetInt32("JdId").Value;
item.ReferenceId = dataReader.GetInt32("ReferenceId").Value;
// item.JdEducationType = (EnumJdEducation) dataReader.GetInt32("JdEducationType").Value;
item.JdCertificationName = dataReader.GetString("JdCertificationName");
item.Remarks = dataReader.GetString("Remarks");
this.SetObjectState(item, Ease.Core.ObjectState.Saved);
}
private JDEducation CreateComponentJDEducation(DataReader dataReader)
{
JDEducation item = new JDEducation();
MapJdEducation(item, dataReader);
return item;
}
private List<JDEducation> createComponentJDEducationList(DataReader dataReader)
{
List<JDEducation> items = new List<JDEducation>();
while (dataReader.Read())
{
JDEducation item = CreateComponentJDEducation(dataReader);
items.Add(item);
}
return items;
}
private JDCertification CreateComponentJDCertification(DataReader dataReader)
{
JDCertification item = new JDCertification();
MapJdCertification(item, dataReader);
return item;
}
private List<JDCertification> createComponentJDCertificationList(DataReader dataReader)
{
List<JDCertification> items = new List<JDCertification>();
while (dataReader.Read())
{
JDCertification item = CreateComponentJDCertification(dataReader);
items.Add(item);
}
return items;
}
private List<JDEducation> CreateComponentJDEducationList(DataReader dataReader)
{
List<JDEducation> items = new List<JDEducation>();
while (dataReader.Read())
{
JDEducation item = CreateComponentJDEducation(dataReader);
items.Add(item);
}
return items;
}
private void MapJdResponsibility(JDResponsibility item, DataReader dataReader)
{
base.SetObjectID(item, dataReader.GetInt32("JdResponsibilityId").Value);
item.JdId = dataReader.GetInt32("JdId").Value;
item.Name = dataReader.GetString("Name");
item.Description = dataReader.GetString("Description");
item.TimeSpentPercent = dataReader.GetInt32("TimeSpentPercent").Value;
item.MeasurementCriteria = dataReader.GetString("MeasurementCriteria");
this.SetObjectState(item, Ease.Core.ObjectState.Saved);
}
private JDResponsibility CreateComponentJDResponsibility(DataReader dataReader)
{
JDResponsibility item = new JDResponsibility();
MapJdResponsibility(item, dataReader);
return item;
}
private List<JDResponsibility> createComponentJdResponsibilityList(DataReader dataReader)
{
List<JDResponsibility> items = new List<JDResponsibility>();
while (dataReader.Read())
{
JDResponsibility item = CreateComponentJDResponsibility(dataReader);
items.Add(item);
}
return items;
}
public void Save(JobDefinition item)
{
TransactionContext tc = null;
try
{
int id = 0;
tc = TransactionContext.Begin(true);
if (item.IsNew)
{
id = tc.GenerateID("JobDefinition", "JdId");
base.SetObjectID(item, id);
JobDefinitionDA.InsertJD(tc, item);
}
else
{
id = item.ID;
JobDefinitionDA.UpdateJD(tc, item);
JobDefinitionDA.DeleteJDEducation(tc, id);
JobDefinitionDA.DeleteJDResponsibility(tc, id);
JobDefinitionDA.DeleteJDCertification(tc, id);
}
if (item.JdEducationList != null)
{
foreach (JDEducation jdr in item.JdEducationList)
{
int jdEducationId = tc.GenerateID("JDEducation", "JdEducationId");
base.SetObjectID(jdr, jdEducationId);
jdr.JdId = id;
jdr.ID = jdEducationId;
JobDefinitionDA.InsertJDEducation(tc, jdr);
}
}
if (item.JdCertificationList != null)
{
foreach (JDCertification jdexp in item.JdCertificationList)
{
int jdCertificationId = tc.GenerateID("JDCertification", "JDCertificationID");
base.SetObjectID(jdexp, jdCertificationId);
jdexp.JdId = id;
jdexp.ID = jdCertificationId;
JobDefinitionDA.InsertJDCertification(tc, jdexp);
}
}
if (item.JdResponsibilityList != null)
{
foreach (JDResponsibility jdResponsibility in item.JdResponsibilityList)
{
int jdResponsibilityId = tc.GenerateID("JdResponsibility", "JdResponsibilityId");
base.SetObjectID(jdResponsibility, jdResponsibilityId);
jdResponsibility.JdId = id;
jdResponsibility.ID = jdResponsibilityId;
JobDefinitionDA.InsertJDResponsibility(tc, jdResponsibility);
}
}
tc.End();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
}
public List<JobDefinition> GetAll()
{
List<JobDefinition> items = new List<JobDefinition>();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
DataReader dr = new DataReader(JobDefinitionDA.GetAllJobDefinition(tc));
items = this.CreateObjects<JobDefinition>(dr);
dr.Close();
foreach (JobDefinition jobDefinition in items)
{
DataReader dr1 = new DataReader(JobDefinitionDA.GetJDCertification(tc, jobDefinition.ID));
//while (dr1.Read())
//{
// jobDefinition.JdCertificationList = this.createComponentJDCertificationList(dr1);
//}
jobDefinition.JdCertificationList = this.createComponentJDCertificationList(dr1);
dr1.Close();
DataReader dr2 = new DataReader(JobDefinitionDA.GetJDEducation(tc, jobDefinition.ID));
//while (dr2.Read())
//{
// jobDefinition.JdEducationList = this.CreateComponentJDEducationList(dr2);
//}
jobDefinition.JdEducationList = this.CreateComponentJDEducationList(dr2);
dr2.Close();
DataReader dr3 = new DataReader(JobDefinitionDA.GetJDResponsibility(tc, jobDefinition.ID));
//while (dr3.Read())
//{
// jobDefinition.JdResponsibilityList = this.createComponentJdResponsibilityList(dr3);
//}
jobDefinition.JdResponsibilityList = this.createComponentJdResponsibilityList(dr3);
dr3.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 void DeleteJobDefinition(int id)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
JobDefinitionDA.DeleteJobDefinition(tc, id);
JobDefinitionDA.DeleteJDEducation(tc, id);
JobDefinitionDA.DeleteJDResponsibility(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
}
}
public List<JobDefinition> Get(int wfStatus)
{
List<JobDefinition> items = new List<JobDefinition>();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
DataReader dr = new DataReader(JobDefinitionDA.GetAllJobDefinition(tc));
items = this.CreateObjects<JobDefinition>(dr);
dr.Close();
foreach (JobDefinition jobDefinition in items)
{
DataReader dr1 = new DataReader(JobDefinitionDA.GetJDCertification(tc, jobDefinition.ID));
while (dr1.Read())
{
jobDefinition.JdCertificationList = this.createComponentJDCertificationList(dr1);
}
dr1.Close();
DataReader dr2 = new DataReader(JobDefinitionDA.GetJDEducation(tc, jobDefinition.ID));
// //while (dr2.Read())
// //{
// // jobDefinition.JdEducationList = this.CreateComponentJDEducationList(dr2);
// //}
jobDefinition.JdEducationList = this.CreateComponentJDEducationList(dr2);
dr2.Close();
DataReader dr3 = new DataReader(JobDefinitionDA.GetJDResponsibility(tc, jobDefinition.ID));
//while (dr3.Read())
//{
// jobDefinition.JdResponsibilityList = this.createComponentJdResponsibilityList(dr3);
//}
jobDefinition.JdResponsibilityList = this.createComponentJdResponsibilityList(dr3);
dr3.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 JobDefinition GetByID(int ID)
{
JobDefinition ob = null;
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
DataReader dr = new DataReader(JobDefinitionDA.GetByID(tc,ID));
if (dr.Read())
{
ob = this.CreateObject<JobDefinition>(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
}
return ob;
}
public JobDefinition GetJobDefinitionById(int ID)
{
JobDefinition ob = null;
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
DataReader dr = new DataReader(JobDefinitionDA.GetByID(tc, ID));
if (dr.Read())
{
ob = this.CreateObject<JobDefinition>(dr);
}
dr.Close();
if(ob != null)
{
DataReader dr1 = new DataReader(JobDefinitionDA.GetJDEducation(tc, ob.ID));
ob.JdEducationList = this.CreateComponentJDEducationList(dr1);
dr1.Close();
DataReader dr2 = new DataReader(JobDefinitionDA.GetJDCertification(tc, ob.ID));
ob.JdCertificationList = this.createComponentJDCertificationList(dr2);
dr2.Close();
DataReader dr3 = new DataReader(JobDefinitionDA.GetJDResponsibility(tc, ob.ID));
ob.JdResponsibilityList = this.createComponentJdResponsibilityList(dr3);
dr3.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 ob;
}
}
}