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

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


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


'===============================
' fin_btwtabelwaarderecord PageSecurity begin
' fin_btwtabelwaarderecord PageSecurity end
'===============================

'===============================
' fin_btwtabelwaarderecord Open Event begin
' fin_btwtabelwaarderecord Open Event end
'===============================

'===============================
' fin_btwtabelwaarderecord OpenAnyPage Event begin
' fin_btwtabelwaarderecord OpenAnyPage Event end
'===============================

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

' fin_btwtabelwaarderecord Show begin
'===============================
' Perform the form's action
'-------------------------------
' Initialize error variables
'-------------------------------
sBTWTabelWaardeRecordErr = ""

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

' fin_btwtabelwaarderecord Show end

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

' fin_btwtabelwaarderecord Close Event begin
' fin_btwtabelwaarderecord Close Event end

cn.Close
Set cn = Nothing
UnloadTemplate
'===============================
'===============================
' Action of the Record Form
'-------------------------------
Sub BTWTabelWaardeRecordAction(sAction)
'-------------------------------
' Initialize variables  
'-------------------------------
  Dim bExecSQL: bExecSQL = true
  Dim sActionFileName : sActionFileName = ""
  Dim sParams : sParams = "?"
  Dim sWhere : sWhere = "" 
  Dim bErr : bErr = False
  Dim pPKFIN_BTWTABELWAARDE_KEY : pPKFIN_BTWTABELWAARDE_KEY = ""
  Dim fldFIN_BTWTABEL_KEY : fldFIN_BTWTABEL_KEY = ""
  Dim fldFIN_BTWTABELWAARDE_CODE : fldFIN_BTWTABELWAARDE_CODE = ""
  Dim fldFIN_BTWTABELWAARDE_OMS : fldFIN_BTWTABELWAARDE_OMS = ""
  Dim fldFIN_BTWTABELWAARDE_PERC : fldFIN_BTWTABELWAARDE_PERC = ""
  Dim fldFIN_BTWTABELWAARDE_VERLEGD : fldFIN_BTWTABELWAARDE_VERLEGD = ""
'-------------------------------

'-------------------------------
' BTWTabelWaardeRecord Action begin
'-------------------------------
  sActionFileName = "fin_btwtabelwaardegrid.asp"
  sParams = sParams & "FIN_BTWTABEL_KEY=" & ToURL(GetParam("Trn_FIN_BTWTABEL_KEY"))

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

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

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


'-------------------------------
' Load all form fields into variables
'-------------------------------
  fldFIN_BTWTABELWAARDE_KEY = GetParam("Rqd_FIN_BTWTABELWAARDE_KEY")
  fldFIN_BTWTABEL_KEY = GetParam("FIN_BTWTABEL_KEY")
  fldFIN_BTWTABELWAARDE_CODE = GetParam("FIN_BTWTABELWAARDE_CODE")
  fldFIN_BTWTABELWAARDE_OMS = GetParam("FIN_BTWTABELWAARDE_OMS")
  fldFIN_BTWTABELWAARDE_PERC = GetParam("FIN_BTWTABELWAARDE_PERC")
  fldFIN_BTWTABELWAARDE_VERLEGD = getCheckBoxValue(GetParam("FIN_BTWTABELWAARDE_VERLEGD"), "1", "0", "Number")

'-------------------------------
' Validate fields
'-------------------------------
  if sAction = "insert" or sAction = "update" then
    if not isNumeric(fldFIN_BTWTABEL_KEY) then
      sBTWTabelWaardeRecordErr = sBTWTabelWaardeRecordErr & "De waarde in veld BTW Tabel is niet correct.<br>"
    end if
    if not isNumeric(fldFIN_BTWTABELWAARDE_PERC) then
      sBTWTabelWaardeRecordErr = sBTWTabelWaardeRecordErr & "De waarde in veld Percentage is niet correct.<br>"
    end if
'-------------------------------
' BTWTabelWaardeRecord Check Event begin
cn.execute "alter session set NLS_DATE_FORMAT='DD-MM-YYYY'"
fldFIN_BTWTABELWAARDE_PERC = SafeToDouble(fldFIN_BTWTABELWAARDE_PERC)
' BTWTabelWaardeRecord Check Event end
'-------------------------------
    If len(sBTWTabelWaardeRecordErr) > 0 then
      exit sub
    end if
  end if
'-------------------------------


'-------------------------------
' Create SQL statement
'-------------------------------
  select case sAction
    case "insert"
