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

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


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


'===============================
' cad_labelrecord PageSecurity begin
' cad_labelrecord PageSecurity end
'===============================

'===============================
' cad_labelrecord Open Event begin
' cad_labelrecord Open Event end
'===============================

'===============================
' cad_labelrecord OpenAnyPage Event begin
' cad_labelrecord OpenAnyPage Event end
'===============================

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

' cad_labelrecord Show begin
'===============================
' Perform the form's action
'-------------------------------
' Initialize error variables
'-------------------------------
sLabelRecordErr = ""

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

' cad_labelrecord Show end

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

' cad_labelrecord Close Event begin
' cad_labelrecord Close Event end

cn.Close
Set cn = Nothing
UnloadTemplate
'===============================
'===============================
' Action of the Record Form
'-------------------------------
Sub LabelRecordAction(sAction)
'-------------------------------
' Initialize variables  
'-------------------------------
  Dim bExecSQL: bExecSQL = true
  Dim sActionFileName : sActionFileName = ""
  Dim sParams : sParams = "?"
  Dim sWhere : sWhere = "" 
  Dim bErr : bErr = False
  Dim pPKCAD_LABEL_KEY : pPKCAD_LABEL_KEY = ""
  Dim fldCAD_LABEL_OMSCHRIJVING : fldCAD_LABEL_OMSCHRIJVING = ""
  Dim fldCAD_LABEL_VIEW : fldCAD_LABEL_VIEW = ""
  Dim fldCAD_LABEL_SIZE : fldCAD_LABEL_SIZE = ""
  Dim fldLabel : fldLabel = ""
  Dim fldFAC_FUNCTIE_KEY : fldFAC_FUNCTIE_KEY = ""
  Dim fldCAD_LABEL_TYPE : fldCAD_LABEL_TYPE = ""
  Dim fldWaar : fldWaar = ""
  Dim fldScenario : fldScenario = ""
'-------------------------------

'-------------------------------
' LabelRecord Action begin
'-------------------------------
  sActionFileName = "cad_labelgrid.asp"
  sParams = sParams & "sCAD_LABEL_OMSCHRIJVING=" & ToURL(GetParam("Trn_sCAD_LABEL_OMSCHRIJVING"))

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

'-------------------------------
' LabelRecord BeforeCancel Event begin
' LabelRecord 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_LABEL_KEY = GetParam("PK_CAD_LABEL_KEY")
    if IsEmpty(pPKCAD_LABEL_KEY) then exit sub
    sWhere = "CAD_LABEL_KEY=" & ToSQL(pPKCAD_LABEL_KEY, "Number")
  end if
'-------------------------------


'-------------------------------
' Load all form fields into variables
'-------------------------------
  fldCAD_LABEL_OMSCHRIJVING = GetParam("CAD_LABEL_OMSCHRIJVING")
  fldCAD_LABEL_VIEW = GetParam("CAD_LABEL_VIEW")
  fldCAD_LABEL_SIZE = GetParam("CAD_LABEL_SIZE")
  fldLabel = getCheckBoxValue(GetParam("Label"), "1", "0", "Number")
  fldFAC_FUNCTIE_KEY = GetParam("FAC_FUNCTIE_KEY")
  fldCAD_LABEL_TYPE = GetParam("CAD_LABEL_TYPE")
  fldWaar = GetParam("Waar")
  fldScenario = GetParam("Scenario")

'-------------------------------
' Validate fields
'-------------------------------
  if sAction = "insert" or sAction = "update" then
    if not isNumeric(fldCAD_LABEL_SIZE) then
      sLabelRecordErr = sLabelRecordErr & "De waarde in veld Label grootte is niet correct.<br>"
    end if
    if not isNumeric(fldFAC_FUNCTIE_KEY) then
      sLabelRecordErr = sLabelRecordErr & "De waarde in veld Autorisatie Als is niet correct.<br>"
    end if
'-------------------------------
' LabelRecord Check Event begin
fldCAD_LABEL_TYPE = CInt(fldWaar) + CInt(fldScenario)

If (fldLabel = 0) Then
  fldCAD_LABEL_SIZE = -1 * fldCAD_LABEL_SIZE
End If
' LabelRecord Check Event end
'-------------------------------
    If len(sLabelRecordErr) > 0 then
      exit sub
    end if
  end if
'-------------------------------


'-------------------------------
' Create SQL statement
'-------------------------------
  select case sAction
    case "insert"
'-------------------------------
' LabelRecord Insert Event begin
' LabelRecord Insert Event end
'-------------------------------
      sSQL = "insert into CAD_LABEL (" & _
          "CAD_LABEL_OMSCHRIJVING," & _
          "CAD_LABEL_VIEW," & _
          "CAD_LABEL_SIZE," & _
          "FAC_FUNCTIE_KEY," & _
          "CAD_LABEL_TYPE)" & _
          " values (" & _
          ToSQL(fldCAD_LABEL_OMSCHRIJVING, "Text") & "," & _
          ToSQL(fldCAD_LABEL_VIEW, "Text") & "," & _
          ToSQL(fldCAD_LABEL_SIZE, "Number") & "," & _
          ToSQL(fldFAC_FUNCTIE_KEY, "Number") & "," & _
          ToSQL(fldCAD_LABEL_TYPE, "Text") & _
          ")"
    case "update"
