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

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


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


'===============================
' fac_usrtabrecord1 PageSecurity begin
' fac_usrtabrecord1 PageSecurity end
'===============================

'===============================
' fac_usrtabrecord1 Open Event begin
' fac_usrtabrecord1 Open Event end
'===============================

'===============================
' fac_usrtabrecord1 OpenAnyPage Event begin
' fac_usrtabrecord1 OpenAnyPage Event end
'===============================

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

' fac_usrtabrecord1 Show begin
'===============================
' Perform the form's action
'-------------------------------
' Initialize error variables
'-------------------------------
sUserTabRecordErr = ""

'-------------------------------
' Select the FormAction
'-------------------------------
Select Case sForm
  Case "UserTabRecord"
    UserTabRecordAction(sAction)
end select
'===============================

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

' fac_usrtabrecord1 Show end

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

' fac_usrtabrecord1 Close Event begin
' fac_usrtabrecord1 Close Event end

cn.Close
Set cn = Nothing
UnloadTemplate
'===============================
'===============================
' Action of the Record Form
'-------------------------------
Sub UserTabRecordAction(sAction)
'-------------------------------
' Initialize variables  
'-------------------------------
  Dim bExecSQL: bExecSQL = true
  Dim sActionFileName : sActionFileName = ""
  Dim sParams : sParams = "?"
  Dim sWhere : sWhere = "" 
  Dim bErr : bErr = False
  Dim pPKFAC_USRTAB_KEY : pPKFAC_USRTAB_KEY = ""
  Dim fldFAC_USRTAB_NAAM : fldFAC_USRTAB_NAAM = ""
  Dim fldFAC_USRTAB_OMSCHRIJVING : fldFAC_USRTAB_OMSCHRIJVING = ""
  Dim fldField1 : fldField1 = ""
  Dim fldField2 : fldField2 = ""
  Dim fldFAC_USRTAB_OBJECT : fldFAC_USRTAB_OBJECT = ""
  Dim fldFAC_USRTAB_PARENTKEY : fldFAC_USRTAB_PARENTKEY = ""
'-------------------------------

'-------------------------------
' UserTabRecord Action begin
'-------------------------------
  sActionFileName = "fac_usrtabgrid.asp"
  sParams = sParams & "sFAC_USRTAB_OMSCHRIJVING=" & ToURL(GetParam("Trn_sFAC_USRTAB_OMSCHRIJVING"))

'-------------------------------
' CANCEL action
'-------------------------------
  if sAction = "cancel" then

'-------------------------------
' UserTabRecord BeforeCancel Event begin
' UserTabRecord BeforeCancel Event end
'-------------------------------
    cn.Close
    Set cn = Nothing
    response.redirect sActionFileName & sParams
  end if
'-------------------------------

'-------------------------------
' Build WHERE statement
'-------------------------------
  if sAction = "update" or sAction = "delete" then
    pPKFAC_USRTAB_KEY = GetParam("PK_FAC_USRTAB_KEY")
    if IsEmpty(pPKFAC_USRTAB_KEY) then exit sub
    sWhere = "FAC_USRTAB_KEY=" & ToSQL(pPKFAC_USRTAB_KEY, "Number")
  end if
'-------------------------------


'-------------------------------
' Load all form fields into variables
'-------------------------------
  fldFAC_USRTAB_NAAM = GetParam("FAC_USRTAB_NAAM")
  fldFAC_USRTAB_OMSCHRIJVING = GetParam("FAC_USRTAB_OMSCHRIJVING")
  fldField1 = GetParam("Field1")
  fldField2 = GetParam("Field2")
  fldFAC_USRTAB_OBJECT = GetParam("FAC_USRTAB_OBJECT")
  fldFAC_USRTAB_PARENTKEY = GetParam("FAC_USRTAB_PARENTKEY")

