示例#1
0
 private void treeProdef_NodeDoubleClick(object sender, TreeNodeMouseEventArgs e)
 {
     try
     {
         Node nodeSelect = treeProdef.SelectedNode;
         if (nodeSelect != null)
         {
             if (nodeSelect.Name.IndexOf("PROPACKAGE_") > -1)
             {
                 if (!nodeSelect.HasChildNodes)
                 {
                     PropackageEntity propackageEntity
                         = (PropackageEntity)nodeSelect.Tag;
                     ProTree.CreateProDef(nodeSelect, propackageEntity.Id, true);
                 }
             }
         }
     }
     catch (Exception er)
     {
         MessageBox.Show(er.Message, "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);
     }
 }
        /// <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);
        }