SourceCode.Workflow.Client API快速入门(发起流程,审批流程) - TOMMYHU - 专注互联网开发及运营技术,提供相关资料及软件下载,奇趣网络时事评论!
Jun 14

SourceCode.Workflow.Client API快速入门(发起流程,审批流程) 不指定

tommyhu , 21:04 , » , Comments(0) , Trackbacks(0) , Reads(8144) , Via Original Large | Medium | Small
本文主要描述SourceCode.Workflow.Client API的使用,为初次进行blackpearl流程开发的朋友提供入门介绍。
首先要在项目中添加对SourceCode.Workflow.Client.dll的引用,然后在代码页面中添加using SourceCode.Workflow.Client;
   (一)发起流程
           Connection conn = null;
            try
            {
                string k2ServerName = "blackpearl"; // 设置K2服务器名称
                conn = new Connection();
                conn.Open(k2ServerName); // 打开连接

                ProcessInstance procInst = conn.CreateProcessInstance("TestProject\\Process1"); // 创建流程实例,参数为流程的FullName

                //设置Folio,以及相关DataField。注意DataField必须在流程设计时已经定义。
                procInst.Folio = "My first process instance";
                procInst.DataFields["Field1"].Value = "...";
                procInst.DataFields["Field2"].Value = "...";

                conn.StartProcessInstance(procInst); // 启动流程。注意当前用户必须对流程TestProject\\Process1有Start(启动)权限,否则抛出无启动权限的错误
            }
            catch (Exception ex)
            {
                throw ex; // 或其它错误处理
            }
            finally
            {
                if (conn != null) // 关闭连接
                {
                    conn.Close();
                }
            }
复制代码
(二)获取工作项
           Connection conn = null;
            try
            {
                string k2ServerName = "blackpearl"; // 设置K2服务器名称
                new Connection();
                conn.Open(k2ServerName); // 打开连接

                Worklist worklist = conn.OpenWorklist(); // 获取当前用户的所有工作项列表,Worklist是WorklistItem的集合
                

                //也可以根据条件获取当前用户的工作项列表
                WorklistCriteria wc = new WorklistCriteria();
                wc.Platform = "ASP";
                wc.AddFilterField(WCLogical.Or, WCField.WorklistItemOwner, "Me", WCCompare.Equal, WCWorklistItemOwner.Me);
                wc.AddFilterField(WCLogical.Or, WCField.WorklistItemOwner, "Other", WCCompare.Equal, WCWorklistItemOwner.Other);

                //想找Folio中含有My的工作项
                wc.AddFilterField(WCLogical.And, WCField.ProcessFolio, WCCompare.Like, "%My%");
                worklist = conn.OpenWorklist(wc); // 获取当前用户的所有工作项列表


            }
            catch (Exception ex)
            {
                throw ex; // 或其它错误处理
            }
            finally
            {
                if (conn != null) // 关闭连接
                {
                    conn.Close();
                }
            }
复制代码
(三) 审批流程
          Connection conn = null;
            try
            {
                string k2ServerName = "blackpearl"; // 设置K2服务器名称
                conn = new Connection();
                conn.Open(k2ServerName); // 打开连接

                string sn = Request["SN"].ToString(); //首先得到一个SN,对ASP.NET表单来说,该值可以从Request["SN"]中得到

                WorklistItem item = conn.OpenWorklistItem(sn); // 根据SN得到具体的工作项

                // 得到WorklistItem后就可以知道该工作项有哪些审批动作,我们可以把这些审批动作显示在用户界面供用户选择
                foreach (SourceCode.Workflow.Client.Action action in item.Actions)
                {
                    this.DropDownList1.Items.Add(action.Name); // 假如您的审批页面用DropDownList控件显示审批动作
                }
                
                // 如何使流程往前走呢?使工作项执行所选定的审批动作就可以了。
                item.Actions[this.DropDownList1.SelectedItem.Text].Execute();
            }
            catch (Exception ex)
            {
                throw ex; // 或其它错误处理
            }
            finally
            {
                if (conn != null) // 关闭连接
                {
                    conn.Close();
                }
            }
▲返回顶部

Add a comment

Nickname

emotemotemotemotemotemotemotemotemotemotemotemotemotemotemotemot