The script for the videotape record is very similar to that for the customer, so rather than go through it step by step I'll just explain where it differs.
The main dispatch table in Library.ls now has a set of keys identical to that for the customer but prefixed with V instead of C. No other changes are needed apart from uncommenting the line that launches the Videotape module.
The Videotape.ls script starts from Customer.ls needs to be altered to reflect the particular record structure used. Here I've decided to use a timestamp for the ID (the same as for Customer) and to have three other fields; Title, Copy and Comment. Title is just that; the title of the tape. Copy is a numeric field to allow the shop to hold more than one copy of a particular tape, and Comment is a field that can be used to note anything the user wishes. It's quite likely that a real system would have extra fields, but these are enough to get us started.
The process of adding a new record is identical to that used for Customer, except for one point. Because there may be several copies of a tape we need a unique Copy value for each. To add convenience for the user, I've arranged that ifthe Copy field is left blank the script will select the next unused number. It does this by reading all the records for that title and making a note of the highest Copy value it finds, then adding one for the new record. Here's the complete subroutine:
AddVideotape: prompt "Add Videotape" set the title to "Add Videotape" put parameter "title" into Title put parameter "copy" into Copy put parameter "comment" into Comment ! Check that all required fields are present if Title is empty begin add template Website cat "servlets/templates/vnew.html" where "*MESSAGE*" is "Please give the title of this tape." and "*TITLE*" is Title and "*COPY*" is Copy and "*COMMENT*" is Comment and "*SCREENID*" is "VAdd" and "*FUNCTION*" is "Add" return end ! Create the new record ! See if this is an existing Videotape ! If so, check this Copy is not already allocated. ! If Copy is 0, use the next available number if Copy is not 0 begin get Videotape using "WHERE title='" cat Title cat "' AND copy='" cat Copy cat "'" if more Videotape begin add template Website cat "servlets/templates/vnew.html" where "*MESSAGE*" is "Copy " cat Copy cat " is already allocated. " cat "Enter zero and I will allocate the next free number." and "*TITLE*" is Title and "*COPY*" is 0 and "*COMMENT*" is Comment and "*SCREENID*" is "VAdd" and "*FUNCTION*" is "Add" return end end else begin ! Copy is 0 so find the highest used number ! by scanning all records for this title. get Videotape using "WHERE title='" cat Title cat "'" put 0 into LastCopy while more Videotape begin get next Videotape put field "copy" of Videotape into Copy if Copy is greater than LastCopy put Copy into LastCopy end add 1 to LastCopy giving Copy end ! Add a new record put the millisecond into ID new transaction create Videotape where field "id" is ID field "title" is Title field "copy" is Copy field "comment" is Comment if the status is "OK" begin commit add "New Videotape " cat Title cat " added." end else begin set the title to "Internal error" add "Can't create record: " cat return add the status end add template the directory cat "servlets/templates/mainmenu.html" return
The part that creates the new Copy number is about half-way down the subroutine.
The Edit and Delete functions are functionally identical to Customer (apart from the field and variable names). The entire script is Videotape.ls, and the version of the main script that matches where we are now is Library-8.ls.