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

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


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


'===============================
' mld_workflowrecord3 PageSecurity begin
' mld_workflowrecord3 PageSecurity end
'===============================

'===============================
' mld_workflowrecord3 Open Event begin
' mld_workflowrecord3 Open Event end
'===============================

'===============================
' mld_workflowrecord3 OpenAnyPage Event begin
' mld_workflowrecord3 OpenAnyPage Event end
'===============================

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

' mld_workflowrecord3 Show begin
'===============================
' Perform the form's action
'-------------------------------
' Initialize error variables
'-------------------------------
sWorkflowRuleRecordErr = ""

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

' mld_workflowrecord3 Show end

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

' mld_workflowrecord3 Close Event begin
' mld_workflowrecord3 Close Event end

cn.Close
Set cn = Nothing
UnloadTemplate
'===============================
'===============================
' Action of the Record Form
'-------------------------------
Sub WorkflowRuleRecordAction(sAction)
'-------------------------------
' Initialize variables  
'-------------------------------
  Dim bExecSQL: bExecSQL = true
  Dim sActionFileName : sActionFileName = ""
  Dim sParams : sParams = "?"
  Dim sWhere : sWhere = "" 
  Dim bErr : bErr = False
  Dim pPKMLD_WORKFLOWRULE_KEY : pPKMLD_WORKFLOWRULE_KEY = ""
  Dim fldMLD_WORKFLOWRULE_OMSCHRIJVING : fldMLD_WORKFLOWRULE_OMSCHRIJVING = ""
  Dim fldMLD_WORKFLOWSTEP_NEXT_KEY : fldMLD_WORKFLOWSTEP_NEXT_KEY = ""
  Dim fldMLD_WORKFLOWRULE_CONDITION : fldMLD_WORKFLOWRULE_CONDITION = ""
  Dim fldMLD_WORKFLOWSTEP_START_KEY : fldMLD_WORKFLOWSTEP_START_KEY = ""
'-------------------------------

'-------------------------------
' WorkflowRuleRecord Action begin
'-------------------------------
  sActionFileName = "mld_workflowrecord1.asp"
  sParams = sParams & "F_MLD_WORKFLOWSTEP_KEY=" & ToURL(GetParam("Trn_F_MLD_WORKFLOWSTEP_KEY")) & "&"
  sParams = sParams & "MLD_WORKFLOWSTEP_KEY=" & ToURL(GetParam("Trn_MLD_WORKFLOWSTEP_KEY"))

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

'-------------------------------
' WorkflowRuleRecord BeforeCancel Event begin
sParams = "?F_MLD_WORKFLOWSTEP_KEY=" & ToURL(GetParam("Trn_F_MLD_WORKFLOWSTEP_KEY"))&_
          "&MLD_WORKFLOWSTEP_KEY="&ToURL(getParam("trn_MLD_WORKFLOWSTEP_KEY"))
' WorkflowRuleRecord BeforeCancel Event end
'-------------------------------
    cn.Close
    Set cn = Nothing
    response.redirect sActionFileName & sParams
  end if
'-------------------------------

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


'-------------------------------
' Load all form fields into variables
'-------------------------------
  fldMLD_WORKFLOWRULE_OMSCHRIJVING = GetParam("MLD_WORKFLOWRULE_OMSCHRIJVING")
  fldMLD_WORKFLOWSTEP_NEXT_KEY = GetParam("MLD_WORKFLOWSTEP_NEXT_KEY")
  fldMLD_WORKFLOWRULE_CONDITION = GetParam("MLD_WORKFLOWRULE_CONDITION")
  fldMLD_WORKFLOWSTEP_START_KEY = GetParam("MLD_WORKFLOWSTEP_START_KEY")

'-------------------------------
' Validate fields
'-------------------------------
  if sAction = "insert" or sAction = "update" then
    if not isNumeric(fldMLD_WORKFLOWSTEP_NEXT_KEY) then
      sWorkflowRuleRecordErr = sWorkflowRuleRecordErr & "The value in field Volgende stap is incorrect.<br>"
    end if
