Exemple #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.");
            }
        }
Exemple #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.");
            }
        }
Exemple #3
0
        private void ValidateWorkflow(HRPaidTimeOffDataContext db, ref ENTValidationErrors validationErrors,
                                      ENTBaseEO item)
        {
            //If the current owner is required.
            if (CurrentOwnerENTUserAccountId == 0)
            {
                validationErrors.Add("Please select the " + WFOwnerGroups.GetByENTWFOwnerGroupId(Convert.ToInt32(CurrentState.ENTWFOwnerGroupId)).OwnerGroupName + ".");
            }

            if (OriginalItem == null)
            {
                throw new Exception("The original item was not sent to the workflow save method.");
            }
            else
            {
                //Check required fields.
                ENTWFStatePropertyEOList entWFStateProperties = new ENTWFStatePropertyEOList();
                entWFStateProperties.Load(db, WFItem.CurrentWFStateId);

                Type objectType = Type.GetType(Workflow.ENTWorkflowObjectName);

                foreach (ENTWFStatePropertyEO entWFStateProperty in entWFStateProperties)
                {
                    if (entWFStateProperty.Required)
                    {
                        PropertyInfo property     = objectType.GetProperty(entWFStateProperty.PropertyName);
                        string       errorMessage = "The " + entWFStateProperty.PropertyName + " is required.";

                        if (property.PropertyType.IsEnum)
                        {
                            Array a       = Enum.GetValues(property.PropertyType);
                            int   value   = Convert.ToInt32(property.GetValue(item, null));
                            bool  isValid = false;
                            foreach (int i in a)
                            {
                                if (i == value)
                                {
                                    isValid = true;
                                    break;
                                }
                            }

                            if (isValid == false)
                            {
                                validationErrors.Add(errorMessage);
                            }
                        }
                        else
                        {
                            switch (property.PropertyType.Name)
                            {
                            case "Int32":
                                if (Convert.ToInt32(property.GetValue(item, null)) == 0)
                                {
                                    validationErrors.Add(errorMessage);
                                }
                                break;

                            case "String":
                                if ((property.GetValue(item, null) == null) || (property.GetValue(item, null).ToString() == string.Empty))
                                {
                                    validationErrors.Add(errorMessage);
                                }
                                break;

                            case "DateTime":
                                if ((property.GetValue(item, null) == null) || (Convert.ToDateTime(property.GetValue(item, null)) == DateTime.MinValue))
                                {
                                    validationErrors.Add(errorMessage);
                                }
                                break;

                            case "Nullable`1":
                                if (property.GetValue(item, null) == null)
                                {
                                    validationErrors.Add(errorMessage);
                                }
                                break;

                            default:
                                throw new Exception("Property type unknown.");
                            }
                        }
                    }

                    //Check if this field is read only.  Only check read only fields if the record was already submitted.
                    if (((ENTBaseWorkflowEO)OriginalItem).CurrentState.ID != 0)
                    {
                        if (entWFStateProperty.ReadOnly)
                        {
                            PropertyInfo property = objectType.GetProperty(entWFStateProperty.PropertyName);

                            if (property.GetValue(item, null).ToString() != property.GetValue(OriginalItem, null).ToString())
                            {
                                validationErrors.Add("The " + entWFStateProperty.PropertyName + " can not be changed.");
                            }
                        }
                    }
                }
            }
        }