'-------------------------------
' LabelRecord Update Event begin
' LabelRecord Update Event end
'-------------------------------
      sSQL = "update CAD_LABEL set " & _
        "CAD_LABEL_OMSCHRIJVING=" & ToSQL(fldCAD_LABEL_OMSCHRIJVING, "Text") & _
        ",CAD_LABEL_VIEW=" & ToSQL(fldCAD_LABEL_VIEW, "Text") & _
        ",CAD_LABEL_SIZE=" & ToSQL(fldCAD_LABEL_SIZE, "Number") & _
        ",FAC_FUNCTIE_KEY=" & ToSQL(fldFAC_FUNCTIE_KEY, "Number") & _
        ",CAD_LABEL_TYPE=" & ToSQL(fldCAD_LABEL_TYPE, "Text")
      sSQL = sSQL & " where " & sWhere
    case "delete"
'-------------------------------
' LabelRecord Delete Event begin
' LabelRecord Delete Event end
'-------------------------------
      sSQL = "delete from CAD_LABEL where " & sWhere
  end select
'-------------------------------
'-------------------------------
' LabelRecord BeforeExecute Event begin
' LabelRecord BeforeExecute Event end
'-------------------------------

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

'===============================
' Display Record Form
'-------------------------------
Sub LabelRecord_Show()
'-------------------------------
' LabelRecord Show begin
'-------------------------------
  Dim sWhere : sWhere = ""
  Dim sFormTitle: sFormTitle = "Details label"
  Dim bPK : bPK = True
  Dim sFAC_FUNCTIE_KEYDisplayValue: sFAC_FUNCTIE_KEYDisplayValue = ""

'-------------------------------
' Load primary key and form parameters
'-------------------------------
  if sLabelRecordErr = "" then
    SetVar "Trn_sCAD_LABEL_OMSCHRIJVING", GetParam("sCAD_LABEL_OMSCHRIJVING")
    pCAD_LABEL_KEY = GetParam("CAD_LABEL_KEY")
    SetVar "LabelRecordError", ""
  else
    fldCAD_LABEL_OMSCHRIJVING = GetParam("CAD_LABEL_OMSCHRIJVING")
    fldCAD_LABEL_VIEW = GetParam("CAD_LABEL_VIEW")
    fldCAD_LABEL_SIZE = GetParam("CAD_LABEL_SIZE")
    fldFAC_FUNCTIE_KEY = GetParam("FAC_FUNCTIE_KEY")
    fldCAD_LABEL_TYPE = GetParam("CAD_LABEL_TYPE")
    SetVar "Trn_sCAD_LABEL_OMSCHRIJVING", GetParam("Trn_sCAD_LABEL_OMSCHRIJVING")
    pCAD_LABEL_KEY = GetParam("PK_CAD_LABEL_KEY")
    SetVar "sLabelRecordErr", sLabelRecordErr
    SetVar "FormTitle", sFormTitle
    Parse "LabelRecordError", False
  end if
'-------------------------------

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

  fldLabel = GetParam("Label")
  fldWaar = GetParam("Waar")
  fldScenario = GetParam("Scenario")
'-------------------------------

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

  if IsEmpty(pCAD_LABEL_KEY) then bPK = False
  
  sWhere = sWhere & "CAD_LABEL_KEY=" & ToSQL(pCAD_LABEL_KEY, "Number")
  SetVar "PK_CAD_LABEL_KEY", pCAD_LABEL_KEY
'-------------------------------
'-------------------------------
' LabelRecord Open Event begin
' LabelRecord Open Event end
'-------------------------------

  SetVar "FormTitle", sFormTitle

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

'-------------------------------
' Load all fields into variables from recordset or input parameters
'-------------------------------
  if bIsUpdateMode then
    fldCAD_LABEL_KEY = GetValue(rs, "CAD_LABEL_KEY")
    fldCAD_LABEL_TYPE = GetValue(rs, "CAD_LABEL_TYPE")

'-------------------------------
' Load data from recordset when form displayed first time
'-------------------------------
    if sLabelRecordErr = "" then
      fldCAD_LABEL_OMSCHRIJVING = GetValue(rs, "CAD_LABEL_OMSCHRIJVING")
      fldCAD_LABEL_VIEW = GetValue(rs, "CAD_LABEL_VIEW")
      fldCAD_LABEL_SIZE = GetValue(rs, "CAD_LABEL_SIZE")
      fldFAC_FUNCTIE_KEY = GetValue(rs, "FAC_FUNCTIE_KEY")
    end if
    SetVar "LabelRecordInsert", ""
    Parse "LabelRecordEdit", False
