Infopath重复表分页(原创)

2024-02-01 04:38
文章标签 重复 分页 原创 infopath

本文主要是介绍Infopath重复表分页(原创),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

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

namespace 模板1
{
    public partial class FormCode
    {
        // 启用浏览器功能的表单不支持成员变量。
        // 请使用代码从 FormState 词典
        // 写入和读取这些值,如下所示:
        //
        //private int RowCount
        //{
        //    get
        //    {
        //        return Convert.ToInt16(Rows);
        //    }
        //    set
        //    {
        //        Rows = value;
        //    }
        //}

        // 注意: 以下是 Microsoft Office InfoPath 所需的过程。
        // 可以使用 Microsoft Office InfoPath 对其进行修改。
        public void InternalStartup()
        {
            ((ButtonEvent)EventManager.ControlEvents["CTRL5_5"]).Clicked += new ClickedEventHandler(CTRL5_5_Clicked);
            ((ButtonEvent)EventManager.ControlEvents["CTRL6_5"]).Clicked += new ClickedEventHandler(CTRL6_5_Clicked);
            EventManager.FormEvents.Loading += new LoadingEventHandler(FormEvents_Loading);
            ((ButtonEvent)EventManager.ControlEvents["CTRL10_5"]).Clicked += new ClickedEventHandler(CTRL10_5_Clicked);
            ((ButtonEvent)EventManager.ControlEvents["CTRL11_5"]).Clicked += new ClickedEventHandler(CTRL11_5_Clicked);
        }

        public void FormEvents_Loading(object sender, LoadingEventArgs e)
        {
            TempTable = GenDataTable(out Rows);
            navRows = this.MainDataSource.CreateNavigator().SelectSingleNode("/my:myFields/my:rows", NamespaceManager);
            navPages = this.MainDataSource.CreateNavigator().SelectSingleNode("/my:myFields/my:pages", NamespaceManager);
            navCurrentPage = this.MainDataSource.CreateNavigator().SelectSingleNode("/my:myFields/my:currentPage", NamespaceManager);
            PageIndex = 1;
            Page();

        }

        //重复表的父节点
        string StrExpression = "/my:myFields/my:group1";
        //重复表当前节点
        string Node = "my:group2";
        //需要导入的域
        string[] Field ={ "my:field1", "my:field2", "my:field3" };
        //当前页
        int PageIndex = 1;
        //每页10条
        int RowsPrePage = 10;
        //页数
        int Pages = 0;
        //记录数
        int Rows=0;
        //临时表
        int LastRows = 0;
        int LoopTimes = 0;

        DataTable TempTable = null;
        XPathNavigator navRows = null;
        XPathNavigator navPages = null;
        XPathNavigator navCurrentPage = null;

        /// <summary>
        /// 执行分页
        /// </summary>
        public void Page()
        {
            XPathNavigator nav = this.MainDataSource.CreateNavigator().SelectSingleNode(StrExpression, NamespaceManager);
            DataTable2Rpt(StrExpression, Node, TempTable, Field, PageIndex);
            navRows.SetValue(Rows.ToString());
            navCurrentPage.SetValue(PageIndex.ToString());
            navPages.SetValue(Pages.ToString());
        }


        public void CTRL10_5_Clicked(object sender, ClickedEventArgs e)
        {
            PageIndex = 1;
            Page();

        }

        public void CTRL11_5_Clicked(object sender, ClickedEventArgs e)
        {
            if (PageIndex < Pages)
            {
                PageIndex = Pages;
                Page();
            }
        }

        public void CTRL5_5_Clicked(object sender, ClickedEventArgs e)
        {  
            if (PageIndex <=1)
            {
                PageIndex = 1;
                return;
            }
            else
            {
                PageIndex--;
                Page();
            }

        }

        public void CTRL6_5_Clicked(object sender, ClickedEventArgs e)
        {
            if (PageIndex >= Pages)
            {
                PageIndex = Pages;
                return;
            }
            else
            {
                PageIndex++;
                Page();
            }

        }

