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

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


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


'===============================
' fin_btwtabelwaardegrid PageSecurity begin
' fin_btwtabelwaardegrid PageSecurity end
'===============================

'===============================
' fin_btwtabelwaardegrid Open Event begin
' fin_btwtabelwaardegrid Open Event end
'===============================

'===============================
' fin_btwtabelwaardegrid OpenAnyPage Event begin
' fin_btwtabelwaardegrid OpenAnyPage Event end
'===============================

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

' fin_btwtabelwaardegrid 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
'-------------------------------
BTWTabelwaardeSearch_Show
BTWTabelwaardegrid_Show
'-------------------------------
' Process page templates
'-------------------------------
Parse "main", False
'-------------------------------
' Output the page to the browser
'-------------------------------
Response.write PrintVar("main")

' fin_btwtabelwaardegrid Show end

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

' fin_btwtabelwaardegrid Close Event begin
' fin_btwtabelwaardegrid Close Event end

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

'===============================
' Display Grid Form
'-------------------------------
Sub BTWTabelwaardegrid_Show()
'-------------------------------
' Initialize variables  
'-------------------------------
  Dim rs
  Dim sWhere : sWhere = ""
  Dim sOrder : sOrder = ""
  Dim sSQL : sSQL = ""
  Dim sFormTitle: sFormTitle = "BTW Tabelwaardes"
  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_btwtabelwaarderecord.asp"

  SetVar "TransitParams", "FIN_BTWTABEL_KEY=" & ToURL(GetParam("FIN_BTWTABEL_KEY")) & "&"
  SetVar "FormParams", "FIN_BTWTABEL_KEY=" & ToURL(GetParam("FIN_BTWTABEL_KEY")) & "&"

'-------------------------------
' Build WHERE statement
'-------------------------------
  pFIN_BTWTABEL_KEY = GetParam("FIN_BTWTABEL_KEY")
  if IsNumeric(pFIN_BTWTABEL_KEY) and not isEmpty(pFIN_BTWTABEL_KEY) then pFIN_BTWTABEL_KEY = ToSQL(pFIN_BTWTABEL_KEY, "Number") else pFIN_BTWTABEL_KEY = Empty
  if not isEmpty(pFIN_BTWTABEL_KEY) then
    HasParam = true
    sWhere = sWhere & "F.FIN_BTWTABEL_KEY=" & pFIN_BTWTABEL_KEY
  end if


  if HasParam then
    sWhere = " AND (FIN_BTWTABELWAARDE_VERWIJDER IS NULL) AND (" & sWhere & ")"
  else
    sWhere = " AND FIN_BTWTABELWAARDE_VERWIJDER IS NULL"
  end if
  
'-------------------------------
' Build ORDER BY statement
'-------------------------------
  sOrder = " order by F.FIN_BTWTABELWAARDE_PERC Asc"
  iSort = GetParam("FormBTWTabelwaardegrid_Sorting")
  iSorted = GetParam("FormBTWTabelwaardegrid_Sorted")
  sDirection = ""
  if IsEmpty(iSort) then
    SetVar "Form_Sorting", ""
  else
    if iSort = iSorted then 
      SetVar "Form_Sorting", ""
      sDirection = " DESC"
      sSortParams = "FormBTWTabelwaardegrid_Sorting=" & iSort & "&FormBTWTabelwaardegrid_Sorted=" & iSort & "&"
    else
      SetVar "Form_Sorting", iSort
      sDirection = " ASC"
      sSortParams = "FormBTWTabelwaardegrid_Sorting=" & iSort & "&FormBTWTabelwaardegrid_Sorted=" & "&"
    end if
    if iSort = 1 then sOrder = " order by F.FIN_BTWTABELWAARDE_KEY" & sDirection
    if iSort = 2 then sOrder = " order by F1.FIN_BTWTABEL_OMSCHRIJVING" & sDirection
    if iSort = 3 then sOrder = " order by F.FIN_BTWTABELWAARDE_CODE" & sDirection
    if iSort = 4 then sOrder = " order by F.FIN_BTWTABELWAARDE_OMS" & sDirection
    if iSort = 5 then sOrder = " order by F.FIN_BTWTABELWAARDE_PERC" & sDirection
    if iSort = 6 then sOrder = " order by F.FIN_BTWTABELWAARDE_VERLEGD" & sDirection
  end if

