home *** CD-ROM | disk | FTP | other *** search
/ DOS Wares / doswares.zip / doswares / DATABASE / DBASE5 / CUA_SAMP.ZIP / CUST.PRG < prev    next >
Encoding:
Text File  |  1994-06-24  |  8.3 KB  |  360 lines

  1. PROCEDURE Cust
  2.     PRIVATE mFormName, lVoid, mDesk, mActive, mClass
  3.     IF TYPE("Cust1.ClassName") # "C"    &&  form doesn't already exist
  4.         mFormOpen=.F.
  5.         DEFINE FORM mTemp PROPERTY VISIBLE .F.
  6.         lVoid = mTemp.OPEN()
  7.         mDesk = mTemp.PARENT
  8.         lVoid = mTemp.CLOSE()
  9.  
  10.         mFormName=SPACE(8)
  11.         mActive=mDesk.ActiveControl()
  12.         IF TYPE("mActive.ClassName")="C"
  13.             mClass=mActive.ClassName
  14.             IF mClass="FORM"
  15.                 mFormName=mActive.Name
  16.                 mFormOpen=.T.
  17.             ENDIF
  18.         ENDIF
  19.  
  20.         #include "Cust.dfm"
  21.         PUBLIC NewRecord
  22.  
  23.  
  24.         NewRecord = .F.
  25.  
  26.         cust1.Action = .F.
  27.         lVoid = Cust1.Open()
  28.     ELSE
  29.         lVoid = Cust1.SetFocus()    && if form exists, make current
  30.     ENDIF
  31. RETURN
  32. ******************
  33. PROCEDURE OpenCust
  34.     PRIVATE lOpen       &&
  35.  
  36.     lOpen = .T.         && was file already open? (assume .T.)
  37.  
  38.  
  39.     IF SUBSTR(DBF(),3)<>"CUST.DBF"
  40.          SELECT SELECT()
  41.          USE Cust ORDER Cust_id ALIAS Cust
  42.          lOpen = .F.
  43.     ENDIF
  44.  
  45.     This.lOPen = lOpen &&   save lOpen in form
  46.  
  47.     lVoid = This.Refresh()
  48.  
  49.     IF .NOT. mFormOpen
  50.         Main.F1.CloseAll.Enabled=.F.
  51.         Main.S.Srch.Enabled=.T.
  52.         Main.S.Tp.Enabled=.T.
  53.         Main.S.Btm.Enabled=.T.
  54.         Main.S.Pck.Enabled=.F.
  55.         Main.S.Indx.Enabled=.F.
  56.         Main.E.Undo.Enabled=.T.
  57.         Main.E.Save.Enabled=.T.
  58.         Main.V.Frm.Enabled=.F.
  59.         Main.App.Ord.Enabled=.F.
  60.         Main.App.Acc.Enabled=.F.
  61.         Main.F1.Bac.Enabled=.F.
  62.         Main.App.Inv.Enabled=.F.
  63.     ENDIF
  64.     Main.App.Cust.Enabled=.F.
  65.  
  66. RETURN
  67.  
  68. *******************
  69. PROCEDURE CloseCust
  70.     IF This.Action
  71.         lVoid = This.Submit()
  72.     ELSE
  73.         IF This.Modified()
  74.             DO ErrorMsg WITH "Exit Cust without saving ..."
  75.         ENDIF
  76.     ENDIF
  77.  
  78.     IF .NOT. This.lOpen     &&   if file wasn't already open on startup
  79.         USE IN Cust         &&   shut it down
  80.     ENDIF
  81.     USE CUST EXCLUS
  82.     DELE FOR CUST_ID=' '
  83.     COUNT FOR DELETED() TO EmpRec
  84.     IF EmpRec<>0
  85.       PACK
  86.     ENDIF
  87.     USE
  88.     LVoid = This.Release()
  89.  
  90.     mFormOpen=.F.
  91.     DEFINE FORM mTemp PROPERTY VISIBLE .F.
  92.     lVoid = mTemp.OPEN()
  93.     mDesk = mTemp.PARENT
  94.     lVoid = mTemp.CLOSE()
  95.  
  96.     mFormName=SPACE(8)
  97.     mActive=mDesk.ActiveControl()
  98.     IF TYPE("mActive.ClassName")="C"
  99.         mClass=mActive.ClassName
  100.         IF mClass="FORM"
  101.             mFormName=mActive.Name
  102.             mFormOpen=.T.
  103.         ENDIF
  104.     ENDIF
  105.  
  106.     IF .NOT. mFormOpen
  107.         Main.F1.CloseAll.Enabled=.T.
  108.         Main.S.Srch.Enabled=.F.
  109.         Main.S.Tp.Enabled=.F.
  110.         Main.S.Btm.Enabled=.F.
  111.         Main.S.Pck.Enabled=.T.
  112.         Main.S.Indx.Enabled=.T.
  113.         Main.E.Undo.Enabled=.F.
  114.         Main.E.Save.Enabled=.F.
  115.         Main.V.Frm.Enabled=.T.
  116.         Main.App.Ord.Enabled=.T.
  117.         Main.App.Acc.Enabled=.T.
  118.         Main.F1.Bac.Enabled=.T.
  119.         Main.App.Inv.Enabled=.T.
  120.     ENDIF
  121.     Main.App.Cust.Enabled=.T.
  122.     RELEASE Cust1
  123.  
  124.  
  125. RETURN
  126.  
  127. ******************
  128. FUNCTION DupCheck
  129.     If NewRecord
  130.         ? "Checking for Duplicates ..."
  131.         SEEK(Cust1.CustID.Value)
  132.         IF FOUND() .AND. Cust1.CustID.Value<>''
  133.             DO ErrorMsg WITH "Duplicate Found, Try Again..."+Cust1.CustID.Value
  134.             CLEAR
  135.             RETURN .F.
  136.         ELSE
  137.             Newrecord = .f.
  138.         ENDIF
  139.     Endif
  140.     CLEAR
  141. RETURN .T.
  142.  
  143. ******************
  144. FUNCTION FindID
  145.     * Generate a form that will can be used by other procedures
  146.     DO GenForm
  147.     * Make the user select Ok before moving on
  148.     lVoid = Search.sValue.Setfocus()
  149.     lVoid = Search.ReadModal()
  150.  
  151. *    ?"FindLast ok"
  152.  
  153. RETURN .T.
  154. **********************
  155. PROCEDURE GenForm
  156.     * Define a search form
  157.     DEFINE FORM Search FROM 5,10 TO 11,45 ;
  158.         PROPERTY ;
  159.             Text "Search"
  160.  
  161.     DEFINE TEXT sVal OF Search AT 1,5 ;
  162.         PROPERTY ;
  163.             Text "Cust ID :"
  164.     DEFINE ENTRYFIELD Svalue OF Search AT 1,14 ;
  165.         PROPERTY ;
  166.             Width 7
  167.     DEFINE PUSHBUTTON sOk OF Search AT 3,12 ;
  168.         PROPERTY ;
  169.             Text "OK",;
  170.             Width 10  ,;
  171.             Default .T. ,;
  172.             OnClick "CloseMe"
  173.  
  174.  
  175. RETURN
  176. *****************
  177. PROCEDURE CloseMe
  178. CLEAR
  179.     * Get value user entered before closing form
  180.     SearchFor = Search.Svalue.value
  181.     SearchWidth = Search.Width  && See if size is Less than 50
  182.  
  183.     lVoid = Search.Close()
  184.     * remove from memory
  185.     lVoid = Search.Release()
  186.  
  187.     * Note : If you place this code in the FindLast routine you will
  188.     * have a timing problem where the variable SearchFor has not been
  189.     * Defined before there is a call referencing it.
  190.  
  191.     * Now Search for value given - Exact match
  192.     IF LEN(SearchFor) > 0
  193.         SEEK(TRIM(SearchFor))
  194.         IF FOUND()
  195.             Cust1.StatusMessage = "Found ID  = "+trim(SearchFor)
  196.             * repaint the form with the current record
  197.             lVoid = Cust1.Refresh()
  198.         ELSE
  199.             DO ErrorMsg WITH "Customer ID Not Found ..."+trim(SearchFor)
  200.         ENDIF
  201.     ENDIF
  202. CLEAR
  203. RETURN
  204. ******************
  205. PROCEDURE PrevHand
  206.  
  207.     * Check to see that the record pointer is not at Beginning of File
  208.  
  209.      IF .NOT. BOF()
  210.         IF Form.Modified()
  211.             lVoid = Form.Submit()
  212.         ENDIF
  213.  
  214.         SKIP -1
  215.         IF BOF()
  216.            DO ErrorMsg WITH "Top of file!"
  217.         ENDIF
  218.  
  219.         IF DELETED()
  220.            Form.cStatus.Text = "DELETED"
  221.         ELSE
  222.            Form.cStatus.Text = ""
  223.         Endif
  224.         lVoid = Form.Refresh()
  225.     ELSE
  226.         DO ErrorMsg WITH "Top of file!"
  227.     ENDIF
  228.     Form.Action = .F.
  229. RETURN
  230.  
  231. *******************
  232. PROCEDURE SkipHand
  233.  
  234.     * Check to see that the record pointer is not end of file
  235.     IF .NOT. EOF()
  236.         IF Form.Modified()
  237.             lVoid = Form.Submit()
  238.  
  239.         ENDIF
  240.         SKIP
  241.         IF CUST_ID=' '
  242.          SKIP -1
  243.          DO ErrorMsg WITH "End of file encountered!"
  244.         ENDIF
  245.         * Show user if the record is marked for deletion
  246.         IF DELETED()
  247.            Form.cStatus.Text = "DELETED"
  248.         ELSE
  249.            Form.cStatus.Text = ""
  250.         Endif
  251.         lVoid = Form.Refresh()
  252.     ELSE
  253.         * Record pointer is at the end of file, tell user
  254.         DO ErrorMsg WITH "End of file encountered!"
  255.     ENDIF
  256.     Form.Action = .F.
  257.  
  258. RETURN
  259. ******************
  260. PROCEDURE Add_new
  261.     *Write data to disk
  262.     lvoid = Form.submit()
  263.     NewRecord=.T.
  264.     * Append a record
  265.     APPEND BLANK
  266.  
  267.     *Refresh Screen Data
  268.     lvoid = Form.refresh()
  269.     Form.cStatus.Text=""
  270.  
  271. RETURN
  272. ******************
  273. PROCEDURE DelIt && Marks record for deletion
  274.     IF DELETED()
  275.       Form.cStatus.Text = ""
  276.       RECALL
  277.     ELSE
  278.       Form.cStatus.Text = "DELETED"
  279.       DELETE
  280.     ENDIF
  281.  
  282. RETURN
  283. *****************
  284. PROCEDURE CanHand
  285.     Form.Action = .F.
  286.     lVoid = Form.Close()
  287. RETURN
  288.  
  289. *****************
  290. PROCEDURE RePaint
  291.     SELE Cust
  292.     lVoid = Cust1.Refresh()
  293. RETURN
  294.  
  295. ******************
  296. PROCEDURE PrintForm
  297.  
  298. DEFINE FORM Prt FROM 5,25 TO 16,50 ;
  299.     PROPERTY ;
  300.         TEXT "Print Form"
  301.  
  302. DEFINE TEXT t1 OF Prt AT 1,1 ;
  303.     PROPERTY ;
  304.         Text "Type :",;
  305.         COLORNORMAL "R/W"
  306.  
  307. DEFINE RADIOBUTTON Rep OF Prt AT 2,1 ;
  308.     PROPERTY ;
  309.         Text "Report",;
  310.         Group .T.,;
  311.         COLORNORMAL "N/W",;
  312.         WIDTH 15
  313.  
  314. DEFINE RADIOBUTTON Lab OF Prt AT 3,1 ;
  315.     PROPERTY ;
  316.         Text "Labels",;
  317.         Group .F.,;
  318.         COLORNORMAL "N/W",;
  319.         WIDTH 15
  320.  
  321. DEFINE TEXT T3 OF Prt AT 9,5 ;
  322.     PROPERTY ;
  323.         TEXT "PRINTING ..." ,;
  324.         VISIBLE .F.,;
  325.         WIDTH 15
  326.  
  327. DEFINE PUSHBUTTON P1 OF Prt AT 8,12 ;
  328.     PROPERTY ;
  329.         TEXT "&Ok",;
  330.         ONCLICK "RunRep",;
  331.         Width 10
  332.  
  333. DEFINE PUSHBUTTON P2 OF Prt AT 8,2 ;
  334.     PROPERTY ;
  335.         TEXT "&Cancel",;
  336.         ONCLICK "CanHand",;
  337.         Width 10
  338.  
  339. lVoid = Prt.Open()
  340.  
  341. ******************
  342. PROCEDURE Runrep
  343.  
  344. * Check for Labels or Reports
  345. DO CASE
  346.     CASE Form.Rep.Value
  347.          * display to user something is happening
  348.          Form.T3.Visible = .t.
  349.          REPORT FORM Cust TO PRINTER
  350.     CASE Form.Lab.Value
  351.          * display to user something is happening
  352.          Form.T3.Visible = .t.
  353.          LABEL FORM Cust TO PRINTER
  354.  
  355. ENDCASE
  356. lVoid = Form.Close()
  357. lVoid = Form.Release()
  358. RETURN
  359.  
  360.