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

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


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


'===============================
' cad_legendawaarderecord PageSecurity begin
' cad_legendawaarderecord PageSecurity end
'===============================

'===============================
' cad_legendawaarderecord Open Event begin
' cad_legendawaarderecord Open Event end
'===============================

'===============================
' cad_legendawaarderecord OpenAnyPage Event begin
' cad_legendawaarderecord OpenAnyPage Event end
'===============================

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

' cad_legendawaarderecord Show begin
'===============================
' Perform the form's action
'-------------------------------
' Initialize error variables
'-------------------------------
sLegendaWaardeRecordErr = ""

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

' cad_legendawaarderecord Show end

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

' cad_legendawaarderecord Close Event begin
' cad_legendawaarderecord Close Event end

cn.Close
Set cn = Nothing
UnloadTemplate
'===============================
'===============================
' Action of the Record Form
'-------------------------------
Sub LegendaWaardeRecordAction(sAction)
'-------------------------------
' Initialize variables  
'-------------------------------
  Dim bExecSQL: bExecSQL = true
  Dim sActionFileName : sActionFileName = ""
  Dim sParams : sParams = "?"
  Dim sWhere : sWhere = "" 
  Dim bErr : bErr = False
  Dim pPKCAD_LEGENDAWAARDE_KEY : pPKCAD_LEGENDAWAARDE_KEY = ""
  Dim fldCAD_LEGENDA_KEY : fldCAD_LEGENDA_KEY = ""
  Dim fldCAD_LEGENDAWAARDE_VALUE : fldCAD_LEGENDAWAARDE_VALUE = ""
  Dim fldCAD_LEGENDAWAARDE_OMSCHR : fldCAD_LEGENDAWAARDE_OMSCHR = ""
  Dim fldCAD_LEGENDAWAARDE_RGB : fldCAD_LEGENDAWAARDE_RGB = ""
'-------------------------------

'-------------------------------
' LegendaWaardeRecord Action begin
'-------------------------------
  sActionFileName = "cad_legendawaardegrid.asp"
  sParams = sParams & "CAD_LEGENDA_KEY=" & ToURL(GetParam("Trn_CAD_LEGENDA_KEY")) & "&"
  sParams = sParams & "sCAD_LEGENDAWAARDE_OMSCHR=" & ToURL(GetParam("Trn_sCAD_LEGENDAWAARDE_OMSCHR"))

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

'-------------------------------
' LegendaWaardeRecord BeforeCancel Event begin
' LegendaWaardeRecord 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_LEGENDAWAARDE_KEY = GetParam("PK_CAD_LEGENDAWAARDE_KEY")
    if IsEmpty(pPKCAD_LEGENDAWAARDE_KEY) then exit sub
    sWhere = "CAD_LEGENDAWAARDE_KEY=" & ToSQL(pPKCAD_LEGENDAWAARDE_KEY, "Number")
  end if
'-------------------------------


'-------------------------------
' Load all form fields into variables
'-------------------------------
  fldCAD_LEGENDAWAARDE_KEY = GetParam("Rqd_CAD_LEGENDAWAARDE_KEY")
  fldCAD_LEGENDA_KEY = GetParam("CAD_LEGENDA_KEY")
  fldCAD_LEGENDAWAARDE_VALUE = GetParam("CAD_LEGENDAWAARDE_VALUE")
  fldCAD_LEGENDAWAARDE_OMSCHR = GetParam("CAD_LEGENDAWAARDE_OMSCHR")
  fldCAD_LEGENDAWAARDE_RGB = GetParam("CAD_LEGENDAWAARDE_RGB")

'-------------------------------
' Validate fields
'-------------------------------
  if sAction = "insert" or sAction = "update" then
    if not isNumeric(fldCAD_LEGENDA_KEY) then
      sLegendaWaardeRecordErr = sLegendaWaardeRecordErr & "De waarde in veld Legenda is niet correct.<br>"
    end if
'-------------------------------
' LegendaWaardeRecord Check Event begin
' LegendaWaardeRecord Check Event end
'-------------------------------
    If len(sLegendaWaardeRecordErr) > 0 then
      exit sub
    end if
  end if
'-------------------------------


'-------------------------------
' Create SQL statement
'-------------------------------
  select case sAction
    case "insert"
