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

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


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


'===============================
' mld_meldbronrecord PageSecurity begin
' mld_meldbronrecord PageSecurity end
'===============================

'===============================
' mld_meldbronrecord Open Event begin
' mld_meldbronrecord Open Event end
'===============================

'===============================
' mld_meldbronrecord OpenAnyPage Event begin
' mld_meldbronrecord OpenAnyPage Event end
'===============================

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

' mld_meldbronrecord Show begin
'===============================
' Perform the form's action
'-------------------------------
' Initialize error variables
'-------------------------------
sMeldbronRecordErr = ""

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

' mld_meldbronrecord Show end

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

' mld_meldbronrecord Close Event begin
' mld_meldbronrecord Close Event end

cn.Close
Set cn = Nothing
UnloadTemplate
'===============================
'===============================
' Action of the Record Form
'-------------------------------
Sub MeldbronRecordAction(sAction)
'-------------------------------
' Initialize variables  
'-------------------------------
  Dim bExecSQL: bExecSQL = true
  Dim sActionFileName : sActionFileName = ""
  Dim sWhere : sWhere = "" 
  Dim bErr : bErr = False
  Dim pPKMLD_MELDBRON_KEY : pPKMLD_MELDBRON_KEY = ""
  Dim fldMLD_MELDBRON_OMSCHRIJVING : fldMLD_MELDBRON_OMSCHRIJVING = ""
  Dim fldMLD_MELDBRON_DEFAULT : fldMLD_MELDBRON_DEFAULT = ""
'-------------------------------

'-------------------------------
' MeldbronRecord Action begin
'-------------------------------
  sActionFileName = "mld_meldbrongrid.asp"

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

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

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


'-------------------------------
' Load all form fields into variables
'-------------------------------
  fldMLD_MELDBRON_OMSCHRIJVING = GetParam("MLD_MELDBRON_OMSCHRIJVING")
  fldMLD_MELDBRON_DEFAULT = getCheckBoxValue(GetParam("MLD_MELDBRON_DEFAULT"), "1", "", "Number")

'-------------------------------
' Validate fields
'-------------------------------
  if sAction = "insert" or sAction = "update" then
    if IsEmpty(fldMLD_MELDBRON_OMSCHRIJVING) then
      sMeldbronRecordErr = sMeldbronRecordErr & "De waarde in veld Omschrijving is verplicht.<br>"
    end if
'-------------------------------
' MeldbronRecord Check Event begin
' MeldbronRecord Check Event end
'-------------------------------
    If len(sMeldbronRecordErr) > 0 then
      exit sub
    end if
  end if
'-------------------------------


'-------------------------------
' Create SQL statement
'-------------------------------
  select case sAction
    case "insert"
'-------------------------------
' MeldbronRecord Insert Event begin
' MeldbronRecord Insert Event end
'-------------------------------
      sSQL = "insert into MLD_V_AANWEZIGMELDBRON (" & _
          "MLD_MELDBRON_OMSCHRIJVING," & _
          "MLD_MELDBRON_DEFAULT)" & _
          " values (" & _
          ToSQL(fldMLD_MELDBRON_OMSCHRIJVING, "Text") & "," & _
          fldMLD_MELDBRON_DEFAULT & _
          ")"
    case "update"
'-------------------------------
' MeldbronRecord Update Event begin
' MeldbronRecord Update Event end
'-------------------------------
      sSQL = "update MLD_V_AANWEZIGMELDBRON set " & _
        "MLD_MELDBRON_OMSCHRIJVING=" & ToSQL(fldMLD_MELDBRON_OMSCHRIJVING, "Text") & _
        ",MLD_MELDBRON_DEFAULT=" & fldMLD_MELDBRON_DEFAULT
      sSQL = sSQL & " where " & sWhere
    case "delete"
