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("positionName", _positionName, value); _positionName = value; } } #endregion #region parentID : ID private ID _parentID; public ID ParentID { get { return _parentID; } set { base.OnPropertyChange("parentID", _parentID, value); _parentID = value; } } #endregion #region tier : int private int _tier; public int Tier { get { return _tier; } set { base.OnPropertyChange("tier", _tier, value); _tier = value; } } #endregion #region uniqueId : int private int _uniqueId; public int UniqueId { get { return _uniqueId; } set { base.OnPropertyChange("uniqueId", _uniqueId, value); _uniqueId = value; } } #endregion #region positionNo : string private string _positionNo; public string PositionNo { get { return _positionNo; } set { base.OnPropertyChange("positionNo", _positionNo, value); _positionNo = value; } } #endregion #region companyID : ID private ID _companyID; public ID CompanyID { get { return _companyID; } set { base.OnPropertyChange("companyID", _companyID, value); _companyID = value; } } #endregion #region departmentID : ID private ID _departmentID; public ID DepartmentID { get { return _departmentID; } set { base.OnPropertyChange("DepartmentID", _departmentID, value); _departmentID = value; } } #endregion #region functionID : ID private ID _functionID; public ID FunctionID { get { return _functionID; } set { base.OnPropertyChange("functionID", _functionID, value); _functionID = value; } } #endregion #region gradeID : ID private ID _gradeID; public ID GradeID { get { return _gradeID; } set { base.OnPropertyChange("gradeID", _gradeID, value); _gradeID = value; } } #endregion #region designationID : ID private ID _designationID; public ID DesignationID { get { return _designationID; } set { base.OnPropertyChange("designationID", _designationID, value); _designationID = value; } } #endregion #region locationID : ID private ID _locationID; public ID LocationID { get { return _locationID; } set { base.OnPropertyChange("locationID", _locationID, value); _locationID = value; } } #endregion #region JDNo : string private string _jdNo; public string JDNo { get { return _jdNo; } set { base.OnPropertyChange("jdNo", _jdNo, value); _jdNo = value; } } #endregion #region RevisionNo private string _revisionNo; public string RevisionNo { get { return _revisionNo; } set { base.OnPropertyChange("revisionNo", _revisionNo, value); _revisionNo = value; } } #endregion #region RevisionDate private DateTime _revisionDate; public DateTime RevisionDate { get { return _revisionDate; } set { base.OnPropertyChange("revisionDate", _revisionDate, value); _revisionDate = value; } } #endregion #region OrganAuthority : OrganogramAuthority private ObjectsTemplate _organAuthority; public ObjectsTemplate OrganAuthority { get { if (_organAuthority == null) _organAuthority = new ObjectsTemplate(); return _organAuthority; } set { _organAuthority = value; } } #endregion #region OrganDelegation : OrganogramDelegation private ObjectsTemplate _organDelegation; public ObjectsTemplate OrganDelegation { get { if (_organDelegation == null) _organDelegation = new ObjectsTemplate(); return _organDelegation; } set { _organDelegation = value; } } #endregion #region OrganJobDesc : OrganogramJobDesc private ObjectsTemplate _organJobDesc; public ObjectsTemplate OrganJobDesc { get { if (_organJobDesc == null) _organJobDesc = new ObjectsTemplate(); return _organJobDesc; } set { _organJobDesc = value; } } #endregion #region OrganResponsibility : OrganogramResponsibility private ObjectsTemplate _organResponsibility; public ObjectsTemplate OrganResponsibility { get { if (_organResponsibility == null) _organResponsibility = new ObjectsTemplate(); return _organResponsibility; } set { _organResponsibility = value; } } #endregion #region OrganSkillLevel : OrganogramSkillLevel private ObjectsTemplate _organSkillLevel; public ObjectsTemplate OrganSkillLevel { get { if (_organSkillLevel == null) _organSkillLevel = new ObjectsTemplate(); 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 _oChilds; public ObjectsTemplate Childs { get { if (_oChilds == null) { _oChilds = new ObjectsTemplate(); _oChilds = OrganogramBasic.GetByParentId(this.ID,EnumStatus.Regardless); } return _oChilds; } set { _oChilds = value; } } #endregion #region OrganPosition : OrganogramPosition private ObjectsTemplate _organPositions; public ObjectsTemplate 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 GetAthorities(EnumAuthorityType type) { ObjectsTemplate oobjects = new ObjectsTemplate(); 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 _organEmployees; public ObjectsTemplate OrganEmployees { get { if (_organEmployees == null && !this.ID.IsUnassigned && this.ID.Integer > 0) _organEmployees = OrganogramEmployee.Get(this.ID); return _organEmployees; } set { _organEmployees = value; } } #endregion /// /// Return assgined employee, if multiple employee assigned, first employee will be returned. /// /// 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(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 /// /// get oranogram node along with node authorities, employees, job-description, /// skill-lebel, positions /// /// Oranogram Node ID /// 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 Get(EnumStatus nstatus) { #region Cache Header ObjectsTemplate organograms = _cache["Get"] as ObjectsTemplate; 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; } /// /// get organogram node(s) /// /// Oranogram Node Id /// public static ObjectsTemplate GetByParentId(ID parentID,EnumStatus status) { ObjectsTemplate items; #region CacheHeader items = (ObjectsTemplate)_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; } /// /// get the organogram node(s), does not have parent (null) /// /// public static ObjectsTemplate GetTopParents(EnumStatus nstatus) { ObjectsTemplate items; try { items = OrganogramBasic.Service.GetTopParents(nstatus); } catch (ServiceException e) { throw new ServiceException(e.Message, e); } return items; } public static ObjectsTemplate Get4OrganAuthority(ID organAuthorityID) { #region Cache Header ObjectsTemplate oOrganAuthority = _cache["Get4OrganAuthority", organAuthorityID] as ObjectsTemplate; 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 Get4OrganDelegation(ID organDelegationID) { #region Cache Header ObjectsTemplate oOrganogramDelegation = _cache["Get4OrganDelegation", organDelegationID] as ObjectsTemplate; 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 Get4OrganJobDesc(ID organJobDescID) { #region Cache Header ObjectsTemplate oOrganogramJobDesc = _cache["Get4OrganJobDesc", organJobDescID] as ObjectsTemplate; 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 Get4OrganResponsibility(ID organResponsibilityID) { #region Cache Header ObjectsTemplate oOrganogramResponsibility = _cache["Get4OrganResponsibility", organResponsibilityID] as ObjectsTemplate; 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 Get4OrganSkilLevel(ID organSkilLevelID) { #region Cache Header ObjectsTemplate oOrganogramSkillLevel = _cache["Get4OrganSkilLevel", organSkilLevelID] as ObjectsTemplate; 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 Get4OrganPosition(ID organPositionID) { #region Cache Header ObjectsTemplate oOrganogramPosition = _cache["Get4OrganPosition", organPositionID] as ObjectsTemplate; 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 GetbyPositionTypeid(ID positiontypeid) { ObjectsTemplate oOrganogramPosition = null; try { oOrganogramPosition = Service.GetbyPositionTypeID(positiontypeid); } catch (ServiceException e) { throw new Exception(e.Message, e); } return oOrganogramPosition; } public static ObjectsTemplate GetAllOrganPosition() { ObjectsTemplate 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 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 Get( EnumStatus status); ObjectsTemplate GetByParentID(ID parentID,EnumStatus status); ID GetMinNodeIdByDept(ID deptID); ObjectsTemplate GetTopParents(EnumStatus status); ObjectsTemplate Get4OrganAuthority(ID NodeID); ObjectsTemplate Get4OrganDelegation(ID NodeID); ObjectsTemplate Get4OrganJobDesc(ID NodeID); ObjectsTemplate Get4OrganResponsibility(ID NodeID); ObjectsTemplate Get4OrganSkilLevel(ID NodeID); ObjectsTemplate Get4OrganPosition(ID NodeID); ObjectsTemplate GetbyPositionTypeID(ID positionTypeid); void UpdateParentAndTier(ObjectsTemplate oNodes); ObjectsTemplate GetAllOrganPosition(); } #endregion }