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

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


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


'===============================
' fin_kenmerkgrid PageSecurity begin
' fin_kenmerkgrid PageSecurity end
'===============================

'===============================
' fin_kenmerkgrid Open Event begin
' fin_kenmerkgrid Open Event end
'===============================

'===============================
' fin_kenmerkgrid OpenAnyPage Event begin
' fin_kenmerkgrid OpenAnyPage Event end
'===============================

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

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

' fin_kenmerkgrid Show end

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

' fin_kenmerkgrid Close Event begin
' fin_kenmerkgrid Close Event end

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

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

  SetVar "TransitParams", "sFIN_KENMERK_KENMERKTYPE=" & ToURL(GetParam("sFIN_KENMERK_KENMERKTYPE")) & "&sFIN_KENMERK_UPPER=" & ToURL(GetParam("sFIN_KENMERK_UPPER")) & "&"
  SetVar "FormParams", "sFIN_KENMERK_KENMERKTYPE=" & ToURL(GetParam("sFIN_KENMERK_KENMERKTYPE")) & "&sFIN_KENMERK_UPPER=" & ToURL(GetParam("sFIN_KENMERK_UPPER")) & "&"

'-------------------------------
' Build WHERE statement
'-------------------------------


  sWhere = " WHERE FIN_KENMERK_VERWIJDER IS NULL"
  
'-------------------------------
' Build ORDER BY statement
'-------------------------------
  sOrder = " order by F.FIN_KENMERK_VOLGNR Asc"
  iSort = GetParam("FormKenmerkGrid_Sorting")
  iSorted = GetParam("FormKenmerkGrid_Sorted")
  sDirection = ""
  if IsEmpty(iSort) then
    SetVar "Form_Sorting", ""
  else
    if iSort = iSorted then 
      SetVar "Form_Sorting", ""
      sDirection = " DESC"
      sSortParams = "FormKenmerkGrid_Sorting=" & iSort & "&FormKenmerkGrid_Sorted=" & iSort & "&"
    else
      SetVar "Form_Sorting", iSort
      sDirection = " ASC"
      sSortParams = "FormKenmerkGrid_Sorting=" & iSort & "&FormKenmerkGrid_Sorted=" & "&"
    end if
    if iSort = 1 then sOrder = " order by F.FIN_KENMERK_KEY" & sDirection
    if iSort = 2 then sOrder = " order by F.FIN_KENMERK_VOLGNR" & sDirection
    if iSort = 3 then sOrder = " order by F.FIN_KENMERK_OMSCHRIJVING" & sDirection
    if iSort = 4 then sOrder = " order by F.FIN_KENMERK_KENMERKTYPE" & sDirection
  end if

'-------------------------------
' Build base SQL statement
'-------------------------------
  sSQL = "select F.FIN_KENMERK_KENMERKTYPE as F_FIN_KENMERK_KENMERKTYPE, " & _
    "F.FIN_KENMERK_KEY as F_FIN_KENMERK_KEY, " & _
    "F.FIN_KENMERK_OMSCHRIJVING as F_FIN_KENMERK_OMSCHRIJVING, " & _
    "F.FIN_KENMERK_VOLGNR as F_FIN_KENMERK_VOLGNR " & _
    " from FIN_KENMERK F "
'-------------------------------

'-------------------------------
' KenmerkGrid Open Event begin
pFIN_KENMERK_UPPER = getParam("sFIN_KENMERK_UPPER")
pFIN_KENMERK_KENMERKTYPE = getParam("sFIN_KENMERK_KENMERKTYPE")
sWhere = ""
tmpWhere = ""
if not isEmpty(pFIN_KENMERK_UPPER) then
  hasParam = true
  tmpWhere = tmpWhere & " AND FIN_KENMERK_UPPER like " & ToSQL("%"& UCase(pFIN_KENMERK_UPPER) &"%", "Text")
end if

if not isEmpty(pFIN_KENMERK_KENMERKTYPE) then
  hasParam = true
  tmpWhere = tmpWhere & " AND FIN_KENMERK_KENMERKTYPE = " & ToSQL(pFIN_KENMERK_KENMERKTYPE, "Text")