'-------------------------------
' BTWTabelWaardeRecord Insert Event begin
' BTWTabelWaardeRecord Insert Event end
'-------------------------------
      sSQL = "insert into FIN_BTWTABELWAARDE (" & _
          "FIN_BTWTABELWAARDE_KEY," & _
          "FIN_BTWTABEL_KEY," & _
          "FIN_BTWTABELWAARDE_CODE," & _
          "FIN_BTWTABELWAARDE_OMS," & _
          "FIN_BTWTABELWAARDE_PERC," & _
          "FIN_BTWTABELWAARDE_VERLEGD)" & _
          " values (" & _
          ToSQL(fldFIN_BTWTABELWAARDE_KEY, "Number") & "," & _
          ToSQL(fldFIN_BTWTABEL_KEY, "Number") & "," & _
          ToSQL(fldFIN_BTWTABELWAARDE_CODE, "Text") & "," & _
          ToSQL(fldFIN_BTWTABELWAARDE_OMS, "Text") & "," & _
          ToSQL(fldFIN_BTWTABELWAARDE_PERC, "Number") & "," & _
          fldFIN_BTWTABELWAARDE_VERLEGD & _
          ")"
    case "update"
'-------------------------------
' BTWTabelWaardeRecord Update Event begin
' BTWTabelWaardeRecord Update Event end
'-------------------------------
      sSQL = "update FIN_BTWTABELWAARDE set " & _
        "FIN_BTWTABEL_KEY=" & ToSQL(fldFIN_BTWTABEL_KEY, "Number") & _
        ",FIN_BTWTABELWAARDE_CODE=" & ToSQL(fldFIN_BTWTABELWAARDE_CODE, "Text") & _
        ",FIN_BTWTABELWAARDE_OMS=" & ToSQL(fldFIN_BTWTABELWAARDE_OMS, "Text") & _
        ",FIN_BTWTABELWAARDE_PERC=" & ToSQL(fldFIN_BTWTABELWAARDE_PERC, "Number") & _
        ",FIN_BTWTABELWAARDE_VERLEGD=" & fldFIN_BTWTABELWAARDE_VERLEGD
      sSQL = sSQL & " where " & sWhere
    case "delete"
'-------------------------------
' BTWTabelWaardeRecord Delete Event begin
dim tmpkey
tmpkey = "PK_"&strToTable(sActionFileName)&"_KEY"
sSql = customFacDelete(sActionFileName,getParam(tmpkey))
set tmpkey = Nothing
' BTWTabelWaardeRecord Delete Event end
'-------------------------------
      if sSQL = "" then
      sSQL = "delete from FIN_BTWTABELWAARDE where " & sWhere
      end if
  end select
'-------------------------------
'-------------------------------
' BTWTabelWaardeRecord BeforeExecute Event begin
' BTWTabelWaardeRecord BeforeExecute Event end
'-------------------------------

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

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

'-------------------------------
' Load primary key and form parameters
'-------------------------------
  if sBTWTabelWaardeRecordErr = "" then
    fldFIN_BTWTABELWAARDE_KEY = GetParam("FIN_BTWTABELWAARDE_KEY")
    fldFIN_BTWTABEL_KEY = GetParam("FIN_BTWTABEL_KEY")
    SetVar "Trn_FIN_BTWTABEL_KEY", GetParam("FIN_BTWTABEL_KEY")
    SetVar "Rqd_FIN_BTWTABELWAARDE_KEY", GetParam("FIN_BTWTABELWAARDE_KEY")
    pFIN_BTWTABELWAARDE_KEY = GetParam("FIN_BTWTABELWAARDE_KEY")
    SetVar "BTWTabelWaardeRecordError", ""
  else
    fldFIN_BTWTABEL_KEY = GetParam("FIN_BTWTABEL_KEY")
    fldFIN_BTWTABELWAARDE_CODE = GetParam("FIN_BTWTABELWAARDE_CODE")
    fldFIN_BTWTABELWAARDE_OMS = GetParam("FIN_BTWTABELWAARDE_OMS")
    fldFIN_BTWTABELWAARDE_PERC = GetParam("FIN_BTWTABELWAARDE_PERC")
    fldFIN_BTWTABELWAARDE_VERLEGD = getCheckBoxValue(GetParam("FIN_BTWTABELWAARDE_VERLEGD"), "1", "0", "Number")
    SetVar "Rqd_FIN_BTWTABELWAARDE_KEY", GetParam("Rqd_FIN_BTWTABELWAARDE_KEY")
    SetVar "Trn_FIN_BTWTABEL_KEY", GetParam("Trn_FIN_BTWTABEL_KEY")
    pFIN_BTWTABELWAARDE_KEY = GetParam("PK_FIN_BTWTABELWAARDE_KEY")
    SetVar "sBTWTabelWaardeRecordErr", sBTWTabelWaardeRecordErr
    SetVar "FormTitle", sFormTitle
    Parse "BTWTabelWaardeRecordError", False
  end if