'-------------------------------
' WorkflowRuleRecord Check Event begin
' WorkflowRuleRecord Check Event end
'-------------------------------
    If len(sWorkflowRuleRecordErr) > 0 then
      exit sub
    end if
  end if
'-------------------------------


'-------------------------------
' Create SQL statement
'-------------------------------
  select case sAction
    case "insert"
'-------------------------------
' WorkflowRuleRecord Insert Event begin
' WorkflowRuleRecord Insert Event end
'-------------------------------
      sSQL = "insert into MLD_WORKFLOWRULE (" & _
          "MLD_WORKFLOWRULE_OMSCHRIJVING," & _
          "MLD_WORKFLOWSTEP_NEXT_KEY," & _
          "MLD_WORKFLOWRULE_CONDITION)" & _
          " values (" & _
          ToSQL(fldMLD_WORKFLOWRULE_OMSCHRIJVING, "Text") & "," & _
          ToSQL(fldMLD_WORKFLOWSTEP_NEXT_KEY, "Number") & "," & _
          ToSQL(fldMLD_WORKFLOWRULE_CONDITION, "Text") & _
          ")"
    case "update"
'-------------------------------
' WorkflowRuleRecord Update Event begin
' WorkflowRuleRecord Update Event end
'-------------------------------
      sSQL = "update MLD_WORKFLOWRULE set " & _
        "MLD_WORKFLOWRULE_OMSCHRIJVING=" & ToSQL(fldMLD_WORKFLOWRULE_OMSCHRIJVING, "Text") & _
        ",MLD_WORKFLOWSTEP_NEXT_KEY=" & ToSQL(fldMLD_WORKFLOWSTEP_NEXT_KEY, "Number") & _
        ",MLD_WORKFLOWRULE_CONDITION=" & ToSQL(fldMLD_WORKFLOWRULE_CONDITION, "Text")
      sSQL = sSQL & " where " & sWhere
    case "delete"
'-------------------------------
' WorkflowRuleRecord Delete Event begin
'Eerst de rule verwijderen, dan (eventueel) de stap

sSQL = "delete from MLD_WORKFLOWRULE where " & sWhere
if len(sWorkflowRuleRecordErr) > 0 then Exit Sub
on error resume next
if bExecSQL then
  cn.execute sSQL
end if
sWorkflowRuleRecordErr = ProcessError
on error goto 0
if len(sWorkflowRuleRecordErr) > 0 then Exit Sub

sSql = "select mld_workflowrule_key "&_
       "from mld_workflowrule "&_
       "where mld_workflowstep_next_key = " & ToSQL(fldMLD_WORKFLOWSTEP_NEXT_KEY, "Number")
openrs rsKeys,sSql
if rsKeys.EOF then
  'Laatste regel naar de stap verwijderd; verwijder de stap ook
  sSql = "delete from mld_workflowstep where mld_workflowstep_key = " & ToSQL(fldMLD_WORKFLOWSTEP_NEXT_KEY, "Number")
else
  sSql = "select 0 "&from_dual
end if
' WorkflowRuleRecord Delete Event end
'-------------------------------
      if sSQL = "" then
      sSQL = "delete from MLD_WORKFLOWRULE where " & sWhere
      end if
  end select
'-------------------------------
'-------------------------------
' WorkflowRuleRecord BeforeExecute Event begin
sParams = "?F_MLD_WORKFLOWSTEP_KEY=" & ToURL(GetParam("Trn_F_MLD_WORKFLOWSTEP_KEY"))&_
          "&MLD_WORKFLOWSTEP_KEY="&ToURL(getParam("trn_MLD_WORKFLOWSTEP_KEY"))
' WorkflowRuleRecord BeforeExecute Event end
'-------------------------------

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

'===============================
' Display Record Form
'-------------------------------
Sub WorkflowRuleRecord_Show()
'-------------------------------
' WorkflowRuleRecord Show begin
'-------------------------------
  Dim sWhere : sWhere = ""
  Dim sFormTitle: sFormTitle = "Details workflowstap"
  Dim bPK : bPK = True