'-------------------------------
' Validate fields
'-------------------------------
  if sAction = "insert" or sAction = "update" then
    if IsEmpty(fldFAC_USRTAB_NAAM) then
      sUserTabRecordErr = sUserTabRecordErr & "De waarde in veld Tabelnaam is verplicht.<br>"
    end if
    if not isNumeric(fldFAC_USRTAB_PARENTKEY) then
      sUserTabRecordErr = sUserTabRecordErr & "De waarde in veld Waarde uit tabel is niet correct.<br>"
    end if
'-------------------------------
' UserTabRecord Check Event begin
' UserTabRecord Check Event end
'-------------------------------
    If len(sUserTabRecordErr) > 0 then
      exit sub
    end if
  end if
'-------------------------------


'-------------------------------
' Create SQL statement
'-------------------------------
  select case sAction
    case "insert"
'-------------------------------
' UserTabRecord Insert Event begin
' UserTabRecord Insert Event end
'-------------------------------
      sSQL = "insert into FAC_USRTAB (" & _
          "FAC_USRTAB_NAAM," & _
          "FAC_USRTAB_OMSCHRIJVING," & _
          "FAC_USRTAB_OBJECT," & _
          "FAC_USRTAB_PARENTKEY)" & _
          " values (" & _
          ToSQL(fldFAC_USRTAB_NAAM, "Text") & "," & _
          ToSQL(fldFAC_USRTAB_OMSCHRIJVING, "Text") & "," & _
          ToSQL(fldFAC_USRTAB_OBJECT, "Text") & "," & _
          ToSQL(fldFAC_USRTAB_PARENTKEY, "Number") & _
          ")"
    case "update"
'-------------------------------
' UserTabRecord Update Event begin
' UserTabRecord Update Event end
'-------------------------------
      sSQL = "update FAC_USRTAB set " & _
        "FAC_USRTAB_NAAM=" & ToSQL(fldFAC_USRTAB_NAAM, "Text") & _
        ",FAC_USRTAB_OMSCHRIJVING=" & ToSQL(fldFAC_USRTAB_OMSCHRIJVING, "Text") & _
        ",FAC_USRTAB_OBJECT=" & ToSQL(fldFAC_USRTAB_OBJECT, "Text") & _
        ",FAC_USRTAB_PARENTKEY=" & ToSQL(fldFAC_USRTAB_PARENTKEY, "Number")
      sSQL = sSQL & " where " & sWhere
    case "delete"
'-------------------------------
' UserTabRecord Delete Event begin
sSql = "update fac_usrtab "&_
       "set fac_usrtab_verwijder = sysdate "&_
       "where fac_usrtab_key="&pPKFAC_USRTAB_KEY
' UserTabRecord Delete Event end
'-------------------------------
      if sSQL = "" then
      sSQL = "delete from FAC_USRTAB where " & sWhere
      end if
  end select
'-------------------------------
'-------------------------------
' UserTabRecord BeforeExecute Event begin
' UserTabRecord BeforeExecute Event end
'-------------------------------

'-------------------------------
' Execute SQL statement
'-------------------------------
if len(sUserTabRecordErr) > 0 then Exit Sub
  on error resume next
  if bExecSQL then 
    cn.execute sSQL
  end if
  sUserTabRecordErr = ProcessError
  on error goto 0
  if len(sUserTabRecordErr) > 0 then Exit Sub
  cn.Close
  Set cn = Nothing
  response.redirect sActionFileName & sParams
'-------------------------------
' UserTabRecord Action end
'-------------------------------
end sub
'===============================

'===============================
' Display Record Form
'-------------------------------
Sub UserTabRecord_Show()
'-------------------------------
' UserTabRecord Show begin
'-------------------------------
  Dim sWhere : sWhere = ""
  Dim sFormTitle: sFormTitle = "Details eigen tabel"
  Dim bPK : bPK = True
  Dim sFAC_USRTAB_PARENTKEYDisplayValue: sFAC_USRTAB_PARENTKEYDisplayValue = ""

