home *** CD-ROM | disk | FTP | other *** search
/ Piper's Pit BBS/FTP: ibm 0010 - 0019 / ibm0010-0019 / ibm0010.tar / ibm0010 / CLIPB52.ZIP / ZINKY.ZIP / EDIT.PRG < prev    next >
Encoding:
Text File  |  1990-05-01  |  8.7 KB  |  304 lines

  1. ********************************
  2. *                              *
  3. *     EDIT.PRG                 *
  4. *                              *
  5. * SUB PROGRAM OF SAMPLE.PRG    *
  6. *                              *     
  7. ********************************
  8.  
  9. *If you are sure that you have variables that will be
  10. *used in one module only, declare them PRIVATE. This
  11. *allows the programmer to use the same variable names
  12. *in different modules, while keeping the values of
  13. *those variables local to that module. Declaring
  14. *variables PRIVATE also ensures that memory will be
  15. *freed when the module is exited. It is a good idea to
  16. *declare arrays used by DBEDIT()as PRIVATE.
  17.  
  18. PRIVATE io_flg, Am_fields[4], Am_namees[4]
  19. io_flg=.T.             && Flag to be used for io later
  20. scr_color = "w/n,r+/b"
  21. CLEAR
  22. SET CURSOR ON
  23. DO MAKEDBF
  24. @ 0,0,24,79 BOX boxframe
  25. SET COLOR TO &scr_color
  26.  
  27. *The subscript value must be as large as the amount of
  28. *fields you choose to use in the DBEDIT() window. In
  29. *this model Am_fields was the author's choice of
  30. *variable name for the fields to be displayed and
  31. *Am_namees was the name chosen for the titles for the
  32. *display.
  33.  
  34. Am_fields[1] = 'Del'
  35. Am_fields[2] = 'SUBSTR(artist,1,20)'
  36. Am_fields[3] = 'condition'
  37. Am_fields[4] = 'STR(book_value,6,2)'
  38. Am_namees[1] = 'Del'
  39. Am_namees[2] = 'Artist'
  40. Am_namees[3] = 'Condition'
  41. Am_namees[4] = 'Book Value'
  42.  
  43. @14,04 TO 21,44
  44. @15,5 SAY "INSERT Key to ADD     records          "
  45. @16,5 SAY "RETURN Key to EDIT    records          "
  46. @17,5 SAY "F5 Key to SEARCH for  record           "
  47. @18,5 SAY "DELETE Key - mark for deletion         "
  48. @19,5 SAY "F4    to make/edit   a memo            "
  49. @20,5 SAY "ESC TO QUIT                            "
  50. DBEDIT(3,3,12,74,Am_fields,"Audf",.t.,Am_namees)
  51.  
  52. *A full coverage of DBEDIT() is beyond our scope,
  53. *however this model includes a brief explanation. The
  54. *numerical parameters contained in the paranthesis,
  55. *locate the upper left and lower right dimensions of
  56. *the DBEDIT() window. Am_fields references the field
  57. *you have chosen. Audf references a user defined
  58. *function to handle the exception keys read by
  59. *DBEDIT(). For example DBEDIT() reads the down-arrow
  60. *and page-up. Those keys are already defined to
  61. *DBEDIT() and not exception keys. If however, you
  62. *wanted to define a search function when a certain key
  63. *is pressed, this is where it would be read. The next
  64. *parameter .T. allows editing of the database. If .F.
  65. *(false) is sent, only browsing is allowed. The last
  66. *parameter Am_namees holds the titles you wish
  67. *displayed.
  68.  
  69. CLOSE ALL                     &&Close the database.
  70. CLEAR SCREEN 
  71. RETURN
  72.  
  73. *The Audf function is a "user-defined" function, and is
  74. *continually called by DBEDIT() to see if any of the
  75. *exception keys have been defined. The two parameters
  76. *(mode and fld_ptr) are required. DBEDIT() modes are:
  77. *You should use the case statement for all your
  78. *exception key statements.
  79. *  0. Idle, all key strokes have been                   
  80. *     processed;nothing pending.
  81. *  1. Attempt to move cursor past beginning of file.
  82. *  2. Attempt to move cursor past end of file.
  83. *  3. Data file is empty.
  84. *  4. Keystroke exception.
  85.  
  86. *The second parameter passes the exact field the cursor
  87. *is positioned on in DBEDIT().
  88. *RETURN(0)- Returning 0 is the value that DBEDIT()
  89. *interprets as exit.
  90.  
  91. *RETURN(1)- Returning 1 is continue DBEDIT().
  92.  
  93. *RETURN(2)- Returning 2 is repaint window and continue.
  94.  
  95. FUNCTION Audf            
  96. PARAMETERS mode,fld_ptr     
  97. Acur_field = Am_fields[fld_ptr]
  98. IF mode < 4                    
  99.   RETURN(1)                
  100. ENDIF                       
  101.  
  102. IF LASTKEY() = 27           
  103.   SAVE SCREEN TO quit_scr
  104.   quit_in = 3              
  105.   @  2,50 SAY '╓───────────────────┐'
  106.   @  3,50 SAY '║    Quit Menu      │'
  107.   @  4,50 SAY '╟───────────────────┤'
  108.   @  5,50 SAY '║ Return to Program │'
  109.   @  6,50 SAY '║ Quit              │'
  110.   @  7,50 SAY '╚═══════════════════╛'
  111.   @  5,52 PROMPT 'Return to Program'
  112.   @  6,52 PROMPT 'Quit             '
  113.   MENU TO quit_in
  114.   IF quit_in = 1 .OR. quit_in = 0
  115.     RESTORE SCREEN FROM quit_scr
  116.     RETURN(1)
  117.   ENDIF
  118.   IF quit_in = 2
  119.     RETURN(0)
  120.   ENDIF
  121. ENDIF
  122. DO CASE
  123.   CASE LASTKEY() = -4  && F5
  124.     SAVE SCREEN TO Ascr_hold
  125.     @ 20,01 SAY "┌─────────────────────────┐"
  126.     @ 21,01 SAY "│Search For:              │"
  127.     @ 22,01 SAY "└─────────────────────────┘"
  128.     search_in = SPACE(80)
  129.     @ 21,13 GET search_in PICTURE "@S14!"
  130.     READ
  131.     SET SOFTSEEK ON
  132.     SEEK search_in
  133.     RESTORE SCREEN FROM Ascr_hold
  134.     SET COLOR TO &scr_color
  135.     SET SOFTSEEK OFF
  136.     RETURN(2)
  137.   CASE LASTKEY() = 7     && Delete Key
  138.     SAVE SCREEN TO Ascr_1
  139.     DO Adel_rec
  140.     RESTORE SCREEN FROM Ascr_1
  141.     SET COLOR TO &scr_color
  142.     RETURN(2)
  143.   CASE LASTKEY() = -3
  144.     SAVE SCREEN TO Ascr_1
  145.     CLEAR
  146.     @ 3,30 SAY 'WRITE OR EDIT YOUR MEMO'
  147.     @ 4,4 to 21,66
  148.     @ 22,30 SAY 'CTRL-W TO SAVE  <ESC>ABORT'
  149.     IF Rlok()
  150.       REPLACE MEMO WITH MEMOEDIT(MEMO,5,5,20,65,.T.)
  151.     ENDIF
  152.     UNLOCK
  153.     COMMIT
  154.  
  155.  
  156. *The COMMIT command sends a message to the operating
  157. *system to write to the database a soon as possible and
  158. *not hold in buffer. This command requires DOS 3.3 or
  159. *higher.
  160.  
  161.     RESTORE SCREEN FROM Ascr_1
  162.     RETURN(2)
  163.   CASE LASTKEY() = 13     && Return Key
  164.     SET CURSOR ON
  165.     SAVE SCREEN TO Ascr_1
  166.     DO Aio WITH .F.,.F.           &&   Editing Records
  167.     RESTORE SCREEN FROM Ascr_1
  168.     SET COLOR TO &scr_color
  169.     RETURN(1)
  170.   CASE LASTKEY() = 22     && Insert Key Or Ctrl-U
  171.     SET CURSOR ON
  172.     SAVE SCREEN TO Ascr_1
  173.     DO Aio WITH .T.,io_flg
  174.     RESTORE SCREEN FROM Ascr_1
  175.     SET COLOR TO &scr_color
  176.     RETURN(2)
  177. ENDCASE
  178. RETURN(1)
  179.  
  180. *The basic concept behind the Aio procedure is 
  181. *aimed at network applications. That is, you should
  182. *have the user inputting data to memory variables, as
  183. *opposed to referencing the field names of the
  184. *database.
  185.  
  186. *The user still has the option to ESC and abort or to
  187. *enter the data and commit it to the file.
  188. *This keeps the record from being locked while they are
  189. *editing, correcting, or inputting.
  190.  
  191. PROCEDURE Aio
  192. PARAMETERS add_flg,val_flg
  193. SET COLOR TO W/N
  194. @ 15,03,23,54 BOX "╔═╗║╝═╚║ "
  195. @ 16,04 SAY "Artist  :"
  196. @ 17,04 SAY "Title   :"
  197. @ 18,04 SAY "Condit. :"
  198. @ 19,04 SAY "Remarks :"
  199. @ 20,04 SAY "Year    :"
  200. @ 21,04 SAY "Book Val:"
  201. @ 22,04 SAY "Catalog :"
  202. SET CURSOR ON
  203. IF val_flg
  204.   m_artist = SPACE(40)
  205.   m_title = SPACE(40)
  206.   m_condition = SPACE(10)
  207.   m_remarks = SPACE(35)
  208.   m_yr_release = SPACE(4)
  209.   m_book_value = 0.00
  210.   m_catalog = SPACE(30)
  211. ENDIF
  212. IF .NOT. val_flg
  213.   m_artist = artist
  214.   m_title = title
  215.   m_condition = condition
  216.   m_remarks = remarks
  217.   m_yr_release = yr_release
  218.   m_book_value = book_value
  219.   m_catalog = catalog
  220. ENDIF
  221. @ 16,13 GET m_artist PICTURE;                           
  222.   "@K!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
  223. @ 17,13 GET m_title  PICTURE;                           
  224.   "@K!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
  225. @ 18,13 GET m_condition PICTURE "@K!!!!!!!!"
  226. @ 19,13 GET m_remarks PICTURE;                          
  227.   "@K!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
  228. @ 20,13 GET m_yr_release PICTURE "@K!!"
  229. @ 21,13 GET m_book_value PICTURE "999.99"
  230. @ 22,13 GET m_catalog PICTURE;                          
  231.   "@K!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
  232. READ
  233. IF LASTKEY() <> 27  && ESC KEY
  234.   IF add_flg
  235.     APPEND BLANK
  236.   ENDIF
  237.   IF Rlok()
  238.     REPLACE artist     WITH m_artist
  239.     REPLACE title      WITH m_title
  240.     REPLACE condition  WITH m_condition
  241.     REPLACE remarks    WITH m_remarks
  242.     REPLACE yr_release WITH m_yr_release
  243.     REPLACE book_value WITH m_book_value
  244.     REPLACE catalog    WITH m_catalog
  245.   ENDIF
  246.   UNLOCK
  247.   COMMIT
  248. ENDIF
  249. RETURN
  250.  
  251. PROCEDURE Adel_rec
  252.  
  253. *Note that in this procedure, to pack a database
  254. *requires that you have exclusive use. 
  255.  
  256. SET COLOR TO &scr_color
  257. @ 01,00,08,12 BOX "┌─┐│┘─└│"
  258. @ 03,00 SAY "├"
  259. @ 03,12 SAY "┤"
  260. SET COLOR TO &scr_color
  261. @ 02,01,07,11 BOX "         "
  262. @ 02,01 SAY  "DELETE MENU"
  263. @ 03,00 SAY "├───────────┤"
  264. @ 04,01 SAY  "Return     "
  265. @ 05,01 SAY  "Delete Rec."
  266. @ 06,01 SAY  "ReCall Rec."
  267. @ 07,01 SAY  "Pack Data  "
  268. SET COLOR TO &scr_color
  269. SET WRAP ON
  270. SET MESSAGE TO
  271. @ 04,01 PROMPT "Return     "
  272. @ 05,01 PROMPT "Delete Rec."
  273. @ 06,01 PROMPT "ReCall Rec."
  274. @ 07,01 PROMPT "Pack Data  "
  275. MENU TO Adel_in
  276. DO CASE
  277.   CASE Adel_in = 0 .OR. Adel_in = 1
  278.     RETURN
  279.   CASE Adel_in = 2
  280.     IF Rlok()
  281.       REPLACE del WITH '*'
  282.       DELETE
  283.     ENDIF
  284.     COMMIT
  285.   CASE Adel_in = 3
  286.     IF Rlok()
  287.       REPLACE del WITH ' '
  288.       RECALL
  289.     ENDIF
  290.   CASE Adel_in = 4
  291.      CLOSE ALL
  292.      SET EXCLUSIVE ON
  293.      USE a_d INDEX a_d
  294.      PACK
  295.      CLOSE ALL
  296.      SET EXCLUSIVE OFF
  297.      USE a_d INDEX a_d
  298.      RETURN
  299. ENDCASE
  300. SET COLOR TO &scr_color
  301. RETURN
  302.  
  303.  
  304.