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

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


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


'===============================
' mld_kenmerkrecord PageSecurity begin
' mld_kenmerkrecord PageSecurity end
'===============================

'===============================
' mld_kenmerkrecord Open Event begin
' mld_kenmerkrecord Open Event end
'===============================

'===============================
' mld_kenmerkrecord OpenAnyPage Event begin
' mld_kenmerkrecord OpenAnyPage Event end
'===============================

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

' mld_kenmerkrecord Show begin
'===============================
' Perform the form's action
'-------------------------------
' Initialize error variables
'-------------------------------
sKenmerkRecordErr = ""

'-------------------------------
' Select the FormAction
'-------------------------------
Select Case sForm
  Case "KenmerkRecord"
    KenmerkRecordAction(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
'-------------------------------
KenmerkRecord_Show
'-------------------------------
' Process page templates
'-------------------------------
Parse "main", False
'-------------------------------
' Output the page to the browser
'-------------------------------
Response.write PrintVar("main")

' mld_kenmerkrecord Show end

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

' mld_kenmerkrecord Close Event begin
' mld_kenmerkrecord Close Event end

cn.Close
Set cn = Nothing
UnloadTemplate
'===============================
'===============================
' Action of the Record Form
'-------------------------------
Sub KenmerkRecordAction(sAction)
'-------------------------------
' Initialize variables  
'-------------------------------
  Dim bExecSQL: bExecSQL = true
  Dim sActionFileName : sActionFileName = ""
  Dim sParams : sParams = "?"
  Dim sWhere : sWhere = "" 
  Dim bErr : bErr = False
  Dim pPKMLD_KENMERK_KEY : pPKMLD_KENMERK_KEY = ""
  Dim fldMLD_SRTKENMERK_KEY : fldMLD_SRTKENMERK_KEY = ""
  Dim fldmelding_opdracht : fldmelding_opdracht = ""
  Dim fldMLD_KENMERK_VOLGNUMMER : fldMLD_KENMERK_VOLGNUMMER = ""
  Dim fldMLD_KENMERK_GROEP : fldMLD_KENMERK_GROEP = ""
  Dim fldMLD_KENMERK_VERPLICHT : fldMLD_KENMERK_VERPLICHT = ""
  Dim fldMLD_KENMERK_VERPLICHT_STATUS : fldMLD_KENMERK_VERPLICHT_STATUS = ""
  Dim fldMLD_KENMERK_TOONBAAR : fldMLD_KENMERK_TOONBAAR = ""
  Dim fldMLD_KENMERK_DEFAULT : fldMLD_KENMERK_DEFAULT = ""
  Dim fldMLD_STDMELDING_KEY : fldMLD_STDMELDING_KEY = ""
  Dim fldMLD_KENMERK_LOCATIEKOLOM : fldMLD_KENMERK_LOCATIEKOLOM = ""
  Dim fldMLD_TYPEOPDR_KEY : fldMLD_TYPEOPDR_KEY = ""
  Dim fldMLD_KENMERK_HINT : fldMLD_KENMERK_HINT = ""
  Dim fldMLD_KENMERK_REGEXP : fldMLD_KENMERK_REGEXP = ""
'-------------------------------

'-------------------------------
' KenmerkRecord Action begin
'-------------------------------
  sActionFileName = "mld_kenmerkgrid.asp"
  sParams = sParams & "MLD_KENMERK_NIVEAU=" & ToURL(GetParam("Trn_MLD_KENMERK_NIVEAU")) & "&"
  sParams = sParams & "MLD_TYPEOPDR_KEY=" & ToURL(GetParam("Trn_MLD_TYPEOPDR_KEY")) & "&"
  sParams = sParams & "mld_kenmerk_omschr=" & ToURL(GetParam("Trn_mld_kenmerk_omschr"))

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

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

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


'-------------------------------
' Load all form fields into variables
'-------------------------------
  fldMLD_SRTKENMERK_KEY = GetParam("MLD_SRTKENMERK_KEY")
  fldmelding_opdracht = GetParam("melding_opdracht")
  fldMLD_KENMERK_VOLGNUMMER = GetParam("MLD_KENMERK_VOLGNUMMER")
  fldMLD_KENMERK_GROEP = GetParam("MLD_KENMERK_GROEP")
  fldMLD_KENMERK_VERPLICHT = GetParam("MLD_KENMERK_VERPLICHT")
  fldMLD_KENMERK_VERPLICHT_STATUS = GetParam("MLD_KENMERK_VERPLICHT_STATUS")
  fldMLD_KENMERK_TOONBAAR = getCheckBoxValue(GetParam("MLD_KENMERK_TOONBAAR"), "1", "", "Number")
  fldMLD_KENMERK_DEFAULT = GetParam("MLD_KENMERK_DEFAULT")
  fldMLD_STDMELDING_KEY = GetParam("MLD_STDMELDING_KEY")
  fldMLD_KENMERK_LOCATIEKOLOM = GetParam("MLD_KENMERK_LOCATIEKOLOM")
  fldMLD_TYPEOPDR_KEY = GetParam("MLD_TYPEOPDR_KEY")
  fldMLD_KENMERK_HINT = GetParam("MLD_KENMERK_HINT")
  fldMLD_KENMERK_REGEXP = GetParam("MLD_KENMERK_REGEXP")

'-------------------------------
' Validate fields
'-------------------------------
  if sAction = "insert" or sAction = "update" then
    if IsEmpty(fldMLD_SRTKENMERK_KEY) then
      sKenmerkRecordErr = sKenmerkRecordErr & "De waarde in veld Kenmerksoort is verplicht.<br>"
    end if
    if IsEmpty(fldmelding_opdracht) then
      sKenmerkRecordErr = sKenmerkRecordErr & "De waarde in veld Opdrachttype is verplicht.<br>"
    end if
    if IsEmpty(fldMLD_KENMERK_VOLGNUMMER) then
      sKenmerkRecordErr = sKenmerkRecordErr & "De waarde in veld Volgnummer is verplicht.<br>"
    end if
    if IsEmpty(fldMLD_KENMERK_GROEP) then
      sKenmerkRecordErr = sKenmerkRecordErr & "De waarde in veld Groep is verplicht.<br>"
    end if
    if not isNumeric(fldMLD_SRTKENMERK_KEY) then
      sKenmerkRecordErr = sKenmerkRecordErr & "De waarde in veld Kenmerksoort is niet correct.<br>"
    end if
    if not isNumeric(fldmelding_opdracht) then
      sKenmerkRecordErr = sKenmerkRecordErr & "De waarde in veld Opdrachttype is niet correct.<br>"
    end if
    if not isNumeric(fldMLD_KENMERK_VOLGNUMMER) then
      sKenmerkRecordErr = sKenmerkRecordErr & "De waarde in veld Volgnummer is niet correct.<br>"
    end if
    if not isNumeric(fldMLD_KENMERK_GROEP) then
      sKenmerkRecordErr = sKenmerkRecordErr & "De waarde in veld Groep is niet correct.<br>"
    end if
    if not isNumeric(fldMLD_KENMERK_VERPLICHT) then
      sKenmerkRecordErr = sKenmerkRecordErr & "De waarde in veld Verplicht is niet correct.<br>"
    end if
    if not isNumeric(fldMLD_KENMERK_VERPLICHT_STATUS) then
      sKenmerkRecordErr = sKenmerkRecordErr & "De waarde in veld Verplicht bij status is niet correct.<br>"
    end if
    if not isNumeric(fldMLD_STDMELDING_KEY) then
      sKenmerkRecordErr = sKenmerkRecordErr & "De waarde in veld MLD_STDMELDING_KEY is niet correct.<br>"
    end if
    if not isNumeric(fldMLD_TYPEOPDR_KEY) then
      sKenmerkRecordErr = sKenmerkRecordErr & "De waarde in veld MLD_TYPEOPDR_KEY is niet correct.<br>"
    end if
'-------------------------------
' KenmerkRecord Check Event begin
if fldMLD_KENMERK_NIVEAU = "O" and (fldmelding_opdracht = "" or fldmelding_opdracht="0") then
  sKenmerkRecordErr = sKenmerkRecordErr & "Er dient een opdrachttype gekozen te worden.<br>"
end if

ongeldig_verplicht_status = false
ssql = "SELECT mld_srtkenmerk_key" &_
      "   FROM mld_srtkenmerk " &_
      "  WHERE mld_srtkenmerk_kenmerktype='M'"
openrs rs, ssql
while not rs.eof
    srtkenmerk_key = getValue(rs,"MLD_SRTKENMERK_KEY")
    if ((cstr(srtkenmerk_key) = cstr(fldMLD_SRTKENMERK_KEY)) AND (cstr(fldMLD_KENMERK_VERPLICHT_STATUS) <> "-1")) then
        ongeldig_verplicht_status = true
        x_srt = cstr(srtkenmerk_key)
    end if
    rs.movenext
wend
rs.Close
Set rs = Nothing
if ongeldig_verplicht_status then
    sKenmerkRecordErr = sKenmerkRecordErr & "Bij dit kenmerksoort moet Verplicht bij status leeg zijn."
end if
' KenmerkRecord Check Event end
'-------------------------------
    If len(sKenmerkRecordErr) > 0 then
      exit sub
    end if
  end if
'-------------------------------


'-------------------------------
' Create SQL statement
'-------------------------------
  select case sAction
    case "insert"
'-------------------------------
' KenmerkRecord Insert Event begin
'Controleer de defaultwaarde, als deze is ingevuld
default = fldMLD_KENMERK_DEFAULT
openrs rs,"select * from MLD_SRTKENMERK where MLD_SRTKENMERK_key = " & ToSQL(fldMLD_SRTKENMERK_KEY, "Number")
nmin = getValue(rs,"MLD_SRTKENMERK_NMIN")
nmax = getValue(rs,"MLD_SRTKENMERK_NMAX")
lengte = getValue(rs,"MLD_SRTKENMERK_LENGTE")
kenmerktype = getValue(rs,"MLD_SRTKENMERK_KENMERKTYPE")
tmp_insert_sql = ""
if (default <> "") and (left(default,7)<>g_sql_prefix) then
  select case kenmerktype
    case "D"
      tmp_insert_sql = toDate(default)
    case "N"
      if not IsNumeric(default) then
        sKenmerkRecordErr = sKenmerkRecordErr & "De defaultwaarde moet een nummer zijn!<br>"
      else
        if (lengte <> "") then
          max = CDbl(10^CInt(lengte))
          if (CDbl(default)>max) then
            sKenmerkRecordErr = sKenmerkRecordErr & "De defaultwaarde mag niet meer posities bevatten dan aangegeven bij lengte!<br>"
          end if
        end if
        if (nmin <> "") then
          min = CDbl(nmin)
          if CDbl(default) < min then
            sKenmerkRecordErr = sKenmerkRecordErr & "Defaultwaarde mag niet kleiner zijn dan het aangegeven minimum!<br>"
          end if
        end if
        if (nmax <> "") then
          max = CDbl(nmax)
          if CDbl(default) > max then
            sKenmerkRecordErr = sKenmerkRecordErr & "Defaultwaarde mag niet groter zijn dan het aangegeven maximum!<br>"
          end if
        end if
      end if
    case "C"
      if (lengte <> "") then
        pos = CDbl(lengte)
        if Len(default) > pos then
          sKenmerkRecordErr = sKenmerkRecordErr & "De lengte van de defaultwaarde mag niet groter zijn dan de aangegeven lengte!<br>"
        end if
      end if
  end select
end if

'Zet de keys op de juiste waarde
  fldMLD_TYPEOPDR_KEY = fldmelding_opdracht
  fldMLD_STDMELDING_KEY = ""

sSQL = "insert into MLD_KENMERK (" & _
          "MLD_SRTKENMERK_KEY," & _
          "MLD_STDMELDING_KEY," & _
          "MLD_TYPEOPDR_KEY," &_
          "MLD_KENMERK_NIVEAU," & _
          "MLD_KENMERK_VOLGNUMMER," & _
          "MLD_KENMERK_LOCATIEKOLOM," & _
          "MLD_KENMERK_GROEP," & _
          "MLD_KENMERK_VERPLICHT," & _
          "MLD_KENMERK_VERPLICHT_STATUS," & _
          "MLD_KENMERK_TOONBAAR," & _
          "MLD_KENMERK_DEFAULT," & _
          "MLD_KENMERK_HINT," & _
          "MLD_KENMERK_REGEXP)" & _
          " values (" & _
          ToSQL(fldMLD_SRTKENMERK_KEY, "Number") & "," & _
          ToSQL(fldMLD_STDMELDING_KEY, "Number") & "," & _
          ToSQL(fldMLD_TYPEOPDR_KEY, "Number") & "," &_
          ToSQL("O", "Text") & "," & _
          ToSQL(fldMLD_KENMERK_VOLGNUMMER, "Number") & "," & _
          ToSQL(fldMLD_KENMERK_LOCATIEKOLOM, "Text") & "," & _
          ToSQL(fldMLD_KENMERK_GROEP, "Number") & "," & _
          ToSQL(fldMLD_KENMERK_VERPLICHT, "Number") & "," & _
          ToSQL(fldMLD_KENMERK_VERPLICHT_STATUS, "Number") & "," & _
          fldMLD_KENMERK_TOONBAAR & ","
if (tmp_insert_sql <> "") then
  sSQL = sSQL & tmp_insert_sql
else
  sSQL = sSQL & ToSQL(default, "Text")
end if
sSQL = sSQL & "," & ToSQL(fldMLD_KENMERK_HINT, "Text")
sSQL = sSQL & "," & ToSQL(fldMLD_KENMERK_REGEXP, "Text")


sSQL = sSQL & ")"
' KenmerkRecord Insert Event end
'-------------------------------
      if sSQL = "" then
      sSQL = "insert into MLD_KENMERK (" & _
          "MLD_SRTKENMERK_KEY," & _
          "MLD_KENMERK_VOLGNUMMER," & _
          "MLD_KENMERK_GROEP," & _
          "MLD_KENMERK_VERPLICHT," & _
          "MLD_KENMERK_VERPLICHT_STATUS," & _
          "MLD_KENMERK_TOONBAAR," & _
          "MLD_KENMERK_DEFAULT," & _
          "MLD_STDMELDING_KEY," & _
          "MLD_KENMERK_LOCATIEKOLOM," & _
          "MLD_TYPEOPDR_KEY," & _
          "MLD_KENMERK_HINT," & _
          "MLD_KENMERK_REGEXP)" & _
          " values (" & _
          ToSQL(fldMLD_SRTKENMERK_KEY, "Number") & "," & _
          ToSQL(fldMLD_KENMERK_VOLGNUMMER, "Number") & "," & _
          ToSQL(fldMLD_KENMERK_GROEP, "Number") & "," & _
          ToSQL(fldMLD_KENMERK_VERPLICHT, "Number") & "," & _
          ToSQL(fldMLD_KENMERK_VERPLICHT_STATUS, "Number") & "," & _
          fldMLD_KENMERK_TOONBAAR & "," & _
          ToSQL(fldMLD_KENMERK_DEFAULT, "Text") & "," & _
          ToSQL(fldMLD_STDMELDING_KEY, "Number") & "," & _
          ToSQL(fldMLD_KENMERK_LOCATIEKOLOM, "Text") & "," & _
          ToSQL(fldMLD_TYPEOPDR_KEY, "Number") & "," & _
          ToSQL(fldMLD_KENMERK_HINT, "Text") & "," & _
          ToSQL(fldMLD_KENMERK_REGEXP, "Text") & _
          ")"
      end if
    case "update"
'-------------------------------
' KenmerkRecord Update Event begin
'Controleer of de defaultwaarde correct is, als deze ingevuld is
tmp_update_sql = ""
openrs rs,"select * from mld_srtkenmerk where mld_srtkenmerk_key = " & ToSQL(fldMLD_SRTKENMERK_KEY, "Number")
lengte = getValue(rs,"MLD_SRTKENMERK_LENGTE")
nmin = getValue(rs,"MLD_SRTKENMERK_NMIN")
nmax = getValue(rs,"MLD_SRTKENMERK_NMAX")
default = fldMLD_KENMERK_DEFAULT
kenmerktype = getValue(rs,"MLD_SRTKENMERK_KENMERKTYPE")
if (default <> "") and (left(default,7)<>g_sql_prefix) then
  select case kenmerktype
    case "D"
      tmp_update_sql = toDate(default)
    case "N"
      if not IsNumeric(default) then
        sKenmerkRecordErr = sKenmerkRecordErr & "De defaultwaarde moet een nummer zijn!<br>"
      else
        if (lengte <> "") then
          max = CDbl(10^CInt(lengte))
          if (CDbl(default)>max) then
            sKenmerkRecordErr = sKenmerkRecordErr & "De defaultwaarde mag niet meer posities bevatten dan aangegeven bij lengte!<br>"
          end if
        end if
        if (nmin <> "") then
          min = CDbl(nmin)
          if CDbl(default) < min then
            sKenmerkRecordErr = sKenmerkRecordErr & "Defaultwaarde mag niet kleiner zijn dan het aangegeven minimum!<br>"
          end if
        end if
        if (nmax <> "") then
          max = CDbl(nmax)
          if CDbl(default) > max then
            sKenmerkRecordErr = sKenmerkRecordErr & "Defaultwaarde mag niet groter zijn dan het aangegeven maximum!<br>"
          end if
        end if
      end if
    case "C"
      pos = CDbl(lengte)
      if Len(default) > pos then
        sKenmerkRecordErr = sKenmerkRecordErr & "De lengte van de defaultwaarde mag niet groter zijn dan de aangegeven lengte!<br>"
      end if
  end select
end if

'Zet de keys op de juiste waarde
  fldMLD_TYPEOPDR_KEY = fldmelding_opdracht
  fldMLD_STDMELDING_KEY = ""

sSQL = "update MLD_KENMERK set " & _
     "MLD_SRTKENMERK_KEY=" & ToSQL(fldMLD_SRTKENMERK_KEY, "Number") & _
     ",MLD_STDMELDING_KEY=" & ToSQL(fldMLD_STDMELDING_KEY, "Number") & _
     ",MLD_TYPEOPDR_KEY=" & ToSql(fldMLD_TYPEOPDR_KEY, "Number") &_
     ",MLD_KENMERK_NIVEAU=" & ToSQL("O", "Text") & _
     ",MLD_KENMERK_VOLGNUMMER=" & ToSQL(fldMLD_KENMERK_VOLGNUMMER, "Number") & _
     ",MLD_KENMERK_LOCATIEKOLOM=" & ToSQL(fldMLD_KENMERK_LOCATIEKOLOM, "Text") & _
     ",MLD_KENMERK_GROEP=" & ToSQL(fldMLD_KENMERK_GROEP, "Number") & _
     ",MLD_KENMERK_VERPLICHT=" & ToSQL(fldMLD_KENMERK_VERPLICHT, "Number") & _
     ",MLD_KENMERK_VERPLICHT_STATUS=" & ToSQL(fldMLD_KENMERK_VERPLICHT_STATUS, "Number") & _
     ",MLD_KENMERK_TOONBAAR=" & fldMLD_KENMERK_TOONBAAR
if (tmp_update_sql <> "") then
  sSQL = sSQL & ",MLD_KENMERK_DEFAULT=" & tmp_update_sql
else
  sSQL = sSQL & ",MLD_KENMERK_DEFAULT=" & ToSQL(default, "Text")
end if
sSQL = sSQL & ",MLD_KENMERK_HINT=" & ToSQL(fldMLD_KENMERK_HINT, "Text")
sSQL = sSQL & ",MLD_KENMERK_REGEXP=" & ToSQL(fldMLD_KENMERK_REGEXP, "Text")
sSQL = sSQL & " where " & sWhere
' KenmerkRecord Update Event end
'-------------------------------
      if sSQL = "" then
      sSQL = "update MLD_KENMERK set " & _
        "MLD_SRTKENMERK_KEY=" & ToSQL(fldMLD_SRTKENMERK_KEY, "Number") & _
        ",MLD_KENMERK_VOLGNUMMER=" & ToSQL(fldMLD_KENMERK_VOLGNUMMER, "Number") & _
        ",MLD_KENMERK_GROEP=" & ToSQL(fldMLD_KENMERK_GROEP, "Number") & _
        ",MLD_KENMERK_VERPLICHT=" & ToSQL(fldMLD_KENMERK_VERPLICHT, "Number") & _
        ",MLD_KENMERK_VERPLICHT_STATUS=" & ToSQL(fldMLD_KENMERK_VERPLICHT_STATUS, "Number") & _
        ",MLD_KENMERK_TOONBAAR=" & fldMLD_KENMERK_TOONBAAR & _
        ",MLD_KENMERK_DEFAULT=" & ToSQL(fldMLD_KENMERK_DEFAULT, "Text") & _
        ",MLD_STDMELDING_KEY=" & ToSQL(fldMLD_STDMELDING_KEY, "Number") & _
        ",MLD_KENMERK_LOCATIEKOLOM=" & ToSQL(fldMLD_KENMERK_LOCATIEKOLOM, "Text") & _
        ",MLD_TYPEOPDR_KEY=" & ToSQL(fldMLD_TYPEOPDR_KEY, "Number") & _
        ",MLD_KENMERK_HINT=" & ToSQL(fldMLD_KENMERK_HINT, "Text") & _
        ",MLD_KENMERK_REGEXP=" & ToSQL(fldMLD_KENMERK_REGEXP, "Text")
      sSQL = sSQL & " where " & sWhere
      end if
    case "delete"
'-------------------------------
' KenmerkRecord Delete Event begin
dim tmpkey
tmpkey = "PK_"&strToTable(sActionFileName)&"_KEY"
sSql = customFacDelete(sActionFileName,getParam(tmpkey))
set tmpkey = Nothing
' KenmerkRecord Delete Event end
'-------------------------------
      if sSQL = "" then
      sSQL = "delete from MLD_KENMERK where " & sWhere
      end if
  end select
'-------------------------------
'-------------------------------
' KenmerkRecord BeforeExecute Event begin
' KenmerkRecord BeforeExecute Event end
'-------------------------------

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

'===============================
' Display Record Form
'-------------------------------
Sub KenmerkRecord_Show()
'-------------------------------
' KenmerkRecord Show begin
'-------------------------------
  Dim sWhere : sWhere = ""
  Dim sFormTitle: sFormTitle = "Details kenmerk"
  Dim bPK : bPK = True
  Dim sMLD_SRTKENMERK_KEYDisplayValue: sMLD_SRTKENMERK_KEYDisplayValue = ""
  Dim smelding_opdrachtDisplayValue: smelding_opdrachtDisplayValue = ""

'-------------------------------
' Load primary key and form parameters
'-------------------------------
  if sKenmerkRecordErr = "" then
    fldMLD_KENMERK_NIVEAU = GetParam("MLD_KENMERK_NIVEAU")
    fldMLD_SRTKENMERK_KEY = GetParam("MLD_SRTKENMERK_KEY")
    fldMLD_STDMELDING_KEY = GetParam("MLD_STDMELDING_KEY")
    fldMLD_TYPEOPDR_KEY = GetParam("MLD_TYPEOPDR_KEY")
    fldMLD_KENMERK_VOLGNUMMER = GetParam("MLD_KENMERK_VOLGNUMMER")
    SetVar "Trn_MLD_KENMERK_NIVEAU", GetParam("MLD_KENMERK_NIVEAU")
    SetVar "Trn_MLD_TYPEOPDR_KEY", GetParam("MLD_TYPEOPDR_KEY")
    SetVar "Trn_mld_kenmerk_omschr", GetParam("mld_kenmerk_omschr")
    pMLD_KENMERK_KEY = GetParam("MLD_KENMERK_KEY")
    SetVar "KenmerkRecordError", ""
  else
    fldMLD_SRTKENMERK_KEY = GetParam("MLD_SRTKENMERK_KEY")
    fldMLD_KENMERK_VOLGNUMMER = GetParam("MLD_KENMERK_VOLGNUMMER")
    fldMLD_KENMERK_GROEP = GetParam("MLD_KENMERK_GROEP")
    fldMLD_KENMERK_VERPLICHT = GetParam("MLD_KENMERK_VERPLICHT")
    fldMLD_KENMERK_VERPLICHT_STATUS = GetParam("MLD_KENMERK_VERPLICHT_STATUS")
    fldMLD_KENMERK_TOONBAAR = getCheckBoxValue(GetParam("MLD_KENMERK_TOONBAAR"), "1", "", "Number")
    fldMLD_KENMERK_DEFAULT = GetParam("MLD_KENMERK_DEFAULT")
    fldMLD_STDMELDING_KEY = GetParam("MLD_STDMELDING_KEY")
    fldMLD_KENMERK_LOCATIEKOLOM = GetParam("MLD_KENMERK_LOCATIEKOLOM")
    fldMLD_TYPEOPDR_KEY = GetParam("MLD_TYPEOPDR_KEY")
    fldMLD_KENMERK_HINT = GetParam("MLD_KENMERK_HINT")
    fldMLD_KENMERK_REGEXP = GetParam("MLD_KENMERK_REGEXP")
    SetVar "Trn_MLD_KENMERK_NIVEAU", GetParam("Trn_MLD_KENMERK_NIVEAU")
    SetVar "Trn_MLD_TYPEOPDR_KEY", GetParam("Trn_MLD_TYPEOPDR_KEY")
    SetVar "Trn_mld_kenmerk_omschr", GetParam("Trn_mld_kenmerk_omschr")
    pMLD_KENMERK_KEY = GetParam("PK_MLD_KENMERK_KEY")
    SetVar "sKenmerkRecordErr", sKenmerkRecordErr
    SetVar "FormTitle", sFormTitle
    Parse "KenmerkRecordError", False
  end if
'-------------------------------

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

  fldmelding_opdracht = GetParam("melding_opdracht")
'-------------------------------

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

  if IsEmpty(pMLD_KENMERK_KEY) then bPK = False
  
  sWhere = sWhere & "MLD_KENMERK_KEY=" & ToSQL(pMLD_KENMERK_KEY, "Number")
  SetVar "PK_MLD_KENMERK_KEY", pMLD_KENMERK_KEY
'-------------------------------
'-------------------------------
' KenmerkRecord Open Event begin
' KenmerkRecord Open Event end
'-------------------------------

  SetVar "FormTitle", sFormTitle

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

'-------------------------------
' Load all fields into variables from recordset or input parameters
'-------------------------------
  if bIsUpdateMode then
    fldMLD_KENMERK_KEY = GetValue(rs, "MLD_KENMERK_KEY")
    fldMLD_KENMERK_LOCATIEKOLOM = GetValue(rs, "MLD_KENMERK_LOCATIEKOLOM")
    fldMLD_STDMELDING_KEY = GetValue(rs, "MLD_STDMELDING_KEY")
    fldMLD_TYPEOPDR_KEY = GetValue(rs, "MLD_TYPEOPDR_KEY")

'-------------------------------
' Load data from recordset when form displayed first time
'-------------------------------
    if sKenmerkRecordErr = "" then
      fldMLD_SRTKENMERK_KEY = GetValue(rs, "MLD_SRTKENMERK_KEY")
      fldMLD_KENMERK_VOLGNUMMER = GetValue(rs, "MLD_KENMERK_VOLGNUMMER")
      fldMLD_KENMERK_GROEP = GetValue(rs, "MLD_KENMERK_GROEP")
      fldMLD_KENMERK_VERPLICHT = GetValue(rs, "MLD_KENMERK_VERPLICHT")
      fldMLD_KENMERK_VERPLICHT_STATUS = GetValue(rs, "MLD_KENMERK_VERPLICHT_STATUS")
      fldMLD_KENMERK_TOONBAAR = GetValue(rs, "MLD_KENMERK_TOONBAAR")
      fldMLD_KENMERK_DEFAULT = GetValue(rs, "MLD_KENMERK_DEFAULT")
      fldMLD_KENMERK_HINT = GetValue(rs, "MLD_KENMERK_HINT")
      fldMLD_KENMERK_REGEXP = GetValue(rs, "MLD_KENMERK_REGEXP")
    end if
    SetVar "KenmerkRecordInsert", ""
    Parse "KenmerkRecordEdit", False
'-------------------------------
' KenmerkRecord ShowEdit Event begin
' KenmerkRecord ShowEdit Event end
'-------------------------------
  else
    if sKenmerkRecordErr = "" then
      fldMLD_SRTKENMERK_KEY = ToHTML(GetParam("MLD_SRTKENMERK_KEY"))
      fldMLD_KENMERK_VOLGNUMMER = ToHTML(GetParam("MLD_KENMERK_VOLGNUMMER"))
      fldMLD_STDMELDING_KEY = ToHTML(GetParam("MLD_STDMELDING_KEY"))
      fldMLD_TYPEOPDR_KEY = ToHTML(GetParam("MLD_TYPEOPDR_KEY"))
    end if
    SetVar "KenmerkRecordEdit", ""
    Parse "KenmerkRecordInsert", False
'-------------------------------
' KenmerkRecord ShowInsert Event begin
' KenmerkRecord ShowInsert Event end
'-------------------------------
  end if
  Parse "KenmerkRecordCancel", false
  if sKenmerkRecordErr = "" then
'-------------------------------
' KenmerkRecord Show Event begin
'Balanceer if's om altijd deze methode uit te voeren.
end if
if true then

  NiveauSql = "select mld_typeopdr_key, mld_typeopdr_omschrijving "&_
              "from mld_typeopdr "&_
              "order by mld_typeopdr_upper asc"
  fldmelding_opdracht = fldMLD_TYPEOPDR_KEY
'  setVar "template","Opdrachttype"
' KenmerkRecord Show Event end
'-------------------------------
  end if

'-------------------------------
' Show form field
'-------------------------------
      SetVar "MLD_KENMERK_KEY", ToHTML(fldMLD_KENMERK_KEY)
      SetVar "KenmerkRecordLBMLD_SRTKENMERK_KEY", ""
      SetVar "Selected", ""
      SetVar "ID", ""
      SetVar "Value", sMLD_SRTKENMERK_KEYDisplayValue
      Parse "KenmerkRecordLBMLD_SRTKENMERK_KEY", True
      openrs rsMLD_SRTKENMERK_KEY, "select MLD_SRTKENMERK_KEY, MLD_SRTKENMERK_OMSCHRIJVING from MLD_SRTKENMERK where MLD_SRTKENMERK_VERWIJDER IS NULL order by mld_srtkenmerk_omschrijving asc"
      while not rsMLD_SRTKENMERK_KEY.EOF
        SetVar "ID", GetValue(rsMLD_SRTKENMERK_KEY, 0) : SetVar "Value", GetValue(rsMLD_SRTKENMERK_KEY, 1)
        if cstr(GetValue(rsMLD_SRTKENMERK_KEY, 0)) = cstr(fldMLD_SRTKENMERK_KEY) then SetVar "Selected", "SELECTED" else SetVar "Selected", ""
        Parse "KenmerkRecordLBMLD_SRTKENMERK_KEY", True
        rsMLD_SRTKENMERK_KEY.MoveNext
      wend
      set rsMLD_SRTKENMERK_KEY = nothing
    
      SetVar "KenmerkRecordLBmelding_opdracht", ""
      SetVar "Selected", ""
      SetVar "ID", ""
      SetVar "Value", smelding_opdrachtDisplayValue
      Parse "KenmerkRecordLBmelding_opdracht", True
      openrs rsmelding_opdracht, ""&NiveauSql&""
      while not rsmelding_opdracht.EOF
        SetVar "ID", GetValue(rsmelding_opdracht, 0) : SetVar "Value", GetValue(rsmelding_opdracht, 1)
        if cstr(GetValue(rsmelding_opdracht, 0)) = cstr(fldmelding_opdracht) then SetVar "Selected", "SELECTED" else SetVar "Selected", ""
        Parse "KenmerkRecordLBmelding_opdracht", True
        rsmelding_opdracht.MoveNext
      wend
      set rsmelding_opdracht = nothing
    
      SetVar "MLD_KENMERK_VOLGNUMMER", ToHTML(fldMLD_KENMERK_VOLGNUMMER)
      SetVar "KenmerkRecordLBMLD_KENMERK_GROEP", ""
      LOV = Split(""&BuildGroepsverplichtingList&"", ";")
      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(fldMLD_KENMERK_GROEP) then SetVar "Selected", "SELECTED" else SetVar "Selected", ""
          Parse "KenmerkRecordLBMLD_KENMERK_GROEP", True
        next
      end if
    
      SetVar "KenmerkRecordLBMLD_KENMERK_VERPLICHT", ""
      LOV = Split(""&buildVerplichtingList&"", ";")
      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(fldMLD_KENMERK_VERPLICHT) then SetVar "Selected", "SELECTED" else SetVar "Selected", ""
          Parse "KenmerkRecordLBMLD_KENMERK_VERPLICHT", True
        next
      end if
    
      SetVar "KenmerkRecordLBMLD_KENMERK_VERPLICHT_STATUS", ""
      LOV = Split(""&buildStatusList&"", ";")
      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(fldMLD_KENMERK_VERPLICHT_STATUS) then SetVar "Selected", "SELECTED" else SetVar "Selected", ""
          Parse "KenmerkRecordLBMLD_KENMERK_VERPLICHT_STATUS", True
        next
      end if
    
  if (LCase(fldMLD_KENMERK_TOONBAAR) = LCase("1")) then
    SetVar "MLD_KENMERK_TOONBAAR_CHECKED", "CHECKED"
  else
    SetVar "MLD_KENMERK_TOONBAAR_CHECKED", ""
  end if

      SetVar "MLD_KENMERK_DEFAULT", ToHTML(fldMLD_KENMERK_DEFAULT)
      SetVar "MLD_STDMELDING_KEY", ToHTML(fldMLD_STDMELDING_KEY)
      SetVar "MLD_KENMERK_LOCATIEKOLOM", ToHTML(fldMLD_KENMERK_LOCATIEKOLOM)
      SetVar "MLD_TYPEOPDR_KEY", ToHTML(fldMLD_TYPEOPDR_KEY)
      SetVar "MLD_KENMERK_HINT", ToHTML(fldMLD_KENMERK_HINT)
      SetVar "MLD_KENMERK_REGEXP", ToHTML(fldMLD_KENMERK_REGEXP)
  Parse "FormKenmerkRecord", False

'-------------------------------
' KenmerkRecord Close Event begin
' KenmerkRecord Close Event end
'-------------------------------

Set rs = Nothing

'-------------------------------
' KenmerkRecord Show end
'-------------------------------
End Sub
'===============================
%>