'-------------------------------
' Load primary key and form parameters
'-------------------------------
  if sUserTabRecordErr = "" then
    SetVar "Trn_sFAC_USRTAB_OMSCHRIJVING", GetParam("sFAC_USRTAB_OMSCHRIJVING")
    pFAC_USRTAB_KEY = GetParam("FAC_USRTAB_KEY")
    SetVar "UserTabRecordError", ""
  else
    fldFAC_USRTAB_NAAM = GetParam("FAC_USRTAB_NAAM")
    fldFAC_USRTAB_OMSCHRIJVING = GetParam("FAC_USRTAB_OMSCHRIJVING")
    fldFAC_USRTAB_OBJECT = GetParam("FAC_USRTAB_OBJECT")
    fldFAC_USRTAB_PARENTKEY = GetParam("FAC_USRTAB_PARENTKEY")
    SetVar "Trn_sFAC_USRTAB_OMSCHRIJVING", GetParam("Trn_sFAC_USRTAB_OMSCHRIJVING")
    pFAC_USRTAB_KEY = GetParam("PK_FAC_USRTAB_KEY")
    SetVar "sUserTabRecordErr", sUserTabRecordErr
    SetVar "FormTitle", sFormTitle
    Parse "UserTabRecordError", False
  end if
'-------------------------------

'-------------------------------
' Load all form fields

  fldField1 = GetParam("Field1")
  fldField2 = GetParam("Field2")
'-------------------------------

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

  if IsEmpty(pFAC_USRTAB_KEY) then bPK = False
  
  sWhere = sWhere & "FAC_USRTAB_KEY=" & ToSQL(pFAC_USRTAB_KEY, "Number")
  SetVar "PK_FAC_USRTAB_KEY", pFAC_USRTAB_KEY
'-------------------------------
'-------------------------------
' UserTabRecord Open Event begin
' UserTabRecord Open Event end
'-------------------------------

  SetVar "FormTitle", sFormTitle

'-------------------------------
' Build SQL statement and open recordset
'-------------------------------
  sSQL = "select * from FAC_USRTAB where " & sWhere
  openrs rs, sSQL
  bIsUpdateMode = (bPK and not(sAction = "insert" and sForm = "UserTabRecord") and not rs.eof)
'-------------------------------

'-------------------------------
' Load all fields into variables from recordset or input parameters
'-------------------------------
  if bIsUpdateMode then
    fldFAC_USRTAB_KEY = GetValue(rs, "FAC_USRTAB_KEY")
    fldFAC_USRTAB_OBJECT = GetValue(rs, "FAC_USRTAB_OBJECT")

'-------------------------------
' Load data from recordset when form displayed first time
'-------------------------------
    if sUserTabRecordErr = "" then
      fldFAC_USRTAB_NAAM = GetValue(rs, "FAC_USRTAB_NAAM")
      fldFAC_USRTAB_OMSCHRIJVING = GetValue(rs, "FAC_USRTAB_OMSCHRIJVING")
      fldFAC_USRTAB_PARENTKEY = GetValue(rs, "FAC_USRTAB_PARENTKEY")
    end if
    SetVar "UserTabRecordInsert", ""
    Parse "UserTabRecordEdit", False
'-------------------------------
' UserTabRecord ShowEdit Event begin
' UserTabRecord ShowEdit Event end
'-------------------------------
  else
    if sUserTabRecordErr = "" then
      fldField1= "Als voor Type View gekozen is kan hier de SQL tekst worden ingevuld waarmee de View zal worden aangemaakt. De eerste regel, 'CREATE VIEW USR_naam AS', zal automatisch ingevoegd worden."
      fldField2= "De definitie van de view moet geldig zijn volgens de Oracle SQL-Plus standaard. Er moet minimaal 1 sleutel-veld en 1 waardeveld worden opgenomen in het select-statement."
    end if
    SetVar "UserTabRecordEdit", ""
    Parse "UserTabRecordInsert", False
