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

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


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


'===============================
' cnt_kenmerkgrid PageSecurity begin
' cnt_kenmerkgrid PageSecurity end
'===============================

'===============================
' cnt_kenmerkgrid Open Event begin
' cnt_kenmerkgrid Open Event end
'===============================

'===============================
' cnt_kenmerkgrid OpenAnyPage Event begin
' cnt_kenmerkgrid OpenAnyPage Event end
'===============================

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

' cnt_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")

' cnt_kenmerkgrid Show end

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

' cnt_kenmerkgrid Close Event begin
' cnt_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 = "cnt_kenmerkrecord.asp"

  SetVar "TransitParams", "CNT_SRTCONTRACT_KEY=" & ToURL(GetParam("CNT_SRTCONTRACT_KEY")) & "&CNT_SRTKENMERK_KEY=" & ToURL(GetParam("CNT_SRTKENMERK_KEY")) & "&sCNT_SRTKENMERK_KENMERKTYPE=" & ToURL(GetParam("sCNT_SRTKENMERK_KENMERKTYPE")) & "&"
  SetVar "FormParams", "CNT_SRTCONTRACT_KEY=" & ToURL(GetParam("CNT_SRTCONTRACT_KEY")) & "&CNT_SRTKENMERK_KEY=" & ToURL(GetParam("CNT_SRTKENMERK_KEY")) & "&sCNT_SRTKENMERK_KENMERKTYPE=" & ToURL(GetParam("sCNT_SRTKENMERK_KENMERKTYPE")) & "&"

'-------------------------------
' Build WHERE statement
'-------------------------------
  pCNT_SRTCONTRACT_KEY = GetParam("CNT_SRTCONTRACT_KEY")
  if IsNumeric(pCNT_SRTCONTRACT_KEY) and not isEmpty(pCNT_SRTCONTRACT_KEY) then pCNT_SRTCONTRACT_KEY = ToSQL(pCNT_SRTCONTRACT_KEY, "Number") else pCNT_SRTCONTRACT_KEY = Empty
  if not isEmpty(pCNT_SRTCONTRACT_KEY) then
    HasParam = true
    sWhere = sWhere & "CNT_SRTCONTRACT_KEY=" & pCNT_SRTCONTRACT_KEY
  end if
  pCNT_SRTKENMERK_KEY = GetParam("CNT_SRTKENMERK_KEY")
  if IsNumeric(pCNT_SRTKENMERK_KEY) and not isEmpty(pCNT_SRTKENMERK_KEY) then pCNT_SRTKENMERK_KEY = ToSQL(pCNT_SRTKENMERK_KEY, "Number") else pCNT_SRTKENMERK_KEY = Empty
  if not isEmpty(pCNT_SRTKENMERK_KEY) then
    if not (sWhere = "") then sWhere = sWhere & " and "
    HasParam = true
    sWhere = sWhere & "CNT_SRTKENMERK_KEY=" & pCNT_SRTKENMERK_KEY
  end if


  if HasParam then
    sWhere = " AND (" & sWhere & ")"
  end if
  
'-------------------------------
' Build ORDER BY statement
'-------------------------------
  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
  end if

'-------------------------------
' Build base SQL statement
'-------------------------------
  sSQL = "SELECT C.CNT_KENMERK_KEY as CNT_KENMERK_KEY,   C.CNT_KENMERK_NIVEAU as CNT_KENMERK_NIVEAU,   C.CNT_KENMERK_VOLGNUMMER as CNT_KENMERK_VOLGNUMMER,   C.CNT_SRTCONTRACT_KEY as CNT_SRTCONTRACT_KEY,   C.CNT_SRTKENMERK_KEY as CNT_SRTKENMERK_KEY,   C1.INS_DISCIPLINE_OMSCHRIJVING as CNT_SRTCONTRACT_OMSCHRIJVING,   C2.CNT_SRTKENMERK_OMSCHRIJVING as CNT_SRTKENMERK_OMSCHRIJVING,   C2.CNT_SRTKENMERK_KENMERKTYPE as CNT_SRTKENMERK_KENMERKTYPE FROM CNT_KENMERK C, CNT_DISCIPLINE C1, CNT_SRTKENMERK C2 WHERE C1.INS_DISCIPLINE_KEY=C.CNT_SRTCONTRACT_KEY and  C2.CNT_SRTKENMERK_KEY=C.CNT_SRTKENMERK_KEY and C.CNT_KENMERK_VERWIJDER is null and C2.CNT_SRTKENMERK_VERWIJDER is null"
  sOrder = ""
'-------------------------------

