/// <summary> /// 审批流程实例 /// </summary> /// <param name="SN">流程编号</param> /// <param name="DicDataFields">流程参数</param> /// <param name="ManagedUser">流程审批者</param> /// <param name="SharedUser">流程共同审批者</param> /// <param name="ActionName">流程动作</param> /// <param name="Platform">流程审批页面平台</param> public static void ApprovalProcessInstance(string SN, Dictionary <string, object> DicDataFields, string ApprovalUserInfoString) { Connection Connection = GetK2Connection();//创建K2 链接 try { ApprovalUserInfo ApprovalUserInfo = ApprovalUserInfoString.ToObject <ApprovalUserInfo>(); ImpersonateUser(Connection, ApprovalUserInfo.ApprovalUserId); //获取流程工作项 SourceCode.Workflow.Client.WorklistItem wit = GetWorkListItemBySN(Connection, SN, ApprovalUserInfo.ManagedUser, ApprovalUserInfo.SharedUser, PLATFORM); BatchSetInstanceDataFields(wit, DicDataFields); //添加审批历史 AddProcessInstanceApprovalHistory(wit, ApprovalUserInfo); //设置审批动作 (节点审批成功(任务自动完成)) string ActionName = string.IsNullOrEmpty(ApprovalUserInfo.ActionName) ? ACTIONNAME : ApprovalUserInfo.ActionName; //执行审批动作 wit.Actions[ActionName].Execute(); } catch (Exception ex) { throw new K2Exception(ex.ToString()); } finally { // 关闭连接 if (Connection != null) { Connection.Close(); } } }
/// <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); }