home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / xbase / library / clipper / oop / oopexm / tformxyz.prg < prev   
Encoding:
Text File  |  1992-01-27  |  6.5 KB  |  239 lines

  1. **
  2. **  PROGRAM TITLE  : TFORMXYZ
  3. **
  4. **   WRITTEN BY    :  Paul Long
  5. **
  6. **   WRITTEN FOR   :  Copyright (C) 1992 All rights reserved. XL Systems, Inc.
  7. **
  8. **   PROGRAM INTENT:  Converts XYZ company's DSHS forms data
  9. **                    to GHOST data and adds it to the SERVICE.DBF file.
  10. **                    Name of forms input file is expected on command line.
  11. **
  12. **   NOTE:            This file uses "traditional," non-OOP programming.
  13. **
  14. #include "fileio.ch"
  15. #include "inkey.ch"
  16.  
  17. // Name of DBF that receives converted form data
  18. #define OUTDBFNAME   "service"
  19.  
  20.  
  21. local nHandle, nFormEntries
  22.  
  23. parameter cInputFile                      // Name of input file to convert
  24.  
  25. // Initialize variables to a known state
  26. public cLastName := "", cFirstName := "", cMiddleInitial := "", ;
  27.       cAcctNo := "", cExamNo := "", cPIC := "", cSSN := "", ;
  28.       dDOB := ctod("  /  /  "), adDOS := {}, ;
  29.       lFormFound := .t., ;
  30.       lDOSFileFound := .t.
  31.  
  32. if (nHandle := DOSFileNew(cInputFile)) != F_ERROR
  33.  
  34.    // Convert and add service entries to DBF
  35.    nFormEntries := FormAdd2DBF(nHandle, OUTDBFNAME)
  36.  
  37.    ?? ltrim(str(nFormEntries)) + ;
  38.             " entries were added to " + OUTDBFNAME + ".dbf"
  39.  
  40.    fclose(nHandle)
  41.  
  42. endif
  43.  
  44.  
  45. *******************************************************
  46. *
  47. *                             FormSkip
  48. *
  49. *******************************************************
  50. * Skip to next form.
  51. *
  52. function FormSkip(nHandle)
  53.  
  54. memvar lFormFound, lDOSFileFound
  55.  
  56. // Each form has "DSHS-OFFICE" at the top
  57. DOSFileLocate(nHandle, "DSHS-OFFICE")
  58. if lFormFound := lDOSFileFound
  59.    FormRead(nHandle)
  60. endif
  61.  
  62. return lFormFound
  63.  
  64.  
  65. *******************************************************
  66. *
  67. *                             FormRead
  68. *
  69. *******************************************************
  70. * Read the next form from the input file, saving pertinent data for latter
  71. * output by Write().
  72. *
  73. function FormRead(nHandle)
  74.  
  75. memvar cLastName, cFirstName, cMiddleInitial, cAcctNo, cExamNo, cPIC, cSSN, ;
  76.       dDOB, adDOS
  77.  
  78. local n, cRecord
  79.  
  80. cRecord := DOSFileSkip(nHandle, 9)        // Skip down to name line
  81. cLastName := substr(cRecord, 4, 15)
  82. cFirstName := substr(cRecord, 19, 13)
  83. cMiddleInitial := substr(cRecord, 32, 1)
  84. dDOB := ctod(substr(cRecord, 43, 8))
  85.  
  86. cRecord := DOSFileSkip(nHandle, 3)        // Skip down to PIC line
  87. cPIC := substr(cRecord, 56, 14)
  88.  
  89. cRecord := DOSFileSkip(nHandle, 31)       // Skip down to first service line
  90. adDOS := {}                               // Clear array from previous form
  91. for n = 1 to 6                            // Maximum of 6 services per form
  92.    if empty(substr(cRecord, 3, 6)) // If no more service, exit loop
  93.       exit
  94.    endif
  95.    // Reformat and convert date of service, then add to date-of-service array
  96.    aadd(adDOS, ctod(substr(cRecord, 3, 2) + "/" + ;
  97.          substr(cRecord, 5, 2) + "/" + substr(cRecord, 7, 2)))
  98.    cRecord := DOSFileSkip(nHandle, 2)     // (Double spaced)
  99. next     
  100.  
  101. // Skip down to account-number line
  102. cRecord := DOSFileSkip(nHandle, 20 - (2 * n))
  103. // (We can only hold the last 9 of the 10 account-number characters)
  104. cAcctNo := substr(cRecord, 5, 9)
  105.  
  106. return nil
  107.  
  108.  
  109. *******************************************************
  110. *
  111. *                             FormAdd2DBF
  112. *
  113. *******************************************************
  114. * Convert forms data to GHOST data and add to DBF
  115. *
  116. function FormAdd2DBF(nHandle, cDBF)
  117.  
  118. local nFormEntries := 0
  119.  
  120. memvar cLastName
  121.  
  122. if file(cDBF + ".dbf")                    // Make sure output .DBF exists
  123.    use (cDBF) exclusive new
  124.    if neterr()
  125.       ?? "*** ERROR *** " + cDBF + ".dbf cannot be opened"
  126.    else
  127.       do while FormSkip(nHandle)          // Read each form
  128.          FormWrite(cDBF)                  // Write data for this form
  129.          ?? ++nFormEntries, cLastName, chr(K_RETURN)  // Tell user progess
  130.       enddo
  131.       (cDBF)->(dbclosearea())
  132.    endif
  133. else
  134.    ?? "*** ERROR *** " + cDBF + ".dbf file is missing"
  135. endif
  136.  
  137. return nFormEntries
  138.  
  139.  
  140. *******************************************************
  141. *
  142. *                             FormWrite
  143. *
  144. *******************************************************
  145. * Write service information from the current form.
  146. *
  147. function FormWrite(cDBF)
  148.  
  149. memvar cLastName, cFirstName, cMiddleInitial, cAcctNo, cExamNo, cPIC, cSSN, ;
  150.       dDOB, adDOS
  151.  
  152. // Add n records to DBF
  153. aeval(adDOS, { | dDOS | ;
  154.       (cDBF)->(dbappend()), ;
  155.       (cDBF)->acctno := cAcctNo, ;
  156.       (cDBF)->examno := cExamNo, ;
  157.       (cDBF)->svcdate := dDOS, ;
  158.       (cDBF)->ssn := cSSN, ;
  159.       (cDBF)->pic := cPIC, ;
  160.       (cDBF)->firstname := cFirstName, ;
  161.       (cDBF)->midinitial := cMiddleInitial, ;
  162.       (cDBF)->lastname := cLastName, ;
  163.       (cDBF)->birthdate := dDOB ;
  164.                })
  165.  
  166. return nil
  167.  
  168.  
  169. *******************************************************
  170. *
  171. *                             DOSFileNew
  172. *
  173. *******************************************************
  174. * Construct DOSFile object mainly by opening input file
  175. *
  176. function DOSFileNew(cFileName)
  177.  
  178. local nHandle := F_ERROR
  179.  
  180. if cFileName == nil
  181.    ?? "*** ERROR *** missing file name"
  182. else
  183.    if (nHandle := fopen(cFileName, FO_READ)) == F_ERROR
  184.       ?? "*** ERROR *** " + cFileName + " cannot be opened"
  185.    endif
  186. endif
  187.  
  188. return nHandle
  189.  
  190.  
  191. *******************************************************
  192. *
  193. *                             DOSFileSkip
  194. *
  195. *******************************************************
  196. * Skip forward through file and read the last, nth record.
  197. * Currently, non-positive skips are treated like DOSFileSkip(1).
  198. * This should probably be changed to accomodate non-positive
  199. * skips.
  200. *
  201. function DOSFileSkip(nHandle, nRecords)
  202.  
  203. local n
  204.  
  205. memvar lDOSFileFound
  206.  
  207. // If nil argument, treat like Skip(1)
  208. nRecords := if(nRecords == nil, 0, nRecords - 1)
  209. lDOSFileFound := .t.
  210.  
  211. for n = 1 to nRecords
  212.    if !(lDOSFileFound := fadvance(nHandle) != F_ERROR)
  213.       exit
  214.    endif
  215. next
  216.  
  217. // Read and return nth record if skip succeeded; otherwise, return null string
  218. return if(lDOSFileFound, freadline(nHandle), "")
  219.  
  220.  
  221. *******************************************************
  222. *
  223. *                             DOSFileLocate
  224. *
  225. *******************************************************
  226. * Search for string in file.  If found, the entire record is read in, and
  227. * file pointer is moved to beginning of next record; otherwise, null string
  228. * is returned.
  229. *
  230. function DOSFileLocate(nHandle, cString)
  231.  
  232. memvar lDOSFileFound
  233.  
  234. if lDOSFileFound := flocate(nHandle, cString) >= 0
  235.    fbol(nHandle)
  236. endif
  237.  
  238. return if(lDOSFileFound, freadline(nHandle), "")
  239.