'-------------------------------
' LegendaWaardeRecord Insert Event begin
' LegendaWaardeRecord Insert Event end
'-------------------------------
      sSQL = "insert into CAD_LEGENDAWAARDE (" & _
          "CAD_LEGENDAWAARDE_KEY," & _
          "CAD_LEGENDA_KEY," & _
          "CAD_LEGENDAWAARDE_VALUE," & _
          "CAD_LEGENDAWAARDE_OMSCHR," & _
          "CAD_LEGENDAWAARDE_RGB)" & _
          " values (" & _
          ToSQL(fldCAD_LEGENDAWAARDE_KEY, "Number") & "," & _
          ToSQL(fldCAD_LEGENDA_KEY, "Number") & "," & _
          ToSQL(fldCAD_LEGENDAWAARDE_VALUE, "Text") & "," & _
          ToSQL(fldCAD_LEGENDAWAARDE_OMSCHR, "Text") & "," & _
          ToSQL(fldCAD_LEGENDAWAARDE_RGB, "Text") & _
          ")"
    case "update"
'-------------------------------
' LegendaWaardeRecord Update Event begin
' LegendaWaardeRecord Update Event end
'-------------------------------
      sSQL = "update CAD_LEGENDAWAARDE set " & _
        "CAD_LEGENDA_KEY=" & ToSQL(fldCAD_LEGENDA_KEY, "Number") & _
        ",CAD_LEGENDAWAARDE_VALUE=" & ToSQL(fldCAD_LEGENDAWAARDE_VALUE, "Text") & _
        ",CAD_LEGENDAWAARDE_OMSCHR=" & ToSQL(fldCAD_LEGENDAWAARDE_OMSCHR, "Text") & _
        ",CAD_LEGENDAWAARDE_RGB=" & ToSQL(fldCAD_LEGENDAWAARDE_RGB, "Text")
      sSQL = sSQL & " where " & sWhere
    case "delete"
'-------------------------------
' LegendaWaardeRecord Delete Event begin
' LegendaWaardeRecord Delete Event end
'-------------------------------
      sSQL = "delete from CAD_LEGENDAWAARDE where " & sWhere
  end select
'-------------------------------
'-------------------------------
' LegendaWaardeRecord BeforeExecute Event begin
' LegendaWaardeRecord BeforeExecute Event end
'-------------------------------

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

'===============================
' Display Record Form
'-------------------------------
Sub LegendaWaardeRecord_Show()
'-------------------------------
' LegendaWaardeRecord Show begin
'-------------------------------
  Dim sWhere : sWhere = ""
  Dim sFormTitle: sFormTitle = "Details legendawaarde"
  Dim bPK : bPK = True

'-------------------------------
' Load primary key and form parameters
'-------------------------------
  if sLegendaWaardeRecordErr = "" then
    fldCAD_LEGENDAWAARDE_KEY = GetParam("CAD_LEGENDAWAARDE_KEY")
    fldCAD_LEGENDA_KEY = GetParam("CAD_LEGENDA_KEY")
    SetVar "Trn_CAD_LEGENDA_KEY", GetParam("CAD_LEGENDA_KEY")
    SetVar "Trn_sCAD_LEGENDAWAARDE_OMSCHR", GetParam("sCAD_LEGENDAWAARDE_OMSCHR")
    SetVar "Rqd_CAD_LEGENDAWAARDE_KEY", GetParam("CAD_LEGENDAWAARDE_KEY")
    pCAD_LEGENDAWAARDE_KEY = GetParam("CAD_LEGENDAWAARDE_KEY")
    SetVar "LegendaWaardeRecordError", ""
  else
    fldCAD_LEGENDA_KEY = GetParam("CAD_LEGENDA_KEY")
    fldCAD_LEGENDAWAARDE_VALUE = GetParam("CAD_LEGENDAWAARDE_VALUE")
    fldCAD_LEGENDAWAARDE_OMSCHR = GetParam("CAD_LEGENDAWAARDE_OMSCHR")
    fldCAD_LEGENDAWAARDE_RGB = GetParam("CAD_LEGENDAWAARDE_RGB")
    SetVar "Rqd_CAD_LEGENDAWAARDE_KEY", GetParam("Rqd_CAD_LEGENDAWAARDE_KEY")
    SetVar "Trn_CAD_LEGENDA_KEY", GetParam("Trn_CAD_LEGENDA_KEY")
    SetVar "Trn_sCAD_LEGENDAWAARDE_OMSCHR", GetParam("Trn_sCAD_LEGENDAWAARDE_OMSCHR")
    pCAD_LEGENDAWAARDE_KEY = GetParam("PK_CAD_LEGENDAWAARDE_KEY")
    SetVar "sLegendaWaardeRecordErr", sLegendaWaardeRecordErr
    SetVar "FormTitle", sFormTitle
    Parse "LegendaWaardeRecordError", False
  end if
'-------------------------------

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

  fldPicker = GetParam("Picker")
'-------------------------------

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

  if IsEmpty(pCAD_LEGENDAWAARDE_KEY) then bPK = False
  
  sWhere = sWhere & "CAD_LEGENDAWAARDE_KEY=" & ToSQL(pCAD_LEGENDAWAARDE_KEY, "Number")
  SetVar "PK_CAD_LEGENDAWAARDE_KEY", pCAD_LEGENDAWAARDE_KEY
