Linux--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 application uses the following objects:
The program uses the "masterfrm" as the general-level master entry, in which the user can only retrieve and browse data, and the "studentfrm" as the detailed screen, in which the user can update specific student information.
The 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 about the students of the named professor. The user may then browse the table field (in read mode), which displays only the names and ages of the students. To request more information about a specific student, the user can select 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 three fields (sgpa, scomment and sadvisor). 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. The user can repeat this process for different professor names.
The application runs on Linux.
Linux: 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 */
C
C Procedure: MAIN
C Purpose: Start up program and call Master driver.
C
## program main
C Start up Ingres and the FORMS system
## declare forms
## forms
## message 'Initializing Student Administrator . . .'
## INGRES personnel
## range of p IS professor, s IS student
call Master()
## clear screen
## endforms
## exit
## end
C
C Procedure: Master
C Purpose: Drive the application, by running 'mstfrm', and
C allowing the user to 'zoom' into a
C selected student.
C Parameters:
C None - Uses the global student 'grad' record.
C
## subroutine Master()
## declare forms
C Declare function
logical StdChg
C grad student record maps to database table
C Student's name
## character*25 Sname
C Student's age
## integer*2 Sage
C Student's birthday
## character*25 Sbdate
C Student's grade point average
## real*4 Sgpa
C Student's unique id number
## integer*4 Sidno
C General comment field
## character*200 Scomm
C Student's advisor
## character*25 Sadv
C Professor info maps to database table
C Professor's name
## character*25 Pname
C Professor's department
## character*10 Pdept
C Useful forms system information
C Last row in table field
## integer*4 lstrow
C Is it a table field ?
# integer*4 istab
C Local utility buffers
C Message buffer
## character*100 msgbuf
C Response buffer
## character*256 rspbuf
C Old advisor before ZOOM
## character*25 oldadv
C Externally compiled master form
external mstfrm
## integer*4 mstfrm
## addform mstfrm
C
C Initialize 'studenttbl' with a data set in READ mode.
C Declare hidden columns for all the extra fields that
C the program will display when more information is
C requested about a student. Columns 'sname' and 'sage'
C are displayed, all other columns are hidden, to be
C used in the student information form.
C
## inittable #mstfrm studenttbl read
## (#sbdate = c25,
## #sgpa = f4,
## #sidno = i4,
## #scomment = text(200),
## #sadvisor = c20)
## display #mstfrm update
## initialize
## {
## message 'Enter an Advisor name . . .'
## sleep 2
## }
## activate menuitem 'Students', field 'pname'
## {
C Load the students of the specified professor
Pname = ' '
## getform (Pname = #pname)
C If no professor name is given then resume
if (Pname .EQ. ' ') then
## resume field #pname
endif
C
C Verify that the professor exists. Local error
C handling just prints the message, and continues.
C We assume that each professor has exactly one
C department.
C
Pdept = ' '
## retrieve (Pdept = p.#pdept)
## where p.#pname = Pname
if (Pdept .EQ. ' ') then
msgbuf = 'No professor with name "' // Pname //
& '"[RETURN]'
## prompt noecho (msgbuf, rspbuf)
## clear field all
## resume field #pname
endif
C Fill the department field and load students
## putform (#pdept = Pdept)
## redisplay /* Refresh for query */
call LdStd (Pname)
## resume field studenttbl
## } /* 'Students' */
## activate menuitem 'Zoom'
## {
C
C Confirm that user is on 'studenttbl', and that
C the table field is not empty. Collect data from
C the row and zoom for browsing and updating.
C
## inquire_frs field #mstfrm (istab = table)
if (istab .EQ. 0) then
## prompt noecho
## ('Select from the student table [RETURN]', rspbuf)
## resume field studenttbl
endif
## inquire_frs table #mstfrm (lstrow = lastrow)
if (lstrow .EQ. 0) then
## prompt noecho ('There are no students [RETURN]', rspbuf)
## resume field #pname
endif
C Collect all data on student into global record
## getrow #mstfrm studenttbl
## (Sname = #sname,
## Sage = #sage,
## Sbdate = #sbdate,
## Sgpa = #sgpa,
## Sidno = #sidno,
## Scomm = #scomment,
## Sadv = #sadvisor)
C
C Display 'stdfrm', and if any changes were made
C make the updates to the local table field row.
C Only make updates to the columns corresponding to
C writable fields in 'stdfrm'. If the student
C changed advisors, then delete this row from the
C display.
C
oldadv = Sadv
if (StdChg (Sname, Sage, Sbdate, Sgpa, Sidno, Scomm,
& Sadv)) then
if (oldadv .NE. Sadv) then
## deleterow #mstfrm studenttbl
else
## putrow #mstfrm studenttbl
## (#sgpa = Sgpa,
## <x:c3>#scomment = Scomm,
## #sadvisor = Sadv)
endif
endif
## } /* 'Zoom' */
## activate menuitem 'Quit', frskey2
## {
## breakdisplay
## } /* 'Quit' */
## finalize
## end
C
C Procedure: LdStd
C Purpose: Given an advisor name, load into the 'studenttbl'
C table field all the students who report to the
C professor with that name.
C Parameters:
C advisor - User specified professor name.
C Uses the global student record.
C
## subroutine LdStd(advisor)
## declare forms
## character*(*) advisor
C grad student record maps to database table
C Student's name
## character*25 Sname
C Student's age
## integer*2 Sage
C Student's birthday
## character*25 Sbdate
C Student's grade point average
## real*4 Sgpa
C Student's unique id number
## integer*4 Sidno
C General comment field
## character*200 Scomm
C Student's advisor
## character*25 Sadv
C
C Clear previous contents of table field. Load the table
C field from the database table based on the advisor name.
C Columns 'sname' and 'sage' will be displayed, and all
C others will be hidden.
C
## message 'Retrieving Student Information . . .'
## clear field studenttbl
## retrieve
## (Sname = s.#sname,
## Sage = s.#sage,
## Sbdate = s.#sbdate,
## Sgpa = s.#sgpa,
## Sidno = s.#sidno,
## Scomm = s.#scomment,
## Sadv = s.#sadvisor)
## where s.sadvisor = advisor
## {
## loadtable #mstfrm studenttbl
## (#sname = Sname,
## #sage = Sage,
## #sbdate = Sbdate,
## #sgpa = Sgpa,
## #sidno = Sidno,
## #scomment = Scomm,
## #sadvisor = Sadv)
## }
## end
C
C Procedure: StdChg
C Purpose: Allow the user to zoom into the details of a
C selected student. Some of the data can be updated
C by the user. If any updates were made, then
C reflect these back into the database table.
C The procedure returns TRUE if any changes were made.
C Parameters:
C None - Uses with data in the global 'grad' record.
C Returns:
C TRUE/FALSE - Changes were made to the database.
C Sets the global 'grad' record with the new data.
C
## logical function StdChg(Sname, Sage, Sbdate, Sgpa, Sidno,
##& Scomm, Sadv)
## declare forms
C grad student record maps to database table
C Student's name
## character*25 Sname
C Student's age
## integer*2 Sage
C Student's birthday
## character*25 Sbdate
C Student's grade point average
## real*4 Sgpa
C Student's unique id number
## integer*4 Sidno
C General comment field
## character*200 Scomm
C Student's advisor
## character*25 Sadv
C Changes made to date in form
## integer*4 chnged
C Valid advisor name ?
## integer*4 vldadv
C Compiled form
external stdfrm
## integer*4 stdfrm
C Control ADDFORM to only initialize once
integer*4 ldform
data ldform/0/
if (ldform .EQ. 0) then
## message 'Loading Student form . . .'
## addform stdfrm
ldform = 1
endif
## display #Stdfrm fill
## initialize
## (#sname = Sname,
## #sage = Sage,
## #sbdate = Sbdate,
## #sgpa = Sgpa,
## #sidno = Sidno,
## #scomment = Scomm,
## #sadvisor = Sadv)
## activate menuitem 'Write'
## {
C
C If changes were made then update the database
C table. Only bother with the fields that are not
C read-only.
C
## inquire_frs form (chnged = change)
if (chnged .EQ. 1) then
## validate
## message 'Writing changes to database. . .'
## getform
## (Sgpa = #sgpa,
## Scomm = #scomment,
## Sadv = #sadvisor)
C Enforce integrity of professor name
vldadv = 0
## retrieve (vldadv = 1)
## where p.pname = Sadv
if (vldadv .EQ. 0) then
## message 'Not a valid advisor name'
## sleep 2
## resume field sadvisor
else
## replace s (#sgpa = Sgpa,
## scomment = Scomm,
## sadvisor = Sadv)
## where s.#sidno = Sidno
## breakdisplay
endif
endif
## }
/* 'Write' */
## activate menuitem 'End', frskey3
## {
C Quit without submitting changes
chnged = 0
## breakdisplay
## }
/* 'Quit' */
## finalize
if (chnged .EQ. 1) then
StdChg = .TRUE.
else
StdChg = .FALSE.
endif
return
## end