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

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


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


'===============================
' cad_legendawaardegrid PageSecurity begin
' cad_legendawaardegrid PageSecurity end
'===============================

'===============================
' cad_legendawaardegrid Open Event begin
' cad_legendawaardegrid Open Event end
'===============================

'===============================
' cad_legendawaardegrid OpenAnyPage Event begin
' cad_legendawaardegrid OpenAnyPage Event end
'===============================

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

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

' cad_legendawaardegrid Show end

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

' cad_legendawaardegrid Close Event begin
' cad_legendawaardegrid Close Event end

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

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

  SetVar "TransitParams", "CAD_LEGENDA_KEY=" & ToURL(GetParam("CAD_LEGENDA_KEY")) & "&sCAD_LEGENDAWAARDE_OMSCHR=" & ToURL(GetParam("sCAD_LEGENDAWAARDE_OMSCHR")) & "&"
  SetVar "FormParams", "CAD_LEGENDA_KEY=" & ToURL(GetParam("CAD_LEGENDA_KEY")) & "&sCAD_LEGENDAWAARDE_OMSCHR=" & ToURL(GetParam("sCAD_LEGENDAWAARDE_OMSCHR")) & "&"

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


  if HasParam then
    sWhere = " AND (" & sWhere & ")"
  end if
  
'-------------------------------
' Build ORDER BY statement
'-------------------------------
  sOrder = " order by C.CAD_LEGENDAWAARDE_VALUE Asc"
  iSort = GetParam("FormLegendaWaardes_Sorting")
  iSorted = GetParam("FormLegendaWaardes_Sorted")
  sDirection = ""
  if IsEmpty(iSort) then
    SetVar "Form_Sorting", ""
  else
    if iSort = iSorted then 
      SetVar "Form_Sorting", ""
      sDirection = " DESC"
      sSortParams = "FormLegendaWaardes_Sorting=" & iSort & "&FormLegendaWaardes_Sorted=" & iSort & "&"
    else
      SetVar "Form_Sorting", iSort
      sDirection = " ASC"
      sSortParams = "FormLegendaWaardes_Sorting=" & iSort & "&FormLegendaWaardes_Sorted=" & "&"
    end if
    if iSort = 1 then sOrder = " order by C.CAD_LEGENDAWAARDE_KEY" & sDirection
    if iSort = 2 then sOrder = " order by C1.CAD_LEGENDA_OMSCHRIJVING" & sDirection
    if iSort = 3 then sOrder = " order by C.CAD_LEGENDAWAARDE_VALUE" & sDirection
    if iSort = 4 then sOrder = " order by C.CAD_LEGENDAWAARDE_OMSCHR" & sDirection
    if iSort = 5 then sOrder = " order by C.CAD_LEGENDAWAARDE_RGB" & sDirection
  end if

'-------------------------------
' Build base SQL statement
'-------------------------------
  sSQL = "select C.CAD_LEGENDAWAARDE_KEY as C_CAD_LEGENDAWAARDE_KEY, " & _
    "C.CAD_LEGENDAWAARDE_OMSCHR as C_CAD_LEGENDAWAARDE_OMSCHR, " & _
    "C.CAD_LEGENDAWAARDE_RGB as C_CAD_LEGENDAWAARDE_RGB, " & _
    "C.CAD_LEGENDAWAARDE_VALUE as C_CAD_LEGENDAWAARDE_VALUE, " & _
    "C.CAD_LEGENDA_KEY as C_CAD_LEGENDA_KEY, " & _
    "C1.CAD_LEGENDA_KEY as C1_CAD_LEGENDA_KEY, " & _
    "C1.CAD_LEGENDA_OMSCHRIJVING as C1_CAD_LEGENDA_OMSCHRIJVING " & _
    " from CAD_LEGENDAWAARDE C, CAD_LEGENDA C1" & _
    " where C1.CAD_LEGENDA_KEY=C.CAD_LEGENDA_KEY  "
'-------------------------------

'-------------------------------
' LegendaWaardes Open Event begin
pCAD_LEGENDAWAARDE_OMSCHR = getParam("sCAD_LEGENDAWAARDE_OMSCHR")
if not isEmpty(pCAD_LEGENDAWAARDE_OMSCHR) then
  sWhere = sWhere & " AND Upper(CAD_LEGENDAWAARDE_OMSCHR) like '%" & UCase(replace(pCAD_LEGENDAWAARDE_OMSCHR,"'","''")) & "%'"
end if
' LegendaWaardes 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 "DListLegendaWaardes", ""
    Parse "LegendaWaardesNoRecords", False
    SetVar "LegendaWaardesNavigator", ""
    Parse "FormLegendaWaardes", False
    exit sub
  end if
