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

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

pINS_DISCIPLINE_KEY = getParam("INS_DISCIPLINE_KEY")
' ins_srtgroeprecord CustomIncludes Event end


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


'===============================
' ins_srtgroeprecord PageSecurity begin
' ins_srtgroeprecord PageSecurity end
'===============================

'===============================
' ins_srtgroeprecord Open Event begin
' ins_srtgroeprecord Open Event end
'===============================

'===============================
' ins_srtgroeprecord OpenAnyPage Event begin
' ins_srtgroeprecord OpenAnyPage Event end
'===============================

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

' ins_srtgroeprecord Show begin
'===============================
' Perform the form's action
'-------------------------------
' Initialize error variables
'-------------------------------
sSrtGroepRecordErr = ""

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

' ins_srtgroeprecord Show end

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

' ins_srtgroeprecord Close Event begin
' ins_srtgroeprecord Close Event end

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

'-------------------------------
' SrtGroepRecord Action begin
'-------------------------------
  sActionFileName = "ins_srtgroepgrid.asp"
  sParams = sParams & "INS_DISCIPLINE_KEY=" & ToURL(GetParam("Trn_INS_DISCIPLINE_KEY")) & "&"
  sParams = sParams & "sINS_SRTGROEP_UPPER=" & ToURL(GetParam("Trn_sINS_SRTGROEP_UPPER"))

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

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

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


'-------------------------------
' Load all form fields into variables
'-------------------------------
  fldINS_DISCIPLINE_KEY = GetParam("INS_DISCIPLINE_KEY")
  fldINS_SRTGROEP_OMSCHRIJVING = GetParam("INS_SRTGROEP_OMSCHRIJVING")

'-------------------------------
' Validate fields
'-------------------------------
  if sAction = "insert" or sAction = "update" then
    if IsEmpty(fldINS_DISCIPLINE_KEY) then
      sSrtGroepRecordErr = sSrtGroepRecordErr & "De waarde in veld Discipline is verplicht.<br>"
    end if
    if IsEmpty(fldINS_SRTGROEP_OMSCHRIJVING) then
      sSrtGroepRecordErr = sSrtGroepRecordErr & "De waarde in veld Omschrijving is verplicht.<br>"
    end if
    if not isNumeric(fldINS_DISCIPLINE_KEY) then
      sSrtGroepRecordErr = sSrtGroepRecordErr & "De waarde in veld Discipline is niet correct.<br>"
    end if
'-------------------------------
' SrtGroepRecord Check Event begin
' SrtGroepRecord Check Event end
'-------------------------------
    If len(sSrtGroepRecordErr) > 0 then
      exit sub
    end if
  end if
'-------------------------------


'-------------------------------
' Create SQL statement
'-------------------------------
  select case sAction
    case "insert"
'-------------------------------
' SrtGroepRecord Insert Event begin
sSQL = "insert into INS_V_AANWEZIGSRTGROEP (" & _
          "INS_DISCIPLINE_KEY," & _
          "INS_SRTGROEP_OMSCHRIJVING," & _
          "INS_SRTGROEP_MODULE)" & _
          " values (" & _
          ToSQL(fldINS_DISCIPLINE_KEY, "Number") & "," & _
          ToSQL(fldINS_SRTGROEP_OMSCHRIJVING, "Text") & "," & _
          "'INS'" & _
          ")"
' SrtGroepRecord Insert Event end
'-------------------------------
      if sSQL = "" then
      sSQL = "insert into INS_V_AANWEZIGSRTGROEP (" & _
          "INS_DISCIPLINE_KEY," & _
          "INS_SRTGROEP_OMSCHRIJVING)" & _
          " values (" & _
          ToSQL(fldINS_DISCIPLINE_KEY, "Number") & "," & _
          ToSQL(fldINS_SRTGROEP_OMSCHRIJVING, "Text") & _
          ")"
      end if
    case "update"
'-------------------------------
' SrtGroepRecord Update Event begin
' SrtGroepRecord Update Event end
'-------------------------------
      sSQL = "update INS_V_AANWEZIGSRTGROEP set " & _
        "INS_DISCIPLINE_KEY=" & ToSQL(fldINS_DISCIPLINE_KEY, "Number") & _
        ",INS_SRTGROEP_OMSCHRIJVING=" & ToSQL(fldINS_SRTGROEP_OMSCHRIJVING, "Text")
      sSQL = sSQL & " where " & sWhere
    case "delete"
'-------------------------------
' SrtGroepRecord Delete Event begin
dim tmpkey
tmpkey = "PK_"&strToTable(sActionFileName)&"_KEY"
sSql = customFacDelete(sActionFileName,getParam(tmpkey))
set tmpkey = Nothing
' SrtGroepRecord Delete Event end
'-------------------------------
      if sSQL = "" then
      sSQL = "delete from INS_V_AANWEZIGSRTGROEP where " & sWhere
      end if
  end select
