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

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


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


'===============================
' prs_kostencombinatiegrid PageSecurity begin
' prs_kostencombinatiegrid PageSecurity end
'===============================

'===============================
' prs_kostencombinatiegrid Open Event begin
' prs_kostencombinatiegrid Open Event end
'===============================

'===============================
' prs_kostencombinatiegrid OpenAnyPage Event begin
' prs_kostencombinatiegrid OpenAnyPage Event end
'===============================

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

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

' prs_kostencombinatiegrid Show end

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

' prs_kostencombinatiegrid Close Event begin
' prs_kostencombinatiegrid Close Event end

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

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

  SetVar "TransitParams", "PRS_KOSTENPLAATSGRP_KEY=" & ToURL(GetParam("PRS_KOSTENPLAATSGRP_KEY")) & "&sPRS_KOSTENCOMBINATIE_OMSCHRIJVING=" & ToURL(GetParam("sPRS_KOSTENCOMBINATIE_OMSCHRIJVING")) & "&"
  SetVar "FormParams", "PRS_KOSTENPLAATSGRP_KEY=" & ToURL(GetParam("PRS_KOSTENPLAATSGRP_KEY")) & "&sPRS_KOSTENCOMBINATIE_OMSCHRIJVING=" & ToURL(GetParam("sPRS_KOSTENCOMBINATIE_OMSCHRIJVING")) & "&"

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


  if HasParam then
    sWhere = " AND (" & sWhere & ")"
  end if
  
'-------------------------------
' Build ORDER BY statement
'-------------------------------
  sOrder = " order by P.PRS_KOSTENSOORT_KEY Asc"
  iSort = GetParam("FormKostencombinatieGrid_Sorting")
  iSorted = GetParam("FormKostencombinatieGrid_Sorted")
  sDirection = ""
  if IsEmpty(iSort) then
    SetVar "Form_Sorting", ""
  else
    if iSort = iSorted then 
      SetVar "Form_Sorting", ""
      sDirection = " DESC"
      sSortParams = "FormKostencombinatieGrid_Sorting=" & iSort & "&FormKostencombinatieGrid_Sorted=" & iSort & "&"
    else
      SetVar "Form_Sorting", iSort
      sDirection = " ASC"
      sSortParams = "FormKostencombinatieGrid_Sorting=" & iSort & "&FormKostencombinatieGrid_Sorted=" & "&"
    end if
    if iSort = 1 then sOrder = " order by P.PRS_KOSTENCOMBINATIE_KEY" & sDirection
    if iSort = 2 then sOrder = " order by P1.PRS_KOSTENSOORT_OMS" & sDirection
    if iSort = 3 then sOrder = " order by P2.PRS_KOSTENPLAATSGRP_OMS" & sDirection
  end if

'-------------------------------
' Build base SQL statement
'-------------------------------
  sSQL = "select P.PRS_KOSTENCOMBINATIE_KEY as P_PRS_KOSTENCOMBINATIE_KEY, " & _
    "P.PRS_KOSTENPLAATSGRP_KEY as P_PRS_KOSTENPLAATSGRP_KEY, " & _
    "P.PRS_KOSTENSOORT_KEY as P_PRS_KOSTENSOORT_KEY, " & _
    "P1.PRS_KOSTENSOORT_KEY as P1_PRS_KOSTENSOORT_KEY, " & _
    "P1.PRS_KOSTENSOORT_OMS as P1_PRS_KOSTENSOORT_OMS, " & _
    "P2.PRS_KOSTENPLAATSGRP_KEY as P2_PRS_KOSTENPLAATSGRP_KEY, " & _
    "P2.PRS_KOSTENPLAATSGRP_OMS as P2_PRS_KOSTENPLAATSGRP_OMS " & _
    " from PRS_KOSTENCOMBINATIE P, PRS_KOSTENSOORT P1, PRS_KOSTENPLAATSGRP P2" & _
    " where P1.PRS_KOSTENSOORT_KEY=P.PRS_KOSTENSOORT_KEY and P2.PRS_KOSTENPLAATSGRP_KEY=P.PRS_KOSTENPLAATSGRP_KEY  "
'-------------------------------

