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

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


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


'===============================
' fac_mgtraprecord PageSecurity begin
' fac_mgtraprecord PageSecurity end
'===============================

'===============================
' fac_mgtraprecord Open Event begin
' fac_mgtraprecord Open Event end
'===============================

'===============================
' fac_mgtraprecord OpenAnyPage Event begin
' fac_mgtraprecord OpenAnyPage Event end
'===============================

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

' fac_mgtraprecord Show begin
'===============================
' Perform the form's action
'-------------------------------
' Initialize error variables
'-------------------------------
sMgtrapRecordErr = ""

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

' fac_mgtraprecord Show end

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

' fac_mgtraprecord Close Event begin
' fac_mgtraprecord Close Event end

cn.Close
Set cn = Nothing
UnloadTemplate
'===============================
'===============================
' Action of the Record Form
'-------------------------------
Sub MgtrapRecordAction(sAction)
'-------------------------------
' Initialize variables  
'-------------------------------
  Dim bExecSQL: bExecSQL = true
  Dim sActionFileName : sActionFileName = ""
  Dim sWhere : sWhere = "" 
  Dim bErr : bErr = False
  Dim pPKFAC_MGTRAP_KEY : pPKFAC_MGTRAP_KEY = ""
  Dim fldFAC_MGTRAP_OMSCHRIJVING : fldFAC_MGTRAP_OMSCHRIJVING = ""
  Dim fldFAC_MGTRAP_VIEW_NAME : fldFAC_MGTRAP_VIEW_NAME = ""
  Dim fldFAC_MGTRAP_INFO : fldFAC_MGTRAP_INFO = ""
  Dim fldFAC_MGTRAP_WAARDE1 : fldFAC_MGTRAP_WAARDE1 = ""
  Dim fldFAC_MGTRAP_WAARDE2 : fldFAC_MGTRAP_WAARDE2 = ""
  Dim fldFAC_MGTRAP_WAARDE3 : fldFAC_MGTRAP_WAARDE3 = ""
  Dim fldFAC_MGTRAP_WAARDE4 : fldFAC_MGTRAP_WAARDE4 = ""
  Dim fldFAC_FUNCTIE_KEY : fldFAC_FUNCTIE_KEY = ""
'-------------------------------

'-------------------------------
' MgtrapRecord Action begin
'-------------------------------
  sActionFileName = "fac_mgtrapgrid.asp"

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

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

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


'-------------------------------
' Load all form fields into variables
'-------------------------------
  fldFAC_MGTRAP_OMSCHRIJVING = GetParam("FAC_MGTRAP_OMSCHRIJVING")
  fldFAC_MGTRAP_VIEW_NAME = GetParam("FAC_MGTRAP_VIEW_NAME")
  fldFAC_MGTRAP_INFO = GetParam("FAC_MGTRAP_INFO")
  fldFAC_MGTRAP_WAARDE1 = GetParam("FAC_MGTRAP_WAARDE1")
  fldFAC_MGTRAP_WAARDE2 = GetParam("FAC_MGTRAP_WAARDE2")
  fldFAC_MGTRAP_WAARDE3 = GetParam("FAC_MGTRAP_WAARDE3")
  fldFAC_MGTRAP_WAARDE4 = GetParam("FAC_MGTRAP_WAARDE4")
  fldFAC_FUNCTIE_KEY = GetParam("FAC_FUNCTIE_KEY")

'-------------------------------
' Validate fields
'-------------------------------
  if sAction = "insert" or sAction = "update" then
    if not isNumeric(fldFAC_MGTRAP_WAARDE1) then
      sMgtrapRecordErr = sMgtrapRecordErr & "De waarde in veld Waarde 1 is niet correct.<br>"
    end if
    if not isNumeric(fldFAC_MGTRAP_WAARDE2) then
      sMgtrapRecordErr = sMgtrapRecordErr & "De waarde in veld Waarde 2 is niet correct.<br>"
    end if
    if not isNumeric(fldFAC_MGTRAP_WAARDE3) then
      sMgtrapRecordErr = sMgtrapRecordErr & "De waarde in veld Waarde 3 is niet correct.<br>"
    end if
    if not isNumeric(fldFAC_MGTRAP_WAARDE4) then
      sMgtrapRecordErr = sMgtrapRecordErr & "De waarde in veld Waarde 4 is niet correct.<br>"
    end if
    if not isNumeric(fldFAC_FUNCTIE_KEY) then
      sMgtrapRecordErr = sMgtrapRecordErr & "De waarde in veld Autorisatie als is niet correct.<br>"
    end if
'-------------------------------
' MgtrapRecord Check Event begin
' MgtrapRecord Check Event end
'-------------------------------
    If len(sMgtrapRecordErr) > 0 then
      exit sub
    end if
  end if
'-------------------------------


'-------------------------------
' Create SQL statement
'-------------------------------
  select case sAction
    case "insert"