'-------------------------------
'-------------------------------
' LegendaWaardeRecord Open Event begin
' LegendaWaardeRecord Open Event end
'-------------------------------

  SetVar "FormTitle", sFormTitle

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

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

'-------------------------------
' Load data from recordset when form displayed first time
'-------------------------------
    if sLegendaWaardeRecordErr = "" then
      fldCAD_LEGENDA_KEY = GetValue(rs, "CAD_LEGENDA_KEY")
      fldCAD_LEGENDAWAARDE_VALUE = GetValue(rs, "CAD_LEGENDAWAARDE_VALUE")
      fldCAD_LEGENDAWAARDE_OMSCHR = GetValue(rs, "CAD_LEGENDAWAARDE_OMSCHR")
      fldCAD_LEGENDAWAARDE_RGB = GetValue(rs, "CAD_LEGENDAWAARDE_RGB")
    end if
    SetVar "LegendaWaardeRecordInsert", ""
    Parse "LegendaWaardeRecordEdit", False
'-------------------------------
' LegendaWaardeRecord ShowEdit Event begin
' LegendaWaardeRecord ShowEdit Event end
'-------------------------------
  else
    if sLegendaWaardeRecordErr = "" then
      fldCAD_LEGENDAWAARDE_KEY = ToHTML(GetParam("CAD_LEGENDAWAARDE_KEY"))
      fldCAD_LEGENDA_KEY = ToHTML(GetParam("CAD_LEGENDA_KEY"))
      fldCAD_LEGENDAWAARDE_RGB= "FFFFFF"
      fldPicker= "<SPAN onClick=""cp.show('pick');return false;"" NAME='pick' ID='pick'>&nbsp;"&FCLTLCL("Kies")&"&nbsp;</SPAN>"
    end if
    SetVar "LegendaWaardeRecordEdit", ""
    Parse "LegendaWaardeRecordInsert", False
'-------------------------------
' LegendaWaardeRecord ShowInsert Event begin
' LegendaWaardeRecord ShowInsert Event end
'-------------------------------
  end if
  Parse "LegendaWaardeRecordCancel", false

'-------------------------------
' Set default values
'-------------------------------
  fldPicker= "<SPAN onClick=""cp.show('pick');return false;"" NAME='pick' ID='pick'>&nbsp;"&FCLTLCL("Kies")&"&nbsp;</SPAN>"
  if sLegendaWaardeRecordErr = "" then
'-------------------------------
' LegendaWaardeRecord Show Event begin
fldPicker = "<span id=pickClr name=pickClr style=""border:1;width:32;height:16;background-color:" & fldCAD_LEGENDAWAARDE_RGB & """>"+fldPicker+"</span>"
' LegendaWaardeRecord Show Event end
'-------------------------------
  end if

'-------------------------------
' Show form field
'-------------------------------
      SetVar "CAD_LEGENDAWAARDE_KEY", ToHTML(fldCAD_LEGENDAWAARDE_KEY)
      SetVar "LegendaWaardeRecordLBCAD_LEGENDA_KEY", ""
      openrs rsCAD_LEGENDA_KEY, "select CAD_LEGENDA_KEY, CAD_LEGENDA_OMSCHRIJVING from CAD_LEGENDA order by 2"
      while not rsCAD_LEGENDA_KEY.EOF
        SetVar "ID", GetValue(rsCAD_LEGENDA_KEY, 0) : SetVar "Value", GetValue(rsCAD_LEGENDA_KEY, 1)
        if cstr(GetValue(rsCAD_LEGENDA_KEY, 0)) = cstr(fldCAD_LEGENDA_KEY) then SetVar "Selected", "SELECTED" else SetVar "Selected", ""
        Parse "LegendaWaardeRecordLBCAD_LEGENDA_KEY", True
        rsCAD_LEGENDA_KEY.MoveNext
      wend
      set rsCAD_LEGENDA_KEY = nothing
    
      SetVar "CAD_LEGENDAWAARDE_VALUE", ToHTML(fldCAD_LEGENDAWAARDE_VALUE)
      SetVar "CAD_LEGENDAWAARDE_OMSCHR", ToHTML(fldCAD_LEGENDAWAARDE_OMSCHR)
      SetVar "CAD_LEGENDAWAARDE_RGB", ToHTML(fldCAD_LEGENDAWAARDE_RGB)
      SetVar "Picker", fldPicker
  Parse "FormLegendaWaardeRecord", False

'-------------------------------
' LegendaWaardeRecord Close Event begin
' LegendaWaardeRecord Close Event end
'-------------------------------

Set rs = Nothing

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