'-------------------------------
' KostencombinatieGrid Open Event begin
tmpWhere = ""
pPRS_KOSTENCOMBINATIE_OMSCHRIJVING = getParam("sPRS_KOSTENCOMBINATIE_OMSCHRIJVING")
if not isEmpty(pPRS_KOSTENCOMBINATIE_OMSCHRIJVING) then
  hasParam = true
  tmpWhere = tmpWhere & " (  Upper(PRS_KOSTENSOORT_OMS)     LIKE '%" & UCase(replace(pPRS_KOSTENCOMBINATIE_OMSCHRIJVING,"'","''")) & "%'" &_
                        " OR Upper(PRS_KOSTENPLAATSGRP_OMS) LIKE '%" & UCase(replace(pPRS_KOSTENCOMBINATIE_OMSCHRIJVING,"'","''")) & "%'" &_
                        " )"
end if

if tmpWhere <> "" then
  sWhere = sWhere & " AND " & tmpWhere
end if
' KostencombinatieGrid 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
'-------------------------------
  openStaticRS rs, sSQL
'-------------------------------

'-------------------------------
' Process empty recordset
'-------------------------------
  if rs.eof then
    set rs = nothing
    SetVar "DListKostencombinatieGrid", ""
    Parse "KostencombinatieGridNoRecords", False
    SetVar "KostencombinatieGridNavigator", ""
    Parse "FormKostencombinatieGrid", False
    exit sub
  end if
'-------------------------------

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

'-------------------------------
' Process page scroller
'-------------------------------
  iPage = GetParam("FormKostencombinatieGrid_Page")
  openrs rsCount, sCountSQL
  dResult = CLng(rsCount.fields(0).value) / iRecordsPerPage
  iPageCount = int(dResult)
  if iPageCount < dResult then iPageCount = iPageCount + 1
  SetVar "KostencombinatieGridPageCount", 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
'-------------------------------
    fldPRS_KOSTENCOMBINATIE_KEY = GetValue(rs, "P_PRS_KOSTENCOMBINATIE_KEY")
    fldPRS_KOSTENPLAATSGRP_KEY_URLLink = "prs_kostencombinatierecord.asp"
    fldPRS_KOSTENPLAATSGRP_KEY_PRS_KOSTENCOMBINATIE_KEY = GetValue(rs, "P_PRS_KOSTENCOMBINATIE_KEY")
    fldPRS_KOSTENPLAATSGRP_KEY = GetValue(rs, "P2_PRS_KOSTENPLAATSGRP_OMS")
    fldPRS_KOSTENSOORT_KEY_URLLink = "prs_kostencombinatierecord.asp"
    fldPRS_KOSTENSOORT_KEY_PRS_KOSTENCOMBINATIE_KEY = GetValue(rs, "P_PRS_KOSTENCOMBINATIE_KEY")
    fldPRS_KOSTENSOORT_KEY = GetValue(rs, "P1_PRS_KOSTENSOORT_OMS")
'-------------------------------
' KostencombinatieGrid Show begin
'-------------------------------

'-------------------------------
' KostencombinatieGrid Show Event begin
' KostencombinatieGrid Show Event end
'-------------------------------

'-------------------------------
' Replace Template fields with database values
'-------------------------------
    
      SetVar "PRS_KOSTENCOMBINATIE_KEY", ToHTML(fldPRS_KOSTENCOMBINATIE_KEY)
      SetVar "PRS_KOSTENSOORT_KEY", ToHTML(fldPRS_KOSTENSOORT_KEY)
      SetVar "PRS_KOSTENSOORT_KEY_URLLink", fldPRS_KOSTENSOORT_KEY_URLLink
      SetVar "PrmPRS_KOSTENSOORT_KEY_PRS_KOSTENCOMBINATIE_KEY", ToURL(fldPRS_KOSTENSOORT_KEY_PRS_KOSTENCOMBINATIE_KEY)
      SetVar "PRS_KOSTENPLAATSGRP_KEY", ToHTML(fldPRS_KOSTENPLAATSGRP_KEY)
      SetVar "PRS_KOSTENPLAATSGRP_KEY_URLLink", fldPRS_KOSTENPLAATSGRP_KEY_URLLink
      SetVar "PrmPRS_KOSTENPLAATSGRP_KEY_PRS_KOSTENCOMBINATIE_KEY", ToURL(fldPRS_KOSTENPLAATSGRP_KEY_PRS_KOSTENCOMBINATIE_KEY)
    Parse "DListKostencombinatieGrid", True

'-------------------------------
' KostencombinatieGrid Show end
'-------------------------------

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


