home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 5 / 05.iso / a / a044 / 3.ddi / MISC / GENERIC.PRG < prev    next >
Encoding:
Text File  |  1993-08-31  |  7.3 KB  |  316 lines

  1. *Program is generic.prg
  2. *This program was modified as an original dBASE program.  We
  3. *added an event loop, a check box, and some buttons.  A real windows
  4. *app would like some other neat stuff.  Note that this program also
  5. *uses a dBFast VALID clause in a unique way.  dBFast permits the 
  6. *key word "CHANGE" in association with a valid clause.  If used, 
  7. *the valid clause is only evaluated if the user actually changes 
  8. *the data.  Here we use it to determine index order.  If the user
  9. *moves to and enters a social security number, we set the index
  10. *to social security and look up in that index.  If the user changes
  11. *the name, we set up that index (the default).  
  12. *
  13. *
  14.  
  15. #define ACTIVEGETS     1
  16. #define READSAVE     2
  17. #define WAITING     3
  18. #define NORMAL         4
  19.  
  20. #define NO_EVENT            -1
  21. #define KEYBD_EVENT         1
  22. #define MENU_EVENT             2
  23. #define SELECTWINDOW_EVENT     3
  24. #define CLOSEWINDOW_EVENT     5
  25. #define BUTTON_EVENT         6
  26.  
  27. #define OUREDIT     1
  28. #define OURNEXT     2
  29. #define OURPREV     3
  30. #define OUREXIT     4
  31. #define OURNEW         5
  32. #define OURDELETE     6
  33.  
  34.  
  35.  
  36. SET PROCEDURE TO generic
  37.  
  38.  
  39. set deleted on
  40.  
  41. PUBLIC begread, mode
  42. STORE 1 TO begread
  43. SET EXIT VIDEO TO 112
  44.  
  45. CREATE BUTTON ' Next ' AT 19,3
  46. CREATE BUTTON ' Prev ' AT 19,16
  47. CREATE BUTTON 'Delete' AT 19,29
  48. CREATE BUTTON ' New  ' AT 19,42
  49. CREATE BUTTON 'Cancel' AT 19,55
  50. CREATE BUTTON ' Edit ' AT 19,68
  51. mode = OUREDIT
  52.  
  53. DO PaintScreen
  54. DO dispinfo
  55.  
  56. set exit video to sayvideo()
  57.  
  58. DO WHILE .T.
  59.    ENABLE BUTTON ' Next '
  60.    ENABLE BUTTON ' Prev '
  61.    ENABLE BUTTON 'Delete'
  62.    ENABLE BUTTON ' New  '
  63.    ENABLE BUTTON 'Cancel'
  64.    ENABLE BUTTON ' Edit '
  65.  
  66.    STORE name TO mname
  67.    STORE ssn TO mssn
  68.    *Note the CHANGE clause in these gets.
  69.    @ 4,11 GET mname VALID chkname(mname) CHANGE MESSAGE ;
  70.                'Enter the name to find' ;
  71.                ERROR 'Name not Found'
  72.    @ 4,58 GET mssn VALID chkssn(mssn)     CHANGE MESSAGE ;
  73.              'Enter the Account number to find' ;
  74.              ERROR 'The account number does not exist'
  75.  
  76.    action = GetEvent(ACTIVEGETS,begread)
  77.    action = TranslateEvent(action)
  78.  
  79.    IF .NOT. doevent(action,.F.)
  80.       IF action = OUREXIT
  81.          EXIT
  82.       ENDIF
  83.       LOOP
  84.    ENDIF
  85.  
  86.    firstpass = .t.
  87.  
  88.    DO WHILE .T.
  89.       IF action = OURNEW
  90.          mode = OURNEW
  91.          APPEND BLANK
  92.          if firstpass
  93.            @ 4,11 GET name
  94.            @ 4,58 GET ssn
  95.          endif
  96.          DISABLE BUTTON ' Next '
  97.          DISABLE BUTTON ' Prev '
  98.          DISABLE BUTTON 'Delete'
  99.          DISABLE BUTTON ' New  '
  100.          DISABLE BUTTON ' Edit '
  101.       ELSE
  102.          DISABLE BUTTON ' Edit '
  103.          DISABLE BUTTON ' New  '
  104.          @ 4,11 SAY name
  105.          @ 4,58 SAY ssn
  106.          mode = OUREDIT
  107.       ENDIF
  108.         if firstpass
  109.             @  8,14 GET address
  110.             @  8,62 GET date MESSAGE 'Enter the date last contacted'
  111.             @ 10,14 GET city
  112.             @ 12,14 GET state
  113.             @ 12,38 GET zip
  114.             @ 10,49 GET notes editbox to 5,15
  115.           @ 16,49 GET active CHECKBOX 'Active'
  116.             @ 14,21 GET busphone  PICTURE '(###)###-####'
  117.             @ 16,21 GET homephone PICTURE '(###)###-####'
  118.          endif
  119.  
  120.       action = GetEvent(READSAVE,0)
  121.       action = TranslateEvent(action)
  122.       IF doevent(action,.T.)
  123.          EXIT
  124.       ENDIF
  125.  
  126.       firstpass = .f.
  127.       update gets
  128.    ENDDO
  129.    clear gets
  130. ENDDO
  131.  
  132. RELEASE begread, mode
  133. CLOSE ALL
  134. RETURN
  135.  
  136. ********************************************
  137. PROCEDURE PaintScreen
  138. ********************************************
  139.  
  140. USE tname 
  141. INDEX on ssn to tssn
  142. INDEX on name to tname
  143. use tname index tname, tssn
  144.  
  145. color = sayvideo()
  146. *Find out the users chosen color, mask our forgrnd, then add 1 to make it blue
  147. color = bitand(240,color) + 1
  148. set say video to color
  149. center('Customer Entry and Modification',1,0,78,10)
  150. set color to
  151.  
  152. @  4,6  SAY 'Name'
  153. @  4,43 SAY 'Account Number'
  154. @  8,6  SAY 'Address'
  155. @ 10,6  SAY 'City'
  156. @ 12,6  SAY 'State'
  157. @ 12,29 SAY 'Zip Code'
  158. @ 14,6  SAY 'Business Phone'
  159. @ 16,6  SAY 'Home Phone'
  160. @  8,49 SAY 'Last Contact'
  161. @ 12,49 SAY 'Notes'
  162. @  7,4 TO 17,73
  163. return
  164.  
  165.  
  166. ********************************************
  167. FUNCTION chkname
  168. ********************************************
  169. PARAMETER target
  170.  
  171.    SET INDEX TO tname
  172.    SEEK TRIM(target)
  173.    begread = 1      | As a convenience, Change default get field
  174.    IF .NOT. EOF()
  175.       GETNO(30)        | Anything larger than number of get fields exist read
  176.    ELSE
  177.       GO BOTTOM
  178.       RETURN(.F.)
  179.    ENDIF
  180. RETURN(.T.)
  181.  
  182.  
  183. ********************************************
  184. FUNCTION chkssn
  185. ********************************************
  186. PARAMETER target
  187.  
  188.    SET INDEX TO tssn
  189.    SEEK TRIM(target)
  190.    begread = 2          | As a convenience, Change default get field
  191.    IF .NOT. EOF()
  192.       GETNO(30)        | Anything larger than number of get fields exist read
  193.    ELSE
  194.       GO BOTTOM
  195.       RETURN(.F.)
  196.    ENDIF
  197. RETURN(.T.)
  198.  
  199.  
  200. ********************************************
  201. FUNCTION doevent
  202. ********************************************
  203. PARAMETER act, dflt
  204.  
  205.    DO CASE
  206.       CASE act = OUREXIT
  207.          IF mode = OUREDIT
  208.             GOTO CURRENT
  209.          ELSE
  210.             UNPEND
  211.          ENDIF
  212.          RETURN(dflt)
  213.       CASE act = 0              |Incorrect entry
  214.          RETURN(.F.)
  215.       CASE act = OURNEXT
  216.          SKIP
  217.          IF EOF()
  218.             SKIP -1
  219.          ENDIF
  220.          do dispinfo
  221.          RETURN(.f.)
  222.       CASE act = OURPREV
  223.          SKIP -1
  224.          IF BOF()
  225.             SKIP
  226.          ENDIF
  227.          DO dispinfo
  228.          RETURN(.F.)
  229.       CASE act = OURDELETE
  230.          DELETE
  231.          SKIP
  232.          IF EOF()
  233.             SKIP -1
  234.          ENDIF
  235.          DO dispinfo
  236.          RETURN(dflt)
  237.    ENDCASE
  238. RETURN(.T.)
  239.  
  240.  
  241. ********************************************
  242. PROCEDURE dispinfo
  243. ********************************************
  244.  
  245.  @  8,14 SAY address
  246.  @ 10,14 SAY city
  247.  @ 12,14 SAY state
  248.  @ 12,38 SAY zip PICTURE '99999'
  249.  @ 14,21 SAY busphone PICTURE '(###)###-####'
  250.  @ 16,21 SAY homephone PICTURE '(###)###-####'
  251.  @  8,62 SAY date 
  252.  
  253. RETURN
  254.  
  255.  
  256. ********************************************
  257. function GetEvent
  258. ********************************************
  259. parameter emode, getstart
  260.  
  261.   do case
  262.     case emode = ACTIVEGETS
  263.       if getstart > 0
  264.         read starting with getstart
  265.       else
  266.         read
  267.       endif
  268.     case emode = READSAVE
  269.       read save
  270.     case emode = WAITING
  271.       @ 0,0 say
  272.       wait ""
  273.     otherwise                      |NORMAL
  274.       return(chkevent())
  275.    endcase
  276. return(event())
  277.  
  278.  
  279. ********************************************
  280. function TranslateEvent(ievent)
  281. ********************************************
  282. parameter ievent
  283.  
  284. do case
  285.   case ievent = KEYBD_EVENT
  286.     key = LASTKEY()
  287.     DO CASE
  288.       CASE key = 27
  289.         RETURN(OUREXIT)
  290.       CASE key = 530
  291.         RETURN(OURPREV)
  292.       CASE key = 536
  293.         RETURN(OURNEXT)
  294.       OTHERWISE
  295.         RETURN(OUREDIT)
  296.     ENDCASE
  297.   case ievent = BUTTON_EVENT           | button event
  298.     STORE BUTTON() TO btext
  299.     DO CASE
  300.       CASE btext =  ' Next '
  301.         RETURN(OURNEXT)
  302.       CASE btext =  ' Prev '
  303.         RETURN(OURPREV)
  304.       CASE btext =  'Delete'
  305.         RETURN(OURDELETE)
  306.       CASE btext =  ' New  '
  307.         RETURN(OURNEW)
  308.       CASE btext =  'Cancel'
  309.         RETURN(OUREXIT)
  310.       CASE btext =  ' Edit '
  311.     ENDCASE
  312.  otherwise
  313.    BEEP
  314.    RETURN(0)
  315. endcase
  316. RETURN(OUREDIT)