'-------------------------------
' KenmerkGrid Open Event begin
if IsEmpty(iSort) then
    iSort = 2
    sDirection = " ASC"
end if
select case iSort
    case "1" sOrder = "CNT_KENMERK_KEY"
'    case "2" sOrder = "CNT_KENMERK_NIVEAU"
    case "2" sOrder = "upper(CNT_SRTCONTRACT_OMSCHRIJVING)"
    case "3" sOrder = "upper(CNT_SRTKENMERK_OMSCHRIJVING)"
    case "4" sOrder = "CNT_KENMERK_VOLGNUMMER"
    case "5" sOrder = "CNT_SRTKENMERK_KENMERKTYPE"
end select
sOrder = " order by " & sOrder & sDirection

' sWhere leeg maken omdat cnt_srtkenmerk_key in twee tabellen voor komt in de query.
sWhere = ""

if not isEmpty(pCNT_SRTCONTRACT_KEY) then
  sWhere = sWhere & " AND C.CNT_SRTCONTRACT_KEY=" & ToSQL(pCNT_SRTCONTRACT_KEY, "Number")
end if

if not isEmpty(pCNT_SRTKENMERK_KEY) then
  sWhere = sWhere & " AND C.CNT_SRTKENMERK_KEY=" & ToSQL(pCNT_SRTKENMERK_KEY, "Number")
end if

pCNT_SRTKENMERK_KENMERKTYPE = getParam("sCNT_SRTKENMERK_KENMERKTYPE")
if not isEmpty(pCNT_SRTKENMERK_KENMERKTYPE) then
  sWhere = sWhere & " AND C2.CNT_SRTKENMERK_KENMERKTYPE = " & ToSQL(pCNT_SRTKENMERK_KENMERKTYPE, "Text")
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
'-------------------------------
    fldCNT_KENMERK_KEY = GetValue(rs, "CNT_KENMERK_KEY")
    fldCNT_KENMERK_NIVEAU = GetValue(rs, "CNT_KENMERK_NIVEAU")
    fldCNT_KENMERK_VOLGNUMMER = GetValue(rs, "CNT_KENMERK_VOLGNUMMER")
    fldCNT_SRTCONTRACT_OMSCHRIJVING_URLLink = "cnt_kenmerkrecord.asp"
    fldCNT_SRTCONTRACT_OMSCHRIJVING_CNT_KENMERK_KEY = GetValue(rs, "CNT_KENMERK_KEY")
    fldCNT_SRTCONTRACT_OMSCHRIJVING = GetValue(rs, "CNT_SRTCONTRACT_OMSCHRIJVING")
    fldCNT_SRTKENMERK_KENMERKTYPE = GetValue(rs, "CNT_SRTKENMERK_KENMERKTYPE")
    fldCNT_SRTKENMERK_OMSCHRIJVING_URLLink = "cnt_kenmerkrecord.asp"
    fldCNT_SRTKENMERK_OMSCHRIJVING_CNT_KENMERK_KEY = GetValue(rs, "CNT_KENMERK_KEY")
    fldCNT_SRTKENMERK_OMSCHRIJVING = GetValue(rs, "CNT_SRTKENMERK_OMSCHRIJVING")
'-------------------------------
' KenmerkGrid Show begin
'-------------------------------

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

'-------------------------------
' Replace Template fields with database values
'-------------------------------
    
      SetVar "CNT_KENMERK_KEY", ToHTML(fldCNT_KENMERK_KEY)
      SetVar "CNT_KENMERK_NIVEAU", ToHTML(fldCNT_KENMERK_NIVEAU)
      SetVar "CNT_SRTCONTRACT_OMSCHRIJVING", ToHTML(fldCNT_SRTCONTRACT_OMSCHRIJVING)
      SetVar "CNT_SRTCONTRACT_OMSCHRIJVING_URLLink", fldCNT_SRTCONTRACT_OMSCHRIJVING_URLLink
      SetVar "PrmCNT_SRTCONTRACT_OMSCHRIJVING_CNT_KENMERK_KEY", ToURL(fldCNT_SRTCONTRACT_OMSCHRIJVING_CNT_KENMERK_KEY)
      SetVar "CNT_SRTKENMERK_OMSCHRIJVING", ToHTML(fldCNT_SRTKENMERK_OMSCHRIJVING)
      SetVar "CNT_SRTKENMERK_OMSCHRIJVING_URLLink", fldCNT_SRTKENMERK_OMSCHRIJVING_URLLink
      SetVar "PrmCNT_SRTKENMERK_OMSCHRIJVING_CNT_KENMERK_KEY", ToURL(fldCNT_SRTKENMERK_OMSCHRIJVING_CNT_KENMERK_KEY)
      SetVar "CNT_KENMERK_VOLGNUMMER", ToHTML(fldCNT_KENMERK_VOLGNUMMER)
      SetVar "CNT_SRTKENMERK_KENMERKTYPE", ToHTML(fldCNT_SRTKENMERK_KENMERKTYPE)
    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 = "cnt_kenmerkgrid.asp"
  Dim sCNT_SRTCONTRACT_KEYDisplayValue: sCNT_SRTCONTRACT_KEYDisplayValue = "Alles"
  Dim sCNT_SRTKENMERK_KEYDisplayValue: sCNT_SRTKENMERK_KEYDisplayValue = "Alles"

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

