Ejemplo n.º 1
0
        public void Save_Click(object sender, AjaxEventArgs e)
        {
            // 一、执行业务业务操作,保存业务数据
            paymentInfo = new TradeInfo()
            {
                Sn               = Sn.Text,
                GoodsName        = GoodsName.SelectedItem.Value,
                UnitPrice        = UnitPrice.Number,
                Quantity         = (long)Quantity.Number,
                Amount           = Amount.Number,
                CustomerName     = CustomerName.Text,
                CustomerMobile   = CustomerMobile.Text,
                CustomerPhoneFax = CustomerPhoneFax.Text
            };
            tradeInfoDao.save(paymentInfo);

            // 二、开始执行流程操作
            IWorkflowSession workflowSession = RuntimeContextExamples.GetRuntimeContext().getWorkflowSession();//.workflowRuntimeContext.getWorkflowSession();

            try
            {
                // 1、创建流程实例
                IProcessInstance procInst = workflowSession.createProcessInstance("Goods_Deliver_Process", this.User.Identity.Name);
                // 2、设置流程变量/业务属性字段
                procInst.setProcessInstanceVariable("sn", paymentInfo.Sn);                 // 设置交易顺序号
                procInst.setProcessInstanceVariable("goodsName", paymentInfo.GoodsName);   // 货物名称
                procInst.setProcessInstanceVariable("quantity", paymentInfo.Quantity);     // 数量
                procInst.setProcessInstanceVariable("mobile", paymentInfo.CustomerMobile); // 客户电话
                procInst.setProcessInstanceVariable("customerName", paymentInfo.CustomerName);

                // 3、启动流程实例,run()方法启动实例并创建第一个环节实例、分派任务
                procInst.run();
            }
            catch
            {
                throw;
            }

            paymentInfo = new TradeInfo();
        }
        public void Save_Click(object sender, AjaxEventArgs e)
        {
            LoanInfoDAO loanInfoDAO = new LoanInfoDAO();
            LoanInfo    loanInfo    = new LoanInfo()
            {
                ApplicantName    = applicantName.Text,
                ApplicantId      = applicantId.Text,
                Address          = address.Text,
                Salary           = int.Parse(salary.Text),
                LoanValue        = int.Parse(loanValue.Text),
                ReturnDate       = returnDate.SelectedDate.ToString("yyyy-MM-dd"),
                Loanteller       = loanteller.Text,
                AppInfoInputDate = DateTime.Parse(appInfoInputDate.Text)
            };

            // 一、执行业务业务操作,保存业务数据
            loanInfoDAO.attachDirty(loanInfo);

            // 二、开始执行流程操作
            IWorkflowSession workflowSession = RuntimeContextExamples.GetRuntimeContext().getWorkflowSession();

            try
            {
                // 1、创建流程实例
                IProcessInstance procInst =
                    workflowSession.createProcessInstance("LoanProcess", this.User.Identity.Name);
                // 2、设置流程变量/业务属性字段
                procInst.setProcessInstanceVariable("sn", loanInfo.Sn);                       // 设置流水号
                procInst.setProcessInstanceVariable("applicantName", loanInfo.ApplicantName); //贷款人姓名
                procInst.setProcessInstanceVariable("loanValue", loanInfo.LoanValue);         // 贷款数额

                // 3、启动流程实例,run()方法启动实例并创建第一个环节实例、分派任务
                procInst.run();
            }
            catch
            {
                throw;
            }
        }
