Gridcontrol实现分页导出

       前几天项目的一个模块,客户需求,Gridcontrol需要实现分页,学习了一下,将写好的代码分享给大家
  1. 首先在GridControl设置分页方法CustomPaging 导出CustomExport
    这里写图片描述
  2. 实现分页代码
 /// <summary>
        /// 备件信息分页
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void gridControl3_CustomPaging(object sender, PageEventArgs e)
        {
            FindDataSmall(e.PageSize, e.CurPage);
        }
        private void FindDataSmall(int intPageSize = 100, int intCurPage = 1)
        {
            //清空数据集
            dstgi_repair_assembly_list.Clear();
            //参数
            object[] objQuery = { strPkid };
            //调用XML中方法返回数据
            DataSet dstQueryInfo = DataSetHelper.BytesToDataSet(EquipmentManageAPI.EquipmentManageService.ExecuteDataSetExtPaged("TGI_REPAIR_ASSEMBLY_LIST", "EquipmentManager.GetTwoRepairQuery", intPageSize, intCurPage - 1, objQuery));
//将返回数据存入数据集            dstgi_repair_assembly_list.Merge(dstQueryInfo.Tables["TGI_REPAIR_ASSEMBLY_LIST"]);

            //计算总数据量 
            gcSpare.RefreshPager(intPageSize, intCurPage, intAllCount); //更新分页控件显示。
        }
        public void RecordRefreshGridList(string strPkid)
        {
            //联动分页(如果主页有数据则查询子页信息)
            if (strPkid != "")
            {
                object[] objQuery = { strPkid };
                DataSet dstQueryInfo = DataSetHelper.BytesToDataSet(EquipmentManageAPI.EquipmentManageService.ExecuteDataSetExt("TGI_REPAIR_ASSEMBLY_LIST", "EquipmentManager.GetTwoRepairCountQuery", objQuery));
                object objResult = dstQueryInfo.Tables["TGI_REPAIR_ASSEMBLY_LIST"].Rows[0]["c"];
                intRecordAllCount = Convert.ToInt16(objResult);
                //分页取第一页内容
                FindDataSmall(7, 1); //自己实现FillGridListCtrlQuery函数。 
            }
            else
            {//无数据,则清空子页信息
                dstgi_repair_assembly_list.Clear();
            }
        }
 /// <summary>
        /// 临时工单导出
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void gcTemporaryOrder_CustomExport(object sender, ExportEventArgs e)
        {
            //如果参数是全部页则导出全部
            if (e.AllPages)
            {

                object[] objParam = { strFactoryId, strWorkShopId, strAreaPkid, strEquipmentName, strWorkPkid, strEquipmentDataDicPkid, strRepairOrderCode, strCostCenterPkid, strStartTime, strEndTime };

                DataSet dstResult = DataSetHelper.BytesToDataSet(EquipmentManageAPI.EquipmentManageService.ExecuteDataSetExt("TGI_REPAIR_ORDER", "EquipmentManager.GetTemporaryOrderWjn", objParam));

                int bolResult = gcPlanOrder.ExportAllPageEx(dstResult);
                if (bolResult == 0)
                    XtraMsgDialog.ShowInfo("导出成功!");
                else if (bolResult == 2)
                    XtraMsgDialog.ShowInfo("导出失败!");
            }
            else
            {
                int bolResult = gcPlanOrder.ExportCuccentPageEx();
                if (bolResult == 0)
                    XtraMsgDialog.ShowInfo("导出成功!");
                else if (bolResult == 2)
                    XtraMsgDialog.ShowInfo("导出失败!");
            }
        }
        #endregion

< 3. Service层封装

/// <summary>
        ///     根据SQL脚本、实体名从服务器缓存中获取数据集信息
        /// </summary>
        /// <param name="strEntityName">实体名</param>
        /// <param name="strSqlName">SQL脚本名</param>
        /// <param name="paramValues">参数值</param>
        /// <returns>DataSet</returns>
        public byte[] ExecuteDataSetExt(string strEntityName, string strSqlName, object[] paramValues)
        {
            var ds = GetDatabase().ExecuteDataSetExt(strEntityName, strSqlName, paramValues);
            return DataSetHelper.DataSetToBytes(ds);
        }

