Example #1
0
        private S_WF_InsTaskExec GetTaskExec(string taskExecID)
        {
            WorkflowEntities flowEntities = FormulaHelper.GetEntities <WorkflowEntities>();
            S_WF_InsTaskExec task         = flowEntities.S_WF_InsTaskExec.FirstOrDefault(p => p.ID == taskExecID);

            return(task);
        }
        public ApprovalResult ActApprovalFlow(long entityId, WorkflowEntities workflowEntity, long approverId, string remark, WorkflowActions action)
        {
            // _orderApplicationService;
            //TODO: Fake User Id
            approverId = 1101;  //Defined user for SAPID
            var lastWorkflowLog = GetLastWorkflowLog(entityId, workflowEntity);

            lastWorkflowLog.ValidateUserAccess(approverId, action);

            //next Step
            var step = GetWorkflowStep(lastWorkflowLog.CurrentWorkflowStep, action, approverId);

            if (step == null)
                throw new WorkFlowException("Invalid Access");

            if (step.NextWorkflowStep != null)
            {
                //var approvableDomainService = ServiceLocator.Current.GetInstance(lastWorkflowLog.GetDomainServiceType()) as IApprovableDomainService;

                lastWorkflowLog.UpdatedState(step);

                var newApprovalWorkFlow = lastWorkflowLog.CreateNextStep(step.ActorUserId,
                    step.NextWorkflowStepId.Value, step.NextWorkflowStep.State, step.NextWorkflowStep.CurrentWorkflowStage);

                _workflowLogRepository.Add(newApprovalWorkFlow);
            }
            else
            {
                throw new WorkFlowException("Invalid Action");
            }

            var result = UpdateApproveState(entityId, workflowEntity, approverId, remark, step.WithWorkflowAction, lastWorkflowLog);

            return result;
        }
 public WorkflowLog CreateApproveFlowLogObject(long entityId, WorkflowEntities actionEntity, DateTime actionDate, WorkflowActions workflowAction, long actorUserId, string remark, long approveWorkFlowConfigId)
 {
     return new WorkflowLog(actionEntity,
        workflowAction,
        actorUserId,
        actionDate,
        remark, approveWorkFlowConfigId, true);
 }
Example #4
0
        public override void UnExecTaskExec(string taskExecID)
        {
            string           id           = GetQueryString("ID");
            WorkflowEntities flowEntities = FormulaHelper.GetEntities <WorkflowEntities>();
            S_WF_InsTaskExec taskExec     = flowEntities.Set <S_WF_InsTaskExec>().SingleOrDefault(c => c.ID == taskExecID);
            string           stepCode     = taskExec.S_WF_InsTask.S_WF_InsDefStep.Code;

            PostingFO.ChangeStatus(id, stepCode);
            base.UnExecTaskExec(taskExecID);
        }
Example #5
0
        public WorkflowLog(WorkflowEntities actionEntity, WorkflowActions? workflowAction, long actorUserId, DateTime actionDate, string remark, long currentWorkflowStepId, bool active)
        {
            WorkflowEntity = actionEntity;

            WorkflowAction = workflowAction;
            ActorUserId = actorUserId;
            ActionDate = actionDate;
            Remark = remark;
            CurrentWorkflowStepId = currentWorkflowStepId;
            Active = active;
        }
 public CharterWorkflowLog(
     Charter charter,
     WorkflowEntities actionEntity,
     DateTime actionDate,
     WorkflowActions? workflowAction,
     long actorUserId,
     string remark, long currentWorkflowStepId, bool active)
     : base(actionEntity, workflowAction, actorUserId, actionDate, remark, currentWorkflowStepId, active)
 {
     Charter = charter;
 }
Example #7
0
 public ScrapWorkflowLog(
     Scrap scrap,
     WorkflowEntities actionEntity,
     DateTime actionDate,
     WorkflowActions? workflowAction,
     long actorUserId,
     string remark, long currentWorkflowStepId, bool active)
     : base(actionEntity, workflowAction, actorUserId, actionDate, remark, currentWorkflowStepId, active)
 {
     Scrap = scrap;
 }
 public OffhireWorkflowLog(
     Offhire offhire,
     WorkflowEntities actionEntity,
     DateTime actionDate,
     WorkflowActions? workflowAction,
     long actorUserId,
     string remark, long currentWorkflowStepId, bool active)
     : base(actionEntity, workflowAction, actorUserId, actionDate, remark, currentWorkflowStepId, active)
 {
     Offhire = offhire;
 }
 public FuelReportWorkflowLog(
     long entityId,
     WorkflowEntities actionEntity,
     DateTime actionDate,
     WorkflowActions? workflowAction,
     long actorUserId,
     string remark, long currentWorkflowStepId, bool active)
     : base(actionEntity, workflowAction, actorUserId, actionDate, remark, currentWorkflowStepId, active)
 {
     FuelReportId = entityId;
 }
