/// <summary> /// 获取下一节点名称及人员信息 /// </summary> /// <param name="instanceId">工作流实例ID</param> /// <param name="fTask">当前环节名</param> /// <param name="nextNodeName">下一节点名称,引用类型</param> /// <param name="roleId">下一节点配置的人员、角色ID,引用类型</param> /// <param name="roleName">下一节点配置的人员、角色名称,引用类型</param> /// <param name="roleType">下一节点配置的类型,用于区别人员还是角色。值为ADAccount时是人员,其它表示角色</param> public static void GetNextNodeContentsByNodeName(string instanceId, string NodeName, ref string nextNodeName, ref string roleId, ref string roleName, ref string roleType) { WorkflowInstance ins = WorkflowInstance.Find(instanceId); //Aim.WorkFlow.WorkflowTemplate temp = Aim.WorkFlow.WorkflowTemplate.Find(ins.WorkflowTemplateID); XmlDocument doc = new XmlDocument(); doc.LoadXml(ins.XAML); XmlElement root = doc.DocumentElement; string nameSpace = root.NamespaceURI; XmlNamespaceManager nsmgr = new XmlNamespaceManager(doc.NameTable); nsmgr.AddNamespace("ns", nameSpace); nsmgr.AddNamespace("x", "http://schemas.microsoft.com/winfx/2006/xaml"); nsmgr.AddNamespace("bwa", "clr-namespace:BPM.WF.Activities;assembly=BPM.WF"); string current = "ApprovalNode Name=\"" + NodeName + "\""; if (root.SelectSingleNode("//*[contains(@ApprovalNodeConfig,'" + current + "')]", nsmgr) != null)//直接路由 { string config = System.Web.HttpUtility.HtmlDecode(root.SelectSingleNode("//*[contains(@ApprovalNodeConfig,'" + current + "')]", nsmgr).Attributes["ApprovalNodeConfig"].InnerXml); XmlDocument docC = new XmlDocument(); docC.LoadXml(config); nextNodeName = docC.DocumentElement.Attributes["Name"].InnerText.ToString(); if (docC.DocumentElement.SelectSingleNode("ApprovalUnits") != null && docC.DocumentElement.SelectSingleNode("ApprovalUnits").ChildNodes.Count > 0) { XmlNodeList list = docC.DocumentElement.SelectSingleNode("ApprovalUnits").ChildNodes; foreach (XmlNode chd in list) { roleId += chd.ChildNodes[0].Attributes["Value"].InnerText + ","; roleName += chd.ChildNodes[0].Attributes["Name"].InnerText + ","; roleType = chd.ChildNodes[0].Attributes["Type"].InnerText; } } } }
/// <summary> /// 获取下一节点名称及人员信息 /// </summary> /// <param name="fTask">Aim.WorkFlow.Task 实体(根据task表ID获得)</param> /// <param name="nextNodeName">下一节点名称,引用类型</param> /// <param name="roleId">下一节点配置的人员、角色ID,引用类型</param> /// <param name="roleName">下一节点配置的人员、角色名称,引用类型</param> /// <param name="roleType">下一节点配置的类型,用于区别人员还是角色。值为ADAccount时是人员,其它表示角色</param> public static void GetNextNodeContents(Task fTask, ref string nextNodeName, ref string roleId, ref string roleName, ref string roleType) { XmlSerializer xs = new XmlSerializer(typeof(TaskContext)); if (!string.IsNullOrEmpty(fTask.Context)) { StringReader sr = new StringReader(fTask.Context); TaskContext content = xs.Deserialize(sr) as TaskContext; if (content.SwitchRules.Length > 0) { TaskContextSwitchRuleNextAction[] arrs = content.SwitchRules[0].NextActions; if (arrs.Length > 0) { string route = arrs[0].Name; WorkflowInstance ins = WorkflowInstance.Find(fTask.WorkflowInstanceID); //Aim.WorkFlow.WorkflowTemplate temp = Aim.WorkFlow.WorkflowTemplate.Find(ins.WorkflowTemplateID); XmlDocument doc = new XmlDocument(); doc.LoadXml(ins.XAML); XmlElement root = doc.DocumentElement; string nameSpace = root.NamespaceURI; XmlNamespaceManager nsmgr = new XmlNamespaceManager(doc.NameTable); nsmgr.AddNamespace("ns", nameSpace); nsmgr.AddNamespace("x", "http://schemas.microsoft.com/winfx/2006/xaml"); nsmgr.AddNamespace("bwa", "clr-namespace:BPM.WF.Activities;assembly=BPM.WF"); string current = "ApprovalNode Name=\"" + fTask.ApprovalNodeName + "\""; XmlNode currentNode = root.SelectSingleNode("//*[contains(@ApprovalNodeConfig,'" + current + "')]", nsmgr); //XmlNode node = root.SelectSingleNode("//*[@x:Key='" + nextName + "']", nsmgr); XmlNode node = currentNode.NextSibling.SelectSingleNode("ns:FlowSwitch/ns:FlowStep[@x:Key='" + route + "']", nsmgr); string contents = "ApprovalNode Name=\"" + route + "\""; if (root.SelectSingleNode("//*[contains(@ApprovalNodeConfig,'" + contents + "')]", nsmgr) != null)//直接路由 { string config = System.Web.HttpUtility.HtmlDecode(root.SelectSingleNode("//*[contains(@ApprovalNodeConfig,'" + contents + "')]", nsmgr).Attributes["ApprovalNodeConfig"].InnerXml); XmlDocument docC = new XmlDocument(); docC.LoadXml(config); nextNodeName = docC.DocumentElement.Attributes["Name"].InnerText.ToString(); if (docC.DocumentElement.SelectSingleNode("ApprovalUnits") != null && docC.DocumentElement.SelectSingleNode("ApprovalUnits").ChildNodes.Count > 0) { XmlNodeList list = docC.DocumentElement.SelectSingleNode("ApprovalUnits").ChildNodes; foreach (XmlNode chd in list) { roleId += chd.ChildNodes[0].Attributes["Value"].InnerText + ","; roleName += chd.ChildNodes[0].Attributes["Name"].InnerText + ","; roleType = chd.ChildNodes[0].Attributes["Type"].InnerText; } } } } } } }
public static ApprovalResult GetApprovalResult(Aim.WorkFlow.WinService.Task task, string taskId, string winstanceId, string route, params string[] UserIdsNames) { ApprovalResult result = new ApprovalResult() { Task = task, TaskId = task.ID, ApprovalDateTime = DateTime.Now, Opinion = ApprovalOpinion.意, ExtendedProperties = new List <KeyValuePair_V2>().ToArray(), ApprovalNodeSkipInfoList = new List <ApprovalNodeSkipInfo>().ToArray(), //Comment = "" }; /// 设定跳过后续哪些节点. /*List<ApprovalNodeSkipInfo> approvalNodeSkipInfos = new List<ApprovalNodeSkipInfo>(); * * if (checkBox1.IsChecked.HasValue && checkBox1.IsChecked.Value) * approvalNodeSkipInfos.Add(new ApprovalNodeSkipInfo() { ApprovalNodeContextName = "经理审批", CanBeSkipped = true }); * * if (checkBox2.IsChecked.HasValue && checkBox2.IsChecked.Value) * approvalNodeSkipInfos.Add(new ApprovalNodeSkipInfo() { ApprovalNodeContextName = "主管审批", CanBeSkipped = true }); * * result.ApprovalNodeSkipInfoList = approvalNodeSkipInfos.ToArray(); */ /// 设定选中的流转节点 if (route != "") { result.SwitchRules = new KeyValuePair_V2[] { new KeyValuePair_V2() { Key = task.ApprovalNodeName, Value = route } }; WorkflowInstance ins = WorkflowInstance.Find(winstanceId); //Aim.WorkFlow.WorkflowTemplate temp = Aim.WorkFlow.WorkflowTemplate.Find(ins.WorkflowTemplateID); XmlDocument doc = new XmlDocument(); doc.LoadXml(ins.XAML); XmlElement root = doc.DocumentElement; string nameSpace = root.NamespaceURI; XmlNamespaceManager nsmgr = new XmlNamespaceManager(doc.NameTable); nsmgr.AddNamespace("ns", nameSpace); nsmgr.AddNamespace("x", "http://schemas.microsoft.com/winfx/2006/xaml"); nsmgr.AddNamespace("bwa", "clr-namespace:BPM.WF.Activities;assembly=BPM.WF"); string current = "ApprovalNode Name=\"" + task.ApprovalNodeName + "\""; XmlNode currentNode = root.SelectSingleNode("//*[contains(@ApprovalNodeConfig,'" + current + "')]", nsmgr); //XmlNode node = root.SelectSingleNode("//*[@x:Key='" + nextName + "']", nsmgr); XmlNode node = currentNode.NextSibling.SelectSingleNode("ns:FlowSwitch/ns:FlowStep[@x:Key='" + route + "']", nsmgr); string nextUserIds = ""; string nextUserNames = ""; string nextUserAccountType = ""; string nextNodeName = ""; string content = "ApprovalNode Name=\"" + route + "\""; if (root.SelectSingleNode("//*[contains(@ApprovalNodeConfig,'" + content + "')]", nsmgr) != null)//直接路由 { string config = System.Web.HttpUtility.HtmlDecode(root.SelectSingleNode("//*[contains(@ApprovalNodeConfig,'" + content + "')]", nsmgr).Attributes["ApprovalNodeConfig"].InnerXml); XmlDocument docC = new XmlDocument(); docC.LoadXml(config); nextNodeName = docC.DocumentElement.Attributes["Name"].InnerText.ToString(); if (docC.DocumentElement.SelectSingleNode("ApprovalUnits") != null && docC.DocumentElement.SelectSingleNode("ApprovalUnits").ChildNodes.Count > 0) { XmlNodeList list = docC.DocumentElement.SelectSingleNode("ApprovalUnits").ChildNodes; foreach (XmlNode chd in list) { nextUserIds += chd.ChildNodes[0].Attributes["Value"].InnerText + ","; nextUserNames += chd.ChildNodes[0].Attributes["Name"].InnerText + ","; nextUserAccountType = chd.ChildNodes[0].Attributes["Type"].InnerText; } } } nextUserIds = nextUserIds.TrimEnd(','); nextUserNames = nextUserNames.TrimEnd(','); /// 设定指定流转节点的审批人员的信息. List <ApprovalNodeContext> approvalNodeContexts = new List <ApprovalNodeContext>(); ApprovalNodeContext specifiedApprovalNodeContext = new ApprovalNodeContext(); specifiedApprovalNodeContext.Name = nextNodeName; if (nextUserAccountType != "ADAccount" && nextUserIds != "" && UserIdsNames != null && UserIdsNames.Length == 0)//如果是组或者角色 { string[] grpIds = nextUserIds.Split(','); string[] grpNames = nextUserNames.Split(','); List <ApprovalUnitContext> approvalUnitContexts = new List <ApprovalUnitContext>(); foreach (string groupId in grpIds) { string cou = @"select count(*) from (select distinct ParentDeptName from View_SysUserGroup where ChildDeptName=(Select Name from SysRole where RoleID='{0}')) a"; string sql = ""; int count = DataHelper.QueryValue <int>(string.Format(cou, groupId)); IList <EasyDictionary> lists = null; //判断角色的唯一性,多部门角色需要对应到部门 if (count > 1) { sql = @"select distinct UserID,UserName Name from View_SysUserGroup where ChildDeptName in (Select Name from SysRole where RoleID='{0}') and (select top 1 Path+'.'+DeptId from View_SysUserGroup where UserID='{1}') like '%'+Path+'%'"; sql = string.Format(sql, groupId, task.OwnerId); lists = DataHelper.QueryDictList(sql); } else if (count == 1) { sql = "select UserId,UserName Name from View_SysUserGroup where ChildDeptName=(Select Name from SysRole where RoleID='{0}')"; sql = string.Format(sql, groupId); lists = DataHelper.QueryDictList(sql); } if (lists == null || lists.Count == 0) { throw new Exception("缺少角色" + nextUserNames + "的人员!"); } foreach (EasyDictionary ed in lists) { approvalUnitContexts.Add(new ApprovalUnitContext() { Approver = new Approver() { Value = ed["UserID"].ToString(), Name = ed["Name"].ToString() } }); } } specifiedApprovalNodeContext.ApprovalUnitContexts = approvalUnitContexts.ToArray(); approvalNodeContexts.Add(specifiedApprovalNodeContext); result.SpecifiedApprovalNodeContexts = approvalNodeContexts.ToArray(); } else if (UserIdsNames != null && UserIdsNames.Length == 2) { LoadFromConfigString(specifiedApprovalNodeContext, UserIdsNames[0].TrimEnd(','), UserIdsNames[1].TrimEnd(',')); approvalNodeContexts.Add(specifiedApprovalNodeContext); result.SpecifiedApprovalNodeContexts = approvalNodeContexts.ToArray(); } else if (nextUserIds.Trim() != "") { LoadFromConfigString(specifiedApprovalNodeContext, nextUserIds, nextUserNames); approvalNodeContexts.Add(specifiedApprovalNodeContext); result.SpecifiedApprovalNodeContexts = approvalNodeContexts.ToArray(); } /*List<ApprovalNodeContext> approvalNodeContexts = new List<ApprovalNodeContext>(); * * ApprovalNodeContext specifiedApprovalNodeContext = new ApprovalNodeContext(); * specifiedApprovalNodeContext.Name = this.RequestData["RouteName"].ToString(); * * string userIds = this.RequestData["UserIds"].ToString().TrimEnd(','); * string userNames = this.RequestData["UserNames"].ToString().TrimEnd(','); * LoadFromConfigString(specifiedApprovalNodeContext, userIds,userNames); * approvalNodeContexts.Add(specifiedApprovalNodeContext); * result.SpecifiedApprovalNodeContexts = approvalNodeContexts.ToArray();*/ } return(result); }