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

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


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


'===============================
' mld_kostenrecord PageSecurity begin
' mld_kostenrecord PageSecurity end
'===============================

'===============================
' mld_kostenrecord Open Event begin
' mld_kostenrecord Open Event end
'===============================

'===============================
' mld_kostenrecord OpenAnyPage Event begin
' mld_kostenrecord OpenAnyPage Event end
'===============================

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

' mld_kostenrecord Show begin
'===============================
' Perform the form's action
'-------------------------------
' Initialize error variables
'-------------------------------
sKostenRecordErr = ""

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

' mld_kostenrecord Show end

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

' mld_kostenrecord Close Event begin
' mld_kostenrecord Close Event end

cn.Close
Set cn = Nothing
UnloadTemplate
'===============================
'===============================
' Action of the Record Form
'-------------------------------
Sub KostenRecordAction(sAction)
'-------------------------------
' Initialize variables  
'-------------------------------
  Dim bExecSQL: bExecSQL = true
  Dim sActionFileName : sActionFileName = ""
  Dim sWhere : sWhere = "" 
  Dim bErr : bErr = False
  Dim pPKMLD_KOSTEN_KEY : pPKMLD_KOSTEN_KEY = ""
  Dim fldMLD_KOSTEN_CODE : fldMLD_KOSTEN_CODE = ""
  Dim fldMLD_KOSTEN_OMSCHRIJVING : fldMLD_KOSTEN_OMSCHRIJVING = ""
  Dim fldMLD_KOSTEN_TYPE : fldMLD_KOSTEN_TYPE = ""
  Dim fldMLD_KOSTEN_EENHEID : fldMLD_KOSTEN_EENHEID = ""
  Dim fldMLD_KOSTEN_KOSTEN : fldMLD_KOSTEN_KOSTEN = ""
'-------------------------------

'-------------------------------
' KostenRecord Action begin
'-------------------------------
  sActionFileName = "mld_kostengrid.asp"

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

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

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


'-------------------------------
' Load all form fields into variables
'-------------------------------
  fldMLD_KOSTEN_CODE = GetParam("MLD_KOSTEN_CODE")
  fldMLD_KOSTEN_OMSCHRIJVING = GetParam("MLD_KOSTEN_OMSCHRIJVING")
  fldMLD_KOSTEN_TYPE = GetParam("MLD_KOSTEN_TYPE")
  fldMLD_KOSTEN_EENHEID = GetParam("MLD_KOSTEN_EENHEID")
  fldMLD_KOSTEN_KOSTEN = GetParam("MLD_KOSTEN_KOSTEN")

'-------------------------------
' Validate fields
'-------------------------------
  if sAction = "insert" or sAction = "update" then
    if IsEmpty(fldMLD_KOSTEN_OMSCHRIJVING) then
      sKostenRecordErr = sKostenRecordErr & "De waarde in veld Omschrijving is verplicht.<br>"
    end if
    if IsEmpty(fldMLD_KOSTEN_TYPE) then
      sKostenRecordErr = sKostenRecordErr & "De waarde in veld Type is verplicht.<br>"
    end if
    if not isNumeric(fldMLD_KOSTEN_TYPE) then
      sKostenRecordErr = sKostenRecordErr & "De waarde in veld Type is niet correct.<br>"
    end if
    if not isNumeric(fldMLD_KOSTEN_KOSTEN) then
      sKostenRecordErr = sKostenRecordErr & "De waarde in veld Kosten is niet correct.<br>"
    end if
'-------------------------------
' KostenRecord Check Event begin
fldMLD_KOSTEN_KOSTEN = SafeToDouble(fldMLD_KOSTEN_KOSTEN)
' KostenRecord Check Event end
'-------------------------------
    If len(sKostenRecordErr) > 0 then
      exit sub
    end if
  end if
'-------------------------------


'-------------------------------
' Create SQL statement
'-------------------------------
  select case sAction
    case "insert"
'-------------------------------
' KostenRecord Insert Event begin
' KostenRecord Insert Event end
'-------------------------------
      sSQL = "insert into MLD_KOSTEN (" & _
          "MLD_KOSTEN_CODE," & _
          "MLD_KOSTEN_OMSCHRIJVING," & _
          "MLD_KOSTEN_TYPE," & _
          "MLD_KOSTEN_EENHEID," & _
          "MLD_KOSTEN_KOSTEN)" & _
          " values (" & _
          ToSQL(fldMLD_KOSTEN_CODE, "Text") & "," & _
          ToSQL(fldMLD_KOSTEN_OMSCHRIJVING, "Text") & "," & _
          ToSQL(fldMLD_KOSTEN_TYPE, "Number") & "," & _
          ToSQL(fldMLD_KOSTEN_EENHEID, "Text") & "," & _
          ToSQL(fldMLD_KOSTEN_KOSTEN, "Number") & _
          ")"
    case "update"
'-------------------------------
' KostenRecord Update Event begin
' KostenRecord Update Event end
'-------------------------------
      sSQL = "update MLD_KOSTEN set " & _
        "MLD_KOSTEN_CODE=" & ToSQL(fldMLD_KOSTEN_CODE, "Text") & _
        ",MLD_KOSTEN_OMSCHRIJVING=" & ToSQL(fldMLD_KOSTEN_OMSCHRIJVING, "Text") & _
        ",MLD_KOSTEN_TYPE=" & ToSQL(fldMLD_KOSTEN_TYPE, "Number") & _
        ",MLD_KOSTEN_EENHEID=" & ToSQL(fldMLD_KOSTEN_EENHEID, "Text") & _
        ",MLD_KOSTEN_KOSTEN=" & ToSQL(fldMLD_KOSTEN_KOSTEN, "Number")
      sSQL = sSQL & " where " & sWhere
    case "delete"
