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

'-------------------------------
' fac_usergraphrecord CustomIncludes begin
%>

<!-- #INCLUDE FILE="Common.asp" -->

<%
' fac_usergraphrecord CustomIncludes end
'-------------------------------

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


'===============================
' fac_usergraphrecord PageSecurity begin
' fac_usergraphrecord PageSecurity end
'===============================

'===============================
' fac_usergraphrecord Open Event begin
' fac_usergraphrecord Open Event end
'===============================

'===============================
' fac_usergraphrecord OpenAnyPage Event begin
' fac_usergraphrecord OpenAnyPage Event end
'===============================

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

' fac_usergraphrecord Show begin
'===============================
' Perform the form's action
'-------------------------------
' Initialize error variables
'-------------------------------
sUsergraphRecordErr = ""

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

' fac_usergraphrecord Show end

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

' fac_usergraphrecord Close Event begin
' fac_usergraphrecord Close Event end

cn.Close
Set cn = Nothing
UnloadTemplate
'===============================
'===============================
' Action of the Record Form
'-------------------------------
Sub UsergraphRecordAction(sAction)
'-------------------------------
' Initialize variables  
'-------------------------------
  Dim bExecSQL: bExecSQL = true
  Dim sActionFileName : sActionFileName = ""
  Dim sWhere : sWhere = "" 
  Dim bErr : bErr = False
  Dim pPKFAC_USRGRAPH_KEY : pPKFAC_USRGRAPH_KEY = ""
  Dim fldFAC_USRGRAPH_OMSCHRIJVING : fldFAC_USRGRAPH_OMSCHRIJVING = ""
  Dim fldFAC_USRGRAPH_VIEW_NAME : fldFAC_USRGRAPH_VIEW_NAME = ""
  Dim fldFAC_USRGRAPH_TYPE : fldFAC_USRGRAPH_TYPE = ""
  Dim fldFAC_FUNCTIE_KEY : fldFAC_FUNCTIE_KEY = ""
  Dim fldFAC_USRGRAPH_ORDERBY : fldFAC_USRGRAPH_ORDERBY = ""
  Dim fldFAC_USRGRAPH_MAXROWS : fldFAC_USRGRAPH_MAXROWS = ""
  Dim fldFAC_USRGRAPH_LIMIET0 : fldFAC_USRGRAPH_LIMIET0 = ""
  Dim fldFAC_USRGRAPH_LIMIET1 : fldFAC_USRGRAPH_LIMIET1 = ""
  Dim fldFAC_USRGRAPH_LIMIET2 : fldFAC_USRGRAPH_LIMIET2 = ""
  Dim fldFAC_USRGRAPH_LIMIET3 : fldFAC_USRGRAPH_LIMIET3 = ""
  Dim fldFAC_USRGRAPH_OPTIONS : fldFAC_USRGRAPH_OPTIONS = ""
'-------------------------------

'-------------------------------
' UsergraphRecord Action begin
'-------------------------------
  sActionFileName = "fac_usergraphgrid.asp"

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

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

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


'-------------------------------
' Load all form fields into variables
'-------------------------------
  fldFAC_USRGRAPH_OMSCHRIJVING = GetParam("FAC_USRGRAPH_OMSCHRIJVING")
  fldFAC_USRGRAPH_VIEW_NAME = GetParam("FAC_USRGRAPH_VIEW_NAME")
  fldFAC_USRGRAPH_TYPE = GetParam("FAC_USRGRAPH_TYPE")
  fldFAC_FUNCTIE_KEY = GetParam("FAC_FUNCTIE_KEY")
  fldFAC_USRGRAPH_ORDERBY = GetParam("FAC_USRGRAPH_ORDERBY")
  fldFAC_USRGRAPH_MAXROWS = GetParam("FAC_USRGRAPH_MAXROWS")
  fldFAC_USRGRAPH_LIMIET0 = GetParam("FAC_USRGRAPH_LIMIET0")
  fldFAC_USRGRAPH_LIMIET1 = GetParam("FAC_USRGRAPH_LIMIET1")
  fldFAC_USRGRAPH_LIMIET2 = GetParam("FAC_USRGRAPH_LIMIET2")
  fldFAC_USRGRAPH_LIMIET3 = GetParam("FAC_USRGRAPH_LIMIET3")
  fldFAC_USRGRAPH_OPTIONS = GetParam("FAC_USRGRAPH_OPTIONS")

