home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 9 / 09.iso / l / l196 / 2.ddi / ISAMDEM2.BA$ / ISAMDEM2.bin
Encoding:
Text File  |  1990-06-24  |  37.6 KB  |  1,347 lines

  1. '       ISAMDEM2.BAS - third module of the ISAM demonstration program.
  2. '
  3. '               Copyright (C) 1989-1990, Microsoft Corporation
  4. '
  5. '   Main module - ISAMDEMO.BAS
  6. '   Include files - ISAMDEMO.BI
  7. '
  8. '
  9. '$INCLUDE: 'isamdemo.bi'
  10.  
  11. DEFINT A-Z
  12. ' RunCustRec
  13. ' Controls customer record form.  Provides viewing, updating, adding and
  14. ' deleting of customers.
  15. '
  16. ' Handle - window handle
  17. '
  18. SUB RunCustRec (handle)
  19.     ON LOCAL ERROR GOTO CustErr
  20.  
  21.     IF ISAMfile$ = "" THEN                          'isam file must be opened
  22.         PrintError "A database file must be opened before records can be viewed."
  23.         EXIT SUB
  24.     END IF
  25.  
  26.     savePosition = SAVEPOINT                        'ISAM savepoint
  27.     ErrFlag = FALSE
  28.  
  29.     GOSUB ShowCustRec
  30.  
  31.     ' window control loop
  32.     finished = FALSE
  33.     WHILE finished = FALSE
  34.         WindowDo curBut, currEditField                ' wait for event
  35.         SELECT CASE Dialog(0)
  36.             CASE 1                                      ' button pressed
  37.                 curBut = Dialog(1)
  38.                 currEditField = 0
  39.                 ButtonSetState pushButton, 1
  40.                 ButtonSetState curBut, 2
  41.                 pushButton = curBut
  42.                 GOSUB CustRecButton
  43.             CASE 2                                      ' edit field
  44.                 IF level < 2 THEN
  45.                     curBut = 0
  46.                     currEditField = Dialog(2)
  47.                 END IF
  48.             CASE 6                                      ' enter
  49.                 curBut = pushButton
  50.                 GOSUB CustRecButton
  51.             CASE 7, 11                                  ' tab, down arrow
  52.                 IF level < 2 THEN
  53.                 SELECT CASE curBut
  54.                     CASE 0
  55.                         SELECT CASE currEditField
  56.                             CASE IS < 9
  57.                                 currEditField = currEditField + 1
  58.                             CASE 9
  59.                                 currEditField = 0
  60.                                 curBut = 1
  61.                         END SELECT
  62.                     CASE 2
  63.                         curBut = 4 + RecCurrent
  64.                     CASE 4
  65.                         curBut = 8 + 3 * RecCurrent
  66.                     CASE 5
  67.                         IF NOT RecCurrent THEN
  68.                             curBut = 8
  69.                         ELSEIF level = 0 THEN
  70.                             curBut = 6
  71.                         ELSEIF HasInvoice THEN
  72.                             curBut = 7
  73.                         ELSE
  74.                             curBut = 8
  75.                         END IF
  76.                     CASE 6
  77.                         curBut = 8 + HasInvoice
  78.                     CASE 9
  79.                         currEditField = 1
  80.                         curBut = 0
  81.                         ButtonSetState pushButton, 1
  82.                         pushButton = 1
  83.                         ButtonSetState pushButton, 2
  84.                     CASE ELSE
  85.                         curBut = curBut + 1
  86.                 END SELECT
  87.                 IF curBut <> 0 THEN
  88.                     ButtonSetState pushButton, 1
  89.                     ButtonSetState curBut, 2
  90.                     pushButton = curBut
  91.                 END IF
  92.                 END IF
  93.             CASE 8, 10                                  ' back tab, up arrow
  94.                 IF level < 2 THEN
  95.                 SELECT CASE curBut
  96.                     CASE 0
  97.                         SELECT CASE currEditField
  98.                             CASE 1
  99.                                 currEditField = 0
  100.                                 curBut = 9
  101.                             CASE ELSE
  102.                                 currEditField = currEditField - 1
  103.                         END SELECT
  104.                     CASE 1
  105.                         currEditField = 9
  106.                         curBut = 0
  107.                     CASE 4
  108.                         curBut = 2 - RecCurent
  109.                     CASE 7
  110.                         curBut = 6 - level
  111.                     CASE 8
  112.                         IF NOT RecCurrent THEN
  113.                             curBut = 4
  114.                         ELSEIF HasInvoice THEN
  115.                             curBut = 7
  116.                         ELSEIF level = 0 THEN
  117.                             curBut = 6
  118.                         ELSE
  119.                             curBut = 5
  120.                         END IF
  121.                     CASE ELSE
  122.                         curBut = curBut - 1
  123.                 END SELECT
  124.                 IF curBut <> 0 THEN
  125.                         ButtonSetState pushButton, 1
  126.                         pushButton = curBut
  127.                         ButtonSetState pushButton, 2
  128.                 END IF
  129.                 END IF
  130.             CASE 9                                      ' escape
  131.                 finished = CANCEL
  132.             CASE 14                                     ' space bar
  133.                 IF curBut > 0 THEN GOSUB CustRecButton
  134.          END SELECT
  135.     WEND
  136.  
  137.     IF finished = OK THEN
  138.         CHECKPOINT
  139.     ELSE
  140.         ROLLBACK savePosition
  141.     END IF
  142.  
  143.     WindowClose handle
  144.     EXIT SUB
  145.  
  146. CustErr:
  147.     SELECT CASE ERR
  148.         CASE 52                                       'open database before continuing
  149.             PrintError "A database file must be opened before customer records can be displayed."
  150.             EXIT SUB
  151.         CASE ELSE
  152.             ShowError ERR
  153.             IF ERR = 86 THEN                            'can't add duplicate records
  154.                 RESUME CustErrReturn
  155.             ELSEIF ERR = 89 THEN                        'not enough ISAM buffers to continue
  156.                 WindowClose handle
  157.                 ROLLBACK savePosition
  158.                 EXIT SUB
  159.             END IF
  160.     END SELECT
  161.     
  162. RESUME NEXT
  163.  
  164. CustRecButton:                                    'process button selection
  165.     IF level > 1 THEN
  166.         finished = CANCEL
  167.     ELSE
  168.     SELECT CASE curBut
  169.         CASE 1                                        'get next record
  170.             GOSUB RetrieveCustRecord
  171.         CASE 2                                        'clear form for new record
  172.             GOSUB ClearCustEditFields
  173.         CASE 3                                        'update current form
  174.             GOSUB RetrieveCustEditFields
  175.             IF NOT ErrFlag THEN
  176.                 UPDATE CustTabNum, CustRec
  177.             ELSE
  178.                 ErrFlag = FALSE
  179.             END IF
  180.         CASE 4                                       'add new record
  181.             GOSUB RetrieveCustEditFields
  182.             IF NOT ErrFlag THEN
  183.                 CustRec.Opened = MID$(DATE$, 9, 2) + MID$(DATE$, 1, 2) + MID$(DATE$, 4, 2)
  184.                 INSERT CustTabNum, CustRec
  185.                 GOSUB ClearCustEditFields
  186.             ELSE
  187.                 ErrFlag = FALSE
  188.             END IF
  189.         CASE 5                                        'delete record
  190.             DELETE CustTabNum
  191.             GOSUB ClearCustEditFields
  192.         CASE 6                                        'purchase order
  193.             ClearInveRecord
  194.             ClearInvoRecord
  195.             RunInvoice WindowNext
  196.             GOSUB CheckInvoice
  197.             GOSUB UpdateButtons
  198.             level = 0
  199.         CASE 7                                        'display list of invoices
  200.             oldlevel = level
  201.             RunList WindowNext, 4
  202.             level = oldlevel
  203.         CASE 8
  204.             finished = OK
  205.         CASE 9
  206.             finished = CANCEL
  207.     END SELECT
  208.     END IF
  209. CustErrReturn:
  210. RETURN
  211.  
  212. RetrieveCustRecord:
  213.     key2$ = UCASE$(LTRIM$(EditFieldInquire$(1)))
  214.     key1$ = LTRIM$(EditFieldInquire$(2))
  215.     status = NextRecord%(CustTabNum, key1$, origkey1$, lastkey1$, key2$, origkey2$, lastkey2$)
  216.  
  217.     IF status = 1 THEN
  218.         RETRIEVE CustTabNum, CustRec
  219.         IF LEFT$(CustRec.AcctNo, LEN(origkey2$)) <> origkey2$ OR UCASE$(LEFT$(CustRec.Company, LEN(origkey1$))) <> UCASE$(origkey1$) THEN
  220.             IF LEFT$(lastkey2$, LEN(origkey2$)) <> origkey2$ OR UCASE$(LEFT$(lastkey1$, LEN(origkey1$))) <> UCASE$(origkey1$) THEN
  221.                 PrintError "No records found matching search criteria."
  222.                 ClearCustRecord
  223.                 CustRec.AcctNo = key2$
  224.                 CustRec.Company = key1$
  225.                 origkey1$ = ""
  226.                 origkey2$ = ""
  227.                 ButtonOpen 1, ButtonInquire(1), "Find", 2, 58, 0, 0, 1
  228.                 status = 0
  229.                 RecCurrent = FALSE
  230.             ELSE
  231.                 key1$ = origkey1$
  232.                 key2$ = origkey2$
  233.                 status = NextRecord%(CustTabNum, key1$, origkey1$, lastkey1$, key2$, origkey2$, lastkey2$)
  234.                 RETRIEVE CustTabNum, CustRec
  235.             END IF
  236.         END IF
  237.         IF status = 1 THEN
  238.             ButtonOpen 1, ButtonInquire(1), "Next", 2, 58, 0, 0, 1
  239.             RecCurrent = TRUE
  240.             GOSUB InsertCustRec
  241.             GOSUB CheckInvoice
  242.         END IF
  243.     ELSEIF status = 2 THEN
  244.         PrintError "No records found matching search criteria."
  245.         ClearCustRecord
  246.         RecCurrent = FALSE
  247.         CustRec.AcctNo = key2$
  248.         CustRec.Company = key1$
  249.         origkey1$ = ""
  250.         origkey2$ = ""
  251.         ButtonOpen 1, ButtonInquire(1), "Find", 2, 58, 0, 0, 1
  252.     ELSEIF status = 3 THEN
  253.         PrintError "Customer database is empty."
  254.         RecCurrent = FALSE
  255.     END IF
  256.     GOSUB UpdateButtons
  257. RETURN
  258.  
  259. RetrieveCustEditFields:
  260.     CustRec.AcctNo = UCASE$(LTRIM$(EditFieldInquire$(1)))
  261.     IF LEN(RTRIM$(CustRec.AcctNo)) = 0 THEN
  262.         PrintError "Customer must have an account number."
  263.         ErrFlag = TRUE
  264.     END IF
  265.     CustRec.Company = LTRIM$(EditFieldInquire$(2))
  266.     IF LEN(RTRIM$(CustRec.Company)) = 0 THEN
  267.         PrintError "Customer must have a company name."
  268.         ErrFlag = TRUE
  269.     END IF
  270.     CustRec.Street = EditFieldInquire$(3)
  271.     CustRec.City = EditFieldInquire$(4)
  272.     CustRec.state = EditFieldInquire$(5)
  273.     CustRec.Zip = EditFieldInquire$(6)
  274.     CustRec.Phone1 = EditFieldInquire$(7)
  275.     CustRec.Phone2 = EditFieldInquire$(8)
  276.     CustRec.Contact = EditFieldInquire$(9)
  277. RETURN
  278.  
  279. InsertCustRec:
  280.     EditFieldOpen 1, RTRIM$(CustRec.AcctNo), 3, 13, 0, 7, 6, 5
  281.     EditFieldOpen 2, RTRIM$(CustRec.Company), 6, 13, 0, 7, 39, 70
  282.     lastkey2$ = EditFieldInquire$(1)
  283.     lastkey1$ = EditFieldInquire$(2)
  284.     EditFieldOpen 3, RTRIM$(CustRec.Street), 9, 13, 0, 7, 39, 70
  285.     EditFieldOpen 4, RTRIM$(CustRec.City), 12, 13, 0, 7, 17, 70
  286.     EditFieldOpen 5, RTRIM$(CustRec.state), 12, 36, 0, 7, 3, 2
  287.     EditFieldOpen 6, RTRIM$(CustRec.Zip), 12, 46, 0, 7, 6, 5
  288.     EditFieldOpen 7, RTRIM$(CustRec.Phone1), 15, 13, 0, 7, 15, 14
  289.     EditFieldOpen 8, RTRIM$(CustRec.Phone2), 15, 37, 0, 7, 15, 14
  290.     EditFieldOpen 9, RTRIM$(CustRec.Contact), 18, 13, 0, 7, 39, 70
  291.     WindowLocate 3, 45
  292.     WindowPrint -2, MID$(CustRec.Opened, 3, 2) + "-" + MID$(CustRec.Opened, 5, 2) + "-" + MID$(CustRec.Opened, 1, 2)
  293. RETURN
  294.  
  295. ClearCustEditFields:
  296.     EditFieldOpen 1, "", 3, 13, 0, 7, 6, 5
  297.     EditFieldOpen 2, "", 6, 13, 0, 7, 39, 70
  298.     EditFieldOpen 3, "", 9, 13, 0, 7, 39, 70
  299.     EditFieldOpen 4, "", 12, 13, 0, 7, 17, 70
  300.     EditFieldOpen 5, "", 12, 36, 0, 7, 3, 2
  301.     EditFieldOpen 6, "", 12, 46, 0, 7, 6, 5
  302.     EditFieldOpen 7, "", 15, 13, 0, 7, 15, 14
  303.     EditFieldOpen 8, "", 15, 37, 0, 7, 15, 14
  304.     EditFieldOpen 9, "", 18, 13, 0, 7, 39, 70
  305.     WindowLocate 3, 45
  306.     WindowPrint -2, "        "
  307.  
  308.     lastkey1$ = ""
  309.     lastkey2$ = ""
  310.     ClearCustRecord
  311.     RecCurrent = FALSE
  312.     IF level < 2 THEN ButtonOpen 1, 1, "Find", 2, 58, 0, 0, 1
  313.     GOSUB UpdateButtons
  314. RETURN
  315.  
  316. UpdateButtons:
  317.     IF NOT RecCurrent THEN
  318.         ButtonClose 3
  319.         ButtonClose 5
  320.         ButtonClose 6
  321.         ButtonClose 7
  322.         IF curBut = 5 THEN
  323.             curBut = 1
  324.             pushButton = 1
  325.             ButtonSetState 1, 2
  326.         END IF
  327.         WindowColor 8, 7
  328.         WindowLocate 6, 58
  329.         WindowPrint -2, "< Update >"
  330.         WindowLocate 8, 58
  331.         WindowPrint -2, "< Delete >"
  332.         WindowLocate 11, 58
  333.         WindowPrint -2, "< P.O. >"
  334.         WindowLocate 12, 58
  335.         WindowPrint -2, "< Invoices >"
  336.         WindowColor 0, 7
  337.         HasInvoices = FALSE
  338.     ELSE
  339.         ButtonOpen 3, 1, "Update", 6, 58, 0, 0, 1
  340.         ButtonOpen 5, 1, "Delete", 8, 58, 0, 0, 1
  341.         IF level = 1 THEN
  342.             WindowColor 8, 7
  343.             WindowLocate 11, 58
  344.             WindowPrint -2, "< P.O. >"
  345.             WindowColor 0, 7
  346.         ELSE
  347.             ButtonOpen 6, 1, "P.O.", 11, 58, 0, 0, 1
  348.         END IF
  349.         IF HasInvoice THEN
  350.             ButtonOpen 7, 1, "Invoices", 12, 58, 0, 0, 1
  351.         ELSE
  352.             ButtonClose 7
  353.             WindowColor 8, 7
  354.             WindowLocate 12, 58
  355.             WindowPrint -2, "< Invoices >"
  356.             WindowColor 0, 7
  357.         END IF
  358.     END IF
  359. RETURN
  360.  
  361. CheckInvoice:
  362.     HasInvoice = FALSE
  363.     SETINDEX InvoTabNum, "InvAcctIndex"
  364.     SEEKGE InvoTabNum, CustRec.AcctNo, "0", "0"
  365.     IF NOT EOF(InvoTabNum) THEN
  366.         RETRIEVE InvoTabNum, InvoiceRec
  367.         IF InvoiceRec.AcctNo = CustRec.AcctNo THEN HasInvoice = TRUE
  368.     END IF
  369.     ClearInvoRecord
  370. RETURN
  371.  
  372. ShowCustRec:
  373.     DispCustWin handle
  374.  
  375.     IF LEN(RTRIM$(CustRec.AcctNo)) = 0 AND LEN(RTRIM$(CustRec.Company)) = 0 THEN
  376.         GOSUB ClearCustEditFields
  377.     ELSE
  378.         GOSUB InsertCustRec
  379.         IF RTRIM$(CustRec.Company) = "" THEN
  380.             SETINDEX CustTabNum, "AcctIndex"
  381.             SEEKEQ CustTabNum, CustRec.AcctNo
  382.         ELSE
  383.             SETINDEX CustTabNum, "CompanyIndex"
  384.             SEEKEQ CustTabNum, CustRec.Company, CustRec.AcctNo
  385.         END IF
  386.         IF EOF(CustTabNum) THEN
  387.             IF level < 2 THEN ButtonOpen 1, 1, "Find", 2, 58, 0, 0, 1
  388.             lastkey1$ = ""
  389.             lastkey2$ = ""
  390.             RecCurrent = FALSE
  391.         ELSE
  392.             IF level < 2 THEN
  393.                 ButtonOpen 1, 1, "Next", 2, 58, 0, 0, 1
  394.                 RecCurrent = TRUE
  395.                 GOSUB CheckInvoice
  396.             END IF
  397.         END IF
  398.     END IF
  399.  
  400.     IF level > 1 THEN
  401.         ButtonOpen 1, 2, "Cancel", 16, 58, 0, 0, 1
  402.         WindowColor 8, 7
  403.         WindowLocate 2, 58
  404.         WindowPrint -2, "< Next >"
  405.         WindowLocate 5, 58
  406.         WindowPrint -2, "< New >"
  407.         WindowLocate 6, 58
  408.         WindowPrint -2, "< Update >"
  409.         WindowLocate 7, 58
  410.         WindowPrint -2, "< Add >"
  411.         WindowLocate 8, 58
  412.         WindowPrint -2, "< Delete >"
  413.         WindowLocate 11, 58
  414.         WindowPrint -2, "< P.O. >"
  415.         WindowLocate 12, 58
  416.         WindowPrint -2, "< Invoices >"
  417.         WindowLocate 15, 58
  418.         WindowPrint -2, "< Commit >"
  419.         WindowColor 0, 7
  420.         curBut = 1
  421.         currEditField = 0
  422.         pushButton = 1
  423.     ELSE
  424.         GOSUB UpdateButtons
  425.         ButtonOpen 2, 1, "New", 5, 58, 0, 0, 1
  426.         ButtonOpen 4, 1, "Add", 7, 58, 0, 0, 1
  427.         ButtonOpen 8, 1, "Commit", 15, 58, 0, 0, 1
  428.         ButtonOpen 9, 1, "Cancel", 16, 58, 0, 0, 1
  429.         curBut = 0
  430.         currEditField = 1
  431.         pushButton = 1
  432.         ButtonSetState 1, 2
  433.     END IF
  434. RETURN
  435.  
  436. END SUB
  437.  
  438. ' RunInventRec
  439. ' Controls inventory record form.  Provides viewing, updating, adding and
  440. ' deleting of inventory items.
  441. '
  442. ' Handle - window handle
  443. '
  444. SUB RunInventRec (handle)
  445.     ON LOCAL ERROR GOTO InventErr
  446.  
  447.     IF ISAMfile$ = "" THEN                          'database must be open
  448.         PrintError "A database file must be opened before records can be viewed."
  449.         EXIT SUB
  450.     END IF
  451.  
  452.     savePosition = SAVEPOINT                        ' database savepoint
  453.     ErrFlag = FALSE
  454.  
  455.     GOSUB ShowInventRec                             'display form
  456.  
  457.     ' window control loop
  458.     finished = FALSE
  459.     WHILE finished = FALSE
  460.         WindowDo curBut, currEditField                ' wait for event
  461.         SELECT CASE Dialog(0)
  462.             CASE 1                                      ' button pressed
  463.                 currEditField = 0
  464.                 curBut = Dialog(1)
  465.                 ButtonSetState pushButton, 1
  466.                 ButtonSetState curBut, 2
  467.                 pushButton = curBut
  468.                 GOSUB InventRecButton
  469.             CASE 2                                      ' edit field
  470.                 IF level <> 3 THEN
  471.                     curBut = 0
  472.                     currEditField = Dialog(2)
  473.                 END IF
  474.             CASE 6                                      ' enter
  475.                 curBut = pushButton
  476.                 GOSUB InventRecButton
  477.             CASE 7, 11                                  ' tab, down arrow
  478.                 IF level <> 3 THEN
  479.                 SELECT CASE curBut
  480.                     CASE 0
  481.                         SELECT CASE currEditField
  482.                             CASE IS < 6
  483.                                 currEditField = currEditField + 1
  484.                             CASE 6
  485.                                 currEditField = 0
  486.                                 curBut = 1
  487.                         END SELECT
  488.                     CASE 2
  489.                         curBut = 4 + RecCurrent
  490.                     CASE 4
  491.                         curBut = 6 + RecCurrent
  492.                     CASE 7
  493.                         currEditField = 1
  494.                         curBut = 0
  495.                         ButtonSetState pushButton, 1
  496.                         pushButton = 1
  497.                         ButtonSetState 1, 2
  498.                     CASE ELSE
  499.                         curBut = curBut + 1
  500.                 END SELECT
  501.                 IF curBut <> 0 THEN
  502.                     ButtonSetState pushButton, 1
  503.                     ButtonSetState curBut, 2
  504.                     pushButton = curBut
  505.                 END IF
  506.                 END IF
  507.             CASE 8, 10                                  ' back tab, up arrow
  508.                 IF level <> 3 THEN
  509.                 SELECT CASE curBut
  510.                     CASE 0
  511.                         SELECT CASE currEditField
  512.                             CASE 1
  513.                                 currEditField = 0
  514.                                 curBut = 7
  515.                             CASE ELSE
  516.                                 currEditField = currEditField - 1
  517.                         END SELECT
  518.                     CASE 1
  519.                         currEditField = 6
  520.                         curBut = 0
  521.                     CASE 4
  522.                         curBut = 2 - RecCurrent
  523.                     CASE 6
  524.                         curBut = 4 - RecCurrent
  525.                     CASE ELSE
  526.                         curBut = curBut - 1
  527.                 END SELECT
  528.                 IF curBut <> 0 THEN
  529.                     ButtonSetState pushButton, 1
  530.                     ButtonSetState curBut, 2
  531.                     pushButton = curBut
  532.                 END IF
  533.                 END IF
  534.             CASE 9                                      ' escape
  535.                 finished = CANCEL
  536.             CASE 14                                     ' space bar
  537.                 IF curBut > 0 THEN GOSUB InventRecButton
  538.          END SELECT
  539.     WEND
  540.  
  541.     IF finished = OK THEN
  542.         CHECKPOINT
  543.     ELSE
  544.         ROLLBACK savePosition
  545.     END IF
  546.  
  547.     WindowClose handle
  548.  
  549.     EXIT SUB
  550.  
  551. InventErr:
  552.     SELECT CASE ERR                                 'must open databas file
  553.         CASE 52
  554.             PrintError "A database file must be opened before inventory records can be displayed."
  555.             EXIT SUB
  556.         CASE ELSE
  557.             ShowError ERR
  558.             IF ERR = 86 THEN                            'can't add duplicate records
  559.                 RESUME InventErrReturn
  560.             ELSEIF ERR = 89 THEN                        'not enough ISAM buffers to continue
  561.                 WindowClose handle
  562.                 ROLLBACK savePosition
  563.                 EXIT SUB
  564.             END IF
  565.     END SELECT
  566. RESUME NEXT
  567.                                                                                                     'process button push
  568. InventRecButton:
  569.     IF level = 3 THEN
  570.         finished = CANCEL
  571.     ELSE
  572.     SELECT CASE curBut
  573.         CASE 1                                        'get next record
  574.             GOSUB RetrieveInventRecord
  575.         CASE 2                                        'clear form for new record
  576.             GOSUB ClearInventEditFields
  577.         CASE 3                                        'update current record
  578.             GOSUB RetrieveInventEditFields
  579.             IF NOT ErrFlag THEN
  580.                 UPDATE InveTabNum, InventRec
  581.             ELSE
  582.                 ErrFlag = FALSE
  583.             END IF
  584.         CASE 4                                        'add new record
  585.             GOSUB RetrieveInventEditFields
  586.             IF NOT ErrFlag THEN
  587.                 INSERT InveTabNum, InventRec
  588.                 GOSUB ClearInventEditFields
  589.             ELSE
  590.                 ErrFlag = FALSE
  591.             END IF
  592.         CASE 5                                        'delete a record
  593.             DELETE InveTabNum
  594.             GOSUB ClearInventEditFields
  595.         CASE 6                                        'done
  596.             finished = OK
  597.         CASE 7
  598.             finished = CANCEL
  599.     END SELECT
  600.     END IF
  601. InventErrReturn:
  602. RETURN
  603.  
  604. RetrieveInventRecord:                             'get inventory record
  605.     key$ = UCASE$(LTRIM$(EditFieldInquire$(1)))
  606.     status = NextRecord%(InveTabNum, key$, origkey$, lastkey$, "", "", "")
  607.  
  608.     IF status = 1 THEN
  609.         RETRIEVE InveTabNum, InventRec
  610.         IF LEFT$(InventRec.ItemNo, LEN(origkey$)) <> origkey$ THEN
  611.             IF LEFT$(lastkey$, LEN(origkey$)) <> origkey$ THEN
  612.                 PrintError "No records found matching search criteria."
  613.                 ClearInveRecord
  614.                 InventRec.ItemNo = key$
  615.                 origkey$ = ""
  616.                 ButtonOpen 1, ButtonInquire(1), "Find", 2, 61, 0, 0, 1
  617.                 status = 0
  618.                 RecCurrent = FALSE
  619.             ELSE
  620.                 key$ = origkey$
  621.                 status = NextRecord%(InveTabNum, key$, origkey$, lastkey$, "", "", "")
  622.                 RETRIEVE InveTabNum, InventRec
  623.             END IF
  624.         END IF
  625.         IF status = 1 THEN
  626.             ButtonOpen 1, ButtonInquire(1), "Next", 2, 61, 0, 0, 1
  627.             RecCurrent = TRUE
  628.             GOSUB InsertInventRec
  629.         END IF
  630.     ELSEIF status = 2 THEN
  631.         PrintError "No records found matching search criteria."
  632.         ClearInveRecord
  633.         RecCurrent = FALSE
  634.         InventRec.ItemNo = key$
  635.         origkey$ = ""
  636.         ButtonOpen 1, ButtonInquire(1), "Find", 2, 61, 0, 0, 1
  637.     ELSEIF status = 3 THEN
  638.         PrintError "Inventory database is empty."
  639.         RecCurrent = FALSE
  640.     END IF
  641.     GOSUB UpdateRecButtons
  642. RETURN
  643.  
  644. RetrieveInventEditFields:                         'get current edit field values
  645.     InventRec.ItemNo = UCASE$(LTRIM$(EditFieldInquire$(1)))
  646.     IF LEN(RTRIM$(InventRec.ItemNo)) = 0 THEN
  647.         PrintError "Item must have an identification number."
  648.         ErrFlag = TRUE
  649.     END IF
  650.     InventRec.Descrip = EditFieldInquire$(2)
  651.     InventRec.Cost = VAL(EditFieldInquire$(3))
  652.     IF InventRec.Cost = 0 AND LTRIM$(EditFieldInquire$(3)) <> "0.00" THEN
  653.         PrintError "Unit cost must be a monetary amount."
  654.         ErrFlag = TRUE
  655.     END IF
  656.     InventRec.Retail = VAL(EditFieldInquire$(4))
  657.     IF InventRec.Retail = 0 AND LTRIM$(EditFieldInquire$(4)) <> "0.00" THEN
  658.         PrintError "Retail price must be a monetary amount."
  659.         ErrFlag = TRUE
  660.     END IF
  661.     InventRec.stock = VAL(EditFieldInquire$(5))
  662.     IF InventRec.stock = 0 AND LTRIM$(EditFieldInquire$(5)) <> "0" THEN
  663.         PrintError "Current stock must be a numeric value."
  664.         ErrFlag = TRUE
  665.     END IF
  666.     InventRec.Vendor = EditFieldInquire$(6)
  667. RETURN
  668.  
  669. InsertInventRec:                                  'insert record into database
  670.     EditFieldOpen 1, RTRIM$(InventRec.ItemNo), 3, 13, 0, 7, 6, 5
  671.     lastkey$ = LTRIM$(EditFieldInquire$(1))
  672.     EditFieldOpen 2, RTRIM$(InventRec.Descrip), 6, 13, 0, 7, 42, 70
  673.     EditFieldOpen 3, FormatS$(InventRec.Cost, "0.00"), 9, 13, 0, 7, 11, 10
  674.     EditFieldOpen 4, FormatS$(InventRec.Retail, "0.00"), 9, 44, 0, 7, 11, 10
  675.     EditFieldOpen 5, LTRIM$(STR$(InventRec.stock)), 12, 13, 0, 7, 8, 7
  676.     EditFieldOpen 6, RTRIM$(InventRec.Vendor), 15, 13, 0, 7, 42, 70
  677. RETURN
  678.  
  679. ClearInventEditFields:                            'clear edit fields
  680.     EditFieldOpen 1, "", 3, 13, 0, 7, 6, 5
  681.     EditFieldOpen 2, "", 6, 13, 0, 7, 42, 70
  682.     EditFieldOpen 3, "", 9, 13, 0, 7, 11, 10
  683.     EditFieldOpen 4, "", 9, 44, 0, 7, 11, 10
  684.     EditFieldOpen 5, "", 12, 13, 0, 7, 8, 7
  685.     EditFieldOpen 6, "", 15, 13, 0, 7, 42, 70
  686.  
  687.     lastkey$ = ""
  688.     ClearInveRecord
  689.     RecCurrent = FALSE
  690.     IF level <> 3 THEN ButtonOpen 1, 1, "Find", 2, 61, 0, 0, 1
  691.     GOSUB UpdateRecButtons
  692. RETURN
  693.  
  694. UpdateRecButtons:                                 'set button states
  695.     IF NOT RecCurrent THEN
  696.         ButtonClose 3
  697.         ButtonClose 5
  698.         IF curBut = 5 THEN
  699.             curBut = 1
  700.             pushButton = 1
  701.             ButtonSetState 1, 2
  702.         END IF
  703.         WindowColor 8, 7
  704.         WindowLocate 6, 61
  705.         WindowPrint -2, "< Update >"
  706.         WindowLocate 8, 61
  707.         WindowPrint -2, "< Delete >"
  708.         WindowColor 0, 7
  709.     ELSE
  710.         ButtonOpen 3, 1, "Update", 6, 61, 0, 0, 1
  711.         ButtonOpen 5, 1, "Delete", 8, 61, 0, 0, 1
  712.     END IF
  713. RETURN
  714.                                                                                                  
  715. ShowInventRec:                                    'display form
  716.     DispInveWin handle
  717.  
  718.     IF LEN(RTRIM$(InventRec.ItemNo)) = 0 THEN
  719.         GOSUB ClearInventEditFields
  720.     ELSE
  721.         GOSUB InsertInventRec
  722.         SETINDEX InveTabNum, "ItemIndex"
  723.         SEEKEQ InveTabNum, InventRec.ItemNo
  724.         IF EOF(InveTabNum) THEN
  725.             GOSUB ClearInventEditFields
  726.             EditFieldOpen 1, RTRIM$(UCASE$(InventRec.ItemNo)), 3, 13, 0, 7, 6, 5
  727.             IF level <> 3 THEN ButtonOpen 1, 1, "Find", 2, 61, 0, 0, 1
  728.             lastkey$ = ""
  729.             RecCurrent = FALSE
  730.         ELSE
  731.             IF level <> 3 THEN ButtonOpen 1, 1, "Next", 2, 61, 0, 0, 1
  732.             RecCurrent = TRUE
  733.         END IF
  734.     END IF
  735.  
  736.     IF level = 3 THEN
  737.         curBut = 1
  738.         currEditField = 0
  739.         pushButton = 1
  740.         ButtonOpen 1, 1, "Cancel", 12, 61, 0, 0, 1
  741.         WindowColor 8, 7
  742.         WindowLocate 2, 61
  743.         WindowPrint -2, "< Next >"
  744.         WindowLocate 5, 61
  745.         WindowPrint -2, "< New >"
  746.         WindowLocate 6, 61
  747.         WindowPrint -2, "< Update >"
  748.         WindowLocate 7, 61
  749.         WindowPrint -2, "< Add >"
  750.         WindowLocate 8, 61
  751.         WindowPrint -2, "< Delete >"
  752.         WindowLocate 11, 61
  753.         WindowPrint -2, "< Commit >"
  754.         WindowColor 0, 7
  755.     ELSE
  756.         curBut = 0
  757.         currEditField = 1
  758.         pushButton = 1
  759.         GOSUB UpdateRecButtons
  760.         ButtonOpen 2, 1, "New", 5, 61, 0, 0, 1
  761.         ButtonOpen 4, 1, "Add", 7, 61, 0, 0, 1
  762.         ButtonOpen 6, 1, "Commit", 11, 61, 0, 0, 1
  763.         ButtonOpen 7, 1, "Cancel", 12, 61, 0, 0, 1
  764.     END IF
  765.     ButtonSetState pushButton, 2
  766. RETURN
  767.  
  768.  
  769. END SUB
  770.  
  771. ' RunInvoiceRec
  772. ' Controls purchase order form.  Allows purchase order to be made.
  773. '
  774. ' Handle - window handle
  775. '
  776. SUB RunInvoice (handle)
  777. DIM transBox AS ListBox, transList$(1 TO 4)
  778.  
  779.     ON LOCAL ERROR GOTO InvoiceErr
  780.  
  781.     IF ISAMfile$ = "" THEN                          'must have open ISAM file
  782.         PrintError "A database file must be opened before purchase order can be made."
  783.         EXIT SUB
  784.     END IF
  785.  
  786.     savePosition = SAVEPOINT
  787.     SETINDEX TranTabNum, "TransInvIndex"
  788.     SETINDEX InveTabNum, "ItemIndex"
  789.  
  790.     GOSUB ShowInvoice
  791.  
  792.     ' window control loop
  793.     finished = FALSE
  794.     WHILE finished = FALSE
  795.         WindowDo curBut, currEditField                ' wait for event
  796.         SELECT CASE Dialog(0)
  797.             CASE 1                                      ' button pressed
  798.                 currEditField = 0
  799.                 curBut = Dialog(1)
  800.                 SELECT CASE curBut
  801.                     CASE 1, 2
  802.                         func = curBut
  803.                     CASE ELSE
  804.                         ButtonSetState pushButton, 1
  805.                         ButtonSetState curBut, 2
  806.                         pushButton = curBut
  807.                 END SELECT
  808.                 GOSUB InvoiceButton
  809.             CASE 2                                      ' edit field
  810.                 IF level < 3 THEN
  811.                     curBut = 0
  812.                     currEditField = Dialog(2)
  813.                 END IF
  814.             CASE 6                                      ' enter
  815.                 curBut = pushButton
  816.                 GOSUB InvoiceButton
  817.             CASE 7                                      ' tab
  818.                 SELECT CASE curBut
  819.                     CASE 0
  820.                         SELECT CASE currEditField
  821.                             CASE 5
  822.                                 currEditField = 0
  823.                                 curBut = 2
  824.                             CASE 6
  825.                                 currEditField = 0
  826.                                 IF level = 3 THEN
  827.                                     curBut = 5
  828.                                 ELSE
  829.                                     curBut = 3
  830.                                 END IF
  831.                                 ButtonSetState pushButton, 1
  832.                                 pushButton = curBut
  833.                                 ButtonSetState pushButton, 2
  834.                             CASE ELSE
  835.                                 currEditField = currEditField + 1
  836.                         END SELECT
  837.                     CASE 1, 2
  838.                         IF level = 3 THEN
  839.                             curBut = 5
  840.                             ButtonSetState pushButton, 1
  841.                             pushButton = curBut
  842.                             ButtonSetState curBut, 2
  843.                         ELSE
  844.                             curBut = 0
  845.                             currEditField = 6
  846.                         END IF
  847.                     CASE 9
  848.                         ButtonSetState pushButton, 1
  849.                         IF level = 3 THEN
  850.                             curBut = 2
  851.                             pushButton = 5
  852.                         ELSE
  853.                             currEditField = 1
  854.                             curBut = 0
  855.                             pushButton = 1
  856.                         END IF
  857.                         ButtonSetState pushButton, 2
  858.                     CASE 6
  859.                         IF level = 3 OR numTrans = 0 THEN
  860.                             curBut = 9
  861.                         ELSE
  862.                             curBut = 7
  863.                         END IF
  864.                         ButtonSetState pushButton, 1
  865.                         pushButton = curBut
  866.                         ButtonSetState pushButton, 2
  867.                     CASE ELSE
  868.                         curBut = curBut + 1
  869.                         ButtonSetState pushButton, 1
  870.                         pushButton = curBut
  871.                         ButtonSetState pushButton, 2
  872.                 END SELECT
  873.             CASE 8                                      ' back tab
  874.                 SELECT CASE curBut
  875.                     CASE 0
  876.                         SELECT CASE currEditField
  877.                             CASE 1
  878.                                 currEditField = 0
  879.                                 ButtonSetState pushButton, 1
  880.                                 curBut = 9
  881.                                 pushButton = curBut
  882.                                 ButtonSetState pushButton, 2
  883.                             CASE 6
  884.                                 currEditField = 0
  885.                                 curBut = 2
  886.                             CASE ELSE
  887.                                 currEditField = currEditField - 1
  888.                         END SELECT
  889.                     CASE 1, 2
  890.                         IF level = 3 THEN
  891.                             curBut = 9
  892.                             ButtonSetState pushButton, 1
  893.                             ButtonSetState 9, 2
  894.                             pushButton = curBut
  895.                         ELSE
  896.                             currEditField = 5
  897.                             curBut = 0
  898.                         END IF
  899.                     CASE 3
  900.                         currEditField = 6
  901.                         curBut = 0
  902.                     CASE 5
  903.                         IF level = 3 THEN
  904.                             curBut = 2
  905.                         ELSE
  906.                             ButtonSetState 5, 1
  907.                             curBut = 4
  908.                             pushButton = curBut
  909.                             ButtonSetState 4, 2
  910.                         END IF
  911.                     CASE 9
  912.                         IF level = 3 OR numTrans = 0 THEN
  913.                             curBut = 6
  914.                         ELSE
  915.                             curBut = 8
  916.                         END IF
  917.                         ButtonSetState pushButton, 1
  918.                         pushButton = curBut
  919.                         ButtonSetState pushButton, 2
  920.                     CASE ELSE
  921.                         ButtonSetState pushButton, 1
  922.                         curBut = curBut - 1
  923.                         pushButton = curBut
  924.                         ButtonSetState pushButton, 2
  925.                 END SELECT
  926.             CASE 9                                      ' escape
  927.                 finished = CANCEL
  928.             CASE 10, 12                                 ' up, left arrow
  929.                 temp = curBut
  930.                 curBut = 2
  931.                 func = 3
  932.                 GOSUB InvoiceButton
  933.                 curBut = temp
  934.             CASE 11, 13                                 'down, right arrow
  935.                 temp = curBut
  936.                 curBut = 2
  937.                 func = 4
  938.                 GOSUB InvoiceButton
  939.                 curBut = temp
  940.             CASE 14                                     ' space bar
  941.                 IF curBut > 2 THEN GOSUB InvoiceButton
  942.          END SELECT
  943.     WEND
  944.  
  945.     IF finished = OK THEN
  946.         CHECKPOINT
  947.     ELSE
  948.         ROLLBACK savePosition
  949.     END IF
  950.     GetNextInvoice
  951.  
  952.     WindowClose handle
  953.  
  954.     EXIT SUB
  955.  
  956. InvoiceErr:
  957.     SELECT CASE ERR
  958.         CASE 52                                     'no database open
  959.             PrintError "A database file must be opened before transactions can be made."
  960.             EXIT SUB
  961.         CASE ELSE
  962.             ShowError ERR                             'display general error message
  963.             IF ERR = 89 THEN                          'not enough ISAM buffers to continue
  964.                 WindowClose handle
  965.                 ROLLBACK savePosition
  966.                 EXIT SUB
  967.             END IF
  968.     END SELECT
  969. RESUME NEXT
  970.  
  971. InvoiceButton:                                    'process button selection
  972.     SELECT CASE curBut
  973.         CASE 1, 2                                     'scroll transaction list
  974.             ScrollList transList$(), transBox, func, 1, topRow, lefCol
  975.  
  976.             currNo = transBox.listPos
  977.             IF level <> 3 THEN
  978.                 state = ButtonInquire(3)
  979.                 IF currNo > numTrans THEN
  980.                     ButtonOpen 3, state, "Add", 2, 61, 0, 0, 1
  981.                 ELSE
  982.                     ButtonOpen 3, state, "Update", 2, 61, 0, 0, 1
  983.                 END IF
  984.             END IF
  985.             GOSUB InsertTransaction
  986.             curBut = 2
  987.         CASE 3                                        'add a transaction
  988.             GOSUB AddTransaction
  989.         CASE 4                                        'void a transaction
  990.             GOSUB VoidTransaction
  991.         CASE 5                                        'get a customer name
  992.             ckey1$ = UCASE$(LTRIM$(EditFieldInquire$(1)))
  993.             ckey2$ = LTRIM$(EditFieldInquire$(2))
  994.             IF (ckey1$ = clastKey1$ AND ckey2$ = clastKey2$) OR (ckey1$ = "" AND ckey2$ = "") THEN
  995.                 IF ckey1$ = "" THEN CustRec.AcctNo = ""
  996.                 IF ckey2$ = "" THEN CustRec.Company = ""
  997.                 RunCustRec WindowNext
  998.                 EditFieldOpen 1, RTRIM$(CustRec.AcctNo), 3, 13, 0, 7, 6, 5
  999.                 EditFieldOpen 2, RTRIM$(CustRec.Company), 6, 13, 0, 7, 41, 70
  1000.                 clastKey1$ = EditFieldInquire$(1)
  1001.                 clastKey2$ = EditFieldInquire$(2)
  1002.             ELSE
  1003.                 status = NextRecord%(CustTabNum, ckey1$, corigKey1$, clastKey1$, ckey2$, corigKey2$, clastKey2$)
  1004.                 IF status = 1 THEN
  1005.                     RETRIEVE CustTabNum, CustRec
  1006.                     IF LEFT$(CustRec.AcctNo, LEN(corigKey1$)) <> corigKey1$ OR UCASE$(LEFT$(CustRec.Company, LEN(corigKey2$))) <> UCASE$(corigKey2$) THEN
  1007.                         PrintError "No records found matching search criteria."
  1008.                         ClearCustRecord
  1009.                         CustRec.AcctNo = ckey1$
  1010.                         clastKey1$ = ckey1$
  1011.                         CustRec.Company = ckey2$
  1012.                         clastKey2$ = ckey2$
  1013.                     ELSE
  1014.                         EditFieldOpen 1, RTRIM$(CustRec.AcctNo), 3, 13, 0, 7, 6, 5
  1015.                         EditFieldOpen 2, RTRIM$(CustRec.Company), 6, 13, 0, 7, 41, 70
  1016.                         clastKey1$ = UCASE$(LTRIM$(EditFieldInquire$(1)))
  1017.                         clastKey2$ = EditFieldInquire$(2)
  1018.                     END IF
  1019.                 ELSEIF status = 2 THEN
  1020.                     PrintError "No records found matching search criteria."
  1021.                     ClearCustRecord
  1022.                     CustRec.AcctNo = ckey1$
  1023.                     clastKey1$ = ckey1$
  1024.                     CustRec.Company = ckey2$
  1025.                     clastKey2$ = ckey2$
  1026.                 ELSEIF status = 3 THEN
  1027.                     PrintError "Customer database is empty."
  1028.                 END IF
  1029.             END IF
  1030.         CASE 6                                        'get an item number
  1031.             ikey$ = UCASE$(LTRIM$(EditFieldInquire$(3)))
  1032.             IF ikey$ <> ilastKey$ AND ikey$ <> "" THEN
  1033.                 status = NextRecord%(InveTabNum, ikey$, iorigKey$, ilastKey$, "", "", "")
  1034.                 IF status = 1 THEN
  1035.                     RETRIEVE InveTabNum, InventRec
  1036.                     IF LEFT$(InventRec.ItemNo, LEN(iorigKey$)) <> iorigKey$ THEN
  1037.                         PrintError "No records found matching search criteria."
  1038.                         ClearInveRecord
  1039.                         InventRec.ItemNo = ikey$
  1040.                         ilastKey$ = ikey$
  1041.                     ELSE
  1042.                         EditFieldOpen 3, RTRIM$(InventRec.ItemNo), 9, 13, 0, 7, 6, 5
  1043.                         ilastKey$ = LTRIM$(EditFieldInquire$(3))
  1044.                         EditFieldOpen 4, FormatS$(InventRec.Retail, "0.00"), 9, 29, 0, 7, 11, 10
  1045.                     END IF
  1046.                 ELSEIF status = 2 THEN
  1047.                     PrintError "No records found matching search criteria."
  1048.                     ClearInveRecord
  1049.                     InventRec.ItemNo = ikey$
  1050.                     ilastKey$ = ikey$
  1051.                 ELSEIF status = 3 THEN
  1052.                     PrintError "Inventory database is empty."
  1053.                 END IF
  1054.             ELSE
  1055.                 IF ikey$ = "" THEN InventRec.ItemNo = ""
  1056.                 RunInventRec WindowNext
  1057.                 EditFieldOpen 3, RTRIM$(InventRec.ItemNo), 9, 13, 0, 7, 6, 5
  1058.                 ilastKey$ = UCASE$(LTRIM$(EditFieldInquire$(3)))
  1059.                 IF ilastKey$ = "" THEN
  1060.                     EditFieldOpen 4, "", 9, 29, 0, 7, 11, 10
  1061.                 ELSE
  1062.                     EditFieldOpen 4, FormatS$(InventRec.Retail, "0.00"), 9, 29, 0, 7, 11, 10
  1063.                 END IF
  1064.             END IF
  1065.         CASE 7                                        'total the invoice
  1066.             junk = TotalInvoice
  1067.         CASE 8                                        'commit invoice
  1068.             InvoiceRec.AcctNo = UCASE$(EditFieldInquire$(1))
  1069.             IF LEN(RTRIM$(InvoiceRec.AcctNo)) = 0 THEN
  1070.                 PrintError "Must specify account number before invoice can be committed."
  1071.             ELSE
  1072.                 SETINDEX CustTabNum, "AcctIndex"
  1073.                 SEEKEQ CustTabNum, InvoiceRec.AcctNo
  1074.                 IF EOF(CustTabNum) THEN
  1075.                     PrintError "Customer does not exist in customer database."
  1076.                 ELSE
  1077.                     InvoiceRec.Date = MID$(DATE$, 9, 2) + MID$(DATE$, 1, 2) + MID$(DATE$, 4, 2)
  1078.                     finished = TotalInvoice
  1079.                 END IF
  1080.             END IF
  1081.         CASE 9                                        'cancel operation
  1082.             finished = CANCEL
  1083.     END SELECT
  1084. RETURN
  1085.  
  1086. AddTransaction:
  1087.     IF currNo <= numTrans THEN
  1088.         SEEKEQ TranTabNum, InvoiceRec.InvoiceNo, currNo
  1089.         RETRIEVE TranTabNum, TransRec
  1090.         origitem$ = TransRec.ItemNo
  1091.         origqty = TransRec.Quantity
  1092.         UpdateInventory origitem$, -(origqty)
  1093.     ELSE
  1094.         origitem$ = ""
  1095.     END IF
  1096.  
  1097.     TransRec.TransNo = currNo
  1098.     TransRec.InvoiceNo = InvoiceRec.InvoiceNo
  1099.  
  1100.     tItemNo$ = UCASE$(LTRIM$(EditFieldInquire$(3)))
  1101.     IF tItemNo$ = "" THEN
  1102.         PrintError "Must specify item number before transaction can be added."
  1103.         RETURN
  1104.     ELSE
  1105.         SEEKEQ InveTabNum, tItemNo$
  1106.         IF NOT EOF(InveTabNum) THEN
  1107.             TransRec.ItemNo = tItemNo$
  1108.         ELSE
  1109.             PrintError "Item not found in inventory database."
  1110.             RETURN
  1111.         END IF
  1112.     END IF
  1113.  
  1114.     tRetailPrice$ = LTRIM$(EditFieldInquire$(4))
  1115.     IF tRetailPrice$ = "" THEN
  1116.         RETRIEVE InveTabNum, InventRec
  1117.         TransRec.Price = InventRec.Retail
  1118.     ELSE
  1119.         TransRec.Price = VAL(tRetailPrice$)
  1120.         IF TransRec.Price = 0 AND tRetailPrice$ <> "0" THEN
  1121.             PrintError "Retail price must be a monetary amount."
  1122.             RETURN
  1123.         END IF
  1124.     END IF
  1125.  
  1126.     tQuantity$ = LTRIM$(EditFieldInquire$(5))
  1127.     IF tQuantity$ = "" THEN
  1128.         qty = 1
  1129.     ELSE
  1130.         qty = VAL(tQuantity$)
  1131.         IF qty = 0 AND tQuantity$ <> "0" THEN
  1132.             PrintError "Quantity must be a numeric value."
  1133.             RETURN
  1134.         ELSEIF qty = 0 THEN
  1135.             PrintError "Quantity cannot equal zero."
  1136.             RETURN
  1137.         END IF
  1138.     END IF
  1139.  
  1140.     UpdateInventory TransRec.ItemNo, qty
  1141.     IF qty <> 0 THEN
  1142.         TransRec.Quantity = qty
  1143.         IF currNo <= numTrans THEN
  1144.             UPDATE TranTabNum, TransRec
  1145.         ELSE
  1146.             INSERT TranTabNum, TransRec
  1147.             currNo = currNo + 1
  1148.             numTrans = numTrans + 1
  1149.             GOSUB UpdateInvButtons
  1150.             GOSUB ClearInvoiceEditFields
  1151.         END IF
  1152.  
  1153.         transBox.listLen = numTrans + 1
  1154.         transBox.listPos = currNo
  1155.         CreateListBox transList$(), transBox, 1
  1156.     ELSEIF currNo <= numTrans AND TransRec.ItemNo = origitem$ THEN
  1157.         UpdateInventory origitem$, origqty
  1158.     END IF
  1159. RETURN
  1160.  
  1161. InsertTransaction:
  1162.     SEEKEQ TranTabNum, InvoiceRec.InvoiceNo, currNo
  1163.     IF EOF(TranTabNum) THEN
  1164.         GOSUB ClearInvoiceEditFields
  1165.         InventRec.ItemNo = ""
  1166.     ELSE
  1167.         RETRIEVE TranTabNum, TransRec
  1168.         EditFieldOpen 3, RTRIM$(TransRec.ItemNo), 9, 13, 0, 7, 6, 5
  1169.         EditFieldOpen 4, FormatS$(TransRec.Price, "0.00"), 9, 29, 0, 7, 11, 10
  1170.         EditFieldOpen 5, LTRIM$(STR$(TransRec.Quantity)), 9, 48, 0, 7, 7, 6
  1171.         SEEKEQ InveTabNum, TransRec.ItemNo
  1172.         RETRIEVE InveTabNum, InventRec
  1173.     END IF
  1174.     ilastKey$ = UCASE$(LTRIM$(EditFieldInquire$(3)))
  1175. RETURN
  1176.  
  1177. VoidTransaction:
  1178.     SEEKEQ TranTabNum, InvoiceRec.InvoiceNo, currNo
  1179.     IF NOT EOF(TranTabNum) THEN
  1180.         RETRIEVE TranTabNum, TransRec
  1181.         UpdateInventory TransRec.ItemNo, -(TransRec.Quantity)
  1182.         DELETE TranTabNum
  1183.  
  1184.         FOR i = currNo + 1 TO numTrans
  1185.             RETRIEVE TranTabNum, TransRec
  1186.             TransRec.TransNo = TransRec.TransNo - 1
  1187.             UPDATE TranTabNum, TransRec
  1188.             MOVENEXT TranTabNum
  1189.         NEXT i
  1190.         numTrans = numTrans - 1
  1191.         state = ButtonInquire(3)
  1192.         IF currNo > numTrans THEN
  1193.             ButtonOpen 3, state, "Add", 2, 61, 0, 0, 1
  1194.         ELSE
  1195.             ButtonOpen 3, state, "Update", 2, 61, 0, 0, 1
  1196.         END IF
  1197.         GOSUB InsertTransaction
  1198.  
  1199.         transBox.listLen = numTrans + 1
  1200.         transBox.listPos = currNo
  1201.         CreateListBox transList$(), transBox, 1
  1202.     ELSE
  1203.         GOSUB ClearInvoiceEditFields
  1204.     END IF
  1205.     GOSUB UpdateInvButtons
  1206. RETURN
  1207.  
  1208. ClearInvoiceEditFields:
  1209.     EditFieldOpen 3, "", 9, 13, 0, 7, 6, 5
  1210.     EditFieldOpen 4, "", 9, 29, 0, 7, 11, 10
  1211.     EditFieldOpen 5, "1", 9, 48, 0, 7, 7, 6
  1212. RETURN
  1213.  
  1214. UpdateInvButtons:
  1215.     IF numTrans > 0 THEN
  1216.         ButtonOpen 7, 1, "Total", 10, 61, 0, 0, 1
  1217.         ButtonOpen 8, 1, "Commit", 12, 61, 0, 0, 1
  1218.     ELSE
  1219.         ButtonClose 7
  1220.         ButtonClose 8
  1221.         WindowColor 8, 7
  1222.         WindowLocate 10, 61
  1223.         WindowPrint -2, "< Total >"
  1224.         WindowLocate 12, 61
  1225.         WindowPrint -2, "< Commit >"
  1226.         WindowColor 0, 7
  1227.     END IF
  1228. RETURN
  1229.  
  1230. ShowInvoice:
  1231.     DispInvoWin handle
  1232.     topRow = 4
  1233.     lefCol = 3
  1234.     transBox.sBut = 1
  1235.     transBox.aBut = 2
  1236.     transBox.topRow = 12
  1237.     transBox.bLen = 4
  1238.     transBox.leftCol = 4
  1239.     transBox.bWid = 50
  1240.     transBox.listPos = 1
  1241.      
  1242.     IF LEN(RTRIM$(InvoiceRec.AcctNo)) = 0 THEN
  1243.         SEEKEQ TranTabNum, InvoiceRec.InvoiceNo, 1
  1244.         DO WHILE NOT EOF(TranTabNum)
  1245.             RETRIEVE TranTabNum, TransRec
  1246.             IF TransRec.InvoiceNo = InvoiceRec.InvoiceNo THEN
  1247.                 DELETE TranTabNum
  1248.             ELSE
  1249.                 EXIT DO
  1250.             END IF
  1251.         LOOP
  1252.         transBox.listLen = 1
  1253.         WindowLocate 1, 16
  1254.         WindowPrint -2, InvoiceRec.InvoiceNo
  1255.         WindowLocate 1, 48
  1256.         WindowPrint -2, MID$(DATE$, 1, 2) + "-" + MID$(DATE$, 4, 2) + "-" + MID$(DATE$, 9, 2)
  1257.         IF LEN(RTRIM$(CustRec.AcctNo)) = 0 OR LEN(RTRIM$(CustRec.Company)) = 0 THEN
  1258.             EditFieldOpen 1, "", 3, 13, 0, 7, 6, 5
  1259.             EditFieldOpen 2, "", 6, 13, 0, 7, 41, 70
  1260.             clastKey1$ = ""
  1261.             clastKey2$ = ""
  1262.             level = 1
  1263.         ELSE
  1264.             EditFieldOpen 1, RTRIM$(CustRec.AcctNo), 3, 13, 0, 7, 6, 5
  1265.             EditFieldOpen 2, RTRIM$(CustRec.Company), 6, 13, 0, 7, 41, 70
  1266.             clastKey1$ = UCASE$(LTRIM$(EditFieldInquire$(1)))
  1267.             clastKey2$ = LTRIM$(EditFieldInquire$(2))
  1268.             level = 2
  1269.         END IF
  1270.         currNo = 1
  1271.         numTrans = 0
  1272.         GOSUB InsertTransaction
  1273.         EditFieldOpen 6, "", 19, 23, 0, 7, 7, 6
  1274.     ELSE
  1275.         level = 3
  1276.         count = 0
  1277.         SEEKEQ TranTabNum, InvoiceRec.InvoiceNo, 1
  1278.         RETRIEVE TranTabNum, TransRec
  1279.         DO
  1280.             SEEKEQ TranTabNum, InvoiceRec.InvoiceNo, count + 1
  1281.             count = count + 1
  1282.         LOOP UNTIL EOF(TranTabNum)
  1283.         transBox.listLen = count - 1
  1284.         currNo = 1
  1285.         numTrans = count - 1
  1286.         GOSUB InsertTransaction
  1287.  
  1288.         WindowLocate 1, 16
  1289.         WindowPrint -2, InvoiceRec.InvoiceNo
  1290.         WindowLocate 1, 48
  1291.         WindowPrint -2, MID$(InvoiceRec.Date, 3, 2) + "-" + MID$(InvoiceRec.Date, 5, 2) + "-" + MID$(InvoiceRec.Date, 1, 2)
  1292.  
  1293.         SETINDEX CustTabNum, "AcctIndex"
  1294.         SEEKEQ CustTabNum, InvoiceRec.AcctNo
  1295.         IF EOF(CustTabNum) THEN
  1296.             PrintError "Customer no longer exists in customer database."
  1297.             Acct$ = InvoiceRec.AcctNo
  1298.             comp$ = ""
  1299.         ELSE
  1300.             RETRIEVE CustTabNum, CustRec
  1301.             Acct$ = CustRec.AcctNo
  1302.             comp$ = CustRec.Company
  1303.         END IF
  1304.         EditFieldOpen 1, RTRIM$(Acct$), 3, 13, 0, 7, 6, 5
  1305.         EditFieldOpen 2, RTRIM$(comp$), 6, 13, 0, 7, 41, 70
  1306.         clastKey1$ = UCASE$(LTRIM$(EditFieldInquire$(1)))
  1307.         clastKey2$ = LTRIM$(EditFieldInquire$(2))
  1308.         EditFieldOpen 6, LTRIM$(STR$(InvoiceRec.TaxRate)), 19, 23, 0, 7, 7, 6
  1309.         WindowLocate 18, 42
  1310.         WindowPrint -2, RIGHT$("          " + FormatS$(InvoiceRec.Total * 100 / (InvoiceRec.TaxRate + 100), "$#,##0.00"), 14)
  1311.         WindowLocate 19, 42
  1312.         WindowPrint -2, RIGHT$("          " + FormatS$(InvoiceRec.Total * InvoiceRec.TaxRate / (InvoiceRec.TaxRate + 100), "$#,##0.00"), 14)
  1313.         WindowLocate 20, 42
  1314.         WindowPrint -2, RIGHT$("          " + FormatS$(InvoiceRec.Total, "$#,##0.00"), 14)
  1315.     END IF
  1316.     CreateListBox transList$(), transBox, 1
  1317.  
  1318.     IF level = 3 THEN
  1319.         pushButton = 5
  1320.         curBut = 2
  1321.         currEditField = 0
  1322.         WindowColor 8, 7
  1323.         WindowLocate 2, 61
  1324.         WindowPrint -2, "< Update >"
  1325.         WindowLocate 3, 61
  1326.         WindowPrint -2, "< Void >"
  1327.         WindowLocate 10, 61
  1328.         WindowPrint -2, "< Total >"
  1329.         WindowLocate 11, 61
  1330.         WindowPrint -2, "< Commit >"
  1331.         WindowColor 0, 7
  1332.     ELSE
  1333.         currEditField = 1
  1334.         curBut = 0
  1335.         pushButton = 3
  1336.         GOSUB UpdateInvButtons
  1337.         ButtonOpen 3, 1, "Add", 2, 61, 0, 0, 1
  1338.         ButtonOpen 4, 1, "Void", 3, 61, 0, 0, 1
  1339.     END IF
  1340.     ButtonOpen 5, 1, "Customer", 6, 61, 0, 0, 1
  1341.     ButtonOpen 6, 1, "Item", 7, 61, 0, 0, 1
  1342.     ButtonOpen 9, 1, "Cancel", 13, 61, 0, 0, 1
  1343.     ButtonSetState pushButton, 2
  1344. RETURN
  1345. END SUB
  1346.  
  1347.