'-------------------------------
' LabelRecord ShowEdit Event begin
' LabelRecord ShowEdit Event end
'-------------------------------
  else
    if sLabelRecordErr = "" then
      fldCAD_LABEL_SIZE= "800"
      fldLabel= "1"
    end if
    SetVar "LabelRecordEdit", ""
    Parse "LabelRecordInsert", False
'-------------------------------
' LabelRecord ShowInsert Event begin
' LabelRecord ShowInsert Event end
'-------------------------------
  end if
  Parse "LabelRecordCancel", false

'-------------------------------
' Set default values
'-------------------------------
  fldLabel= "1"
  if sLabelRecordErr = "" then
'-------------------------------
' LabelRecord Show Event begin
fldWaar = fldCAD_LABEL_TYPE AND 27 ' &B11011
If fldWaar = 0 Then
    fldWaar = 1 ' Default binnen
End If
fldScenario = fldCAD_LABEL_TYPE AND 4' &B100

fldCAD_LABEL_SIZE = -1 * CInt(fldCAD_LABEL_SIZE)
If fldCAD_LABEL_SIZE < 0 Then
  fldCAD_LABEL_SIZE = -1 * fldCAD_LABEL_SIZE
  fldLabel = 0
Else
  fldLabel = 1
End If
' LabelRecord Show Event end
'-------------------------------
  end if

'-------------------------------
' Show form field
'-------------------------------
      SetVar "CAD_LABEL_KEY", ToHTML(fldCAD_LABEL_KEY)
      SetVar "CAD_LABEL_OMSCHRIJVING", ToHTML(fldCAD_LABEL_OMSCHRIJVING)
      SetVar "CAD_LABEL_VIEW", ToHTML(fldCAD_LABEL_VIEW)
      SetVar "CAD_LABEL_SIZE", ToHTML(fldCAD_LABEL_SIZE)
  if (LCase(fldLabel) = LCase("1")) then
    SetVar "Label_CHECKED", "CHECKED"
  else
    SetVar "Label_CHECKED", ""
  end if

      SetVar "LabelRecordLBFAC_FUNCTIE_KEY", ""
      SetVar "Selected", ""
      SetVar "ID", ""
      SetVar "Value", sFAC_FUNCTIE_KEYDisplayValue
      Parse "LabelRecordLBFAC_FUNCTIE_KEY", True
      openrs rsFAC_FUNCTIE_KEY, "select FAC_FUNCTIE_KEY, FAC_FUNCTIE_OMSCHRIJVING from FAC_FUNCTIE order by 2"
      while not rsFAC_FUNCTIE_KEY.EOF
        SetVar "ID", GetValue(rsFAC_FUNCTIE_KEY, 0) : SetVar "Value", GetValue(rsFAC_FUNCTIE_KEY, 1)
        if cstr(GetValue(rsFAC_FUNCTIE_KEY, 0)) = cstr(fldFAC_FUNCTIE_KEY) then SetVar "Selected", "SELECTED" else SetVar "Selected", ""
        Parse "LabelRecordLBFAC_FUNCTIE_KEY", True
        rsFAC_FUNCTIE_KEY.MoveNext
      wend
      set rsFAC_FUNCTIE_KEY = nothing
    
      SetVar "CAD_LABEL_TYPE", ToHTML(fldCAD_LABEL_TYPE)
      SetVar "LabelRecordRLWaar", ""
    
      LOV = Split(""&FCLTLCL("1;Binnen (ruimte);9;Binnen (werkplek);17;Binnen (object);2;Buiten (terreinsector);18;Buiten (object)")&"", ";")
      if (ubound(LOV) mod 2) = 1 then
        for i = 0 to ubound(LOV) step 2
          SetVar "ID", LOV(i) : SetVar "Value", LOV(i+1)
          if cstr(LOV(i)) = cstr(fldWaar) then SetVar "Selected", "CHECKED" else SetVar "Selected", ""
          Parse "LabelRecordRLWaar", True
        next
      end if
    
      SetVar "LabelRecordRLScenario", ""
    
      LOV = Split(""&FCLTLCL("0;Actuele situatie;4;Scenario situatie")&"", ";")
      if (ubound(LOV) mod 2) = 1 then
        for i = 0 to ubound(LOV) step 2
          SetVar "ID", LOV(i) : SetVar "Value", LOV(i+1)
          if cstr(LOV(i)) = cstr(fldScenario) then SetVar "Selected", "CHECKED" else SetVar "Selected", ""
          Parse "LabelRecordRLScenario", True
        next
      end if
    
  Parse "FormLabelRecord", False

'-------------------------------
' LabelRecord Close Event begin
' LabelRecord Close Event end
'-------------------------------

Set rs = Nothing

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