コード例 #1
0
        /// <summary>
        /// 退回任务
        /// </summary>
        public bool BackTask(string backWorkTaskId, OperationUser currentUser, string applyContent)
        {
            //找到定义的流程
            WorkTask currenTask = DefinitionWorkFlow.WorkTasks.Find(u => u.WorkTaskId == this.WorkTaskId);

            foreach (var record in WorkFlowRecords)
            {
                if (string.Equals(record.ApplyUserNo, currentUser.UserNo,
                                  StringComparison.CurrentCultureIgnoreCase))
                {
                    record.ActivityStateId = ActivityState.SendBacked;
                    record.EndTime         = DateTime.Now;
                    record.ApplyContent    = applyContent ?? "不同意";
                }
                else
                {
                    if (currenTask.OperationTypeId == OperationType.All ||
                        currenTask.OperationTypeId == OperationType.ChocieOne)
                    {
                        record.ActivityStateId = ActivityState.End;
                        record.EndTime         = DateTime.Now;
                        record.ApplyContent    = "流程已结束";
                    }
                }
            }
            List <WorkFlowRecord> wrs = WorkFlowRecords.Where(u => u.WorkTaskIns.WorkTaskId == backWorkTaskId).ToList();

            foreach (var record in wrs)
            {
                WorkFlowRecord r = record;
                r.ActivityStateId = ActivityState.Running;
                r.CreateTime      = DateTime.Now;
                r.EndTime         = null;
                r.ApplyContent    = "";
                WorkFlowRecords.Add(r);
            }
            return(false);
        }
コード例 #2
0
        public WorkFlowInstance NextTask(OperationUser currentUser, string applyContent, string nextWorkTaskId,
                                         List <OperationUser> operationUsers)
        {
            List <WorkFlowRecord> workFlowRecords =
                WorkFlowRecords.Where(u => u.WorkTaskIns.WorkTaskId == WorkTaskId).ToList();

            WorkTask currenTask = DefinitionWorkFlow.WorkTasks.Find(u => u.WorkTaskId == WorkTaskId);


            foreach (var record in workFlowRecords)
            {
                if (string.Equals(record.ApplyUserNo, currentUser.UserNo,
                                  StringComparison.CurrentCultureIgnoreCase))
                {
                    record.ActivityStateId = ActivityState.Completed;
                    record.EndTime         = DateTime.Now;
                    record.ApplyContent    = applyContent ?? "同意";
                }
                else
                {
                    if (currenTask.OperationTypeId == OperationType.ChocieOne)
                    {
                        record.ActivityStateId = ActivityState.End;
                        record.EndTime         = DateTime.Now;
                        record.ApplyContent    = "流程已结束";
                    }
                }
            }
            if (currenTask.OperationTypeId == OperationType.All && workFlowRecords.Count !=
                workFlowRecords.Count(u => u.ActivityStateId == ActivityState.Completed))
            {
                return(this);
            }
            string nextTaskid = string.IsNullOrEmpty(nextWorkTaskId) ? currenTask.NextWorkTaskId : nextWorkTaskId;

            WorkTaskId = nextTaskid;
            WorkTask nextworkTask = DefinitionWorkFlow.WorkTasks.Find(u => u.WorkTaskId == nextTaskid);

            if (operationUsers != null && operationUsers.Count > 0)
            {
                foreach (var user in operationUsers)
                {
                    WorkFlowRecord nxetRecord = new WorkFlowRecord()
                    {
                        WorkTaskIns     = nextworkTask,
                        ActivityName    = nextworkTask.Name,
                        ActivityStateId = ActivityState.Running,
                        ApplyUserName   = user.UserName,
                        ApplyUserNo     = user.UserName,
                        CreateTime      = DateTime.Now,
                    };
                    WorkFlowRecords.Add(nxetRecord);
                }
            }
            else
            {
                foreach (var user in nextworkTask.OperationUsers ?? new List <OperationUser>())
                {
                    WorkFlowRecord nxetRecord = new WorkFlowRecord()
                    {
                        WorkTaskIns     = nextworkTask,
                        ActivityName    = nextworkTask.Name,
                        ActivityStateId = ActivityState.Running,
                        ApplyUserName   = user.UserName,
                        ApplyUserNo     = user.UserName,
                        CreateTime      = DateTime.Now,
                    };
                    WorkFlowRecords.Add(nxetRecord);
                }
                if (nextworkTask.TaskTypeId == TaskType.End)
                {
                    WorkFlowRecord nxetRecord = new WorkFlowRecord()
                    {
                        WorkTaskIns     = nextworkTask,
                        ActivityName    = nextworkTask.Name,
                        ActivityStateId = ActivityState.End,
                        ApplyContent    = "流程结束",
                        CreateTime      = DateTime.Now,
                        EndTime         = DateTime.Now
                    };
                    WorkFlowRecords.Add(nxetRecord);
                    WorkFlowStateId = WorkFlowState.Completed;
                }
            }
            return(this);
        }
コード例 #3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="workFlow"></param>
        /// <param name="operationUsers"></param>
        /// <returns></returns>
        public WorkFlowInstance StartTask(WorkFlow workFlow, List <OperationUser> operationUsers)
        {
            CreateTime      = DateTime.Now;
            WorkFlowStateId = WorkFlowState.Running;
            WorkFlowRecords = new List <WorkFlowRecord>();
            //找到定义的流程
            DefinitionWorkFlow = workFlow;
            //处理当前任务
            WorkTask       currentTask   = workFlow.WorkTasks.FirstOrDefault(u => u.WorkTaskId == WorkTaskId);
            WorkFlowRecord currentRecord = new WorkFlowRecord()
            {
                WorkTaskIns     = currentTask,
                ActivityName    = currentTask.Name,
                ActivityStateId = ActivityState.Completed,
                ApplyContent    = "编辑",
                ApplyUserName   = CreateUserName,
                ApplyUserNo     = CreateUserNo,
                CreateTime      = DateTime.Now,
                EndTime         = DateTime.Now
            };

            WorkFlowRecords.Add(currentRecord);
            //处理下一步任务
            WorkTask nxetTask = workFlow.WorkTasks.FirstOrDefault(u => u.WorkTaskId == currentTask.NextWorkTaskId);

            if (operationUsers != null && operationUsers.Count > 0)
            {
                foreach (var user in operationUsers)
                {
                    WorkFlowRecord nxetRecord = new WorkFlowRecord()
                    {
                        WorkTaskIns     = nxetTask,
                        ActivityName    = nxetTask.Name,
                        ActivityStateId = ActivityState.Running,
                        ApplyUserName   = user.UserName,
                        ApplyUserNo     = user.UserName,
                        CreateTime      = DateTime.Now,
                    };
                    WorkFlowRecords.Add(nxetRecord);
                }
            }
            else
            {
                foreach (var user in nxetTask.OperationUsers ?? new List <OperationUser>())
                {
                    WorkFlowRecord nxetRecord = new WorkFlowRecord()
                    {
                        WorkTaskIns     = nxetTask,
                        ActivityName    = nxetTask.Name,
                        ActivityStateId = ActivityState.Running,
                        ApplyUserName   = user.UserName,
                        ApplyUserNo     = user.UserName,
                        CreateTime      = DateTime.Now,
                    };
                    WorkFlowRecords.Add(nxetRecord);
                }
            }
            //当前未处理的任务
            WorkTaskId = nxetTask.WorkTaskId;
            return(this);
        }