6. Embedded QUEL for BASIC : Sample Applications : The Professor-Student Mixed Form Application
 
Share this page                  
The Professor-Student Mixed Form Application
This EQUEL/FORMS application lets the user browse and update information about graduate students who report to a specific professor. The program is structured in a master/detail fashion, with the professor being the master entry, and the students the detail entries. The application uses two forms--one to contain general professor information and another for detailed student information.
The objects used in this application are:
Object
Description
personnel
The program's database environment.
professor
A database table with two columns:
pname (c25)
pdept (c10)
See its create statement below for a full description.
student
A database table with seven columns:
sname (c25)
sage (i1)
sbdate (c25)
sgpa (f4)
sidno (i1)
scomment (text(200))
advisor (c25)
See the create statement below for a full description. The sadvisor column is the join field with the pname column in the Professor table.
masterfrm
The main form has the Pname and Pdept fields, which correspond to the information in the Professor table, and table field studenttbl. The Pdept field is display-only. "Masterfrm" is a compiled form.
studenttbl
A table field in "masterfrm" with the sname and sage columns. When initialized, it also has five more hidden columns corresponding to information in the Student table.
studentfrm
The detail form, with seven fields, which correspond to information in the Student table. Only the Sgpa, Scomment and Sadvisor fields are updatable. All other fields are display-only. "Studentfrm" is a compiled form.
grad
A global structure, whose members correspond in name and type to the columns of the Student database table, the "studentfrm" form and the studenttbl table field.
The program uses the "masterfrm" as the general-level master entry, in which data can only be retrieved and browsed, and the "studentfrm" as the detailed screen, in which specific student information can be updated.
The runtime user enters a name in the Pname (professor name) field and then selects the Students menu operation. The operation fills the displayed and hidden columns of the Studenttbl table field with detailed information of the students reporting to the named professor.
The user may then browse the table field (in read mode), which displays only the names and ages of the students. More information about a specific student may be requested by selecting the Zoom menu operation. This operation displays the form "studentfrm." The fields of "studentfrm" are filled with values stored in the hidden columns of "studenttbl."
The user can make changes to the Sgpa, Scomment and Sadvisor fields. If validated, these changes are written back to the database table (based on the unique student id), and to the table field's data set. This process can be repeated for different professor names.
The following two create statements describe the Professor and Student database tables:
     ##      create student                ! Graduate student table 
     ##             (sname = c25,          ! Name 
##                   sage = i1,            ! Age
##                   sbdate = c25,         ! Birth date 
##                   sgpa = f4,            ! Grade point average 
##                   sidno = i4,           ! Unique student number
##                   scomment = text(200), ! General comments 
##                   sadvisor = c25)       ! Advisor's name

     ##      create professor              ! Professor table 
