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

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


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


'===============================
' mld_impropdrrecord PageSecurity begin
' mld_impropdrrecord PageSecurity end
'===============================

'===============================
' mld_impropdrrecord Open Event begin
' mld_impropdrrecord Open Event end
'===============================

'===============================
' mld_impropdrrecord OpenAnyPage Event begin
' mld_impropdrrecord OpenAnyPage Event end
'===============================

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

' mld_impropdrrecord Show begin
'===============================
' Perform the form's action
'-------------------------------
' Initialize error variables
'-------------------------------
sImpropdrRecordErr = ""

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

' mld_impropdrrecord Show end

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

' mld_impropdrrecord Close Event begin
' mld_impropdrrecord Close Event end

cn.Close
Set cn = Nothing
UnloadTemplate
'===============================
'===============================
' Action of the Record Form
'-------------------------------
Sub ImpropdrRecordAction(sAction)
'-------------------------------
' Initialize variables  
'-------------------------------
  Dim bExecSQL: bExecSQL = true
  Dim sActionFileName : sActionFileName = ""
  Dim sWhere : sWhere = "" 
  Dim bErr : bErr = False
  Dim pPKMLD_IMPROPDR_KEY : pPKMLD_IMPROPDR_KEY = ""
  Dim fldMLD_IMPROPDR_CODE : fldMLD_IMPROPDR_CODE = ""
  Dim fldMLD_IMPROPDR_OMSCHRIJVING : fldMLD_IMPROPDR_OMSCHRIJVING = ""
  Dim fldMLD_IMPROPDR_ONKOSTEN : fldMLD_IMPROPDR_ONKOSTEN = ""
'-------------------------------

'-------------------------------
' ImpropdrRecord Action begin
'-------------------------------
  sActionFileName = "mld_impropdrgrid.asp"

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

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

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


'-------------------------------
' Load all form fields into variables
'-------------------------------
  fldMLD_IMPROPDR_CODE = GetParam("MLD_IMPROPDR_CODE")
  fldMLD_IMPROPDR_OMSCHRIJVING = GetParam("MLD_IMPROPDR_OMSCHRIJVING")
  fldMLD_IMPROPDR_ONKOSTEN = getCheckBoxValue(GetParam("MLD_IMPROPDR_ONKOSTEN"), "1", "0", "Number")

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


'-------------------------------
' Create SQL statement
'-------------------------------
  select case sAction
    case "insert"
'-------------------------------
' ImpropdrRecord Insert Event begin
' ImpropdrRecord Insert Event end
'-------------------------------
      sSQL = "insert into MLD_IMPROPDR (" & _
          "MLD_IMPROPDR_CODE," & _
          "MLD_IMPROPDR_OMSCHRIJVING," & _
          "MLD_IMPROPDR_ONKOSTEN)" & _
          " values (" & _
          ToSQL(fldMLD_IMPROPDR_CODE, "Text") & "," & _
          ToSQL(fldMLD_IMPROPDR_OMSCHRIJVING, "Text") & "," & _
          fldMLD_IMPROPDR_ONKOSTEN & _
          ")"
    case "update"
'-------------------------------
' ImpropdrRecord Update Event begin
' ImpropdrRecord Update Event end
'-------------------------------
      sSQL = "update MLD_IMPROPDR set " & _
        "MLD_IMPROPDR_CODE=" & ToSQL(fldMLD_IMPROPDR_CODE, "Text") & _
        ",MLD_IMPROPDR_OMSCHRIJVING=" & ToSQL(fldMLD_IMPROPDR_OMSCHRIJVING, "Text") & _
        ",MLD_IMPROPDR_ONKOSTEN=" & fldMLD_IMPROPDR_ONKOSTEN
      sSQL = sSQL & " where " & sWhere
    case "delete"
'-------------------------------
' ImpropdrRecord Delete Event begin
sSql = "update mld_impropdr set mld_impropdr_verwijder="+sysdate+" where mld_impropdr_key = " & ToSQL(getParam("PK_MLD_IMPROPDR_KEY"), "Number")
' ImpropdrRecord Delete Event end
'-------------------------------
      if sSQL = "" then
      sSQL = "delete from MLD_IMPROPDR where " & sWhere
      end if
  end select
