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

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


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


'===============================
' prs_kostencombinatierecord PageSecurity begin
' prs_kostencombinatierecord PageSecurity end
'===============================

'===============================
' prs_kostencombinatierecord Open Event begin
' prs_kostencombinatierecord Open Event end
'===============================

'===============================
' prs_kostencombinatierecord OpenAnyPage Event begin
' prs_kostencombinatierecord OpenAnyPage Event end
'===============================

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

' prs_kostencombinatierecord Show begin
'===============================
' Perform the form's action
'-------------------------------
' Initialize error variables
'-------------------------------
sKostenCombinatieRecordErr = ""

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

' prs_kostencombinatierecord Show end

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

' prs_kostencombinatierecord Close Event begin
' prs_kostencombinatierecord Close Event end

cn.Close
Set cn = Nothing
UnloadTemplate
'===============================
'===============================
' Action of the Record Form
'-------------------------------
Sub KostenCombinatieRecordAction(sAction)
'-------------------------------
' Initialize variables  
'-------------------------------
  Dim bExecSQL: bExecSQL = true
  Dim sActionFileName : sActionFileName = ""
  Dim sParams : sParams = "?"
  Dim sWhere : sWhere = "" 
  Dim bErr : bErr = False
  Dim pPKPRS_KOSTENCOMBINATIE_KEY : pPKPRS_KOSTENCOMBINATIE_KEY = ""
  Dim fldPRS_KOSTENSOORT_KEY : fldPRS_KOSTENSOORT_KEY = ""
  Dim fldPRS_KOSTENPLAATSGRP_KEY : fldPRS_KOSTENPLAATSGRP_KEY = ""
'-------------------------------

'-------------------------------
' KostenCombinatieRecord Action begin
'-------------------------------
  sActionFileName = "prs_kostencombinatiegrid.asp"
  sParams = sParams & "sPRS_KOSTENCOMBINATIE_OMSCHRIJVING=" & ToURL(GetParam("Trn_sPRS_KOSTENCOMBINATIE_OMSCHRIJVING")) & "&"
  sParams = sParams & "PRS_KOSTENPLAATSGRP_KEY=" & ToURL(GetParam("Trn_PRS_KOSTENPLAATSGRP_KEY"))

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

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

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


'-------------------------------
' Load all form fields into variables
'-------------------------------
  fldPRS_KOSTENSOORT_KEY = GetParam("PRS_KOSTENSOORT_KEY")
  fldPRS_KOSTENPLAATSGRP_KEY = GetParam("PRS_KOSTENPLAATSGRP_KEY")

'-------------------------------
' Validate fields
'-------------------------------
  if sAction = "insert" or sAction = "update" then
    if IsEmpty(fldPRS_KOSTENSOORT_KEY) then
      sKostenCombinatieRecordErr = sKostenCombinatieRecordErr & "De waarde in veld Kostensoort is verplicht.<br>"
    end if
    if IsEmpty(fldPRS_KOSTENPLAATSGRP_KEY) then
      sKostenCombinatieRecordErr = sKostenCombinatieRecordErr & "De waarde in veld KPN Groep is verplicht.<br>"
    end if
    if not isNumeric(fldPRS_KOSTENSOORT_KEY) then
      sKostenCombinatieRecordErr = sKostenCombinatieRecordErr & "De waarde in veld Kostensoort is niet correct.<br>"
    end if
    if not isNumeric(fldPRS_KOSTENPLAATSGRP_KEY) then
      sKostenCombinatieRecordErr = sKostenCombinatieRecordErr & "De waarde in veld KPN Groep is niet correct.<br>"
    end if
'-------------------------------
' KostenCombinatieRecord Check Event begin
' KostenCombinatieRecord Check Event end
'-------------------------------
    If len(sKostenCombinatieRecordErr) > 0 then
      exit sub
    end if
  end if
'-------------------------------


'-------------------------------
' Create SQL statement
'-------------------------------
  select case sAction
    case "insert"