Example #10
0
        public WorkflowStep(
              WorkflowEntities workflowEntity,
             long actorUserId,
             States state,
             WorkflowStages currentWorkflowStage,
             WorkflowActions withWorkflowAction,
            long? nextWorkflowStepId

   )
        {
            ActorUserId = actorUserId;
            NextWorkflowStepId = nextWorkflowStepId;
            WithWorkflowAction = withWorkflowAction;
            State = state;
            WorkflowEntity = workflowEntity;
            CurrentWorkflowStage = currentWorkflowStage;
        }
Example #11
0
 public WorkflowEntities Init(IConfiguration configuration)
 {
     return(dbContext ?? (dbContext = new WorkflowEntities(configuration)));
 }
Example #12
0
        public override bool ExecTaskExec(Workflow.Logic.Domain.S_WF_InsTaskExec taskExec, Workflow.Logic.Domain.S_WF_InsDefRouting routing, string nextExecUserIDs, string nextExecUserNames, string nextExecUserIDsGroup, string nextExecRoleIDs, string nextExecOrgIDs, string execComment)
        {
            WorkflowEntities entitiesFlow = FormulaHelper.GetEntities <WorkflowEntities>();
            bool             flowComplete = base.ExecTaskExec(taskExec, routing, nextExecUserIDs, nextExecUserNames, nextExecUserIDsGroup, nextExecRoleIDs, nextExecOrgIDs, execComment);
            S_D_Posting      model        = entities.Set <S_D_Posting>().Find(taskExec.S_WF_InsFlow.FormInstanceID);

            if (taskExec.S_WF_InsTask.Status == FlowTaskStatus.Complete.ToString())
            {
                if (model != null)
                {
                    if (string.IsNullOrEmpty(model.InsFlowID))
                    {
                        model.InsFlowID = taskExec.S_WF_InsTask.InsFlowID;
                    }

                    string[] arr = new string[2] {
                        routing.InsDefStepID, routing.EndID
                    };
                    List <S_WF_InsDefStep> steps = entitiesFlow.Set <S_WF_InsDefStep>().Where(c => arr.Contains(c.ID)).ToList();
                    string endID = routing.EndID;
                    if (steps.Find(c => c.ID == endID) != null)
                    {
                        model.Status = steps.Find(c => c.ID == endID).Code;
                    }
                    string exStatus = string.Empty;
                    string stepID   = routing.InsDefStepID;
                    if (steps.Find(c => c.ID == stepID) != null)
                    {
                        exStatus = steps.Find(c => c.ID == stepID).Code;
                    }
                    if (model.Status == PostingStatus.Draft.ToString())
                    {
                        string[] arrExecSteps = string.IsNullOrEmpty(model.ExecutedSteps) ? new string[1] {
                            exStatus
                        } : (model.ExecutedSteps + "," + exStatus).Split(',');
                        foreach (string str in arrExecSteps)
                        {
                            if (!string.IsNullOrEmpty(str))
                            {
                                string[] arrValTxt = new string[2] {
                                    str, str + "ID"
                                };
                                foreach (string s in arrValTxt)
                                {
                                    PropertyInfo pi = model.GetType().GetProperty(s, BindingFlags.Public | BindingFlags.Instance | BindingFlags.IgnoreCase);
                                    if (pi != null && pi.CanWrite)
                                    {
                                        pi.SetValue(model, string.Empty, null);
                                    }
                                }
                            }
                        }
                        model.ExecutedSteps = string.Empty;
                    }
                    else
                    {
                        if (exStatus != string.Empty)
                        {
                            if (string.IsNullOrEmpty(model.ExecutedSteps))
                            {
                                model.ExecutedSteps = exStatus;
                            }
                            else
                            {
                                model.ExecutedSteps += "," + exStatus;
                            }
                        }
                    }
                    //转PDF
                    if (steps.Find(c => c.ID == stepID).Code == PostingStatus.TaoHong.ToString())
                    {
                        if (string.IsNullOrEmpty(model.MergeDocID))
                        {
                            model.MergeDocID = model.DocID;
                        }
                        PostingFO.AddPDFTask(model.MergeDocID);
                    }
                    entities.SaveChanges();
                }
            }

            return(flowComplete);
        }
 protected virtual void CreateWorkFlowStep(long entityId, WorkflowEntities actionEntity, WorkflowActions workflowAction, long actorUserId, string remark, long approveWorkFlowConfigId)
 {
     //            var ent = _approveWorkFlowFactory.CreateApproveFlowLogObject(
     //                entityId,
     //                actionEntity,
     //                DateTime.Now,
     //                workflowAction,
     //                actorUserId,
     //                remark, approveWorkFlowConfigId);
     //
     //            _workflowLogRepository.Add(ent);
     //
     //            _unitOfWorkScope.Commit();
 }
        private ApprovalResult UpdateApproveState(long entityId, WorkflowEntities actionEntity, long approverId, string remark,
                                              WorkflowActions currentAction, WorkflowLog currentApprovalWorkFlowLog)
        {
            currentApprovalWorkFlowLog.UpdateInfo(currentAction, approverId, remark);

            _unitOfWorkScope.Commit();

            var result = new ApprovalResult
                             {
                                 WorkflowAction = currentAction,
                                 ActorId = approverId,
                                 DecisionType = DecisionTypes.Approved,
                                 EntityId = entityId,
                                 Entity = actionEntity,
                                 Remark = remark
                             };

            return result;
        }
        private WorkflowLog GetLastWorkflowLog(long entityId, WorkflowEntities actionEntity)
        {
            WorkflowLog currentApprovalWorkFlow;
            switch (actionEntity)
            {
                case WorkflowEntities.Order:
                    var orderWorkflow = _workflowLogRepository.GetQuery().OfType<OrderWorkflowLog>().FirstOrDefault(
                            c => c.WorkflowEntity == actionEntity && c.OrderId == entityId && c.Active);
                    if (orderWorkflow == null)
                        throw new ObjectNotFound("OrderWorkflow", entityId);

                    orderConfigurator.Configure(orderWorkflow.Order);
                    currentApprovalWorkFlow = orderWorkflow;

                    break;
                case WorkflowEntities.Invoice:
                    var invoiceWorkflow = _workflowLogRepository.GetQuery().OfType<InvoiceWorkflowLog>().
                        FirstOrDefault(
                            c => c.WorkflowEntity == actionEntity && c.InvoiceId == entityId && c.Active);

                    if (invoiceWorkflow == null)
                        throw new ObjectNotFound("InvoiceWorkflow", entityId);

                    invoiceConfigurator.Configure(invoiceWorkflow.Invoice);
                    currentApprovalWorkFlow = invoiceWorkflow;

                    break;
                case WorkflowEntities.FuelReport:
                    var fuelReportWorkflow =
                        _workflowLogRepository.GetQuery().OfType<FuelReportWorkflowLog>().FirstOrDefault(
                            c => c.WorkflowEntity == actionEntity && c.FuelReportId == entityId && c.Active);

                    if (fuelReportWorkflow == null)
                        throw new ObjectNotFound("FuelReportWorkflow", entityId);

                    fuelReportConfigurator.Configure(fuelReportWorkflow.FuelReport);

                    currentApprovalWorkFlow = fuelReportWorkflow;

                    break;

                case WorkflowEntities.CharterIn:
                    var charterWorkflow =
                        _workflowLogRepository.GetQuery().OfType<CharterWorkflowLog>().FirstOrDefault(
                            c => c.WorkflowEntity == actionEntity && c.CharterId == entityId && c.Active);

                    if (charterWorkflow == null)
                        throw new ObjectNotFound("CharterWorkflow", entityId);

                    _charterConfigurator.Configure(charterWorkflow.Charter);

                    currentApprovalWorkFlow = charterWorkflow;

                    break;
                case WorkflowEntities.CharterOut:
                    var charterOutWorkflow =
                        _workflowLogRepository.GetQuery().OfType<CharterWorkflowLog>().FirstOrDefault(
                            c => c.WorkflowEntity == actionEntity && c.CharterId == entityId && c.Active);

                    if (charterOutWorkflow == null)
                        throw new ObjectNotFound("CharterWorkflow", entityId);

                    _charterConfigurator.Configure(charterOutWorkflow.Charter);

                    currentApprovalWorkFlow = charterOutWorkflow;

                    break;
                case WorkflowEntities.Scrap:
                    var scrapWorkflow =
                        _workflowLogRepository.GetQuery().OfType<ScrapWorkflowLog>().FirstOrDefault(
                            c => c.WorkflowEntity == actionEntity && c.ScrapId == entityId && c.Active);

                    if (scrapWorkflow == null)
                        throw new ObjectNotFound("ScrapWorkflow", entityId);

                    scrapConfigurator.Configure(scrapWorkflow.Scrap);

                    currentApprovalWorkFlow = scrapWorkflow;

                    break;
                case WorkflowEntities.Offhire:
                    var offhireWorkflow =
                        _workflowLogRepository.GetQuery().OfType<OffhireWorkflowLog>().FirstOrDefault(
                            c => c.WorkflowEntity == actionEntity && c.OffhireId == entityId && c.Active);

                    if (offhireWorkflow == null)
                        throw new ObjectNotFound("OffhireWorkflow", entityId);

                    offhireConfigurator.Configure(offhireWorkflow.Offhire);

                    currentApprovalWorkFlow = offhireWorkflow;

                    break;
                default:
                    throw new ArgumentOutOfRangeException("actionEntity");
            }

            if (currentApprovalWorkFlow == null)
                throw new WorkFlowException("Record Not Have WorkFlow Object");
            return currentApprovalWorkFlow;
        }