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

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


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


'===============================
' fac_groeprecord CustomSecurity Event begin
checkAutorisation("WEB_FACMSU")
' fac_groeprecord CustomSecurity Event end
'===============================

'===============================
' fac_groeprecord Open Event begin
' fac_groeprecord Open Event end
'===============================

'===============================
' fac_groeprecord OpenAnyPage Event begin
' fac_groeprecord OpenAnyPage Event end
'===============================

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

' fac_groeprecord Show begin
'===============================
' Perform the form's action
'-------------------------------
' Initialize error variables
'-------------------------------
sGroepRecordErr = ""

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

' fac_groeprecord Show end

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

' fac_groeprecord Close Event begin
' fac_groeprecord Close Event end

cn.Close
Set cn = Nothing
UnloadTemplate
'===============================
'===============================
' Action of the Record Form
'-------------------------------
Sub GroepRecordAction(sAction)
'-------------------------------
' Initialize variables  
'-------------------------------
  Dim bExecSQL: bExecSQL = true
  Dim sActionFileName : sActionFileName = ""
  Dim sParams : sParams = "?"
  Dim sWhere : sWhere = "" 
  Dim bErr : bErr = False
  Dim pPKFAC_GROEP_KEY : pPKFAC_GROEP_KEY = ""
  Dim fldFAC_GROEP_OMSCHRIJVING : fldFAC_GROEP_OMSCHRIJVING = ""
  Dim fldFAC_GROEP_COLLEGA : fldFAC_GROEP_COLLEGA = ""
'-------------------------------

'-------------------------------
' GroepRecord Action begin
'-------------------------------
  sActionFileName = "fac_groepgrid.asp"
  sParams = sParams & "sFAC_GROEP_UPPER=" & ToURL(GetParam("Trn_sFAC_GROEP_UPPER"))

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

'-------------------------------
' GroepRecord BeforeCancel Event begin
' GroepRecord 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_GROEP_KEY = GetParam("PK_FAC_GROEP_KEY")
    if IsEmpty(pPKFAC_GROEP_KEY) then exit sub
    sWhere = "FAC_GROEP_KEY=" & ToSQL(pPKFAC_GROEP_KEY, "Number")
  end if
'-------------------------------


'-------------------------------
' Load all form fields into variables
'-------------------------------
  fldFAC_GROEP_OMSCHRIJVING = GetParam("FAC_GROEP_OMSCHRIJVING")
  fldFAC_GROEP_COLLEGA = getCheckBoxValue(GetParam("FAC_GROEP_COLLEGA"), "1", "0", "Number")

'-------------------------------
' Validate fields
'-------------------------------
  if sAction = "insert" or sAction = "update" then
    if IsEmpty(fldFAC_GROEP_OMSCHRIJVING) then
      sGroepRecordErr = sGroepRecordErr & "De waarde in veld Omschrijving is verplicht.<br>"
    end if
'-------------------------------
' GroepRecord Check Event begin
' GroepRecord Check Event end
'-------------------------------
    If len(sGroepRecordErr) > 0 then
      exit sub
    end if
  end if
'-------------------------------


'-------------------------------
' Create SQL statement
'-------------------------------
  select case sAction
    case "insert"
'-------------------------------
' GroepRecord Insert Event begin
' GroepRecord Insert Event end
'-------------------------------
      sSQL = "insert into FAC_GROEP (" & _
          "FAC_GROEP_OMSCHRIJVING," & _
          "FAC_GROEP_COLLEGA)" & _
          " values (" & _
          ToSQL(fldFAC_GROEP_OMSCHRIJVING, "Text") & "," & _
          fldFAC_GROEP_COLLEGA & _
          ")"
    case "update"
'-------------------------------
' GroepRecord Update Event begin
' GroepRecord Update Event end
'-------------------------------
      sSQL = "update FAC_GROEP set " & _
        "FAC_GROEP_OMSCHRIJVING=" & ToSQL(fldFAC_GROEP_OMSCHRIJVING, "Text") & _
        ",FAC_GROEP_COLLEGA=" & fldFAC_GROEP_COLLEGA
      sSQL = sSQL & " where " & sWhere
    case "delete"