'-------------------------------
' UserTabRecord ShowInsert Event begin
' UserTabRecord ShowInsert Event end
'-------------------------------
  end if
  Parse "UserTabRecordCancel", false

'-------------------------------
' Set default values
'-------------------------------
  fldField1= "Als voor Type View gekozen is kan hier de SQL tekst worden ingevuld waarmee de View zal worden aangemaakt. De eerste regel, 'CREATE VIEW USR_naam AS', zal automatisch ingevoegd worden."
  fldField2= "De definitie van de view moet geldig zijn volgens de Oracle SQL-Plus standaard. Er moet minimaal 1 sleutel-veld en 1 waardeveld worden opgenomen in het select-statement."
'-------------------------------
' UserTabRecord Show Event begin
' UserTabRecord Show Event end
'-------------------------------

'-------------------------------
' Show form field
'-------------------------------
      SetVar "FAC_USRTAB_KEY", ToHTML(fldFAC_USRTAB_KEY)
      SetVar "FAC_USRTAB_NAAM", ToHTML(fldFAC_USRTAB_NAAM)
      SetVar "FAC_USRTAB_OMSCHRIJVING", ToHTML(fldFAC_USRTAB_OMSCHRIJVING)
      SetVar "Field1", ToHTML(fldField1)
      SetVar "Field2", ToHTML(fldField2)
      SetVar "FAC_USRTAB_OBJECT", ToHTML(fldFAC_USRTAB_OBJECT)
      SetVar "UserTabRecordLBFAC_USRTAB_PARENTKEY", ""
      SetVar "Selected", ""
      SetVar "ID", ""
      SetVar "Value", sFAC_USRTAB_PARENTKEYDisplayValue
      Parse "UserTabRecordLBFAC_USRTAB_PARENTKEY", True
      openrs rsFAC_USRTAB_PARENTKEY, "SELECT fac_usrtab_key , fac_usrtab_naam FROM fac_usrtab WHERE fac_usrtab_key <> nvl(" & ToSQL(fldFAC_USRTAB_KEY, "Number") & ",0) ORDER BY fac_usrtab_naam"
      while not rsFAC_USRTAB_PARENTKEY.EOF
        SetVar "ID", GetValue(rsFAC_USRTAB_PARENTKEY, 0) : SetVar "Value", GetValue(rsFAC_USRTAB_PARENTKEY, 1)
        if cstr(GetValue(rsFAC_USRTAB_PARENTKEY, 0)) = cstr(fldFAC_USRTAB_PARENTKEY) then SetVar "Selected", "SELECTED" else SetVar "Selected", ""
        Parse "UserTabRecordLBFAC_USRTAB_PARENTKEY", True
        rsFAC_USRTAB_PARENTKEY.MoveNext
      wend
      set rsFAC_USRTAB_PARENTKEY = nothing
    
  Parse "FormUserTabRecord", False

'-------------------------------
' UserTabRecord Close Event begin
' UserTabRecord Close Event end
'-------------------------------

Set rs = Nothing

'-------------------------------
' UserTabRecord Show end
'-------------------------------
End Sub
'===============================

'===============================
' Display Grid Form
'-------------------------------
Sub fac_usrtab_datagrid_Show()
'-------------------------------
' Initialize variables  
'-------------------------------
  Dim rs
  Dim sWhere : sWhere = ""
  Dim sOrder : sOrder = ""
  Dim sSQL : sSQL = ""
  Dim sFormTitle: sFormTitle = "Waarden bij eigen tabel"
  Dim HasParam : HasParam = false
  Dim bReq : bReq = true
  Dim iSort : iSort = ""
  Dim iSorted : iSorted = ""
  Dim sDirection : sDirection = ""
  Dim sSortParams : sSortParams = ""
  Dim iRecordsPerPage : iRecordsPerPage = 20
  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 = "fac_usrdatarecord1.asp"

  SetVar "TransitParams", "FAC_USRDATA_PARENTKEY=" & ToURL(GetParam("FAC_USRDATA_PARENTKEY")) & "&FAC_USRTAB_KEY=" & ToURL(GetParam("FAC_USRTAB_KEY")) & "&sFAC_USRTAB_OMSCHRIJVING=" & ToURL(GetParam("sFAC_USRTAB_OMSCHRIJVING")) & "&"
  SetVar "FormParams", "FAC_USRDATA_PARENTKEY=" & ToURL(GetParam("FAC_USRDATA_PARENTKEY")) & "&FAC_USRTAB_KEY=" & ToURL(GetParam("FAC_USRTAB_KEY")) & "&sFAC_USRTAB_OMSCHRIJVING=" & ToURL(GetParam("sFAC_USRTAB_OMSCHRIJVING")) & "&"

