'注:btnFirstPage,btnPrevPage,btnNextPage,btnLastPage对应首页,前一页,下一页,尾页按钮
g_strFilterSQLWhere = "" '-------筛选SQL条件
g_strShowFieldNames = "DosID,DosCode,DosBagCode,Name,Gender" '-----------要显示的字段
g_nPageSize = 20 '----------每页数据显示记录数
g_nCurPage = 1 '----------当前页号
g_nTotalPageCount = 1 '--------总页数,动态计算
'窗体装载事件
Sub DBEngine_EventLoad(strInitData, strInitType)
'-----失效页面跳转按钮
btnFirstPage.Enabled = FALSE
btnPrevPage.Enabled = FALSE
btnNextPage.Enabled = FALSE
btnLastPage.Enabled = FALSE
End Sub
'-------在网格里显示分页数据
Sub ShowQueryData(strTableName, strFieldNames, strSQLWhere, strOrder, nPage, nPageSize)
'-----SqlQuery分页方案,优点:速度快,缺点:不能显示自定义的表样式
'strSQL = "Select "+strFieldNames+" From "+strTableName
'if strSQLWhere <> "" then
' strSQL = strSQL+" Where "+strSQLWhere
'end if
'if strOrder <> "" then
' strSQL = strSQL+" "+strOrder
'end if
'strInput = "<Input><SQL>"+DBEngine.TextToDoc(strSQL)+"</SQL><Page>"+CStr(nPage)+"</Page><PageSize>"+CStr(nPageSize)+"</PageSize></Input>"
'DBEngine.BeginWaitCursor '----显示等待
'strRet = DBEngine.WebFunction("SqlQuery", strInput, "")
'---GetTableDataXML分页方案,优点:能显示自定义的表样式,缺点:速度慢
strInput = "<Input><TableName>"+strTableName+"</TableName><FieldNames>"+strFieldNames+"</FieldNames><SQLWhere>"+DBEngine.TextToDoc(strSQLWhere)+"</SQLWhere>"
strInput = strInput+"<Order>"+strOrder+"</Order><Page>"+CStr(nPage)+"</Page><PageSize>"+CStr(nPageSize)+"</PageSize></Input>"
DBEngine.BeginWaitCursor '----显示等待
strRet = DBEngine.WebFunction("GetTableDataXML", strInput, "")
strError = DBEngine.GetNodeText(strRet, "Error")
if strError <> "" then
DBEngine.MsgBox strError
DBEngine.EndWaitCursor
Exit Sub
End if
MainGrid.SetTableXML(strRet)
MainGrid.AutoSizeColumns
'---------返回符合条件的总记录数
strInput = "<Input><TableName>"+strTableName+"</TableName><SQLWhere>"+DBEngine.TextToDoc(strSQLWhere)+"</SQLWhere></Input>"
strRecordCount = DBEngine.WebFunction("GetRecordCount", strInput, "")
lblCount.Caption = strRecordCount
g_nTotalPageCount = Clng(strRecordCount)/nPageSize
if Clng(strRecordCount) Mod nPageSize <> 0 then
g_nTotalPageCount = CInt(g_nTotalPageCount)+1
end if
'lbTotalPage.Caption = "共"+CStr(g_nTotalPageCount)+"页 当前页:"+CStr(nPage)
DBEngine.EndWaitCursor
End Sub
'注释:首页
Sub btnFirstPage_Click()
g_nCurPage = 1
Call ShowQueryData("t_b_rs_DosBasicInfo", g_strShowFieldNames, g_strFilterSQLWhere, "Order by DosCode", g_nCurPage, g_nPageSize)
btnFirstPage.Enabled = FALSE
btnPrevPage.Enabled = FALSE
btnNextPage.Enabled = TRUE
btnLastPage.Enabled = TRUE
End Sub
'注释:前一页
Sub btnPrevPage_Click()
g_nCurPage = g_nCurPage-1
if g_nCurPage < 1 then
g_nCurPage = 1
end if
Call ShowQueryData("t_b_rs_DosBasicInfo", g_strShowFieldNames, g_strFilterSQLWhere, "Order by DosCode", g_nCurPage, g_nPageSize)
if g_nCurPage = 1 then
btnFirstPage.Enabled = FALSE
btnPrevPage.Enabled = FALSE
else
btnFirstPage.Enabled = TRUE
btnPrevPage.Enabled = TRUE
end if
btnNextPage.Enabled = TRUE
btnLastPage.Enabled = TRUE
End Sub
'注释:下一页
Sub btnNextPage_Click()
g_nCurPage = g_nCurPage+1
if g_nCurPage > g_nTotalPageCount then
g_nCurPage = g_nTotalPageCount
end if
Call ShowQueryData("t_b_rs_DosBasicInfo", g_strShowFieldNames, g_strFilterSQLWhere, "Order by DosCode", g_nCurPage, g_nPageSize)
btnFirstPage.Enabled = TRUE
btnPrevPage.Enabled = TRUE
if g_nCurPage = g_nTotalPageCount then
btnNextPage.Enabled = FALSE
btnLastPage.Enabled = FALSE
else
btnNextPage.Enabled = TRUE
btnLastPage.Enabled = TRUE
end if
End Sub
'注释:尾页
Sub btnLastPage_Click()
g_nCurPage = g_nTotalPageCount
Call ShowQueryData("t_b_rs_DosBasicInfo", g_strShowFieldNames, g_strFilterSQLWhere, "Order by DosCode", g_nCurPage, g_nPageSize)
btnFirstPage.Enabled = TRUE
btnPrevPage.Enabled = TRUE
btnNextPage.Enabled = FALSE
btnLastPage.Enabled = FALSE
End Sub