'-------------------------------
' Build base SQL statement
'-------------------------------
  sSQL = "select F.FIN_BTWTABELWAARDE_CODE as F_FIN_BTWTABELWAARDE_CODE, " & _
    "F.FIN_BTWTABELWAARDE_KEY as F_FIN_BTWTABELWAARDE_KEY, " & _
    "F.FIN_BTWTABELWAARDE_OMS as F_FIN_BTWTABELWAARDE_OMS, " & _
    "F.FIN_BTWTABELWAARDE_PERC as F_FIN_BTWTABELWAARDE_PERC, " & _
    "F.FIN_BTWTABELWAARDE_VERLEGD as F_FIN_BTWTABELWAARDE_VERLEGD, " & _
    "F.FIN_BTWTABEL_KEY as F_FIN_BTWTABEL_KEY, " & _
    "F1.FIN_BTWTABEL_KEY as F1_FIN_BTWTABEL_KEY, " & _
    "F1.FIN_BTWTABEL_OMSCHRIJVING as F1_FIN_BTWTABEL_OMSCHRIJVING " & _
    " from FIN_BTWTABELWAARDE F, FIN_BTWTABEL F1" & _
    " where F1.FIN_BTWTABEL_KEY=F.FIN_BTWTABEL_KEY  "
'-------------------------------

'-------------------------------
' BTWTabelwaardegrid Open Event begin
' BTWTabelwaardegrid 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 "DListBTWTabelwaardegrid", ""
    Parse "BTWTabelwaardegridNoRecords", False
    SetVar "BTWTabelwaardegridNavigator", ""
    Parse "FormBTWTabelwaardegrid", False
    exit sub
  end if
'-------------------------------

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

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

'-------------------------------
' Process page scroller
'-------------------------------
  iPage = GetParam("FormBTWTabelwaardegrid_Page")
  openrs rsCount, sCountSQL
  dResult = CLng(rsCount.fields(0).value) / iRecordsPerPage
  iPageCount = int(dResult)
  if iPageCount < dResult then iPageCount = iPageCount + 1
  SetVar "BTWTabelwaardegridPageCount", 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_KEY = GetValue(rs, "F1_FIN_BTWTABEL_OMSCHRIJVING")
    fldFIN_BTWTABELWAARDE_CODE_URLLink = "fin_btwtabelwaarderecord.asp"
    fldFIN_BTWTABELWAARDE_CODE_FIN_BTWTABELWAARDE_KEY = GetValue(rs, "F_FIN_BTWTABELWAARDE_KEY")
    fldFIN_BTWTABELWAARDE_CODE = GetValue(rs, "F_FIN_BTWTABELWAARDE_CODE")
    fldFIN_BTWTABELWAARDE_KEY = GetValue(rs, "F_FIN_BTWTABELWAARDE_KEY")
    fldFIN_BTWTABELWAARDE_OMS_URLLink = "fin_btwtabelwaarderecord.asp"
    fldFIN_BTWTABELWAARDE_OMS_FIN_BTWTABELWAARDE_KEY = GetValue(rs, "F_FIN_BTWTABELWAARDE_KEY")
    fldFIN_BTWTABELWAARDE_OMS = GetValue(rs, "F_FIN_BTWTABELWAARDE_OMS")
    fldFIN_BTWTABELWAARDE_PERC = GetValue(rs, "F_FIN_BTWTABELWAARDE_PERC")
    fldFIN_BTWTABELWAARDE_VERLEGD = GetValue(rs, "F_FIN_BTWTABELWAARDE_VERLEGD")
'-------------------------------
' BTWTabelwaardegrid Show begin
'-------------------------------

'-------------------------------
' BTWTabelwaardegrid Show Event begin
' BTWTabelwaardegrid Show Event end
'-------------------------------

'-------------------------------
' Replace Template fields with database values
'-------------------------------
    
      SetVar "FIN_BTWTABELWAARDE_KEY", ToHTML(fldFIN_BTWTABELWAARDE_KEY)
      SetVar "FIN_BTWTABEL_KEY", ToHTML(fldFIN_BTWTABEL_KEY)
      SetVar "FIN_BTWTABELWAARDE_CODE", ToHTML(fldFIN_BTWTABELWAARDE_CODE)
      SetVar "FIN_BTWTABELWAARDE_CODE_URLLink", fldFIN_BTWTABELWAARDE_CODE_URLLink
      SetVar "PrmFIN_BTWTABELWAARDE_CODE_FIN_BTWTABELWAARDE_KEY", ToURL(fldFIN_BTWTABELWAARDE_CODE_FIN_BTWTABELWAARDE_KEY)
      SetVar "FIN_BTWTABELWAARDE_OMS", ToHTML(fldFIN_BTWTABELWAARDE_OMS)
      SetVar "FIN_BTWTABELWAARDE_OMS_URLLink", fldFIN_BTWTABELWAARDE_OMS_URLLink
      SetVar "PrmFIN_BTWTABELWAARDE_OMS_FIN_BTWTABELWAARDE_KEY", ToURL(fldFIN_BTWTABELWAARDE_OMS_FIN_BTWTABELWAARDE_KEY)
      SetVar "FIN_BTWTABELWAARDE_PERC", fldFIN_BTWTABELWAARDE_PERC
      fldFIN_BTWTABELWAARDE_VERLEGD = getValFromLOV(fldFIN_BTWTABELWAARDE_VERLEGD, aFIN_BTWTABELWAARDE_VERLEGD)
      SetVar "FIN_BTWTABELWAARDE_VERLEGD", ToHTML(fldFIN_BTWTABELWAARDE_VERLEGD)
    Parse "DListBTWTabelwaardegrid", True