'-------------------------------
' Build WHERE statement
'-------------------------------
  pFAC_USRDATA_PARENTKEY = GetParam("FAC_USRDATA_PARENTKEY")
  if IsNumeric(pFAC_USRDATA_PARENTKEY) and not isEmpty(pFAC_USRDATA_PARENTKEY) then pFAC_USRDATA_PARENTKEY = ToSQL(pFAC_USRDATA_PARENTKEY, "Number") else pFAC_USRDATA_PARENTKEY = Empty
  if not isEmpty(pFAC_USRDATA_PARENTKEY) then
    HasParam = true
    sWhere = sWhere & "F.FAC_USRDATA_PARENTKEY=" & pFAC_USRDATA_PARENTKEY
  end if
  pFAC_USRTAB_KEY = GetParam("FAC_USRTAB_KEY")
  if IsNumeric(pFAC_USRTAB_KEY) and not isEmpty(pFAC_USRTAB_KEY) then pFAC_USRTAB_KEY = ToSQL(pFAC_USRTAB_KEY, "Number") else pFAC_USRTAB_KEY = Empty
  if not isEmpty(pFAC_USRTAB_KEY) then
    if not (sWhere = "") then sWhere = sWhere & " and "
    HasParam = true
    sWhere = sWhere & "F.FAC_USRTAB_KEY=" & pFAC_USRTAB_KEY
  else
    bReq = false
  end if


  if HasParam then
    sWhere = " WHERE (" & sWhere & ")"
  end if
  
'-------------------------------
' Build ORDER BY statement
'-------------------------------
  iSort = GetParam("Formfac_usrtab_datagrid_Sorting")
  iSorted = GetParam("Formfac_usrtab_datagrid_Sorted")
  sDirection = ""
  if IsEmpty(iSort) then
    SetVar "Form_Sorting", ""
  else
    if iSort = iSorted then 
      SetVar "Form_Sorting", ""
      sDirection = " DESC"
      sSortParams = "Formfac_usrtab_datagrid_Sorting=" & iSort & "&Formfac_usrtab_datagrid_Sorted=" & iSort & "&"
    else
      SetVar "Form_Sorting", iSort
      sDirection = " ASC"
      sSortParams = "Formfac_usrtab_datagrid_Sorting=" & iSort & "&Formfac_usrtab_datagrid_Sorted=" & "&"
    end if
    if iSort = 1 then sOrder = " order by F.FAC_USRDATA_KEY" & sDirection
    if iSort = 2 then sOrder = " order by F.FAC_USRDATA_OMSCHR" & sDirection
    if iSort = 3 then sOrder = " order by F.FAC_USRDATA_CODE" & sDirection
    if iSort = 4 then sOrder = " order by F.FAC_USRDATA_VOLGNR" & sDirection
    if iSort = 5 then sOrder = " order by F.FAC_USRDATA_PRIJS" & sDirection
    if iSort = 6 then sOrder = " order by F.FAC_USRDATA_VERVALDATUM" & sDirection
  end if