'-------------------------------
'-------------------------------
' ImpropdrRecord BeforeExecute Event begin
' ImpropdrRecord BeforeExecute Event end
'-------------------------------

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

'===============================
' Display Record Form
'-------------------------------
Sub ImpropdrRecord_Show()
'-------------------------------
' ImpropdrRecord Show begin
'-------------------------------
  Dim sWhere : sWhere = ""
  Dim sFormTitle: sFormTitle = "Details improductief"
  Dim bPK : bPK = True

'-------------------------------
' Load primary key and form parameters
'-------------------------------
  if sImpropdrRecordErr = "" then
    pMLD_IMPROPDR_KEY = GetParam("MLD_IMPROPDR_KEY")
    SetVar "ImpropdrRecordError", ""
  else
    fldMLD_IMPROPDR_CODE = GetParam("MLD_IMPROPDR_CODE")
    fldMLD_IMPROPDR_OMSCHRIJVING = GetParam("MLD_IMPROPDR_OMSCHRIJVING")
    fldMLD_IMPROPDR_ONKOSTEN = getCheckBoxValue(GetParam("MLD_IMPROPDR_ONKOSTEN"), "1", "0", "Number")
    pMLD_IMPROPDR_KEY = GetParam("PK_MLD_IMPROPDR_KEY")
    SetVar "sImpropdrRecordErr", sImpropdrRecordErr
    SetVar "FormTitle", sFormTitle
    Parse "ImpropdrRecordError", False
  end if
'-------------------------------

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

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

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

  if IsEmpty(pMLD_IMPROPDR_KEY) then bPK = False
  
  sWhere = sWhere & "MLD_IMPROPDR_KEY=" & ToSQL(pMLD_IMPROPDR_KEY, "Number")
  SetVar "PK_MLD_IMPROPDR_KEY", pMLD_IMPROPDR_KEY
'-------------------------------
'-------------------------------
' ImpropdrRecord Open Event begin
' ImpropdrRecord Open Event end
'-------------------------------

  SetVar "FormTitle", sFormTitle

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

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

'-------------------------------
' Load data from recordset when form displayed first time
'-------------------------------
    if sImpropdrRecordErr = "" then
      fldMLD_IMPROPDR_CODE = GetValue(rs, "MLD_IMPROPDR_CODE")
      fldMLD_IMPROPDR_OMSCHRIJVING = GetValue(rs, "MLD_IMPROPDR_OMSCHRIJVING")
      fldMLD_IMPROPDR_ONKOSTEN = GetValue(rs, "MLD_IMPROPDR_ONKOSTEN")
    end if
    SetVar "ImpropdrRecordInsert", ""
    Parse "ImpropdrRecordEdit", False
'-------------------------------
' ImpropdrRecord ShowEdit Event begin
' ImpropdrRecord ShowEdit Event end
'-------------------------------
  else
    if sImpropdrRecordErr = "" then
      fldMLD_IMPROPDR_ONKOSTEN= "2"
    end if
    SetVar "ImpropdrRecordEdit", ""
    Parse "ImpropdrRecordInsert", False
'-------------------------------
' ImpropdrRecord ShowInsert Event begin
' ImpropdrRecord ShowInsert Event end
'-------------------------------
  end if
  Parse "ImpropdrRecordCancel", false
'-------------------------------
' ImpropdrRecord Show Event begin
' ImpropdrRecord Show Event end
'-------------------------------

'-------------------------------
' Show form field
'-------------------------------
      SetVar "MLD_IMPROPDR_KEY", ToHTML(fldMLD_IMPROPDR_KEY)
      SetVar "MLD_IMPROPDR_CODE", ToHTML(fldMLD_IMPROPDR_CODE)
      SetVar "MLD_IMPROPDR_OMSCHRIJVING", ToHTML(fldMLD_IMPROPDR_OMSCHRIJVING)
  if (LCase(fldMLD_IMPROPDR_ONKOSTEN) = LCase("1")) then
    SetVar "MLD_IMPROPDR_ONKOSTEN_CHECKED", "CHECKED"
  else
    SetVar "MLD_IMPROPDR_ONKOSTEN_CHECKED", ""
  end if

  Parse "FormImpropdrRecord", False

'-------------------------------
' ImpropdrRecord Close Event begin
' ImpropdrRecord Close Event end
'-------------------------------

Set rs = Nothing

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