Ejemplo n.º 3
0
        public void run(IWorkflowSession currentSession, RuntimeContext runtimeContext,
                        IProcessInstance processInstance, ITaskInstance taskInstance)// throws EngineException, KernelException
        {
            if (taskInstance.TaskType != TaskTypeEnum.SUBFLOW)
            {
                throw new EngineException(processInstance, taskInstance.Activity,
                                          "DefaultSubflowTaskInstanceRunner:TaskInstance的任务类型错误,只能为SUBFLOW类型");
            }
            Task task = taskInstance.Task;
            SubWorkflowProcess Subflow = ((SubflowTask)task).SubWorkflowProcess;

            WorkflowDefinition subWorkflowDef = runtimeContext.DefinitionService.GetTheLatestVersionOfWorkflowDefinition(Subflow.WorkflowProcessId);

            if (subWorkflowDef == null)
            {
                WorkflowProcess parentWorkflowProcess = taskInstance.WorkflowProcess;
                throw new EngineException(taskInstance.ProcessInstanceId, parentWorkflowProcess, taskInstance.TaskId,
                                          "系统中没有Id为" + Subflow.WorkflowProcessId + "的流程定义");
            }
            WorkflowProcess subWorkflowProcess = subWorkflowDef.getWorkflowProcess();

            if (subWorkflowProcess == null)
            {
                WorkflowProcess parentWorkflowProcess = taskInstance.WorkflowProcess;
                throw new EngineException(taskInstance.ProcessInstanceId, parentWorkflowProcess, taskInstance.TaskId,
                                          "系统中没有Id为" + Subflow.WorkflowProcessId + "的流程定义");
            }

            IPersistenceService persistenceService = runtimeContext.PersistenceService;

            //更改任务的状态和开始时间
            ((TaskInstance)taskInstance).State       = TaskInstanceStateEnum.RUNNING;
            ((TaskInstance)taskInstance).StartedTime = runtimeContext.CalendarService.getSysDate();
            persistenceService.SaveOrUpdateTaskInstance(taskInstance);

            IProcessInstance subProcessInstance = currentSession.createProcessInstance(subWorkflowProcess.Name, taskInstance);

            //初始化流程变量,从父实例获得初始值
            Dictionary <String, Object> processVars = ((TaskInstance)taskInstance).AliveProcessInstance.ProcessInstanceVariables;
            List <DataField>            datafields  = subWorkflowProcess.DataFields;

            for (int i = 0; datafields != null && i < datafields.Count; i++)
            {
                DataField df = (DataField)datafields[i];
                if (df.DataType == DataTypeEnum.STRING)
                {
                    if (processVars[df.Name] != null && (processVars[df.Name] is String))
                    {
                        subProcessInstance.setProcessInstanceVariable(df.Name, processVars[df.Name]);
                    }
                    else if (df.InitialValue != null)
                    {
                        subProcessInstance.setProcessInstanceVariable(df.Name, df.InitialValue);
                    }
                    else
                    {
                        subProcessInstance.setProcessInstanceVariable(df.Name, "");
                    }
                }
                else if (df.DataType == DataTypeEnum.INTEGER)
                {
                    if (processVars[df.Name] != null && (processVars[df.Name] is Int32))
                    {
                        subProcessInstance.setProcessInstanceVariable(df.Name, processVars[df.Name]);
                    }
                    else if (df.InitialValue != null)
                    {
                        try
                        {
                            Int32 intValue = Int32.Parse(df.InitialValue);
                            subProcessInstance.setProcessInstanceVariable(df.Name, intValue);
                        }
                        catch { }
                    }
                    else
                    {
                        subProcessInstance.setProcessInstanceVariable(df.Name, (Int32)0);
                    }
                }
                else if (df.DataType == DataTypeEnum.FLOAT)
                {
                    if (processVars[df.Name] != null && (processVars[df.Name] is float))
                    {
                        subProcessInstance.setProcessInstanceVariable(df.Name, processVars[df.Name]);
                    }
                    else if (df.InitialValue != null)
                    {
                        float floatValue = float.Parse(df.InitialValue);
                        subProcessInstance.setProcessInstanceVariable(df.Name, floatValue);
                    }
                    else
                    {
                        subProcessInstance.setProcessInstanceVariable(df.Name, (float)0);
                    }
                }
                else if (df.DataType == DataTypeEnum.BOOLEAN)
                {
                    if (processVars[df.Name] != null && (processVars[df.Name] is Boolean))
                    {
                        subProcessInstance.setProcessInstanceVariable(df.Name, processVars[df.Name]);
                    }
                    else if (df.InitialValue != null)
                    {
                        Boolean booleanValue = Boolean.Parse(df.InitialValue);
                        subProcessInstance.setProcessInstanceVariable(df.Name, booleanValue);
                    }
                    else
                    {
                        subProcessInstance.setProcessInstanceVariable(df.Name, false);
                    }
                }
                else if (df.DataType == DataTypeEnum.DATETIME)
                {
                    //TODO 需要完善一下 ( 父子流程数据传递——时间类型的数据还未做传递-不知道为什么?)
                    //wmj2003 20090925 补充上了
                    if (processVars[df.Name] != null && (processVars[df.Name] is DateTime))
                    {
                        subProcessInstance.setProcessInstanceVariable(df.Name, processVars[df.Name]);
                    }
                    else if (df.InitialValue != null)
                    {
                        try
                        {
                            DateTime dateTmp = DateTime.Parse(df.InitialValue);
                            subProcessInstance.setProcessInstanceVariable(df.Name, dateTmp);
                        }
                        catch
                        {
                            subProcessInstance.setProcessInstanceVariable(df.Name, null);
                        }
                    }
                }
                //TODO 应将下面这句删除!这里还需要吗?应该直接subProcessInstance.run()就可以了。
                runtimeContext.PersistenceService.SaveOrUpdateProcessInstance(subProcessInstance);
                subProcessInstance.run();
            }
        }