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

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


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


'===============================
' mld_dienstniveaurecord1 PageSecurity begin
' mld_dienstniveaurecord1 PageSecurity end
'===============================

'===============================
' mld_dienstniveaurecord1 Open Event begin
' mld_dienstniveaurecord1 Open Event end
'===============================

'===============================
' mld_dienstniveaurecord1 OpenAnyPage Event begin
' mld_dienstniveaurecord1 OpenAnyPage Event end
'===============================

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

' mld_dienstniveaurecord1 Show begin
'===============================
' Perform the form's action
'-------------------------------
' Initialize error variables
'-------------------------------
sDienstniveauRecordErr = ""
sDienstpakketGridErr = ""

'-------------------------------
' Select the FormAction
'-------------------------------
Select Case sForm
  Case "DienstniveauRecord"
    DienstniveauRecordAction(sAction)
  Case "DienstpakketGrid"
    DienstpakketGridAction(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
'-------------------------------
DienstniveauRecord_Show
DienstpakketSearch_Show
DienstpakketGrid_Show
'-------------------------------
' Process page templates
'-------------------------------
Parse "main", False
'-------------------------------
' Output the page to the browser
'-------------------------------
Response.write PrintVar("main")

' mld_dienstniveaurecord1 Show end

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

' mld_dienstniveaurecord1 Close Event begin
' mld_dienstniveaurecord1 Close Event end

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

'-------------------------------
' DienstniveauRecord Action begin
'-------------------------------
  sActionFileName = "mld_dienstniveaugrid.asp"

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

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

'-------------------------------
' Load all form fields into variables
'-------------------------------

'-------------------------------
' Validate fields
'-------------------------------
  if sAction = "insert" or sAction = "update" then
'-------------------------------
' DienstniveauRecord Check Event begin
' DienstniveauRecord Check Event end
'-------------------------------
    If len(sDienstniveauRecordErr) > 0 then
      exit sub
    end if
  end if
'-------------------------------

'-------------------------------
' DienstniveauRecord BeforeExecute Event begin
' DienstniveauRecord BeforeExecute Event end
'-------------------------------

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

'===============================
' Display Record Form
'-------------------------------
Sub DienstniveauRecord_Show()
'-------------------------------
' DienstniveauRecord Show begin
'-------------------------------
  Dim sWhere : sWhere = ""
  Dim sFormTitle: sFormTitle = "Details dienstniveau"
  Dim bPK : bPK = True

'-------------------------------
' Load primary key and form parameters
'-------------------------------
  if sDienstniveauRecordErr = "" then
    pMLD_DIENSTNIVEAU_KEY = GetParam("MLD_DIENSTNIVEAU_KEY")
    SetVar "DienstniveauRecordError", ""
  else
    pMLD_DIENSTNIVEAU_KEY = GetParam("PK_MLD_DIENSTNIVEAU_KEY")
    SetVar "sDienstniveauRecordErr", sDienstniveauRecordErr
    SetVar "FormTitle", sFormTitle
    Parse "DienstniveauRecordError", False
  end if
'-------------------------------

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

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

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

  if IsEmpty(pMLD_DIENSTNIVEAU_KEY) then bPK = False
  
  sWhere = sWhere & "MLD_DIENSTNIVEAU_KEY=" & ToSQL(pMLD_DIENSTNIVEAU_KEY, "Number")
  SetVar "PK_MLD_DIENSTNIVEAU_KEY", pMLD_DIENSTNIVEAU_KEY
'-------------------------------
'-------------------------------
' DienstniveauRecord Open Event begin
' DienstniveauRecord Open Event end
'-------------------------------

  SetVar "FormTitle", sFormTitle

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

'-------------------------------
' Load all fields into variables from recordset or input parameters
'-------------------------------
  if bIsUpdateMode then
    fldMLD_DIENSTNIVEAU_KEY = GetValue(rs, "MLD_DIENSTNIVEAU_KEY")
    fldMLD_DIENSTNIVEAU_OMSCHR = GetValue(rs, "MLD_DIENSTNIVEAU_OMSCHR")
    SetVar "DienstniveauRecordDelete", ""
    SetVar "DienstniveauRecordUpdate", ""
    SetVar "DienstniveauRecordInsert", ""
'-------------------------------
' DienstniveauRecord ShowEdit Event begin
' DienstniveauRecord ShowEdit Event end
'-------------------------------
  else
    SetVar "DienstniveauRecordEdit", ""
    SetVar "DienstniveauRecordInsert", ""
'-------------------------------
' DienstniveauRecord ShowInsert Event begin
' DienstniveauRecord ShowInsert Event end
'-------------------------------
  end if
  Parse "DienstniveauRecordCancel", false
'-------------------------------
' DienstniveauRecord Show Event begin
' DienstniveauRecord Show Event end
'-------------------------------

'-------------------------------
' Show form field
'-------------------------------
      SetVar "MLD_DIENSTNIVEAU_KEY", ToHTML(fldMLD_DIENSTNIVEAU_KEY)
      SetVar "MLD_DIENSTNIVEAU_OMSCHR", ToHTML(fldMLD_DIENSTNIVEAU_OMSCHR)
  Parse "FormDienstniveauRecord", False

'-------------------------------
' DienstniveauRecord Close Event begin
' DienstniveauRecord Close Event end
'-------------------------------

Set rs = Nothing

'-------------------------------
' DienstniveauRecord Show end
'-------------------------------
End Sub
'===============================
'===============================
' Action of the Record Form
'-------------------------------
Sub DienstpakketGridAction(sAction)
'-------------------------------
' Initialize variables  
'-------------------------------
  Dim bExecSQL: bExecSQL = true
  Dim sActionFileName : sActionFileName = ""
  Dim sParams : sParams = "?"
  Dim sWhere : sWhere = "" 
  Dim bErr : bErr = False
  Dim pPKMLD_DIENSTPAKKET_KEY : pPKMLD_DIENSTPAKKET_KEY = ""
  Dim fldMLD_DIENSTNIVEAU_KEY : fldMLD_DIENSTNIVEAU_KEY = ""
  Dim fldMLD_STDMELDING_KEY : fldMLD_STDMELDING_KEY = ""
'-------------------------------

'-------------------------------
' DienstpakketGrid Action begin
'-------------------------------
  sActionFileName = "mld_dienstniveaurecord.asp"
  sParams = sParams & "MLD_DIENSTNIVEAU_KEY=" & ToURL(GetParam("Trn_MLD_DIENSTNIVEAU_KEY")) & "&"
  sParams = sParams & "MLD_INS_DISCIPLINE_KEY=" & ToURL(GetParam("Trn_MLD_INS_DISCIPLINE_KEY"))

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

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

'-------------------------------
' Load all form fields into variables
'-------------------------------
  fldMLD_DIENSTNIVEAU_KEY = GetParam("MLD_DIENSTNIVEAU_KEY")
  fldMLD_STDMELDING_KEY = GetParam("MLD_STDMELDING_KEY")

'-------------------------------
' Create SQL statement
'-------------------------------
  select case sAction
    case "insert"
'-------------------------------
' DienstpakketGrid Insert Event begin
if false then
    ' We maken hier een dummy select-case om de standaard insert te omzeilen.
    select case sAction
        case "insert"
' DienstpakketGrid Insert Event end
'-------------------------------
      if sSQL = "" then
      sSQL = "insert into MLD_DIENSTPAKKET (" & _
          "MLD_DIENSTNIVEAU_KEY," & _
          "MLD_STDMELDING_KEY)" & _
          " values (" & _
          ToSQL(fldMLD_DIENSTNIVEAU_KEY, "Number") & "," & _
          ToSQL(fldMLD_STDMELDING_KEY, "Number") & _
          ")"
      end if
  end select
'-------------------------------
'-------------------------------
' DienstpakketGrid BeforeExecute Event begin
end if ' Afsluiten overslaan van default insert sql
  '
  ' Multiple insert ipv de default action op insert
  For i = 1 To Request.Form("MLD_STDMELDING_KEY").Count
     sql_m = "INSERT INTO MLD_DIENSTPAKKET " &_
             "( MLD_DIENSTNIVEAU_KEY " &_
             ", MLD_STDMELDING_KEY " &_
             ") VALUES " &_
             "(" & ToSQL(fldMLD_DIENSTNIVEAU_KEY, "Number") &_
             "," & ToSQL(Request.Form("MLD_STDMELDING_KEY")(i), "Number") &_
             ")"
     on error resume next
     cn.execute sql_m
   Next
  '
end select 
' Voorkom uitvoeren van default insert action
bExecSQL = false
' DienstpakketGrid BeforeExecute Event end
'-------------------------------

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

'===============================
' Display Record Form
'-------------------------------
Sub DienstpakketGrid_Show()
'-------------------------------
' DienstpakketGrid Show begin
'-------------------------------
  Dim sWhere : sWhere = ""
  Dim sFormTitle: sFormTitle = "Dienstpakketten"
  Dim bPK : bPK = True

'-------------------------------
' Load primary key and form parameters
'-------------------------------
  if sDienstpakketGridErr = "" then
    fldMLD_DIENSTNIVEAU_KEY = GetParam("MLD_DIENSTNIVEAU_KEY")
    SetVar "Trn_MLD_DIENSTNIVEAU_KEY", GetParam("MLD_DIENSTNIVEAU_KEY")
    SetVar "Trn_MLD_INS_DISCIPLINE_KEY", GetParam("MLD_INS_DISCIPLINE_KEY")
    pMLD_DIENSTPAKKET_KEY = GetParam("MLD_DIENSTPAKKET_KEY")
    SetVar "DienstpakketGridError", ""
  else
    fldMLD_DIENSTPAKKET_KEY = GetParam("MLD_DIENSTPAKKET_KEY")
    fldMLD_DIENSTNIVEAU_KEY = GetParam("MLD_DIENSTNIVEAU_KEY")
    fldMLD_STDMELDING_KEY = GetParam("MLD_STDMELDING_KEY")
    SetVar "Trn_MLD_DIENSTNIVEAU_KEY", GetParam("Trn_MLD_DIENSTNIVEAU_KEY")
    SetVar "Trn_MLD_INS_DISCIPLINE_KEY", GetParam("Trn_MLD_INS_DISCIPLINE_KEY")
    pMLD_DIENSTPAKKET_KEY = GetParam("PK_MLD_DIENSTPAKKET_KEY")
    SetVar "sDienstpakketGridErr", sDienstpakketGridErr
    SetVar "FormTitle", sFormTitle
    Parse "DienstpakketGridError", False
  end if
'-------------------------------

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

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

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

  if IsEmpty(pMLD_DIENSTPAKKET_KEY) then bPK = False
  
  sWhere = sWhere & "MLD_DIENSTPAKKET_KEY=" & ToSQL(pMLD_DIENSTPAKKET_KEY, "Number")
  SetVar "PK_MLD_DIENSTPAKKET_KEY", pMLD_DIENSTPAKKET_KEY
'-------------------------------
'-------------------------------
' DienstpakketGrid Open Event begin
' DienstpakketGrid Open Event end
'-------------------------------

  SetVar "FormTitle", sFormTitle

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

'-------------------------------
' Load all fields into variables from recordset or input parameters
'-------------------------------
  if bIsUpdateMode then
    fldMLD_DIENSTNIVEAU_KEY = GetValue(rs, "MLD_DIENSTNIVEAU_KEY")
    fldMLD_DIENSTPAKKET_KEY = GetValue(rs, "MLD_DIENSTPAKKET_KEY")

'-------------------------------
' Load data from recordset when form displayed first time
'-------------------------------
    if sDienstpakketGridErr = "" then
      fldMLD_STDMELDING_KEY = GetValue(rs, "MLD_STDMELDING_KEY")
    end if
    SetVar "DienstpakketGridDelete", ""
    SetVar "DienstpakketGridUpdate", ""
    SetVar "DienstpakketGridInsert", ""
'-------------------------------
' DienstpakketGrid ShowEdit Event begin
' DienstpakketGrid ShowEdit Event end
'-------------------------------
  else
    if sDienstpakketGridErr = "" then
      fldMLD_DIENSTNIVEAU_KEY = ToHTML(GetParam("MLD_DIENSTNIVEAU_KEY"))
    end if
    SetVar "DienstpakketGridEdit", ""
    Parse "DienstpakketGridInsert", False
'-------------------------------
' DienstpakketGrid ShowInsert Event begin
' DienstpakketGrid ShowInsert Event end
'-------------------------------
  end if
  Parse "DienstpakketGridCancel", false
  if sDienstpakketGridErr = "" then
'-------------------------------
' DienstpakketGrid Show Event begin
pDiscipline = ToHTML(GetParam("MLD_INS_DISCIPLINE_KEY"))
if pDiscipline <> "" then
	pDiscipline = " AND mld_ins_discipline_key = " & ToSQL(pDiscipline, "Number")
end if
' DienstpakketGrid Show Event end
'-------------------------------
  end if

'-------------------------------
' Show form field
'-------------------------------
      SetVar "MLD_DIENSTPAKKET_KEY", ToHTML(fldMLD_DIENSTPAKKET_KEY)
      SetVar "MLD_DIENSTNIVEAU_KEY", ToHTML(fldMLD_DIENSTNIVEAU_KEY)
      SetVar "DienstpakketGridLBMLD_STDMELDING_KEY", ""
      openrs rsMLD_STDMELDING_KEY, "SELECT m.mld_stdmelding_key,             sr.ins_srtdiscipline_prefix          || '-'          || i.ins_discipline_omschrijving          || ' / '          || m.mld_stdmelding_omschrijving     FROM mld_stdmelding m, mld_v_aanwezigdiscipline i, INS_SRTDISCIPLINE sr    WHERE     m.mld_ins_discipline_key = i.ins_discipline_key          AND i.ins_srtdiscipline_key = sr.ins_srtdiscipline_key          AND mld_stdmelding_verwijder IS NULL          " & pDiscipline & "          AND mld_stdmelding_key NOT IN             (SELECT mld_stdmelding_key                FROM mld_dienstpakket               WHERE mld_dienstniveau_key = " & ToSQL(fldMLD_DIENSTNIVEAU_KEY, "Number") & "             ) ORDER BY 2, m.mld_stdmelding_upper"
      while not rsMLD_STDMELDING_KEY.EOF
        SetVar "ID", GetValue(rsMLD_STDMELDING_KEY, 0) : SetVar "Value", GetValue(rsMLD_STDMELDING_KEY, 1)
        if cstr(GetValue(rsMLD_STDMELDING_KEY, 0)) = cstr(fldMLD_STDMELDING_KEY) then SetVar "Selected", "SELECTED" else SetVar "Selected", ""
        Parse "DienstpakketGridLBMLD_STDMELDING_KEY", True
        rsMLD_STDMELDING_KEY.MoveNext
      wend
      set rsMLD_STDMELDING_KEY = nothing
    
  Parse "FormDienstpakketGrid", False

'-------------------------------
' DienstpakketGrid Close Event begin
' DienstpakketGrid Close Event end
'-------------------------------

Set rs = Nothing

'-------------------------------
' DienstpakketGrid Show end
'-------------------------------
End Sub
'===============================

'===============================
' Display Search Form
'-------------------------------
Sub DienstpakketSearch_Show()
  Dim sFormTitle: sFormTitle = "Dienstpakketten"
  Dim sActionFileName: sActionFileName = "mld_dienstniveaurecord1.asp"
  Dim sMLD_INS_DISCIPLINE_KEYDisplayValue: sMLD_INS_DISCIPLINE_KEYDisplayValue = "Alles"

'-------------------------------
' DienstpakketSearch Open Event begin
' DienstpakketSearch Open Event end
'-------------------------------
      SetVar "FormTitle", sFormTitle
      SetVar "ActionPage", sActionFileName
      SetVar "mld_dienstniveau_key", ToHTML(GetParam("mld_dienstniveau_key"))

'-------------------------------
' Set variables with search parameters
'-------------------------------
      fldMLD_INS_DISCIPLINE_KEY = GetParam("MLD_INS_DISCIPLINE_KEY")

'-------------------------------
' DienstpakketSearch Show begin
'-------------------------------


'-------------------------------
' DienstpakketSearch Show Event begin
' DienstpakketSearch Show Event end
'-------------------------------
      SetVar "DienstpakketSearchLBMLD_INS_DISCIPLINE_KEY", ""
      SetVar "Selected", ""
      SetVar "ID", ""
      SetVar "Value", sMLD_INS_DISCIPLINE_KEYDisplayValue
      Parse "DienstpakketSearchLBMLD_INS_DISCIPLINE_KEY", True
      openrs rsMLD_INS_DISCIPLINE_KEY, "SELECT   ins_discipline_key,          sr.ins_srtdiscipline_prefix || '-' || ins_discipline_omschrijving     FROM mld_v_aanwezigdiscipline ml, INS_SRTDISCIPLINE sr    WHERE ml.ins_srtdiscipline_key = sr.ins_srtdiscipline_key ORDER BY 2"
      while not rsMLD_INS_DISCIPLINE_KEY.EOF
        SetVar "ID", GetValue(rsMLD_INS_DISCIPLINE_KEY, 0) : SetVar "Value", GetValue(rsMLD_INS_DISCIPLINE_KEY, 1)
        if cstr(GetValue(rsMLD_INS_DISCIPLINE_KEY, 0)) = cstr(fldMLD_INS_DISCIPLINE_KEY) then SetVar "Selected", "SELECTED" else SetVar "Selected", ""
        Parse "DienstpakketSearchLBMLD_INS_DISCIPLINE_KEY", True
        rsMLD_INS_DISCIPLINE_KEY.MoveNext
      wend
      set rsMLD_INS_DISCIPLINE_KEY = nothing
    

'-------------------------------
' DienstpakketSearch Show end
'-------------------------------

'-------------------------------
' DienstpakketSearch Close Event begin
' DienstpakketSearch Close Event end
'-------------------------------
      Parse "FormDienstpakketSearch", False
End Sub
'===============================

%>