1、采用WF实现审批备案的流程运转,采用微软WF工作流实现国资监管审批备案业务的流程定义和运转,主要内容,国资监管审批备案业务概述微软WF工作流概述采用WF定义审批备案业务流程DotNET程序与WF工作流之间调用和通信实现步骤,国资监管审批备案业务概述,审批备案是国资委各处室使用较频繁的一项业务。主要包括审批和备案两项业务。审批业务定义:国资委各相应处室对企业上报的审批事项进行审批,审批结束后通知企业审批结果。备案业务定义:国资委各相应处室对企业上报的备案事项进行审批,审批通过后进行备案。审批备案的审批流程参与处室较多,且流程多变。使用手工代码处理流程的方式因维护量大、开发周期长,已不能满足灵活多
2、变的审批流程的要求。,审批备案业务流程,微软WF工作流概述,微软WF(WorkFlow Foundation)免费的基于DotNET平台的工作流组件。运行在DotNET Framework3.0及以上版本。WF提供了流程运行引擎和流程设计工具。流程引擎运行在宿主程序中,宿主程序可以是桌面程序,也可以是web程序。通过引用System.Workflow.Runtime调用引擎。流程设计工具集成在VisualStudio中,Vs2008自带。可以新建WorkFlow项目。,微软WF工作流概述,WF工作流分为两种类型顺序工作流 Sequential WorkFow状态机工作流 StateMachin
3、e WorkFlow顺序工作流基于自上而下的流程。适用于一次性的数据处理。可用于基于SOA的EAI,微软的EAI工具BizTalk就是基于WF的。状态机工作流基于状态流转的工作流。适用于人和系统之间的交互可用与审批流包含丰富的活动控件(Activity),将各活动控件连接起来形成一个完成的工作流,采用WF定义审批备案业务流程,DotNET程序与WF工作流之间调用和通信,DotNET程序激活工作流,工作流调用外部DotNET程序,实现步骤,创建工作流创建工作流服务接口和服务程序,将服务接口绑定工作流创建用户程序启动运行时创建工作流实例。并绑定工作流服务,创建工作流,拖拽State在State中添
4、加EventDriven双击EventDriven添加handleExternal和SetState,创建工作流,绑定handleExternalActivity在State中添加EventDriven,工作流服务接口,ExternalDataExchange public interface IApproveService event EventHandler Upload; event EventHandler ReUpload; event EventHandler OfficeOK; event EventHandler OfficeNo; event EventHandler Dep
5、artmentOK; event EventHandler DepartmentNo;,工作流服务,Serializable public class ApproveService : IApproveService public event EventHandler Upload; public event EventHandler ReUpload; public event EventHandler OfficeOK; public event EventHandler OfficeNo; public event EventHandler DepartmentOK; public ev
6、ent EventHandler DepartmentNo; public void RaiseUploadEvent(string approveItemID, Guid instanceId) if (Upload != null) ApproveEventArgs e = new ApproveEventArgs(instanceId, approveItemID); Upload(this, e); ,工作流实例传递参数,Serializable public class ApproveEventArgs : ExternalDataEventArgs private string a
7、pproveItemID; public ApproveEventArgs(Guid instanceId, string ApproveItemID) : base(instanceId) approveItemID = ApproveItemID; public string ApproveItemID get return approveItemID; set approveItemID = value; ,用户程序-启动工作流运行时runtime,WorkflowRuntime runtime;ApproveService approveService; runtime = new W
8、orkflowRuntime(); runtime.WorkflowTerminated += new EventHandler(Runtime_WorkflowTerminated);runtime.WorkflowCompleted += new EventHandler(Runtime_WorkflowCompleted);runtime.WorkflowIdled += new EventHandler(Runtime_WorkflowIdled); ExternalDataExchangeService dataExchangeService = new ExternalDataEx
9、changeService();runtime.AddService(dataExchangeService); approveService = new ApproveService();dataExchangeService.AddService(approveService); runtime.StartRuntime();,用户程序-启动工作流实例,Assembly workflowsAssembly =Assembly.Load(Workflow); Type workflowType = workflowsAssembly.GetType(Workflow.Workflow1);i
10、f (workflowType = null) return Guid.Empty;WorkflowInstance instance = runtime.CreateWorkflow(workflowType,parameters); StateMachineWorkflowInstance stateMachineInstance = new StateMachineWorkflowInstance(runtime, instance.InstanceId);instance.Start();,用户程序-激活工作流的handleExternal活动,-激活工作流运转approveServi
11、ce.RaiseOfficeOKEvent(01, new Guid(item.Text);-检索宿主程序中的工作流ReadOnlyCollection os = runtime.GetLoadedWorkflows();foreach (WorkflowInstance o in os) StateMachineWorkflowInstance stateInstance = new StateMachineWorkflowInstance(runtime, o.InstanceId);ListViewItem item = this.listView1.Items.Add( o.Insta
12、nceId.ToString(), o.InstanceId.ToString(), ); item.SubItems.Add(); item.SubItems.Add(stateInstance.CurrentStateName);,运行效果,Advance Topic,传参程序与工作流实例之间传递参数分两种方式初始化传参事件传参持久化WF提供持续化服务接口,可将工作流实例持续化到文件或数据库中。WF为我们提供了SQLServer的持续化服务。,初始化传参,在工作流中定义属性public string itemID = string.Empty;public string ItemID ge
13、t return this.itemID; set this.itemID = value; 程序创建工作流的时候给属性赋值Dictionary parameters = new Dictionary();parameters.Add(ItemID, this.textBox1.Text); WorkflowInstance instance = runtime.CreateWorkflow(workflowType, parameters);,事件传参,在工作流中定义属性程序创建工作流的时候给属性赋值public void RaiseDepartmentOKEvent(string appr
14、oveItemID, Guid instanceId) if (DepartmentOK != null) ApproveEventArgs e = new ApproveEventArgs(instanceId, approveItemID); DepartmentOK(this, e);,持久化,创建表C:WINDOWSMicrosoft.NETFrameworkv3.0Windows Workflow FoundationSQLENSqlPersistenceService_Schema.sqlSqlPersistenceService_Logic.sql程序调用String connS
15、tringPersistence = String.Format(“Initial Catalog=0;Data Source=1;User=2;Password=3”, “model”, “gsligc”, “sa”, “密码);persistence = new SqlWorkflowPersistenceService(connStringPersistence, true, new TimeSpan(0, 2, 0), new TimeSpan(0, 0, 5);runtime.AddService(persistence);,检索持久化数据库中的工作流,foreach (SqlPer
16、sistenceWorkflowInstanceDescription o in (SqlWorkflowPersistenceService)persistence).GetAllWorkflows() StateMachineWorkflowInstance stateInstance = new StateMachineWorkflowInstance(runtime, o.WorkflowInstanceId); ListViewItem item = this.listView1.Items.Add(o.WorkflowInstanceId.ToString(), o.WorkflowInstanceId.ToString(), ); item.SubItems.Add(); item.SubItems.Add(stateInstance.CurrentStateName);,THE END,