        /// <summary>
        /// 生成演示数据
        /// </summary>
        /// <param name="rows">输出参数rows</param>
        /// <returns>DataTable</returns>
        public DataTable GenDataTable(out int rows)
        {
            DataTable dt = new DataTable();

            for (int i = 0; i < 3; i++)
            {
                dt.Columns.Add(i.GetHashCode().ToString());
            }

            for (int i = 1; i < 300; i++)
            {
               DataRow dr = dt.NewRow();
               for (int j = 0; j < 3; j++)
                {
                    dr[j] = i.ToString() +"--"+ j.ToString();
                }
                dt.Rows.Add(dr);
            }

            rows = dt.Rows.Count;
            return dt;
        }


        public XPathNavigator GetLastChild(XPathNavigator list)
        {
            XPathNodeIterator iter = list.SelectChildren(XPathNodeType.Element);
            XPathNavigator nav = null;
            while (iter.MoveNext())
            {
                nav = iter.Current;
            }
            return nav;
        }

        public void DelFirstChild(XPathNavigator list)
        {
            XPathNodeIterator iter = list.SelectChildren(XPathNodeType.Element);
            while (iter.MoveNext())
            {
                if (iter.CurrentPosition == 1)
                {
                    iter.Current.DeleteSelf();
                }
            }
        }


        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 int GetCount(string body, string node)
        {
            XPathNavigator parent = this.MainDataSource.CreateNavigator().SelectSingleNode(body, this.NamespaceManager);

            if (parent != null)
            {
                XPathNodeIterator rowitor = parent.Select(node, this.NamespaceManager);
                return rowitor.Count;
            }
            else
            {
                return 0;
            }
       
        }

        public void DelRange(string body, string node,int count)
        {
            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 + "[" + count + "]", this.NamespaceManager);
                    xn.MoveTo(n1);

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

        }


        /// <summary>
        /// 将DataTable导入进重复表
        /// </summary>
        /// <param name="strExpression">重复表的父节点</param>
        /// <param name="dt">传入的DataTable</param>
        /// <param name="fields">域名的数组集合</param>
        public void DataTable2Rpt(string strExpression, string node, DataTable dt, string[] fields, int index)
        {
            if (Rows % RowsPrePage == 0)
            {
                Pages = Rows / RowsPrePage;
            }
            else
            {
                Pages = Convert.ToInt32(Rows / RowsPrePage + 1);
            }
           
            if (index > Pages)
            { return; }
            XPathNavigator Nav = this.MainDataSource.CreateNavigator().SelectSingleNode(strExpression, NamespaceManager);
            XPathNodeIterator iter = Nav.SelectChildren(XPathNodeType.Element);
            XPathNodeIterator newNodeIter = null;
            XPathNavigator newNode = null;

            //复制一条
            while (iter.MoveNext())
            {
                if (iter.CurrentPosition == 1)
                {
                    newNode = iter.Current.Clone();
                }
            }
            int thisrows = 0;
            int beginRow = 0;

            if (index != Pages)
            {  
                thisrows=RowsPrePage * index;
                beginRow=thisrows - RowsPrePage ;
            }
            else
            {
                beginRow = RowsPrePage * (index-1);
                thisrows = Rows;
            }
           
            LastRows=thisrows-beginRow;

            //thisrows = RowsPrePage * index;
            if (thisrows <= dt.Rows.Count && thisrows > 0)
            {
                for (int i = beginRow; i < thisrows; i++)
                {
                    Nav.AppendChild(newNode);
                    newNode = GetLastChild(Nav);
                    newNodeIter = newNode.SelectChildren(XPathNodeType.Element);

                    for (int j = 0; j < dt.Columns.Count; j++)
                    {
                        //导入将对应位置的值
                        newNodeIter.Current.SelectSingleNode(fields[j], NamespaceManager).SetValue(dt.Rows[i][j].ToString());
                    }
                }
            }
            //删除第一条无效数据
            if (LoopTimes == 0)
            {
                DelFirstChild(Nav);
                LoopTimes++;
            }
            else //删除之前的数据
            {
                LoopTimes++;
                DelRange(StrExpression, node, LastRows);
            }
          
        }

 

       

      
    }
}

这篇关于Infopath重复表分页(原创)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/666108

相关文章

一文教你使用Python实现本地分页

