• 重复表的复制操作


    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
  • 相关阅读:
    Linux下使用cut切割有规则的列文本
    注解相关
    修改Feign数据解析,由jackson改为fastjson,同时解决fastjson中Content-Type问题
    Spring Data JPA整合REST客户端Feign时: 分页查询的反序列化报错的问题
    Aliyun STS Java SDK示例
    GIT : IDEA切换到某个tag
    [LeetCode] 351. Android Unlock Patterns 安卓解锁模式
    QSpinBox 和 QSlider 联合使用方法
    Qt 控件随窗口缩放
    [LeetCode] 350. Intersection of Two Arrays II 两个数组相交之二
  • 原文地址:https://www.cnblogs.com/starcrm/p/1403159.html
Copyright © 2020-2023  润新知