1176 lines
41 KiB
C#
1176 lines
41 KiB
C#
using System;
|
|
using System.Data;
|
|
using System.Linq;
|
|
using Ease.Core.Model;
|
|
using Ease.Core.DataAccess;
|
|
using HRM.BO;
|
|
using System.Collections.Generic;
|
|
using Ease.Core.Utility;
|
|
|
|
namespace HRM.DA
|
|
{
|
|
#region Organogram Service
|
|
|
|
public class OrganogramService : ServiceTemplate, IOrganogramService
|
|
{
|
|
#region Private functions and declaration
|
|
|
|
public OrganogramService()
|
|
{
|
|
}
|
|
|
|
private void MapObject(OrganogramBasic oOrganogram, DataReader oReader)
|
|
{
|
|
base.SetObjectID(oOrganogram, oReader.GetInt32("OrganogramID").Value);
|
|
oOrganogram.PositionName = oReader.GetString("PositionName");
|
|
oOrganogram.ParentID = oReader.GetInt32("ParentID");
|
|
oOrganogram.Tier = oReader.GetInt32("Tier").Value;
|
|
oOrganogram.UniqueId = oReader.GetInt32("UniqueId").Value;
|
|
//oOrganogram.PositionTypeID = oReader.GetID("PositionTypeID");
|
|
oOrganogram.PositionNo = oReader.GetString("PositionNo");
|
|
oOrganogram.CompanyID = oReader.GetInt32("CompanyID", 0);
|
|
oOrganogram.DepartmentID = oReader.GetInt32("DepartmentID").Value;
|
|
oOrganogram.FunctionID = oReader.GetInt32("FunctionID", 0);
|
|
oOrganogram.GradeID = oReader.GetInt32("GradeID");
|
|
oOrganogram.DesignationID = oReader.GetInt32("DesignationID").Value;
|
|
oOrganogram.LocationID = oReader.GetInt32("LocationID").Value;
|
|
//oOrganogram.ReportingNodeID = oReader.GetID("RepotingNodeID");
|
|
oOrganogram.Tier = oReader.GetInt32("Tier").Value;
|
|
oOrganogram.Sequence = oReader.GetInt32("SequenceNO").Value;
|
|
oOrganogram.Status = (EnumStatus)oReader.GetInt32("Status").Value;
|
|
oOrganogram.JDNo = oReader.GetString("JDNo");
|
|
oOrganogram.RevisionNo = oReader.GetString("RevisionNo") == null ? "" : oReader.GetString("RevisionNo");
|
|
oOrganogram.RevisionDate = oReader.GetDateTime("RevisionDate").GetValueOrDefault();
|
|
oOrganogram.CreatedBy = oReader.GetInt32("CreatedBy").Value;
|
|
oOrganogram.CreatedDate = oReader.GetDateTime("CreationDate").Value;
|
|
oOrganogram.ModifiedBy = oReader.GetInt32("ModifiedBy");
|
|
oOrganogram.ModifiedDate = oReader.GetDateTime("ModifiedDate");
|
|
this.SetObjectState(oOrganogram, Ease.Core.ObjectState.Saved);
|
|
}
|
|
|
|
protected override T CreateObject<T>(DataReader oReader)
|
|
{
|
|
OrganogramBasic oOrganogram = new OrganogramBasic();
|
|
MapObject(oOrganogram, oReader);
|
|
return oOrganogram as T;
|
|
}
|
|
|
|
private void MapOrganAuthorityObject(OrganogramAuthority organAuthority, DataReader oReader)
|
|
{
|
|
base.SetObjectID(organAuthority, oReader.GetInt32("OrganAuthorityID").Value);
|
|
organAuthority.NodeID = oReader.GetInt32("NodeID", 0);
|
|
organAuthority.AuthorityType = (EnumAuthorityType)oReader.GetInt32("AuthorityType").Value;
|
|
organAuthority.ChildNodeID = oReader.GetInt32("ChildNodeID", 0);
|
|
organAuthority.EmployeeID = oReader.GetInt32("EmployeeID", 0);
|
|
//organAuthority.ModifiedBy = oReader.GetID("ModifiedBy");
|
|
// organAuthority.ModifiedDate = oReader.GetDateTime("ModifiedDate").Value;
|
|
this.SetObjectState(organAuthority, Ease.Core.ObjectState.Saved);
|
|
}
|
|
|
|
protected List<OrganogramAuthority> CreateOrganAuthorityObject(DataReader oReader)
|
|
{
|
|
List<OrganogramAuthority> organAuthorities = new List<OrganogramAuthority>();
|
|
while (oReader.Read())
|
|
{
|
|
OrganogramAuthority organAuthority = new OrganogramAuthority();
|
|
MapOrganAuthorityObject(organAuthority, oReader);
|
|
organAuthorities.Add(organAuthority);
|
|
}
|
|
|
|
return organAuthorities;
|
|
}
|
|
|
|
private void MapOrganDelegationObject(OrganogramDelegation organDelegation, DataReader oReader)
|
|
{
|
|
base.SetObjectID(organDelegation, oReader.GetInt32("OrganDelegationID").Value);
|
|
organDelegation.NodeID = oReader.GetInt32("NodeID", 0);
|
|
organDelegation.EmployeeID = oReader.GetInt32("EmployeeID", 0);
|
|
organDelegation.FromDate = oReader.GetDateTime("FromDate").Value;
|
|
organDelegation.ToDate = oReader.GetDateTime("ToDate").Value;
|
|
organDelegation.DelegationType = oReader.GetString("DelegationType");
|
|
organDelegation.IsActive = oReader.GetBoolean("IsActive").Value;
|
|
organDelegation.CreatedBy = oReader.GetInt32("CreatedBy", 0);
|
|
organDelegation.CreatedDate = oReader.GetDateTime("CreationDate").Value;
|
|
organDelegation.ModifiedBy = oReader.GetInt32("ModifiedBy", 0);
|
|
organDelegation.ModifiedDate = oReader.GetDateTime("ModifiedDate");
|
|
this.SetObjectState(organDelegation, Ease.Core.ObjectState.Saved);
|
|
}
|
|
|
|
public List<Employee> GetOrganogramAutoriyEmployee(List<Employee> oEmps, List<OrganogramEmployee> oOrgEmployees, List<OrganogramBasic> oOrgBasics, List<OrganogramAuthority> oOrgAuthorities, EnumAuthorityType authType, Employee oEmployee)
|
|
{
|
|
List<Employee> oInternalEmployees = new List<Employee>();
|
|
|
|
OrganogramEmployee oORgEmployee = oOrgEmployees.FirstOrDefault(x => x.EmployeeID == oEmployee.ID);
|
|
|
|
if (oORgEmployee != null)
|
|
{
|
|
OrganogramBasic orgBasic = oOrgBasics.FirstOrDefault(x => x.ID == oORgEmployee.NodeID);
|
|
|
|
if (orgBasic != null)
|
|
{
|
|
List<OrganogramAuthority> oOrgAuthority = oOrgAuthorities.Where(x => x.NodeID == orgBasic.ID && x.AuthorityType == authType).ToList();
|
|
|
|
//StringBuilder sb = new StringBuilder();
|
|
|
|
foreach (OrganogramAuthority item in oOrgAuthority)
|
|
{
|
|
OrganogramBasic orgBasicTemp = oOrgBasics.FirstOrDefault(x => x.ID == item.ChildNodeID);
|
|
if (orgBasicTemp != null)
|
|
{
|
|
Employee oEmpTemp = oEmps.FirstOrDefault(x => x.EmployeeNo.Trim().ToUpper() == orgBasicTemp.PositionNo.ToString().Trim());
|
|
if (oEmpTemp != null)
|
|
{
|
|
oInternalEmployees.Add(oEmpTemp);
|
|
//sb.AppendFormat("{0},", oEmpTemp.Name);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return oInternalEmployees;
|
|
}
|
|
|
|
protected List<OrganogramDelegation> CreateOrganDelegationObject(DataReader oReader)
|
|
{
|
|
List<OrganogramDelegation> organDelegations = new List<OrganogramDelegation>();
|
|
while (oReader.Read())
|
|
{
|
|
OrganogramDelegation organDelegation = new OrganogramDelegation();
|
|
MapOrganDelegationObject(organDelegation, oReader);
|
|
organDelegations.Add(organDelegation);
|
|
}
|
|
|
|
return organDelegations;
|
|
}
|
|
|
|
private void MapOrganJobDescObject(OrganogramJobDesc organJobDesc, DataReader oReader)
|
|
{
|
|
base.SetObjectID(organJobDesc, oReader.GetInt32("OrganJobDescID").Value);
|
|
organJobDesc.NodeID = oReader.GetInt32("NodeID", 0);
|
|
organJobDesc.Purpose = oReader.GetString("Purpose");
|
|
organJobDesc.JobSummery = oReader.GetString("JobSummery");
|
|
organJobDesc.Experience = oReader.GetString("Experience");
|
|
organJobDesc.Education = oReader.GetString("Education");
|
|
organJobDesc.CreatedBy = oReader.GetInt32("CreatedBy", 0);
|
|
organJobDesc.CreatedDate = oReader.GetDateTime("CreationDate").Value;
|
|
organJobDesc.ModifiedBy = oReader.GetInt32("ModifiedBy", 0);
|
|
//organDelegation.ModifiedDate = oReader.GetDateTime("ModifiedDate");
|
|
this.SetObjectState(organJobDesc, Ease.Core.ObjectState.Saved);
|
|
}
|
|
|
|
protected List<OrganogramJobDesc> CreateOrganJobDescObject(DataReader oReader)
|
|
{
|
|
List<OrganogramJobDesc> organJobDescs = new List<OrganogramJobDesc>();
|
|
while (oReader.Read())
|
|
{
|
|
OrganogramJobDesc organJobDesc = new OrganogramJobDesc();
|
|
MapOrganJobDescObject(organJobDesc, oReader);
|
|
organJobDescs.Add(organJobDesc);
|
|
}
|
|
|
|
return organJobDescs;
|
|
}
|
|
|
|
private void MapOrganResponsibilityObject(OrganogramResponsibility organResp, DataReader oReader)
|
|
{
|
|
base.SetObjectID(organResp, oReader.GetInt32("OrganResponsibilityID").Value);
|
|
organResp.NodeID = oReader.GetInt32("NodeID", 0);
|
|
organResp.Responsibility = oReader.GetString("Responsibility");
|
|
organResp.IsPrimary = oReader.GetBoolean("IsPrimary").Value;
|
|
//organResp.CreatedBy = oReader.GetID("CreatedBy");
|
|
//organResp.CreatedDate = oReader.GetDateTime("CreationDate").Value;
|
|
//organResp.ModifiedBy = oReader.GetID("ModifiedBy");
|
|
//organResp.ModifiedDate = oReader.GetDateTime("ModifiedDate").Value;
|
|
this.SetObjectState(organResp, Ease.Core.ObjectState.Saved);
|
|
}
|
|
|
|
protected List<OrganogramResponsibility> CreateOrganResponsibilityObject(DataReader oReader)
|
|
{
|
|
List<OrganogramResponsibility> organResponsibilities = new List<OrganogramResponsibility>();
|
|
while (oReader.Read())
|
|
{
|
|
OrganogramResponsibility organResponsibility = new OrganogramResponsibility();
|
|
MapOrganResponsibilityObject(organResponsibility, oReader);
|
|
organResponsibilities.Add(organResponsibility);
|
|
}
|
|
|
|
return organResponsibilities;
|
|
}
|
|
|
|
private void MapOrganSkilLevelObject(OrganogramSkillLevel organSlilLevel, DataReader oReader)
|
|
{
|
|
base.SetObjectID(organSlilLevel, oReader.GetInt32("OrganSkillLevelID").Value);
|
|
organSlilLevel.NodeID = oReader.GetInt32("NodeID", 0);
|
|
//organSlilLevel.NodeResponsibilityID = oReader.GetID("NodeResponsibilityID");
|
|
organSlilLevel.LevelID = oReader.GetInt32("LevelID", 0);
|
|
organSlilLevel.SkillID = oReader.GetInt32("SkillID", 0);
|
|
//organSlilLevel.CreatedBy = oReader.GetID("CreatedBy");
|
|
//organSlilLevel.CreatedDate = oReader.GetDateTime("CreationDate").Value;
|
|
//organSlilLevel.ModifiedBy = oReader.GetID("ModifiedBy");
|
|
//organSlilLevel.ModifiedDate = oReader.GetDateTime("ModifiedDate").Value;
|
|
this.SetObjectState(organSlilLevel, Ease.Core.ObjectState.Saved);
|
|
}
|
|
|
|
protected List<OrganogramSkillLevel> CreateOrganSkilLevelObject(DataReader oReader)
|
|
{
|
|
List<OrganogramSkillLevel> organSkilLevels = new List<OrganogramSkillLevel>();
|
|
while (oReader.Read())
|
|
{
|
|
OrganogramSkillLevel organSkilLevel = new OrganogramSkillLevel();
|
|
MapOrganSkilLevelObject(organSkilLevel, oReader);
|
|
organSkilLevels.Add(organSkilLevel);
|
|
}
|
|
|
|
return organSkilLevels;
|
|
}
|
|
|
|
private void MapOrganPositionObject(OrganogramPosition OrganPosition, DataReader oReader)
|
|
{
|
|
base.SetObjectID(OrganPosition, oReader.GetInt32("OrganPositionID").Value);
|
|
OrganPosition.NodeID = oReader.GetInt32("NodeID").Value;
|
|
OrganPosition.PositionTypeID = oReader.GetInt32("PositionTypeID").Value;
|
|
// OrganPosition.CreatedBy = oReader.GetInt32("CreatedBy").Value;
|
|
//OrganPosition.CreatedDate = oReader.GetDateTime("CreationDate").Value;
|
|
// OrganPosition.ModifiedBy = oReader.GetID("ModifiedBy");
|
|
// OrganPosition.ModifiedDate = oReader.GetDateTime("ModifiedDate").Value;
|
|
this.SetObjectState(OrganPosition, Ease.Core.ObjectState.Saved);
|
|
}
|
|
|
|
protected List<OrganogramPosition> CreateOrganPositionObject(DataReader oReader)
|
|
{
|
|
List<OrganogramPosition> organPositions = new List<OrganogramPosition>();
|
|
while (oReader.Read())
|
|
{
|
|
OrganogramPosition organPosition = new OrganogramPosition();
|
|
MapOrganPositionObject(organPosition, oReader);
|
|
organPositions.Add(organPosition);
|
|
}
|
|
|
|
return organPositions;
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Service implementation
|
|
|
|
#region Insert
|
|
public int Save(OrganogramBasic oOrganogram)
|
|
{
|
|
TransactionContext tc = null;
|
|
int id=0;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin(true);
|
|
id = this.Save(tc, oOrganogram);
|
|
|
|
tc.End();
|
|
|
|
return oOrganogram.ID;
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
#region Handle Exception
|
|
|
|
if (tc != null)
|
|
tc.HandleError();
|
|
ExceptionLog.Write(e);
|
|
//string smessage = "Faliled to save Organogram (table:" + tableName + ") for the Position:("
|
|
// + oOrganogram.PositionNo + ") " + oOrganogram.PositionName + ". Error :";
|
|
throw new ServiceException(e.Message, e);
|
|
|
|
#endregion
|
|
}
|
|
return id;
|
|
}
|
|
public int Save(TransactionContext tc ,OrganogramBasic oOrganogram)
|
|
{
|
|
|
|
try
|
|
{
|
|
|
|
int id = 0;
|
|
if (oOrganogram.IsNew)
|
|
{
|
|
id = tc.GenerateID("Organogram", "OrganogramID");
|
|
base.SetObjectID(oOrganogram, (id));
|
|
OrganogramDA.Insert(tc, oOrganogram);
|
|
}
|
|
else
|
|
{
|
|
OrganogramDA.Update(tc, oOrganogram);
|
|
OrganogramDA.DeleteOrganAuthority(tc, oOrganogram.ID);
|
|
OrganogramDA.DeleteOrganDelegation(tc, oOrganogram.ID);
|
|
OrganogramDA.DeleteOranJobDesc(tc, oOrganogram.ID);
|
|
OrganogramDA.DeleteOrganResponsibility(tc, oOrganogram.ID);
|
|
OrganogramDA.DeleteOrganSkilLevel(tc, oOrganogram.ID);
|
|
OrganogramDA.DeleteOrganPosition(tc, oOrganogram.ID);
|
|
}
|
|
|
|
//tableName = "OrganAuthority";
|
|
foreach (OrganogramAuthority organAuthor in oOrganogram.OrganAuthority)
|
|
{
|
|
id = tc.GenerateID("OrganAuthority", "OrganAuthorityID");
|
|
organAuthor.NodeID = oOrganogram.ID;
|
|
base.SetObjectID(organAuthor, (id));
|
|
OrganogramDA.Insert(tc, organAuthor);
|
|
}
|
|
|
|
//tableName = "OrganDelegation";
|
|
foreach (OrganogramDelegation organDele in oOrganogram.OrganDelegation)
|
|
{
|
|
id = tc.GenerateID("OrganDelegation", "OrganDelegationID");
|
|
organDele.NodeID = oOrganogram.ID;
|
|
base.SetObjectID(organDele, (id));
|
|
OrganogramDA.Insert(tc, organDele);
|
|
}
|
|
|
|
//tableName = "OrganJobDescription";
|
|
foreach (OrganogramJobDesc organJob in oOrganogram.OrganJobDesc)
|
|
{
|
|
id = tc.GenerateID("OrganJobDescription", "OrganJobDescID");
|
|
organJob.NodeID = oOrganogram.ID;
|
|
organJob.CreatedBy = oOrganogram.CreatedBy;
|
|
organJob.CreatedDate = oOrganogram.CreatedDate;
|
|
base.SetObjectID(organJob, (id));
|
|
OrganogramDA.Insert(tc, organJob);
|
|
}
|
|
|
|
//tableName = "OrganResponsibility";
|
|
foreach (OrganogramResponsibility organRes in oOrganogram.OrganResponsibility)
|
|
{
|
|
id = tc.GenerateID("OrganResponsibility", "OrganResponsibilityID");
|
|
organRes.NodeID = oOrganogram.ID;
|
|
base.SetObjectID(organRes, (id));
|
|
OrganogramDA.Insert(tc, organRes);
|
|
}
|
|
|
|
|
|
//tableName = "OrganSkillLevel";
|
|
foreach (OrganogramSkillLevel organSkillLvl in oOrganogram.OrganSkillLevel)
|
|
{
|
|
id = tc.GenerateID("OrganSkillLevel", "OrganSkillLevelID");
|
|
organSkillLvl.NodeID = oOrganogram.ID;
|
|
base.SetObjectID(organSkillLvl, (id));
|
|
OrganogramDA.Insert(tc, organSkillLvl);
|
|
}
|
|
|
|
//tableName = "OrganPosition";
|
|
if (oOrganogram.OrganPositions != null)
|
|
{
|
|
foreach (OrganogramPosition organPosn in oOrganogram.OrganPositions)
|
|
{
|
|
id = tc.GenerateID("OrganPosition", "OrganPositionID");
|
|
organPosn.NodeID = oOrganogram.ID;
|
|
base.SetObjectID(organPosn, (id));
|
|
OrganogramDA.Insert(tc, organPosn);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
return oOrganogram.ID;
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
#region Handle Exception
|
|
|
|
if (tc != null)
|
|
tc.HandleError();
|
|
ExceptionLog.Write(e);
|
|
//string smessage = "Faliled to save Organogram (table:" + tableName + ") for the Position:("
|
|
// + oOrganogram.PositionNo + ") " + oOrganogram.PositionName + ". Error :";
|
|
throw new ServiceException(e.Message, e);
|
|
|
|
#endregion
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Delete
|
|
|
|
public void Delete(int id)
|
|
{
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin(true);
|
|
OrganogramDA.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 DeleteAll()
|
|
{
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin(true);
|
|
OrganogramDA.DeleteAll(tc);
|
|
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 Get
|
|
|
|
public List<OrganogramAuthority> GetAllOrganAuthority()
|
|
{
|
|
|
|
List<OrganogramAuthority> Organograms = new List<OrganogramAuthority>();
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin();
|
|
DataReader dr = new DataReader(OrganogramDA.GetAllOrganAuthority(tc));
|
|
Organograms = this.CreateOrganAuthorityObject(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 Organograms;
|
|
}
|
|
|
|
public OrganogramBasic GetbyEmployeeid(int employeeid)
|
|
{
|
|
List<OrganogramBasic> Organograms = new List<OrganogramBasic>();
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin();
|
|
DataReader dr = new DataReader(OrganogramDA.GetbyEmployeeID(tc, employeeid));
|
|
Organograms = this.CreateObjects<OrganogramBasic>(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
|
|
}
|
|
|
|
if (Organograms != null && Organograms.Count > 0)
|
|
return Organograms[0];
|
|
else return null;
|
|
}
|
|
|
|
public int GetMaxTier(TransactionContext tc)
|
|
{
|
|
int maxLevel = 0;
|
|
try
|
|
{
|
|
#region Retrieving data
|
|
|
|
maxLevel = OrganogramDA.GetMaxTier(tc);
|
|
|
|
#endregion
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
#region Handle Exception
|
|
|
|
if (tc != null)
|
|
tc.HandleError();
|
|
|
|
throw new ServiceException(e.Message, e);
|
|
|
|
#endregion
|
|
}
|
|
|
|
return maxLevel;
|
|
}
|
|
|
|
public OrganogramBasic Get(int id)
|
|
{
|
|
OrganogramBasic oOrganogram = null;
|
|
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin();
|
|
DataReader oreader = new DataReader(OrganogramDA.Get(tc, id));
|
|
if (oreader.Read())
|
|
{
|
|
oOrganogram = this.CreateObject<OrganogramBasic>(oreader);
|
|
}
|
|
|
|
oreader.Close();
|
|
if (oOrganogram != null)
|
|
{
|
|
OrganogramEmployeeService ore = new OrganogramEmployeeService();
|
|
oOrganogram.OrganEmployees = ore.Get(tc, oOrganogram.ID);
|
|
|
|
DataReader dr = new DataReader(OrganogramDA.Get4OrganPosition(tc, oOrganogram.ID));
|
|
oOrganogram.OrganPositions = this.CreateOrganPositionObject(dr);
|
|
dr.Close();
|
|
|
|
//dr = new DataReader(OrganogramDA.Get4OrganAuthority(tc, oOrganogram.ID));
|
|
//oOrganogram.OrganAuthority = this.CreateOrganAuthorityObject(dr);
|
|
//dr.Close();
|
|
|
|
//dr = new DataReader(OrganogramDA.Get4OrganJobDesc(tc, oOrganogram.ID));
|
|
//oOrganogram.OrganJobDesc = this.CreateOrganJobDescObject(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 oOrganogram;
|
|
}
|
|
|
|
public List<OrganogramBasic> Get(EnumStatus status)
|
|
{
|
|
List<OrganogramBasic> Organograms = new List<OrganogramBasic>();
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin();
|
|
DataReader dr = new DataReader(OrganogramDA.Get(tc, status));
|
|
Organograms = this.CreateObjects<OrganogramBasic>(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 Organograms;
|
|
}
|
|
|
|
public List<OrganogramBasic> GetbyTier(int fromTier, int toTier)
|
|
{
|
|
List<OrganogramBasic> Organograms = new List<OrganogramBasic>();
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin();
|
|
DataReader dr = new DataReader(OrganogramDA.GetbyTier(tc, fromTier, toTier));
|
|
Organograms = this.CreateObjects<OrganogramBasic>(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 Organograms;
|
|
}
|
|
|
|
public List<OrganogramBasic> GetbyPositionTypeID(int postiontypeid)
|
|
{
|
|
List<OrganogramBasic> Organograms = null;
|
|
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin();
|
|
DataReader dr = new DataReader(OrganogramDA.GetbyPositionType(tc, postiontypeid));
|
|
Organograms = this.CreateObjects<OrganogramBasic>(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 Organograms;
|
|
}
|
|
|
|
public List<OrganogramBasic> GetTopParents(EnumStatus status)
|
|
{
|
|
List<OrganogramBasic> items = new List<OrganogramBasic>();
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin();
|
|
DataReader dr = new DataReader(OrganogramDA.GetTopParents(tc, status));
|
|
items = this.CreateObjects<OrganogramBasic>(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 items;
|
|
}
|
|
|
|
public List<OrganogramBasic> GetByParentID(int parentID, EnumStatus status)
|
|
{
|
|
List<OrganogramBasic> items = new List<OrganogramBasic>();
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin();
|
|
DataReader dr = new DataReader(OrganogramDA.GetByParentID(tc, parentID, status));
|
|
items = this.CreateObjects<OrganogramBasic>(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 items;
|
|
}
|
|
|
|
|
|
public List<OrganogramAuthority> Get4OrganAuthority(int nodeID)
|
|
{
|
|
List<OrganogramAuthority> Organograms = new List<OrganogramAuthority>();
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin();
|
|
DataReader dr = new DataReader(OrganogramDA.Get4OrganAuthority(tc, nodeID));
|
|
Organograms = this.CreateOrganAuthorityObject(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 Organograms;
|
|
}
|
|
|
|
public List<OrganogramDelegation> Get4OrganDelegation(int nodeID)
|
|
{
|
|
List<OrganogramDelegation> Organograms = new List<OrganogramDelegation>();
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin();
|
|
DataReader dr = new DataReader(OrganogramDA.Get4OrganDelegation(tc, nodeID));
|
|
Organograms = this.CreateOrganDelegationObject(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 Organograms;
|
|
}
|
|
|
|
public List<OrganogramJobDesc> Get4OrganJobDesc(int nodeID)
|
|
{
|
|
List<OrganogramJobDesc> Organograms = new List<OrganogramJobDesc>();
|
|
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin();
|
|
DataReader dr = new DataReader(OrganogramDA.Get4OrganJobDesc(tc, nodeID));
|
|
Organograms = this.CreateOrganJobDescObject(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 Organograms;
|
|
}
|
|
|
|
public List<OrganogramResponsibility> Get4OrganResponsibility(int nodeId)
|
|
{
|
|
List<OrganogramResponsibility> Organograms = new List<OrganogramResponsibility>();
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin();
|
|
DataReader dr = new DataReader(OrganogramDA.Get4OrganResponsibility(tc, nodeId));
|
|
Organograms = this.CreateOrganResponsibilityObject(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 Organograms;
|
|
}
|
|
|
|
public List<OrganogramSkillLevel> Get4OrganSkilLevel(int nodeID)
|
|
{
|
|
List<OrganogramSkillLevel> Organograms = new List<OrganogramSkillLevel>();
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin();
|
|
DataReader dr = new DataReader(OrganogramDA.Get4OrganSkilLevel(tc, nodeID));
|
|
Organograms = this.CreateOrganSkilLevelObject(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 Organograms;
|
|
}
|
|
|
|
public List<OrganogramPosition> Get4OrganPosition(int nodeID)
|
|
{
|
|
List<OrganogramPosition> Organograms = new List<OrganogramPosition>();
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin();
|
|
DataReader dr = new DataReader(OrganogramDA.Get4OrganPosition(tc, nodeID));
|
|
Organograms = this.CreateOrganPositionObject(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 Organograms;
|
|
}
|
|
|
|
public List<OrganogramPosition> GetAllOrganPosition()
|
|
{
|
|
List<OrganogramPosition> Organograms = new List<OrganogramPosition>();
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin();
|
|
DataReader dr = new DataReader(OrganogramDA.GetAllOrganPosition(tc));
|
|
Organograms = this.CreateOrganPositionObject(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 Organograms;
|
|
}
|
|
|
|
public List<OrganogramAuthority> GetOrganAuthorityByEmp(int EmpID)
|
|
{
|
|
List<OrganogramAuthority> Organograms = new List<OrganogramAuthority>();
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin();
|
|
DataReader dr = new DataReader(OrganogramDA.GetOrganAuthorityByEmp(tc, EmpID));
|
|
Organograms = this.CreateOrganAuthorityObject(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 Organograms;
|
|
}
|
|
|
|
public DataTable GetManagers(string sEmpIDs)
|
|
{
|
|
DataTable dataTableOfEmployee = new DataTable("Employee");
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin();
|
|
|
|
DataSet dataSet = OrganogramDA.GetManagers(tc, sEmpIDs);
|
|
dataTableOfEmployee = dataSet.Tables[0];
|
|
dataSet.Dispose();
|
|
tc.End();
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
#region Handle Exception
|
|
|
|
if (tc != null)
|
|
tc.HandleError();
|
|
ExceptionLog.Write(e);
|
|
|
|
throw new ServiceException(e.Message, e);
|
|
|
|
#endregion
|
|
}
|
|
|
|
return dataTableOfEmployee;
|
|
}
|
|
|
|
|
|
|
|
public void UpdateParentAndTier(List<OrganogramBasic> oNodes)
|
|
{
|
|
try
|
|
{
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
#region Update data
|
|
|
|
tc = TransactionContext.Begin(true);
|
|
foreach (OrganogramBasic oNode in oNodes)
|
|
{
|
|
OrganogramDA.UpdateParentAndTier(tc, oNode);
|
|
if(oNode.ParentID !=null)
|
|
HREmployeeDA.updateLineManagerOnlyByOrganogram(tc, oNode);
|
|
}
|
|
|
|
tc.End();
|
|
|
|
#endregion
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
#region Handle Exception
|
|
|
|
if (tc != null)
|
|
tc.HandleError();
|
|
throw new ServiceException(e.Message, e);
|
|
|
|
#endregion
|
|
}
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
throw new ServiceException(e.Message, e);
|
|
}
|
|
}
|
|
|
|
public int GetMinNodeIdByDept(int deptID)
|
|
{
|
|
OrganogramBasic oOrganogram = null;
|
|
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin();
|
|
DataReader oreader = new DataReader(OrganogramDA.GetMinNodeIdByDept(tc, deptID));
|
|
if (oreader.Read())
|
|
{
|
|
oOrganogram = this.CreateObject<OrganogramBasic>(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
|
|
}
|
|
|
|
if (oOrganogram == null) return 0;
|
|
else return oOrganogram.ID;
|
|
}
|
|
|
|
public void CreateOrgFromEmployee(int userid)
|
|
{
|
|
List<Employee> emps = new EmployeeService().GetAllEmps();
|
|
List<Designation> desgs = new DesignationService().GetAll();
|
|
List<Employee> parents = emps.FindAll(x => x.LineManagerID == null);
|
|
this.DeleteAll();
|
|
if (parents!=null)
|
|
{
|
|
foreach(Employee emp in parents )
|
|
{
|
|
if (emp.Status == EnumEmployeeStatus.Live)
|
|
this.CreateOrgFromEmp(emps, userid, emp.ID, null,1, desgs);
|
|
}
|
|
}
|
|
}
|
|
public void CreateOrgFromEmp(List<Employee> emps,int userid, int empID, int? nodeid,int tier, List<Designation> designations )
|
|
{
|
|
OrganogramBasic obasic = new OrganogramBasic();
|
|
Employee oemp = emps.FirstOrDefault(x => x.ID == empID);
|
|
var deg = designations.FirstOrDefault(x => x.ID == oemp.DesignationID);
|
|
if (deg != null)
|
|
obasic.PositionName = deg.Name;
|
|
if(oemp.DesignationID!=null)
|
|
obasic.DesignationID =(int) oemp.DesignationID;
|
|
if (oemp.LocationID != null)
|
|
obasic.LocationID =(int) oemp.LocationID;
|
|
if (oemp.GradeID != null)
|
|
obasic.GradeID = oemp.GradeID;
|
|
if (oemp.DepartmentID != null)
|
|
obasic.DepartmentID =(int) oemp.DepartmentID;
|
|
if (nodeid != null)
|
|
obasic.ParentID =(int) nodeid;
|
|
OrganogramEmployee oge = new OrganogramEmployee();
|
|
oge.EmployeeID = empID;
|
|
oge.CreatedBy = userid;
|
|
oge.CreatedDate = DateTime.Today;
|
|
obasic.OrganEmployees = new List<OrganogramEmployee>();
|
|
obasic.OrganEmployees.Add(oge);
|
|
obasic.CreatedBy = userid;
|
|
obasic.CreatedDate = DateTime.Today;
|
|
obasic.Tier = tier;
|
|
this.Save(obasic);
|
|
oge.AssignDate = DateTime.Today;
|
|
oge.NodeID = obasic.ID;
|
|
new OrganogramEmployeeService().Save(oge);
|
|
|
|
List<Employee> childs = emps.FindAll(x => x.LineManagerID == empID);
|
|
if(childs!= null)
|
|
{
|
|
foreach(Employee item in childs)
|
|
{
|
|
if(item.Status == EnumEmployeeStatus.Live)
|
|
CreateOrgFromEmp(emps, userid, item.ID, obasic.ID, tier +1, designations);
|
|
}
|
|
}
|
|
}
|
|
public DataSet GetOrganogramNodes(int nNodeID)
|
|
{
|
|
DataSet ds = new DataSet();
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin();
|
|
ds = OrganogramDA.GetOrganogramNodes(tc, nNodeID);
|
|
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 DataSet GetLMOrganogramNodes(int nNodeID)
|
|
{
|
|
DataSet ds = new DataSet();
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin();
|
|
ds = OrganogramDA.GetLMOrganogramNodes(tc, nNodeID);
|
|
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 int MaxTier()
|
|
{
|
|
int tier = 0;
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin();
|
|
tier = OrganogramDA.MaxTier(tc);
|
|
tc.End();
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
#region Handle Exception
|
|
|
|
if (tc != null)
|
|
tc.HandleError();
|
|
ExceptionLog.Write(e);
|
|
throw new ServiceException(e.Message, e);
|
|
|
|
#endregion
|
|
}
|
|
|
|
return tier;
|
|
}
|
|
|
|
#endregion
|
|
|
|
#endregion
|
|
}
|
|
|
|
#endregion
|
|
} |