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

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


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


'===============================
' fin_btwtabelrecord PageSecurity begin
' fin_btwtabelrecord PageSecurity end
'===============================

'===============================
' fin_btwtabelrecord Open Event begin
' fin_btwtabelrecord Open Event end
'===============================

'===============================
' fin_btwtabelrecord OpenAnyPage Event begin
' fin_btwtabelrecord OpenAnyPage Event end
'===============================

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

' fin_btwtabelrecord Show begin
'===============================
' Perform the form's action
'-------------------------------
' Initialize error variables
'-------------------------------
sBTWtabelRecordErr = ""

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

' fin_btwtabelrecord Show end

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

' fin_btwtabelrecord Close Event begin
' fin_btwtabelrecord Close Event end

cn.Close
Set cn = Nothing
UnloadTemplate
'===============================
'===============================
' Action of the Record Form
'-------------------------------
Sub BTWtabelRecordAction(sAction)
'-------------------------------
' Initialize variables  
'-------------------------------
  Dim bExecSQL: bExecSQL = true
  Dim sActionFileName : sActionFileName = ""
  Dim sWhere : sWhere = "" 
  Dim bErr : bErr = False
  Dim pPKFIN_BTWTABEL_KEY : pPKFIN_BTWTABEL_KEY = ""
  Dim fldFIN_BTWTABEL_OMSCHRIJVING : fldFIN_BTWTABEL_OMSCHRIJVING = ""
  Dim fldFIN_BTWTABEL_DEFAULT : fldFIN_BTWTABEL_DEFAULT = ""
'-------------------------------

'-------------------------------
' BTWtabelRecord Action begin
'-------------------------------
  sActionFileName = "fin_btwtabelgrid.asp"

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

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

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


'-------------------------------
' Load all form fields into variables
'-------------------------------
  fldFIN_BTWTABEL_OMSCHRIJVING = GetParam("FIN_BTWTABEL_OMSCHRIJVING")
  fldFIN_BTWTABEL_DEFAULT = getCheckBoxValue(GetParam("FIN_BTWTABEL_DEFAULT"), "1", "0", "Number")

'-------------------------------
' Validate fields
'-------------------------------
  if sAction = "insert" or sAction = "update" then
'-------------------------------
' BTWtabelRecord Check Event begin
' BTWtabelRecord Check Event end
'-------------------------------
    If len(sBTWtabelRecordErr) > 0 then
      exit sub
    end if
  end if
'-------------------------------


'-------------------------------
' Create SQL statement
'-------------------------------
  select case sAction
    case "insert"
'-------------------------------
' BTWtabelRecord Insert Event begin
' BTWtabelRecord Insert Event end
'-------------------------------
      sSQL = "insert into FIN_BTWTABEL (" & _
          "FIN_BTWTABEL_OMSCHRIJVING," & _
          "FIN_BTWTABEL_DEFAULT)" & _
          " values (" & _
          ToSQL(fldFIN_BTWTABEL_OMSCHRIJVING, "Text") & "," & _
          fldFIN_BTWTABEL_DEFAULT & _
          ")"
    case "update"
'-------------------------------
' BTWtabelRecord Update Event begin
' BTWtabelRecord Update Event end
'-------------------------------
      sSQL = "update FIN_BTWTABEL set " & _
        "FIN_BTWTABEL_OMSCHRIJVING=" & ToSQL(fldFIN_BTWTABEL_OMSCHRIJVING, "Text") & _
        ",FIN_BTWTABEL_DEFAULT=" & fldFIN_BTWTABEL_DEFAULT
      sSQL = sSQL & " where " & sWhere
    case "delete"
'-------------------------------
' BTWtabelRecord Delete Event begin
dim tmpkey
tmpkey = "PK_"&strToTable(sActionFileName)&"_KEY"
sSql = customFacDelete(sActionFileName,getParam(tmpkey))
set tmpkey = Nothing
' BTWtabelRecord Delete Event end
'-------------------------------
      if sSQL = "" then
      sSQL = "delete from FIN_BTWTABEL where " & sWhere
      end if
  end select