'-------------------------------
' KostenRecord Delete Event begin
sSql = "update mld_kosten set mld_kosten_verwijder="+sysdate+" where mld_kosten_key = " & ToSQL(getParam("PK_MLD_KOSTEN_KEY"), "Number")
' KostenRecord Delete Event end
'-------------------------------
      if sSQL = "" then
      sSQL = "delete from MLD_KOSTEN where " & sWhere
      end if
  end select
'-------------------------------
'-------------------------------
' KostenRecord BeforeExecute Event begin
' KostenRecord BeforeExecute Event end
'-------------------------------

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

'===============================
' Display Record Form
'-------------------------------
Sub KostenRecord_Show()
'-------------------------------
' KostenRecord Show begin
'-------------------------------
  Dim sWhere : sWhere = ""
  Dim sFormTitle: sFormTitle = "Details kosten"
  Dim bPK : bPK = True

'-------------------------------
' Load primary key and form parameters
'-------------------------------
  if sKostenRecordErr = "" then
    pMLD_KOSTEN_KEY = GetParam("MLD_KOSTEN_KEY")
    SetVar "KostenRecordError", ""
  else
    fldMLD_KOSTEN_CODE = GetParam("MLD_KOSTEN_CODE")
    fldMLD_KOSTEN_OMSCHRIJVING = GetParam("MLD_KOSTEN_OMSCHRIJVING")
    fldMLD_KOSTEN_TYPE = GetParam("MLD_KOSTEN_TYPE")
    fldMLD_KOSTEN_EENHEID = GetParam("MLD_KOSTEN_EENHEID")
    fldMLD_KOSTEN_KOSTEN = GetParam("MLD_KOSTEN_KOSTEN")
    pMLD_KOSTEN_KEY = GetParam("PK_MLD_KOSTEN_KEY")
    SetVar "sKostenRecordErr", sKostenRecordErr
    SetVar "FormTitle", sFormTitle
    Parse "KostenRecordError", False
  end if
'-------------------------------

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

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

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

  if IsEmpty(pMLD_KOSTEN_KEY) then bPK = False
  
  sWhere = sWhere & "MLD_KOSTEN_KEY=" & ToSQL(pMLD_KOSTEN_KEY, "Number")
  SetVar "PK_MLD_KOSTEN_KEY", pMLD_KOSTEN_KEY
'-------------------------------
'-------------------------------
' KostenRecord Open Event begin
' KostenRecord Open Event end
'-------------------------------

  SetVar "FormTitle", sFormTitle

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

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

'-------------------------------
' Load data from recordset when form displayed first time
'-------------------------------
    if sKostenRecordErr = "" then
      fldMLD_KOSTEN_CODE = GetValue(rs, "MLD_KOSTEN_CODE")
      fldMLD_KOSTEN_OMSCHRIJVING = GetValue(rs, "MLD_KOSTEN_OMSCHRIJVING")
      fldMLD_KOSTEN_TYPE = GetValue(rs, "MLD_KOSTEN_TYPE")
      fldMLD_KOSTEN_EENHEID = GetValue(rs, "MLD_KOSTEN_EENHEID")
      fldMLD_KOSTEN_KOSTEN = GetValue(rs, "MLD_KOSTEN_KOSTEN")
    end if
    SetVar "KostenRecordInsert", ""
    Parse "KostenRecordEdit", False
'-------------------------------
' KostenRecord ShowEdit Event begin
' KostenRecord ShowEdit Event end
'-------------------------------
  else
    if sKostenRecordErr = "" then
      fldMLD_KOSTEN_TYPE= "2"
    end if
    SetVar "KostenRecordEdit", ""
    Parse "KostenRecordInsert", False
'-------------------------------
' KostenRecord ShowInsert Event begin
' KostenRecord ShowInsert Event end
'-------------------------------
  end if
  Parse "KostenRecordCancel", false
'-------------------------------
' KostenRecord Show Event begin
' KostenRecord Show Event end
'-------------------------------

'-------------------------------
' Show form field
'-------------------------------
      SetVar "MLD_KOSTEN_KEY", ToHTML(fldMLD_KOSTEN_KEY)
      SetVar "MLD_KOSTEN_CODE", ToHTML(fldMLD_KOSTEN_CODE)
      SetVar "MLD_KOSTEN_OMSCHRIJVING", ToHTML(fldMLD_KOSTEN_OMSCHRIJVING)
      SetVar "KostenRecordLBMLD_KOSTEN_TYPE", ""
      LOV = Split(""&FCLTLCL("2;Hoeveelheid;1;Vinkje")&"", ";")
      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_KOSTEN_TYPE) then SetVar "Selected", "SELECTED" else SetVar "Selected", ""
          Parse "KostenRecordLBMLD_KOSTEN_TYPE", True
        next
      end if
    
      SetVar "MLD_KOSTEN_EENHEID", ToHTML(fldMLD_KOSTEN_EENHEID)
      SetVar "MLD_KOSTEN_KOSTEN", ToHTML(fldMLD_KOSTEN_KOSTEN)
  Parse "FormKostenRecord", False

'-------------------------------
' KostenRecord Close Event begin
' KostenRecord Close Event end
'-------------------------------

Set rs = Nothing

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