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

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


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


'===============================
' cnt_termijnrecord PageSecurity begin
' cnt_termijnrecord PageSecurity end
'===============================

'===============================
' cnt_termijnrecord Open Event begin
' cnt_termijnrecord Open Event end
'===============================

'===============================
' cnt_termijnrecord OpenAnyPage Event begin
' cnt_termijnrecord OpenAnyPage Event end
'===============================

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

' cnt_termijnrecord Show begin
'===============================
' Perform the form's action
'-------------------------------
' Initialize error variables
'-------------------------------
sTermijnRecordErr = ""

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

' cnt_termijnrecord Show end

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

' cnt_termijnrecord Close Event begin
' cnt_termijnrecord Close Event end

cn.Close
Set cn = Nothing
UnloadTemplate
'===============================
'===============================
' Action of the Record Form
'-------------------------------
Sub TermijnRecordAction(sAction)
'-------------------------------
' Initialize variables  
'-------------------------------
  Dim bExecSQL: bExecSQL = true
  Dim sActionFileName : sActionFileName = ""
  Dim sParams : sParams = "?"
  Dim sWhere : sWhere = "" 
  Dim bErr : bErr = False
  Dim pPKCNT_TERMIJN_KEY : pPKCNT_TERMIJN_KEY = ""
  Dim fldCNT_TERMIJN_OMSCHRIJVING : fldCNT_TERMIJN_OMSCHRIJVING = ""
  Dim fldCNT_TERMIJN_TYPE : fldCNT_TERMIJN_TYPE = ""
  Dim fldCNT_TERMIJN_AANTAL : fldCNT_TERMIJN_AANTAL = ""
  Dim fldCNT_TERMIJN_VOLGNUMMER : fldCNT_TERMIJN_VOLGNUMMER = ""
'-------------------------------

'-------------------------------
' TermijnRecord Action begin
'-------------------------------
  sActionFileName = "cnt_termijngrid.asp"
  sParams = sParams & "sCNT_TERMIJN_OMSCHRIJVING=" & ToURL(GetParam("Trn_sCNT_TERMIJN_OMSCHRIJVING"))

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

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

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


'-------------------------------
' Load all form fields into variables
'-------------------------------
  fldCNT_TERMIJN_OMSCHRIJVING = GetParam("CNT_TERMIJN_OMSCHRIJVING")
  fldCNT_TERMIJN_TYPE = GetParam("CNT_TERMIJN_TYPE")
  fldCNT_TERMIJN_AANTAL = GetParam("CNT_TERMIJN_AANTAL")
  fldCNT_TERMIJN_VOLGNUMMER = GetParam("CNT_TERMIJN_VOLGNUMMER")

'-------------------------------
' Validate fields
'-------------------------------
  if sAction = "insert" or sAction = "update" then
    if not isNumeric(fldCNT_TERMIJN_AANTAL) then
      sTermijnRecordErr = sTermijnRecordErr & "De waarde in veld Aantal is niet correct.<br>"
    end if
    if not isNumeric(fldCNT_TERMIJN_VOLGNUMMER) then
      sTermijnRecordErr = sTermijnRecordErr & "De waarde in veld Volgnummer is niet correct.<br>"
    end if
'-------------------------------
' TermijnRecord Check Event begin
' TermijnRecord Check Event end
'-------------------------------
    If len(sTermijnRecordErr) > 0 then
      exit sub
    end if
  end if
'-------------------------------


'-------------------------------
' Create SQL statement
'-------------------------------
  select case sAction
    case "insert"
'-------------------------------
' TermijnRecord Insert Event begin
' TermijnRecord Insert Event end
'-------------------------------
      sSQL = "insert into CNT_TERMIJN (" & _
          "CNT_TERMIJN_OMSCHRIJVING," & _
          "CNT_TERMIJN_TYPE," & _
          "CNT_TERMIJN_AANTAL," & _
          "CNT_TERMIJN_VOLGNUMMER)" & _
          " values (" & _
          ToSQL(fldCNT_TERMIJN_OMSCHRIJVING, "Text") & "," & _
          ToSQL(fldCNT_TERMIJN_TYPE, "Text") & "," & _
          ToSQL(fldCNT_TERMIJN_AANTAL, "Number") & "," & _
          ToSQL(fldCNT_TERMIJN_VOLGNUMMER, "Number") & _
          ")"
    case "update"
'-------------------------------
' TermijnRecord Update Event begin
' TermijnRecord Update Event end
'-------------------------------
      sSQL = "update CNT_TERMIJN set " & _
        "CNT_TERMIJN_OMSCHRIJVING=" & ToSQL(fldCNT_TERMIJN_OMSCHRIJVING, "Text") & _
        ",CNT_TERMIJN_TYPE=" & ToSQL(fldCNT_TERMIJN_TYPE, "Text") & _
        ",CNT_TERMIJN_AANTAL=" & ToSQL(fldCNT_TERMIJN_AANTAL, "Number") & _
        ",CNT_TERMIJN_VOLGNUMMER=" & ToSQL(fldCNT_TERMIJN_VOLGNUMMER, "Number")
      sSQL = sSQL & " where " & sWhere
    case "delete"