'-------------------------------
'-------------------------------
' BTWtabelRecord BeforeExecute Event begin
' BTWtabelRecord BeforeExecute Event end
'-------------------------------

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

'===============================
' Display Record Form
'-------------------------------
Sub BTWtabelRecord_Show()
'-------------------------------
' BTWtabelRecord Show begin
'-------------------------------
  Dim sWhere : sWhere = ""
  Dim sFormTitle: sFormTitle = "Details BTW"
  Dim bPK : bPK = True

'-------------------------------
' Load primary key and form parameters
'-------------------------------
  if sBTWtabelRecordErr = "" then
    pFIN_BTWTABEL_KEY = GetParam("FIN_BTWTABEL_KEY")
    SetVar "BTWtabelRecordError", ""
  else
    fldFIN_BTWTABEL_OMSCHRIJVING = GetParam("FIN_BTWTABEL_OMSCHRIJVING")
    fldFIN_BTWTABEL_DEFAULT = getCheckBoxValue(GetParam("FIN_BTWTABEL_DEFAULT"), "1", "0", "Number")
    pFIN_BTWTABEL_KEY = GetParam("PK_FIN_BTWTABEL_KEY")
    SetVar "sBTWtabelRecordErr", sBTWtabelRecordErr
    SetVar "FormTitle", sFormTitle
    Parse "BTWtabelRecordError", False
  end if
'-------------------------------

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

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

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

  if IsEmpty(pFIN_BTWTABEL_KEY) then bPK = False
  
  sWhere = sWhere & "FIN_BTWTABEL_KEY=" & ToSQL(pFIN_BTWTABEL_KEY, "Number")
  SetVar "PK_FIN_BTWTABEL_KEY", pFIN_BTWTABEL_KEY
'-------------------------------
'-------------------------------
' BTWtabelRecord Open Event begin
' BTWtabelRecord Open Event end
'-------------------------------

  SetVar "FormTitle", sFormTitle

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

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

'-------------------------------
' Load data from recordset when form displayed first time
'-------------------------------
    if sBTWtabelRecordErr = "" then
      fldFIN_BTWTABEL_OMSCHRIJVING = GetValue(rs, "FIN_BTWTABEL_OMSCHRIJVING")
      fldFIN_BTWTABEL_DEFAULT = GetValue(rs, "FIN_BTWTABEL_DEFAULT")
    end if
    SetVar "BTWtabelRecordInsert", ""
    Parse "BTWtabelRecordEdit", False
'-------------------------------
' BTWtabelRecord ShowEdit Event begin
' BTWtabelRecord ShowEdit Event end
'-------------------------------
  else
    if sBTWtabelRecordErr = "" then
      fldFIN_BTWTABEL_DEFAULT= "1"
    end if
    SetVar "BTWtabelRecordEdit", ""
    Parse "BTWtabelRecordInsert", False
'-------------------------------
' BTWtabelRecord ShowInsert Event begin
' BTWtabelRecord ShowInsert Event end
'-------------------------------
  end if
  Parse "BTWtabelRecordCancel", false
'-------------------------------
' BTWtabelRecord Show Event begin
' BTWtabelRecord Show Event end
'-------------------------------

'-------------------------------
' Show form field
'-------------------------------
      SetVar "FIN_BTWTABEL_KEY", ToHTML(fldFIN_BTWTABEL_KEY)
      SetVar "FIN_BTWTABEL_OMSCHRIJVING", ToHTML(fldFIN_BTWTABEL_OMSCHRIJVING)
  if (LCase(fldFIN_BTWTABEL_DEFAULT) = LCase("1")) then
    SetVar "FIN_BTWTABEL_DEFAULT_CHECKED", "CHECKED"
  else
    SetVar "FIN_BTWTABEL_DEFAULT_CHECKED", ""
  end if

  Parse "FormBTWtabelRecord", False

'-------------------------------
' BTWtabelRecord Close Event begin
' BTWtabelRecord Close Event end
'-------------------------------

Set rs = Nothing

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