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

  1. ******************************************************************************
  2. *  PROGRAM:      Orders.mnu
  3. *
  4. *  WRITTEN BY:   Borland Samples Group
  5. *
  6. *  DATE:         12/93
  7. *
  8. *  UPDATED:      7/94
  9. *
  10. *  REVISION:     $Revision:   1.42  $
  11. *
  12. *  VERSION:      dBASE FOR WINDOWS 5.0
  13. *
  14. *  DESCRIPTION:  This is a menu file used by Orders.wfm for
  15. *                performing simple tasks.  It allows adding and deleting
  16. *                records, searching for a value in the order field of the
  17. *                current table viewed, and exiting the form in view.
  18. *
  19. *  PARAMETERS:   FormObj -- the form to which this menu will belong.
  20. *
  21. *  CALLS:        None
  22. *
  23. *  USAGE:        form.menuFile = "Orders.mnu"
  24. *
  25. *******************************************************************************
  26. #include <Messdlg.h>
  27.  
  28. ** END HEADER -- do not remove this line*
  29. * Generated on 05/06/94
  30. *
  31. Parameter FormObj
  32. NEW ORDERS(FormObj,"Root")
  33. CLASS ORDERS(FormObj,Name) OF MENU(FormObj,Name)
  34.    this.Text = ""
  35.  
  36.    DEFINE MENU FILE OF THIS;
  37.        PROPERTY;
  38.          Text "&File"
  39.  
  40.          DEFINE MENU EXIT OF THIS.FILE;
  41.              PROPERTY;
  42.                OnClick CLASS::ONEXIT,;
  43.                Text "E&xit",;
  44.                StatusMessage "Leave Orders form."
  45.  
  46.    DEFINE MENU ORDER OF THIS;
  47.        PROPERTY;
  48.          Text "&Order"
  49.  
  50.          DEFINE MENU VIEWEDIT OF THIS.ORDER;
  51.              PROPERTY;
  52.                OnClick CLASS::VIEWEDITONCLICK,;
  53.                Text "&Edit",;
  54.                Shortcut "Ctrl-E",;
  55.                StatusMessage "Edit data."
  56.  
  57.          DEFINE MENU SEPARATOR1 OF THIS.ORDER;
  58.              PROPERTY;
  59.                Separator .T.,;
  60.                Text ""
  61.  
  62.          DEFINE MENU ADD OF THIS.ORDER;
  63.              PROPERTY;
  64.                OnClick CLASS::ADDONCLICK,;
  65.                Text "&Add",;
  66.                Enabled .T.,;
  67.                Shortcut "Ctrl-A",;
  68.                StatusMessage "Add a new order."
  69.  
  70.          DEFINE MENU DELETE OF THIS.ORDER;
  71.              PROPERTY;
  72.                OnClick CLASS::DELETEONCLICK,;
  73.                Text "&Delete",;
  74.                Enabled .F.,;
  75.                Shortcut "Ctrl-D",;
  76.                StatusMessage "Delete the current order."
  77.  
  78.          DEFINE MENU SEPARATOR2 OF THIS.ORDER;
  79.              PROPERTY;
  80.                Separator .T.,;
  81.                Text ""
  82.  
  83.          DEFINE MENU SEARCH OF THIS.ORDER;
  84.              PROPERTY;
  85.                OnClick CLASS::SEARCHONCLICK,;
  86.                Text "&Search ...",;
  87.                Shortcut "Ctrl-S",;
  88.                StatusMessage "Search for an order."
  89.  
  90.          DEFINE MENU SEPARATOR3 OF THIS.ORDER;
  91.              PROPERTY;
  92.                Separator .T.,;
  93.                Text ""
  94.  
  95.          DEFINE MENU CURRENT_CUSTOMER OF THIS.ORDER;
  96.              PROPERTY;
  97.                OnClick CLASS::CURRENTCUSTOMERONCLICK,;
  98.                Text "Custo&mer ...",;
  99.                Shortcut "Ctrl-M",;
  100.                StatusMessage "View detailed information about the current customer."
  101.  
  102.  
  103.    DEFINE MENU REPORT OF THIS;
  104.        PROPERTY;
  105.          Text "&Report"
  106.  
  107.          DEFINE MENU ORDERSREPORT OF THIS.REPORT;
  108.              PROPERTY;
  109.                OnClick {;report form orders},;
  110.                Text "&Invoices",;
  111.                Shortcut "Ctrl-I"
  112.  
  113.  
  114.  
  115.  
  116.    ****************************************************************************
  117.    procedure SearchOnClick
  118.    ****************************************************************************
  119.    private searchForm, searchItem, saveRec, saveFilt
  120.    form.CheckChanged(.t.)
  121.    set procedure to Search.wfm additive
  122.    searchForm = new SearchForm()
  123.    searchForm.keyName = "Order Number"  && Indicator of key expression
  124.    searchForm.formatting = "9999"       && format specific to this key
  125.    searchForm.mdi = .f.
  126.    searchItem = searchForm.Readmodal()
  127.    if type("searchItem") = "O" .and. searchItem.id <> 0
  128.                                    && If search wasn't cancelled
  129.       saveRec = recno()            && save current record in case seek is unsucessfull
  130.       seek ltrim(searchForm.value)
  131.       if .not. found()
  132.          InformationMessage(FormatStr("Order %1 \n Was not Found.",;
  133.                                       searchForm.value),;
  134.                             "Info")
  135.          go saveRec
  136.       endif
  137.    endif
  138.    searchForm.Release()
  139.    close procedure Search.wfm
  140.  
  141.    ****************************************************************************
  142.    procedure DeleteOnClick
  143.    ****************************************************************************
  144.    if ConfirmationMessage("Are you sure you want to delete this order?",;
  145.                           "Confirm") = YES
  146.       delete  && DELETED is ON, so deleted records are still there until
  147.               && a PACK is executed
  148.       commit()
  149.       form.changesMade = .f.
  150.       begintrans()
  151.       form.nextOrderButton.OnClick()  && Move to next record
  152.    endif
  153.  
  154.    ****************************************************************************
  155.    procedure AddOnClick
  156.    ****************************************************************************
  157.    private addForm, newOrder, saleDateField, orderNoField, custNoField, custNo
  158.    form.CheckChanged(.t.)
  159.    if ConfirmationMessage("Are you sure you want to add an order?",;
  160.                           "Confirmation") = YES
  161.                           
  162.  
  163.       orderNoField = field(1)                 && Customer_n field
  164.       custNoField = field(2)                  && Order_no field
  165.       saleDateField = field(3)                && Sale_date field
  166.       
  167.       if type("form.parentCustomerForm") <> "U"
  168.          custNo = form.customer_n
  169.       else
  170.          custNo = customer->customer_n           && Save customer no
  171.       endif
  172.  
  173.       if .not. form.inEditMode
  174.          form.ViewEdit()                      && Make sure record is editable
  175.       else
  176.          form.childBrowse.setFocus()
  177.       endif
  178.       form.changesMade = .t.
  179.       form.previousRecord = bookmark()
  180.       append blank
  181.       orderNoField = field(1)
  182.       newOrder = str(val(form.maxOrder) + 1,4)
  183.       replace &orderNoField with newOrder     && Assign new order number
  184.       replace &custNoField with custNo        && Use the same customer
  185.       replace &saleDateField with date()      && Default sale date is today
  186.       form.maxOrder = newOrder
  187.       refresh
  188.       select lineitem
  189.       append blank
  190.       refresh
  191.       select orders
  192.    endif
  193.  
  194.  
  195.    ****************************************************************************
  196.    procedure CurrentCustomerOnclick
  197.    ****************************************************************************
  198.    form.CheckChanged(.t.)
  199.    if type("form.parentCustomerForm") = "U"
  200.       if type ("form.childCustomerForm") = "U"
  201.          form.StartCustomerForm()
  202.          form.CallShowCustomer(orders->customer_n)
  203.       else
  204.          form.CallShowCustomer(orders->customer_n)
  205.          form.childCustomerForm.open()
  206.          form.childCustomerForm.windowState = 0
  207.          form.childCustomerForm.setFocus()
  208.       endif
  209.    else
  210.       form.parentCustomerForm.setFocus()
  211.    endif
  212.  
  213.  
  214.    ***************************************************************************
  215.    procedure ViewEditOnClick
  216.    ****************************************************************************
  217.    form.ViewEdit()
  218.    
  219.    ****************************************************************************
  220.    procedure OnExit
  221.    ****************************************************************************
  222.    if type ("form.parentCustomerForm") <> "U"
  223.       form.parentCustomerForm.close()
  224.    else if type ("form.childCustomerForm") <> "U"
  225.       form.childCustomerForm.close()
  226.    endif
  227.    form.Close()
  228.    
  229. ENDCLASS
  230.  
  231.  
  232.  
  233.  
  234.  
  235.  
  236. ********************************************************************************
  237. function FormatStr(string)
  238. *
  239. * Could have 0 or more parameters.
  240. * This function will replace occurrences of "%<n>" with the corresponding
  241. * parameter string.  It will also replace all occurrences of "\n" with a Carriage
  242. * Return, and all occurrences of "\t" with a Tab.
  243. *
  244. * Example: x = FormatStr("Hello \n %1", "World") &&prints Hello World on 2 lines
  245. ********************************************************************************
  246. #define ENTER  chr(13)
  247. #define TAB    chr(9)
  248. local i, strPos, strCnt, tmpStr
  249.  
  250. tmpStr = string
  251. for i = 2 to argc()    && while have something to search for
  252.    tmpStr = StrTran(tmpStr, "%" + ltrim(str(i - 1)), argv(i))
  253. next
  254. tmpStr = StrTran(tmpStr, "\n", ENTER)
  255. tmpStr = StrTran(tmpStr, "\t", TAB)
  256.  
  257. return tmpStr
  258.  
  259.  
  260. *******************************************************************************
  261. function StrTran(string,curStr,repStr)
  262. *
  263. * Replaces all occurrences of curStr in string with repStr
  264. *******************************************************************************
  265. local strPos, lenCurStr, tmpStr
  266. tmpStr = string
  267. lenCurStr = len(curStr)
  268. strPos = at(curStr,tmpStr)
  269. do while strPos > 0
  270.    tmpStr = stuff(tmpStr, strPos, lenCurStr, repStr)
  271.    strPos = at(curStr,tmpStr)
  272. enddo
  273. return tmpStr
  274.  
  275.  
  276.  
  277.  
  278.