'-------------------------------
' Validate fields
'-------------------------------
  if sAction = "insert" or sAction = "update" then
    if IsEmpty(fldFAC_USRGRAPH_VIEW_NAME) then
      sUsergraphRecordErr = sUsergraphRecordErr & "De waarde in veld Viewname is verplicht.<br>"
    end if
    if not isNumeric(fldFAC_USRGRAPH_TYPE) then
      sUsergraphRecordErr = sUsergraphRecordErr & "De waarde in veld Soort grafiek is niet correct.<br>"
    end if
    if not isNumeric(fldFAC_FUNCTIE_KEY) then
      sUsergraphRecordErr = sUsergraphRecordErr & "De waarde in veld Autorisatie als is niet correct.<br>"
    end if
    if not isNumeric(fldFAC_USRGRAPH_MAXROWS) then
      sUsergraphRecordErr = sUsergraphRecordErr & "De waarde in veld Max. aantal regels is niet correct.<br>"
    end if
    if not isNumeric(fldFAC_USRGRAPH_LIMIET0) then
      sUsergraphRecordErr = sUsergraphRecordErr & "De waarde in veld Rood vanaf is niet correct.<br>"
    end if
    if not isNumeric(fldFAC_USRGRAPH_LIMIET1) then
      sUsergraphRecordErr = sUsergraphRecordErr & "De waarde in veld Oranje vanaf is niet correct.<br>"
    end if
    if not isNumeric(fldFAC_USRGRAPH_LIMIET2) then
      sUsergraphRecordErr = sUsergraphRecordErr & "De waarde in veld Groen vanaf is niet correct.<br>"
    end if
    if not isNumeric(fldFAC_USRGRAPH_LIMIET3) then
      sUsergraphRecordErr = sUsergraphRecordErr & "De waarde in veld Groen tot is niet correct.<br>"
    end if
'-------------------------------
' UsergraphRecord Check Event begin
' UsergraphRecord Check Event end
'-------------------------------
    If len(sUsergraphRecordErr) > 0 then
      exit sub
    end if
  end if
'-------------------------------


'-------------------------------
' Create SQL statement
'-------------------------------
  select case sAction
    case "insert"
'-------------------------------
' UsergraphRecord Insert Event begin
' UsergraphRecord Insert Event end
'-------------------------------
      sSQL = "insert into FAC_USRGRAPH (" & _
          "FAC_USRGRAPH_OMSCHRIJVING," & _
          "FAC_USRGRAPH_VIEW_NAME," & _
          "FAC_USRGRAPH_TYPE," & _
          "FAC_FUNCTIE_KEY," & _
          "FAC_USRGRAPH_ORDERBY," & _
          "FAC_USRGRAPH_MAXROWS," & _
          "FAC_USRGRAPH_LIMIET0," & _
          "FAC_USRGRAPH_LIMIET1," & _
          "FAC_USRGRAPH_LIMIET2," & _
          "FAC_USRGRAPH_LIMIET3," & _
          "FAC_USRGRAPH_OPTIONS)" & _
          " values (" & _
          ToSQL(fldFAC_USRGRAPH_OMSCHRIJVING, "Text") & "," & _
          ToSQL(fldFAC_USRGRAPH_VIEW_NAME, "Text") & "," & _
          ToSQL(fldFAC_USRGRAPH_TYPE, "Number") & "," & _
          ToSQL(fldFAC_FUNCTIE_KEY, "Number") & "," & _
          ToSQL(fldFAC_USRGRAPH_ORDERBY, "Text") & "," & _
          ToSQL(fldFAC_USRGRAPH_MAXROWS, "Number") & "," & _
          ToSQL(fldFAC_USRGRAPH_LIMIET0, "Number") & "," & _
          ToSQL(fldFAC_USRGRAPH_LIMIET1, "Number") & "," & _
          ToSQL(fldFAC_USRGRAPH_LIMIET2, "Number") & "," & _
          ToSQL(fldFAC_USRGRAPH_LIMIET3, "Number") & "," & _
          ToSQL(fldFAC_USRGRAPH_OPTIONS, "Text") & _
          ")"
    case "update"