'-------------------------------

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

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

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

  if IsEmpty(pFIN_BTWTABELWAARDE_KEY) then bPK = False
  
  sWhere = sWhere & "FIN_BTWTABELWAARDE_KEY=" & ToSQL(pFIN_BTWTABELWAARDE_KEY, "Number")
  SetVar "PK_FIN_BTWTABELWAARDE_KEY", pFIN_BTWTABELWAARDE_KEY
'-------------------------------
'-------------------------------
' BTWTabelWaardeRecord Open Event begin
' BTWTabelWaardeRecord Open Event end
'-------------------------------

  SetVar "FormTitle", sFormTitle

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

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

'-------------------------------
' Load data from recordset when form displayed first time
'-------------------------------
    if sBTWTabelWaardeRecordErr = "" then
      fldFIN_BTWTABEL_KEY = GetValue(rs, "FIN_BTWTABEL_KEY")
      fldFIN_BTWTABELWAARDE_CODE = GetValue(rs, "FIN_BTWTABELWAARDE_CODE")
      fldFIN_BTWTABELWAARDE_OMS = GetValue(rs, "FIN_BTWTABELWAARDE_OMS")
      fldFIN_BTWTABELWAARDE_PERC = GetValue(rs, "FIN_BTWTABELWAARDE_PERC")
      fldFIN_BTWTABELWAARDE_VERLEGD = GetValue(rs, "FIN_BTWTABELWAARDE_VERLEGD")
    end if
    SetVar "BTWTabelWaardeRecordInsert", ""
    Parse "BTWTabelWaardeRecordEdit", False
'-------------------------------
' BTWTabelWaardeRecord ShowEdit Event begin
' BTWTabelWaardeRecord ShowEdit Event end
'-------------------------------
  else
    if sBTWTabelWaardeRecordErr = "" then
      fldFIN_BTWTABELWAARDE_KEY = ToHTML(GetParam("FIN_BTWTABELWAARDE_KEY"))
      fldFIN_BTWTABEL_KEY = ToHTML(GetParam("FIN_BTWTABEL_KEY"))
      fldFIN_BTWTABELWAARDE_PERC= "0"
    end if
    SetVar "BTWTabelWaardeRecordEdit", ""
    Parse "BTWTabelWaardeRecordInsert", False
'-------------------------------
' BTWTabelWaardeRecord ShowInsert Event begin
' BTWTabelWaardeRecord ShowInsert Event end
'-------------------------------
  end if
  Parse "BTWTabelWaardeRecordCancel", false
'-------------------------------
' BTWTabelWaardeRecord Show Event begin
' BTWTabelWaardeRecord Show Event end
'-------------------------------

'-------------------------------
' Show form field
'-------------------------------
      SetVar "FIN_BTWTABELWAARDE_KEY", ToHTML(fldFIN_BTWTABELWAARDE_KEY)
      SetVar "BTWTabelWaardeRecordLBFIN_BTWTABEL_KEY", ""
      openrs rsFIN_BTWTABEL_KEY, "select FIN_BTWTABEL_KEY, FIN_BTWTABEL_OMSCHRIJVING from FIN_BTWTABEL order by 2"
      while not rsFIN_BTWTABEL_KEY.EOF
        SetVar "ID", GetValue(rsFIN_BTWTABEL_KEY, 0) : SetVar "Value", GetValue(rsFIN_BTWTABEL_KEY, 1)
        if cstr(GetValue(rsFIN_BTWTABEL_KEY, 0)) = cstr(fldFIN_BTWTABEL_KEY) then SetVar "Selected", "SELECTED" else SetVar "Selected", ""
        Parse "BTWTabelWaardeRecordLBFIN_BTWTABEL_KEY", True
        rsFIN_BTWTABEL_KEY.MoveNext
      wend
      set rsFIN_BTWTABEL_KEY = nothing
    
      SetVar "FIN_BTWTABELWAARDE_CODE", ToHTML(fldFIN_BTWTABELWAARDE_CODE)
      SetVar "FIN_BTWTABELWAARDE_OMS", ToHTML(fldFIN_BTWTABELWAARDE_OMS)
      SetVar "FIN_BTWTABELWAARDE_PERC", ToHTML(fldFIN_BTWTABELWAARDE_PERC)
  if (LCase(fldFIN_BTWTABELWAARDE_VERLEGD) = LCase("1")) then
    SetVar "FIN_BTWTABELWAARDE_VERLEGD_CHECKED", "CHECKED"
  else
    SetVar "FIN_BTWTABELWAARDE_VERLEGD_CHECKED", ""
  end if

  Parse "FormBTWTabelWaardeRecord", False

'-------------------------------
' BTWTabelWaardeRecord Close Event begin
' BTWTabelWaardeRecord Close Event end
'-------------------------------

Set rs = Nothing

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