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

  1. ******************************************************************************
  2. *  PROGRAM:      Customer.mnu
  3. *
  4. *  WRITTEN BY:   Borland Samples Group
  5. *
  6. *  DATE:         12/93
  7. *
  8. *  UPDATED:      7/94
  9. *
  10. *  REVISION:     $Revision:   1.41  $
  11. *
  12. *  VERSION:      dBASE FOR WINDOWS 5.0
  13. *
  14. *  DESCRIPTION:  This menu file is used by Customer.wfm for performing simple
  15. *                tasks.  It allows adding, deleting, and searching for
  16. *                customers, brings up the orders form for a customer,
  17. *                and runs reports.
  18. *
  19. *  PARAMETERS:   FormObj -- the form to which this menu is attached.
  20. *
  21. *  CALLS:        None
  22. *
  23. *  USAGE:        form.menuFile = "Customer.mnu"
  24. *
  25. *******************************************************************************
  26. #include <Messdlg.h>
  27.  
  28. ** END HEADER -- do not remove this line*
  29. * Generated on 06/21/94
  30. *
  31. Parameter FormObj
  32. NEW CUSTOMERMENU(FormObj,"Root")
  33. CLASS CUSTOMERMENU(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 Customer form."
  45.  
  46.    DEFINE MENU CUSTOMER OF THIS;
  47.        PROPERTY;
  48.          Text "&Customer"
  49.  
  50.          DEFINE MENU VIEWEDIT OF THIS.CUSTOMER;
  51.              PROPERTY;
  52.                OnClick CLASS::VIEWEDITONCLICK,;
  53.                Text "&Edit",;
  54.                Shortcut "Ctrl-E",;
  55.                StatusMessage "Edit data."
  56.  
  57.          DEFINE MENU SEPARATOR1 OF THIS.CUSTOMER;
  58.              PROPERTY;
  59.                Separator .T.,;
  60.                Text ""
  61.  
  62.          DEFINE MENU ADD OF THIS.CUSTOMER;
  63.              PROPERTY;
  64.                OnClick CLASS::ADDONCLICK,;
  65.                Text "&Add",;
  66.                Shortcut "Ctrl-A",;
  67.                Enabled .T.,;
  68.                StatusMessage "Add a new customer."
  69.  
  70.          DEFINE MENU DELETE OF THIS.CUSTOMER;
  71.              PROPERTY;
  72.                OnClick CLASS::DELETEONCLICK,;
  73.                Text "&Delete",;
  74.                Shortcut "Ctrl-D",;
  75.                Enabled .F.,;
  76.                StatusMessage "Delete the current customer."
  77.  
  78.          DEFINE MENU SEPARATOR2 OF THIS.CUSTOMER;
  79.              PROPERTY;
  80.                Separator .T.,;
  81.                Text ""
  82.  
  83.          DEFINE MENU SEARCH OF THIS.CUSTOMER;
  84.              PROPERTY;
  85.                OnClick CLASS::SEARCHONCLICK,;
  86.                Text "&Search ...",;
  87.                Shortcut "Ctrl-S",;
  88.                StatusMessage "Search for a customer."
  89.  
  90.          DEFINE MENU SEPARATOR3 OF THIS.CUSTOMER;
  91.              PROPERTY;
  92.                Separator .T.,;
  93.                Text ""
  94.  
  95.          DEFINE MENU CURRENT_ORDERS OF THIS.CUSTOMER;
  96.              PROPERTY;
  97.                OnClick CLASS::CURRENTORDERSONCLICK,;
  98.                Text "&Orders ...",;
  99.                Shortcut "Ctrl-O",;
  100.                StatusMessage "See the orders for the current customer in the Orders form."
  101.  
  102.    DEFINE MENU REPORT OF THIS;
  103.        PROPERTY;
  104.          Text "&Report"
  105.  
  106.          DEFINE MENU CUSTOMER_REPORT OF THIS.REPORT;
  107.              PROPERTY;
  108.                OnClick {;report form customer},;
  109.                Text "Customer &Report",;
  110.                Shortcut "Ctrl-R",;
  111.                StatusMessage "Display a report of customer information."
  112.  
  113.          DEFINE MENU CUSTOMER_LABELS OF THIS.REPORT;
  114.              PROPERTY;
  115.                OnClick {;report form customer.rpl},;
  116.                Text "Customer &Labels",;
  117.                Shortcut "Ctrl-L",;
  118.                StatusMessage "Display labels for all customers."
  119.  
  120.  
  121.    ****************************************************************************
  122.    procedure SearchOnClick
  123.    ****************************************************************************
  124.    private searchForm,searchItem,saveRec
  125.    form.CheckChanged(.t.)
  126.    set procedure to Search.wfm additive
  127.    searchForm = new SearchForm()
  128.    searchForm.keyName = "Name"       && Indicate to user expression to enter
  129.    searchForm.formatting = "@X"
  130.    searchForm.mdi = .f.              && Necessary for a modal form
  131.    searchItem = searchForm.Readmodal()
  132.    if type("searchItem") = "O" .and. searchItem.id <> 0;
  133.                                .and. .not. empty(searchForm.value)
  134.       *** If Cancel or ESC wasn't used to exit Search.wfm
  135.       saveRec = recno()
  136.       form.enabled = .f.
  137.       seek upper(ltrim(rtrim(searchForm.value)))
  138.       if .not. found()
  139.          go saveRec
  140.          InformationMessage(FormatStr("Customer %1 \n Was not Found.",;
  141.                                       searchForm.value),;
  142.                             "Info")
  143.       endif
  144.       form.enabled = .t.
  145.    endif
  146.    searchForm.Release()
  147.    close procedure Search.wfm
  148.  
  149.    ****************************************************************************
  150.    procedure DeleteOnClick
  151.    ****************************************************************************
  152.    if ConfirmationMessage("Are you sure you want to delete this customer?",;
  153.                              "Confirm") = YES
  154.       delete  && Deleted is on, so deleted records are there until you PACK
  155.       commit()
  156.       form.changesMade = .f.
  157.       begintrans()
  158.       form.nextCustButton.OnClick()  && Move to next record
  159.    endif
  160.  
  161.  
  162.    ****************************************************************************
  163.    procedure AddOnClick
  164.    ****************************************************************************
  165.    private addForm, custNoField, newCustomer
  166.    form.CheckChanged(.t.)
  167.    if ConfirmationMessage("Are you sure you want to add a customer?",;
  168.                              "Confirmation") = YES
  169.       if .not. form.inEditMode
  170.          form.ViewEdit()                 && Make sure record is editable
  171.       else
  172.          form.nameEntry.SetFocus()
  173.       endif                              && and begin a transaction
  174.       form.changesMade = .t.             && Since we are adding a record
  175.       form.previousRecord = bookmark()
  176.       append blank                       && This must be done after begintrans()
  177.       custNoField = field(1)             && so rollback() could delete if necessary
  178.       newCustomer = str(val(form.maxCustNo) + 1, 4)
  179.       replace &custNoField with newCustomer     && New customer number
  180.       form.maxCustNo = newCustomer
  181.    endif
  182.  
  183.  
  184.    ****************************************************************************
  185.    procedure CurrentOrdersOnclick
  186.    ****************************************************************************
  187.    form.CheckChanged(.t.)
  188.    if type ("form.parentOrdersForm") = "U"
  189.       if type ("form.childOrdersForm") = "U"
  190.          form.StartOrdersForm()
  191.          form.CallShowOrders(customer->customer_n)
  192.       else
  193.          form.CallShowOrders(customer->customer_n)
  194.          form.childOrdersForm.open()
  195.          form.childOrdersForm.windowState = 0
  196.          form.childOrdersForm.windowState = 0
  197.          form.childOrdersForm.setFocus()
  198.       endif
  199.    else
  200.       form.parentOrdersForm.setFocus()
  201.    endif
  202.  
  203.  
  204.    ****************************************************************************
  205.    procedure ViewEditOnClick
  206.    ****************************************************************************
  207.    form.ViewEdit()
  208.  
  209.    ****************************************************************************
  210.    procedure OnExit
  211.    ****************************************************************************
  212.    if type ("form.parentOrdersForm") <> "U"
  213.       form.parentOrdersForm.close()
  214.    else if type ("form.childOrdersForm") <> "U"
  215.       form.childOrdersForm.close()
  216.    endif
  217.    form.Close()
  218.       
  219. ENDCLASS
  220.  
  221.  
  222. ********************************************************************************
  223. function FormatStr(string)
  224.  
  225. * Could have 0 or more parameters.
  226. * This function will replace occurrences of "%<n>" with the corresponding
  227. * parameter string.  It will also replace all occurrences of "\n" with a
  228. * carriage return, and all occurrences of "\t" with a tab.
  229. *
  230. * Example - This prints Hello World on 2 lines:
  231. *           FormatStr("Hello \n %1", "World")
  232. ********************************************************************************
  233. #define ENTER  chr(13)
  234. #define TAB    chr(9)
  235. local i, strPos, strCnt, tmpStr
  236.  
  237. tmpStr = string
  238. for i = 2 to argc()                    && While have something to search for
  239.    tmpStr = StrTran(tmpStr, "%" + ltrim(str(i - 1)), argv(i))
  240. next
  241. tmpStr = StrTran(tmpStr, "\n", ENTER)
  242. tmpStr = StrTran(tmpStr, "\t", TAB)
  243.  
  244. return tmpStr
  245.  
  246.  
  247. *******************************************************************************
  248. function StrTran(string,curStr,repStr)
  249. *
  250. * Replaces all occurrences of curStr in string with repStr
  251. *******************************************************************************
  252. local strPos, lenCurStr, tmpStr
  253. tmpStr = string
  254. lenCurStr = len(curStr)
  255. strPos = at(curStr,tmpStr)
  256. do while strPos > 0
  257.    tmpStr = stuff(tmpStr, strPos, lenCurStr, repStr)
  258.    strPos = at(curStr,tmpStr)
  259. enddo
  260. return tmpStr
  261.  
  262.  
  263.  
  264.