'-------------------------------
' UsergraphRecord Update Event begin
' UsergraphRecord Update Event end
'-------------------------------
      sSQL = "update FAC_USRGRAPH set " & _
        "FAC_USRGRAPH_OMSCHRIJVING=" & ToSQL(fldFAC_USRGRAPH_OMSCHRIJVING, "Text") & _
        ",FAC_USRGRAPH_VIEW_NAME=" & ToSQL(fldFAC_USRGRAPH_VIEW_NAME, "Text") & _
        ",FAC_USRGRAPH_TYPE=" & ToSQL(fldFAC_USRGRAPH_TYPE, "Number") & _
        ",FAC_FUNCTIE_KEY=" & ToSQL(fldFAC_FUNCTIE_KEY, "Number") & _
        ",FAC_USRGRAPH_ORDERBY=" & ToSQL(fldFAC_USRGRAPH_ORDERBY, "Text") & _
        ",FAC_USRGRAPH_MAXROWS=" & ToSQL(fldFAC_USRGRAPH_MAXROWS, "Number") & _
        ",FAC_USRGRAPH_LIMIET0=" & ToSQL(fldFAC_USRGRAPH_LIMIET0, "Number") & _
        ",FAC_USRGRAPH_LIMIET1=" & ToSQL(fldFAC_USRGRAPH_LIMIET1, "Number") & _
        ",FAC_USRGRAPH_LIMIET2=" & ToSQL(fldFAC_USRGRAPH_LIMIET2, "Number") & _
        ",FAC_USRGRAPH_LIMIET3=" & ToSQL(fldFAC_USRGRAPH_LIMIET3, "Number") & _
        ",FAC_USRGRAPH_OPTIONS=" & ToSQL(fldFAC_USRGRAPH_OPTIONS, "Text")
      sSQL = sSQL & " where " & sWhere
    case "delete"
'-------------------------------
' UsergraphRecord Delete Event begin
' UsergraphRecord Delete Event end
'-------------------------------
      sSQL = "delete from FAC_USRGRAPH where " & sWhere
  end select
'-------------------------------
'-------------------------------
' UsergraphRecord BeforeExecute Event begin
' UsergraphRecord BeforeExecute Event end
'-------------------------------

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

'===============================
' Display Record Form
'-------------------------------
Sub UsergraphRecord_Show()
'-------------------------------
' UsergraphRecord Show begin
'-------------------------------
  Dim sWhere : sWhere = ""
  Dim sFormTitle: sFormTitle = "Details grafiek"
  Dim bPK : bPK = True
  Dim sFAC_FUNCTIE_KEYDisplayValue: sFAC_FUNCTIE_KEYDisplayValue = ""

'-------------------------------
' Load primary key and form parameters
'-------------------------------
  if sUsergraphRecordErr = "" then
    pFAC_USRGRAPH_KEY = GetParam("FAC_USRGRAPH_KEY")
    SetVar "UsergraphRecordError", ""
  else
    fldFAC_USRGRAPH_OMSCHRIJVING = GetParam("FAC_USRGRAPH_OMSCHRIJVING")
    fldFAC_USRGRAPH_VIEW_NAME = GetParam("FAC_USRGRAPH_VIEW_NAME")
    fldFAC_USRGRAPH_TYPE = GetParam("FAC_USRGRAPH_TYPE")
    fldFAC_FUNCTIE_KEY = GetParam("FAC_FUNCTIE_KEY")
    fldFAC_USRGRAPH_ORDERBY = GetParam("FAC_USRGRAPH_ORDERBY")
    fldFAC_USRGRAPH_MAXROWS = GetParam("FAC_USRGRAPH_MAXROWS")
    fldFAC_USRGRAPH_LIMIET0 = GetParam("FAC_USRGRAPH_LIMIET0")
    fldFAC_USRGRAPH_LIMIET1 = GetParam("FAC_USRGRAPH_LIMIET1")
    fldFAC_USRGRAPH_LIMIET2 = GetParam("FAC_USRGRAPH_LIMIET2")
    fldFAC_USRGRAPH_LIMIET3 = GetParam("FAC_USRGRAPH_LIMIET3")
    fldFAC_USRGRAPH_OPTIONS = GetParam("FAC_USRGRAPH_OPTIONS")
    pFAC_USRGRAPH_KEY = GetParam("PK_FAC_USRGRAPH_KEY")
    SetVar "sUsergraphRecordErr", sUsergraphRecordErr
    SetVar "FormTitle", sFormTitle
    Parse "UsergraphRecordError", False
  end if
'-------------------------------

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

  fldField5 = GetParam("Field5")
'-------------------------------

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

  if IsEmpty(pFAC_USRGRAPH_KEY) then bPK = False
  
  sWhere = sWhere & "FAC_USRGRAPH_KEY=" & ToSQL(pFAC_USRGRAPH_KEY, "Number")
  SetVar "PK_FAC_USRGRAPH_KEY", pFAC_USRGRAPH_KEY
'-------------------------------
'-------------------------------
' UsergraphRecord Open Event begin
' UsergraphRecord Open Event end
'-------------------------------

  SetVar "FormTitle", sFormTitle

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

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

