示例#1
0
        /// <summary>
        /// 保存流程数据
        /// </summary>
        /// <param name="flowEngine">流程</param>
        /// <param name="category">分类</param>
        /// <param name="owner">具体业务数据对应的PK</param>
        public void FlowSave(Eastday.WorkFlowEngine.FlowEngine flowEngine)
        {
            using (WorkFlowBLL workFlowBLL = new WorkFlowBLL())
            {
                workFlowBLL.DbContext = workFlowBLL.CreateDbContext(true);
                WorkFlowEntity workFlowEntity = workFlowBLL.Usp_Flow_ByOwner(flowEngine.Attachment.Owner);
                if (workFlowEntity == null)
                {
                    workFlowEntity = new WorkFlowEntity();
                }
                workFlowEntity.I_Owner = flowEngine.Attachment.Owner;
                workFlowEntity.I_State = (int)flowEngine.FlowState;
                workFlowEntity.I_Flag  = 1;

                //ParticipantEntity
                var aCurrent = flowEngine.GetCurrent();
                var steps    = from step in flowEngine.FlowSteps where !(step is StepEnd) select step;
                List <ParticipantEntity> participants = new List <ParticipantEntity>();
                foreach (var step in steps)
                {
                    foreach (var node in step.Nodes)
                    {
                        ParticipantEntity participantEntity = new ParticipantEntity();
                        participantEntity.I_Reference = node.Participant.Reference;
                        participantEntity.I_WorkFlow  = workFlowEntity.Id;
                        participantEntity.C_Step      = step.Identification;
                        participantEntity.C_Node      = node.Identification;
                        participantEntity.I_Auditer   = node.Conclusion.Auditer;
                        participantEntity.D_Audit     = node.Conclusion.AuditDate;
                        participantEntity.I_Bind      = node.Participant.Category;
                        participantEntity.I_Current   = step == aCurrent && node.AuditType == AuditType.UnAudit ? 1 : (int)node.Conclusion.AuditType;

                        participants.Add(participantEntity);
                    }
                }

                if (workFlowBLL.Usp_Flow_Insert(workFlowEntity, participants) > 0)
                {
                    workFlowBLL.DbContext.CommitTransaction();
                    this.Save(flowEngine);
                }
            }
        }