'-------------------------------
' MgtrapRecord Insert Event begin
' MgtrapRecord Insert Event end
'-------------------------------
      sSQL = "insert into FAC_MGTRAP (" & _
          "FAC_MGTRAP_OMSCHRIJVING," & _
          "FAC_MGTRAP_VIEW_NAME," & _
          "FAC_MGTRAP_INFO," & _
          "FAC_MGTRAP_WAARDE1," & _
          "FAC_MGTRAP_WAARDE2," & _
          "FAC_MGTRAP_WAARDE3," & _
          "FAC_MGTRAP_WAARDE4," & _
          "FAC_FUNCTIE_KEY)" & _
          " values (" & _
          ToSQL(fldFAC_MGTRAP_OMSCHRIJVING, "Text") & "," & _
          ToSQL(fldFAC_MGTRAP_VIEW_NAME, "Text") & "," & _
          ToSQL(fldFAC_MGTRAP_INFO, "Text") & "," & _
          ToSQL(fldFAC_MGTRAP_WAARDE1, "Number") & "," & _
          ToSQL(fldFAC_MGTRAP_WAARDE2, "Number") & "," & _
          ToSQL(fldFAC_MGTRAP_WAARDE3, "Number") & "," & _
          ToSQL(fldFAC_MGTRAP_WAARDE4, "Number") & "," & _
          ToSQL(fldFAC_FUNCTIE_KEY, "Number") & _
          ")"
    case "update"
'-------------------------------
' MgtrapRecord Update Event begin
' MgtrapRecord Update Event end
'-------------------------------
      sSQL = "update FAC_MGTRAP set " & _
        "FAC_MGTRAP_OMSCHRIJVING=" & ToSQL(fldFAC_MGTRAP_OMSCHRIJVING, "Text") & _
        ",FAC_MGTRAP_VIEW_NAME=" & ToSQL(fldFAC_MGTRAP_VIEW_NAME, "Text") & _
        ",FAC_MGTRAP_INFO=" & ToSQL(fldFAC_MGTRAP_INFO, "Text") & _
        ",FAC_MGTRAP_WAARDE1=" & ToSQL(fldFAC_MGTRAP_WAARDE1, "Number") & _
        ",FAC_MGTRAP_WAARDE2=" & ToSQL(fldFAC_MGTRAP_WAARDE2, "Number") & _
        ",FAC_MGTRAP_WAARDE3=" & ToSQL(fldFAC_MGTRAP_WAARDE3, "Number") & _
        ",FAC_MGTRAP_WAARDE4=" & ToSQL(fldFAC_MGTRAP_WAARDE4, "Number") & _
        ",FAC_FUNCTIE_KEY=" & ToSQL(fldFAC_FUNCTIE_KEY, "Number")
      sSQL = sSQL & " where " & sWhere
    case "delete"
'-------------------------------
' MgtrapRecord Delete Event begin
' MgtrapRecord Delete Event end
'-------------------------------
      sSQL = "delete from FAC_MGTRAP where " & sWhere
  end select
'-------------------------------
'-------------------------------
' MgtrapRecord BeforeExecute Event begin
' MgtrapRecord BeforeExecute Event end
'-------------------------------

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

'===============================
' Display Record Form
'-------------------------------
Sub MgtrapRecord_Show()
'-------------------------------
' MgtrapRecord Show begin
'-------------------------------
  Dim sWhere : sWhere = ""
  Dim sFormTitle: sFormTitle = "Details dashboard"
  Dim bPK : bPK = True
  Dim sFAC_FUNCTIE_KEYDisplayValue: sFAC_FUNCTIE_KEYDisplayValue = ""

'-------------------------------
' Load primary key and form parameters
'-------------------------------
  if sMgtrapRecordErr = "" then
    pFAC_MGTRAP_KEY = GetParam("FAC_MGTRAP_KEY")
    SetVar "MgtrapRecordError", ""
  else
    fldFAC_MGTRAP_OMSCHRIJVING = GetParam("FAC_MGTRAP_OMSCHRIJVING")
    fldFAC_MGTRAP_VIEW_NAME = GetParam("FAC_MGTRAP_VIEW_NAME")
    fldFAC_MGTRAP_INFO = GetParam("FAC_MGTRAP_INFO")
    fldFAC_MGTRAP_WAARDE1 = GetParam("FAC_MGTRAP_WAARDE1")
    fldFAC_MGTRAP_WAARDE2 = GetParam("FAC_MGTRAP_WAARDE2")
    fldFAC_MGTRAP_WAARDE3 = GetParam("FAC_MGTRAP_WAARDE3")
    fldFAC_MGTRAP_WAARDE4 = GetParam("FAC_MGTRAP_WAARDE4")
    fldFAC_FUNCTIE_KEY = GetParam("FAC_FUNCTIE_KEY")
    pFAC_MGTRAP_KEY = GetParam("PK_FAC_MGTRAP_KEY")
    SetVar "sMgtrapRecordErr", sMgtrapRecordErr
    SetVar "FormTitle", sFormTitle
    Parse "MgtrapRecordError", False
  end if