'-------------------------------

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

'-------------------------------
' Process page scroller
'-------------------------------
  iPage = GetParam("FormLegendaWaardes_Page")
  openrs rsCount, sCountSQL
  dResult = CLng(rsCount.fields(0).value) / iRecordsPerPage
  iPageCount = int(dResult)
  if iPageCount < dResult then iPageCount = iPageCount + 1
  SetVar "LegendaWaardesPageCount", 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
'-------------------------------
    fldKleur_URLLink = "cad_legendawaarderecord.asp"
    fldKleur_CAD_LEGENDAWAARDE_KEY = GetValue(rs, "C_CAD_LEGENDAWAARDE_KEY")
    fldCAD_LEGENDA_KEY = GetValue(rs, "C1_CAD_LEGENDA_OMSCHRIJVING")
    fldCAD_LEGENDAWAARDE_KEY = GetValue(rs, "C_CAD_LEGENDAWAARDE_KEY")
    fldCAD_LEGENDAWAARDE_OMSCHR_URLLink = "cad_legendawaarderecord.asp"
    fldCAD_LEGENDAWAARDE_OMSCHR_CAD_LEGENDAWAARDE_KEY = GetValue(rs, "C_CAD_LEGENDAWAARDE_KEY")
    fldCAD_LEGENDAWAARDE_OMSCHR = GetValue(rs, "C_CAD_LEGENDAWAARDE_OMSCHR")
    fldCAD_LEGENDAWAARDE_RGB_URLLink = "cad_legendawaarderecord.asp"
    fldCAD_LEGENDAWAARDE_RGB_CAD_LEGENDAWAARDE_KEY = GetValue(rs, "C_CAD_LEGENDAWAARDE_KEY")
    fldCAD_LEGENDAWAARDE_RGB = GetValue(rs, "C_CAD_LEGENDAWAARDE_RGB")
    fldCAD_LEGENDAWAARDE_VALUE_URLLink = "cad_legendawaarderecord.asp"
    fldCAD_LEGENDAWAARDE_VALUE_CAD_LEGENDAWAARDE_KEY = GetValue(rs, "C_CAD_LEGENDAWAARDE_KEY")
    fldCAD_LEGENDAWAARDE_VALUE = GetValue(rs, "C_CAD_LEGENDAWAARDE_VALUE")
'-------------------------------
' LegendaWaardes Show begin
'-------------------------------

