/// <summary> /// 增加iframe节点 /// </summary> /// <param name="iframe"></param> /// <param name="actdef"></param> /// <param name="prodef"></param> public static void AddIframeToXML(IFrameEntity iframe, ActdefEntity actdef, ProdefEntity prodef, String secondPackageId, String childProdefId) { String path = CreateActionCommon.GetXmlPath(prodef.Key, childProdefId); XmlNode nodeActdef = null; XmlDocument doc = GetActdefNode(actdef, prodef, out nodeActdef, path, secondPackageId); XmlNode nodeIframe = nodeActdef.SelectSingleNode("iframe"); if (nodeIframe == null) { nodeIframe = doc.CreateElement("iframe") as XmlNode; nodeActdef.AppendChild(nodeIframe); } XmlNode nodeTempIframe = nodeIframe.SelectSingleNode("iframeChild[@ID='" + iframe.Id + "']"); if (nodeTempIframe != null) { nodeTempIframe.ParentNode.RemoveChild(nodeTempIframe); } XmlElement elementTempIframe = doc.CreateElement("iframeChild"); elementTempIframe.SetAttribute("ID", iframe.Id); elementTempIframe.SetAttribute("Name", iframe.Name); elementTempIframe.SetAttribute("URL", iframe.UrlPath); nodeIframe.AppendChild(elementTempIframe); doc.Save(path); }
/// <summary> /// 添加环节信息 /// </summary> /// <param name="actdef"></param> /// <param name="prodef"></param> /// <param name="nodeActdef"></param> /// <param name="path"></param> /// <returns></returns> private static XmlDocument GetActdefNode(ActdefEntity actdef, ProdefEntity prodef, out XmlNode nodeActdef, String path, String secondPackageId) { XmlDocument doc = new XmlDocument(); if (File.Exists(path)) { doc.Load(path); } XmlNode nodeRoot = doc.SelectSingleNode("Element"); if (nodeRoot == null) { XmlDeclaration declar = doc.CreateXmlDeclaration("1.0", "utf-8", "yes"); doc.AppendChild(declar); nodeRoot = doc.CreateElement("Element") as XmlNode; doc.AppendChild(nodeRoot); } XmlNode nodeProdef = nodeRoot.SelectSingleNode("Prodef[@ID='" + prodef.Key + "']"); if (nodeProdef == null) { XmlElement elementProdef = doc.CreateElement("Prodef"); elementProdef.SetAttribute("ID", prodef.Key); elementProdef.SetAttribute("Name", prodef.Name); elementProdef.SetAttribute("PackageID", secondPackageId); nodeProdef = elementProdef as XmlElement; nodeRoot.AppendChild(nodeProdef); } nodeActdef = nodeProdef.SelectSingleNode("Actdef[@ID='" + actdef.Task_id + "']"); if (nodeActdef == null) { XmlElement elementActdef = doc.CreateElement("Actdef"); elementActdef.SetAttribute("ID", actdef.Task_id); elementActdef.SetAttribute("Name", actdef.Task_name); nodeActdef = elementActdef as XmlElement; nodeProdef.AppendChild(nodeActdef); } return(doc); }
/// <summary> /// 复制流程方案 /// </summary> /// <param name="prodefId"></param> /// <param name="lstSchemaId"></param> /// <param name="lstBCopy"></param> public static void CopyProdefSchemaToOtherProdef(String prodefId, List <String> lstSchemaId, List <Node> lstBCopy) { XmlDocument doc = new XmlDocument(); doc.Load(MProdefListXmlPath); XmlNode nodeRoot = doc.SelectSingleNode("Element"); XmlNode nodeProdef = doc.SelectSingleNode("//Prodef[@ID='" + prodefId + "']"); if (nodeProdef == null) { throw new Exception("找不到被复制对象的流程配置信息,请检查!"); } //所有选中的方案 List <XmlNode> lstSelectSchemaNode = new List <XmlNode>(); lstSchemaId.ForEach(p => { lstSelectSchemaNode.Add(nodeProdef.SelectSingleNode("ProdefChild[@ID='" + p + "']")); }); XmlNode nodeCopyToProdefXmlNode = null; XmlElement elementCopyToProdefXmlElement = null; XmlElement elementProdefSchema = null; lstBCopy.ForEach(p => { ProdefEntity prodefEntity = (ProdefEntity)p.Tag; PropackageEntity propackageEntity = (PropackageEntity)p.Parent.Tag; String copyToProdefId = prodefEntity.Id; String copyToProdefName = prodefEntity.Name; String copyToPropackageName = propackageEntity.Caption; nodeCopyToProdefXmlNode = doc.SelectSingleNode("//Prodef[@ID='" + copyToProdefId + "']"); if (nodeCopyToProdefXmlNode == null) { nodeCopyToProdefXmlNode = doc.CreateElement("Prodef"); nodeRoot.AppendChild(nodeCopyToProdefXmlNode); } elementCopyToProdefXmlElement = nodeCopyToProdefXmlNode as XmlElement; elementCopyToProdefXmlElement.SetAttribute("ID", copyToProdefId); elementCopyToProdefXmlElement.SetAttribute("Name", prodefEntity.Name); elementCopyToProdefXmlElement.SetAttribute("PackageName", propackageEntity.Caption); lstSelectSchemaNode.ForEach(t => { String newChildProdefId = Guid.NewGuid().ToString(); elementProdefSchema = doc.CreateElement("ProdefChild"); elementProdefSchema.SetAttribute("ID", newChildProdefId); elementProdefSchema.SetAttribute("Name", t.Attributes["Name"].Value + "_copy" + Guid.NewGuid().ToString()); elementCopyToProdefXmlElement.AppendChild(elementProdefSchema); //复制配置文件 String dictoryPath = AppDomain.CurrentDomain.BaseDirectory + @"\XML\"; String filePath = dictoryPath + string.Format("Prodef_{0}_{1}.xml", prodefId, t.Attributes["ID"].Value); String newFilePath = dictoryPath + string.Format("Prodef_{0}_{1}.xml", copyToProdefId, newChildProdefId); File.Copy(filePath, newFilePath, true); ActdefDataEntity actdefDataEntity = ProTree.GetActdefInfo(new string[] { prodefEntity.Key }); List <ActdefEntity> allActdef = actdefDataEntity.ListTaskInfor.ToList <ActdefEntity>(); XmlDocument docProdefDetailXml = new XmlDocument(); docProdefDetailXml.Load(newFilePath); XmlElement nodeDetailProdef = docProdefDetailXml.SelectSingleNode("//Prodef") as XmlElement; nodeDetailProdef.SetAttribute("ID", copyToProdefId); nodeDetailProdef.SetAttribute("Name", copyToProdefName); nodeDetailProdef.SetAttribute("PackageName", copyToPropackageName); allActdef.ForEach(o => { XmlNode nodeDetailActdef = nodeDetailProdef.SelectSingleNode("Actdef[@Name='" + o.Task_name + "']"); if (nodeDetailActdef != null) { XmlElement elementDetailActdef = nodeDetailActdef as XmlElement; elementDetailActdef.SetAttribute("ID", o.Task_id); } }); docProdefDetailXml.Save(newFilePath); }); }); doc.Save(MProdefListXmlPath); }