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

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


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


'===============================
' mld_kostengrid PageSecurity begin
' mld_kostengrid PageSecurity end
'===============================

'===============================
' mld_kostengrid Open Event begin
' mld_kostengrid Open Event end
'===============================

'===============================
' mld_kostengrid OpenAnyPage Event begin
' mld_kostengrid OpenAnyPage Event end
'===============================

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

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

' mld_kostengrid Show end

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

' mld_kostengrid Close Event begin
' mld_kostengrid Close Event end

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

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

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


  sWhere = " WHERE MLD_KOSTEN_VERWIJDER IS NULL"
  
'-------------------------------
' Build ORDER BY statement
'-------------------------------
  sOrder = " order by M.MLD_KOSTEN_KEY Asc"
  iSort = GetParam("FormKostenGrid_Sorting")
  iSorted = GetParam("FormKostenGrid_Sorted")
  sDirection = ""
  if IsEmpty(iSort) then
    SetVar "Form_Sorting", ""
  else
    if iSort = iSorted then 
      SetVar "Form_Sorting", ""
      sDirection = " DESC"
      sSortParams = "FormKostenGrid_Sorting=" & iSort & "&FormKostenGrid_Sorted=" & iSort & "&"
    else
      SetVar "Form_Sorting", iSort
      sDirection = " ASC"
      sSortParams = "FormKostenGrid_Sorting=" & iSort & "&FormKostenGrid_Sorted=" & "&"
    end if
    if iSort = 1 then sOrder = " order by M.MLD_KOSTEN_KEY" & sDirection
    if iSort = 2 then sOrder = " order by M.MLD_KOSTEN_CODE" & sDirection
    if iSort = 3 then sOrder = " order by M.MLD_KOSTEN_OMSCHRIJVING" & sDirection
    if iSort = 4 then sOrder = " order by M.MLD_KOSTEN_TYPE" & sDirection
    if iSort = 5 then sOrder = " order by M.MLD_KOSTEN_EENHEID" & sDirection
    if iSort = 6 then sOrder = " order by M.MLD_KOSTEN_KOSTEN" & sDirection
  end if

'-------------------------------
' Build base SQL statement
'-------------------------------
  sSQL = "select M.MLD_KOSTEN_CODE as M_MLD_KOSTEN_CODE, " & _
    "M.MLD_KOSTEN_EENHEID as M_MLD_KOSTEN_EENHEID, " & _
    "M.MLD_KOSTEN_KEY as M_MLD_KOSTEN_KEY, " & _
    "M.MLD_KOSTEN_KOSTEN as M_MLD_KOSTEN_KOSTEN, " & _
    "M.MLD_KOSTEN_OMSCHRIJVING as M_MLD_KOSTEN_OMSCHRIJVING, " & _
    "M.MLD_KOSTEN_TYPE as M_MLD_KOSTEN_TYPE " & _
    " from MLD_KOSTEN M "
'-------------------------------

'-------------------------------
' KostenGrid Open Event begin
' KostenGrid 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 "DListKostenGrid", ""
    Parse "KostenGridNoRecords", False
    SetVar "KostenGridNavigator", ""
    Parse "FormKostenGrid", False
    exit sub
  end if
'-------------------------------

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

  aMLD_KOSTEN_TYPE = Split(""&FCLTLCL("1;Vinkje;2;Hoeveelheid")&"", ";")
'-------------------------------
'-------------------------------
' Initialize page counter and records per page
'-------------------------------
  iRecordsPerPage = 25
  iCounter = 0
'-------------------------------

'-------------------------------
' Process page scroller
'-------------------------------
  iPage = GetParam("FormKostenGrid_Page")
  openrs rsCount, sCountSQL
  dResult = CLng(rsCount.fields(0).value) / iRecordsPerPage
  iPageCount = int(dResult)
  if iPageCount < dResult then iPageCount = iPageCount + 1
  SetVar "KostenGridPageCount", 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
'-------------------------------
    fldMLD_KOSTEN_CODE_URLLink = "mld_kostenrecord.asp"
    fldMLD_KOSTEN_CODE_MLD_KOSTEN_KEY = GetValue(rs, "M_MLD_KOSTEN_KEY")
    fldMLD_KOSTEN_CODE = GetValue(rs, "M_MLD_KOSTEN_CODE")
    fldMLD_KOSTEN_EENHEID = GetValue(rs, "M_MLD_KOSTEN_EENHEID")
    fldMLD_KOSTEN_KEY_URLLink = "mld_kostenrecord.asp"
    fldMLD_KOSTEN_KEY_MLD_KOSTEN_KEY = GetValue(rs, "M_MLD_KOSTEN_KEY")
    fldMLD_KOSTEN_KEY = GetValue(rs, "M_MLD_KOSTEN_KEY")
    fldMLD_KOSTEN_KOSTEN = GetValue(rs, "M_MLD_KOSTEN_KOSTEN")
    fldMLD_KOSTEN_OMSCHRIJVING_URLLink = "mld_kostenrecord.asp"
    fldMLD_KOSTEN_OMSCHRIJVING_MLD_KOSTEN_KEY = GetValue(rs, "M_MLD_KOSTEN_KEY")
    fldMLD_KOSTEN_OMSCHRIJVING = GetValue(rs, "M_MLD_KOSTEN_OMSCHRIJVING")
    fldMLD_KOSTEN_TYPE = GetValue(rs, "M_MLD_KOSTEN_TYPE")