'-------------------------------
' Load primary key and form parameters
'-------------------------------
  if sWorkflowRuleRecordErr = "" then
    SetVar "Trn_F_MLD_WORKFLOWSTEP_KEY", GetParam("F_MLD_WORKFLOWSTEP_KEY")
    SetVar "Trn_MLD_WORKFLOWSTEP_KEY", GetParam("MLD_WORKFLOWSTEP_KEY")
    pMLD_WORKFLOWRULE_KEY = GetParam("MLD_WORKFLOWRULE_KEY")
    SetVar "WorkflowRuleRecordError", ""
  else
    fldMLD_WORKFLOWRULE_OMSCHRIJVING = GetParam("MLD_WORKFLOWRULE_OMSCHRIJVING")
    fldMLD_WORKFLOWSTEP_NEXT_KEY = GetParam("MLD_WORKFLOWSTEP_NEXT_KEY")
    fldMLD_WORKFLOWRULE_CONDITION = GetParam("MLD_WORKFLOWRULE_CONDITION")
    SetVar "Trn_F_MLD_WORKFLOWSTEP_KEY", GetParam("Trn_F_MLD_WORKFLOWSTEP_KEY")
    SetVar "Trn_MLD_WORKFLOWSTEP_KEY", GetParam("Trn_MLD_WORKFLOWSTEP_KEY")
    pMLD_WORKFLOWRULE_KEY = GetParam("PK_MLD_WORKFLOWRULE_KEY")
    SetVar "sWorkflowRuleRecordErr", sWorkflowRuleRecordErr
    SetVar "FormTitle", sFormTitle
    Parse "WorkflowRuleRecordError", False
  end if
'-------------------------------

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

  fldExprBuilder = GetParam("ExprBuilder")
  fldMLD_WORKFLOWSTEP_START_KEY = GetParam("MLD_WORKFLOWSTEP_START_KEY")
'-------------------------------

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

  if IsEmpty(pMLD_WORKFLOWRULE_KEY) then bPK = False
  
  sWhere = sWhere & "MLD_WORKFLOWRULE_KEY=" & ToSQL(pMLD_WORKFLOWRULE_KEY, "Number")
  SetVar "PK_MLD_WORKFLOWRULE_KEY", pMLD_WORKFLOWRULE_KEY
'-------------------------------
'-------------------------------
' WorkflowRuleRecord Open Event begin
if getParam("F_MLD_WORKFLOWSTEP_KEY") <> "" then
  fldMLD_WORKFLOWSTEP_START_KEY = getParam("F_MLD_WORKFLOWSTEP_KEY")
else
  fldMLD_WORKFLOWSTEP_START_KEY = "-1"
end if
' WorkflowRuleRecord Open Event end
'-------------------------------

  SetVar "FormTitle", sFormTitle

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

'-------------------------------
' Load all fields into variables from recordset or input parameters
'-------------------------------
  if bIsUpdateMode then
    fldMLD_WORKFLOWRULE_KEY = GetValue(rs, "MLD_WORKFLOWRULE_KEY")
    fldMLD_WORKFLOWRULE_RESULT = GetValue(rs, "MLD_WORKFLOWRULE_RESULT")
    fldMLD_WORKFLOWSTEP_KEY = GetValue(rs, "MLD_WORKFLOWSTEP_KEY")

'-------------------------------
' Load data from recordset when form displayed first time
'-------------------------------
    if sWorkflowRuleRecordErr = "" then
      fldMLD_WORKFLOWRULE_OMSCHRIJVING = GetValue(rs, "MLD_WORKFLOWRULE_OMSCHRIJVING")
      fldMLD_WORKFLOWSTEP_NEXT_KEY = GetValue(rs, "MLD_WORKFLOWSTEP_NEXT_KEY")
      fldMLD_WORKFLOWRULE_CONDITION = GetValue(rs, "MLD_WORKFLOWRULE_CONDITION")
    end if
    SetVar "WorkflowRuleRecordInsert", ""
    Parse "WorkflowRuleRecordEdit", False
'-------------------------------
' WorkflowRuleRecord ShowEdit Event begin
' WorkflowRuleRecord ShowEdit Event end
'-------------------------------
  else
    if sWorkflowRuleRecordErr = "" then
    end if
    SetVar "WorkflowRuleRecordEdit", ""
    Parse "WorkflowRuleRecordInsert", False