'-------------------------------
' MeldbronRecord Delete Event begin
dim tmpkey
tmpkey = "PK_"&strToTable(sActionFileName)&"_KEY"
sSql = customFacDelete(sActionFileName,getParam(tmpkey))
set tmpkey = Nothing
' MeldbronRecord Delete Event end
'-------------------------------
      if sSQL = "" then
      sSQL = "delete from MLD_V_AANWEZIGMELDBRON where " & sWhere
      end if
  end select
'-------------------------------
'-------------------------------
' MeldbronRecord BeforeExecute Event begin
' MeldbronRecord BeforeExecute Event end
'-------------------------------

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

'===============================
' Display Record Form
'-------------------------------
Sub MeldbronRecord_Show()
'-------------------------------
' MeldbronRecord Show begin
'-------------------------------
  Dim sWhere : sWhere = ""
  Dim sFormTitle: sFormTitle = "Details meldbron"
  Dim bPK : bPK = True

'-------------------------------
' Load primary key and form parameters
'-------------------------------
  if sMeldbronRecordErr = "" then
    pMLD_MELDBRON_KEY = GetParam("MLD_MELDBRON_KEY")
    SetVar "MeldbronRecordError", ""
  else
    fldMLD_MELDBRON_OMSCHRIJVING = GetParam("MLD_MELDBRON_OMSCHRIJVING")
    fldMLD_MELDBRON_DEFAULT = getCheckBoxValue(GetParam("MLD_MELDBRON_DEFAULT"), "1", "", "Number")
    pMLD_MELDBRON_KEY = GetParam("PK_MLD_MELDBRON_KEY")
    SetVar "sMeldbronRecordErr", sMeldbronRecordErr
    SetVar "FormTitle", sFormTitle
    Parse "MeldbronRecordError", False
  end if
'-------------------------------

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

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

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

  if IsEmpty(pMLD_MELDBRON_KEY) then bPK = False
  
  sWhere = sWhere & "MLD_MELDBRON_KEY=" & ToSQL(pMLD_MELDBRON_KEY, "Number")
  SetVar "PK_MLD_MELDBRON_KEY", pMLD_MELDBRON_KEY
'-------------------------------
'-------------------------------
' MeldbronRecord Open Event begin
' MeldbronRecord Open Event end
'-------------------------------

  SetVar "FormTitle", sFormTitle

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

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

'-------------------------------
' Load data from recordset when form displayed first time
'-------------------------------
    if sMeldbronRecordErr = "" then
      fldMLD_MELDBRON_OMSCHRIJVING = GetValue(rs, "MLD_MELDBRON_OMSCHRIJVING")
      fldMLD_MELDBRON_DEFAULT = GetValue(rs, "MLD_MELDBRON_DEFAULT")
    end if
    SetVar "MeldbronRecordInsert", ""
    Parse "MeldbronRecordEdit", False
'-------------------------------
' MeldbronRecord ShowEdit Event begin
' MeldbronRecord ShowEdit Event end
'-------------------------------
  else
    SetVar "MeldbronRecordEdit", ""
    Parse "MeldbronRecordInsert", False
'-------------------------------
' MeldbronRecord ShowInsert Event begin
' MeldbronRecord ShowInsert Event end
'-------------------------------
  end if
  Parse "MeldbronRecordCancel", false
'-------------------------------
' MeldbronRecord Show Event begin
' MeldbronRecord Show Event end
'-------------------------------

'-------------------------------
' Show form field
'-------------------------------
      SetVar "MLD_MELDBRON_KEY", ToHTML(fldMLD_MELDBRON_KEY)
      SetVar "MLD_MELDBRON_OMSCHRIJVING", ToHTML(fldMLD_MELDBRON_OMSCHRIJVING)
  if (LCase(fldMLD_MELDBRON_DEFAULT) = LCase("1")) then
    SetVar "MLD_MELDBRON_DEFAULT_CHECKED", "CHECKED"
  else
    SetVar "MLD_MELDBRON_DEFAULT_CHECKED", ""
  end if

  Parse "FormMeldbronRecord", False

'-------------------------------
' MeldbronRecord Close Event begin
' MeldbronRecord Close Event end
'-------------------------------

Set rs = Nothing

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