'-------------------------------
' Build base SQL statement
'-------------------------------
  sSQL = "select F.FAC_USRDATA_CODE as F_FAC_USRDATA_CODE, " & _
    "F.FAC_USRDATA_KEY as F_FAC_USRDATA_KEY, " & _
    "F.FAC_USRDATA_OMSCHR as F_FAC_USRDATA_OMSCHR, " & _
    "F.FAC_USRDATA_PARENTKEY as F_FAC_USRDATA_PARENTKEY, " & _
    "F.FAC_USRDATA_PRIJS as F_FAC_USRDATA_PRIJS, " & _
    "F.FAC_USRDATA_VERVALDATUM as F_FAC_USRDATA_VERVALDATUM, " & _
    "F.FAC_USRDATA_VOLGNR as F_FAC_USRDATA_VOLGNR, " & _
    "F.FAC_USRTAB_KEY as F_FAC_USRTAB_KEY " & _
    " from FAC_V_AANWEZIGUSRDATA F "
'-------------------------------

'-------------------------------
' fac_usrtab_datagrid Open Event begin
' fac_usrtab_datagrid 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
'-------------------------------

'-------------------------------
' Process if form has all required parameter
'-------------------------------
  if not bReq then
    SetVar "DListfac_usrtab_datagrid", ""
    Parse "fac_usrtab_datagridNoRecords", False
    SetVar "fac_usrtab_datagridNavigator", ""
    Parse "Formfac_usrtab_datagrid", False
    exit sub
  end if
'-------------------------------

'-------------------------------
' Open the recordset
'-------------------------------
  openrs rs, sSQL
'-------------------------------

'-------------------------------
' Process empty recordset
'-------------------------------
  if rs.eof then
    set rs = nothing
    SetVar "DListfac_usrtab_datagrid", ""
    Parse "fac_usrtab_datagridNoRecords", False
    SetVar "fac_usrtab_datagridNavigator", ""
    Parse "Formfac_usrtab_datagrid", False
    exit sub
  end if
'-------------------------------

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

'-------------------------------
' Process page scroller
'-------------------------------
  iPage = GetParam("Formfac_usrtab_datagrid_Page")
  openrs rsCount, sCountSQL
  dResult = CLng(rsCount.fields(0).value) / iRecordsPerPage
  iPageCount = int(dResult)
  if iPageCount < dResult then iPageCount = iPageCount + 1
  SetVar "fac_usrtab_datagridPageCount", 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
'-------------------------------
    fldFAC_USRDATA_CODE = GetValue(rs, "F_FAC_USRDATA_CODE")
    fldFAC_USRDATA_KEY_URLLink = "fac_usrdatarecord1.asp"
    fldFAC_USRDATA_KEY_FAC_USRDATA_KEY = GetValue(rs, "F_FAC_USRDATA_KEY")
    fldFAC_USRDATA_KEY_FAC_USRDATA_PARENTKEY = GetValue(rs, "F_FAC_USRDATA_PARENTKEY")
    fldFAC_USRDATA_KEY = GetValue(rs, "F_FAC_USRDATA_KEY")
    fldFAC_USRDATA_OMSCHR_URLLink = "fac_usrdatarecord1.asp"
    fldFAC_USRDATA_OMSCHR_FAC_USRDATA_KEY = GetValue(rs, "F_FAC_USRDATA_KEY")
    fldFAC_USRDATA_OMSCHR_FAC_USRDATA_PARENTKEY = GetValue(rs, "F_FAC_USRDATA_PARENTKEY")
    fldFAC_USRDATA_OMSCHR = GetValue(rs, "F_FAC_USRDATA_OMSCHR")
    fldFAC_USRDATA_PRIJS = GetValue(rs, "F_FAC_USRDATA_PRIJS")
    fldFAC_USRDATA_VERVALDATUM = GetValue(rs, "F_FAC_USRDATA_VERVALDATUM")
    fldFAC_USRDATA_VOLGNR = GetValue(rs, "F_FAC_USRDATA_VOLGNR")
'-------------------------------
' fac_usrtab_datagrid Show begin
'-------------------------------