'-------------------------------
' KostenCombinatieRecord Insert Event begin
' KostenCombinatieRecord Insert Event end
'-------------------------------
      sSQL = "insert into PRS_KOSTENCOMBINATIE (" & _
          "PRS_KOSTENSOORT_KEY," & _
          "PRS_KOSTENPLAATSGRP_KEY)" & _
          " values (" & _
          ToSQL(fldPRS_KOSTENSOORT_KEY, "Number") & "," & _
          ToSQL(fldPRS_KOSTENPLAATSGRP_KEY, "Number") & _
          ")"
    case "update"
'-------------------------------
' KostenCombinatieRecord Update Event begin
' KostenCombinatieRecord Update Event end
'-------------------------------
      sSQL = "update PRS_KOSTENCOMBINATIE set " & _
        "PRS_KOSTENSOORT_KEY=" & ToSQL(fldPRS_KOSTENSOORT_KEY, "Number") & _
        ",PRS_KOSTENPLAATSGRP_KEY=" & ToSQL(fldPRS_KOSTENPLAATSGRP_KEY, "Number")
      sSQL = sSQL & " where " & sWhere
    case "delete"
'-------------------------------
' KostenCombinatieRecord Delete Event begin
' KostenCombinatieRecord Delete Event end
'-------------------------------
      sSQL = "delete from PRS_KOSTENCOMBINATIE where " & sWhere
  end select
'-------------------------------
'-------------------------------
' KostenCombinatieRecord BeforeExecute Event begin
' KostenCombinatieRecord BeforeExecute Event end
'-------------------------------

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

'===============================
' Display Record Form
'-------------------------------
Sub KostenCombinatieRecord_Show()
'-------------------------------
' KostenCombinatieRecord Show begin
'-------------------------------
  Dim sWhere : sWhere = ""
  Dim sFormTitle: sFormTitle = "Details Combinatievalidatie"
  Dim bPK : bPK = True

'-------------------------------
' Load primary key and form parameters
'-------------------------------
  if sKostenCombinatieRecordErr = "" then
    SetVar "Trn_sPRS_KOSTENCOMBINATIE_OMSCHRIJVING", GetParam("sPRS_KOSTENCOMBINATIE_OMSCHRIJVING")
    SetVar "Trn_PRS_KOSTENPLAATSGRP_KEY", GetParam("PRS_KOSTENPLAATSGRP_KEY")
    pPRS_KOSTENCOMBINATIE_KEY = GetParam("PRS_KOSTENCOMBINATIE_KEY")
    SetVar "KostenCombinatieRecordError", ""
  else
    fldPRS_KOSTENSOORT_KEY = GetParam("PRS_KOSTENSOORT_KEY")
    fldPRS_KOSTENPLAATSGRP_KEY = GetParam("PRS_KOSTENPLAATSGRP_KEY")
    SetVar "Trn_sPRS_KOSTENCOMBINATIE_OMSCHRIJVING", GetParam("Trn_sPRS_KOSTENCOMBINATIE_OMSCHRIJVING")
    SetVar "Trn_PRS_KOSTENPLAATSGRP_KEY", GetParam("Trn_PRS_KOSTENPLAATSGRP_KEY")
    pPRS_KOSTENCOMBINATIE_KEY = GetParam("PK_PRS_KOSTENCOMBINATIE_KEY")
    SetVar "sKostenCombinatieRecordErr", sKostenCombinatieRecordErr
    SetVar "FormTitle", sFormTitle
    Parse "KostenCombinatieRecordError", False
  end if
'-------------------------------

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

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

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

  if IsEmpty(pPRS_KOSTENCOMBINATIE_KEY) then bPK = False
  
  sWhere = sWhere & "PRS_KOSTENCOMBINATIE_KEY=" & ToSQL(pPRS_KOSTENCOMBINATIE_KEY, "Number")
  SetVar "PK_PRS_KOSTENCOMBINATIE_KEY", pPRS_KOSTENCOMBINATIE_KEY
