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

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


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


'===============================
' fac_profielwaarderecord PageSecurity begin
' fac_profielwaarderecord PageSecurity end
'===============================

'===============================
' fac_profielwaarderecord Open Event begin
' fac_profielwaarderecord Open Event end
'===============================

'===============================
' fac_profielwaarderecord OpenAnyPage Event begin
' fac_profielwaarderecord OpenAnyPage Event end
'===============================

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

' fac_profielwaarderecord Show begin
'===============================
' Perform the form's action
'-------------------------------
' Initialize error variables
'-------------------------------
sProfielWaardeRecordErr = ""

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

' fac_profielwaarderecord Show end

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

' fac_profielwaarderecord Close Event begin
' fac_profielwaarderecord Close Event end

cn.Close
Set cn = Nothing
UnloadTemplate
'===============================
'===============================
' Action of the Record Form
'-------------------------------
Sub ProfielWaardeRecordAction(sAction)
'-------------------------------
' Initialize variables  
'-------------------------------
  Dim bExecSQL: bExecSQL = true
  Dim sActionFileName : sActionFileName = ""
  Dim sParams : sParams = "?"
  Dim sWhere : sWhere = "" 
  Dim bErr : bErr = False
  Dim pPKFAC_PROFIELWAARDE_KEY : pPKFAC_PROFIELWAARDE_KEY = ""
  Dim fldFAC_PROFIEL_KEY : fldFAC_PROFIEL_KEY = ""
  Dim fldINS_DISCIPLINE_KEY : fldINS_DISCIPLINE_KEY = ""
  Dim fldFAC_PROFIELWAARDE_LIMIET : fldFAC_PROFIELWAARDE_LIMIET = ""
'-------------------------------

'-------------------------------
' ProfielWaardeRecord Action begin
'-------------------------------
  sActionFileName = "fac_profielwaardegrid.asp"
  sParams = sParams & "FAC_PROFIEL_KEY=" & ToURL(GetParam("Trn_FAC_PROFIEL_KEY"))

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

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

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


'-------------------------------
' Load all form fields into variables
'-------------------------------
  fldFAC_PROFIELWAARDE_KEY = GetParam("Rqd_FAC_PROFIELWAARDE_KEY")
  fldFAC_PROFIEL_KEY = GetParam("FAC_PROFIEL_KEY")
  fldINS_DISCIPLINE_KEY = GetParam("INS_DISCIPLINE_KEY")
  fldFAC_PROFIELWAARDE_LIMIET = GetParam("FAC_PROFIELWAARDE_LIMIET")

'-------------------------------
' Validate fields
'-------------------------------
  if sAction = "insert" or sAction = "update" then
    if IsEmpty(fldFAC_PROFIELWAARDE_LIMIET) then
      sProfielWaardeRecordErr = sProfielWaardeRecordErr & "De waarde in veld Limiet is verplicht.<br>"
    end if
    if not isNumeric(fldFAC_PROFIEL_KEY) then
      sProfielWaardeRecordErr = sProfielWaardeRecordErr & "De waarde in veld Profiel is niet correct.<br>"
    end if
    if not isNumeric(fldINS_DISCIPLINE_KEY) then
      sProfielWaardeRecordErr = sProfielWaardeRecordErr & "De waarde in veld Vakgroep/Catalogus is niet correct.<br>"
    end if
    if not isNumeric(fldFAC_PROFIELWAARDE_LIMIET) then
      sProfielWaardeRecordErr = sProfielWaardeRecordErr & "De waarde in veld Limiet is niet correct.<br>"
    end if
'-------------------------------
' ProfielWaardeRecord Check Event begin
' ProfielWaardeRecord Check Event end
'-------------------------------
    If len(sProfielWaardeRecordErr) > 0 then
      exit sub
    end if
  end if
'-------------------------------


'-------------------------------
' Create SQL statement
'-------------------------------
  select case sAction
    case "insert"
