workflow-创建顺序工作流

1 vs2012中新建项目,选择.net framework3.0->workflow->顺序工作流控制台程序

 

 

 

2 在Workflow1.cs中,拖入IfElse和两个Code活动,并改名

 

 

3 添加代码条件,选择条件->选择代码->在Condition中输入代码方法,按回车

4选择ApprovalOrder活动,在属性事件窗口,选择ExecuteCode按回车 

5 修改后的Workflow代码

using System;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.Collections;

using System.Workflow.ComponentModel.Compiler;
using System.Workflow.ComponentModel.Serialization;
using System.Workflow.ComponentModel;
using System.Workflow.ComponentModel.Design;
using System.Workflow.Runtime;
using System.Workflow.Activities;
using System.Workflow.Activities.Rules;

namespace MyApprovalOrder
{
    public sealed partial class Workflow1 : SequentialWorkflowActivity
    {
        public Workflow1()
        {
            InitializeComponent();
        }

        private bool _Approved =false;

        public bool Approved
        {
            get { return _Approved; }
            set { _Approved = value; }
        }
        


        private void IsApproved(object sender, ConditionalEventArgs e)
        {
            e.Result = _Approved;
        }

        private void ApprovalOrder_ExecuteCode(object sender, EventArgs e)
        {
            Console.WriteLine("订单被批准了");
        }

        private void RejectOrder_ExecuteCode(object sender, EventArgs e)
        {
            Console.WriteLine("订单被取消了");
        }
    }

}

 6 修改Program代码

using System;
using System.Collections.Generic;

using System.Text;
using System.Threading;
using System.Workflow.Runtime;
using System.Workflow.Runtime.Hosting;

namespace MyApprovalOrder
{
    class Program
    {
        static void Main(string[] args)
        {

            Console.WriteLine("是否核准该单据?请输入Y或者Yes");
            string str = Console.ReadLine();

            using (WorkflowRuntime workflowRuntime = new WorkflowRuntime())
            {
                AutoResetEvent waitHandle = new AutoResetEvent(false);
                workflowRuntime.WorkflowCompleted += delegate(object sender, WorkflowCompletedEventArgs e) { waitHandle.Set(); };
                workflowRuntime.WorkflowTerminated += delegate(object sender, WorkflowTerminatedEventArgs e)
                {
                    Console.WriteLine(e.Exception.Message);
                    waitHandle.Set();
                };


                Dictionary<string, object> wfArgument = new Dictionary<string, object>();
                bool approvedArg = str == "Y" ? true : false;
                wfArgument.Add("Approved", approvedArg);


                WorkflowInstance instance = workflowRuntime.CreateWorkflow(typeof(MyApprovalOrder.Workflow1),wfArgument);
                instance.Start();

                waitHandle.WaitOne();
            }


            Console.Read();
        }
    }
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值