##                (pname = c25,            ! Professor's name
##                 pdept = c10)            ! Department
10   ## declare ingres

      ! Master and student compiled forms (imported objects)
     ## external integer masterfrm, studentfrm

      ! Program: Prof_Student
      ! Purpose: Main body of "Professor Student" Master-Detail application. 

      ! Graduate student record maps to "student" database table 
       ## record Student_Rec
       ##                    string sname = 25
       ##                    byte sage
       ##                    string sbdate = 15
       ##                    real sgpa
       ##                    integer sidno
       ##                    string scomment = 200
       ##                    string sadvisor = 25
       ## end record
       ## declare Student_Rec grad

      ! Professor record maps to "professor" database table 
       ## record Prof_Rec
       ##                    string pname = 25
       ##                    string pdept = 10
       ## end record
       ## declare Prof_Rec prof

      ! Useful forms runtime information 
       ## declare integer lastrow,   ! Lastrow in table field 
       ##                 istable    ! Is a table field?

      ! Utility buffers 
       ## declare string msgbuf,       ! Message buffer 
       ##                respbuf,      ! Response buffer 
       ##                old_advisor   ! Old advisor before ZOOM
       ! Function: Student_Info_Changed
       ! Purpose:  Allow the user to zoom into the details of a
       !           selected student. Some of the data can be
       !           updated by the user. If any updates were made,
       !           then reflect these back into the database table.
       !           The procedure returns 1 if any changes were made.
       ! Parameters:
       !           None
       ! Returns:
       !                   1/0 - Changes were made to the database.
       !                   Sets the global "grad" record with the new data.
       ## def integer Student_Info_Changed

       ## declare integer changed,        ! Changes made to the form?
       ##                 valid_advisor   ! Valid advisor name?

      ! Display the detailed student information
       ## display #studentfrm fill
       ## initialize
       ##                   (sname = grad::sname,
       ##                    sage = grad::sage,
       ##                    sbdate = grad::sbdate,
       ##                    sgpa = grad::sgpa,
       ##                    sidno = grad::sidno,
       ##                    scomment = grad::scomment,
       ##                    sadvisor = grad::sadvisor)

       ## activate menuitem "Write"
       ## {
      If changes were made then update the
      ! database table. Only bother with the
      ! fields that are not read-only.

      ## inquire_frs form (changed = change)

      if (changed = 1) then
      ##       validate
      ##       message "Writing to database. . ."

      ##       getform
      ##          (grad::sgpa = sgpa,
      ##           grad::scomment = scomment,
      ##           grad::sadvisor = sadvisor)

           ! Enforce integrity of professor name
             valid_advisor = 0
      ##           retrieve
      ##               (valid_advisor = 1)
      ##                  where p.pname = grad::sadvisor

             if (valid_advisor = 0) then
      ##               message "Not a valid advisor name"
      ##               sleep 2
      ##               resume field sadvisor
             else
      ##               replace s 
      ##                       (sgpa = grad::sgpa,
            ##                  comment = grad::scomment,
            ##                  sadvisor = grad::sadvisor)
            ##                  where s.sidno = grad::sidno
            ##         breakdisplay
             end if
          end if
      ## } ! "Write"
      ## activate menuitem "End" , frskey3
      ## {
                   ! Quit without submitting changes 
                   changed = 0
      ##              breakdisplay
      ## } ! "Quit" 
      ## finalize

      Student_Info_Changed = changed

      ## end def ! Student_Info_Changed;

      ! Start up Ingres and the Forms system 
      ## forms

      ## message "Initializing Student Administrator . . ."
      ## ingres personnel

      ## range of p is professor, s is student

      ## addform masterfrm
      ## addform studentfrm

      ! Initialize "studenttbl" with a data set in READ mode.
      ! Declare hidden columns for all the extra fields that
      ! the program will display when more information is
      ! requested about a student. Columns "sname" and "sage"
      ! are displayed, all other columns are hidden, to be
      ! used in the student information form.

      ## inittable #masterfrm studenttbl read
      ##                   (sbdate = char(25),
      ##                         sgpa = float,
      ##                         sidno = integer,
      ##                         scomment = char(200),
      ##                         sadvisor = char(20))
      ! Drive the application, by running "masterfrm", and
      ! allowing the user to "zoom" into a selected student.
      ## display #masterfrm update

      ## initialize
      ## {
      ##         message "Enter an Advisor name . . ."
      ##         sleep 2
      ## }
      ## activate menuitem "Students", field "pname"
      ## {
                 ! Load the students of the specified professor 
      ##         getform (prof::pname = pname)

                 ! If no professor name is given then resume 
                 if (len(edit$(prof::pname,8)) = 0) then
                     ## resume field pname
                 end if

                 ! Verify that the professor exists. If not print
                 ! print a message, and continue. We assume that
                 ! each professor has exactly one department.

                 prof::pdept = space$(10)
      ##            retrieve (prof::pdept = p.pdept)
      ##                where p.pname = prof::pname

                 ! If no professor report error
                 if (len(edit$(prof::pdept,8)) = 0) then
                             msgbuf = 'No professor with name "' &
                             + trm$(prof::pname) + '" [RETURN]'
      ##                     prompt noecho (msgbuf, respbuf)
      ##                     clear field all
      ##                     resume field pname
                 end if

                 ! Fill the department field and load students 
      ##         message "Retrieving Student Information . . ."

      ##         putform (pdept = prof::pdept)
      ##         clear field studenttbl
      ##         redisplay ! Refresh for query
               ! With the advisor name, load into the "studenttbl" table field 
               ! all the graduate students who report to the professor with 
               ! that name.
               ! Columns "sname" and "sage" will be displayed, 
               ! and all other columns will be hidden.

      ##         retrieve
      ##                      (grad::sname = s.sname,
      ##                       grad::sage = s.sage,
      ##                      grad::sbdate = s.sbdate,
      ##                       grad::sgpa = s.sgpa,
      ##                       grad::sidno = s.sidno,
      ##                       grad::scomment = s.scomment,
      ##                       grad::sadvisor = s.sadvisor)
      ##                       where s.sadvisor = prof::pname
      ##                      {
      ##                      loadtable #masterfrm studenttbl
      ##                              (sname = grad::sname,
      ##                               sage = grad::sage,
      ##                               sbdate = grad::sbdate,
      ##                               sgpa = grad::sgpa,
      ##                               sidno = grad::sidno,
      ##                               comment = grad::scomment,
      ##                               advisor = grad::sadvisor)
      ##                      }

      ##     resume field studenttbl
      ## } ! "Students"

      ## activate menuitem "Zoom"
      ## {
                   ! Confirm that user is on "studenttbl", and that
                   ! the table field is not empty. Collect data from
                   ! the row and zoom for browsing and updating.

      ##          inquire_frs field #masterfrm (istable = table)
                  if (istable = 0) then
      ##                    prompt noecho
      ##                        ("Select from the student table [RETURN]",
      ##                        respbuf)
      ##                   resume field studenttbl
                   end if

            ## inquire_frs table #masterfrm (lastrow = lastrow)
            if (lastrow = 0) then
      ##                prompt noecho
      ##                ("There are no students [RETURN]",
      ##                respbuf)
      ##         resume field pname
             end if
            ! Collect all data on student into graduate record 
      ##    getrow #masterfrm studenttbl
      ##           (grad::sname = sname,
      ##            grad::sage = sage,
      ##            grad::sbdate = sbdate,
      ##            grad::sgpa = sgpa,
      ##            grad::sidno = sidno,
      ##            grad::scomment = scomment,
      ##            grad::sadvisor = sadvisor)

           ! Display "studentfrm", and if any changes were made
           ! make the updates to the local table field row.
           ! Only make updates to the columns corresponding to
           ! writable fields in "studentfrm". If the student
           ! changed advisors, then delete this row from the
           ! display.

           old_advisor = grad::sadvisor
           if (Student_Info_Changed = 1) then
                  if not (old_advisor = grad::sadvisor) then
      ##                         deleterow #masterfrm studenttbl
                  else
      ##                         putrow #masterfrm studenttbl
      ##                         (sgpa = grad::sgpa,
      ##                          scomment = grad::scomment,
      ##                          sadvisor = grad::sadvisor)
                  end if
           end if

      ## }                   ! "Zoom"

      ## activate menuitem "Quit" , frskey2
      ## {
      ##             breakdisplay
      ## }                     ! "Exit"

      ## finalize

      ## clear screen
      ## endforms
      ## exit

      ## end                   ! main