'-------------------------------
' ProfielWaardeRecord Insert Event begin
' ProfielWaardeRecord Insert Event end
'-------------------------------
      sSQL = "insert into FAC_PROFIELWAARDE (" & _
          "FAC_PROFIELWAARDE_KEY," & _
          "FAC_PROFIEL_KEY," & _
          "INS_DISCIPLINE_KEY," & _
          "FAC_PROFIELWAARDE_LIMIET)" & _
          " values (" & _
          ToSQL(fldFAC_PROFIELWAARDE_KEY, "Number") & "," & _
          ToSQL(fldFAC_PROFIEL_KEY, "Number") & "," & _
          ToSQL(fldINS_DISCIPLINE_KEY, "Number") & "," & _
          ToSQL(fldFAC_PROFIELWAARDE_LIMIET, "Number") & _
          ")"
    case "update"
'-------------------------------
' ProfielWaardeRecord Update Event begin
' ProfielWaardeRecord Update Event end
'-------------------------------
      sSQL = "update FAC_PROFIELWAARDE set " & _
        "FAC_PROFIEL_KEY=" & ToSQL(fldFAC_PROFIEL_KEY, "Number") & _
        ",INS_DISCIPLINE_KEY=" & ToSQL(fldINS_DISCIPLINE_KEY, "Number") & _
        ",FAC_PROFIELWAARDE_LIMIET=" & ToSQL(fldFAC_PROFIELWAARDE_LIMIET, "Number")
      sSQL = sSQL & " where " & sWhere
    case "delete"
'-------------------------------
' ProfielWaardeRecord Delete Event begin
' ProfielWaardeRecord Delete Event end
'-------------------------------
      sSQL = "delete from FAC_PROFIELWAARDE where " & sWhere
  end select
'-------------------------------
'-------------------------------
' ProfielWaardeRecord BeforeExecute Event begin
' ProfielWaardeRecord BeforeExecute Event end
'-------------------------------

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

'===============================
' Display Record Form
'-------------------------------
Sub ProfielWaardeRecord_Show()
'-------------------------------
' ProfielWaardeRecord Show begin
'-------------------------------
  Dim sWhere : sWhere = ""
  Dim sFormTitle: sFormTitle = "Details profielwaarde"
  Dim bPK : bPK = True

'-------------------------------
' Load primary key and form parameters
'-------------------------------
  if sProfielWaardeRecordErr = "" then
    fldFAC_PROFIELWAARDE_KEY = GetParam("FAC_PROFIELWAARDE_KEY")
    fldFAC_PROFIEL_KEY = GetParam("FAC_PROFIEL_KEY")
    SetVar "Trn_FAC_PROFIEL_KEY", GetParam("FAC_PROFIEL_KEY")
    SetVar "Rqd_FAC_PROFIELWAARDE_KEY", GetParam("FAC_PROFIELWAARDE_KEY")
    pFAC_PROFIELWAARDE_KEY = GetParam("FAC_PROFIELWAARDE_KEY")
    SetVar "ProfielWaardeRecordError", ""
  else
    fldFAC_PROFIEL_KEY = GetParam("FAC_PROFIEL_KEY")
    fldINS_DISCIPLINE_KEY = GetParam("INS_DISCIPLINE_KEY")
    fldFAC_PROFIELWAARDE_LIMIET = GetParam("FAC_PROFIELWAARDE_LIMIET")
    SetVar "Rqd_FAC_PROFIELWAARDE_KEY", GetParam("Rqd_FAC_PROFIELWAARDE_KEY")
    SetVar "Trn_FAC_PROFIEL_KEY", GetParam("Trn_FAC_PROFIEL_KEY")
    pFAC_PROFIELWAARDE_KEY = GetParam("PK_FAC_PROFIELWAARDE_KEY")
    SetVar "sProfielWaardeRecordErr", sProfielWaardeRecordErr
    SetVar "FormTitle", sFormTitle
    Parse "ProfielWaardeRecordError", False
  end if
'-------------------------------

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

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

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

  if IsEmpty(pFAC_PROFIELWAARDE_KEY) then bPK = False
  
  sWhere = sWhere & "FAC_PROFIELWAARDE_KEY=" & ToSQL(pFAC_PROFIELWAARDE_KEY, "Number")
  SetVar "PK_FAC_PROFIELWAARDE_KEY", pFAC_PROFIELWAARDE_KEY
'-------------------------------
'-------------------------------
' ProfielWaardeRecord Open Event begin
' ProfielWaardeRecord Open Event end
'-------------------------------

  SetVar "FormTitle", sFormTitle

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

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

