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

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


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


'===============================
' cad_legendarecord PageSecurity begin
' cad_legendarecord PageSecurity end
'===============================

'===============================
' cad_legendarecord Open Event begin
' cad_legendarecord Open Event end
'===============================

'===============================
' cad_legendarecord OpenAnyPage Event begin
' cad_legendarecord OpenAnyPage Event end
'===============================

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

' cad_legendarecord Show begin
'===============================
' Perform the form's action
'-------------------------------
' Initialize error variables
'-------------------------------
sLegendaRecordErr = ""

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

' cad_legendarecord Show end

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

' cad_legendarecord Close Event begin
' cad_legendarecord Close Event end

cn.Close
Set cn = Nothing
UnloadTemplate
'===============================
'===============================
' Action of the Record Form
'-------------------------------
Sub LegendaRecordAction(sAction)
'-------------------------------
' Initialize variables  
'-------------------------------
  Dim bExecSQL: bExecSQL = true
  Dim sActionFileName : sActionFileName = ""
  Dim sParams : sParams = "?"
  Dim sWhere : sWhere = "" 
  Dim bErr : bErr = False
  Dim pPKCAD_LEGENDA_KEY : pPKCAD_LEGENDA_KEY = ""
  Dim fldCAD_LEGENDA_OMSCHRIJVING : fldCAD_LEGENDA_OMSCHRIJVING = ""
  Dim fldCAD_LEGENDA_DISCREET : fldCAD_LEGENDA_DISCREET = ""
'-------------------------------

'-------------------------------
' LegendaRecord Action begin
'-------------------------------
  sActionFileName = "cad_legendagrid.asp"
  sParams = sParams & "sCAD_LEGENDA_OMSCHRIJVING=" & ToURL(GetParam("Trn_sCAD_LEGENDA_OMSCHRIJVING"))

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

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

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


'-------------------------------
' Load all form fields into variables
'-------------------------------
  fldCAD_LEGENDA_OMSCHRIJVING = GetParam("CAD_LEGENDA_OMSCHRIJVING")
  fldCAD_LEGENDA_DISCREET = getCheckBoxValue(GetParam("CAD_LEGENDA_DISCREET"), "1", "0", "Number")

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


'-------------------------------
' Create SQL statement
'-------------------------------
  select case sAction
    case "insert"
'-------------------------------
' LegendaRecord Insert Event begin
' LegendaRecord Insert Event end
'-------------------------------
      sSQL = "insert into CAD_LEGENDA (" & _
          "CAD_LEGENDA_OMSCHRIJVING," & _
          "CAD_LEGENDA_DISCREET)" & _
          " values (" & _
          ToSQL(fldCAD_LEGENDA_OMSCHRIJVING, "Text") & "," & _
          fldCAD_LEGENDA_DISCREET & _
          ")"
    case "update"
'-------------------------------
' LegendaRecord Update Event begin
' LegendaRecord Update Event end
'-------------------------------
      sSQL = "update CAD_LEGENDA set " & _
        "CAD_LEGENDA_OMSCHRIJVING=" & ToSQL(fldCAD_LEGENDA_OMSCHRIJVING, "Text") & _
        ",CAD_LEGENDA_DISCREET=" & fldCAD_LEGENDA_DISCREET
      sSQL = sSQL & " where " & sWhere
    case "delete"
'-------------------------------
' LegendaRecord Delete Event begin
' LegendaRecord Delete Event end
'-------------------------------
      sSQL = "delete from CAD_LEGENDA where " & sWhere
  end select
'-------------------------------
'-------------------------------
' LegendaRecord BeforeExecute Event begin
' LegendaRecord BeforeExecute Event end
'-------------------------------

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

'===============================
' Display Record Form
'-------------------------------
Sub LegendaRecord_Show()
'-------------------------------
' LegendaRecord Show begin
'-------------------------------
  Dim sWhere : sWhere = ""
  Dim sFormTitle: sFormTitle = "Details Legenda"
  Dim bPK : bPK = True

'-------------------------------
' Load primary key and form parameters
'-------------------------------
  if sLegendaRecordErr = "" then
    SetVar "Trn_sCAD_LEGENDA_OMSCHRIJVING", GetParam("sCAD_LEGENDA_OMSCHRIJVING")
    pCAD_LEGENDA_KEY = GetParam("CAD_LEGENDA_KEY")
    SetVar "LegendaRecordError", ""
  else
    fldCAD_LEGENDA_OMSCHRIJVING = GetParam("CAD_LEGENDA_OMSCHRIJVING")
    fldCAD_LEGENDA_DISCREET = getCheckBoxValue(GetParam("CAD_LEGENDA_DISCREET"), "1", "0", "Number")
    SetVar "Trn_sCAD_LEGENDA_OMSCHRIJVING", GetParam("Trn_sCAD_LEGENDA_OMSCHRIJVING")
    pCAD_LEGENDA_KEY = GetParam("PK_CAD_LEGENDA_KEY")
    SetVar "sLegendaRecordErr", sLegendaRecordErr
    SetVar "FormTitle", sFormTitle
    Parse "LegendaRecordError", False
  end if
'-------------------------------

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

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

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

  if IsEmpty(pCAD_LEGENDA_KEY) then bPK = False
  
  sWhere = sWhere & "CAD_LEGENDA_KEY=" & ToSQL(pCAD_LEGENDA_KEY, "Number")
  SetVar "PK_CAD_LEGENDA_KEY", pCAD_LEGENDA_KEY
'-------------------------------
'-------------------------------
' LegendaRecord Open Event begin
' LegendaRecord Open Event end
'-------------------------------

  SetVar "FormTitle", sFormTitle

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

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

'-------------------------------
' Load data from recordset when form displayed first time
'-------------------------------
    if sLegendaRecordErr = "" then
      fldCAD_LEGENDA_OMSCHRIJVING = GetValue(rs, "CAD_LEGENDA_OMSCHRIJVING")
      fldCAD_LEGENDA_DISCREET = GetValue(rs, "CAD_LEGENDA_DISCREET")
    end if
    SetVar "LegendaRecordInsert", ""
    Parse "LegendaRecordEdit", False
'-------------------------------
' LegendaRecord ShowEdit Event begin
' LegendaRecord ShowEdit Event end
'-------------------------------
  else
    if sLegendaRecordErr = "" then
      fldCAD_LEGENDA_DISCREET= "1"
    end if
    SetVar "LegendaRecordEdit", ""
    Parse "LegendaRecordInsert", False
'-------------------------------
' LegendaRecord ShowInsert Event begin
' LegendaRecord ShowInsert Event end
'-------------------------------
  end if
  Parse "LegendaRecordCancel", false
'-------------------------------
' LegendaRecord Show Event begin
' LegendaRecord Show Event end
'-------------------------------

'-------------------------------
' Show form field
'-------------------------------
      SetVar "CAD_LEGENDA_KEY", ToHTML(fldCAD_LEGENDA_KEY)
      SetVar "CAD_LEGENDA_OMSCHRIJVING", ToHTML(fldCAD_LEGENDA_OMSCHRIJVING)
  if (LCase(fldCAD_LEGENDA_DISCREET) = LCase("1")) then
    SetVar "CAD_LEGENDA_DISCREET_CHECKED", "CHECKED"
  else
    SetVar "CAD_LEGENDA_DISCREET_CHECKED", ""
  end if

  Parse "FormLegendaRecord", False

'-------------------------------
' LegendaRecord Close Event begin
' LegendaRecord Close Event end
'-------------------------------

Set rs = Nothing

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