前几天项目的一个模块,客户需求,Gridcontrol需要实现分页,学习了一下,将写好的代码分享给大家
- 首先在GridControl设置分页方法CustomPaging 导出CustomExport
- 实现分页代码
/// <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. 最终实现样式