'-------------------------------
' Load data from recordset when form displayed first time
'-------------------------------
    if sProfielWaardeRecordErr = "" then
      fldFAC_PROFIEL_KEY = GetValue(rs, "FAC_PROFIEL_KEY")
      fldINS_DISCIPLINE_KEY = GetValue(rs, "INS_DISCIPLINE_KEY")
      fldFAC_PROFIELWAARDE_LIMIET = GetValue(rs, "FAC_PROFIELWAARDE_LIMIET")
    end if
    SetVar "ProfielWaardeRecordInsert", ""
    Parse "ProfielWaardeRecordEdit", False
'-------------------------------
' ProfielWaardeRecord ShowEdit Event begin
' ProfielWaardeRecord ShowEdit Event end
'-------------------------------
  else
    if sProfielWaardeRecordErr = "" then
      fldFAC_PROFIELWAARDE_KEY = ToHTML(GetParam("FAC_PROFIELWAARDE_KEY"))
      fldFAC_PROFIEL_KEY = ToHTML(GetParam("FAC_PROFIEL_KEY"))
    end if
    SetVar "ProfielWaardeRecordEdit", ""
    Parse "ProfielWaardeRecordInsert", False
'-------------------------------
' ProfielWaardeRecord ShowInsert Event begin
' ProfielWaardeRecord ShowInsert Event end
'-------------------------------
  end if
  Parse "ProfielWaardeRecordCancel", false
'-------------------------------
' ProfielWaardeRecord Show Event begin
' ProfielWaardeRecord Show Event end
'-------------------------------

'-------------------------------
' Show form field
'-------------------------------
      SetVar "FAC_PROFIELWAARDE_KEY", ToHTML(fldFAC_PROFIELWAARDE_KEY)
      SetVar "ProfielWaardeRecordLBFAC_PROFIEL_KEY", ""
      openrs rsFAC_PROFIEL_KEY, "select FAC_PROFIEL_KEY, FAC_PROFIEL_OMSCHRIJVING from FAC_PROFIEL order by 2"
      while not rsFAC_PROFIEL_KEY.EOF
        SetVar "ID", GetValue(rsFAC_PROFIEL_KEY, 0) : SetVar "Value", GetValue(rsFAC_PROFIEL_KEY, 1)
        if cstr(GetValue(rsFAC_PROFIEL_KEY, 0)) = cstr(fldFAC_PROFIEL_KEY) then SetVar "Selected", "SELECTED" else SetVar "Selected", ""
        Parse "ProfielWaardeRecordLBFAC_PROFIEL_KEY", True
        rsFAC_PROFIEL_KEY.MoveNext
      wend
      set rsFAC_PROFIEL_KEY = nothing
    
      SetVar "ProfielWaardeRecordLBINS_DISCIPLINE_KEY", ""
      openrs rsINS_DISCIPLINE_KEY, "select INS_DISCIPLINE_KEY , 'Catalogus: '||INS_DISCIPLINE_OMSCHRIJVING  from BES_V_AANWEZIGDISCIPLINE union all select INS_DISCIPLINE_KEY ,      'Vakgroep: '||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 rsINS_DISCIPLINE_KEY.EOF
        SetVar "ID", GetValue(rsINS_DISCIPLINE_KEY, 0) : SetVar "Value", GetValue(rsINS_DISCIPLINE_KEY, 1)
        if cstr(GetValue(rsINS_DISCIPLINE_KEY, 0)) = cstr(fldINS_DISCIPLINE_KEY) then SetVar "Selected", "SELECTED" else SetVar "Selected", ""
        Parse "ProfielWaardeRecordLBINS_DISCIPLINE_KEY", True
        rsINS_DISCIPLINE_KEY.MoveNext
      wend
      set rsINS_DISCIPLINE_KEY = nothing
    
      SetVar "FAC_PROFIELWAARDE_LIMIET", ToHTML(fldFAC_PROFIELWAARDE_LIMIET)
  Parse "FormProfielWaardeRecord", False

'-------------------------------
' ProfielWaardeRecord Close Event begin
' ProfielWaardeRecord Close Event end
'-------------------------------

Set rs = Nothing

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