<%
'
'    Filename: fin_btwtabelgrid.asp
'    Generated with CodeCharge 2.0.5
'    ASP 2.0 & Templates.ccp build 11/30/2001
'

'-------------------------------
' 
' fin_btwtabelgrid CustomIncludes Event begin
%>
<!-- #INCLUDE FILE="Common.asp" -->
<%
' fin_btwtabelgrid CustomIncludes Event end


'===============================
' Save Page and File Name available into variables
'-------------------------------
sFileName = "fin_btwtabelgrid.asp"
sTemplateFileName = "fin_btwtabelgrid.html"
'===============================


'===============================
' fin_btwtabelgrid PageSecurity begin
' fin_btwtabelgrid PageSecurity end
'===============================

'===============================
' fin_btwtabelgrid Open Event begin
' fin_btwtabelgrid Open Event end
'===============================

'===============================
' fin_btwtabelgrid OpenAnyPage Event begin
' fin_btwtabelgrid OpenAnyPage Event end
'===============================

'===============================
'Save the name of the form and type of action into the variables
'-------------------------------
sAction = GetParam("FormAction")
sForm = GetParam("FormName")
'===============================

' fin_btwtabelgrid Show begin

'===============================
' Display page
'-------------------------------
' Load HTML template for this page
'-------------------------------
LoadTemplate sAppPath & sTemplateFileName, "main"
'-------------------------------
' Load HTML template of Header and Footer
'-------------------------------
'-------------------------------
SetVar "FileName", sFileName


'-------------------------------
' Step through each form
'-------------------------------
BTWTabelGrid_Show
'-------------------------------
' Process page templates
'-------------------------------
Parse "main", False
'-------------------------------
' Output the page to the browser
'-------------------------------
Response.write PrintVar("main")

' fin_btwtabelgrid Show end

'-------------------------------
' Destroy all object variables
'-------------------------------

' fin_btwtabelgrid Close Event begin
' fin_btwtabelgrid Close Event end

cn.Close
Set cn = Nothing
UnloadTemplate
'===============================

'===============================
' Display Grid Form
'-------------------------------
Sub BTWTabelGrid_Show()
'-------------------------------
' Initialize variables  
'-------------------------------
  Dim rs
  Dim sWhere : sWhere = ""
  Dim sOrder : sOrder = ""
  Dim sSQL : sSQL = ""
  Dim sFormTitle: sFormTitle = "BTW Tabellen"
  Dim HasParam : HasParam = false
  Dim iSort : iSort = ""
  Dim iSorted : iSorted = ""
  Dim sDirection : sDirection = ""
  Dim sSortParams : sSortParams = ""
  Dim iRecordsPerPage : iRecordsPerPage = 25
  Dim iCounter : iCounter = 0
  Dim iPage : iPage = 0
  Dim bEof : bEof = False
  Dim iTmpI : iTmpI = 0
  Dim iTmpJ : iTmpJ = 0
  Dim sCountSQL : sCountSQL = ""
  Dim sActionFileName : sActionFileName = "fin_btwtabelrecord.asp"

  SetVar "TransitParams", ""
  SetVar "FormParams", ""


  sWhere = " WHERE FIN_BTWTABEL_VERWIJDER IS NULL"
  
'-------------------------------
' Build ORDER BY statement
'-------------------------------
  sOrder = " order by F.FIN_BTWTABEL_OMSCHRIJVING Asc"
  iSort = GetParam("FormBTWTabelGrid_Sorting")
  iSorted = GetParam("FormBTWTabelGrid_Sorted")
  sDirection = ""
  if IsEmpty(iSort) then
    SetVar "Form_Sorting", ""
  else
    if iSort = iSorted then 
      SetVar "Form_Sorting", ""
      sDirection = " DESC"
      sSortParams = "FormBTWTabelGrid_Sorting=" & iSort & "&FormBTWTabelGrid_Sorted=" & iSort & "&"
    else
      SetVar "Form_Sorting", iSort
      sDirection = " ASC"
      sSortParams = "FormBTWTabelGrid_Sorting=" & iSort & "&FormBTWTabelGrid_Sorted=" & "&"
    end if
    if iSort = 1 then sOrder = " order by F.FIN_BTWTABEL_KEY" & sDirection
    if iSort = 2 then sOrder = " order by F.FIN_BTWTABEL_OMSCHRIJVING" & sDirection
    if iSort = 3 then sOrder = " order by F.FIN_BTWTABEL_DEFAULT" & sDirection
  end if