'-------------------------------
' KostencombinatieGrid Navigation begin
'-------------------------------
  bEof = rs.eof
  if rs.eof and iPage = 1 then
	SetVar "KostencombinatieGridNavigator", ""
  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 "KostencombinatieGridNavigatorPages", true
      iDisplayPages = iDisplayPages + 1
    next
    SetVar "NavigatorPageSwitch", "_"
    SetVar "NavigatorPageNumber", iPage
    SetVar "NavigatorPageNumberView", iPage
    Parse "KostencombinatieGridNavigatorPages", true
    iDisplayPages = iDisplayPages + 1
    SetVar "NavigatorPageSwitch", ""
    iPageCount = iPage + 1
    while iDisplayPages < iNumberOfPages and iStartPage + iDisplayPages < iHasPages
      SetVar "NavigatorPageNumber", iPageCount
      SetVar "NavigatorPageNumberView", iPageCount
      Parse "KostencombinatieGridNavigatorPages", true
      iDisplayPages = iDisplayPages + 1
      iPageCount = iPageCount + 1
    wend
    if bEof then
      SetVar "KostencombinatieGridNavigatorLastPage", "_"
    else
      SetVar "NextPage", (iPage + 1)
    end if
    if iPage = 1 then
      SetVar "KostencombinatieGridNavigatorFirstPage", "_"
    else
      SetVar "PrevPage", (iPage - 1)
    end if
    SetVar "KostencombinatieGridCurrentPage", iPage
    Parse "KostencombinatieGridNavigator", False
  end if
'-------------------------------
' KostencombinatieGrid Navigation end
'-------------------------------

'-------------------------------
' Finish form processing
'-------------------------------
  set rs = nothing
  SetVar "KostencombinatieGridNoRecords", ""
  Parse "FormKostencombinatieGrid", False

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


'===============================
' Display Search Form
'-------------------------------
Sub KostencombinatieSearch_Show()
  Dim sFormTitle: sFormTitle = ""
  Dim sActionFileName: sActionFileName = "prs_kostencombinatiegrid.asp"
  Dim sPRS_KOSTENPLAATSGRP_KEYDisplayValue: sPRS_KOSTENPLAATSGRP_KEYDisplayValue = "Alles"

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

'-------------------------------
' Set variables with search parameters
'-------------------------------
      fldsPRS_KOSTENCOMBINATIE_OMSCHRIJVING = GetParam("sPRS_KOSTENCOMBINATIE_OMSCHRIJVING")
      fldPRS_KOSTENPLAATSGRP_KEY = GetParam("PRS_KOSTENPLAATSGRP_KEY")

'-------------------------------
' KostencombinatieSearch Show begin
'-------------------------------


'-------------------------------
' KostencombinatieSearch Show Event begin
' KostencombinatieSearch Show Event end
'-------------------------------
      SetVar "sPRS_KOSTENCOMBINATIE_OMSCHRIJVING", ToHTML(fldsPRS_KOSTENCOMBINATIE_OMSCHRIJVING)
      SetVar "KostencombinatieSearchLBPRS_KOSTENPLAATSGRP_KEY", ""
      SetVar "Selected", ""
      SetVar "ID", ""
      SetVar "Value", sPRS_KOSTENPLAATSGRP_KEYDisplayValue
      Parse "KostencombinatieSearchLBPRS_KOSTENPLAATSGRP_KEY", True
      openrs rsPRS_KOSTENPLAATSGRP_KEY, "select PRS_KOSTENPLAATSGRP_KEY, PRS_KOSTENPLAATSGRP_OMS from PRS_KOSTENPLAATSGRP order by 2"
      while not rsPRS_KOSTENPLAATSGRP_KEY.EOF
        SetVar "ID", GetValue(rsPRS_KOSTENPLAATSGRP_KEY, 0) : SetVar "Value", GetValue(rsPRS_KOSTENPLAATSGRP_KEY, 1)
        if cstr(GetValue(rsPRS_KOSTENPLAATSGRP_KEY, 0)) = cstr(fldPRS_KOSTENPLAATSGRP_KEY) then SetVar "Selected", "SELECTED" else SetVar "Selected", ""
        Parse "KostencombinatieSearchLBPRS_KOSTENPLAATSGRP_KEY", True
        rsPRS_KOSTENPLAATSGRP_KEY.MoveNext
      wend
      set rsPRS_KOSTENPLAATSGRP_KEY = nothing
    

'-------------------------------
' KostencombinatieSearch Show end
'-------------------------------

'-------------------------------
' KostencombinatieSearch Close Event begin
' KostencombinatieSearch Close Event end
'-------------------------------
      Parse "FormKostencombinatieSearch", False
End Sub
'===============================

%>