'-------------------------------
' WorkflowRuleRecord ShowInsert Event begin
' WorkflowRuleRecord ShowInsert Event end
'-------------------------------
  end if
  Parse "WorkflowRuleRecordCancel", false
  if sWorkflowRuleRecordErr = "" then
'-------------------------------
' WorkflowRuleRecord Show Event begin
end if
if true then

sqlNextKeys = "select w.mld_workflowstep_key, "&_
              "w.mld_workflowstep_omschrijving "&str_concat&_
              " '( ' "&str_concat&" d.ins_discipline_omschrijving "&str_concat&" ' / ' "&str_concat&" s.mld_stdmelding_omschrijving "&str_concat&" ')' "&_
              "from mld_workflowstep w, mld_discipline d, mld_stdmelding s "&_
              "where s.mld_ins_discipline_key = d.ins_discipline_key "&_
              "  and w.mld_stdmelding_key = s.mld_stdmelding_key "&_
              "  and w.mld_workflowstep_start_key = " & ToSQL(fldMLD_WORKFLOWSTEP_START_KEY, "Number")


fldExprBuilder= "<input type=button onClick=""Uitdrukking("&GetParam("MLD_WORKFLOWSTEP_KEY")&");return false;"" NAME='pick' ID='pick' value=""Uitdrukking""></input>"

fldMLD_WORKFLOWSTEP_KEY = getWorkflowStepOmschr(fldMLD_WORKFLOWSTEP_KEY)

if fldMLD_WORKFLOWRULE_RESULT = "1" then
  fldMLD_WORKFLOWRULE_RESULT = "Afgemeld"
elseif fldMLD_WORKFLOWRULE_RESULT = "0" then
  fldMLD_WORKFLOWRULE_RESULT = "Afgewezen"
end if
' WorkflowRuleRecord Show Event end
'-------------------------------
  end if

'-------------------------------
' Show form field
'-------------------------------
      SetVar "MLD_WORKFLOWRULE_KEY", ToHTML(fldMLD_WORKFLOWRULE_KEY)
      SetVar "MLD_WORKFLOWSTEP_KEY", ToHTML(fldMLD_WORKFLOWSTEP_KEY)
      SetVar "MLD_WORKFLOWRULE_RESULT", ToHTML(fldMLD_WORKFLOWRULE_RESULT)
      SetVar "MLD_WORKFLOWRULE_OMSCHRIJVING", ToHTML(fldMLD_WORKFLOWRULE_OMSCHRIJVING)
      SetVar "WorkflowRuleRecordLBMLD_WORKFLOWSTEP_NEXT_KEY", ""
      openrs rsMLD_WORKFLOWSTEP_NEXT_KEY, ""&sqlNextKeys&""
      while not rsMLD_WORKFLOWSTEP_NEXT_KEY.EOF
        SetVar "ID", GetValue(rsMLD_WORKFLOWSTEP_NEXT_KEY, 0) : SetVar "Value", GetValue(rsMLD_WORKFLOWSTEP_NEXT_KEY, 1)
        if cstr(GetValue(rsMLD_WORKFLOWSTEP_NEXT_KEY, 0)) = cstr(fldMLD_WORKFLOWSTEP_NEXT_KEY) then SetVar "Selected", "SELECTED" else SetVar "Selected", ""
        Parse "WorkflowRuleRecordLBMLD_WORKFLOWSTEP_NEXT_KEY", True
        rsMLD_WORKFLOWSTEP_NEXT_KEY.MoveNext
      wend
      set rsMLD_WORKFLOWSTEP_NEXT_KEY = nothing
    
      SetVar "MLD_WORKFLOWRULE_CONDITION", ToHTML(fldMLD_WORKFLOWRULE_CONDITION)
      SetVar "ExprBuilder", fldExprBuilder
      SetVar "MLD_WORKFLOWSTEP_START_KEY", ToHTML(fldMLD_WORKFLOWSTEP_START_KEY)
  Parse "FormWorkflowRuleRecord", False

'-------------------------------
' WorkflowRuleRecord Close Event begin
' WorkflowRuleRecord Close Event end
'-------------------------------

Set rs = Nothing

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