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

  1. *******************************************************************************
  2. *  PROGRAM:      Getflts.wfm
  3. *
  4. *  WRITTEN BY:   Borland Samples Group
  5. *
  6. *  DATE:         5/93
  7. *
  8. *  UPDATED:      5/95
  9. *
  10. *  REVISION:     $Revision:   1.30  $
  11. *
  12. *  VERSION:      Visual dBASE
  13. *
  14. *  DESCRIPTION:  This is a form called from Equipmnt.wfm that brings up a
  15. *                dialog which allows selecting AirBorland flights based on
  16. *                their origin, destination, and departure date.  This form
  17. *                has two listboxes -- originList and destList, and one
  18. *                spinbox -- dateSpin.  It also has Ok and Cancel buttons
  19. *                that respectively allow the selections to be saved or
  20. *                ignored.
  21. *
  22. *
  23. *  PARAMETERS:   None
  24. *
  25. *  CALLS:        Buttons.cc   (Custom controls file)
  26. *                Equipmnt.qbe (View of tables)
  27. *
  28. *  USAGE:        SET PROCEDURE TO GETFLTS.WFM
  29. *                LOCAL F
  30. *                F = NEW GETFLTS()
  31. *                F.READMODAL()
  32. *
  33. *******************************************************************************
  34. #include <Messdlg.h>
  35. #include <Utils.h>
  36. #include "Equipmnt.h"
  37.  
  38.  
  39. create session
  40. set talk off
  41. set ldCheck off
  42.  
  43. set ldCheck off
  44.  
  45. ** END HEADER -- do not remove this line*
  46. * Generated on 07/06/95
  47. *
  48. parameter bModal
  49. local f
  50. f = new GETFLTSFORM()
  51. if (bModal)
  52.    f.mdi = .F. && ensure not MDI
  53.    f.ReadModal()
  54. else
  55.    f.Open()
  56. endif
  57. CLASS GETFLTSFORM OF FORM
  58.    Set Procedure To &_dbwinhome.samples\BUTTONS.CC additive
  59.    this.OnOpen = CLASS::ONOPEN
  60.    this.Height = 14.5293
  61.    this.OnClose = CLASS::ONCLOSE
  62.    this.MousePointer = 1
  63.    this.ColorNormal = "N/GB+"
  64.    this.Text = "Flight Selection"
  65.    this.Width = 54.166
  66.    this.Top = 0.1172
  67.    this.OnSelection = CLASS::ONSELECTION
  68.    this.Left = 16.666
  69.  
  70.    DEFINE IMAGE LOGOIMAGE OF THIS;
  71.        PROPERTY;
  72.          Height 7.5293,;
  73.          Width 53,;
  74.          DataSource "FILENAME AIRBRLND.BMP",;
  75.          Alignment 2,;
  76.          Left 0.5
  77.  
  78.    DEFINE TEXT ORIGTEXT OF THIS;
  79.        PROPERTY;
  80.          Height 1,;
  81.          ColorNormal "N/GB+",;
  82.          Text "Origin",;
  83.          Width 17,;
  84.          Top 7.6465,;
  85.          FontSize 10,;
  86.          Left 1
  87.  
  88.    DEFINE LISTBOX ORIGINLIST OF THIS;
  89.        PROPERTY;
  90.          Height 5.8701,;
  91.          ColorNormal "N/W",;
  92.          FontBold .F.,;
  93.          ColorHighLight "W+/B",;
  94.          Width 17,;
  95.          ID 800,;
  96.          Top 8.5996,;
  97.          FontSize 9,;
  98.          Left 1
  99.  
  100.    DEFINE TEXT DESTTEXT OF THIS;
  101.        PROPERTY;
  102.          Height 1,;
  103.          ColorNormal "N/GB+",;
  104.          Text "Destination",;
  105.          Width 17,;
  106.          Top 7.6465,;
  107.          FontSize 10,;
  108.          Left 20
  109.  
  110.    DEFINE LISTBOX DESTLIST OF THIS;
  111.        PROPERTY;
  112.          Height 5.8701,;
  113.          ColorNormal "N/W",;
  114.          FontBold .F.,;
  115.          ColorHighLight "W+/B",;
  116.          Width 17,;
  117.          ID 800,;
  118.          Top 8.5996,;
  119.          FontSize 9,;
  120.          Left 20
  121.  
  122.    DEFINE TEXT DATETEXT OF THIS;
  123.        PROPERTY;
  124.          Height 1,;
  125.          ColorNormal "N/GB+",;
  126.          Text "Date",;
  127.          Width 14.5,;
  128.          Top 7.6465,;
  129.          FontSize 10,;
  130.          Left 39
  131.  
  132.    DEFINE SPINBOX DATESPIN OF THIS;
  133.        PROPERTY;
  134.          Height 1.2822,;
  135.          Function "J",;
  136.          FontBold .F.,;
  137.          ColorNormal "N/W",;
  138.          Value {01/01/92},;
  139.          ColorHighLight "W+/B",;
  140.          Rangemin {01/01/90},;
  141.          Width 14.166,;
  142.          Rangemax {01/01/94},;
  143.          Top 8.5996,;
  144.          FontSize 10,;
  145.          Left 39
  146.  
  147.    DEFINE OKBUTTON GETFLTSOKBUTTON OF THIS;
  148.        PROPERTY;
  149.          Height 1.5469,;
  150.          Width 14.166,;
  151.          Top 11.0996,;
  152.          Group .T.,;
  153.          Left 39
  154.  
  155.    DEFINE CANCELBUTTON GETFLTSCANCELBUTTON OF THIS;
  156.        PROPERTY;
  157.          Height 1.5527,;
  158.          Width 14.166,;
  159.          ID 0,;
  160.          Top 12.7998,;
  161.          Group .F.,;
  162.          Left 39
  163.  
  164.    procedure OnOpen
  165.    *******************************************************************************
  166.    set procedure to program(1) additive  && for functions located after class
  167.    set procedure to &_dbwinhome.samples\Sampproc.prg additive
  168.                                          && for FormatStr function
  169.  
  170.    if type("originAr") = "U"
  171.  
  172.       public originAr, destAr            && if called stand alone, create vars
  173.       local curRecCnt
  174.       private tagName
  175.  
  176.       this.standAlone = .T.
  177.       this.view = "Equipmnt.qbe"
  178.       *** make arrays of unique origins and destinations
  179.       select flights
  180.       tagName = field(2) + "UN"
  181.       set order to &tagName   && origin unique
  182.       count to curRecCnt      && count of unique origins -- for declaring array
  183.  
  184.       declare originAr[curRecCnt,1]
  185.       declare destAr[curRecCnt,1]
  186.  
  187.       copy to array originAr field origin
  188.       tagName = field(3) + "UN"
  189.       set order to &tagName   && destination unique
  190.       count to curRecCnt   && count of unique destinations -- for declaring array
  191.       copy to array destAr field dest
  192.       tagName = field(1)
  193.       set order to &tagName   && don't need the index for a while
  194.       go top
  195.    else
  196.       this.standAlone = .F.
  197.    endif
  198.    this.originList.dataSource = "Array originAr"
  199.    this.destList.dataSource = "Array destAr"
  200.    this.dateSpin.value = flights->date
  201.  
  202.    *******************************************************************************
  203.  
  204.    procedure OnClose
  205.    *******************************************************************************
  206.  
  207.    if form.standAlone   && if not called from equipmnt.wfm
  208.       release originAr, destAr
  209.    endif
  210.  
  211.    close procedure &_dbwinhome.samples\Buttons.cc,;
  212.        &_dbwinhome.samples\Sampproc.prg,;
  213.        program(1)
  214.  
  215.  
  216.    *******************************************************************************
  217.  
  218.    procedure OnSelection (controlId)
  219.  
  220.    * Filter out records that match specified conditions.
  221.    *******************************************************************************
  222.    private originT, destT, dateT, filter, planeT, curTable, tryAgain, tagName
  223.  
  224.    tryAgain = .F.
  225.    *** if Cancel wasn't selected and if not running standalone
  226.    if controlId <> 0
  227.       * get the selected origin, destination
  228.       originT = ALLTRIM(form.originList.value)
  229.       destT =  ALLTRIM(form.destList.value)
  230.       dateT = form.dateSpin.value
  231.       filter = ""
  232.       *** longer, but looks cleaner with IF instead of IIF()
  233.       if .not. empty(originT)
  234.          filter = FormatStr("origin = %1", AddQuotes(originT))
  235.       endif
  236.       if .not. empty(destT)
  237.          if .not. empty(filter)
  238.             filter = FormatStr("%1 .and. dest = %2", filter, AddQuotes(destT))
  239.          else
  240.             filter = FormatStr("dest = %1", AddQuotes(destT))
  241.          endif
  242.       endif
  243.       if .not. empty(dateT)
  244.          if .not. empty(filter)
  245.             filter = FormatStr("%1 .and. date >= ctod(%2)", filter, AddQuotes(dtoc(dateT)))
  246.          else
  247.             filter = FormatStr("date >= ctod(%1)", AddQuotes(dtoc(dateT)))
  248.          endif
  249.       endif
  250.       * Check filter in another area, so form doesn't get updated unnecessarily
  251.       use dbf() in select() alias temp
  252.       select temp
  253.       set filter to &filter
  254.       go top
  255.       if eof()             && no flights match the selections made
  256.          if ConfirmationMessage(;
  257.             FormatStr("There are no flights from %1 to %2 on or after %3."+;
  258.                          chr(13) +;
  259.                          "Would you like to select another set of flights?",;
  260.                       originT, destT, dtoc(dateT)),;
  261.             "Confirmation") = YES
  262.             tryAgain = .T.             && flag to specify that form stays open
  263.          endif
  264.          select flights
  265.       else
  266.          select flights
  267.          set filter to &filter
  268.          go top
  269.          do case
  270.             case .not. empty(originT)  && if an origin was specified, index on
  271.                                        && origin, and look for selected origin
  272.                tagName = field(2)
  273.                set order to &tagName   && tag origin
  274.                seek originT
  275.             case .not. empty(destT)    && otherwise, if a destination was
  276.                tagName = field(3)      && specified, index on that, and seek.
  277.                set order to &tagName   && tag dest
  278.                seek destT
  279.  
  280.             otherwise                          && index on origin if no selection was
  281.                tagName = field(2)
  282.                set order to &tagName           && made, and go to the top of the database
  283.                go top
  284.          endcase
  285.       endif
  286.       use in temp
  287.    endif
  288.    if .not. tryAgain
  289.       form.Close()
  290.    endif
  291.  
  292. ENDCLASS
  293.  
  294. *******************************************************************************
  295. function AddQuotes(string)
  296.  
  297. * Add quotes to the parameter string.  This function is used when combining
  298. * several strings and macrosubstituting (&) the resulting string
  299. *******************************************************************************
  300.  
  301. return "'" + string + "'"
  302.  
  303.  
  304.  
  305.  
  306.  
  307.  
  308.  
  309.  
  310.