end if

if HasParam then
  sWhere = " WHERE (FIN_KENMERK_VERWIJDER IS NULL) " & tmpWhere
else
  sWhere = " WHERE FIN_KENMERK_VERWIJDER IS NULL"
end if
' KenmerkGrid 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 "DListKenmerkGrid", ""
    Parse "KenmerkGridNoRecords", False
    SetVar "KenmerkGridNavigator", ""
    Parse "FormKenmerkGrid", False
    exit sub
  end if
'-------------------------------

'-------------------------------
' Initialize page counter and records per page
'-------------------------------
  iRecordsPerPage = 25
  iCounter = 0
'-------------------------------

'-------------------------------
' Process page scroller
'-------------------------------
  iPage = GetParam("FormKenmerkGrid_Page")
  openrs rsCount, sCountSQL
  dResult = CLng(rsCount.fields(0).value) / iRecordsPerPage
  iPageCount = int(dResult)
  if iPageCount < dResult then iPageCount = iPageCount + 1
  SetVar "KenmerkGridPageCount", 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_KENMERK_KENMERKTYPE_URLLink = "fin_kenmerkrecord.asp"
    fldFIN_KENMERK_KENMERKTYPE_FIN_KENMERK_KEY = GetValue(rs, "F_FIN_KENMERK_KEY")
    fldFIN_KENMERK_KENMERKTYPE = GetValue(rs, "F_FIN_KENMERK_KENMERKTYPE")
    fldFIN_KENMERK_KEY = GetValue(rs, "F_FIN_KENMERK_KEY")
    fldFIN_KENMERK_OMSCHRIJVING_URLLink = "fin_kenmerkrecord.asp"
    fldFIN_KENMERK_OMSCHRIJVING_FIN_KENMERK_KEY = GetValue(rs, "F_FIN_KENMERK_KEY")
    fldFIN_KENMERK_OMSCHRIJVING = GetValue(rs, "F_FIN_KENMERK_OMSCHRIJVING")
    fldFIN_KENMERK_VOLGNR_URLLink = "fin_kenmerkrecord.asp"
    fldFIN_KENMERK_VOLGNR_FIN_KENMERK_KEY = GetValue(rs, "F_FIN_KENMERK_KEY")
    fldFIN_KENMERK_VOLGNR = GetValue(rs, "F_FIN_KENMERK_VOLGNR")
'-------------------------------
' KenmerkGrid Show begin
'-------------------------------

'-------------------------------
' KenmerkGrid Show Event begin
fldFIN_KENMERK_KENMERKTYPE = decodeKenmerkType(fldFIN_KENMERK_KENMERKTYPE)
' KenmerkGrid Show Event end
'-------------------------------

'-------------------------------
' Replace Template fields with database values
'-------------------------------
    
      SetVar "FIN_KENMERK_KEY", ToHTML(fldFIN_KENMERK_KEY)
      SetVar "FIN_KENMERK_VOLGNR", ToHTML(fldFIN_KENMERK_VOLGNR)
      SetVar "FIN_KENMERK_VOLGNR_URLLink", fldFIN_KENMERK_VOLGNR_URLLink
      SetVar "PrmFIN_KENMERK_VOLGNR_FIN_KENMERK_KEY", ToURL(fldFIN_KENMERK_VOLGNR_FIN_KENMERK_KEY)
      SetVar "FIN_KENMERK_OMSCHRIJVING", ToHTML(fldFIN_KENMERK_OMSCHRIJVING)
      SetVar "FIN_KENMERK_OMSCHRIJVING_URLLink", fldFIN_KENMERK_OMSCHRIJVING_URLLink
      SetVar "PrmFIN_KENMERK_OMSCHRIJVING_FIN_KENMERK_KEY", ToURL(fldFIN_KENMERK_OMSCHRIJVING_FIN_KENMERK_KEY)
      SetVar "FIN_KENMERK_KENMERKTYPE", ToHTML(fldFIN_KENMERK_KENMERKTYPE)
      SetVar "FIN_KENMERK_KENMERKTYPE_URLLink", fldFIN_KENMERK_KENMERKTYPE_URLLink
      SetVar "PrmFIN_KENMERK_KENMERKTYPE_FIN_KENMERK_KEY", ToURL(fldFIN_KENMERK_KENMERKTYPE_FIN_KENMERK_KEY)
    Parse "DListKenmerkGrid", True