< 4. XML中Sql语句

 <sqlStruct name="GetStateQuery" description="点检信息查询">
    <commandText>
      <![CDATA[
          select teb.pkid,
                               teb.area_set_up_pkid,
                               teb.equipment_code,
                               teb.equipment_name,
                               teb.factory_pkid,
                               teb.workshop_pkid,
                               tpcj.flag_check_result,
                               tpcj.check_state,
                               tcps.checkpoint_items_content,
                               tcps.checkpoint_items_code,
                               tpcj.check_time
                          from tgi_equipment_bill      teb,
                               tgi_point_check_journal tpcj,
                               tgi_checkpoint_standard tcps
                         where tpcj.equipment_bill_pkid = teb.pkid
                           and tcps.equipment_bill_pkid = teb.pkid
                           and tpcj.check_time > TO_DATE(:p_strStartTime,'yyyy-mm-dd hh24:mi:ss')
                           AND tpcj.check_time < TO_DATE(:p_strEndTime,'yyyy-mm-dd hh24:mi:ss')
                           AND NVL2(:p_strFactoryId,teb.factory_pkid,'%') = NVL(:p_strFactoryId,'%')
                           AND NVL2(:p_strWorkShopId,teb.workshop_pkid,'%') = NVL(:p_strWorkShopId,'%')
                           AND NVL2(:p_strAreaPkid,teb.area_set_up_pkid,'%') = NVL(:p_strAreaPkid,'%')
                           AND teb.equipment_name LIKE  '%' || :p_strEquipmentName || '%'
                           AND teb.equipment_code LIKE  '%' || :p_strEquipmentCode || '%'
                           AND tcps.checkpoint_items_code LIKE '%' || :p_strCheckPointCode || '%'
      ]]>
    </commandText>
    <commandType>Text</commandType>
    <params>
      <param name=":p_strFactoryId" />
      <param name=":p_strStartTime" />
      <param name=":p_strEndTime" />
      <param name=":p_strWorkShopId" />
      <param name=":p_strAreaPkid" />
      <param name=":p_strEquipmentName" />
      <param name=":p_strEquipmentCode" />
      <param name=":p_strCheckPointCode" />
    </params>
  </sqlStruct>
 <sqlStruct name="GetStateCountQuery" description="点检信息查询数量">
    <commandText>
      <![CDATA[
          SELECT      count(count(teb.pkid)) c
         from tgi_equipment_bill      teb,
                               tgi_point_check_journal tpcj,
                               tgi_checkpoint_standard tcps
                         where tpcj.equipment_bill_pkid = teb.pkid
                           and tcps.equipment_bill_pkid = teb.pkid
                           and tpcj.check_time > TO_DATE(:p_strStartTime,'yyyy-mm-dd hh24:mi:ss')
                           AND tpcj.check_time < TO_DATE(:p_strEndTime,'yyyy-mm-dd hh24:mi:ss')
                           AND NVL2(:p_strFactoryId,teb.factory_pkid,'%') = NVL(:p_strFactoryId,'%')
                           AND NVL2(:p_strWorkShopId,teb.workshop_pkid,'%') = NVL(:p_strWorkShopId,'%')
                           AND NVL2(:p_strAreaPkid,teb.area_set_up_pkid,'%') = NVL(:p_strAreaPkid,'%')
                           AND teb.equipment_name LIKE  '%' || :p_strEquipmentName || '%'
                           AND teb.equipment_code LIKE  '%' || :p_strEquipmentCode || '%'
                           AND tcps.checkpoint_items_code LIKE '%' || :p_strCheckPointCode || '%'
                           GROUP BY    teb.pkid
      ]]>
    </commandText>
    <commandType>Text</commandType>
    <params>
      <param name=":p_strFactoryId" />
      <param name=":p_strStartTime" />
      <param name=":p_strEndTime" />
      <param name=":p_strWorkShopId" />
      <param name=":p_strAreaPkid" />
      <param name=":p_strEquipmentName" />
      <param name=":p_strEquipmentCode" />
      <param name=":p_strCheckPointCode" />
    </params>
  </sqlStruct>

<5. 最终实现样式
这里写图片描述

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值