'-------------------------------
'-------------------------------
' SrtGroepRecord BeforeExecute Event begin
' SrtGroepRecord BeforeExecute Event end
'-------------------------------

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

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

'-------------------------------
' Load primary key and form parameters
'-------------------------------
  if sSrtGroepRecordErr = "" then
    SetVar "Trn_INS_DISCIPLINE_KEY", GetParam("INS_DISCIPLINE_KEY")
    SetVar "Trn_sINS_SRTGROEP_UPPER", GetParam("sINS_SRTGROEP_UPPER")
    pINS_SRTGROEP_KEY = GetParam("INS_SRTGROEP_KEY")
    SetVar "SrtGroepRecordError", ""
  else
    fldINS_DISCIPLINE_KEY = GetParam("INS_DISCIPLINE_KEY")
    fldINS_SRTGROEP_OMSCHRIJVING = GetParam("INS_SRTGROEP_OMSCHRIJVING")
    SetVar "Trn_INS_DISCIPLINE_KEY", GetParam("Trn_INS_DISCIPLINE_KEY")
    SetVar "Trn_sINS_SRTGROEP_UPPER", GetParam("Trn_sINS_SRTGROEP_UPPER")
    pINS_SRTGROEP_KEY = GetParam("PK_INS_SRTGROEP_KEY")
    SetVar "sSrtGroepRecordErr", sSrtGroepRecordErr
    SetVar "FormTitle", sFormTitle
    Parse "SrtGroepRecordError", False
  end if
'-------------------------------

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

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

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

  if IsEmpty(pINS_SRTGROEP_KEY) then bPK = False
  
  sWhere = sWhere & "INS_SRTGROEP_KEY=" & ToSQL(pINS_SRTGROEP_KEY, "Number")
  SetVar "PK_INS_SRTGROEP_KEY", pINS_SRTGROEP_KEY
'-------------------------------
'-------------------------------
' SrtGroepRecord Open Event begin
' SrtGroepRecord Open Event end
'-------------------------------

  SetVar "FormTitle", sFormTitle

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

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

'-------------------------------
' Load data from recordset when form displayed first time
'-------------------------------
    if sSrtGroepRecordErr = "" then
      fldINS_DISCIPLINE_KEY = GetValue(rs, "INS_DISCIPLINE_KEY")
      fldINS_SRTGROEP_OMSCHRIJVING = GetValue(rs, "INS_SRTGROEP_OMSCHRIJVING")
    end if
    SetVar "SrtGroepRecordInsert", ""
    Parse "SrtGroepRecordEdit", False
'-------------------------------
' SrtGroepRecord ShowEdit Event begin
' SrtGroepRecord ShowEdit Event end
'-------------------------------
  else
    SetVar "SrtGroepRecordEdit", ""
    Parse "SrtGroepRecordInsert", False
'-------------------------------
' SrtGroepRecord ShowInsert Event begin
' SrtGroepRecord ShowInsert Event end
'-------------------------------
  end if
  Parse "SrtGroepRecordCancel", false
  if sSrtGroepRecordErr = "" then
'-------------------------------
' SrtGroepRecord Show Event begin
if fldINS_SRTGROEP_KEY = "" then
  fldINS_DISCIPLINE_KEY = pINS_DISCIPLINE_KEY
end if
' SrtGroepRecord Show Event end
'-------------------------------
  end if

'-------------------------------
' Show form field
'-------------------------------
      SetVar "INS_SRTGROEP_KEY", ToHTML(fldINS_SRTGROEP_KEY)
      SetVar "SrtGroepRecordLBINS_DISCIPLINE_KEY", ""
      SetVar "Selected", ""
      SetVar "ID", ""
      SetVar "Value", sINS_DISCIPLINE_KEYDisplayValue
      Parse "SrtGroepRecordLBINS_DISCIPLINE_KEY", True
      openrs rsINS_DISCIPLINE_KEY, "select ins_discipline_key,   ins_discipline_omschrijving from ins_discipline where ins_discipline_verwijder is null order by ins_discipline_omschrijving"
      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 "SrtGroepRecordLBINS_DISCIPLINE_KEY", True
        rsINS_DISCIPLINE_KEY.MoveNext
      wend
      set rsINS_DISCIPLINE_KEY = nothing
    
      SetVar "INS_SRTGROEP_OMSCHRIJVING", ToHTML(fldINS_SRTGROEP_OMSCHRIJVING)
  Parse "FormSrtGroepRecord", False

'-------------------------------
' SrtGroepRecord Close Event begin
' SrtGroepRecord Close Event end
'-------------------------------

Set rs = Nothing

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