'-------------------------------
' LegendaWaardes Show Event begin
fldKleur = "<span style=""border:1px;width:16px;display: inline-block;background-color:#" & Trim(fldCAD_LEGENDAWAARDE_RGB) & """>&nbsp;</span>"
' LegendaWaardes Show Event end
'-------------------------------

'-------------------------------
' Replace Template fields with database values
'-------------------------------
    
      SetVar "CAD_LEGENDAWAARDE_KEY", ToHTML(fldCAD_LEGENDAWAARDE_KEY)
      SetVar "CAD_LEGENDA_KEY", ToHTML(fldCAD_LEGENDA_KEY)
      SetVar "CAD_LEGENDAWAARDE_VALUE", ToHTML(fldCAD_LEGENDAWAARDE_VALUE)
      SetVar "CAD_LEGENDAWAARDE_VALUE_URLLink", fldCAD_LEGENDAWAARDE_VALUE_URLLink
      SetVar "PrmCAD_LEGENDAWAARDE_VALUE_CAD_LEGENDAWAARDE_KEY", ToURL(fldCAD_LEGENDAWAARDE_VALUE_CAD_LEGENDAWAARDE_KEY)
      SetVar "CAD_LEGENDAWAARDE_OMSCHR", ToHTML(fldCAD_LEGENDAWAARDE_OMSCHR)
      SetVar "CAD_LEGENDAWAARDE_OMSCHR_URLLink", fldCAD_LEGENDAWAARDE_OMSCHR_URLLink
      SetVar "PrmCAD_LEGENDAWAARDE_OMSCHR_CAD_LEGENDAWAARDE_KEY", ToURL(fldCAD_LEGENDAWAARDE_OMSCHR_CAD_LEGENDAWAARDE_KEY)
      SetVar "Kleur", fldKleur
      SetVar "Kleur_URLLink", fldKleur_URLLink
      SetVar "PrmKleur_CAD_LEGENDAWAARDE_KEY", ToURL(fldKleur_CAD_LEGENDAWAARDE_KEY)
      SetVar "CAD_LEGENDAWAARDE_RGB", ToHTML(fldCAD_LEGENDAWAARDE_RGB)
      SetVar "CAD_LEGENDAWAARDE_RGB_URLLink", fldCAD_LEGENDAWAARDE_RGB_URLLink
      SetVar "PrmCAD_LEGENDAWAARDE_RGB_CAD_LEGENDAWAARDE_KEY", ToURL(fldCAD_LEGENDAWAARDE_RGB_CAD_LEGENDAWAARDE_KEY)
    Parse "DListLegendaWaardes", True

'-------------------------------
' LegendaWaardes Show end
'-------------------------------

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


'-------------------------------
' LegendaWaardes Navigation begin
'-------------------------------
  bEof = rs.eof
  if rs.eof and iPage = 1 then
	SetVar "LegendaWaardesNavigator", ""
  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 "LegendaWaardesNavigatorPages", true
      iDisplayPages = iDisplayPages + 1
    next
    SetVar "NavigatorPageSwitch", "_"
    SetVar "NavigatorPageNumber", iPage
    SetVar "NavigatorPageNumberView", iPage
    Parse "LegendaWaardesNavigatorPages", true
    iDisplayPages = iDisplayPages + 1
    SetVar "NavigatorPageSwitch", ""
    iPageCount = iPage + 1
    while iDisplayPages < iNumberOfPages and iStartPage + iDisplayPages < iHasPages
      SetVar "NavigatorPageNumber", iPageCount
      SetVar "NavigatorPageNumberView", iPageCount
      Parse "LegendaWaardesNavigatorPages", true
      iDisplayPages = iDisplayPages + 1
      iPageCount = iPageCount + 1
    wend
    if bEof then
      SetVar "LegendaWaardesNavigatorLastPage", "_"
    else
      SetVar "NextPage", (iPage + 1)
    end if
    if iPage = 1 then
      SetVar "LegendaWaardesNavigatorFirstPage", "_"
    else
      SetVar "PrevPage", (iPage - 1)
    end if
    SetVar "LegendaWaardesCurrentPage", iPage
    Parse "LegendaWaardesNavigator", False
  end if
'-------------------------------
' LegendaWaardes Navigation end
'-------------------------------

'-------------------------------
' Finish form processing
'-------------------------------
  set rs = nothing
  SetVar "LegendaWaardesNoRecords", ""
  Parse "FormLegendaWaardes", False

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


'===============================
' Display Search Form
'-------------------------------
Sub LegendaSearch_Show()
  Dim sFormTitle: sFormTitle = ""
  Dim sActionFileName: sActionFileName = "cad_legendawaardegrid.asp"
  Dim sCAD_LEGENDA_KEYDisplayValue: sCAD_LEGENDA_KEYDisplayValue = ""

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

'-------------------------------
' Set variables with search parameters
'-------------------------------
      fldCAD_LEGENDA_KEY = GetParam("CAD_LEGENDA_KEY")
      fldsCAD_LEGENDAWAARDE_OMSCHR = GetParam("sCAD_LEGENDAWAARDE_OMSCHR")

'-------------------------------
' LegendaSearch Show begin
'-------------------------------


'-------------------------------
' LegendaSearch Show Event begin
' LegendaSearch Show Event end
'-------------------------------
      SetVar "LegendaSearchLBCAD_LEGENDA_KEY", ""
      SetVar "Selected", ""
      SetVar "ID", ""
      SetVar "Value", sCAD_LEGENDA_KEYDisplayValue
      Parse "LegendaSearchLBCAD_LEGENDA_KEY", True
      openrs rsCAD_LEGENDA_KEY, "select CAD_LEGENDA_KEY, CAD_LEGENDA_OMSCHRIJVING from CAD_LEGENDA order by 2"
      while not rsCAD_LEGENDA_KEY.EOF
        SetVar "ID", GetValue(rsCAD_LEGENDA_KEY, 0) : SetVar "Value", GetValue(rsCAD_LEGENDA_KEY, 1)
        if cstr(GetValue(rsCAD_LEGENDA_KEY, 0)) = cstr(fldCAD_LEGENDA_KEY) then SetVar "Selected", "SELECTED" else SetVar "Selected", ""
        Parse "LegendaSearchLBCAD_LEGENDA_KEY", True
        rsCAD_LEGENDA_KEY.MoveNext
      wend
      set rsCAD_LEGENDA_KEY = nothing
    
      SetVar "sCAD_LEGENDAWAARDE_OMSCHR", ToHTML(fldsCAD_LEGENDAWAARDE_OMSCHR)

'-------------------------------
' LegendaSearch Show end
'-------------------------------

'-------------------------------
' LegendaSearch Close Event begin
' LegendaSearch Close Event end
'-------------------------------
      Parse "FormLegendaSearch", False
End Sub
'===============================

%>