'-------------------------------
' BTWTabelwaardegrid Show end
'-------------------------------

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


'-------------------------------
' BTWTabelwaardegrid Navigation begin
'-------------------------------
  bEof = rs.eof
  if rs.eof and iPage = 1 then
	SetVar "BTWTabelwaardegridNavigator", ""
  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 "BTWTabelwaardegridNavigatorPages", true
      iDisplayPages = iDisplayPages + 1
    next
    SetVar "NavigatorPageSwitch", "_"
    SetVar "NavigatorPageNumber", iPage
    SetVar "NavigatorPageNumberView", iPage
    Parse "BTWTabelwaardegridNavigatorPages", true
    iDisplayPages = iDisplayPages + 1
    SetVar "NavigatorPageSwitch", ""
    iPageCount = iPage + 1
    while iDisplayPages < iNumberOfPages and iStartPage + iDisplayPages < iHasPages
      SetVar "NavigatorPageNumber", iPageCount
      SetVar "NavigatorPageNumberView", iPageCount
      Parse "BTWTabelwaardegridNavigatorPages", true
      iDisplayPages = iDisplayPages + 1
      iPageCount = iPageCount + 1
    wend
    if bEof then
      SetVar "BTWTabelwaardegridNavigatorLastPage", "_"
    else
      SetVar "NextPage", (iPage + 1)
    end if
    if iPage = 1 then
      SetVar "BTWTabelwaardegridNavigatorFirstPage", "_"
    else
      SetVar "PrevPage", (iPage - 1)
    end if
    SetVar "BTWTabelwaardegridCurrentPage", iPage
    Parse "BTWTabelwaardegridNavigator", False
  end if
'-------------------------------
' BTWTabelwaardegrid Navigation end
'-------------------------------

'-------------------------------
' Finish form processing
'-------------------------------
  set rs = nothing
  SetVar "BTWTabelwaardegridNoRecords", ""
  Parse "FormBTWTabelwaardegrid", False

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


'===============================
' Display Search Form
'-------------------------------
Sub BTWTabelwaardeSearch_Show()
  Dim sFormTitle: sFormTitle = ""
  Dim sActionFileName: sActionFileName = "fin_btwtabelwaardegrid.asp"
  Dim sFIN_BTWTABEL_KEYDisplayValue: sFIN_BTWTABEL_KEYDisplayValue = ""

'-------------------------------
' BTWTabelwaardeSearch Open Event begin
' BTWTabelwaardeSearch Open Event end
'-------------------------------
      SetVar "FormTitle", sFormTitle
      SetVar "ActionPage", sActionFileName

'-------------------------------
' Set variables with search parameters
'-------------------------------
      fldFIN_BTWTABEL_KEY = GetParam("FIN_BTWTABEL_KEY")

'-------------------------------
' BTWTabelwaardeSearch Show begin
'-------------------------------


'-------------------------------
' BTWTabelwaardeSearch Show Event begin
' BTWTabelwaardeSearch Show Event end
'-------------------------------
      SetVar "BTWTabelwaardeSearchLBFIN_BTWTABEL_KEY", ""
      SetVar "Selected", ""
      SetVar "ID", ""
      SetVar "Value", sFIN_BTWTABEL_KEYDisplayValue
      Parse "BTWTabelwaardeSearchLBFIN_BTWTABEL_KEY", True
      openrs rsFIN_BTWTABEL_KEY, "select FIN_BTWTABEL_KEY, FIN_BTWTABEL_OMSCHRIJVING from FIN_BTWTABEL order by 2"
      while not rsFIN_BTWTABEL_KEY.EOF
        SetVar "ID", GetValue(rsFIN_BTWTABEL_KEY, 0) : SetVar "Value", GetValue(rsFIN_BTWTABEL_KEY, 1)
        if cstr(GetValue(rsFIN_BTWTABEL_KEY, 0)) = cstr(fldFIN_BTWTABEL_KEY) then SetVar "Selected", "SELECTED" else SetVar "Selected", ""
        Parse "BTWTabelwaardeSearchLBFIN_BTWTABEL_KEY", True
        rsFIN_BTWTABEL_KEY.MoveNext
      wend
      set rsFIN_BTWTABEL_KEY = nothing
    

'-------------------------------
' BTWTabelwaardeSearch Show end
'-------------------------------

'-------------------------------
' BTWTabelwaardeSearch Close Event begin
' BTWTabelwaardeSearch Close Event end
'-------------------------------
      Parse "FormBTWTabelwaardeSearch", False
End Sub
'===============================

%>