'-------------------------------
' Load data from recordset when form displayed first time
'-------------------------------
    if sUsergraphRecordErr = "" then
      fldFAC_USRGRAPH_OMSCHRIJVING = GetValue(rs, "FAC_USRGRAPH_OMSCHRIJVING")
      fldFAC_USRGRAPH_VIEW_NAME = GetValue(rs, "FAC_USRGRAPH_VIEW_NAME")
      fldFAC_USRGRAPH_TYPE = GetValue(rs, "FAC_USRGRAPH_TYPE")
      fldFAC_FUNCTIE_KEY = GetValue(rs, "FAC_FUNCTIE_KEY")
      fldFAC_USRGRAPH_ORDERBY = GetValue(rs, "FAC_USRGRAPH_ORDERBY")
      fldFAC_USRGRAPH_MAXROWS = GetValue(rs, "FAC_USRGRAPH_MAXROWS")
      fldFAC_USRGRAPH_LIMIET0 = GetValue(rs, "FAC_USRGRAPH_LIMIET0")
      fldFAC_USRGRAPH_LIMIET1 = GetValue(rs, "FAC_USRGRAPH_LIMIET1")
      fldFAC_USRGRAPH_LIMIET2 = GetValue(rs, "FAC_USRGRAPH_LIMIET2")
      fldFAC_USRGRAPH_LIMIET3 = GetValue(rs, "FAC_USRGRAPH_LIMIET3")
      fldFAC_USRGRAPH_OPTIONS = GetValue(rs, "FAC_USRGRAPH_OPTIONS")
    end if
    SetVar "UsergraphRecordInsert", ""
    Parse "UsergraphRecordEdit", False
'-------------------------------
' UsergraphRecord ShowEdit Event begin
' UsergraphRecord ShowEdit Event end
'-------------------------------
  else
    if sUsergraphRecordErr = "" then
      fldField5= "<b>"&FCLTLCL("Grenzen bij dashbord")&"</b>"
    end if
    SetVar "UsergraphRecordEdit", ""
    Parse "UsergraphRecordInsert", False
'-------------------------------
' UsergraphRecord ShowInsert Event begin
' UsergraphRecord ShowInsert Event end
'-------------------------------
  end if
  Parse "UsergraphRecordCancel", false

'-------------------------------
' Set default values
'-------------------------------
  fldField5= "<b>"&FCLTLCL("Grenzen bij dashbord")&"</b>"
'-------------------------------
' UsergraphRecord Show Event begin
' UsergraphRecord Show Event end
'-------------------------------

'-------------------------------
' Show form field
'-------------------------------
      SetVar "FAC_USRGRAPH_KEY", ToHTML(fldFAC_USRGRAPH_KEY)
      SetVar "FAC_USRGRAPH_OMSCHRIJVING", ToHTML(fldFAC_USRGRAPH_OMSCHRIJVING)
      SetVar "FAC_USRGRAPH_VIEW_NAME", ToHTML(fldFAC_USRGRAPH_VIEW_NAME)
      SetVar "UsergraphRecordLBFAC_USRGRAPH_TYPE", ""
      LOV = Split(""&FCLTLCL("1;Staafgrafiek;2;Dashboard;3;Taartgrafiek;4;Lijngrafiek")&"", ";")
      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(fldFAC_USRGRAPH_TYPE) then SetVar "Selected", "SELECTED" else SetVar "Selected", ""
          Parse "UsergraphRecordLBFAC_USRGRAPH_TYPE", True
        next
      end if
    
      SetVar "UsergraphRecordLBFAC_FUNCTIE_KEY", ""
      SetVar "Selected", ""
      SetVar "ID", ""
      SetVar "Value", sFAC_FUNCTIE_KEYDisplayValue
      Parse "UsergraphRecordLBFAC_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 "UsergraphRecordLBFAC_FUNCTIE_KEY", True
        rsFAC_FUNCTIE_KEY.MoveNext
      wend
      set rsFAC_FUNCTIE_KEY = nothing
    
      SetVar "FAC_USRGRAPH_ORDERBY", ToHTML(fldFAC_USRGRAPH_ORDERBY)
      SetVar "FAC_USRGRAPH_MAXROWS", ToHTML(fldFAC_USRGRAPH_MAXROWS)
      SetVar "Field5", fldField5
      SetVar "FAC_USRGRAPH_LIMIET0", ToHTML(fldFAC_USRGRAPH_LIMIET0)
      SetVar "FAC_USRGRAPH_LIMIET1", ToHTML(fldFAC_USRGRAPH_LIMIET1)
      SetVar "FAC_USRGRAPH_LIMIET2", ToHTML(fldFAC_USRGRAPH_LIMIET2)
      SetVar "FAC_USRGRAPH_LIMIET3", ToHTML(fldFAC_USRGRAPH_LIMIET3)
      SetVar "FAC_USRGRAPH_OPTIONS", ToHTML(fldFAC_USRGRAPH_OPTIONS)
  Parse "FormUsergraphRecord", False

'-------------------------------
' UsergraphRecord Close Event begin
' UsergraphRecord Close Event end
'-------------------------------

Set rs = Nothing

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