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

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