《一文教你使用Python实现本地分页》这篇文章主要为大家详细介绍了Python如何实现本地分页的算法,主要针对二级数据结构,文中的示例代码简洁易懂,有需要的小伙伴可以了解下... 在项目开发的过程中,遇到分页的第一页就展示大量的数据,导致前端列表加载展示的速度慢,所以需要在本地加入分页处理,把所有数据先放

Redis存储的列表分页和检索的实现方法

《Redis存储的列表分页和检索的实现方法》在Redis中,列表(List)是一种有序的数据结构,通常用于存储一系列元素,由于列表是有序的,可以通过索引来访问元素,因此可以很方便地实现分页和检索功能,... 目录一、Redis 列表的基本操作二、分页实现三、检索实现3.1 方法 1:客户端过滤3.2 方法

Redis 多规则限流和防重复提交方案实现小结

《Redis多规则限流和防重复提交方案实现小结》本文主要介绍了Redis多规则限流和防重复提交方案实现小结,包括使用String结构和Zset结构来记录用户IP的访问次数,具有一定的参考价值,感兴趣... 目录一:使用 String 结构记录固定时间段内某用户 IP 访问某接口的次数二:使用 Zset 进行

Spring Boot 整合 ShedLock 处理定时任务重复执行的问题小结

《SpringBoot整合ShedLock处理定时任务重复执行的问题小结》ShedLock是解决分布式系统中定时任务重复执行问题的Java库,通过在数据库中加锁,确保只有一个节点在指定时间执行... 目录前言什么是 ShedLock?ShedLock 的工作原理:定时任务重复执行China编程的问题使用 Shed

Oracle数据库使用 listagg去重删除重复数据的方法汇总

《Oracle数据库使用listagg去重删除重复数据的方法汇总》文章介绍了在Oracle数据库中使用LISTAGG和XMLAGG函数进行字符串聚合并去重的方法,包括去重聚合、使用XML解析和CLO... 目录案例表第一种:使用wm_concat() + distinct去重聚合第二种:使用listagg,

MySQL中删除重复数据SQL的三种写法

《MySQL中删除重复数据SQL的三种写法》:本文主要介绍MySQL中删除重复数据SQL的三种写法,文中通过代码示例讲解的非常详细,对大家的学习或工作有一定的帮助,需要的朋友可以参考下... 目录方法一:使用 left join + 子查询删除重复数据(推荐)方法二:创建临时表(需分多步执行,逻辑清晰,但会

poj2406(连续重复子串)

题意:判断串s是不是str^n,求str的最大长度。 解题思路:kmp可解,后缀数组的倍增算法超时。next[i]表示在第i位匹配失败后,自动跳转到next[i],所以1到next[n]这个串 等于 n-next[n]+1到n这个串。 代码如下; #include<iostream>#include<algorithm>#include<stdio.h>#include<math.

poj3261(可重复k次的最长子串)

题意:可重复k次的最长子串 解题思路:求所有区间[x,x+k-1]中的最小值的最大值。求sa时间复杂度Nlog(N),求最值时间复杂度N*N,但实际复杂度很低。题目数据也比较水,不然估计过不了。 代码入下: #include<iostream>#include<algorithm>#include<stdio.h>#include<math.h>#include<cstring

pip-tools:打造可重复、可控的 Python 开发环境,解决依赖关系,让代码更稳定

在 Python 开发中,管理依赖关系是一项繁琐且容易出错的任务。手动更新依赖版本、处理冲突、确保一致性等等,都可能让开发者感到头疼。而 pip-tools 为开发者提供了一套稳定可靠的解决方案。 什么是 pip-tools? pip-tools 是一组命令行工具,旨在简化 Python 依赖关系的管理,确保项目环境的稳定性和可重复性。它主要包含两个核心工具:pip-compile 和 pip

oracle分页和mysql分页

mysql 分页 --查前5 数据select * from table_name limit 0,5 select * from table_name limit 5 --limit关键字的用法:LIMIT [offset,] rows--offset指定要返回的第一行的偏移量,rows第二个指定返回行的最大数目。初始行的偏移量是0(不是1)。   oracle 分页 --查前1-9