home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / ProgramD2.iso / Visual Database / Visual dBase v5.5 / MUSIC1.PAK / FILTER.WFM < prev    next >
Encoding:
Text File  |  1995-07-18  |  29.0 KB  |  943 lines

  1. *******************************************************************************
  2. *  PROGRAM:      Filter.wfm
  3. *
  4. *  WRITTEN BY:   Borland Samples Group
  5. *
  6. *  DATE:         1/94
  7. *
  8. *  UPDATED:      6/95
  9. *
  10. *  REVISION:     $Revision:   1.31  $
  11. *
  12. *  VERSION:      Visual dBASE
  13. *
  14. *  DESCRIPTION:  This form allows setting a filter on the items currently
  15. *                viewed.  It allows you to create a combination filter based
  16. *                on the artist, title, price, release date, and media type
  17. *                of the available items from the Musical Methods store.
  18. *
  19. *  PARAMETERS:   None
  20. *
  21. *  CALLS:        Music.qbe     (view of tables)
  22. *                Music.cc      (for custom pushbuttons)
  23. *
  24. *
  25. *  USAGE:        DO Filter.wfm  && or
  26. *
  27. *                local f
  28. *                set procedure to Filter.wfm additive
  29. *                f = new FilterForm()
  30. *                f.ReadModal
  31. *******************************************************************************
  32. #include <Messdlg.h>
  33. #include "Music.h"
  34. #define EMPTY_STRING          " "
  35. #define EMPTY_OP              "       "
  36. #define EMPTY_LOGIC           "     "
  37. #define STRING_DELIMITERS     ['"]
  38. #define ENTRY_WIDTH           30
  39. #define AND_STRING            " and "
  40. #define OR_STRING             " or  "
  41. #define LOGIC_OP_LEN          7                     && -Max length of logical op
  42. #define DISPLAY_LOGIC_OP_LEN  5                     && -Max length of logical op
  43. #define RETURN_CHAR           chr(13)               &&  in a sentence to be
  44.                                                     &&  displayed
  45. create session                  && If form run on its own, it should close all open tables
  46. set century on
  47. set talk off
  48. set ldcheck off
  49.  
  50. ** END HEADER -- do not remove this line*
  51. * Generated on 05/12/94
  52. *
  53. parameter bModal
  54. local f
  55. f = new FILTERFORM()
  56. if (bModal)
  57.    f.mdi = .F. && ensure not MDI
  58.    f.ReadModal()
  59. else
  60.    f.Open()
  61. endif
  62. CLASS FILTERFORM OF FORM
  63.    Set Procedure To Music.cc Additive
  64.    this.OnOpen = CLASS::ONOPEN
  65.    this.OnSelection = CLASS::ONSELECTION
  66.    this.OnClose = CLASS::ONCLOSE
  67.    this.MousePointer =          1
  68.    this.ColorNormal = "W"
  69.    this.Text = "Set Filter"
  70.    this.Width =         96.64
  71.    this.Top =          2.02
  72.    this.Left =          2.70
  73.    this.Height =         16.3
  74.    this.Minimize = .F.
  75.    this.Maximize = .F.
  76.    this.HelpFile = ""
  77.    this.HelpId = ""
  78.  
  79.  
  80.    DEFINE RECTANGLE MEDIATYPERECT OF THIS;
  81.        PROPERTY;
  82.          ColorNormal "N/W",;
  83.          Text "",;
  84.          Height          2.02,;
  85.          Width         94.61,;
  86.          Top         10.61,;
  87.          Left          0.67,;
  88.          Border .T.
  89.  
  90.    DEFINE RECTANGLE RELEASEDATERECT OF THIS;
  91.        PROPERTY;
  92.          ColorNormal "N/W",;
  93.          Text "",;
  94.          Height          2.02,;
  95.          Width         94.61,;
  96.          Top          8.58,;
  97.          Left          0.67,;
  98.          Border .T.
  99.  
  100.    DEFINE RECTANGLE SALESPRICERECT OF THIS;
  101.        PROPERTY;
  102.          ColorNormal "N/W",;
  103.          Text "",;
  104.          Height          2.02,;
  105.          Width         94.61,;
  106.          Top          6.57,;
  107.          Left          0.67,;
  108.          Border .T.
  109.  
  110.    DEFINE RECTANGLE RANKRECT OF THIS;
  111.        PROPERTY;
  112.          ColorNormal "N/W",;
  113.          Text "",;
  114.          Height          2.02,;
  115.          Width         94.61,;
  116.          Top          4.55,;
  117.          Left          0.67,;
  118.          Border .T.
  119.  
  120.    DEFINE RECTANGLE TITLERECT OF THIS;
  121.        PROPERTY;
  122.          ColorNormal "N/W",;
  123.          Text "",;
  124.          Height          2.02,;
  125.          Width         94.61,;
  126.          Top          2.53,;
  127.          Left          0.67,;
  128.          Border .T.
  129.  
  130.    DEFINE RECTANGLE ARTISTRECT OF THIS;
  131.        PROPERTY;
  132.          ColorNormal "N/W",;
  133.          Text "",;
  134.          Height          2.02,;
  135.          Width         94.61,;
  136.          Top          0.50,;
  137.          Left          0.67,;
  138.          Border .T.
  139.  
  140.    DEFINE NORMALTEXT ARTISTTEXT OF THIS;
  141.        PROPERTY;
  142.          Alignment 5,;
  143.          Text "Artist",;
  144.          Width         16.22,;
  145.          Top          1.01,;
  146.          Left          1.35,;
  147.          Height          1.01,;
  148.          Border .F.
  149.  
  150.    DEFINE COMBOBOX ARTISTOPCOMBO OF THIS;
  151.       PROPERTY;
  152.         Tabstop .F.,;
  153.         Enabled     .F.,;
  154.         Width          8.11,;
  155.         Top          1.01,;
  156.         Left         18.92,;
  157.         Height          1.26,;
  158.         FontSize          7.00,;
  159.         Style          2
  160.  
  161.    DEFINE COMBOBOX ARTISTCOMBO OF THIS;
  162.        PROPERTY;
  163.          OnGotFocus CLASS::ONGOTFOCUSFIELD,;
  164.          OnLostFocus CLASS::ONLOSTFOCUSFIELD,;
  165.          Style 1,;
  166.          Enabled .T.,;
  167.          Width         40.55,;
  168.          Top          1.01,;
  169.          Left         31.08,;
  170.          Height          1.07,;
  171.          Value ""
  172.  
  173.    DEFINE COMBOBOX ARTISTLOGICCOMBO OF THIS;
  174.       PROPERTY     ;
  175.          Tabstop .F.,;
  176.          Enabled      .F.,;
  177.          Width          10.81,     ;
  178.          Top          1.01,     ;
  179.          Left         72.98,     ;
  180.          Height          1.26,     ;
  181.          Value "",     ;
  182.          Style          2
  183.  
  184.    DEFINE PUSHBUTTON CLEARARTISTBUTTON OF THIS;
  185.        PROPERTY;
  186.          Id 1,;
  187.          ColorNormal "N/W",;
  188.          OnClick CLASS::CLEARARTIST,;
  189.          Text "Clear",;
  190.          Tabstop      .F.,;
  191.          Width          6.76,;
  192.          Top          1.15,;
  193.          Left         86.53,;
  194.          Height          1.01
  195.  
  196.    DEFINE NORMALTEXT TITLETEXT OF THIS;
  197.        PROPERTY;
  198.          Alignment 5,;
  199.          Text "Title",;
  200.          Width         16.22,;
  201.          Top          3.03,;
  202.          Left          1.35,;
  203.          Height          1.21
  204.  
  205.    DEFINE COMBOBOX TITLEOPCOMBO OF THIS;
  206.       PROPERTY     ;
  207.          Tabstop .F.,;
  208.          Enabled     .F.,;
  209.          Width          8.11,     ;
  210.          Top          3.03,     ;
  211.          Left         18.92,     ;
  212.          Height          1.26,     ;
  213.          Value "",     ;
  214.          Style          2
  215.  
  216.    DEFINE COMBOBOX TITLECOMBO OF THIS;
  217.        PROPERTY;
  218.          OnGotFocus CLASS::ONGOTFOCUSFIELD,;
  219.          OnLostFocus CLASS::ONLOSTFOCUSFIELD,;
  220.          Style 1,;
  221.          Enabled .T.,;
  222.          Width         40.55,;
  223.          Top          3.03,;
  224.          Left         31.08,;
  225.          Height          1.07,;
  226.          Value ""
  227.  
  228.  
  229.  
  230.    DEFINE COMBOBOX TITLELOGICCOMBO OF THIS   ;
  231.       PROPERTY     ;
  232.          Tabstop .F.,;
  233.          Enabled      .F.,;
  234.          Width          10.81,     ;
  235.          Top          3.03,     ;
  236.          Left         72.98,     ;
  237.          Height          1.26,     ;
  238.          Value "",     ;
  239.          Style          2
  240.  
  241.  
  242.    DEFINE PUSHBUTTON CLEARTITLEBUTTON OF THIS;
  243.        PROPERTY;
  244.          Id 2,;
  245.          ColorNormal "N/W",;
  246.          OnClick CLASS::CLEARTITLE,;
  247.          Text "Clear",;
  248.          Tabstop      .F.,;
  249.          Width          6.76,;
  250.          Top          3.17,;
  251.          Left         86.53,;
  252.          Height          1.01
  253.  
  254.    DEFINE NORMALTEXT RANKTEXT OF THIS;
  255.        PROPERTY;
  256.          Alignment 5,;
  257.          Text "Rank",;
  258.          Width         16.22,;
  259.          Top          5.05,;
  260.          Left          1.35,;
  261.          Height          1.01
  262.  
  263.    DEFINE COMBOBOX RANKOPCOMBO OF THIS;
  264.       PROPERTY     ;
  265.          Tabstop .F.,;
  266.          Enabled     .F.,;
  267.          Width          8.11,     ;
  268.          Top          5.05,     ;
  269.          Left         18.92,     ;
  270.          Height          1.26,     ;
  271.          Value "",     ;
  272.          Style          2
  273.  
  274.    DEFINE SPINBOX RANKSPIN OF THIS;
  275.        PROPERTY;
  276.          OnGotFocus CLASS::ONGOTFOCUSFIELD,;
  277.          OnLostFocus CLASS::ONLOSTFOCUSFIELD,;
  278.          ColorNormal "r/w",;
  279.          Picture "9999",;
  280.          Function "J",;
  281.          Width         13.52,;
  282.          Top          5.05,;
  283.          Left         31.08,;
  284.          Height          1.01,;
  285.          Border .T.,;
  286.          Value          0,;
  287.          Rangemin          0,;
  288.          Rangemax       2500,;
  289.          ColorHighLight "r/w*"
  290.  
  291.  
  292.    DEFINE COMBOBOX RANKLOGICCOMBO OF THIS;
  293.       PROPERTY     ;
  294.          Tabstop .F.,;
  295.          Enabled      .F.,;
  296.          Width          10.81,     ;
  297.          Top          5.05,     ;
  298.          Left         72.98,     ;
  299.          Height          1.26,     ;
  300.          Value "",     ;
  301.          Style          2
  302.  
  303.    DEFINE PUSHBUTTON CLEARRANKBUTTON OF THIS;
  304.        PROPERTY;
  305.          Id 3,;
  306.          ColorNormal "N/W",;
  307.          OnClick CLASS::CLEARRANK,;
  308.          Text "Clear",;
  309.          Tabstop      .F.,;
  310.          Width          6.76,;
  311.          Top          5.20,;
  312.          Left         86.53,;
  313.          Height          1.01
  314.  
  315.    DEFINE NORMALTEXT SALESPRICETEXT OF THIS;
  316.        PROPERTY;
  317.          Alignment 5,;
  318.          Text "Sales Price",;
  319.          Width         16.22,;
  320.          Top          7.07,;
  321.          Left          1.35,;
  322.          Height          1.01
  323.  
  324.    DEFINE COMBOBOX SALESPRICEOPCOMBO OF THIS;
  325.       PROPERTY     ;
  326.          Tabstop .F.,;
  327.          Enabled     .F.,;
  328.          Width          8.11,     ;
  329.          Top          7.07,     ;
  330.          Left         18.92,     ;
  331.          Height          1.26,     ;
  332.          Value "",     ;
  333.          Style          2
  334.  
  335.    DEFINE SPINBOX SALESPRICESPIN OF THIS;
  336.        PROPERTY;
  337.          OnGotFocus CLASS::ONGOTFOCUSFIELD,;
  338.          OnLostFocus CLASS::ONLOSTFOCUSFIELD,;
  339.          ColorNormal "r/w",;
  340.          Width         13.52,;
  341.          Top          7.07,;
  342.          Left         31.08,;
  343.          Height          1.01,;
  344.          Border .T.,;
  345.          Value          0,;
  346.          Rangemin          1,;
  347.          Rangemax        100,;
  348.          ColorHighLight "r/w*",;
  349.          Picture "999.99",;
  350.          Function "$J"
  351.  
  352.    DEFINE COMBOBOX SALESPRICELOGICCOMBO OF THIS;
  353.       PROPERTY     ;
  354.          Tabstop .F.,;
  355.          Enabled      .F.,;
  356.          Width          10.81,     ;
  357.          Top          7.07,     ;
  358.          Left         72.98,     ;
  359.          Height          1.26,     ;
  360.          Value "",     ;
  361.          Style          2
  362.  
  363.    DEFINE PUSHBUTTON CLEARSALESPRICEBUTTON OF THIS;
  364.        PROPERTY;
  365.          Id 5,;
  366.          ColorNormal "N/W",;
  367.          OnClick CLASS::CLEARSALESPRICE,;
  368.          Text "Clear",;
  369.          Tabstop      .F.,;
  370.          Width          6.76,;
  371.          Top          7.23,;
  372.          Left         86.53,;
  373.          Height          1.01
  374.  
  375.    DEFINE NORMALTEXT RELEASEDATETEXT OF THIS;
  376.        PROPERTY;
  377.          Alignment 5,;
  378.          Text "Release Date",;
  379.          Width         16.22,;
  380.          Top          9.09,;
  381.          Left          1.35,;
  382.          Height          1.01
  383.  
  384.    DEFINE COMBOBOX RELEASEDATEOPCOMBO OF THIS;
  385.       PROPERTY     ;
  386.          Tabstop .F.,;
  387.          Enabled     .F.,;
  388.          Width          8.11,     ;
  389.          Top          9.09,     ;
  390.          Left         18.92,     ;
  391.          Height          1.26,     ;
  392.          Value "",     ;
  393.          Style          2
  394.  
  395.    DEFINE ENTRYFIELD RELEASEDATEENTRY OF THIS;
  396.        PROPERTY;
  397.          OnGotFocus CLASS::ONGOTFOCUSFIELD,;
  398.          OnLostFocus CLASS::ONLOSTFOCUSFIELD,;
  399.          ColorNormal "r/w",;
  400.          Width         13.52,;
  401.          Top          9.09,;
  402.          Left         31.08,;
  403.          Height          1.07,;
  404.          Border .T.,;
  405.          Value {},;
  406.          ColorHighLight "r/w*",;
  407.          Function "DJ",;
  408.          Maxlength 10
  409.  
  410.    DEFINE COMBOBOX RELEASEDATELOGICCOMBO OF THIS;
  411.       PROPERTY     ;
  412.          Tabstop .F.,;
  413.          Enabled      .F.,;
  414.          Width          10.81,     ;
  415.          Top          9.09,     ;
  416.          Left         72.98,     ;
  417.          Height          1.26,     ;
  418.          Value "",     ;
  419.          Style          2
  420.  
  421.    DEFINE PUSHBUTTON CLEARRELEASEDATEBUTTON OF THIS;
  422.        PROPERTY;
  423.          Id 4,;
  424.          ColorNormal "N/W",;
  425.          OnClick CLASS::CLEARRELEASEDATE,;
  426.          Text "Clear",;
  427.          Tabstop      .F.,;
  428.          Width          6.76,;
  429.          Top          9.24,;
  430.          Left         86.53,;
  431.          Height          1.01
  432.  
  433.  
  434.    DEFINE NORMALTEXT MEDIATYPETEXT OF THIS;
  435.        PROPERTY;
  436.          Alignment 5,;
  437.          Text "Media Type",;
  438.          Width         16.22,;
  439.          Top         11.11,;
  440.          Left          1.35,;
  441.          Height          1.21
  442.  
  443.  
  444.    DEFINE COMBOBOX MEDIATYPEOPCOMBO OF THIS;
  445.       PROPERTY     ;
  446.          Tabstop .F.,;
  447.          Enabled     .F.,;
  448.          Width          8.11,     ;
  449.          Top         11.11,     ;
  450.          Left         18.92,     ;
  451.          Height          1.26,     ;
  452.          Value "",     ;
  453.          Style          2
  454.  
  455.  
  456.    DEFINE COMBOBOX MEDIATYPECOMBO OF THIS;
  457.       PROPERTY;
  458.          Tabstop .F.,;
  459.          OnGotFocus CLASS::ONGOTFOCUSFIELD,;
  460.          OnLostFocus CLASS::ONLOSTFOCUSFIELD,;
  461.          Width         40.55,;
  462.          Top         11.11,;
  463.          Left         31.08,;
  464.          Height          1.26,;
  465.          Value " ",;
  466.          Style          2
  467.  
  468.    DEFINE PUSHBUTTON CLEARMEDIATYPEBUTTON OF THIS;
  469.        PROPERTY;
  470.          Id 6,;
  471.          ColorNormal "N/W",;
  472.          OnClick CLASS::CLEARMEDIATYPE,;
  473.          Text "Clear",;
  474.          Tabstop      .F.,;
  475.          Width          6.76,;
  476.          Top         11.26,;
  477.          Left         86.53,;
  478.          Height          1.01
  479.  
  480.    DEFINE IMAGE LOGOIMAGE OF THIS;
  481.        PROPERTY;
  482.          Width          10.81,;
  483.          Top         13.13,;
  484.          Left         1.35,;
  485.          Height          3.03,;
  486.          DataSource "FILENAME SMLMUSIC.BMP"
  487.  
  488.    DEFINE OKMBUTTON FILTEROKBUTTON OF THIS;
  489.        PROPERTY;
  490.          Width        14.11,;
  491.          Top         14.14,;
  492.          Left         64.87,;
  493.          Height          1.50,;
  494.          Default .T.,;
  495.          Group .T.
  496.  
  497.    DEFINE CANCELMBUTTON FILTERCANCELBUTTON OF THIS;
  498.        PROPERTY;
  499.          Width        14.11,;
  500.          Top         14.14,;
  501.          Left         79.74,;
  502.          Height          1.50,;
  503.          ID          0,;
  504.          Group .F.
  505.  
  506.  
  507. *******************************************************************************
  508. procedure OnOpen
  509. *******************************************************************************
  510.  
  511. set procedure to Music.prg additive
  512. this.saveExact = set("exact")
  513. this.saveFields = setto("fields")
  514. setSkip = "Music"
  515. if empty(alias())
  516.    set view to  Music.qbe
  517. endif
  518. use configs again in select() alias configs2 order descript  && for media types
  519. set exact off
  520. set fields to
  521. set skip to &setSkip
  522.  
  523.  
  524. this.CreateArrays()
  525.  
  526. this.mediaTypeCombo.dataSource = "array form.configsAr"
  527. this.artistOpCombo.dataSource = "array form.charOpAr"
  528. this.titleOpCombo.dataSource = "array form.charOpAr"
  529. this.rankOpCombo.dataSource = "array form.operatorAr"
  530. this.salesPriceOpCombo.dataSource = "array form.operatorAr"
  531. this.releaseDateOpCombo.dataSource = "array form.operatorAr"
  532. this.mediaTypeOpCombo.dataSource = "array form.charOpAr"
  533. this.artistLogicCombo.dataSource = "array form.logicOpAr"
  534. this.titleLogicCombo.dataSource = "array form.logicOpAr"
  535. this.rankLogicCombo.dataSource = "array form.logicOpAr"
  536. this.salesPriceLogicCombo.dataSource = "array form.logicOpAr"
  537. this.releaseDateLogicCombo.dataSource = "array form.logicOpAr"
  538.  
  539. this.artistCombo.Datasource = "field music->artist"
  540. this.titleCombo.Datasource = "field music->title"
  541. this.titleCombo.value = ""
  542.  
  543.  
  544. this.artistCombo.prevObj     = this.artistOpCombo
  545. this.titleCombo.prevObj      = this.titleOpCombo
  546. this.rankSpin.prevObj        = this.rankOpCombo
  547. this.salesPriceSpin.prevObj  = this.salesPriceOpCombo
  548. this.releaseDateEntry.prevObj = this.releaseDateOpCombo
  549. this.mediaTypeCombo.prevObj  = this.mediaTypeOpCombo
  550.  
  551. this.artistCombo.nextObj     = this.artistLogicCombo
  552. this.titleCombo.nextObj      = this.titleLogicCombo
  553. this.rankSpin.nextObj        = this.rankLogicCombo
  554. this.salesPriceSpin.nextObj  = this.salesPriceLogicCombo
  555. this.releaseDateEntry.nextObj = this.releaseDateLogicCombo
  556. this.mediaTypeCombo.nextObj  = this.mediaTypeCombo.prevObj  && no combobox
  557.                                                             && after media types
  558. this.filter = ""                    && property containing selected filter
  559. this.count = reccount()             && count of records in the filter
  560.  
  561.  
  562. *******************************************************************************
  563. procedure OnClose
  564. *******************************************************************************
  565. private saveExact, saveFields
  566.  
  567. set skip to
  568. saveExact = this.saveExact
  569. saveFields = this.saveFields
  570. set exact &saveExact
  571. set fields to &saveFields
  572. use in configs2                     && Close temporary configs table
  573.  
  574. *** If form is not opened modally
  575. if _app.framewin.text <> "Musical Methods" .and. type("this.viewForm") <> "U"
  576.    this.viewForm.filter = set("filter")
  577. endif
  578.  
  579.  
  580. *******************************************************************************
  581. procedure OnGotFocusField
  582. *******************************************************************************
  583.  
  584. if empty(this.prevObj.value)
  585.    this.prevObj.value = " is "
  586. endif
  587. if .not. empty(this.nextObj) .and. empty(this.nextObj.value)
  588.    this.nextObj.value = AND_STRING
  589. endif
  590. this.prevObj.enabled = .T.
  591. this.nextObj.enabled = .T.
  592. this.prevObj.tabstop = .T.
  593. this.nextObj.tabstop = .T.
  594.  
  595.  
  596. *******************************************************************************
  597. procedure OnLostFocusField
  598. *******************************************************************************
  599.  
  600. if empty(this.value)                && Nothing was entered
  601.    this.prevObj.value = EMPTY_OP
  602.    this.prevObj.tabstop = .F.
  603.    this.prevObj.enabled = .F.
  604.    show object this.prevObj
  605.    this.nextObj.value = EMPTY_LOGIC
  606.    this.nextObj.tabstop = .F.
  607.    this.nextObj.enabled = .F.
  608.    show object this.nextObj
  609. else                                && Enable comboboxes if they exist
  610.    if .not. empty(this.nextObj)     && (MediaTypeCombo doesn't have nextObj)
  611.       this.nextObj.enabled = .T.
  612.       if empty(this.nextObj.value)
  613.          this.nextObj.value = "and"
  614.       endif
  615.    endif
  616.    this.prevObj.enabled = .T.
  617.    if empty(this.prevObj.value)     && if no operator, assign one
  618.       this.prevObj.value = " is  "
  619.    endif
  620. endif
  621. if type("this.value") = "C"
  622.    this.value = form.CleanString(this.value)
  623.    show object this
  624. endif
  625.  
  626.  
  627. *******************************************************************************
  628. procedure CreateArrays
  629. *******************************************************************************
  630. local arrayRef  && variable for minimizing property access
  631.  
  632. * combobox datasource arrays
  633. this.operatorAr = new array(5)
  634. this.charOpAr = new array(3)
  635. this.logicOpAr  = new array(3)
  636. this.configsAr  = new array(reccount("configs2") + 1)  && add 1 for empty value
  637.  
  638. arrayRef = this.operatorAr
  639. arrayRef[1] = EMPTY_OP
  640. arrayRef[2] = " is    "
  641. arrayRef[3] = " isn't "
  642. arrayRef[4] = " <     "
  643. arrayRef[5] = " >     "
  644.  
  645. acopy(this.operatorAr,this.charOpAr,1,3)  && only want "is" and "isn't"
  646.  
  647. arrayRef = this.logicOpAr
  648. arrayRef[1] = EMPTY_LOGIC
  649. arrayRef[2] = AND_STRING
  650. arrayRef[3] = OR_STRING
  651.  
  652. arrayRef = this.configsAr
  653. arrayRef[1] = EMPTY_STRING
  654. arrayRef[2] = "12 in. VINYL"
  655. arrayRef[3] = "COMPACT DISC"
  656. arrayRef[4] = "VHS VIDEO"
  657. arrayRef[5] = "CASSETTE"
  658. arrayRef[6] = "DIGITAL COMPACT CASSETTE"
  659. arrayRef[7] = "12 in. LASER DISC"
  660. arrayRef[8] = "MINI-DISC"
  661. arrayRef[9] = "ACCESSORIES"
  662.  
  663.  
  664. *******************************************************************************
  665. Procedure OnSelection(controlId)
  666. *******************************************************************************
  667. private filterVar, filterStr, strConfig, saveFilter, saveRec, closeForm,;
  668.     curTable
  669.  
  670. form.selectedId = controlId         && Indicates to calling procedure what
  671. closeForm = .F.
  672. curTable = alias()
  673. do case                             && control was selected
  674.    case controlId > 0  && Clear buttons were selected -- don't do anything
  675.    case controlId = 0  && Cancel was selected
  676.       closeForm = .T.
  677.    otherwise
  678.       filterVar = ""
  679.       filterStr = ""
  680.       if .not. empty(this.artistCombo.value)      && Artist was entered
  681.          this.AddFilter(filterVar, filterStr, " Music->Artist ",;
  682.                       this.artistText.text, this.artistOpCombo,;
  683.                       this.artistCombo.value, this.artistLogicCombo)
  684.       endif
  685.       if .not. empty(this.titleCombo.value)       && Title was entered
  686.          this.AddFilter(filterVar, filterStr, " Music->Title ",;
  687.                       this.titleText.text, this.titleOpCombo,;
  688.                       this.titleCombo.value, this.titleLogicCombo)
  689.       endif
  690.       if .not. empty(this.rankSpin.value)         && Rank was entered
  691.          this.AddFilter(filterVar, filterStr, " Music->Rank ",;
  692.                       this.rankText.text, this.rankOpCombo,;
  693.                       this.rankSpin.value, this.rankLogicCombo)
  694.       endif
  695.       if .not. empty(this.salesPriceSpin.value)   && Sales Price was entered
  696.          this.AddFilter(filterVar, filterStr, " Music->List_Price ",;
  697.                       this.salesPriceText.text, this.salesPriceOpCombo,;
  698.                       this.salesPriceSpin.value, this.salesPriceLogicCombo)
  699.       endif
  700.       if .not. empty(this.releaseDateEntry.value) && Release Date was entered
  701.          this.AddFilter(filterVar, filterStr, " Music->Street_Dt ",;
  702.                       this.releaseDateText.text, this.releaseDateOpCombo,;
  703.                       this.releaseDateEntry.value, this.ReleaseDateLogicCombo)
  704.       endif
  705.       if .not. empty(this.mediaTypeCombo.value)   && Media Type was specified
  706.          select configs2
  707.          seek this.mediaTypeCombo.value
  708.          strConfig = str(configs2->config)
  709.          select &curTable
  710.          this.AddFilter(filterVar, filterStr, " Music->Config ",;
  711.                    this.mediaTypeText.text, this.mediaTypeOpCombo,;
  712.                    strConfig, "")
  713.       endif
  714.       * If last word was .and./.or., delete it
  715.       if CLASS::BackRat(" .or.  ",filterVar) = 7 .or.;
  716.                                         CLASS::BackRat(" .and. ",filterVar) = 7
  717.          filterVar = substr(filterVar,1,len(filterVar) - LOGIC_OP_LEN)
  718.          filterStr = substr(filterStr,1,len(filterStr) - DISPLAY_LOGIC_OP_LEN)
  719.       endif
  720.       saveRec = iif(eof(), reccount(), recno())
  721.       saveFilter = set("filter")
  722.  
  723.       * Set the filter
  724.       select music
  725.       set filter to &filterVar
  726.       go top
  727.  
  728.       select &curTable
  729.       set filter to &filterVar
  730.       count to form.count
  731.       go top
  732.  
  733.       if eof()                                 && no matching records
  734.          set filter to &saveFilter
  735.          go top
  736.          go saveRec
  737.          if ConfirmationMessage("No matching data was found. Continue?",;
  738.                                 "Sorry") = NO
  739.             closeForm = .T.
  740.          endif
  741.       else       && matching records
  742.          form.filter = filterStr
  743.          if type("form.viewForm") <> "U"
  744.             form.viewForm.filter = filterStr   && Save filter in view form
  745.          endif
  746.          InformationMessage(;
  747.             FormatStr("%1 items meet the specified condition:\n\n%2",;
  748.                       ltrim(str(this.count)),;
  749.                       form.filter),;
  750.             "Information")
  751.          closeForm = .T.
  752.       endif
  753. endcase
  754. if closeForm
  755.    form.Close()
  756. endif
  757.  
  758.  
  759. *******************************************************************************
  760. procedure DecodeOp(opControl)
  761. *******************************************************************************
  762. private op,decodedOp
  763.  
  764. op = opControl.value
  765. decodedOp = op         && some operators are directly transferable, but
  766. do case                && the case statement handles ones that aren't
  767.    case op = " is    "
  768.       decodedOp =     " =  "
  769.    case op = " isn't "
  770.       decodedOp =     " <> "
  771.    case op = AND_STRING
  772.       decodedOp =     " .and. "
  773.    case op = OR_STRING
  774.       decodedOp =     " .or.  "
  775. endcase
  776. return decodedOp
  777.  
  778.  
  779. *******************************************************************************
  780. Procedure ClearArtist
  781. *******************************************************************************
  782.  
  783. form.artistOpCombo.value    = EMPTY_OP
  784. form.artistCombo.value      = space(ENTRY_WIDTH)
  785. form.artistLogicCombo.value = EMPTY_LOGIC
  786. form.artistCombo.OnLostFocus()
  787.  
  788.  
  789. *******************************************************************************
  790. Procedure ClearTitle
  791. *******************************************************************************
  792.  
  793. form.titleOpCombo.value    = EMPTY_OP
  794. form.titleCombo.value      = space(ENTRY_WIDTH)
  795. form.titleLogicCombo.value = EMPTY_LOGIC
  796. form.titleCombo.OnLostFocus()
  797.  
  798.  
  799. *******************************************************************************
  800. Procedure ClearRank
  801. *******************************************************************************
  802.  
  803. form.rankOpCombo.value    = EMPTY_OP
  804. form.rankSpin.value       = 0
  805. form.rankLogicCombo.value = EMPTY_LOGIC
  806. form.rankSpin.OnLostFocus()
  807.  
  808.  
  809. *******************************************************************************
  810. Procedure ClearSalesPrice
  811. *******************************************************************************
  812.  
  813. form.salesPriceOpCombo.value    = EMPTY_OP
  814. form.salesPriceSpin.value       = 0
  815. form.salesPriceLogicCombo.value = EMPTY_LOGIC
  816. form.salesPriceSpin.OnLostFocus()
  817.  
  818.  
  819. *******************************************************************************
  820. Procedure ClearReleaseDate
  821. *******************************************************************************
  822.  
  823. form.releaseDateOpCombo.value    = EMPTY_OP
  824. form.releaseDateEntry.value       = {//}
  825. form.releaseDateLogicCombo.value = EMPTY_LOGIC
  826. form.releaseDateEntry.OnLostFocus()
  827.  
  828.  
  829. *******************************************************************************
  830. Procedure ClearMediaType
  831. *******************************************************************************
  832.  
  833. form.mediaTypeOpCombo.value = EMPTY_OP
  834. form.mediaTypeCombo.value   = " "
  835. form.mediaTypeCombo.OnLostFocus()
  836.  
  837.  
  838. *******************************************************************************
  839. procedure AddFilter(filterVar, filterStr, field,;
  840.                     text, opCombo, value, logicCombo)
  841. *******************************************************************************
  842. private filterValue, displayValue, filterLogicOp, displayLogicOp
  843.  
  844. do case
  845.    case text = "Artist" .or. text = "Title"
  846.       filterValue  = '"' + ALLTRIM(value) + '"'
  847.       displayValue = ALLTRIM(value)
  848.    case text = "Rank"
  849.       filterValue  = str(value,4)
  850.       displayValue = str(value,4)
  851.    case text = "Sales Price"
  852.       filterValue  = stuff(str(value,5,2),3,1,".")
  853.       displayValue = "$" + ltrim(stuff(str(value,5,2),3,1,"."))
  854.    case text = "Release Date"
  855.       filterValue  = "ctod('" +dtoc(this.releaseDateEntry.value) + "')"
  856.       displayValue = dtoc(value)
  857.    case text = "Media Type"
  858.       filterValue  = value
  859.       displayValue = configs2->descript
  860. endcase
  861.  
  862. * Make sure comboboxes have meaningful values
  863. opCombo.value = iif(empty(opCombo.value)," is ", opCombo.value)
  864. if .not. empty(logicCombo)
  865.    logicCombo.value = iif(empty(logicCombo.value), " and ", logicCombo.value)
  866.    filterLogicOp = this.DecodeOp(logicCombo)
  867.    displayLogicOp = logicCombo.value + RETURN_CHAR  && end sentence with Return
  868. else
  869.    filterLogicOp = ""
  870.    displayLogicOp = ""
  871. endif
  872. filterVar = filterVar + ;
  873.                field + ;
  874.                this.DecodeOp(opCombo) +;
  875.                filterValue +;
  876.                filterLogicOp
  877. filterStr = filterStr +;
  878.                text +;
  879.                opCombo.value +;
  880.                displayValue +;
  881.                displayLogicOp
  882.  
  883.  
  884. *******************************************************************************
  885. function BackRat(searchStr, targetStr)
  886. *******************************************************************************
  887. local lenTarget, lenSearch, foundLoc
  888.  
  889. lenTarget = len(targetStr)
  890. lenSearch = len(searchStr)
  891. foundLoc = rat(searchStr, targetStr)
  892. return iif(foundLoc = 0,;
  893.            0,;
  894.            lenTarget - foundLoc + 1)
  895.  
  896.  
  897. *******************************************************************************
  898. function CleanString(s)
  899.  
  900. * Delete extraneous delimiters from string
  901. *******************************************************************************
  902. private firstChar, lastChar, lenS, atDelim1
  903.  
  904. s = rtrim(s)
  905. firstChar = left(s, 1)
  906. lastChar = right(s, 1)
  907. lenS = len(s)
  908. atDelim1 = at('"', s)
  909. do case
  910.    case firstChar $ STRING_DELIMITERS
  911.       do case
  912.          case lenS = 1
  913.             * string only contains quote -- make it be empty
  914.             s = ""
  915.          case lastChar = firstChar
  916.             * Get rid of first and last characters, and try function again
  917.             s = this.CleanString(substr(s, 2, lenS - 2))
  918.          otherwise
  919.             * Get rid of first character and try function again
  920.             s = this.CleanString(substr(s, 2))
  921.       endcase
  922.    case lastChar $ STRING_DELIMITERS
  923.       * Get rid of last character
  924.       s = this.CleanString(substr(s, 1, lenS - 1))
  925.    case atDelim1 > 0
  926.       * Get rid of delimiters in middle
  927.       s = left(s, atDelim1 - 1) + this.CleanString(right(s, lenS - atDelim1 + 1))
  928. endcase
  929.  
  930. return s + space(ENTRY_WIDTH - lenS)  && return string of ENTRY_WIDTH length
  931.  
  932.  
  933.  
  934. ENDCLASS
  935.  
  936.  
  937.  
  938.  
  939.  
  940.  
  941.  
  942.  
  943.