Beispiel #1
0
        /// <summary>
        /// 根据流程类型生成 Folio
        /// </summary>
        /// <returns></returns>
        public static string CreateFolio(string WorkflowTypeName, ApplyUserInfo ApplyUserInfo)
        {
            switch (WorkflowTypeName)
            {
            case "上海职员劳务合同审批":
                return("[" + ApplyUserInfo.ApplyDeptName + " " + ApplyUserInfo.ApplyUserName + "/" + ApplyUserInfo.ApplyUserId + "]提交的" + WorkflowTypeName);

            default:
                return("");
            }
        }
Beispiel #2
0
        /// <summary>
        /// 发起新的流程实例
        /// </summary>
        /// <param name="WorkflowTypeName">流程类型</param>
        /// <param name="dicDataFields">流程参数集合</param>
        /// <param name="Folio">流程单号</param>
        /// <param name="Sync">发起流程是否异步(默认否)</param>
        /// <returns></returns>
        public static void StartProcessInstance(string WorkflowTypeName, Dictionary <string, object> dicDataFields, string ApplyUserInfoString, bool Sync = false)
        {
            Connection connection = GetK2Connection();//创建K2 链接

            try
            {
                string ProcessInstanceName = GetWorkflowName(WorkflowTypeName);//获取流程全称

                //创建新的流程实例
                SourceCode.Workflow.Client.ProcessInstance pi = connection.CreateProcessInstance(ProcessInstanceName);
                var PIDataFields = pi.DataFields;

                //循环赋值流程参数
                foreach (var dic in dicDataFields)
                {
                    PIDataFields[dic.Key].Value = dic.Value;
                }
                ApplyUserInfo applyUserInfo = ApplyUserInfoString.ToObject <ApplyUserInfo>();

                pi.Folio = CreateFolio(WorkflowTypeName, applyUserInfo);

                //添加审批历史
                string ApprovalResultXML = string.Empty;
                ApprovalResultXML = XMLApproval.ToResultXML(ApprovalResultXML);
                XMLApproval xmlApproval = new XMLApproval();
                xmlApproval.LoadFromXML(ApprovalResultXML);
                xmlApproval.AddApproval(applyUserInfo.ApplyUserName, applyUserInfo.ApplyUserId, "发起", string.Empty, "发起流程");
                pi.XmlFields["ApprovalResult"].Value = xmlApproval.ToXML();

                //发起流程实例
                connection.StartProcessInstance(pi, Sync);
            }
            catch (Exception ex)
            {
                throw new K2Exception(ex.ToString());
            }
            finally
            {
                // 关闭连接
                if (connection != null)
                {
                    connection.Close();
                }
            }
        }