'-------------------------------
' Build base SQL statement
'-------------------------------
  sSQL = "select F.FIN_BTWTABEL_DEFAULT as F_FIN_BTWTABEL_DEFAULT, " & _
    "F.FIN_BTWTABEL_KEY as F_FIN_BTWTABEL_KEY, " & _
    "F.FIN_BTWTABEL_OMSCHRIJVING as F_FIN_BTWTABEL_OMSCHRIJVING " & _
    " from FIN_BTWTABEL F "
'-------------------------------

'-------------------------------
' BTWTabelGrid Open Event begin
' BTWTabelGrid Open Event end
'-------------------------------

'-------------------------------
' Assemble full SQL statement
'-------------------------------
  sSQL = sSQL & sWhere & sOrder
  if sCountSQL = "" then
    iTmpI = instr(lcase(sSQL), "select")
    iTmpJ = instr(lcase(sSQL), "from") - 1
    sCountSQL = replace(sSQL, mid(sSQL, iTmpI + 6, iTmpJ - 6), " count(*) ")
    iTmpI = instr(lcase(sCountSQl), "order by")
    if iTmpI > 1 then sCountSQL = left(sCountSQL, iTmpI - 1)
  end if
'-------------------------------

SetVar "FormTitle", sFormTitle

'-------------------------------
' Process the link to the record page
'-------------------------------
  SetVar "FormAction", sActionFileName
'-------------------------------

'-------------------------------
' Process the parameters for sorting
'-------------------------------
  SetVar "SortParams", sSortParams
'-------------------------------

'-------------------------------
' Open the recordset
'-------------------------------
  openrs rs, sSQL
'-------------------------------

'-------------------------------
' Process empty recordset
'-------------------------------
  if rs.eof then
    set rs = nothing
    SetVar "DListBTWTabelGrid", ""
    Parse "BTWTabelGridNoRecords", False
    SetVar "BTWTabelGridNavigator", ""
    Parse "FormBTWTabelGrid", False
    exit sub
  end if
'-------------------------------

'-------------------------------
' Prepare the lists of values
'-------------------------------

  aFIN_BTWTABEL_DEFAULT = Split(""&FCLTLCL("0;;1;Ja")&"", ";")
'-------------------------------
'-------------------------------
' Initialize page counter and records per page
'-------------------------------
  iRecordsPerPage = 25
  iCounter = 0
'-------------------------------

'-------------------------------
' Process page scroller
'-------------------------------
  iPage = GetParam("FormBTWTabelGrid_Page")
  openrs rsCount, sCountSQL
  dResult = CLng(rsCount.fields(0).value) / iRecordsPerPage
  iPageCount = int(dResult)
  if iPageCount < dResult then iPageCount = iPageCount + 1
  SetVar "BTWTabelGridPageCount", iPageCount
  set rsCount = nothing
  if IsEmpty(iPage) then
    iPage = 1
  else
    if iPage = "last" then iPage = iPageCount
  end if
  while not rs.eof and iCounter < (iPage-1)*iRecordsPerPage
    rs.movenext
    iCounter = iCounter + 1
  wend
  iCounter = 0
'-------------------------------

'-------------------------------
' Display grid based on recordset
'-------------------------------
  while not rs.EOF  and iCounter < iRecordsPerPage
'-------------------------------
' Create field variables based on database fields
'-------------------------------
    fldFIN_BTWTABEL_DEFAULT = GetValue(rs, "F_FIN_BTWTABEL_DEFAULT")
    fldFIN_BTWTABEL_KEY_URLLink = "fin_btwtabelwaarderecord.asp"
    fldFIN_BTWTABEL_KEY = GetValue(rs, "F_FIN_BTWTABEL_KEY")
    fldFIN_BTWTABEL_OMSCHRIJVING_URLLink = "fin_btwtabelrecord.asp"
    fldFIN_BTWTABEL_OMSCHRIJVING_FIN_BTWTABEL_KEY = GetValue(rs, "F_FIN_BTWTABEL_KEY")
    fldFIN_BTWTABEL_OMSCHRIJVING = GetValue(rs, "F_FIN_BTWTABEL_OMSCHRIJVING")