'-------------------------------
' GroepRecord Delete Event begin
' GroepRecord Delete Event end
'-------------------------------
      sSQL = "delete from FAC_GROEP where " & sWhere
  end select
'-------------------------------
'-------------------------------
' GroepRecord BeforeExecute Event begin
' GroepRecord BeforeExecute Event end
'-------------------------------

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

'===============================
' Display Record Form
'-------------------------------
Sub GroepRecord_Show()
'-------------------------------
' GroepRecord Show begin
'-------------------------------
  Dim sWhere : sWhere = ""
  Dim sFormTitle: sFormTitle = "Details groep"
  Dim bPK : bPK = True

'-------------------------------
' Load primary key and form parameters
'-------------------------------
  if sGroepRecordErr = "" then
    SetVar "Trn_sFAC_GROEP_UPPER", GetParam("sFAC_GROEP_UPPER")
    pFAC_GROEP_KEY = GetParam("FAC_GROEP_KEY")
    SetVar "GroepRecordError", ""
  else
    fldFAC_GROEP_OMSCHRIJVING = GetParam("FAC_GROEP_OMSCHRIJVING")
    fldFAC_GROEP_COLLEGA = getCheckBoxValue(GetParam("FAC_GROEP_COLLEGA"), "1", "0", "Number")
    SetVar "Trn_sFAC_GROEP_UPPER", GetParam("Trn_sFAC_GROEP_UPPER")
    pFAC_GROEP_KEY = GetParam("PK_FAC_GROEP_KEY")
    SetVar "sGroepRecordErr", sGroepRecordErr
    SetVar "FormTitle", sFormTitle
    Parse "GroepRecordError", False
  end if
'-------------------------------

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

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

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

  if IsEmpty(pFAC_GROEP_KEY) then bPK = False
  
  sWhere = sWhere & "FAC_GROEP_KEY=" & ToSQL(pFAC_GROEP_KEY, "Number")
  SetVar "PK_FAC_GROEP_KEY", pFAC_GROEP_KEY
'-------------------------------
'-------------------------------
' GroepRecord Open Event begin
' GroepRecord Open Event end
'-------------------------------

  SetVar "FormTitle", sFormTitle

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

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

'-------------------------------
' Load data from recordset when form displayed first time
'-------------------------------
    if sGroepRecordErr = "" then
      fldFAC_GROEP_OMSCHRIJVING = GetValue(rs, "FAC_GROEP_OMSCHRIJVING")
      fldFAC_GROEP_COLLEGA = GetValue(rs, "FAC_GROEP_COLLEGA")
    end if
    SetVar "GroepRecordInsert", ""
    Parse "GroepRecordEdit", False
'-------------------------------
' GroepRecord ShowEdit Event begin
' GroepRecord ShowEdit Event end
'-------------------------------
  else
    SetVar "GroepRecordEdit", ""
    Parse "GroepRecordInsert", False
'-------------------------------
' GroepRecord ShowInsert Event begin
' GroepRecord ShowInsert Event end
'-------------------------------
  end if
  Parse "GroepRecordCancel", false
'-------------------------------
' GroepRecord Show Event begin
' GroepRecord Show Event end
'-------------------------------

'-------------------------------
' Show form field
'-------------------------------
      SetVar "FAC_GROEP_KEY", ToHTML(fldFAC_GROEP_KEY)
      SetVar "FAC_GROEP_OMSCHRIJVING", ToHTML(fldFAC_GROEP_OMSCHRIJVING)
  if (LCase(fldFAC_GROEP_COLLEGA) = LCase("1")) then
    SetVar "FAC_GROEP_COLLEGA_CHECKED", "CHECKED"
  else
    SetVar "FAC_GROEP_COLLEGA_CHECKED", ""
  end if

  Parse "FormGroepRecord", False

'-------------------------------
' GroepRecord Close Event begin
' GroepRecord Close Event end
'-------------------------------

Set rs = Nothing

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