'-------------------------------
' KenmerkGrid Show end
'-------------------------------

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


'-------------------------------
' KenmerkGrid Navigation begin
'-------------------------------
  bEof = rs.eof
  if rs.eof and iPage = 1 then
	SetVar "KenmerkGridNavigator", ""
  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 "KenmerkGridNavigatorPages", true
      iDisplayPages = iDisplayPages + 1
    next
    SetVar "NavigatorPageSwitch", "_"
    SetVar "NavigatorPageNumber", iPage
    SetVar "NavigatorPageNumberView", iPage
    Parse "KenmerkGridNavigatorPages", true
    iDisplayPages = iDisplayPages + 1
    SetVar "NavigatorPageSwitch", ""
    iPageCount = iPage + 1
    while iDisplayPages < iNumberOfPages and iStartPage + iDisplayPages < iHasPages
      SetVar "NavigatorPageNumber", iPageCount
      SetVar "NavigatorPageNumberView", iPageCount
      Parse "KenmerkGridNavigatorPages", true
      iDisplayPages = iDisplayPages + 1
      iPageCount = iPageCount + 1
    wend
    if bEof then
      SetVar "KenmerkGridNavigatorLastPage", "_"
    else
      SetVar "NextPage", (iPage + 1)
    end if
    if iPage = 1 then
      SetVar "KenmerkGridNavigatorFirstPage", "_"
    else
      SetVar "PrevPage", (iPage - 1)
    end if
    SetVar "KenmerkGridCurrentPage", iPage
    Parse "KenmerkGridNavigator", False
  end if
'-------------------------------
' KenmerkGrid Navigation end
'-------------------------------

'-------------------------------
' Finish form processing
'-------------------------------
  set rs = nothing
  SetVar "KenmerkGridNoRecords", ""
  Parse "FormKenmerkGrid", False

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


'===============================
' Display Search Form
'-------------------------------
Sub KenmerkSearch_Show()
  Dim sFormTitle: sFormTitle = ""
  Dim sActionFileName: sActionFileName = "fin_kenmerkgrid.asp"

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

'-------------------------------
' Set variables with search parameters
'-------------------------------
      fldsFIN_KENMERK_UPPER = GetParam("sFIN_KENMERK_UPPER")
      fldsFIN_KENMERK_KENMERKTYPE = GetParam("sFIN_KENMERK_KENMERKTYPE")

'-------------------------------
' KenmerkSearch Show begin
'-------------------------------


'-------------------------------
' KenmerkSearch Show Event begin
' KenmerkSearch Show Event end
'-------------------------------
      SetVar "sFIN_KENMERK_UPPER", ToHTML(fldsFIN_KENMERK_UPPER)
      SetVar "KenmerkSearchLBsFIN_KENMERK_KENMERKTYPE", ""
      LOV = Split(""&buildKenmerkTypeSearch()&"", ";")
      if (ubound(LOV) mod 2) = 1 then
        for i = 0 to ubound(LOV) step 2
          SetVar "ID", LOV(i) : SetVar "Value", LOV(i+1)
          if cstr(LOV(i)) = cstr(fldsFIN_KENMERK_KENMERKTYPE) then SetVar "Selected", "SELECTED" else SetVar "Selected", ""
          Parse "KenmerkSearchLBsFIN_KENMERK_KENMERKTYPE", True
        next
      end if
    

'-------------------------------
' KenmerkSearch Show end
'-------------------------------

'-------------------------------
' KenmerkSearch Close Event begin
' KenmerkSearch Close Event end
'-------------------------------
      Parse "FormKenmerkSearch", False
End Sub
'===============================

%>