'-------------------------------

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

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

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

  if IsEmpty(pFAC_MGTRAP_KEY) then bPK = False
  
  sWhere = sWhere & "FAC_MGTRAP_KEY=" & ToSQL(pFAC_MGTRAP_KEY, "Number")
  SetVar "PK_FAC_MGTRAP_KEY", pFAC_MGTRAP_KEY
'-------------------------------
'-------------------------------
' MgtrapRecord Open Event begin
' MgtrapRecord Open Event end
'-------------------------------

  SetVar "FormTitle", sFormTitle

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

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

'-------------------------------
' Load data from recordset when form displayed first time
'-------------------------------
    if sMgtrapRecordErr = "" then
      fldFAC_MGTRAP_OMSCHRIJVING = GetValue(rs, "FAC_MGTRAP_OMSCHRIJVING")
      fldFAC_MGTRAP_VIEW_NAME = GetValue(rs, "FAC_MGTRAP_VIEW_NAME")
      fldFAC_MGTRAP_INFO = GetValue(rs, "FAC_MGTRAP_INFO")
      fldFAC_MGTRAP_WAARDE1 = GetValue(rs, "FAC_MGTRAP_WAARDE1")
      fldFAC_MGTRAP_WAARDE2 = GetValue(rs, "FAC_MGTRAP_WAARDE2")
      fldFAC_MGTRAP_WAARDE3 = GetValue(rs, "FAC_MGTRAP_WAARDE3")
      fldFAC_MGTRAP_WAARDE4 = GetValue(rs, "FAC_MGTRAP_WAARDE4")
      fldFAC_FUNCTIE_KEY = GetValue(rs, "FAC_FUNCTIE_KEY")
    end if
    SetVar "MgtrapRecordInsert", ""
    Parse "MgtrapRecordEdit", False
'-------------------------------
' MgtrapRecord ShowEdit Event begin
' MgtrapRecord ShowEdit Event end
'-------------------------------
  else
    SetVar "MgtrapRecordEdit", ""
    Parse "MgtrapRecordInsert", False
'-------------------------------
' MgtrapRecord ShowInsert Event begin
' MgtrapRecord ShowInsert Event end
'-------------------------------
  end if
  Parse "MgtrapRecordCancel", false
'-------------------------------
' MgtrapRecord Show Event begin
' MgtrapRecord Show Event end
'-------------------------------

'-------------------------------
' Show form field
'-------------------------------
      SetVar "FAC_MGTRAP_KEY", ToHTML(fldFAC_MGTRAP_KEY)
      SetVar "FAC_MGTRAP_OMSCHRIJVING", ToHTML(fldFAC_MGTRAP_OMSCHRIJVING)
      SetVar "FAC_MGTRAP_VIEW_NAME", ToHTML(fldFAC_MGTRAP_VIEW_NAME)
      SetVar "FAC_MGTRAP_INFO", ToHTML(fldFAC_MGTRAP_INFO)
      SetVar "FAC_MGTRAP_WAARDE1", ToHTML(fldFAC_MGTRAP_WAARDE1)
      SetVar "FAC_MGTRAP_WAARDE2", ToHTML(fldFAC_MGTRAP_WAARDE2)
      SetVar "FAC_MGTRAP_WAARDE3", ToHTML(fldFAC_MGTRAP_WAARDE3)
      SetVar "FAC_MGTRAP_WAARDE4", ToHTML(fldFAC_MGTRAP_WAARDE4)
      SetVar "MgtrapRecordLBFAC_FUNCTIE_KEY", ""
      SetVar "Selected", ""
      SetVar "ID", ""
      SetVar "Value", sFAC_FUNCTIE_KEYDisplayValue
      Parse "MgtrapRecordLBFAC_FUNCTIE_KEY", True
      openrs rsFAC_FUNCTIE_KEY, "select fac_functie_key, fac_functie_omschrijving from fac_functie order by fac_functie_omschrijving asc"
      while not rsFAC_FUNCTIE_KEY.EOF
        SetVar "ID", GetValue(rsFAC_FUNCTIE_KEY, 0) : SetVar "Value", GetValue(rsFAC_FUNCTIE_KEY, 1)
        if cstr(GetValue(rsFAC_FUNCTIE_KEY, 0)) = cstr(fldFAC_FUNCTIE_KEY) then SetVar "Selected", "SELECTED" else SetVar "Selected", ""
        Parse "MgtrapRecordLBFAC_FUNCTIE_KEY", True
        rsFAC_FUNCTIE_KEY.MoveNext
      wend
      set rsFAC_FUNCTIE_KEY = nothing
    
  Parse "FormMgtrapRecord", False

'-------------------------------
' MgtrapRecord Close Event begin
' MgtrapRecord Close Event end
'-------------------------------

Set rs = Nothing

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