EchoTex_Payroll/HRM.DA/Service/Organogram/OrganogramEmployeeService.cs

537 lines
16 KiB
C#
Raw Permalink Normal View History

2024-10-14 10:01:49 +06:00
using System;
using System.Data;
using System.Collections.Generic;
using Ease.Core.Model;
using Ease.Core.DataAccess;
using Ease.Core.Utility;
using HRM.BO;
namespace HRM.DA
{
#region OrganogramEmployee Service
public class OrganogramEmployeeService : ServiceTemplate, IOrganogramEmployeeService
{
public OrganogramEmployeeService()
{
}
private void MapObject(OrganogramEmployee oOrganEmp, DataReader oReader)
{
//base.SetObjectID(oOrganEmp,ID.FromComplex(oReader.GetID("NodeID"),oReader.GetID("EmployeeID")));
base.SetObjectID(oOrganEmp, oReader.GetInt32("OrganEmpID").Value);
oOrganEmp.NodeID = oReader.GetInt32("NodeID", 0);
oOrganEmp.EmployeeID = oReader.GetInt32("EmployeeID", 0);
oOrganEmp.AssignDate = oReader.GetDateTime("AssignDate").Value;
oOrganEmp.CreatedBy = oReader.GetInt32("CreatedBy", 0);
oOrganEmp.CreatedDate = oReader.GetDateTime("CreationDate").Value;
oOrganEmp.ModifiedBy = oReader.GetInt32("ModifiedBy", 0);
//oOrganEmp.ModifiedDate = oReader.GetDateTime("ModifiedDate");
this.SetObjectState(oOrganEmp, Ease.Core.ObjectState.Saved);
}
protected override T CreateObject<T>(DataReader oReader)
{
OrganogramEmployee oOrganogramEmployee = new OrganogramEmployee();
MapObject(oOrganogramEmployee, oReader);
return oOrganogramEmployee as T;
}
#region Service implementation
public int Save(OrganogramEmployee oOrganogramEmployee)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
Save(tc, oOrganogramEmployee);
tc.End();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
return oOrganogramEmployee.ID;
}
public void Save(List<OrganogramEmployee> OrganEmps)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
foreach (OrganogramEmployee oOrganogramEmployee in OrganEmps)
{
Save(tc, oOrganogramEmployee);
}
tc.End();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
}
public int Save(TransactionContext tc, OrganogramEmployee oOrganogramEmployee)
{
try
{
if (oOrganogramEmployee.IsNew)
{
int id = tc.GenerateID("OrganEmployee", "OrganEmpID");
base.SetObjectID(oOrganogramEmployee, (id));
OrganogramEmployeeDA.Insert(tc, oOrganogramEmployee);
}
else
{
OrganogramEmployeeDA.Update(tc, oOrganogramEmployee);
}
return oOrganogramEmployee.ID;
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
}
//public static void SaveForEmpLIfeCycle(TransactionContext tc, OrganogramEmployee oOrganogramEmployee)
//{
// try
// {
// int id = tc.GenerateID("OrganEmployee", "OrganEmpID");
// OrganogramEmployeeDA.InsertForLifeCycle(tc, oOrganogramEmployee,id);
// }
// 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(true);
OrganogramEmployeeDA.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
}
}
public void Delete()
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
OrganogramEmployeeDA.Delete(tc);
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 DeleteByEmp(TransactionContext tc, int id)
{
try
{
OrganogramEmployeeDA.DeleteByEmp(tc, id);
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
}
public void DeleteByNode(TransactionContext tc, int nodeid)
{
try
{
OrganogramEmployeeDA.DeleteByNode(tc, nodeid);
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
}
public List<OrganogramBasic> GetOrganogramInfo()
{
DataSet ods = new DataSet();
List<OrganogramBasic> oOrgs = new List<OrganogramBasic>();
TransactionContext tc = null;
int nCount = 1;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(OrganogramEmployeeDA.GetOrganogramInfo(tc));
while (dr.Read())
{
OrganogramBasic org = new OrganogramBasic();
org.ID = Convert.ToInt32(dr.GetInt32(0));
var pid = dr.GetInt32(1);
if (pid != null)
org.ParentID = (pid);
org.PositionName = dr.GetString(2);
org.EmployeeNoView = dr.GetString(3);
org.EmployeeNameView = dr.GetString(4);
// org.EmployeeNameView = Convert.ToInt32(dr.GetInt32(5));
org.Tier = Convert.ToInt32(dr.GetInt32(6));
oOrgs.Add(org);
nCount++;
}
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 oOrgs;
}
public List<OrganogramEmployee> Get(TransactionContext tc, int nodeID)
{
List<OrganogramEmployee> oOrganogramEmployee = new List<OrganogramEmployee>();
try
{
DataReader dr = new DataReader(OrganogramEmployeeDA.Get(tc, nodeID));
oOrganogramEmployee = this.CreateObjects<OrganogramEmployee>(dr);
dr.Close();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
return oOrganogramEmployee;
}
public List<OrganogramEmployee> GetByEmp(int empID)
{
List<OrganogramEmployee> oOrganogramEmployee = new List<OrganogramEmployee>();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(OrganogramEmployeeDA.GetByEmp(tc, empID));
oOrganogramEmployee = this.CreateObjects<OrganogramEmployee>(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 oOrganogramEmployee;
}
public List<OrganogramEmployee> GetByTier(int tierFrom, int tierTo)
{
List<OrganogramEmployee> oOrganogramEmployee = new List<OrganogramEmployee>();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(OrganogramEmployeeDA.GetByTier(tc, tierFrom, tierTo));
oOrganogramEmployee = this.CreateObjects<OrganogramEmployee>(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 oOrganogramEmployee;
}
public List<OrganogramEmployee> GetByGrades(string gradeIds)
{
List<OrganogramEmployee> oOrganogramEmployee = new List<OrganogramEmployee>();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(OrganogramEmployeeDA.GetByGrades(tc, gradeIds));
oOrganogramEmployee = this.CreateObjects<OrganogramEmployee>(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 oOrganogramEmployee;
}
public List<OrganogramEmployee> Get(int nodeID)
{
List<OrganogramEmployee> oOrganogramEmployee = new List<OrganogramEmployee>();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(OrganogramEmployeeDA.Get(tc, nodeID));
oOrganogramEmployee = this.CreateObjects<OrganogramEmployee>(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 oOrganogramEmployee;
}
public List<OrganogramEmployee> Get()
{
List<OrganogramEmployee> oOrganogramEmployee = new List<OrganogramEmployee>();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(OrganogramEmployeeDA.Get(tc));
oOrganogramEmployee = this.CreateObjects<OrganogramEmployee>(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 oOrganogramEmployee;
}
public List<OrganogramEmployee> GetByPositionType(EnumOGPositionType enPositionType)
{
List<OrganogramEmployee> oOrganogramEmployee = new List<OrganogramEmployee>();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(OrganogramEmployeeDA.GetByPositionType(tc, enPositionType));
oOrganogramEmployee = this.CreateObjects<OrganogramEmployee>(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 oOrganogramEmployee;
}
public List<OrganogramEmployee> GetByPositionType(TransactionContext tc, EnumOGPositionType enPositionType)
{
List<OrganogramEmployee> oOrganogramEmployee = new List<OrganogramEmployee>();
try
{
DataReader dr = new DataReader(OrganogramEmployeeDA.GetByPositionType(tc, enPositionType));
oOrganogramEmployee = this.CreateObjects<OrganogramEmployee>(dr);
dr.Close();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
return oOrganogramEmployee;
}
public List<OrganogramBasicTemp> getTopHiararchy(TransactionContext tc, int employeeid)
{
List<OrganogramBasicTemp> orgs = new List<OrganogramBasicTemp>();
//TransactionContext tc = null;
try
{
//Organogramid, PositionName, tier, POSITIONTYPEID, Manager, EMPLOYEEID, OGPOSITIONTYPE
//tc = TransactionContext.Begin();
DataReader dr = new DataReader(OrganogramEmployeeDA.getTopHiararchy(tc, employeeid));
while (dr.Read())
{
OrganogramBasicTemp org = new OrganogramBasicTemp();
org.OrganogramID = Convert.ToInt32(dr.GetInt32(0));
org.PositionName = dr.GetString(1);
org.Tier = Convert.ToInt32(dr.GetInt32(2));
var pid = dr.GetInt32(3);
if (pid != null)
org.PositionTypeID =(int) (pid);
pid = dr.GetInt32(5);
if (pid != null)
org.EmployeeID = (int)(pid);
pid = dr.GetInt32(6);
if (pid != null)
org.positionType = (EnumOGPositionType)(pid);
orgs.Add(org);
}
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 orgs;
}
#endregion
}
#endregion
}