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

  1. **
  2. **  PROGRAM TITLE  : FORM
  3. **
  4. **   WRITTEN BY    :  Paul Long
  5. **
  6. **   WRITTEN FOR   :  Copyright (C) 1992 All rights reserved. XL Systems, Inc.
  7. **
  8. **   PROGRAM INTENT:  Class for converting DSHS forms data to GHOST data
  9. **                    and adds it to a DBF.
  10. **
  11. #include "oclip.ch"
  12. #include "inkey.ch"
  13.  
  14.  
  15. // Form abstract superclass definition
  16. CLASS Form
  17.    VAR oFile                              // File.  Contains form data
  18.    VAR oFound                             // Boolean.  Whether search succeeded
  19.    VAR nEntries                           // Service entries on current form
  20.  
  21.    // Fields transfered from form to DBF
  22.    VAR cLastName
  23.    VAR cFirstName
  24.    VAR cMiddleInitial
  25.    VAR dDOB
  26.    VAR cAcctNo
  27.    VAR cExamNo
  28.    VAR adDOS
  29.    VAR cPIC
  30.    VAR cSSN
  31.  
  32.    METHOD New = FormNew                   // Constructor
  33.    METHOD Destruct = FormDestruct         // Destructor
  34.    METHOD Add2DBF = FormAdd2DBF           // Convert and add form data to .DBF
  35.    METHOD Entries = FormEntries           // Return number of service entries
  36.    METHOD Skip                            // Skip to next form
  37.    METHOD Read
  38.       // Read() reads the current form data from the input file, saving
  39.       // pertinent data for latter output by Write().  Data
  40.       // is stored in the following instance variables: cLastName,
  41.       // cFirstName, cMiddleInitial, dDOB, cAcctNo, cExamNo, adDOS,
  42.       // cPIC, and cSSN.  Read() and Skip() must be provided by the subclass.
  43.       // Because of this, Form is an abstract class.
  44.    METHOD Found = FormFound               // Return whether search succeeded
  45.    METHOD Write = FormWrite               // Write form data out to .DBF
  46. ENDCLASS
  47.  
  48.  
  49. *******************************************************
  50. *
  51. *                             FormNew
  52. *
  53. *******************************************************
  54. * Construct Form object mainly by constructing DOSFile object.
  55. *
  56. METHOD FUNCTION FormNew(cFileName)
  57.  
  58. // Initialize all instance variables to a known state
  59. ::nEntries := 0
  60. ::cLastName := ::cFirstName := ::cMiddleInitial := ""
  61. ::cAcctNo := ::cExamNo := ::cPIC := ::cSSN := ""
  62. ::dDOB := ctod("  /  /  ")
  63. ::adDOS := {}
  64. ::oFile := DOSFile():New(cFileName)
  65. ::oFound := Boolean():New(.t.)
  66.  
  67. return if(::oFile == nil, nil, Self)
  68.  
  69.  
  70. *******************************************************
  71. *
  72. *                             FormDestruct
  73. *
  74. *******************************************************
  75. * Destruct form object by destructing input file
  76. *
  77. METHOD FUNCTION FormDestruct
  78.  
  79. ::oFile:Destruct()
  80.  
  81. return nil
  82.  
  83.  
  84. *******************************************************
  85. *
  86. *                             FormAdd2DBF
  87. *
  88. *******************************************************
  89. * Convert forms data to GHOST data and add to DBF
  90. *
  91. METHOD FUNCTION FormAdd2DBF(cDBF)
  92.  
  93. if file(cDBF + ".dbf")                    // Make sure output .DBF exists
  94.    use (cDBF) exclusive new
  95.    if neterr()
  96.       ?? "*** ERROR *** " + cDBF + ".dbf cannot be opened"
  97.    else
  98.       do while ::Skip():Found()           // Read each form
  99.          ::Write(cDBF)                    // Write data for this form
  100.          ?? ++::nEntries, ::cLastName, chr(K_RETURN)  // Tell user progess
  101.       enddo
  102.       (cDBF)->(dbclosearea())
  103.    endif
  104. else
  105.    ?? "*** ERROR *** " + cDBF + ".dbf file is missing"
  106. endif
  107.  
  108. return Self
  109.  
  110.  
  111. *******************************************************
  112. *
  113. *                             FormEntries
  114. *
  115. *******************************************************
  116. * Return number of entries in last-converted form
  117. *
  118. METHOD FUNCTION FormEntries
  119.  
  120. return ::nEntries
  121.  
  122.  
  123. *******************************************************
  124. *
  125. *                             FormWrite
  126. *
  127. *******************************************************
  128. * Write service information from the current form.
  129. *
  130. METHOD FUNCTION FormWrite(cDBF)
  131.  
  132. // Add n records to DBF
  133. aeval(::adDOS, { | dDOS | ;
  134.       (cDBF)->(dbappend()), ;
  135.       (cDBF)->acctno := ::cAcctNo, ;
  136.       (cDBF)->examno := ::cExamNo, ;
  137.       (cDBF)->svcdate := dDOS, ;
  138.       (cDBF)->ssn := ::cSSN, ;
  139.       (cDBF)->pic := ::cPIC, ;
  140.       (cDBF)->firstname := ::cFirstName, ;
  141.       (cDBF)->midinitial := ::cMiddleInitial, ;
  142.       (cDBF)->lastname := ::cLastName, ;
  143.       (cDBF)->birthdate := ::dDOB ;
  144.                })
  145.  
  146. return Self
  147.  
  148.  
  149. *******************************************************
  150. *
  151. *                             FormFound
  152. *
  153. *******************************************************
  154. * Return whether last search succeeded.
  155. *
  156. METHOD FUNCTION FormFound(lWhetherFound)
  157.  
  158. return ::oFound:Value(lWhetherFound)
  159.