'-------------------------------
' KostenGrid Show begin
'-------------------------------

'-------------------------------
' KostenGrid Show Event begin
' KostenGrid Show Event end
'-------------------------------

'-------------------------------
' Replace Template fields with database values
'-------------------------------
    
      SetVar "MLD_KOSTEN_KEY", ToHTML(fldMLD_KOSTEN_KEY)
      SetVar "MLD_KOSTEN_KEY_URLLink", fldMLD_KOSTEN_KEY_URLLink
      SetVar "PrmMLD_KOSTEN_KEY_MLD_KOSTEN_KEY", ToURL(fldMLD_KOSTEN_KEY_MLD_KOSTEN_KEY)
      SetVar "MLD_KOSTEN_CODE", ToHTML(fldMLD_KOSTEN_CODE)
      SetVar "MLD_KOSTEN_CODE_URLLink", fldMLD_KOSTEN_CODE_URLLink
      SetVar "PrmMLD_KOSTEN_CODE_MLD_KOSTEN_KEY", ToURL(fldMLD_KOSTEN_CODE_MLD_KOSTEN_KEY)
      SetVar "MLD_KOSTEN_OMSCHRIJVING", ToHTML(fldMLD_KOSTEN_OMSCHRIJVING)
      SetVar "MLD_KOSTEN_OMSCHRIJVING_URLLink", fldMLD_KOSTEN_OMSCHRIJVING_URLLink
      SetVar "PrmMLD_KOSTEN_OMSCHRIJVING_MLD_KOSTEN_KEY", ToURL(fldMLD_KOSTEN_OMSCHRIJVING_MLD_KOSTEN_KEY)
      fldMLD_KOSTEN_TYPE = getValFromLOV(fldMLD_KOSTEN_TYPE, aMLD_KOSTEN_TYPE)
      SetVar "MLD_KOSTEN_TYPE", ToHTML(fldMLD_KOSTEN_TYPE)
      SetVar "MLD_KOSTEN_EENHEID", ToHTML(fldMLD_KOSTEN_EENHEID)
      SetVar "MLD_KOSTEN_KOSTEN", ToHTML(fldMLD_KOSTEN_KOSTEN)
    Parse "DListKostenGrid", True

'-------------------------------
' KostenGrid Show end
'-------------------------------

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


'-------------------------------
' KostenGrid Navigation begin
'-------------------------------
  bEof = rs.eof
  if rs.eof and iPage = 1 then
	SetVar "KostenGridNavigator", ""
  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 "KostenGridNavigatorPages", true
      iDisplayPages = iDisplayPages + 1
    next
    SetVar "NavigatorPageSwitch", "_"
    SetVar "NavigatorPageNumber", iPage
    SetVar "NavigatorPageNumberView", iPage
    Parse "KostenGridNavigatorPages", true
    iDisplayPages = iDisplayPages + 1
    SetVar "NavigatorPageSwitch", ""
    iPageCount = iPage + 1
    while iDisplayPages < iNumberOfPages and iStartPage + iDisplayPages < iHasPages
      SetVar "NavigatorPageNumber", iPageCount
      SetVar "NavigatorPageNumberView", iPageCount
      Parse "KostenGridNavigatorPages", true
      iDisplayPages = iDisplayPages + 1
      iPageCount = iPageCount + 1
    wend
    if bEof then
      SetVar "KostenGridNavigatorLastPage", "_"
    else
      SetVar "NextPage", (iPage + 1)
    end if
    if iPage = 1 then
      SetVar "KostenGridNavigatorFirstPage", "_"
    else
      SetVar "PrevPage", (iPage - 1)
    end if
    SetVar "KostenGridCurrentPage", iPage
    Parse "KostenGridNavigator", False
  end if
'-------------------------------
' KostenGrid Navigation end
'-------------------------------

'-------------------------------
' Finish form processing
'-------------------------------
  set rs = nothing
  SetVar "KostenGridNoRecords", ""
  Parse "FormKostenGrid", False

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

%>