Esempio n. 1
0
        /// <summary>
        /// 添加流程实例审批历史
        /// </summary>
        public static void AddProcessInstanceApprovalHistory(SourceCode.Workflow.Client.WorklistItem worklistItem, ApprovalUserInfo ApprovalUserInfo)
        {
            //获取流程审批历史
            string ApprovalResultXML     = GetInstanceDataFields(worklistItem, "ApprovalResult", true);
            string LastApprovalResultXML = GetInstanceDataFields(worklistItem, "LastApprovalResult", true);

            ApprovalResultXML     = XMLApproval.ToResultXML(ApprovalResultXML);
            LastApprovalResultXML = XMLApproval.ToResultXML(LastApprovalResultXML);

            XMLApproval xmlApproval = new XMLApproval();

            //增加一个审批记录
            xmlApproval.LoadFromXML(ApprovalResultXML);
            xmlApproval.AddApproval(ApprovalUserInfo.ApprovalUserName, ApprovalUserInfo.ApprovalUserId, ApprovalUserInfo.ComAuditText, ApprovalUserInfo.ComAuditComment, GetCurrentActivityName(worklistItem));
            SetInstanceDataFields(worklistItem, "ApprovalResult", xmlApproval.ToXML(), true);

            //设置最后审批历史记录
            xmlApproval.LoadFromXML(LastApprovalResultXML);
            xmlApproval.SetLastApproval(ApprovalUserInfo.ApprovalUserName, ApprovalUserInfo.ApprovalUserId, ApprovalUserInfo.ComAuditText, ApprovalUserInfo.ComAuditComment, GetCurrentActivityName(worklistItem));
            SetInstanceDataFields(worklistItem, "LastApprovalResult", xmlApproval.ToXML(), true);

            //设置审批结果
            SetInstanceDataFields(worklistItem, "ComAuditComment", ApprovalUserInfo.ComAuditComment, false);
            SetInstanceDataFields(worklistItem, "ComAuditResult", ApprovalUserInfo.ComAuditResult, false);
        }
Esempio n. 2
0
        /// <summary>
        /// 获取流程实例审批历史(转JSON)
        /// </summary>
        /// <param name="SN"></param>
        /// <param name="ApprovalUserId"></param>
        /// <returns></returns>
        public static string GetProcessInstanceApprovalHistory(string SN, string ApprovalUserId)
        {
            Connection connection = GetK2Connection();

            try
            {
                ImpersonateUser(connection, ApprovalUserId);
                SourceCode.Workflow.Client.WorklistItem worklistItem = connection.OpenWorklistItem(SN);
                string ApprovalResultXML = worklistItem.ProcessInstance.XmlFields["ApprovalResult"].Value;
                if (ApprovalResultXML != null)
                {
                    XMLApproval xmlApproval = new XMLApproval();
                    xmlApproval.LoadFromXML(ApprovalResultXML);
                    return(xmlApproval.mobj.ToJson());
                }
                return("");
            }
            catch (Exception ex)
            {
                throw new K2Exception(ex.ToString());
            }
            finally
            {
                // 关闭连接
                if (connection != null)
                {
                    connection.Close();
                }
            }
        }
Esempio n. 3
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();
                }
            }
        }