'-------------------------------
' TermijnRecord Delete Event begin
' TermijnRecord Delete Event end
'-------------------------------
      sSQL = "delete from CNT_TERMIJN where " & sWhere
  end select
'-------------------------------
'-------------------------------
' TermijnRecord BeforeExecute Event begin
' TermijnRecord BeforeExecute Event end
'-------------------------------

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

'===============================
' Display Record Form
'-------------------------------
Sub TermijnRecord_Show()
'-------------------------------
' TermijnRecord Show begin
'-------------------------------
  Dim sWhere : sWhere = ""
  Dim sFormTitle: sFormTitle = "Details termijn"
  Dim bPK : bPK = True

'-------------------------------
' Load primary key and form parameters
'-------------------------------
  if sTermijnRecordErr = "" then
    SetVar "Trn_sCNT_TERMIJN_OMSCHRIJVING", GetParam("sCNT_TERMIJN_OMSCHRIJVING")
    pCNT_TERMIJN_KEY = GetParam("CNT_TERMIJN_KEY")
    SetVar "TermijnRecordError", ""
  else
    fldCNT_TERMIJN_OMSCHRIJVING = GetParam("CNT_TERMIJN_OMSCHRIJVING")
    fldCNT_TERMIJN_TYPE = GetParam("CNT_TERMIJN_TYPE")
    fldCNT_TERMIJN_AANTAL = GetParam("CNT_TERMIJN_AANTAL")
    fldCNT_TERMIJN_VOLGNUMMER = GetParam("CNT_TERMIJN_VOLGNUMMER")
    SetVar "Trn_sCNT_TERMIJN_OMSCHRIJVING", GetParam("Trn_sCNT_TERMIJN_OMSCHRIJVING")
    pCNT_TERMIJN_KEY = GetParam("PK_CNT_TERMIJN_KEY")
    SetVar "sTermijnRecordErr", sTermijnRecordErr
    SetVar "FormTitle", sFormTitle
    Parse "TermijnRecordError", False
  end if
'-------------------------------

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

'-------------------------------

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

  if IsEmpty(pCNT_TERMIJN_KEY) then bPK = False
  
  sWhere = sWhere & "CNT_TERMIJN_KEY=" & ToSQL(pCNT_TERMIJN_KEY, "Number")
  SetVar "PK_CNT_TERMIJN_KEY", pCNT_TERMIJN_KEY
'-------------------------------
'-------------------------------
' TermijnRecord Open Event begin
' TermijnRecord Open Event end
'-------------------------------

  SetVar "FormTitle", sFormTitle

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

'-------------------------------
' Load all fields into variables from recordset or input parameters
'-------------------------------
  if bIsUpdateMode then
    fldCNT_TERMIJN_KEY = GetValue(rs, "CNT_TERMIJN_KEY")

'-------------------------------
' Load data from recordset when form displayed first time
'-------------------------------
    if sTermijnRecordErr = "" then
      fldCNT_TERMIJN_OMSCHRIJVING = GetValue(rs, "CNT_TERMIJN_OMSCHRIJVING")
      fldCNT_TERMIJN_TYPE = GetValue(rs, "CNT_TERMIJN_TYPE")
      fldCNT_TERMIJN_AANTAL = GetValue(rs, "CNT_TERMIJN_AANTAL")
      fldCNT_TERMIJN_VOLGNUMMER = GetValue(rs, "CNT_TERMIJN_VOLGNUMMER")
    end if
    SetVar "TermijnRecordInsert", ""
    Parse "TermijnRecordEdit", False
'-------------------------------
' TermijnRecord ShowEdit Event begin
' TermijnRecord ShowEdit Event end
'-------------------------------
  else
    SetVar "TermijnRecordEdit", ""
    Parse "TermijnRecordInsert", False
'-------------------------------
' TermijnRecord ShowInsert Event begin
' TermijnRecord ShowInsert Event end
'-------------------------------
  end if
  Parse "TermijnRecordCancel", false
'-------------------------------
' TermijnRecord Show Event begin
' TermijnRecord Show Event end
'-------------------------------

'-------------------------------
' Show form field
'-------------------------------
      SetVar "CNT_TERMIJN_KEY", ToHTML(fldCNT_TERMIJN_KEY)
      SetVar "CNT_TERMIJN_OMSCHRIJVING", ToHTML(fldCNT_TERMIJN_OMSCHRIJVING)
      SetVar "TermijnRecordLBCNT_TERMIJN_TYPE", ""
      LOV = Split(""&FCLTLCL("D;Dag;W;Week;M;Maand;Y;Jaar")&"", ";")
      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(fldCNT_TERMIJN_TYPE) then SetVar "Selected", "SELECTED" else SetVar "Selected", ""
          Parse "TermijnRecordLBCNT_TERMIJN_TYPE", True
        next
      end if
    
      SetVar "CNT_TERMIJN_AANTAL", ToHTML(fldCNT_TERMIJN_AANTAL)
      SetVar "CNT_TERMIJN_VOLGNUMMER", ToHTML(fldCNT_TERMIJN_VOLGNUMMER)
  Parse "FormTermijnRecord", False

'-------------------------------
' TermijnRecord Close Event begin
' TermijnRecord Close Event end
'-------------------------------

Set rs = Nothing

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