using System; using System.Collections.Generic; using System.Linq; using System.Text; using Ease.CoreV35; using Ease.CoreV35.Caching; using Ease.CoreV35.Model; using Ease.CoreV35.Utility; namespace Payroll.BO { #region WFSetup [Serializable] public class WFSetup : BasicBaseObject { #region Cache Store private static Cache _cache = new Cache(typeof(WFSetup)); #endregion #region Constructor public WFSetup() { _wfTypeId = null; _wfSetupRules = null; } #endregion #region Property //#region Property WFSetupID : ID //private ID _wfSetupId; //public ID WFSetupID //{ // get { return _wfSetupId; } // set { _wfSetupId = value; } //} //#endregion #region Property WFTypeId : ID private ID _wfTypeId; public ID WFTypeId { get { return _wfTypeId; } set { _wfTypeId = value; } } #endregion #region WFRuleDetailDesignation : WFRuleDetailDesignation //private ObjectsTemplate _wfDetailDesigs; //public ObjectsTemplate WFDetailDesigs //{ // get // { // if (_wfDetailDesigs == null) // _wfDetailDesigs = Service.Get4WFRuleDD(this.ID); // return _wfDetailDesigs; // } // set // { // _wfDetailDesigs = value; // } //} #endregion #region WFRuleDetailNode : WFRuleDetailNode //private ObjectsTemplate _wfRuleNodes; //public ObjectsTemplate WFRuleNodes //{ // get // { // if (_wfRuleNodes == null) // _wfRuleNodes = Service.Get4WFRuleNode(this.ID); // return _wfRuleNodes; // } // set // { // _wfRuleNodes = value; // } //} #endregion #region WFRuleDetailOS : WFRuleDetailOS //private ObjectsTemplate _wfRuleDOSs; //public ObjectsTemplate WFRuleDOSs //{ // get // { // if (_wfRuleDOSs == null ) // { // _wfRuleDOSs = Service.Get4WFRuleDetailOS(this.ID); // } // return _wfRuleDOSs; // } // set // { // _wfRuleDOSs = value; // } //} #endregion #region WFSetupRule : WFSetupRule private ObjectsTemplate _wfSetupRules; public ObjectsTemplate WFSetupRules { get { if (_wfSetupRules == null && this.ID != null && this.ID.IsUnassigned == false) { _wfSetupRules = Service.Get4WFSetupRule(this.ID); } return _wfSetupRules; } set { _wfSetupRules = value; } } #endregion #region WFType : WFType private WFType _wfType; public WFType WFType { get { if (_wfType == null) _wfType = WFType.Get(_wfTypeId); return _wfType; } set { _wfType = value; } } #endregion #endregion #region Functions #region Save public ID Save() { base.SetAuditTrailProperties(); return WFSetup.Service.Save(this); } #endregion #region Delete public void Delete() { WFSetup.Service.Delete(ID); } #endregion public bool IsInitiator(OrganogramBasic ogNode) { return (this.GetNodeRules(ogNode).Count > 0); } #region Get public WFSetupRule GetNodeRule(OrganogramBasic ogNode) { ObjectsTemplate oRules = this.GetNodeRules(ogNode); WFSetupRule oRule = null; int nMaxPriority = -1; foreach (WFSetupRule oItem in oRules) { if (oItem.Priority > nMaxPriority) { oRule = oItem; nMaxPriority = oItem.Priority; } } return oRule; } public WFSetupRule GetRule(ID RuleID) { WFSetupRule oRule = null; foreach (WFSetupRule oItem in this.WFSetupRules) { if (oItem.ID.Integer == RuleID.Integer) { return oItem; } } return oRule; } public ObjectsTemplate[] GetFullPath(WFSetupRule oRule, int nTier, OrganogramBasic ogNode) { ObjectsTemplate[] oPaths = null; switch (oRule.WFRuleType) { case EnumWFRuleType.StraightAuthority: if (oRule.StAuthorityLevel - nTier > 0) { oPaths = new ObjectsTemplate[oRule.StAuthorityLevel - (nTier + 1)]; oPaths[0] = new ObjectsTemplate(); oPaths[0].Add(ogNode); for (int i = 1; i < oRule.StAuthorityLevel - nTier; i++) { oPaths[i] = new ObjectsTemplate(); oPaths[i].Add(oPaths[i - 1][0].Parent); } } break; case EnumWFRuleType.FixedOGNode: case EnumWFRuleType.Designation: case EnumWFRuleType.OrganizationStructure: ObjectsTemplate oP; oPaths = new ObjectsTemplate[oRule.LevelDepth - (nTier + 1)]; oPaths[0].Add(ogNode); for (int i = nTier; i <= oRule.LevelDepth - (nTier + 1); i++) { oP = Approvers(oRule, ogNode, i); foreach (OrganogramBasic oItem in oP) { oPaths[i].Add(oItem); } } break; default: break; } return oPaths; } public ObjectsTemplate[] GetFullPath(OrganogramBasic ogNode) { WFSetupRule oRule = this.GetNodeRule(ogNode); ObjectsTemplate[] oPaths = null; // = new HR.BO.OrgChart.RAHierarchyNodes(); switch (oRule.WFRuleType) { case EnumWFRuleType.StraightAuthority: oPaths = new ObjectsTemplate[oRule.StAuthorityLevel + 1]; oPaths[0] = new ObjectsTemplate(); oPaths[0].Add(ogNode); for (int i = 1; i <= oRule.StAuthorityLevel; i++) { oPaths[i] = new ObjectsTemplate(); oPaths[i].Add(oPaths[i - 1][0].Parent); } break; case EnumWFRuleType.FixedOGNode: case EnumWFRuleType.Designation: case EnumWFRuleType.OrganizationStructure: ObjectsTemplate oP; oPaths = new ObjectsTemplate[oRule.LevelDepth + 1]; oPaths[0] = new ObjectsTemplate(); oPaths[0].Add(ogNode); for (int i = 1; i <= oRule.LevelDepth; i++) { oP = Approvers(oRule, ogNode, i); foreach (OrganogramBasic oItem in oP) { oPaths[i] = new ObjectsTemplate(); oPaths[i].Add(oItem); } } break; case EnumWFRuleType.Manual: oPaths = new ObjectsTemplate[oRule.LevelDepth + 1]; oPaths[0] = new ObjectsTemplate(); oPaths[0].Add(ogNode); for (int i = 1; i < oRule.LevelDepth; i++) { ObjectsTemplate oPM = Approvers(oRule, oPaths[i - 1][0], i+1); oPaths[i] = new ObjectsTemplate(); foreach (OrganogramBasic oItem in oPM) { oPaths[i].Add(oItem); } } break; default: break; } return oPaths; } public ObjectsTemplate[] GetFullPathOnTier(WFSetupRule oRule, int nTier, OrganogramBasic ogNode) { ObjectsTemplate[] oPaths; if (nTier > 0) { oPaths = new ObjectsTemplate[nTier]; oPaths[0] = new ObjectsTemplate(); oPaths[0].Add(ogNode); for (int i = 1; i < nTier; i++) { oPaths[i] = new ObjectsTemplate(); oPaths[i].Add(oPaths[i - 1][0].Parent); } } else { ObjectsTemplate oP = null; oPaths = new ObjectsTemplate[oRule.LevelDepth - 1]; oPaths[0].Add(ogNode); for (int i = nTier; i <= oRule.LevelDepth; i++) { oP = Approvers(oRule, ogNode, i); foreach (OrganogramBasic oItem in oP) { oPaths[i].Add(oItem); } } } return oPaths; } public OrganogramBasic InitiatorToTierNode(OrganogramBasic oInitiatorNode, WFSetupRule oRule, int nTier) { ObjectsTemplate[] oPaths = null; switch (oRule.WFRuleType) { case EnumWFRuleType.StraightAuthority: oPaths = new ObjectsTemplate[nTier]; oPaths[0] = new ObjectsTemplate(); oPaths[0].Add(oInitiatorNode); for (int i = 1; i < nTier; i++) { oPaths[i] = new ObjectsTemplate(); oPaths[i].Add(oPaths[i - 1][0].Parent); } break; case EnumWFRuleType.FixedOGNode: case EnumWFRuleType.Designation: case EnumWFRuleType.OrganizationStructure: case EnumWFRuleType.Manual: ObjectsTemplate oP; oPaths = new ObjectsTemplate[nTier]; oPaths[0] = new ObjectsTemplate(); oPaths[0].Add(oInitiatorNode); for (int i = 1; i < nTier; i++) { oP = Approvers(oRule, oPaths[i - 1][0], i); oPaths[i] = new ObjectsTemplate(); foreach (OrganogramBasic oItem in oP) { oPaths[i].Add(oItem); } } break; default: break; } return oPaths[nTier - 1][0]; } public ObjectsTemplate Approvers(WFSetupRule oRule, OrganogramBasic ogNode, int ntier) { ObjectsTemplate oApprovarNodes = new ObjectsTemplate(); switch (oRule.WFRuleType) { case EnumWFRuleType.StraightAuthority: if (oRule.IsRAuthority == false) { if (ogNode.Parent == null) throw new ServiceException("Approver Organogram position/node is vacant. please assign an employee at the postion first."); oApprovarNodes.Add(ogNode.Parent); } else { ObjectsTemplate rpau = ogNode.GetAthorities(EnumAuthorityType.Reporting); foreach (OrganogramBasic og in rpau) { oApprovarNodes.Add(og); } } break; case EnumWFRuleType.OrganizationStructure: oApprovarNodes = oRule.Approver(ogNode, ntier); break; case EnumWFRuleType.FixedOGNode: oApprovarNodes = oRule.Approver(ogNode, ntier); break; case EnumWFRuleType.Designation: oApprovarNodes = oRule.Approver(ogNode, ntier); break; case EnumWFRuleType.Manual: oApprovarNodes = oRule.Approver(ogNode, ntier); break; default: break; } return oApprovarNodes; } public ObjectsTemplate GetNodeRules(OrganogramBasic ogNode) { ObjectsTemplate oselectedRules = new ObjectsTemplate(); foreach (WFSetupRule oItem in this.WFSetupRules) { switch (oItem.WFRuleType) { case EnumWFRuleType.StraightAuthority: if (oItem.WFRuleDeatilDesignations.Count > 0 && oItem.WFRuleDeatilOSs.Count > 0) { if (WFRuleDetailDesignation.IsInitiator(oItem.WFRuleDeatilDesignations, ogNode.DesignationID) == true && WFRuleDetailOS.IsInitiator(oItem.WFRuleDeatilOSs, ogNode.DepartmentID) == true) { oselectedRules.Add(oItem); } } else if (oItem.WFRuleDeatilDesignations.Count > 0) { if (WFRuleDetailDesignation.IsInitiator(oItem.WFRuleDeatilDesignations, ogNode.DesignationID) == true) oselectedRules.Add(oItem); } else if (oItem.WFRuleDeatilOSs.Count > 0) { if (WFRuleDetailOS.IsInitiator(oItem.WFRuleDeatilOSs, ogNode.DepartmentID) == true) oselectedRules.Add(oItem); } else oselectedRules.Add(oItem); break; case EnumWFRuleType.OrganizationStructure: if (WFRuleDetailOS.IsInitiator(oItem.WFRuleDeatilOSs, ogNode.DesignationID) == true) { oselectedRules.Add(oItem); } break; case EnumWFRuleType.Designation: if (WFRuleDetailDesignation.IsInitiator(oItem.WFRuleDeatilDesignations, ogNode.DesignationID) == true) { oselectedRules.Add(oItem); } break; case EnumWFRuleType.FixedOGNode: if (WFRuleDetailNode.IsInitiator(oItem.WFRuleDetailNodes, ogNode.ID)) { oselectedRules.Add(oItem); } break; case EnumWFRuleType.Manual: if (WFRuleDetailManual.IsInitiator(oItem.WFRuleDetailManual, ogNode.ID)) { oselectedRules.Add(oItem); } break; default: break; } } return oselectedRules; } public static WFSetup GetByWFTypeID(ID nType) { WFSetup WFSetup = null; #region Cache Header WFSetup = (WFSetup)_cache["Get", nType]; if (WFSetup != null) return WFSetup; #endregion WFSetup = WFSetup.Service.GetByWFTypeID(nType); #region Cache Footer _cache.Add(WFSetup, "Get", nType); #endregion return WFSetup; } public static WFSetup Get(ID nID) { WFSetup wfSetup = null; #region Cache Header wfSetup = (WFSetup)_cache["Get", nID]; if (wfSetup != null) return wfSetup; #endregion wfSetup = WFSetup.Service.Get(nID); #region Cache Footer _cache.Add(wfSetup, "Get", nID); #endregion return wfSetup; } public static ObjectsTemplate Get() { #region Cache Header ObjectsTemplate wfSetup = _cache["Get"] as ObjectsTemplate; if (wfSetup != null) return wfSetup; #endregion try { wfSetup = Service.Get(); } catch (ServiceException e) { throw new Exception(e.Message, e); } #region Cache Footer _cache.Add(wfSetup, "Get"); #endregion return wfSetup; } public static ObjectsTemplate Get4WFRuleDD(ID wfRuleDetailID) { #region Cache Header ObjectsTemplate oWFRuleDetailDesignation = _cache["Get4WFRuleDD", wfRuleDetailID] as ObjectsTemplate; if (oWFRuleDetailDesignation != null) return oWFRuleDetailDesignation; #endregion try { oWFRuleDetailDesignation = Service.Get4WFRuleDD(wfRuleDetailID); } catch (ServiceException e) { throw new Exception(e.Message, e); } #region Cache Footer _cache.Add(oWFRuleDetailDesignation, "Get4WFRuleDD", wfRuleDetailID); #endregion return oWFRuleDetailDesignation; } public static ObjectsTemplate Get4WFRuleNode(ID wfRuleNodeID) { #region Cache Header ObjectsTemplate oWFRuleNode = _cache["Get4WFRuleNode", wfRuleNodeID] as ObjectsTemplate; if (oWFRuleNode != null) return oWFRuleNode; #endregion try { oWFRuleNode = Service.Get4WFRuleNode(wfRuleNodeID); } catch (ServiceException e) { throw new Exception(e.Message, e); } #region Cache Footer _cache.Add(oWFRuleNode, "Get4WFRuleNode", wfRuleNodeID); #endregion return oWFRuleNode; } public static ObjectsTemplate Get4WFRuleManual(ID wfRuleNodeID) { ObjectsTemplate oWFRuleNode = null; try { oWFRuleNode = Service.Get4WFRuleDetailManual(wfRuleNodeID); } catch (ServiceException e) { throw new Exception(e.Message, e); } return oWFRuleNode; } public static ObjectsTemplate Get4WFSetupRule(ID wfSetupRuleID) { #region Cache Header ObjectsTemplate oWFSetupRule = _cache["Get4WFSetupRule", wfSetupRuleID] as ObjectsTemplate; if (oWFSetupRule != null) return oWFSetupRule; #endregion try { oWFSetupRule = Service.Get4WFSetupRule(wfSetupRuleID); } catch (ServiceException e) { throw new Exception(e.Message, e); } #region Cache Footer _cache.Add(oWFSetupRule, "Get4WFSetupRule", wfSetupRuleID); #endregion return oWFSetupRule; } public static ObjectsTemplate Get4WFRuleDetailOS(ID osID) { #region Cache Header ObjectsTemplate oWFRuleDetailOS = _cache["Get4WFRuleDetailOS", osID] as ObjectsTemplate; if (oWFRuleDetailOS != null) return oWFRuleDetailOS; #endregion try { oWFRuleDetailOS = Service.Get4WFRuleDetailOS(osID); } catch (ServiceException e) { throw new Exception(e.Message, e); } #region Cache Footer _cache.Add(oWFRuleDetailOS, "Get4WFRuleDetailOS", osID); #endregion return oWFRuleDetailOS; } #endregion public bool CheckPriority(int PriorityLevel) { foreach (WFSetupRule oItem in this.WFSetupRules) { if (oItem.Priority == PriorityLevel) { return true; } } return false; } #endregion #region Service Factory internal static IWFSetupService Service { get { return Services.Factory.CreateService(typeof(IWFSetupService)); } } #endregion } #endregion #region Interface public interface IWFSetupService { ID Save(WFSetup item); void Delete(ID Id); WFSetup Get(ID id); WFSetup GetByWFTypeID(ID nType); ObjectsTemplate Get(); ObjectsTemplate Get4WFRuleDD(ID ruleid); ObjectsTemplate Get4WFRuleNode(ID ruleId); ObjectsTemplate Get4WFSetupRule(ID id); ObjectsTemplate Get4WFRuleDetailOS(ID ruleid); ObjectsTemplate Get4WFRuleDetailManual(ID ruleid); } #endregion }