Ejemplo n.º 1
0
        private static void SF_MoveTo(UserInfo currentUser, FlowInfo flow, FlowStatus nextStatus, RequestInfo request, string comments)
        {
            Dictionary <ApproverInfo, RoleType> nextUser = new Dictionary <ApproverInfo, RoleType>();

            switch (nextStatus)
            {
                #region case RequestStatus.Submitted
            case FlowStatus.Submitted:
                //List<UserInfo> users = OrgMgr.GetApprovers(flow.FlowId, "approver");
                List <ApproverInfo> approvers = OrgMgr.GetApprovers(flow.FlowId).FindAll(obj => { return(obj.ApproveType == "approver"); });
                foreach (var item in approvers)
                {
                    nextUser.Add(item, RoleType.Approver);
                }
                break;
                #endregion

                #region case RequestStatus.Approved
            case FlowStatus.Approved:
                List <ApproverInfo> engs = OrgMgr.GetApprovers(flow.FlowId).FindAll(obj => { return(obj.ApproveType == "eng"); });
                if (request.FlowType == 1)      //并行
                {
                    foreach (var item in engs)
                    {
                        nextUser.Add(item, RoleType.Eng);
                    }
                }
                else      //串行
                {
                    nextUser.Add(engs[0], RoleType.Eng);
                }
                break;
                #endregion
            }

            WorkflowMgr.UpdateStatus(flow.FlowId, nextStatus);
            flow.Status = nextStatus;
            AddTasks(nextUser, flow);

            SendMail(currentUser, request, flow, nextUser, comments);
        }
Ejemplo n.º 2
0
        public static void HandleTask(UserInfo currentUser, int taskId, FlowInfo flow,
                                      RequestInfo request, ActionType action, string comments)
        {
            IList <ActionType> accessList = GetRequestPermission(taskId, flow, request, currentUser.UID);

            //judge current user whether have permission to do the action
            if (accessList.IndexOf(action) < 0)
            {
                throw new Exception("You don't have permission to do this action.");
            }

            WorkflowMgr.UpdateTask(taskId, action, comments);
            //FlowStatus oldStatus = flow.Status;
            FlowStatus nextStatus = flow.Status;
            Dictionary <ApproverInfo, RoleType> nextUser = new Dictionary <ApproverInfo, RoleType>();

            if (flow.Status == FlowStatus.Approved)
            {
                if (action == ActionType.Commit)
                {
                    if (request.FlowType == 1)   // 并行
                    {
                        if (WorkflowMgr.IsParallelLastApprover(currentUser.UID, flow))
                        {
                            nextStatus = FlowStatus.Closed;
                            WorkflowMgr.UpdateStatus(flow.FlowId, nextStatus);

                            SendMail(currentUser, request, flow, nextUser, comments);
                        }
                    }
                    else  //串行
                    {
                        List <ApproverInfo> approvers = OrgMgr.GetApprovers(flow.FlowId).FindAll(obj => { return(obj.ApproveType == "eng"); });

                        TaskInfo ts = WorkflowMgr.GetTask(taskId);
                        if (ts.UID.ToLower() == approvers[approvers.Count - 1].UID.ToLower())
                        {
                            nextStatus = FlowStatus.Closed;
                            WorkflowMgr.UpdateStatus(flow.FlowId, nextStatus);

                            SendMail(currentUser, request, flow, nextUser, comments);
                        }
                        else
                        {
                            int idx = approvers.FindIndex(obj => { return(obj.UID.ToLower() == ts.UID.ToLower()); });
                            nextUser.Add(approvers[idx + 1], RoleType.Eng);

                            AddTasks(nextUser, flow);
                            //send mail to next eng
                            SendMail(currentUser, request, flow, nextUser, comments);
                        }
                    }
                }
                else if (action == ActionType.Cancel)
                {
                    nextStatus = FlowStatus.Canceled;
                    WorkflowMgr.CancelAllOtherTasks(currentUser, flow, action);

                    WorkflowMgr.UpdateStatus(flow.FlowId, nextStatus);

                    SendMail(currentUser, request, flow, nextUser, comments);
                }
                else
                {
                    throw new Exception("Wrong Action");
                }
            }
            else
            {
                SF_MoveAfterTaskDone(currentUser, flow, request, action, comments);
            }
        }