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

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


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


'===============================
' fac_profielrecord PageSecurity begin
' fac_profielrecord PageSecurity end
'===============================

'===============================
' fac_profielrecord Open Event begin
' fac_profielrecord Open Event end
'===============================

'===============================
' fac_profielrecord OpenAnyPage Event begin
' fac_profielrecord OpenAnyPage Event end
'===============================

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

' fac_profielrecord Show begin
'===============================
' Perform the form's action
'-------------------------------
' Initialize error variables
'-------------------------------
sProfielRecordErr = ""

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

' fac_profielrecord Show end

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

' fac_profielrecord Close Event begin
' fac_profielrecord Close Event end

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

'-------------------------------
' ProfielRecord Action begin
'-------------------------------
  sActionFileName = "fac_profielgrid.asp"

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

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

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


'-------------------------------
' Load all form fields into variables
'-------------------------------
  fldFAC_PROFIEL_OMSCHRIJVING = GetParam("FAC_PROFIEL_OMSCHRIJVING")
  fldFAC_PROFIEL_LIMIET = GetParam("FAC_PROFIEL_LIMIET")

'-------------------------------
' Validate fields
'-------------------------------
  if sAction = "insert" or sAction = "update" then
    if IsEmpty(fldFAC_PROFIEL_OMSCHRIJVING) then
      sProfielRecordErr = sProfielRecordErr & "De waarde in veld Omschrijving is verplicht.<br>"
    end if
    if not isNumeric(fldFAC_PROFIEL_LIMIET) then
      sProfielRecordErr = sProfielRecordErr & "De waarde in veld Limiet voor alle disciplines is niet correct.<br>"
    end if
'-------------------------------
' ProfielRecord Check Event begin
' ProfielRecord Check Event end
'-------------------------------
    If len(sProfielRecordErr) > 0 then
      exit sub
    end if
  end if
'-------------------------------


'-------------------------------
' Create SQL statement
'-------------------------------
  select case sAction
    case "insert"
'-------------------------------
' ProfielRecord Insert Event begin
' ProfielRecord Insert Event end
'-------------------------------
      sSQL = "insert into FAC_PROFIEL (" & _
          "FAC_PROFIEL_OMSCHRIJVING," & _
          "FAC_PROFIEL_LIMIET)" & _
          " values (" & _
          ToSQL(fldFAC_PROFIEL_OMSCHRIJVING, "Text") & "," & _
          ToSQL(fldFAC_PROFIEL_LIMIET, "Number") & _
          ")"
    case "update"
'-------------------------------
' ProfielRecord Update Event begin
' ProfielRecord Update Event end
'-------------------------------
      sSQL = "update FAC_PROFIEL set " & _
        "FAC_PROFIEL_OMSCHRIJVING=" & ToSQL(fldFAC_PROFIEL_OMSCHRIJVING, "Text") & _
        ",FAC_PROFIEL_LIMIET=" & ToSQL(fldFAC_PROFIEL_LIMIET, "Number")
      sSQL = sSQL & " where " & sWhere
    case "delete"
'-------------------------------
' ProfielRecord Delete Event begin
' ProfielRecord Delete Event end
'-------------------------------
      sSQL = "delete from FAC_PROFIEL where " & sWhere
  end select
'-------------------------------
'-------------------------------
' ProfielRecord BeforeExecute Event begin
' ProfielRecord BeforeExecute Event end
'-------------------------------

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

'===============================
' Display Record Form
'-------------------------------
Sub ProfielRecord_Show()
'-------------------------------
' ProfielRecord Show begin
'-------------------------------
  Dim sWhere : sWhere = ""
  Dim sFormTitle: sFormTitle = "Details profielen"
  Dim bPK : bPK = True

'-------------------------------
' Load primary key and form parameters
'-------------------------------
  if sProfielRecordErr = "" then
    pFAC_PROFIEL_KEY = GetParam("FAC_PROFIEL_KEY")
    SetVar "ProfielRecordError", ""
  else
    fldFAC_PROFIEL_OMSCHRIJVING = GetParam("FAC_PROFIEL_OMSCHRIJVING")
    fldFAC_PROFIEL_LIMIET = GetParam("FAC_PROFIEL_LIMIET")
    pFAC_PROFIEL_KEY = GetParam("PK_FAC_PROFIEL_KEY")
    SetVar "sProfielRecordErr", sProfielRecordErr
    SetVar "FormTitle", sFormTitle
    Parse "ProfielRecordError", False
  end if
'-------------------------------

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

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

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

  if IsEmpty(pFAC_PROFIEL_KEY) then bPK = False
  
  sWhere = sWhere & "FAC_PROFIEL_KEY=" & ToSQL(pFAC_PROFIEL_KEY, "Number")
  SetVar "PK_FAC_PROFIEL_KEY", pFAC_PROFIEL_KEY
'-------------------------------
'-------------------------------
' ProfielRecord Open Event begin
' ProfielRecord Open Event end
'-------------------------------

  SetVar "FormTitle", sFormTitle

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

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

'-------------------------------
' Load data from recordset when form displayed first time
'-------------------------------
    if sProfielRecordErr = "" then
      fldFAC_PROFIEL_OMSCHRIJVING = GetValue(rs, "FAC_PROFIEL_OMSCHRIJVING")
      fldFAC_PROFIEL_LIMIET = GetValue(rs, "FAC_PROFIEL_LIMIET")
    end if
    SetVar "ProfielRecordInsert", ""
    Parse "ProfielRecordEdit", False
'-------------------------------
' ProfielRecord ShowEdit Event begin
' ProfielRecord ShowEdit Event end
'-------------------------------
  else
    SetVar "ProfielRecordEdit", ""
    Parse "ProfielRecordInsert", False
'-------------------------------
' ProfielRecord ShowInsert Event begin
' ProfielRecord ShowInsert Event end
'-------------------------------
  end if
  Parse "ProfielRecordCancel", false
'-------------------------------
' ProfielRecord Show Event begin
' ProfielRecord Show Event end
'-------------------------------

'-------------------------------
' Show form field
'-------------------------------
      SetVar "FAC_PROFIEL_KEY", ToHTML(fldFAC_PROFIEL_KEY)
      SetVar "FAC_PROFIEL_OMSCHRIJVING", ToHTML(fldFAC_PROFIEL_OMSCHRIJVING)
      SetVar "FAC_PROFIEL_LIMIET", ToHTML(fldFAC_PROFIEL_LIMIET)
  Parse "FormProfielRecord", False

'-------------------------------
' ProfielRecord Close Event begin
' ProfielRecord Close Event end
'-------------------------------

Set rs = Nothing

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