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

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


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


'===============================
' mrk_disciplinerecord PageSecurity begin
' mrk_disciplinerecord PageSecurity end
'===============================

'===============================
' mrk_disciplinerecord Open Event begin
' mrk_disciplinerecord Open Event end
'===============================

'===============================
' mrk_disciplinerecord OpenAnyPage Event begin
' mrk_disciplinerecord OpenAnyPage Event end
'===============================

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

' mrk_disciplinerecord Show begin
'===============================
' Perform the form's action
'-------------------------------
' Initialize error variables
'-------------------------------
sDisciplineRecordErr = ""

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

' mrk_disciplinerecord Show end

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

' mrk_disciplinerecord Close Event begin
' mrk_disciplinerecord Close Event end

cn.Close
Set cn = Nothing
UnloadTemplate
'===============================
'===============================
' Action of the Record Form
'-------------------------------
Sub DisciplineRecordAction(sAction)
'-------------------------------
' Initialize variables  
'-------------------------------
  Dim bExecSQL: bExecSQL = true
  Dim sActionFileName : sActionFileName = ""
  Dim sWhere : sWhere = "" 
  Dim bErr : bErr = False
  Dim pPKINS_DISCIPLINE_KEY : pPKINS_DISCIPLINE_KEY = ""
  Dim fldINS_DISCIPLINE_MODULE : fldINS_DISCIPLINE_MODULE = ""
  Dim fldINS_DISCIPLINE_OMSCHRIJVING : fldINS_DISCIPLINE_OMSCHRIJVING = ""
'-------------------------------

'-------------------------------
' DisciplineRecord Action begin
'-------------------------------
  sActionFileName = "mrk_disciplinegrid.asp"

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

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

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


'-------------------------------
' Load all form fields into variables
'-------------------------------
  fldINS_DISCIPLINE_MODULE = GetParam("INS_DISCIPLINE_MODULE")
  fldINS_DISCIPLINE_OMSCHRIJVING = GetParam("INS_DISCIPLINE_OMSCHRIJVING")

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


'-------------------------------
' Create SQL statement
'-------------------------------
  select case sAction
    case "insert"
'-------------------------------
' DisciplineRecord Insert Event begin
' DisciplineRecord Insert Event end
'-------------------------------
      sSQL = "insert into INS_TAB_DISCIPLINE (" & _
          "INS_DISCIPLINE_MODULE," & _
          "INS_DISCIPLINE_OMSCHRIJVING)" & _
          " values (" & _
          ToSQL(fldINS_DISCIPLINE_MODULE, "Text") & "," & _
          ToSQL(fldINS_DISCIPLINE_OMSCHRIJVING, "Text") & _
          ")"
    case "update"
'-------------------------------
' DisciplineRecord Update Event begin
' DisciplineRecord Update Event end
'-------------------------------
      sSQL = "update INS_TAB_DISCIPLINE set " & _
        "INS_DISCIPLINE_MODULE=" & ToSQL(fldINS_DISCIPLINE_MODULE, "Text") & _
        ",INS_DISCIPLINE_OMSCHRIJVING=" & ToSQL(fldINS_DISCIPLINE_OMSCHRIJVING, "Text")
      sSQL = sSQL & " where " & sWhere
    case "delete"
'-------------------------------
' DisciplineRecord Delete Event begin
sSql = "UPDATE INS_TAB_DISCIPLINE SET INS_DISCIPLINE_VERWIJDER="+sysdate+" WHERE INS_DISCIPLINE_KEY = "+pPKINS_DISCIPLINE_KEY
' DisciplineRecord Delete Event end
'-------------------------------
      if sSQL = "" then
      sSQL = "delete from INS_TAB_DISCIPLINE where " & sWhere
      end if
  end select
'-------------------------------
'-------------------------------
' DisciplineRecord BeforeExecute Event begin
' DisciplineRecord BeforeExecute Event end
'-------------------------------

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

'===============================
' Display Record Form
'-------------------------------
Sub DisciplineRecord_Show()
'-------------------------------
' DisciplineRecord Show begin
'-------------------------------
  Dim sWhere : sWhere = ""
  Dim sFormTitle: sFormTitle = "Details categorie"
  Dim bPK : bPK = True

'-------------------------------
' Load primary key and form parameters
'-------------------------------
  if sDisciplineRecordErr = "" then
    pINS_DISCIPLINE_KEY = GetParam("INS_DISCIPLINE_KEY")
    SetVar "DisciplineRecordError", ""
  else
    fldINS_DISCIPLINE_MODULE = GetParam("INS_DISCIPLINE_MODULE")
    fldINS_DISCIPLINE_OMSCHRIJVING = GetParam("INS_DISCIPLINE_OMSCHRIJVING")
    pINS_DISCIPLINE_KEY = GetParam("PK_INS_DISCIPLINE_KEY")
    SetVar "sDisciplineRecordErr", sDisciplineRecordErr
    SetVar "FormTitle", sFormTitle
    Parse "DisciplineRecordError", False
  end if
'-------------------------------

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

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

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

  if IsEmpty(pINS_DISCIPLINE_KEY) then bPK = False
  
  sWhere = sWhere & "INS_DISCIPLINE_KEY=" & ToSQL(pINS_DISCIPLINE_KEY, "Number")
  SetVar "PK_INS_DISCIPLINE_KEY", pINS_DISCIPLINE_KEY
'-------------------------------
'-------------------------------
' DisciplineRecord Open Event begin
' DisciplineRecord Open Event end
'-------------------------------

  SetVar "FormTitle", sFormTitle

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

'-------------------------------
' Load all fields into variables from recordset or input parameters
'-------------------------------
  if bIsUpdateMode then
    fldINS_DISCIPLINE_KEY = GetValue(rs, "INS_DISCIPLINE_KEY")
    fldINS_DISCIPLINE_MODULE = GetValue(rs, "INS_DISCIPLINE_MODULE")

'-------------------------------
' Load data from recordset when form displayed first time
'-------------------------------
    if sDisciplineRecordErr = "" then
      fldINS_DISCIPLINE_OMSCHRIJVING = GetValue(rs, "INS_DISCIPLINE_OMSCHRIJVING")
    end if
    SetVar "DisciplineRecordInsert", ""
    Parse "DisciplineRecordEdit", False
'-------------------------------
' DisciplineRecord ShowEdit Event begin
' DisciplineRecord ShowEdit Event end
'-------------------------------
  else
    if sDisciplineRecordErr = "" then
      fldINS_DISCIPLINE_MODULE= "MRK"
    end if
    SetVar "DisciplineRecordEdit", ""
    Parse "DisciplineRecordInsert", False
'-------------------------------
' DisciplineRecord ShowInsert Event begin
' DisciplineRecord ShowInsert Event end
'-------------------------------
  end if
  Parse "DisciplineRecordCancel", false
'-------------------------------
' DisciplineRecord Show Event begin
' DisciplineRecord Show Event end
'-------------------------------

'-------------------------------
' Show form field
'-------------------------------
      SetVar "INS_DISCIPLINE_KEY", ToHTML(fldINS_DISCIPLINE_KEY)
      SetVar "INS_DISCIPLINE_MODULE", ToHTML(fldINS_DISCIPLINE_MODULE)
      SetVar "INS_DISCIPLINE_OMSCHRIJVING", ToHTML(fldINS_DISCIPLINE_OMSCHRIJVING)
  Parse "FormDisciplineRecord", False

'-------------------------------
' DisciplineRecord Close Event begin
' DisciplineRecord Close Event end
'-------------------------------

Set rs = Nothing

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