home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / ProgramD2.iso / Visual Database / Visual dBase Pro v7.0 / DATA1.CAB / Sample_dBASE / Mugs / CustomerSelect.wfm < prev    next >
Encoding:
Text File  |  1997-11-20  |  8.2 KB  |  315 lines

  1. //--------------------------------------------------------------
  2. //
  3. //  CustomerSelect.wfm - Mugs Sample Application
  4. //
  5. //  Customer selection dialog for Invoice data entry form.
  6. //
  7. //  Dependencies: <none>
  8. //
  9. //  Visual dBASE Samples Group
  10. //
  11. //  $Revision:   1.10  $
  12. //
  13. //  Copyright (c) 1997, Borland International, Inc. 
  14. //  All rights reserved.
  15. //
  16. //---------------------------------------------------------------
  17. ** END HEADER -- do not remove this line
  18. //
  19. // Generated on 10/23/97
  20. //
  21. parameter bModal
  22. local f
  23. f = new CustomerSelectForm()
  24. if (bModal)
  25.    f.mdi = false // ensure not MDI
  26.    f.readModal()
  27. else
  28.    f.open()
  29. endif
  30.  
  31. class CustomerSelectForm of FORM
  32.    with (this)
  33.       open = class::FORM_OPEN
  34.       onOpen = class::FORM_ONOPEN
  35.       readModal = class::FORM_READMODAL
  36.       autoCenter = true
  37.       scaleFontSize = 8
  38.       scaleFontBold = false
  39.       height = 12.1364
  40.       left = 23.4286
  41.       top = 3.1364
  42.       width = 55.8571
  43.       text = "Select Customer"
  44.    endwith
  45.  
  46.  
  47.    this.DMCONNECT = new DATAMODREF()
  48.    this.DMCONNECT.parent = this
  49.    with (this.DMCONNECT)
  50.       filename = "connect.dmd"
  51.       dataModClass = "connectDataModule"
  52.       share = 0
  53.       active = true
  54.       left = 50
  55.       top = 0
  56.    endwith
  57.  
  58.  
  59.    this.TEXT1 = new TEXT(this)
  60.    with (this.TEXT1)
  61.       height = 1
  62.       left = 2
  63.       top = 1
  64.       width = 12
  65.       metric = 0
  66.       colorNormal = "BtnText"
  67.       fontName = "MS Sans Serif"
  68.       fontSize = 8
  69.       text = "Customer:"
  70.    endwith
  71.  
  72.  
  73.    this.LISTCUSTOMER = new LISTBOX(this)
  74.    with (this.LISTCUSTOMER)
  75.       height = 8
  76.       left = 2
  77.       top = 2
  78.       width = 35
  79.       metric = 0
  80.       id = 103
  81.       fontName = "MS Sans Serif"
  82.       fontSize = 8
  83.       colorHighLight = "HighLightText/HighLight"
  84.    endwith
  85.  
  86.  
  87.    this.LABELSORTBY = new TEXT(this)
  88.    with (this.LABELSORTBY)
  89.       height = 1
  90.       left = 3
  91.       top = 10.5
  92.       width = 7
  93.       metric = 0
  94.       colorNormal = "BtnText"
  95.       fontName = "MS Sans Serif"
  96.       fontSize = 8
  97.       text = "Sort by:"
  98.    endwith
  99.  
  100.  
  101.    this.RADIOID = new RADIOBUTTON(this)
  102.    with (this.RADIOID)
  103.       onGotFocus = {; this.form.setList(this.form, class::getID())}
  104.       transparent = false
  105.       height = 1
  106.       left = 10
  107.       top = 10.5
  108.       width = 5
  109.       text = "ID"
  110.       metric = 0
  111.       colorNormal = "WindowText/BtnFace"
  112.       fontName = "MS Sans Serif"
  113.       fontSize = 8
  114.       group = true
  115.       value = true
  116.    endwith
  117.  
  118.  
  119.    this.RADIOLAST = new RADIOBUTTON(this)
  120.    with (this.RADIOLAST)
  121.       onGotFocus = {; this.form.setList(this.form, class::getID())}
  122.       transparent = false
  123.       height = 1
  124.       left = 16
  125.       top = 10.5
  126.       width = 12
  127.       text = "Last name"
  128.       metric = 0
  129.       colorNormal = "WindowText/BtnFace"
  130.       fontName = "MS Sans Serif"
  131.       fontSize = 8
  132.       group = false
  133.       value = false
  134.    endwith
  135.  
  136.  
  137.    this.RADIOFIRST = new RADIOBUTTON(this)
  138.    with (this.RADIOFIRST)
  139.       onGotFocus = {; this.form.setList(this.form, class::getID())}
  140.       transparent = false
  141.       height = 1
  142.       left = 29
  143.       top = 10.5
  144.       width = 14
  145.       text = "First name"
  146.       metric = 0
  147.       colorNormal = "WindowText/BtnFace"
  148.       fontName = "MS Sans Serif"
  149.       fontSize = 8
  150.       group = false
  151.       value = false
  152.    endwith
  153.  
  154.  
  155.    this.BUTTONNEW = new PUSHBUTTON(this)
  156.    with (this.BUTTONNEW)
  157.       onClick = class::BUTTONNEW_ONCLICK
  158.       height = 1.1818
  159.       left = 39
  160.       top = 2.5
  161.       width = 15
  162.       text = "New Customer"
  163.       metric = 0
  164.       fontName = "MS Sans Serif"
  165.       fontSize = 8
  166.       group = true
  167.       colorNormal = "BtnText/BtnFace"
  168.       value = false
  169.    endwith
  170.  
  171.  
  172.    this.BUTTONSELECT = new PUSHBUTTON(this)
  173.    with (this.BUTTONSELECT)
  174.       onClick = class::BUTTONSELECT_ONCLICK
  175.       height = 1.1818
  176.       left = 39
  177.       top = 4
  178.       width = 15
  179.       text = "Select"
  180.       metric = 0
  181.       default = true
  182.       fontName = "MS Sans Serif"
  183.       fontSize = 8
  184.       group = true
  185.       colorNormal = "BtnText/BtnFace"
  186.       value = false
  187.    endwith
  188.  
  189.  
  190.    this.BUTTONCANCEL = new PUSHBUTTON(this)
  191.    with (this.BUTTONCANCEL)
  192.       onClick = class::BUTTONCANCEL_ONCLICK
  193.       height = 1.1818
  194.       left = 39
  195.       top = 5.5
  196.       width = 15
  197.       text = "Cancel"
  198.       metric = 0
  199.       fontName = "MS Sans Serif"
  200.       fontSize = 8
  201.       group = true
  202.       colorNormal = "BtnText/BtnFace"
  203.       value = false
  204.    endwith
  205.  
  206.  
  207.    // {Linked Method} form.buttoncancel.onClick
  208.    function BUTTONCANCEL_OnClick
  209.       this.form.selectID = null
  210.    return ( this.form.close() )
  211.  
  212.    // {Linked Method} form.buttonnew.onClick
  213.    function BUTTONNEW_OnClick
  214.       this.form.selectID = -1
  215.    return ( this.form.close() )
  216.  
  217.    // {Linked Method} form.buttonselect.onClick
  218.    function BUTTONSELECT_OnClick
  219.       this.form.selectID = class::getID()
  220.    return ( this.form.close() )
  221.  
  222.    // {Linked Method} form.open
  223.    function Form_Open       
  224.    return ( class::Form_readModal() )
  225.  
  226.    // {Linked Method} form.readModal
  227.    function Form_ReadModal
  228.       local nCount, sID
  229.       q = new Query()
  230.       with ( q )
  231.          database := this.dmConnect.ref.dbMugs
  232.          sql      := 'SELECT customer."Customer ID", ' + ; 
  233.                      '       customer."Last Name", ' + ;
  234.                      '       customer."First Name" ' + ;
  235.                      ' FROM "customer.dbf" customer ' + ;
  236.                      ' ORDER BY customer."Customer ID"'
  237.          active   := true
  238.       endwith
  239.       nCount = q.rowset.count()
  240.  
  241.       // Add custom properties to the form
  242.       this.aID         = new Array( nCount )
  243.       this.aLast       = new Array( nCount )
  244.       this.aFirst      = new Array( nCount )
  245.       this.aListSource = new Array( nCount )
  246.  
  247.       for i = 1 to nCount
  248.           this.aID[i]    := LTRIM(STR(q.rowset.fields["Customer ID"].value))
  249.           this.aLast[i]  := q.rowset.fields["Last Name"].value.rightTrim()
  250.           this.aFirst[i] := q.rowset.fields["First Name"].value.rightTrim()
  251.           q.rowset.next()
  252.       next      
  253.       q.active := false
  254.       class::SetList( this, -1 )
  255.  
  256.       with ( this )
  257.          visible := false // set to visible after curSel is set.
  258.          mdi     := false
  259.       endwith
  260.  
  261.       if ( TYPE("this.selectID") == "N" )
  262.          this.listCustomer.dataSource := null
  263.          this.listCustomer.dataSource := "ARRAY form.aListSource"
  264.       endif
  265.  
  266.    return ( CUSTOMERSELECTFORM::ReadModal() )
  267.  
  268.    function Form_onOpen
  269.       local sID
  270.       sID = ""
  271.       if ( TYPE("this.selectID") == "N" )
  272.          sID := LTRIM( STR( this.selectID ) )
  273.          this.listCustomer.curSel := this.aID.scan( sID )
  274.       else
  275.          this.listCustomer.curSel := 1
  276.       endif
  277.       this.visible := true
  278.    return true
  279.  
  280.    function getID
  281.       local nID, sID
  282.       nID = null
  283.       sID = RTRIM(this.form.listCustomer.value)
  284.       if ( RIGHT(sID,1) = "]" and "[" $ sID )
  285.          sID = SUBSTR( sID, RAT("[",sID) + 1, LEN(sID) )        
  286.       endif
  287.       nID = VAL( sID )
  288.    return ( nID )
  289.  
  290.    function SetList( thisForm, nID )
  291.       local sKey
  292.       for i = 1 to thisForm.aListSource.size
  293.           do case
  294.              case thisForm.radioID.value
  295.                   thisForm.aListSource[i] := TRANSFORM(VAL(thisForm.aID[i]),"9999") + " - " + thisForm.aLast[i] + ", " + thisForm.aFirst[i]
  296.              case thisForm.radioLast.value
  297.                   thisForm.aListSource[i] := thisForm.aLast[i] + ", " + thisForm.aFirst[i] + " [ " + thisForm.aID[i] + " ]"
  298.              otherwise
  299.                   thisForm.aListSource[i] := thisForm.aFirst[i] + " " + thisForm.aLast[i] + " [ " + thisForm.aID[i] + " ] "
  300.           endcase
  301.           if ( nID == VAL( thisForm.aID[i] ) )
  302.              sKey = thisForm.aListSource[i]
  303.           endif
  304.       next
  305.       thisForm.aListSource.sort()
  306.       thisForm.listCustomer.visible := false
  307.       if ( nID > 0)
  308.          thisForm.listCustomer.curSel := thisForm.aListSource.scan( sKey )
  309.       endif
  310.       thisForm.listCustomer.dataSource := null
  311.       thisForm.listCustomer.dataSource := "ARRAY form.aListSource"     
  312.       thisForm.listCustomer.visible := true
  313.    return ( i )
  314. endclass
  315.