home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 1998 April B / Pcwk4b98.iso / Borland / Dbase50w / SAMPLES1.PAK / ORDERS.WFM < prev    next >
Text File  |  1994-08-02  |  27KB  |  814 lines

  1. *******************************************************************************
  2. *  PROGRAM:      Orders.wfm
  3. *
  4. *  WRITTEN BY:   Borland Samples Group
  5. *
  6. *  DATE:         1/94
  7. *
  8. *  UPDATED:      7/94
  9. *
  10. *  REVISION:     $Revision:   1.86  $
  11. *
  12. *  VERSION:      dBASE FOR WINDOWS 5.0
  13. *
  14. *  DESCRIPTION:  This form displays information about an order from a company.
  15. *                It allows traversing through orders and going to the top and
  16. *                bottom.  This form also has a corresponding menu, OrdCust.mnu,
  17. *                which allows adding,deleting and searching for an order.
  18. *                When an unknown customer number is entered, a dialog will come
  19. *                up asking you if you want to add a new customer.  If you
  20. *                selecte the Yes button, the Customer form (in customer.wfm)
  21. *                will be opened, so a new customer can be added.
  22. *
  23. *  PARAMETERS:   None
  24. *
  25. *  CALLS:        Orders.mnu       (Menu file)
  26. *                Buttons.cc       (Custom controls file)
  27. *                Customer.wfm     (Form for displaying customer information)
  28. *                Orders.qbe       (View of tables)
  29. *
  30. *  USAGE:        DO Orders.wfm    && Note that you can also DO Customer.wfm
  31. *
  32. *******************************************************************************
  33. #include <Messdlg.h>
  34. shell(.f.,.t.)
  35. create session
  36. set talk off
  37. set ldCheck off                        && To avoid language driver conflicts
  38.  
  39. ** END HEADER -- do not remove this line*
  40. * Generated on 07/07/94
  41. *
  42. local f
  43. f = NEW ORDERSFORM()
  44. f.Open()
  45.  
  46. CLASS ORDERSFORM OF FORM
  47.    Set Procedure To BUTTONS.CC additive
  48.    this.HelpFile = ""
  49.    this.Top =          0.00
  50.    this.MenuFile = "ORDERS.MNU"
  51.    this.MousePointer =          1
  52.    this.View = "ORDERS.QBE"
  53.    this.Left =          3.40
  54.    this.Maximize = .F.
  55.    this.HelpId = ""
  56.    this.Text = "Orders -- View Mode"
  57.    this.Minimize = .F.
  58.    this.Height =         20.80
  59.    this.Width =        92.65
  60.    this.OnClose = CLASS::ONCLOSE
  61.    this.EscExit = .f.
  62.  
  63.    DEFINE RECTANGLE ORDERCUSTRECT OF THIS;
  64.        PROPERTY;
  65.          Top          0.35,;
  66.          Left          0.85,;
  67.          Text "Order Info",;
  68.          Height          2.74,;
  69.          Border .T.,;
  70.          Width         75.65,;
  71.          ColorNormal "W"
  72.  
  73.    DEFINE RECTANGLE PAYMENTRECT OF THIS;
  74.        PROPERTY;
  75.          Top         10.57,;
  76.          Left          0.85,;
  77.          Text "Totals",;
  78.          Height          6.06,;
  79.          Border .T.,;
  80.          Width         34.00,;
  81.          ColorNormal "W"
  82.  
  83.    DEFINE RECTANGLE SHIPRECT OF THIS;
  84.        PROPERTY;
  85.          Top         16.82,;
  86.          Left          0.85,;
  87.          Text "Ship Info",;
  88.          Height          3.44,;
  89.          Border .T.,;
  90.          Width         75.65,;
  91.          ColorNormal "W"
  92.  
  93.    DEFINE TEXT ORDERNOTEXT OF THIS;
  94.        PROPERTY;
  95.          Top          1.24,;
  96.          Alignment          5,;
  97.          Left          2.55,;
  98.          Text "Order No:",;
  99.          Height          1.25,;
  100.          Border .F.,;
  101.          Width         11.05,;
  102.          ColorNormal "B/W"
  103.  
  104.    DEFINE ENTRYFIELD ORDERNOENTRY OF THIS;
  105.        PROPERTY;
  106.          Top          1.19,;
  107.          OnChange CLASS::CHANGESMADE,;
  108.          Left         14.45,;
  109.          Enabled .F.,;
  110.          DataLink "ORDERS->ORDER_NO",;
  111.          Height          1.19,;
  112.          Border .T.,;
  113.          Width          6.80,;
  114.          ColorNormal "N/W"
  115.  
  116.    DEFINE TEXT CUSTOMERNOTEXT OF THIS;
  117.        PROPERTY;
  118.          Top          1.24,;
  119.          Alignment          5,;
  120.          Left         25.50,;
  121.          Text "Customer No:",;
  122.          Height          1.25,;
  123.          Border .F.,;
  124.          Width         13.09,;
  125.          ColorNormal "B/W"
  126.  
  127.    DEFINE ENTRYFIELD CUSTOMERNOENTRY OF THIS;
  128.        PROPERTY;
  129.          Top          1.19,;
  130.          OnChange CLASS::CHANGESMADE,;
  131.          Left         39.10,;
  132.          Enabled .F.,;
  133.          DataLink "ORDERS->CUSTOMER_N",;
  134.          Height          1.19,;
  135.          Border .T.,;
  136.          Width          5.95,;
  137.          ColorNormal "N/W"
  138.  
  139.    DEFINE TEXT SALEDATETEXT OF THIS;
  140.        PROPERTY;
  141.          Top          1.24,;
  142.          Alignment          5,;
  143.          Left         46.75,;
  144.          Text "&Sale Date:",;
  145.          Height          1.25,;
  146.          Border .F.,;
  147.          Width         12.75,;
  148.          ColorNormal "B/W"
  149.  
  150.    DEFINE SPINBOX SALEDATESPIN OF THIS;
  151.        PROPERTY;
  152.          Top          1.19,;
  153.          OnChange CLASS::CHANGESMADE,;
  154.          Left         61.20,;
  155.          Enabled .F.,;
  156.          DataLink "ORDERS->SALE_DATE",;
  157.          Height          1.19,;
  158.          Border .T.,;
  159.          Width         13.60,;
  160.          ColorNormal "N/W",;
  161.          Rangemax        100,;
  162.          Rangemin          0.00
  163.  
  164.    DEFINE RECTANGLE LINEITEMSRECT OF THIS;
  165.        PROPERTY;
  166.          Top          3.38,;
  167.          Left          0.85,;
  168.          Text "&Line Items",;
  169.          Height          7.07,;
  170.          Border .T.,;
  171.          Width         75.65,;
  172.          ColorNormal "N/W"
  173.  
  174.    DEFINE BROWSE CHILDBROWSE OF THIS;
  175.        PROPERTY;
  176.          Append .F.,;
  177.          ShowRecNo .F.,;
  178.          OnNavigate CLASS::BrowseOnNavigate,;
  179.          Top          4.45,;
  180.          Alias "Lineitem",;
  181.          FontBold .F.,;
  182.          OnChange CLASS::BROWSECHANGESMADE,;
  183.          Fields "STOCK_NO\13,QTY\14,SELL_PRICE\16,TOTAL = SELL_PRICE*QTY\16",;
  184.          Left          1.70,;
  185.          ShowDeleted .F.,;
  186.          Delete .F.,;
  187.          Height          5.40,;
  188.          Width         73.95,;
  189.          ColorNormal "B/W",;
  190.          Modify .F.
  191.  
  192.    DEFINE TEXT TOTINVTEXT OF THIS;
  193.        PROPERTY;
  194.          Top         11.62,;
  195.          Alignment          8,;
  196.          Left          1.70,;
  197.          Text "Total Invoice:",;
  198.          Height          1.07,;
  199.          Border .F.,;
  200.          Width         13.60,;
  201.          ColorNormal "B/W"
  202.  
  203.    DEFINE ENTRYFIELD TOTINVENTRY OF THIS;
  204.        PROPERTY;
  205.          Top         11.62,;
  206.          Left         17.00,;
  207.          Enabled .F.,;
  208.          DataLink "ORDERS->TOTAL",;
  209.          Height          1.01,;
  210.          Border .T.,;
  211.          Picture "9,999,999.99",;
  212.          Width         17.00,;
  213.          ColorNormal "N/W",;
  214.          Function "J"
  215.  
  216.    DEFINE TEXT TOTPAIDTEXT OF THIS;
  217.        PROPERTY;
  218.          Top         13.13,;
  219.          Alignment          8,;
  220.          Left          1.70,;
  221.          Text "A&mount Paid:",;
  222.          Height          1.01,;
  223.          Border .F.,;
  224.          Width         13.09,;
  225.          ColorNormal "B/W"
  226.  
  227.    DEFINE ENTRYFIELD AMTPAIDENTRY OF THIS;
  228.        PROPERTY;
  229.          Top         13.13,;
  230.          Left         17.00,;
  231.          DataLink "ORDERS->AMT_PAID",;
  232.          Height          1.01,;
  233.          Border .T.,;
  234.          Picture "9,999,999.99",;
  235.          Width         17.00,;
  236.          ColorNormal "N/W",;
  237.          Enabled .F.,;
  238.          OnChange CLASS::AMTPAIDONCHANGE,;
  239.          Function "J"
  240.  
  241.    DEFINE TEXT BALDUETEXT OF THIS;
  242.        PROPERTY;
  243.          Top         14.65,;
  244.          Alignment          8,;
  245.          Left          1.70,;
  246.          Text "Balance Due:",;
  247.          Height          1.01,;
  248.          Border .F.,;
  249.          Width         13.09,;
  250.          ColorNormal "B/W"
  251.  
  252.    DEFINE ENTRYFIELD BALDUEENTRY OF THIS;
  253.        PROPERTY;
  254.          Value          0.00,;
  255.          Top         14.65,;
  256.          Left         17.00,;
  257.          Height          1.01,;
  258.          Border .T.,;
  259.          Picture "9,999,999.99",;
  260.          Width         17.00,;
  261.          ColorNormal "N/W",;
  262.          Enabled .F.,;
  263.          Function "J"
  264.  
  265.    DEFINE RECTANGLE TERMSRECT OF THIS;
  266.        PROPERTY;
  267.          Top         10.57,;
  268.          Left         35.70,;
  269.          Text "&Terms",;
  270.          Height          6.06,;
  271.          Border .T.,;
  272.          Width         16.15,;
  273.          ColorNormal "W"
  274.  
  275.    DEFINE RADIOBUTTON TERMSFOB OF THIS;
  276.        PROPERTY;
  277.          Top         11.23,;
  278.          Group .T.,;
  279.          OnChange CLASS::CHANGESMADE,;
  280.          Left         37.40,;
  281.          Enabled .F.,;
  282.          DataLink "TERMS",;
  283.          Text "FOB",;
  284.          Height          1.25,;
  285.          Width         12.75,;
  286.          ColorNormal "N/W"
  287.  
  288.    DEFINE RADIOBUTTON TERMSNET30 OF THIS;
  289.        PROPERTY;
  290.          Top         12.30,;
  291.          Group .F.,;
  292.          OnChange CLASS::CHANGESMADE,;
  293.          Left         37.40,;
  294.          Enabled .F.,;
  295.          DataLink "TERMS",;
  296.          Text "Net 30",;
  297.          Height          1.25,;
  298.          Width         12.75,;
  299.          ColorNormal "N/W"
  300.  
  301.    DEFINE RECTANGLE PAYMETHODRECT OF THIS;
  302.        PROPERTY;
  303.          Top         10.61,;
  304.          Left         52.70,;
  305.          Text "Pa&yment Method",;
  306.          Height          6.06,;
  307.          Border .T.,;
  308.          Width         23.80,;
  309.          ColorNormal "W"
  310.  
  311.    DEFINE RADIOBUTTON PAYCHECK OF THIS;
  312.        PROPERTY;
  313.          Top         11.40,;
  314.          Group .T.,;
  315.          OnChange CLASS::CHANGESMADE,;
  316.          Left         54.40,;
  317.          ID          1,;
  318.          Enabled .F.,;
  319.          DataLink "PAY_METHOD",;
  320.          Text "Check",;
  321.          Height          1.01,;
  322.          Width         12.75,;
  323.          ColorNormal "N/W"
  324.  
  325.    DEFINE RADIOBUTTON PAYCREDIT OF THIS;
  326.        PROPERTY;
  327.          Top         12.47,;
  328.          Group .F.,;
  329.          OnChange CLASS::CHANGESMADE,;
  330.          Left         54.40,;
  331.          ID          1,;
  332.          Enabled .F.,;
  333.          DataLink "PAY_METHOD",;
  334.          Text "Credit",;
  335.          Height          0.66,;
  336.          Width         12.75,;
  337.          ColorNormal "N/W"
  338.  
  339.    DEFINE RADIOBUTTON PAYMC OF THIS;
  340.        PROPERTY;
  341.          Top         13.36,;
  342.          Group .F.,;
  343.          OnChange CLASS::CHANGESMADE,;
  344.          Left         54.40,;
  345.          Enabled .F.,;
  346.          DataLink "PAY_METHOD",;
  347.          Text "MC",;
  348.          Height          0.78,;
  349.          Width         12.75,;
  350.          ColorNormal "N/W"
  351.  
  352.    DEFINE RADIOBUTTON PAYCASH OF THIS;
  353.        PROPERTY;
  354.          Top         14.32,;
  355.          Group .F.,;
  356.          OnChange CLASS::CHANGESMADE,;
  357.          Left         54.40,;
  358.          Enabled .F.,;
  359.          DataLink "PAY_METHOD",;
  360.          Text "Cash",;
  361.          Height          1.01,;
  362.          Width         12.75,;
  363.          ColorNormal "n/w"
  364.  
  365.    DEFINE RADIOBUTTON PAYVISA OF THIS;
  366.        PROPERTY;
  367.          Top         15.33,;
  368.          Group .F.,;
  369.          OnChange CLASS::CHANGESMADE,;
  370.          Left         54.40,;
  371.          Enabled .F.,;
  372.          DataLink "PAY_METHOD",;
  373.          Text "Visa",;
  374.          Height          1.01,;
  375.          Width         11.05,;
  376.          ColorNormal "N/W"
  377.  
  378.    DEFINE TEXT SHIPDATETEXT OF THIS;
  379.        PROPERTY;
  380.          Top         17.77,;
  381.          Alignment          5,;
  382.          Left          1.87,;
  383.          Text "S&hip Date:",;
  384.          Height          0.72,;
  385.          Border .F.,;
  386.          Width         12.75,;
  387.          ColorNormal "B/W"
  388.  
  389.    DEFINE SPINBOX SHIPDATESPIN OF THIS;
  390.        PROPERTY;
  391.          Top         17.35,;
  392.          OnChange CLASS::CHANGESMADE,;
  393.          Left         17.00,;
  394.          Enabled .F.,;
  395.          DataLink "ORDERS->SHIP_DATE",;
  396.          Height          1.19,;
  397.          Border .T.,;
  398.          Width         17.34,;
  399.          ColorNormal "N/W",;
  400.          Rangemax        100,;
  401.          Rangemin          0.00
  402.  
  403.    DEFINE TEXT SHIPVIATEXT OF THIS;
  404.        PROPERTY;
  405.          Top         18.84,;
  406.          Alignment          5,;
  407.          Left          3.40,;
  408.          Text "Ship &Via:",;
  409.          Height          1.25,;
  410.          Border .F.,;
  411.          Width         11.39,;
  412.          ColorNormal "B/W"
  413.  
  414.    DEFINE RADIOBUTTON SHIPDHL OF THIS;
  415.        PROPERTY;
  416.          Top         19.19,;
  417.          Group .T.,;
  418.          OnChange CLASS::CHANGESMADE,;
  419.          Left         17.85,;
  420.          Enabled .F.,;
  421.          DataLink "SHIP_VIA",;
  422.          Text "DHL",;
  423.          Height          0.81,;
  424.          Width         10.20,;
  425.          ColorNormal "N/W"
  426.  
  427.    DEFINE RADIOBUTTON SHIPEMERY OF THIS;
  428.        PROPERTY;
  429.          Top         19.19,;
  430.          Group .F.,;
  431.          OnChange CLASS::CHANGESMADE,;
  432.          Left         28.90,;
  433.          Enabled .F.,;
  434.          DataLink "SHIP_VIA",;
  435.          Text "Emery",;
  436.          Height          0.81,;
  437.          Width         10.20,;
  438.          ColorNormal "N/W"
  439.  
  440.    DEFINE RADIOBUTTON SHIPFEDEX OF THIS;
  441.        PROPERTY;
  442.          Top         19.19,;
  443.          Group .F.,;
  444.          OnChange CLASS::CHANGESMADE,;
  445.          Left         39.10,;
  446.          Enabled .F.,;
  447.          DataLink "SHIP_VIA",;
  448.          Text "FedEx",;
  449.          Height          0.81,;
  450.          Width         10.20,;
  451.          ColorNormal "N/W"
  452.  
  453.    DEFINE RADIOBUTTON SHIPUPS OF THIS;
  454.        PROPERTY;
  455.          Top         19.19,;
  456.          Group .F.,;
  457.          OnChange CLASS::CHANGESMADE,;
  458.          Left         50.15,;
  459.          Enabled .F.,;
  460.          DataLink "SHIP_VIA",;
  461.          Text "UPS",;
  462.          Height          0.81,;
  463.          Width         10.20,;
  464.          ColorNormal "N/W"
  465.  
  466.    DEFINE RADIOBUTTON SHIPUSMAIL OF THIS;
  467.        PROPERTY;
  468.          Top         19.19,;
  469.          Group .F.,;
  470.          OnChange CLASS::CHANGESMADE,;
  471.          Left         61.20,;
  472.          Enabled .F.,;
  473.          DataLink "SHIP_VIA",;
  474.          Text "US Mail",;
  475.          Height          0.81,;
  476.          Width         12.75,;
  477.          ColorNormal "N/W"
  478.  
  479.    DEFINE PREVBUTTON PREVORDERBUTTON OF THIS;
  480.        PROPERTY;
  481.          Top          0.80,;
  482.          Group .T.,;
  483.          OnClick CLASS::PREVIOUS,;
  484.          Left         77.35,;
  485.          Height          1.50,;
  486.          Width         14.11
  487.  
  488.    DEFINE NEXTBUTTON NEXTORDERBUTTON OF THIS;
  489.        PROPERTY;
  490.          Top          3.15,;
  491.          Group .F.,;
  492.          OnClick CLASS::NEXT,;
  493.          Left         77.35,;
  494.          Default .T.,;
  495.          Height          1.50,;
  496.          Width         14.11
  497.  
  498.    DEFINE PUSHBUTTON FIRSTORDERBUTTON OF THIS;
  499.        PROPERTY;
  500.          Top          5.23,;
  501.          Group .F.,;
  502.          OnClick {;form.CheckCommit(form.inEditMode);go top},;
  503.          Left         77.35,;
  504.          Text "F&irst",;
  505.          Height          1.50,;
  506.          Width         14.11,;
  507.          ColorNormal ""
  508.  
  509.    DEFINE PUSHBUTTON LASTORDERBUTTON OF THIS;
  510.        PROPERTY;
  511.          Top          7.42,;
  512.          Group .F.,;
  513.          OnClick {;form.CheckCommit(form.inEditMode);go bottom},;
  514.          Left         77.35,;
  515.          Text "L&ast",;
  516.          Height          1.50,;
  517.          Width         14.11,;
  518.          ColorNormal ""
  519.  
  520.    DEFINE IMAGE LOGOIMAGE OF THIS;
  521.        PROPERTY;
  522.          Top         17.35,;
  523.          Alignment          1,;
  524.          Left         77.35,;
  525.          Height          2.85,;
  526.          Width         15.30,;
  527.          DataSource "FILENAME DIVESHOP.BMP"
  528.  
  529.    ****************************************************************************
  530.    procedure Open
  531.    ****************************************************************************
  532.    private orderNoField
  533.  
  534.    if type("form.init") = "U"
  535.       form.init = .t.
  536.  
  537.       set skip to                     && orders.qbe contains set skip to lineitem
  538.       set exact off                   && the .qbe file contains SET EXACT ON
  539.  
  540.       set procedure to Sampproc additive
  541.       set procedure to Customer.wfm additive
  542.  
  543.       form.inEditMode = .f.           && indicator of view/edit state
  544.       form.changesMade = .f.          && indicator of changes made to field values
  545.       form.previousRecord = .f.       && Save record number when appending
  546.  
  547.       *** do calculations in another area so form doesn't get updated
  548.       use orders again in select() alias temp
  549.       select temp
  550.       orderNoField = field(1)         && order_no field
  551.       set order to &orderNoField      && order_no -- tag name is same as field
  552.       go bottom
  553.       form.maxOrder = &orderNoField   && max value for key field -- for creating
  554.                                       && new orders
  555.       use in temp
  556.       select orders
  557.       ***
  558.  
  559.       *** Open table for calculating totals and balance due in another work area
  560.       *** so that datalinks are not affected by record movements
  561.       use lineitem again in select() alias lineitem2 order tag order_no
  562.       select orders
  563.       set relation to order_no into lineitem2 constrain integrity additive
  564.       ***
  565.  
  566.       if type("form.parentCustomerForm") <> "U"
  567.          form.EscExit = .t.
  568.       endif
  569.    endif
  570.    form.BrowseOnNavigate()                    && calculate totals
  571.    form::open()                         && Now the form actually opens
  572.  
  573.    ****************************************************************************
  574.    procedure OnClose
  575.    ****************************************************************************
  576.    if form.inEditMode
  577.       form.ViewEdit()
  578.    endif
  579.    if type("form.parentCustomerForm") = "U"  && If called from Customer, leave shell(.f.)
  580.       shell(.t.)
  581.       close procedure SampProc
  582.       close procedure Customer.wfm
  583.       close procedure Orders.mnu
  584.    endif
  585.  
  586.    ****************************************************************************
  587.    procedure BrowseOnNavigate
  588.    ****************************************************************************
  589.    * calculate total invoice and balance
  590.    if eof()
  591.       form.root.order.viewEdit.enabled = .f.
  592.    else
  593.       form.root.order.viewEdit.enabled = .t.
  594.       form.balDueEntry.value = orders->total - form.AmtPaidEntry.value
  595.       show object form.balDueEntry
  596.    endif
  597.    form.CallShowCustomer()
  598.  
  599.    ****************************************************************************
  600.    procedure ChangesMade
  601.    ****************************************************************************
  602.    form.changesMade = .t.
  603.  
  604.    ****************************************************************************
  605.    procedure BrowseChangesMade
  606.    ****************************************************************************
  607.    local t
  608.  
  609.    form.changesMade = .t.
  610.    go recno("LINEITEM") in lineitem    && Make sure change is posted
  611.    select lineitem2                    && recalculate totals in other workarea
  612.    calculate sum(lineitem2->sell_price * lineitem2->qty) to t
  613.    select orders
  614.    replace orders->total with t
  615.    form.balDueEntry.value = orders->total - orders->amt_paid
  616.  
  617.    ****************************************************************************
  618.    procedure AmtPaidOnChange
  619.    ****************************************************************************
  620.    form.changesMade = .t.
  621.    form.BrowseOnNavigate()                    && calculate totals
  622.  
  623.    ****************************************************************************
  624.    procedure Next
  625.    ****************************************************************************
  626.    form.CheckCommit(form.inEditMode)
  627.    if .not. eof()
  628.       NEXTBUTTON::OnClick()
  629.    endif
  630.  
  631.    ****************************************************************************
  632.    procedure Previous
  633.    ****************************************************************************
  634.    form.CheckCommit(form.inEditMode)
  635.    PREVBUTTON::OnClick()
  636.  
  637.    ****************************************************************************
  638.    procedure CheckCommit (newInEditMode)
  639.    ****************************************************************************
  640.    private orderField, changesMade
  641.  
  642.    changesMade = form.changesMade
  643.    if form.changesMade
  644.       orderField = field(1)                  && Field Order_no
  645.       if ConfirmationMessage("Commit changes?",;
  646.                               FormatStr("Order %1",&orderField)) = YES
  647.          commit()
  648.       else
  649.          rollback()
  650.          if .not. empty(form.previousRecord)
  651.             go form.previousRecord
  652.             form.previousRecord = .f.
  653.          endif
  654.       endif
  655.       if form.inEditMode .and. newInEditMode
  656.          begintrans()
  657.       endif
  658.       form.changesMade = .f.
  659.    endif
  660.    if form.inEditMode <> newInEditMode
  661.       if newInEditMode                       && Going to Edit mode
  662.          begintrans()
  663.       else                                   && Going to View mode
  664.          if .not. changesMade
  665.             rollback()
  666.          endif
  667.       endif
  668.       form.inEditMode = newInEditMode
  669.    endif
  670.  
  671.    ****************************************************************************
  672.    procedure ViewEdit
  673.    ****************************************************************************
  674.    local inEditMode, control, editMenu
  675.  
  676.    editMenu = form.root.order.viewEdit
  677.  
  678.    *** If editing is completed, close transaction, otherwise open a transaction
  679.    if form.inEditMode                           && Change to View mode
  680.       form.checkChanged(.f.)
  681.       editMenu.text = "&Edit"
  682.       editMenu.shortcut = "Ctrl-E"
  683.       editMenu.statusMessage = "Edit data."
  684.       form.root.order.delete.enabled = .f.      && disabled in view mode
  685.       form.CheckCommit(.f.)                     && Check transaction and
  686.       form.text = "Orders -- View Mode"         && change mode to View
  687.       form.childBrowse.modify = .f.
  688.       form.statusMessage = "Select Order - Edit menu choice to " +;
  689.                            "edit/delete data."
  690.    else                                         && Change to Edit mode
  691.       editMenu.text = "&View"
  692.       editMenu.shortcut = "Ctrl-E"
  693.       editMenu.statusMessage = "View data."
  694.       form.root.order.delete.enabled = .t.      && enabled in edit mode
  695.       form.CheckCommit(.t.)                     && Check transaction and
  696.       form.text = "Orders -- Edit Mode"         && change mode to Edit
  697.       form.childBrowse.modify = .t.
  698.       form.statusMessage = "In Edit Mode.  " +;
  699.                            "Select Order - View menu choice to switch " +;
  700.                            "to View mode."
  701.    endif
  702.    form.childBrowse.setFocus()
  703.    control = form.first
  704.  
  705.    inEditMode = form.inEditMode    && so don't have to reference many times
  706.    do
  707.       do case
  708.          case control.name $ "ORDERNOENTRY,CUSTOMERNOENTRY,TOTINVENTRY,BALDUEENTRY"
  709.             * these are never editable
  710.             control.enabled = .f.
  711.          case .not. control.className $ "BROWSE,NEXTBUTTON,PREVBUTTON,PUSHBUTTON,IMAGE,TEXT"
  712.             * doesn't make sense to make the above classes enabled/not
  713.             control.enabled = inEditMode
  714.          case control.className = "BROWSE"
  715.             control.Modify = inEditMode
  716.             control.Delete = inEditMode
  717.             control.Append = inEditMode
  718.       endcase
  719.       control = control.before
  720.    until control.name = form.first.name
  721.    form.CustomerNoEntry.enabled = .f.       && Key field is always disabled
  722.    form.OrderNoEntry.enabled = .f.          && Key field is always disabled
  723.    form.setFocus()
  724.  
  725.  
  726.    ****************************************************************************
  727.    procedure CheckChanged(callCommit)
  728.  
  729.    * Check if changes have been made to the current entryfield.  This procedure
  730.    * is called from menu routines to make sure the form.changesMade gets
  731.    * updated when a menu is selected while the changed control has focus.
  732.    ****************************************************************************
  733.    private control, fieldValue
  734.  
  735.    if form.inEditMode
  736.       control = form.activeControl
  737.       fieldValue = iif(type("control.datalink") <> "U", control.datalink, .f.)
  738.       if control.classname = "ENTRYFIELD" .and. type("fieldValue") <> "L" ;
  739.          .and. control.value <> &fieldValue
  740.          form.changesMade = .t.
  741.       endif
  742.    endif
  743.    if form.changesMade .and. callCommit
  744.       form.CheckCommit(form.inEditMode)     && Check transactions
  745.    endif
  746.  
  747.  
  748.    ****************************************************************************
  749.    procedure StartCustomerForm
  750.  
  751.    * Starts the Customer form in it's own session.  Note that control returns
  752.    * to the current session when this procedure is returned from.  This means
  753.    * that between the create session command and return you cannot access
  754.    * tables in the current session.
  755.    ****************************************************************************
  756.    local custNo
  757.  
  758.    custNo = orders->customer_n            && Pass customer_n into into
  759.                                           && customer form in the new session
  760.    create session
  761.    set talk off                           && Set these for the new session
  762.    set ldCheck off
  763.  
  764.    form.childCustomerForm = new CustomerForm()  && Use Customer.wfm to view
  765.                                                 && or edit a customer
  766.    form.childCustomerForm.top  =  2.02
  767.    form.childCustomerForm.left =  4.25
  768.    form.childCustomerForm.customer_n = custNo
  769.    form.childCustomerForm.parentOrdersForm = form   && Store a reference to this
  770.                                                     && form so that Orders can
  771.                                                     && call events in this form
  772.    form.childCustomerForm.open()
  773.  
  774.    ****************************************************************************
  775.    procedure CallShowCustomer
  776.  
  777.    * Synchronizes the Customer form to the same customer.  This is done when
  778.    * Orders is run first (form.parentCustomerForm is undefined), and the
  779.    * Customer form has been opened (form.childCustomerForm is defined).
  780.    ****************************************************************************
  781.    if type("form.parentCustomerForm") = "U"        && Orders is the parent form
  782.       if type ("form.childCustomerForm") <> "U"    && Customer form defined
  783.          form.childCustomerForm.ShowCustomer(orders->customer_n)
  784.       endif
  785.    endif
  786.  
  787.    ****************************************************************************
  788.    procedure ShowOrders(custNo, orderNo)
  789.  
  790.    * Called by Customer.wfm when it is the first form run.  Used to synchronize
  791.    * this form to the same customer for a given order displayed in Customer.
  792.    ****************************************************************************
  793.    private pCustNo
  794.    
  795.    form.CheckChanged(.t.)
  796.    set order to custord                   && Order is customer_n + order_no
  797.    pCustNo = custNo                       && Parameters are local so cannot macro
  798.    form.customer_n = custNo               && For adding new orders
  799.    set key to "&pCustNo"                  && Only see corresponding orders
  800.    go top
  801.    seek custNo+orderNo
  802.  
  803. ENDCLASS
  804.  
  805.  
  806.  
  807.  
  808.  
  809.  
  810.  
  811.  
  812.  
  813.  
  814.