'-------------------------------
' BTWTabelGrid Show begin
'-------------------------------

'-------------------------------
' BTWTabelGrid Show Event begin
' BTWTabelGrid Show Event end
'-------------------------------

'-------------------------------
' Replace Template fields with database values
'-------------------------------
    
      SetVar "FIN_BTWTABEL_KEY", ToHTML(fldFIN_BTWTABEL_KEY)
      SetVar "FIN_BTWTABEL_KEY_URLLink", fldFIN_BTWTABEL_KEY_URLLink
      SetVar "FIN_BTWTABEL_OMSCHRIJVING", ToHTML(fldFIN_BTWTABEL_OMSCHRIJVING)
      SetVar "FIN_BTWTABEL_OMSCHRIJVING_URLLink", fldFIN_BTWTABEL_OMSCHRIJVING_URLLink
      SetVar "PrmFIN_BTWTABEL_OMSCHRIJVING_FIN_BTWTABEL_KEY", ToURL(fldFIN_BTWTABEL_OMSCHRIJVING_FIN_BTWTABEL_KEY)
      fldFIN_BTWTABEL_DEFAULT = getValFromLOV(fldFIN_BTWTABEL_DEFAULT, aFIN_BTWTABEL_DEFAULT)
      SetVar "FIN_BTWTABEL_DEFAULT", ToHTML(fldFIN_BTWTABEL_DEFAULT)
    Parse "DListBTWTabelGrid", True

'-------------------------------
' BTWTabelGrid Show end
'-------------------------------

'-------------------------------
' Move to the next record and increase record counter
'-------------------------------
    rs.MoveNext
    iCounter = iCounter + 1
  wend
'-------------------------------


'-------------------------------
' BTWTabelGrid Navigation begin
'-------------------------------
  bEof = rs.eof
  if rs.eof and iPage = 1 then
	SetVar "BTWTabelGridNavigator", ""
  else
    iCounter = 1
    iHasPages = iPage
    iDisplayPages = 0
    iNumberOfPages = 10
    iHasPages = iPageCount
    if (iHasPages - iPage) < int(iNumberOfPages/2) then
      iStartPage = iHasPages - iNumberOfPages
    else
      iStartPage = iPage - iNumberOfPages + int(iNumberOfPages/2)
    end if
    if iStartPage < 0 then iStartPage = 0
    for iPageCount = iStartPage + 1 to iPage - 1
      SetVar "NavigatorPageNumber", iPageCount
      SetVar "NavigatorPageNumberView", iPageCount
      Parse "BTWTabelGridNavigatorPages", true
      iDisplayPages = iDisplayPages + 1
    next
    SetVar "NavigatorPageSwitch", "_"
    SetVar "NavigatorPageNumber", iPage
    SetVar "NavigatorPageNumberView", iPage
    Parse "BTWTabelGridNavigatorPages", true
    iDisplayPages = iDisplayPages + 1
    SetVar "NavigatorPageSwitch", ""
    iPageCount = iPage + 1
    while iDisplayPages < iNumberOfPages and iStartPage + iDisplayPages < iHasPages
      SetVar "NavigatorPageNumber", iPageCount
      SetVar "NavigatorPageNumberView", iPageCount
      Parse "BTWTabelGridNavigatorPages", true
      iDisplayPages = iDisplayPages + 1
      iPageCount = iPageCount + 1
    wend
    if bEof then
      SetVar "BTWTabelGridNavigatorLastPage", "_"
    else
      SetVar "NextPage", (iPage + 1)
    end if
    if iPage = 1 then
      SetVar "BTWTabelGridNavigatorFirstPage", "_"
    else
      SetVar "PrevPage", (iPage - 1)
    end if
    SetVar "BTWTabelGridCurrentPage", iPage
    Parse "BTWTabelGridNavigator", False
  end if
'-------------------------------
' BTWTabelGrid Navigation end
'-------------------------------

'-------------------------------
' Finish form processing
'-------------------------------
  set rs = nothing
  SetVar "BTWTabelGridNoRecords", ""
  Parse "FormBTWTabelGrid", False

'-------------------------------
' BTWTabelGrid Close Event begin
' BTWTabelGrid Close Event end
'-------------------------------
End Sub
'===============================

%>