zoukankan      html  css  js  c++  java
  • 重复表的复制操作

    using Microsoft.Office.InfoPath;
    using System;
    using System.Xml;
    using System.Xml.XPath;

    namespace copytable
    {
        public partial class FormCode
        {
            // 注意: 以下是 Microsoft Office InfoPath 所需的过程。
            // 可以使用 Microsoft Office InfoPath 对其进行修改。
            public void InternalStartup()
            {
                EventManager.XmlEvents["/my:myFields/my:group1/my:group2"].Changed += new XmlChangedEventHandler(group2_Changed);
            }

            public void group2_Changed(object sender, XmlEventArgs e)
            {
                DelRange("/my:myFields/my:group3", "my:group4");

                string strExpression = @"/my:myFields/my:group1/my:group2[my:check1='Y']";
                string toNav = "/my:myFields/my:group3/my:group4[last()]";
                string[] fromNodes ={ "my:field2", "my:field3" };
                string[] toNodes ={ "my:field4", "my:field5" };
                copyTable(strExpression, toNav, fromNodes, toNodes);

                AddBlank("/my:myFields/my:group3/my:group4[last()]");

            }

            public void copyTable(string strExpression, string toNav, string[] fromNodes, string[] toNodes)
            {
                XPathNavigator xn = MainDataSource.CreateNavigator();
                XPathNodeIterator itor = xn.Select(strExpression, NamespaceManager);
                XPathNavigator to = this.MainDataSource.CreateNavigator().SelectSingleNode(toNav, this.NamespaceManager);
                XPathNavigator clone = null;

                while (itor.MoveNext())
                {
                    {
                        clone = to.Clone();
                        for (int i = 0; i < fromNodes.Length;i++ )
                        {
                            to.SelectSingleNode(toNodes[i], NamespaceManager).SetValue(itor.Current.SelectSingleNode(fromNodes[i], NamespaceManager).Value);
                        }
                        to.InsertBefore(clone);
                    }

                }
            }

            public void DelRange(string body, string node)
            {
                try
                {
                    XPathNavigator parent = this.MainDataSource.CreateNavigator().SelectSingleNode(body, this.NamespaceManager);

                    if (parent != null)
                    {

                        XPathNodeIterator rowitor = parent.Select(node, this.NamespaceManager);
                        XPathNavigator xn = this.MainDataSource.CreateNavigator();

                        XPathNavigator n1 = xn.SelectSingleNode(body + "/" + node + "[1]", this.NamespaceManager);
                        XPathNavigator n2 = n1.SelectSingleNode(body + "/" + node + "[" + (rowitor.Count - 1) + "]", this.NamespaceManager);
                        xn.MoveTo(n1);

                        if (rowitor.Count > 1)
                        {
                            xn.DeleteRange(n2);
                        }
                    }
                }
                catch (Exception ex)
                {
                    throw ex;
                }

            }

            public void DeleteAll(string body,string node)
            {

                XPathNavigator parent = this.MainDataSource.CreateNavigator().SelectSingleNode(body, this.NamespaceManager);

                if (parent != null)
                {

                    XPathNodeIterator rowitor = parent.Select(node, this.NamespaceManager);
                    if (rowitor.Count > 0)
                    {
                        for (int i = 0; i < Convert.ToInt32(rowitor.Count)-1; i++)
                        {
                            rowitor.Current.DeleteSelf();
                            rowitor.MoveNext();

                        }
                    }
                }
     

            }

            public void AddBlank(string node)
            {
                try
                {
                    XPathNavigator group = this.MainDataSource.CreateNavigator().SelectSingleNode(node, this.NamespaceManager);
                    group.SelectSingleNode("my:field4", NamespaceManager).SetValue("");
                    group.SelectSingleNode("my:field5", NamespaceManager).SetValue("");
                    group.SelectSingleNode("my:field6", NamespaceManager).SetValue("");

                }
                catch (Exception ex)
                {
                    throw ex;
                }

            }
        }
    }

    关于作者: 王昕(QQ:475660) 在广州工作生活30余年。十多年开发经验,在Java、即时通讯、NoSQL、BPM、大数据等领域较有经验。
    目前维护的开源产品:https://gitee.com/475660
  • 相关阅读:
    {purple8}
    {purple7}
    {暴力}
    uva1103(dfs)
    {purple5练习题}
    c++复习题
    关于继承
    lrj紫书第五章
    20个Linux系统监视工具
    linux上配置jdk+Apache
  • 原文地址:https://www.cnblogs.com/starcrm/p/1403159.html
Copyright © 2011-2022 走看看