예제 #1
0
        public void InitWorkflow(string className)
        {
            //Get the workflow object by class name
            if (Workflow.LoadByObjectName(className))
            {
                //Get all unique owners for this workflow
                WFOwnerGroups.Load(Workflow.ID);

                //Add an owner group to the work flow owners
                foreach (ENTWFOwnerGroupEO entWFOwnerGroup in WFOwnerGroups)
                {
                    Nullable <int> entUserAccountId = null;

                    if (entWFOwnerGroup.IsDefaultSameAsLast)
                    {
                        //Get this user's last request and set it as the default.
                        var lastUser = new ENTWFItemOwnerData().SelectLastUserByGroupId(entWFOwnerGroup.ID, WFItem.SubmitterENTUserAccountId);
                        if ((lastUser != null) && (lastUser.ENTUserAccountId != null))
                        {
                            entUserAccountId = lastUser.ENTUserAccountId;
                        }
                    }
                    else
                    {
                        //set the owner to the default one selected for this group.
                        entUserAccountId = entWFOwnerGroup.DefaultENTUserAccountId;
                    }

                    string userName = "";
                    if (entUserAccountId != null)
                    {
                        //get the user's name
                        var userAccount = new ENTUserAccountEO();
                        userAccount.Load((int)entUserAccountId);
                        userName = userAccount.DisplayText;
                    }

                    //Add this item owner with the default user.
                    WFOwners.Add(new ENTWFItemOwnerEO {
                        ENTUserAccountId = entUserAccountId, ENTWFOwnerGroupId = entWFOwnerGroup.ID, UserName = userName
                    });
                }

                //Load the transitions based on the current state.
                WFTransitions.Load(WFItem.CurrentWFStateId);
            }
            else
            {
                throw new Exception("Workflow not set correctly.  Please associate this item with a workflow.");
            }
        }
예제 #2
0
        /// <summary>
        /// Retrieves all the workflow data associated with this item.
        /// </summary>
        /// <param name="className"></param>
        /// <param name="itemId"></param>
        public void LoadWorkflow(string className, int itemId)
        {
            //Get the workflow object by class name
            if (Workflow.LoadByObjectName(className))
            {
                //Load the WFItem using the itemId, this is the not the same as the primary key for the WFItem.
                WFItem.LoadByItemId(Workflow.ID, itemId);

                //Get all owner groups for this workflow
                WFOwnerGroups.Load(Workflow.ID);

                //Get the owners for this item
                WFOwners.Load(WFItem.ID);

                //Add any owner groups that aren't in the list
                foreach (ENTWFOwnerGroupEO wfOwnerGroup in WFOwnerGroups)
                {
                    ENTWFItemOwnerEO wfItemOwner = WFOwners.SingleOrDefault(o => o.ENTWFOwnerGroupId == wfOwnerGroup.ID);

                    if (wfItemOwner == null)
                    {
                        //Add this with a blank user
                        WFOwners.Add(new ENTWFItemOwnerEO {
                            ENTWFItemId = itemId, ENTWFOwnerGroupId = wfOwnerGroup.ID
                        });
                    }
                }

                //Get all the state histories
                WFStateHistory.Load(WFItem.ID);

                //Load the transitions based on the current state.
                WFTransitions.Load(WFItem.CurrentWFStateId);

                //Load the current state.
                _currentState = new ENTWFStateEO();
                _currentState.Load(WFItem.CurrentWFStateId);
            }
            else
            {
                throw new Exception("Workflow not set correctly.  Please associate this item with a workflow.");
            }
        }