CEL_Payroll/Payroll.BO/Organogram/OrganogramBasic.cs

813 lines
23 KiB
C#
Raw Permalink Normal View History

2024-09-17 14:30:13 +06:00
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Ease.CoreV35;
using Ease.CoreV35.Model;
using Ease.CoreV35.Caching;
using System.Data.Linq.Mapping;
namespace Payroll.BO
{
#region Organogram
[Serializable]
public class OrganogramBasic : BasicBaseObject
{
#region Cache Store
private static Cache _cache = new Cache(typeof(OrganogramBasic));
#endregion
#region Constructor
public OrganogramBasic()
{
_positionName = string.Empty;
_parentID = null;
_tier = 0;
_uniqueId = 0;
//_positionTypeID = null;
_positionNo = string.Empty;
_companyID = null;
_departmentID = null;
_functionID = null;
_gradeID = null;
_designationID = null;
_locationID = null;
//_reportingNodeID = null;
//_employeeID = null;
_parent = null;
_oChilds = null;
//_positionNo = string.Empty;
_jdNo = string.Empty;
_revisionNo = string.Empty;
_revisionDate = DateTime.MinValue;
}
#endregion
#region Properties
#region positionName : string
private string _positionName;
public string PositionName
{
get { return _positionName; }
set
{
base.OnPropertyChange<string>("positionName", _positionName, value);
_positionName = value;
}
}
#endregion
#region parentID : ID
private ID _parentID;
public ID ParentID
{
get { return _parentID; }
set
{
base.OnPropertyChange<ID>("parentID", _parentID, value);
_parentID = value;
}
}
#endregion
#region tier : int
private int _tier;
public int Tier
{
get { return _tier; }
set
{
base.OnPropertyChange<int>("tier", _tier, value);
_tier = value;
}
}
#endregion
#region uniqueId : int
private int _uniqueId;
public int UniqueId
{
get { return _uniqueId; }
set
{
base.OnPropertyChange<int>("uniqueId", _uniqueId, value);
_uniqueId = value;
}
}
#endregion
#region positionNo : string
private string _positionNo;
public string PositionNo
{
get { return _positionNo; }
set
{
base.OnPropertyChange<string>("positionNo", _positionNo, value);
_positionNo = value;
}
}
#endregion
#region companyID : ID
private ID _companyID;
public ID CompanyID
{
get { return _companyID; }
set
{
base.OnPropertyChange<ID>("companyID", _companyID, value);
_companyID = value;
}
}
#endregion
#region departmentID : ID
private ID _departmentID;
public ID DepartmentID
{
get { return _departmentID; }
set
{
base.OnPropertyChange<ID>("DepartmentID", _departmentID, value);
_departmentID = value;
}
}
#endregion
#region functionID : ID
private ID _functionID;
public ID FunctionID
{
get { return _functionID; }
set
{
base.OnPropertyChange<ID>("functionID", _functionID, value);
_functionID = value;
}
}
#endregion
#region gradeID : ID
private ID _gradeID;
public ID GradeID
{
get { return _gradeID; }
set
{
base.OnPropertyChange<ID>("gradeID", _gradeID, value);
_gradeID = value;
}
}
#endregion
#region designationID : ID
private ID _designationID;
public ID DesignationID
{
get { return _designationID; }
set
{
base.OnPropertyChange<ID>("designationID", _designationID, value);
_designationID = value;
}
}
#endregion
#region locationID : ID
private ID _locationID;
public ID LocationID
{
get { return _locationID; }
set
{
base.OnPropertyChange<ID>("locationID", _locationID, value);
_locationID = value;
}
}
#endregion
#region JDNo : string
private string _jdNo;
public string JDNo
{
get { return _jdNo; }
set
{
base.OnPropertyChange<string>("jdNo", _jdNo, value);
_jdNo = value;
}
}
#endregion
#region RevisionNo
private string _revisionNo;
public string RevisionNo
{
get { return _revisionNo; }
set
{
base.OnPropertyChange<string>("revisionNo", _revisionNo, value);
_revisionNo = value;
}
}
#endregion
#region RevisionDate
private DateTime _revisionDate;
public DateTime RevisionDate
{
get { return _revisionDate; }
set
{
base.OnPropertyChange<DateTime>("revisionDate", _revisionDate, value);
_revisionDate = value;
}
}
#endregion
#region OrganAuthority : OrganogramAuthority
private ObjectsTemplate<OrganogramAuthority> _organAuthority;
public ObjectsTemplate<OrganogramAuthority> OrganAuthority
{
get
{
if (_organAuthority == null) _organAuthority = new ObjectsTemplate<OrganogramAuthority>();
return _organAuthority;
}
set
{
_organAuthority = value;
}
}
#endregion
#region OrganDelegation : OrganogramDelegation
private ObjectsTemplate<OrganogramDelegation> _organDelegation;
public ObjectsTemplate<OrganogramDelegation> OrganDelegation
{
get
{
if (_organDelegation == null) _organDelegation = new ObjectsTemplate<OrganogramDelegation>();
return _organDelegation;
}
set
{
_organDelegation = value;
}
}
#endregion
#region OrganJobDesc : OrganogramJobDesc
private ObjectsTemplate<OrganogramJobDesc> _organJobDesc;
public ObjectsTemplate<OrganogramJobDesc> OrganJobDesc
{
get
{
if (_organJobDesc == null) _organJobDesc = new ObjectsTemplate<OrganogramJobDesc>();
return _organJobDesc;
}
set
{
_organJobDesc = value;
}
}
#endregion
#region OrganResponsibility : OrganogramResponsibility
private ObjectsTemplate<OrganogramResponsibility> _organResponsibility;
public ObjectsTemplate<OrganogramResponsibility> OrganResponsibility
{
get
{
if (_organResponsibility == null) _organResponsibility = new ObjectsTemplate<OrganogramResponsibility>();
return _organResponsibility;
}
set
{
_organResponsibility = value;
}
}
#endregion
#region OrganSkillLevel : OrganogramSkillLevel
private ObjectsTemplate<OrganogramSkillLevel> _organSkillLevel;
public ObjectsTemplate<OrganogramSkillLevel> OrganSkillLevel
{
get
{
if (_organSkillLevel == null) _organSkillLevel = new ObjectsTemplate<OrganogramSkillLevel>();
return _organSkillLevel;
}
set
{
_organSkillLevel = value;
}
}
#endregion
#region OrganPosition : OrganogramPosition
private OrganogramBasic _parent;
public OrganogramBasic Parent
{
get
{
if (_parent == null )
{
if (!_parentID.IsUnassigned) _parent = OrganogramBasic.Get(_parentID);
else return null;
}
return _parent;
}
set
{
_parent = value;
}
}
#endregion
#region ChildNodes
private ObjectsTemplate<OrganogramBasic> _oChilds;
public ObjectsTemplate<OrganogramBasic> Childs
{
get
{
if (_oChilds == null)
{
_oChilds = new ObjectsTemplate<OrganogramBasic>();
_oChilds = OrganogramBasic.GetByParentId(this.ID,EnumStatus.Regardless);
}
return _oChilds;
}
set { _oChilds = value; }
}
#endregion
#region OrganPosition : OrganogramPosition
private ObjectsTemplate<OrganogramPosition> _organPositions;
public ObjectsTemplate<OrganogramPosition> OrganPositions
{
get
{
if (_organPositions == null && !this.ID.IsUnassigned && this.ID.Integer > 0)
{
_organPositions = OrganogramBasic.Get4OrganPosition(this.ID);
}
return this._organPositions;
}
set
{
_organPositions = value;
}
}
#endregion
public ObjectsTemplate<OrganogramBasic> GetAthorities(EnumAuthorityType type)
{
ObjectsTemplate<OrganogramBasic> oobjects = new ObjectsTemplate<OrganogramBasic>();
foreach (OrganogramAuthority oitem in this.OrganAuthority)
{
if (oitem.AuthorityType == type)
{
OrganogramBasic organogram = OrganogramBasic.Get(oitem.ChildNodeID);
oobjects.Add(organogram);
}
}
return oobjects;
}
#region OrganEmployee : OrganEmployees
private ObjectsTemplate<OrganogramEmployee> _organEmployees;
public ObjectsTemplate<OrganogramEmployee> OrganEmployees
{
get
{
if (_organEmployees == null && !this.ID.IsUnassigned && this.ID.Integer > 0)
_organEmployees = OrganogramEmployee.Get(this.ID);
return _organEmployees;
}
set
{
_organEmployees = value;
}
}
#endregion
/// <summary>
/// Return assgined employee, if multiple employee assigned, first employee will be returned.
/// </summary>
/// <returns></returns>
public Employee GetAssignedEmployee()
{
Employee oEmp = null;
if (EmployeeAssigned==false)
throw new Exception("Employee not yet assigned in this position");
oEmp = _organEmployees[0].Employee;
return oEmp;
}
public bool EmployeeAssigned
{
get
{
if (this.OrganEmployees != null && this.OrganEmployees.Count > 0)
return true;
else
return false;
}
}
#region Service Factory IOrganogramService : IOrganogramService
internal static IOrganogramService Service
{
get { return Services.Factory.CreateService<IOrganogramService>(typeof(IOrganogramService)); }
}
#endregion
#endregion
#region Functions
#region Save
public ID Save()
{
this.SetAuditTrailProperties();
return OrganogramBasic.Service.Save(this);
}
#endregion
#region Delete
public void Delete(ID id)
{
OrganogramBasic.Service.Delete(id);
}
#endregion
#region Get
/// <summary>
/// get oranogram node along with node authorities, employees, job-description,
/// skill-lebel, positions
/// </summary>
/// <param name="nID">Oranogram Node ID</param>
/// <returns></returns>
public static OrganogramBasic Get(ID nodeID)
{
OrganogramBasic oOrganogram = null;
#region Cache Header
oOrganogram = (OrganogramBasic)_cache["Get", nodeID];
if (oOrganogram != null)
return oOrganogram;
#endregion
oOrganogram = OrganogramBasic.Service.Get(nodeID);
#region Cache Footer
_cache.Add(oOrganogram, "Get", nodeID);
#endregion
return oOrganogram;
}
public static OrganogramBasic GetbyEmployeeid(ID employeeid)
{
OrganogramBasic oOrganogram = null;
oOrganogram = OrganogramBasic.Service.GetbyEmployeeid(employeeid);
return oOrganogram;
}
public static ObjectsTemplate<OrganogramBasic> Get(EnumStatus nstatus)
{
#region Cache Header
ObjectsTemplate<OrganogramBasic> organograms = _cache["Get"] as ObjectsTemplate<OrganogramBasic>;
if (organograms != null)
return organograms;
#endregion
try
{
organograms = Service.Get(nstatus);
}
catch (ServiceException e)
{
throw new Exception(e.Message, e);
}
#region Cache Footer
_cache.Add(organograms, "Get");
#endregion
return organograms;
}
/// <summary>
/// get organogram node(s)
/// </summary>
/// <param name="parentID">Oranogram Node Id</param>
/// <returns></returns>
public static ObjectsTemplate<OrganogramBasic> GetByParentId(ID parentID,EnumStatus status)
{
ObjectsTemplate<OrganogramBasic> items;
#region CacheHeader
items = (ObjectsTemplate<OrganogramBasic>)_cache["GetByParentId"];
if (items != null)
return items;
#endregion
try
{
items = OrganogramBasic.Service.GetByParentID(parentID,status);
}
catch (ServiceException e)
{
throw new ServiceException(e.Message, e);
}
#region CacheFooter
_cache.Add(items, "GetByParentId");
#endregion
return items;
}
/// <summary>
/// get the organogram node(s), does not have parent (null)
/// </summary>
/// <returns></returns>
public static ObjectsTemplate<OrganogramBasic> GetTopParents(EnumStatus nstatus)
{
ObjectsTemplate<OrganogramBasic> items;
try
{
items = OrganogramBasic.Service.GetTopParents(nstatus);
}
catch (ServiceException e)
{
throw new ServiceException(e.Message, e);
}
return items;
}
public static ObjectsTemplate<OrganogramAuthority> Get4OrganAuthority(ID organAuthorityID)
{
#region Cache Header
ObjectsTemplate<OrganogramAuthority> oOrganAuthority = _cache["Get4OrganAuthority", organAuthorityID] as ObjectsTemplate<OrganogramAuthority>;
if (oOrganAuthority != null)
return oOrganAuthority;
#endregion
try
{
oOrganAuthority = Service.Get4OrganAuthority(organAuthorityID);
}
catch (ServiceException e)
{
throw new Exception(e.Message, e);
}
#region Cache Footer
_cache.Add(oOrganAuthority, "Get4OrganAuthority", organAuthorityID);
#endregion
return oOrganAuthority;
}
public static ObjectsTemplate<OrganogramDelegation> Get4OrganDelegation(ID organDelegationID)
{
#region Cache Header
ObjectsTemplate<OrganogramDelegation> oOrganogramDelegation = _cache["Get4OrganDelegation", organDelegationID] as ObjectsTemplate<OrganogramDelegation>;
if (oOrganogramDelegation != null)
return oOrganogramDelegation;
#endregion
try
{
oOrganogramDelegation = Service.Get4OrganDelegation(organDelegationID);
}
catch (ServiceException e)
{
throw new Exception(e.Message, e);
}
#region Cache Footer
_cache.Add(oOrganogramDelegation, "Get4OrganDelegation", organDelegationID);
#endregion
return oOrganogramDelegation;
}
public static ObjectsTemplate<OrganogramJobDesc> Get4OrganJobDesc(ID organJobDescID)
{
#region Cache Header
ObjectsTemplate<OrganogramJobDesc> oOrganogramJobDesc = _cache["Get4OrganJobDesc", organJobDescID] as ObjectsTemplate<OrganogramJobDesc>;
if (oOrganogramJobDesc != null)
return oOrganogramJobDesc;
#endregion
try
{
oOrganogramJobDesc = Service.Get4OrganJobDesc(organJobDescID);
}
catch (ServiceException e)
{
throw new Exception(e.Message, e);
}
#region Cache Footer
_cache.Add(oOrganogramJobDesc, "Get4OrganJobDesc", organJobDescID);
#endregion
return oOrganogramJobDesc;
}
public static ObjectsTemplate<OrganogramResponsibility> Get4OrganResponsibility(ID organResponsibilityID)
{
#region Cache Header
ObjectsTemplate<OrganogramResponsibility> oOrganogramResponsibility = _cache["Get4OrganResponsibility", organResponsibilityID] as ObjectsTemplate<OrganogramResponsibility>;
if (oOrganogramResponsibility != null)
return oOrganogramResponsibility;
#endregion
try
{
oOrganogramResponsibility = Service.Get4OrganResponsibility(organResponsibilityID);
}
catch (ServiceException e)
{
throw new Exception(e.Message, e);
}
#region Cache Footer
_cache.Add(oOrganogramResponsibility, "Get4OrganResponsibility", organResponsibilityID);
#endregion
return oOrganogramResponsibility;
}
public static ObjectsTemplate<OrganogramSkillLevel> Get4OrganSkilLevel(ID organSkilLevelID)
{
#region Cache Header
ObjectsTemplate<OrganogramSkillLevel> oOrganogramSkillLevel = _cache["Get4OrganSkilLevel", organSkilLevelID] as ObjectsTemplate<OrganogramSkillLevel>;
if (oOrganogramSkillLevel != null)
return oOrganogramSkillLevel;
#endregion
try
{
oOrganogramSkillLevel = Service.Get4OrganSkilLevel(organSkilLevelID);
}
catch (ServiceException e)
{
throw new Exception(e.Message, e);
}
#region Cache Footer
_cache.Add(oOrganogramSkillLevel, "Get4OrganSkilLevel", organSkilLevelID);
#endregion
return oOrganogramSkillLevel;
}
public static ObjectsTemplate<OrganogramPosition> Get4OrganPosition(ID organPositionID)
{
#region Cache Header
ObjectsTemplate<OrganogramPosition> oOrganogramPosition = _cache["Get4OrganPosition", organPositionID] as ObjectsTemplate<OrganogramPosition>;
if (oOrganogramPosition != null)
return oOrganogramPosition;
#endregion
try
{
oOrganogramPosition = Service.Get4OrganPosition(organPositionID);
}
catch (ServiceException e)
{
throw new Exception(e.Message, e);
}
#region Cache Footer
_cache.Add(oOrganogramPosition, "Get4OrganPosition", organPositionID);
#endregion
return oOrganogramPosition;
}
public static ObjectsTemplate<OrganogramBasic> GetbyPositionTypeid(ID positiontypeid)
{
ObjectsTemplate<OrganogramBasic> oOrganogramPosition = null;
try
{
oOrganogramPosition = Service.GetbyPositionTypeID(positiontypeid);
}
catch (ServiceException e)
{
throw new Exception(e.Message, e);
}
return oOrganogramPosition;
}
public static ObjectsTemplate<OrganogramPosition> GetAllOrganPosition()
{
ObjectsTemplate<OrganogramPosition> oOrganogramPosition = null;
try
{
oOrganogramPosition = Service.GetAllOrganPosition();
}
catch (ServiceException e)
{
throw new Exception(e.Message, e);
}
return oOrganogramPosition;
}
public static ID GetMinNodeIdByDept(ID deptID)
{
ID nNodeID = null;
nNodeID = OrganogramBasic.Service.GetMinNodeIdByDept(deptID);
return nNodeID;
}
public void UpdateParentAndTier(ObjectsTemplate<OrganogramBasic> oOrganNodes)
{
try
{
OrganogramBasic.Service.UpdateParentAndTier(oOrganNodes);
}
catch (ServiceException e)
{
throw new ServiceException(e.Message, e);
}
}
#endregion
#endregion
}
#endregion
#region IOrganogram Service
public interface IOrganogramService
{
ID Save(OrganogramBasic item);
void Delete(ID id);
OrganogramBasic Get(ID id);
OrganogramBasic GetbyEmployeeid(ID EmployeeID);
ObjectsTemplate<OrganogramBasic> Get( EnumStatus status);
ObjectsTemplate<OrganogramBasic> GetByParentID(ID parentID,EnumStatus status);
ID GetMinNodeIdByDept(ID deptID);
ObjectsTemplate<OrganogramBasic> GetTopParents(EnumStatus status);
ObjectsTemplate<OrganogramAuthority> Get4OrganAuthority(ID NodeID);
ObjectsTemplate<OrganogramDelegation> Get4OrganDelegation(ID NodeID);
ObjectsTemplate<OrganogramJobDesc> Get4OrganJobDesc(ID NodeID);
ObjectsTemplate<OrganogramResponsibility> Get4OrganResponsibility(ID NodeID);
ObjectsTemplate<OrganogramSkillLevel> Get4OrganSkilLevel(ID NodeID);
ObjectsTemplate<OrganogramPosition> Get4OrganPosition(ID NodeID);
ObjectsTemplate<OrganogramBasic> GetbyPositionTypeID(ID positionTypeid);
void UpdateParentAndTier(ObjectsTemplate<OrganogramBasic> oNodes);
ObjectsTemplate<OrganogramPosition> GetAllOrganPosition();
}
#endregion
}