'-------------------------------
'-------------------------------
' KostenCombinatieRecord Open Event begin
' KostenCombinatieRecord Open Event end
'-------------------------------

  SetVar "FormTitle", sFormTitle

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

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

'-------------------------------
' Load data from recordset when form displayed first time
'-------------------------------
    if sKostenCombinatieRecordErr = "" then
      fldPRS_KOSTENSOORT_KEY = GetValue(rs, "PRS_KOSTENSOORT_KEY")
      fldPRS_KOSTENPLAATSGRP_KEY = GetValue(rs, "PRS_KOSTENPLAATSGRP_KEY")
    end if
    SetVar "KostenCombinatieRecordInsert", ""
    Parse "KostenCombinatieRecordEdit", False
'-------------------------------
' KostenCombinatieRecord ShowEdit Event begin
' KostenCombinatieRecord ShowEdit Event end
'-------------------------------
  else
    SetVar "KostenCombinatieRecordEdit", ""
    Parse "KostenCombinatieRecordInsert", False
'-------------------------------
' KostenCombinatieRecord ShowInsert Event begin
' KostenCombinatieRecord ShowInsert Event end
'-------------------------------
  end if
  Parse "KostenCombinatieRecordCancel", false
'-------------------------------
' KostenCombinatieRecord Show Event begin
' KostenCombinatieRecord Show Event end
'-------------------------------

'-------------------------------
' Show form field
'-------------------------------
      SetVar "PRS_KOSTENCOMBINATIE_KEY", ToHTML(fldPRS_KOSTENCOMBINATIE_KEY)
      SetVar "KostenCombinatieRecordLBPRS_KOSTENSOORT_KEY", ""
      openrs rsPRS_KOSTENSOORT_KEY, "select PRS_KOSTENSOORT_KEY, PRS_KOSTENSOORT_OMS from PRS_KOSTENSOORT order by 2"
      while not rsPRS_KOSTENSOORT_KEY.EOF
        SetVar "ID", GetValue(rsPRS_KOSTENSOORT_KEY, 0) : SetVar "Value", GetValue(rsPRS_KOSTENSOORT_KEY, 1)
        if cstr(GetValue(rsPRS_KOSTENSOORT_KEY, 0)) = cstr(fldPRS_KOSTENSOORT_KEY) then SetVar "Selected", "SELECTED" else SetVar "Selected", ""
        Parse "KostenCombinatieRecordLBPRS_KOSTENSOORT_KEY", True
        rsPRS_KOSTENSOORT_KEY.MoveNext
      wend
      set rsPRS_KOSTENSOORT_KEY = nothing
    
      SetVar "KostenCombinatieRecordLBPRS_KOSTENPLAATSGRP_KEY", ""
      openrs rsPRS_KOSTENPLAATSGRP_KEY, "select PRS_KOSTENPLAATSGRP_KEY, PRS_KOSTENPLAATSGRP_OMS from PRS_KOSTENPLAATSGRP order by 2"
      while not rsPRS_KOSTENPLAATSGRP_KEY.EOF
        SetVar "ID", GetValue(rsPRS_KOSTENPLAATSGRP_KEY, 0) : SetVar "Value", GetValue(rsPRS_KOSTENPLAATSGRP_KEY, 1)
        if cstr(GetValue(rsPRS_KOSTENPLAATSGRP_KEY, 0)) = cstr(fldPRS_KOSTENPLAATSGRP_KEY) then SetVar "Selected", "SELECTED" else SetVar "Selected", ""
        Parse "KostenCombinatieRecordLBPRS_KOSTENPLAATSGRP_KEY", True
        rsPRS_KOSTENPLAATSGRP_KEY.MoveNext
      wend
      set rsPRS_KOSTENPLAATSGRP_KEY = nothing
    
  Parse "FormKostenCombinatieRecord", False

'-------------------------------
' KostenCombinatieRecord Close Event begin
' KostenCombinatieRecord Close Event end
'-------------------------------

Set rs = Nothing

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