'-------------------------------
' fac_usrtab_datagrid Show Event begin
' fac_usrtab_datagrid Show Event end
'-------------------------------

'-------------------------------
' Replace Template fields with database values
'-------------------------------
    
      SetVar "FAC_USRDATA_KEY", ToHTML(fldFAC_USRDATA_KEY)
      SetVar "FAC_USRDATA_KEY_URLLink", fldFAC_USRDATA_KEY_URLLink
      SetVar "PrmFAC_USRDATA_KEY_FAC_USRDATA_KEY", ToURL(fldFAC_USRDATA_KEY_FAC_USRDATA_KEY)
      SetVar "PrmFAC_USRDATA_KEY_FAC_USRDATA_PARENTKEY", ToURL(fldFAC_USRDATA_KEY_FAC_USRDATA_PARENTKEY)
      SetVar "FAC_USRDATA_OMSCHR", ToHTML(fldFAC_USRDATA_OMSCHR)
      SetVar "FAC_USRDATA_OMSCHR_URLLink", fldFAC_USRDATA_OMSCHR_URLLink
      SetVar "PrmFAC_USRDATA_OMSCHR_FAC_USRDATA_KEY", ToURL(fldFAC_USRDATA_OMSCHR_FAC_USRDATA_KEY)
      SetVar "PrmFAC_USRDATA_OMSCHR_FAC_USRDATA_PARENTKEY", ToURL(fldFAC_USRDATA_OMSCHR_FAC_USRDATA_PARENTKEY)
      SetVar "FAC_USRDATA_CODE", ToHTML(fldFAC_USRDATA_CODE)
      SetVar "FAC_USRDATA_VOLGNR", ToHTML(fldFAC_USRDATA_VOLGNR)
      SetVar "FAC_USRDATA_PRIJS", ToHTML(fldFAC_USRDATA_PRIJS)
      SetVar "FAC_USRDATA_VERVALDATUM", ToHTML(fldFAC_USRDATA_VERVALDATUM)
    Parse "DListfac_usrtab_datagrid", True

'-------------------------------
' fac_usrtab_datagrid Show end
'-------------------------------

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


'-------------------------------
' fac_usrtab_datagrid Navigation begin
'-------------------------------
  bEof = rs.eof
  if rs.eof and iPage = 1 then
	SetVar "fac_usrtab_datagridNavigator", ""
  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 "fac_usrtab_datagridNavigatorPages", true
      iDisplayPages = iDisplayPages + 1
    next
    SetVar "NavigatorPageSwitch", "_"
    SetVar "NavigatorPageNumber", iPage
    SetVar "NavigatorPageNumberView", iPage
    Parse "fac_usrtab_datagridNavigatorPages", true
    iDisplayPages = iDisplayPages + 1
    SetVar "NavigatorPageSwitch", ""
    iPageCount = iPage + 1
    while iDisplayPages < iNumberOfPages and iStartPage + iDisplayPages < iHasPages
      SetVar "NavigatorPageNumber", iPageCount
      SetVar "NavigatorPageNumberView", iPageCount
      Parse "fac_usrtab_datagridNavigatorPages", true
      iDisplayPages = iDisplayPages + 1
      iPageCount = iPageCount + 1
    wend
    if bEof then
      SetVar "fac_usrtab_datagridNavigatorLastPage", "_"
    else
      SetVar "NextPage", (iPage + 1)
    end if
    if iPage = 1 then
      SetVar "fac_usrtab_datagridNavigatorFirstPage", "_"
    else
      SetVar "PrevPage", (iPage - 1)
    end if
    SetVar "fac_usrtab_datagridCurrentPage", iPage
    Parse "fac_usrtab_datagridNavigator", False
  end if
'-------------------------------
' fac_usrtab_datagrid Navigation end
'-------------------------------

'-------------------------------
' Finish form processing
'-------------------------------
  set rs = nothing
  SetVar "fac_usrtab_datagridNoRecords", ""
  Parse "Formfac_usrtab_datagrid", False

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

%>