'-------------------------------
' Set variables with search parameters
'-------------------------------
      fldCNT_SRTCONTRACT_KEY = GetParam("CNT_SRTCONTRACT_KEY")
      fldCNT_SRTKENMERK_KEY = GetParam("CNT_SRTKENMERK_KEY")
      fldsCNT_SRTKENMERK_KENMERKTYPE = GetParam("sCNT_SRTKENMERK_KENMERKTYPE")

'-------------------------------
' Kenmerksearch Show begin
'-------------------------------


'-------------------------------
' Kenmerksearch Show Event begin
' Kenmerksearch Show Event end
'-------------------------------
      SetVar "KenmerksearchLBCNT_SRTCONTRACT_KEY", ""
      SetVar "Selected", ""
      SetVar "ID", ""
      SetVar "Value", sCNT_SRTCONTRACT_KEYDisplayValue
      Parse "KenmerksearchLBCNT_SRTCONTRACT_KEY", True
      openrs rsCNT_SRTCONTRACT_KEY, "select ins_discipline_key, ins_discipline_omschrijving from cnt_discipline where ins_discipline_verwijder is null order by ins_discipline_omschrijving asc"
      while not rsCNT_SRTCONTRACT_KEY.EOF
        SetVar "ID", GetValue(rsCNT_SRTCONTRACT_KEY, 0) : SetVar "Value", GetValue(rsCNT_SRTCONTRACT_KEY, 1)
        if cstr(GetValue(rsCNT_SRTCONTRACT_KEY, 0)) = cstr(fldCNT_SRTCONTRACT_KEY) then SetVar "Selected", "SELECTED" else SetVar "Selected", ""
        Parse "KenmerksearchLBCNT_SRTCONTRACT_KEY", True
        rsCNT_SRTCONTRACT_KEY.MoveNext
      wend
      set rsCNT_SRTCONTRACT_KEY = nothing
    
      SetVar "KenmerksearchLBCNT_SRTKENMERK_KEY", ""
      SetVar "Selected", ""
      SetVar "ID", ""
      SetVar "Value", sCNT_SRTKENMERK_KEYDisplayValue
      Parse "KenmerksearchLBCNT_SRTKENMERK_KEY", True
      openrs rsCNT_SRTKENMERK_KEY, "select cnt_srtkenmerk_key, cnt_srtkenmerk_omschrijving from cnt_srtkenmerk where cnt_srtkenmerk_verwijder is null order by cnt_srtkenmerk_upper asc"
      while not rsCNT_SRTKENMERK_KEY.EOF
        SetVar "ID", GetValue(rsCNT_SRTKENMERK_KEY, 0) : SetVar "Value", GetValue(rsCNT_SRTKENMERK_KEY, 1)
        if cstr(GetValue(rsCNT_SRTKENMERK_KEY, 0)) = cstr(fldCNT_SRTKENMERK_KEY) then SetVar "Selected", "SELECTED" else SetVar "Selected", ""
        Parse "KenmerksearchLBCNT_SRTKENMERK_KEY", True
        rsCNT_SRTKENMERK_KEY.MoveNext
      wend
      set rsCNT_SRTKENMERK_KEY = nothing
    
      SetVar "KenmerksearchLBsCNT_SRTKENMERK_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(fldsCNT_SRTKENMERK_KENMERKTYPE) then SetVar "Selected", "SELECTED" else SetVar "Selected", ""
          Parse "KenmerksearchLBsCNT_SRTKENMERK_KENMERKTYPE", True
        next
      end if
    

'-------------------------------
' Kenmerksearch Show end
'-------------------------------

'-------------------------------
' Kenmerksearch Close Event begin
' Kenmerksearch Close Event end
'-------------------------------
      Parse "FormKenmerksearch", False
End Sub
'===============================

%>