%---------Must be included into programs using The GUI Module-----------------------------------%
import GUI in "%oot/support/lib/GUI"
%---------Set Window Size to 780x475-----------------------------------------------------------%
View.Set ("graphics:780;475")
%---------Set Background Color-----------------------------------------------------------------%
GUI.SetBackgroundColor (30)
/*##############################################################################################
########################### GLOBAL VARIABLES ##################################################
#############################################################################################*/
%---------Menu Variables-----------------------------------------------------------------------%
var first, second, third, fourth : int
%---------Menu Items Variables-----------------------------------------------------------------%
var menuItem : array 1 .. 10 of int
%---------Menu Item Names----------------------------------------------------------------------%
var menuName : array 1 .. 10 of string := init
%---------File Menu Items----------------------------------------------------------------------%
("New Database", "Open Database File", "Close Database File", "---", "Exit Program",
%---------Records Menu Items-------------------------------------------------------------------%
"Add Records", "View Records", "Sort Records",
%---------About Menu Items---------------------------------------------------------------------%
"About LDS", "User Manual")
%---------File Variables-----------------------------------------------------------------------%
var file, temp : int
%---------Text Field Variables-----------------------------------------------------------------%
var titleTextField, firstnameTextField, lastnameTextField, valueTextField,
genreTextField, keywordTextField, subjectTextField : int
%---------Font Variables-----------------------------------------------------------------------%
var title, title2, main, small : int
title := Font.New ("arial:8:bold")
title2 := Font.New ("arial:10:bold")
main := Font.New ("arial:10")
small := Font.New ("arial:8:italic")
%---------Data Variables-----------------------------------------------------------------------%
var Data :
record
title : string
firstname : string
lastname : string
value : string
genre : string
keyword : string
subject : string
end record
/*##############################################################################################
########################### PROCEDURES ########################################################
#############################################################################################*/
%---------Called When Menu Items are Selected--------------------------------------------------%
procedure MenuSelected
for i : 1 .. 10
if menuItem (i) = GUI.GetEventWidgetID then
locate (maxrow, 1)
put "Menu Item \"" + menuName (i) + "\" selected " ..
end if
end for
end MenuSelected
%---------Called When User Selects Open Database File------------------------------------------%
/*procedure OpenFile
var data : string
open : file, "a:/names.txt", get %open file to get previous data
open : temp, "a:/temp.txt", put % open the temporary file to store previous data and get more
loop
exit when eof (file) %exits when you get to the end of the file
get : file, data %get the data from the old file
put : temp, data %write to the temp file
end loop
end OpenFile*/
%---------Called When User Selects Close Database File-----------------------------------------%
/*procedure CloseFile
close : file
close : temp
File.Delete ("a:/names.txt") %deletes names
File.Rename ("a:/temp.txt", "a:/names.txt") %rename temp to names
end CloseFile*/
%---------Called When User Selects Add Book----------------------------------------------------%
procedure AddBook
var data : string
var errormessage : string := ""
var valid : boolean := true
%set values in text boxes to data record
Data.title := (GUI.GetText (titleTextField))
Data.firstname := (GUI.GetText (firstnameTextField))
Data.lastname := (GUI.GetText (lastnameTextField))
Data.value := (GUI.GetText (valueTextField))
Data.genre := (GUI.GetText (genreTextField))
Data.keyword := (GUI.GetText (keywordTextField))
Data.subject := (GUI.GetText (subjectTextField))
open : file, "a:/names.txt", get %open file to get previous data
open : temp, "a:/temp.txt", put % open the temporary file to store previous data and get more
loop
exit when eof (file) %exits when you get to the end of the file
get : file, data %get the data from the old file
put : temp, data %write to the temp file
end loop
%save data to temp.txt
put : temp, "Title: " + Data.title
put : temp, "Author's Name: " + Data.firstname + " " + Data.lastname
put : temp, "Book Value: " + Data.value
put : temp, "Genre: " + Data.genre
put : temp, "Keyword: " + Data.keyword
put : temp, "Subject: " + Data.subject
put : temp, repeat ("-", 30) + "Book #", entrynum , repeat ("-", 30)
%Clear Text Fields
GUI.SetText (titleTextField, "")
GUI.SetText (firstnameTextField, "")
GUI.SetText (lastnameTextField, "")
GUI.SetText (valueTextField, "")
GUI.SetText (genreTextField, "")
GUI.SetText (keywordTextField, "")
GUI.SetText (subjectTextField, "")
GUI.SetActive (titleTextField)
close : file
close : temp
File.Delete ("a:/names.txt") %deletes names
File.Rename ("a:/temp.txt", "a:/names.txt") %rename temp to names
end AddBook
%---------Called When User Selects Add Records------------------------------------------------%
%When the user hits [enter] key, the program skips to the next textbox
procedure titleEntered (text : string)
GUI.SetSelection (firstnameTextField, -1, -1)
GUI.SetActive (firstnameTextField)
end titleEntered
procedure firstnameEntered (text : string)
GUI.SetSelection (lastnameTextField, -1, -1)
GUI.SetActive (lastnameTextField)
end firstnameEntered
procedure lastnameEntered (text : string)
GUI.SetSelection (valueTextField, -1, -1)
GUI.SetActive (valueTextField)
end lastnameEntered
procedure valueEntered (text : string)
GUI.SetSelection (genreTextField, -1, -1)
GUI.SetActive (genreTextField)
end valueEntered
procedure genreEntered (text : string)
GUI.SetSelection (keywordTextField, -1, -1)
GUI.SetActive (keywordTextField)
end genreEntered
procedure keywordEntered (text : string)
GUI.SetSelection (subjectTextField, -1, -1)
GUI.SetActive (subjectTextField)
end keywordEntered
procedure subjectEntered (text : string)
GUI.SetSelection (titleTextField, -1, -1)
GUI.SetActive (titleTextField)
end subjectEntered
procedure AddRecords
%Text Fields
titleTextField := GUI.CreateTextFieldFull (100, 355, 275, "",
titleEntered, GUI.INDENT, main, 0)
firstnameTextField := GUI.CreateTextFieldFull (100, 325, 125, "",
firstnameEntered, GUI.INDENT, main, 0)
lastnameTextField := GUI.CreateTextFieldFull (250, 325, 125, "",
lastnameEntered, GUI.INDENT, main, 0)
valueTextField := GUI.CreateTextFieldFull (100, 280, 275, "",
valueEntered, GUI.INDENT, main, 0)
genreTextField := GUI.CreateTextFieldFull (100, 250, 275, "",
genreEntered, GUI.INDENT, main, 0)
keywordTextField := GUI.CreateTextFieldFull (100, 220, 275, "",
keywordEntered, GUI.INDENT, main, 0)
subjectTextField := GUI.CreateTextFieldFull (100, 190, 275, "",
subjectEntered, GUI.INDENT, main, 0)
%Labels
var titleLabel := GUI.CreateLabelFull (90, 357, "Title", 0, 0,
GUI.RIGHT, title)
var authornameLabel := GUI.CreateLabelFull (90, 327, "Author's Name", 0, 0,
GUI.RIGHT, title)
var firstnameLabel := GUI.CreateLabelFull (180, 307, "First Name", 0, 0,
GUI.RIGHT, small)
var lastnameLabel := GUI.CreateLabelFull (340, 307, "Last Name", 0, 0,
GUI.RIGHT, small)
var valueLabel := GUI.CreateLabelFull (90, 282, "Book Value", 0, 0,
GUI.RIGHT, title)
var genreLabel := GUI.CreateLabelFull (90, 252, "Genre", 0, 0,
GUI.RIGHT, title)
var keywordLabel := GUI.CreateLabelFull (90, 222, "Keyword", 0, 0,
GUI.RIGHT, title)
var subjectLabel := GUI.CreateLabelFull (90, 192, "Subject", 0, 0,
GUI.RIGHT, title)
%Add Book Button
var AddButton := GUI.CreateButton (200, 130, 100, "Add Book", AddBook)
end AddRecords
%---------Called When User Selects View Records------------------------------------------------%
procedure DoNothing
end DoNothing
procedure SortButtons
var titlesort := GUI.CreateButton (490, 370, 150, "Title", DoNothing)
var firstnamesort := GUI.CreateButton (490, 340, 150, "Author's First Name", DoNothing)
var lastnamesort := GUI.CreateButton (490, 310, 150, "Author's Last Name", DoNothing)
var valuesort := GUI.CreateButton (490, 280, 150, "Value", DoNothing)
var genresort := GUI.CreateButton (490, 250, 150, "Genre", DoNothing)
var keywordsort := GUI.CreateButton (490, 220, 150, "Keyword", DoNothing)
var subjectsort := GUI.CreateButton (490, 190, 150, "Subject", DoNothing)
end SortButtons
procedure ViewRecords
var textBox : int %Textbox
var line : string %Line
%Open File
open : file, "a:/names.txt", get
% Create the title label and text box.
textBox := GUI.CreateTextBoxFull (20, 10, 460, 420,
GUI.INDENT, main)
% Read the file and place it in the text box.
loop
exit when eof (file)
get : file, line : *
GUI.AddLine (textBox, line)
end loop
close : file % Close the file.
SortButtons
end ViewRecords
/*##############################################################################################
########################### MAIN PROGRAM ######################################################
#############################################################################################*/
%---------File Menu----------------------------------------------------------------------------%
first := GUI.CreateMenu ("File")
menuItem (1) := GUI.CreateMenuItem (menuName (1), MenuSelected) %New
menuItem (2) := GUI.CreateMenuItem (menuName (2), MenuSelected) %Open
menuItem (3) := GUI.CreateMenuItem (menuName (3), MenuSelected) %Close
menuItem (4) := GUI.CreateMenuItem (menuName (4), MenuSelected) %---
menuItem (5) := GUI.CreateMenuItem (menuName (5), GUI.Quit) %Quit
%---------Records Menu-------------------------------------------------------------------------%
second := GUI.CreateMenu ("Records")
menuItem (6) := GUI.CreateMenuItem (menuName (6), AddRecords) %Add Records
menuItem (7) := GUI.CreateMenuItem (menuName (7), ViewRecords) %View Records
menuItem (8) := GUI.CreateMenuItem (menuName (8), MenuSelected) %Sort Records
%---------About Menu---------------------------------------------------------------------------%
third := GUI.CreateMenu ("About")
menuItem (9) := GUI.CreateMenuItem (menuName (9), MenuSelected) %About LDS
menuItem (10) := GUI.CreateMenuItem (menuName (10), MenuSelected) %User Manual
loop
exit when GUI.ProcessEvent
end loop
%GUI.SetText (widgetID,"") Clear textfiled text
%GUI.ClearText (boxname) Clear Text Box text
%(GUI.GetText (Num1TextField)) Get text from a text field
|