GRIDPLUS - Example 6
Home Reference Manpage Examples Download License Contact

Example Of a Partial Application

This is an example of a partial "Course Bookings" application based on a MetaKit database. This example is intended to demonstrate a number of GRIDPLUS screen desgin/layout features and how a GRIDPLUS application may be structured.

Note: The courses/locations/names in this example are entirely ficticious!!!

This example assumes familiarity with the previous/earlier examples, as the more basic GRIDPLUS usage is not described in full.

User Guide

Main Window:

The toolbar contains four links:-

Make Booking.
Show Bookings.
Show Location.
Exit Application.

The main display has two tablelists. On the left is a list of available training courses, on the right is a list of dates on which the course is run.

The details of the selected course are shown in the bottom left text display. By default, details of the location for the currently selected course/date are shown in the bottom right text display.

Some courses are run at more than one location, selecting a date with a different location will update the location display:-

Selecting the Show Bookings toolbar link will cause the bottom right text display to show the bookings for the currently selected course/date. Selecting a different date will update the bookings display.

Selecting the Show Location toolbar link will cause the bottom right text display to show the location details for the currently selected course/date.


Make Booking:

Selecting the "Make Booking" link will display the following modal (toplevel) window:-

The "New Booking" window toolbar contains two links help:-

Save new booking.
Close "New Booking" window without saving booking.


Show Bookings:

When in "Show Bookings" mode the bottom right text display will show the bookings for the currently selected course/date.

Each booking has two associated icons:-

Edit booking.
Cancel booking.


Show Location:

When in "Show Location" mode the bottom right text display will show the location for the currently selected course/date.


Edit Booking:

Clicking the "Edit Booking" icon in the bookings text will display the following modal (toplevel) window:-

The "Edit Booking" window toolbar contains two links:-

Save amended booking.
Close "Edit Booking" window without saving changes.


Cancel Booking:

Clicking the "Cancel Booking" icon in the bookings text will display the following modal (toplevel) window:-

Pressing the "Yes" button will cancel (delete) the booking. Pressing the "No" button will abort the cancel (delete) operation.

Source Code

#-----------------------------------------#
# Procedure To Display New Booking Screen #
#-----------------------------------------#

proc toolbar,book {} {
   global {}

   set bookedStudents [mk::get db.dates![mk::select db.dates time [lindex $(.dates) 0] locationid [lindex $(.dates) 1]] students]

   if {$(.course.students) == $bookedStudents} {
      tk_messageBox -title "New Booking" -message "Course \"[lindex $(.courses) 1]\" is Fully Booked"
      return
   }

   gridplus window .booking -modal 1 -deletewindow booking:toolbar,close

   gridplus link .booking.toolbar -style toolbar {
      {:filesave16 "Save Booking" .save} | {:fileclose16 "Close" .close}
   }

   gridplus layout .booking.toolbar_border -style toolbar {
      .booking.toolbar
   }

   gridplus line .booking.line -style inputline

   gridplus entry .booking.details -style input {
      {"Course Title"       .title <}
      {"Location"           .location <}
      {"Date"               .date 12 <}
      {"Booking Reference " .bookingid 12 <}
      {@booking.line:ew}
      {"First Name"         .firstname +}
      {"Last Name"          .lastname}
      {"Company"            .company}
      {"Address"            .address1}
      {""                   .address2}
      {""                   .address3}
      {"Zip Code"           .zipcode 12}
   }

   gridplus layout .booking.main -title "New Booking" {
      .booking.toolbar_border:ew
      .booking.details
   }

   gpset [list \
      .booking.details,title      [lindex $(.courses) 1]            \
      .booking.details,location   [lindex $(.dates) 3]              \
      .booking.details,date       [lindex $(.dates) 2]              \
      .booking.details,locationid [lindex $(.dates) 1]              \
      .booking.details,bookingid  [format {SAT%06s} [getBookingID]] \
   ]

   pack .booking.main
}

#------------------------------------------------------#
# Procedure To Set "Info" Text Widget To Show Bookings #
#------------------------------------------------------#

proc toolbar,bookings {} {
   global {}

   set (showLocation) 0

   refreshInfo
}

#------------------------------------------------------#
# Procedure To Set "Info" Text Widget To Show Location #
#------------------------------------------------------#

proc toolbar,location {} {
   global {}

   set (showLocation) 1

   refreshInfo
}

#-------------------------------#
# Procedure To Exit Application #
#-------------------------------#

proc toolbar,exit {} {

   mk::file commit db
   mk::file close  db

   exit
}

#---------------------------#
# Procedure To Edit Booking #
#---------------------------#

proc info,edit {} {
   global {}

   gridplus window .edit -modal 1 -deletewindow edit:toolbar,close

   gridplus link .edit.toolbar -style toolbar {
      {:filesave16 "Save Booking" .save} | {:fileclose16 "Close" .close}
   }

   gridplus layout .edit.toolbar_border -style toolbar {
      .edit.toolbar
   }

   gridplus line .edit.line -style inputline

   gridplus entry .edit.details -style input {
      {"Course Title"       .title <}
      {"Location"           .location <}
      {"Date"               .date 12 <}
      {"Booking Reference " .bookingid 12 <}
      {@edit.line:ew}
      {"First Name"         .firstname +}
      {"Last Name"          .lastname}
      {"Company"            .company}
      {"Address"            .address1}
      {""                   .address2}
      {""                   .address3}
      {"Zip Code"           .zipcode 12}
   }

   gridplus layout .edit.main -title "Edit Booking" {
      .edit.toolbar_border:ew
      .edit.details
   }

   set row [mk::select db.bookings bookingid $(.info)]

   array set booking [mk::get db.bookings!$row]

   gpset [list \
      .edit.details,title     [mk::get db.courses![mk::select db.courses courseid $booking(courseid)] title]            \
      .edit.details,location  [mk::get db.locations![mk::select db.locations locationid $booking(locationid)] address1] \
      .edit.details,date      [clock format $booking(time) -format %d/%m/%Y]                                            \
      .edit.details,row       $row                                                                                      \
      .edit.details,bookingid $booking(bookingid)                                                                       \
      .edit.details,firstname $booking(firstname)                                                                       \
      .edit.details,lastname  $booking(lastname)                                                                        \
      .edit.details,company   $booking(company)                                                                         \
      .edit.details,address1  $booking(address1)                                                                        \
      .edit.details,address2  $booking(address2)                                                                        \
      .edit.details,address3  $booking(address3)                                                                        \
      .edit.details,zipcode   $booking(zipcode)                                                                         \
   ]

   pack .edit.main
}

#-----------------------------#
# Procedure To Cancel Booking #
#-----------------------------#

proc info,cancel {} {
   global {}

   set row  [mk::select db.bookings bookingid $(.info)]
   set name [mk::get db.bookings!$row firstname lastname] 

   set action [tk_messageBox -icon warning -title "Cancel Booking" -message "Cancel Booking For \"$name\"" -type yesno]

   if {$action eq "yes"} {
      setStudents $(.info) -
      mk::row delete db.bookings!$row
      updateBookings
      refreshInfo
   }

}

#-------------------------------#
# Procedure To Save New Booking #
#-------------------------------#

proc booking:toolbar,save {} {
   global {}

   mk::row append db.bookings                   \
      bookingid  $(.booking.details,bookingid)  \
      courseid   [lindex $(.courses) 0]         \
      locationid $(.booking.details,locationid) \
      time       [lindex $(.dates) 0]           \
      firstname  $(.booking.details,firstname)  \
      lastname   $(.booking.details,lastname)   \
      company    $(.booking.details,company)    \
      address1   $(.booking.details,address1)   \
      address2   $(.booking.details,address2)   \
      address3   $(.booking.details,address3)   \
      zipcode    $(.booking.details,zipcode)

   setStudents $(.booking.details,bookingid) +

   updateBookings
   refreshInfo

   booking:toolbar,close
}

#------------------------------------------------------#
# Procedure To Close New Booking Window Without Saving #
#------------------------------------------------------#

proc booking:toolbar,close {} {

   gridplus clear .booking

   destroy .booking
}

#----------------------------------#
# Procedure To Save Edited Booking #
#----------------------------------#

proc edit:toolbar,save {} {
   global {}

   mk::set db.bookings!$(.edit.details,row) \
      firstname  $(.edit.details,firstname) \
      lastname   $(.edit.details,lastname)  \
      company    $(.edit.details,company)   \
      address1   $(.edit.details,address1)  \
      address2   $(.edit.details,address2)  \
      address3   $(.edit.details,address3)  \
      zipcode    $(.edit.details,zipcode)

   updateBookings
   refreshInfo

   edit:toolbar,close
}

#-------------------------------------------------------#
# Procedure To Close Edit Booking Window Without Saving #
#-------------------------------------------------------#

proc edit:toolbar,close {} {

   gridplus clear .edit

   destroy .edit
}

#----------------------------------#
# Procedure To Generate Booking ID #
#----------------------------------#

proc getBookingID {} {

   set bookingid [mk::get db.control!0 nextid]

   mk::set db.control!0 nextid [expr $bookingid + 1]
   mk::file commit db

   return $bookingid
}

#-------------------------------------------------------#
# Procedure To Set Number Of Students Booked For Course #
#-------------------------------------------------------#

proc setStudents {bookingid operator} {

   array set booking [mk::get db.bookings![mk::select db.bookings bookingid $bookingid]]

   set row      [mk::select db.dates courseid $booking(courseid) time $booking(time)]
   set students [mk::get db.dates!$row students]

   mk::set db.dates!$row students [expr $students $operator 1]

   mk::file commit db
}

#--------------------------------------#
# Procedure To Refresh Courses Display #
#--------------------------------------#

proc refreshCourses {} {
   global {}

   mk::loop row db.courses {
      lappend result [mk::get $row courseid title duration]
   }

   gpset .courses $result 
}

#------------------------------------#
# Procedure To Refresh Couse Display #
#------------------------------------#

proc refreshCourse {} {
   global {}

   array set course [mk::get db.courses![mk::select db.courses courseid [lindex $(.courses) 0]]]

   gpset .course.students $course(students)

   gpset .course \
"<font helvetica:default><size 10:default><bgcolor lightgray><size +6><b>$course(title)</b></size>
</bgcolor>
<b>Course Code</b><indent 6>$course(courseid)</indent>

<b>Format</b><indent 6>$course(format)</indent>

<b>Duration</b><indent 6>$course(duration)</indent>

<b>Description</b><indent 6>$course(description)</indent>

<b>Prerequisites</b><indent 6>$course(prerequisites)</indent>

<b>Objectives</b><indent 6>$course(objectives)</indent>

<b>Students</b><indent 6>$course(students) (maximum)</indent>
"
}

#---------------------------------------------------------------#
# Procedure To Update/Refresh Display When A Course Is Selected #
#---------------------------------------------------------------#

proc courses {} {

   refreshCourse
   refreshDates
   updateLocation
   updateBookings
   refreshInfo
}

#-------------------------------------------------------------------#
# Procedure To Update/Refresh Display When A Couse Date Is Selected #
#-------------------------------------------------------------------#

proc dates {} {

   updateLocation
   updateBookings
   refreshInfo
}

#------------------------------------#
# Procedure To Refresh Dates Display #
#------------------------------------#

proc refreshDates {} {
   global {}

   foreach row [mk::select db.dates courseid [lindex $(.courses) 0]] {
      set dateinfo   [mk::get db.dates!$row time locationid]
      set date       [clock format [lindex $dateinfo 0] -format %d/%m/%Y]
      set location   [mk::get db.locations![mk::select db.locations locationid [lindex $dateinfo 1]] address1]
      lappend result [lappend dateinfo $date $location]
   }

   gpset .dates $result 
}

#----------------------------------------------#
# Procedure To Update Location Display Details #
#----------------------------------------------#

proc updateLocation {} {
   global {}

   array set location [mk::get db.locations![mk::select db.locations locationid [lindex $(.dates) 1]]]

   image create photo locationImage -data $location(image)

   set (location) \
"<font helvetica:default><size 10:default><bgcolor lightgray><size +6><b>$location(address1)</b></size>
</bgcolor>
<b>Image</b><indent 6><image locationImage></indent>

<b>Address</b><indent 6>$location(address1)
$location(address2)
$location(address3)
$location(zipcode)</indent>
"
}

#----------------------------------------------#
# Procedure To Update Bookings Display Details #
#----------------------------------------------#

proc updateBookings {} {
   global {}

   set (bookings) \
"<font helvetica:default><size 10:default><bgcolor lightgray><size +6><b>Bookings: <size +4>[lindex $(.dates) 2]</b></size>
</bgcolor>"

   foreach row [mk::select db.bookings courseid [lindex $(.courses) 0] time [lindex $(.dates) 0]] {
      array set booking [mk::get db.bookings!$row]

      set (bookings) \
"$(bookings)
<image :edit16~edit:$booking(bookingid)> <image :actcross16~cancel:$booking(bookingid)><indent 3>$booking(firstname) $booking(lastname)
$booking(company)
$booking(address1)
$booking(address2)
$booking(address3)
$booking(zipcode)</indent>
"
   }
}

#-------------------------------------#
# Procedure To Refresh "Info" Display #
#-------------------------------------#

proc refreshInfo {} {
   global {}

   if {$(showLocation)} {
      gpset .info $(location)
   } else {
      gpset .info $(bookings)
   }
}

#=======================#
# Start The Application #
#=======================#

#----------------------#
# Initialise Variables #
#----------------------#

set (showLocation) 1

#---------------#
# Open Database #
#---------------#

package require Mk4tcl

mk::file open db booking.mk

#-----------------------------------------#
# Set Widget Defaults And GRIDPLUS Styles #
#-----------------------------------------#

option add *Font                       {helvetica 8}
option add *Entry.borderWidth          1
option add *Entry.disabledBackground   lightgray
option add *Entry.relief               solid
option add *Gridplus.borderWidth       0
option add *Gridplus.pad               0
option add *Tablelist.labelBackground  lightgray
option add *Tablelist.labelBorderWidth 1

gridplus style toolbar {
   -background   black
   -buttoncolor  /black
   -linkcolor    white
   -space        0
}

gridplus style input {
   -background skyblue1
   -pad        5
   -size       60
}

gridplus style inputline {
   -background steelblue2
}

#----------------------------#
# Create Main User Interface #
#----------------------------#

gridplus link .toolbar -style toolbar {
   {:caltoday16 "Make Booking" .book}     | {:callist16 "Show Bookings" .bookings} |\
   {:navhome16 "Show Location" .location} | {:actexit16 "Exit" .exit}
}

gridplus layout .toolbar_border -style toolbar {
   .toolbar
}

gridplus tablelist .courses -scroll y -height 8 -width 75 -selectfirst 1 -action single {
   0 Code
   0 Title
   0 Duration
}

gridplus tablelist .dates -scroll y -height 8 -width 45 -selectfirst 1 -sortfirst 1 -action single {
   0 time       hide
   0 locationid hide
   0 Date
   0 Location
}

gridplus text .course -scroll y -tags 1 -height 20 -width 75

gridplus text .info -scroll y -tags 1 -height 20 -width 45

gridplus layout .main -title "Course Bookings" {
   .toolbar_border:ew -
   .courses           .dates
   .course            .info
}

pack .main

#------------------------------#
# Populate Interface With Data #
#------------------------------#

refreshCourses
courses

Comments

proc toolbar,book {} {
   global {}

   set bookedStudents [mk::get db.dates![mk::select db.dates time [lindex $(.dates) 0] locationid [lindex $(.dates) 1]] students]

   if {$(.course.students) == $bookedStudents} {
      tk_messageBox -title "New Booking" -message "Course \"[lindex $(.courses) 1]\" is Fully Booked"
      return
   }

   gridplus window .booking -modal 1 -deletewindow booking:toolbar,close

   gridplus link .booking.toolbar -style toolbar {
      {:filesave16 "Save Booking" .save} | {:fileclose16 "Close" .close}
   }

   gridplus layout .booking.toolbar_border -style toolbar {
      .booking.toolbar
   }

   gridplus line .booking.line -style inputline

   gridplus entry .booking.details -style input {
      {"Course Title"       .title <}
      {"Location"           .location <}
      {"Date"               .date 12 <}
      {"Booking Reference " .bookingid 12 <}
      {@booking.line:ew}
      {"First Name"         .firstname +}
      {"Last Name"          .lastname}
      {"Company"            .company}
      {"Address"            .address1}
      {""                   .address2}
      {""                   .address3}
      {"Zip Code"           .zipcode 12}
   }

   gridplus layout .booking.main -title "New Booking" {
      .booking.toolbar_border:ew
      .booking.details
   }

   gpset [list \
      .booking.details,title      [lindex $(.courses) 1]            \
      .booking.details,location   [lindex $(.dates) 3]              \
      .booking.details,date       [lindex $(.dates) 2]              \
      .booking.details,locationid [lindex $(.dates) 1]              \
      .booking.details,bookingid  [format {SAT%06s} [getBookingID]] \
   ]

   pack .booking.main
}

This is a procedure to display the "New Booking" screen.


proc toolbar,bookings {} {
   global {}

   set (showLocation) 0

   refreshInfo
}

This is a procedure to set the "showLocation" flag. When this flag is set to zero the bottom right text display will show the bookings for the currently selected course/date.

The flag is stored in the global null named array. This to store the values of the GRIDPLUS widgets, but it is safe to use it for other purposes. All GRIDPLUS values begin with a dot, so the name "showLocation" will not clash, and will not be cleared by a GRIDPLUS clear command/mode.

The call to "refreshInfo" updates the ".info" text to show the bookings.


proc toolbar,location {} {
   global {}

   set (showLocation) 1

   refreshInfo
}

This is a procedure to set the "showLocation" flag. When this flag is set to zero the bottom right text display will show the bookings for the currently selected course/date.

See the above comments for "toolbar,bookings".


proc toolbar,exit {} {

   mk::file commit db
   mk::file close  db

   exit
}

This is a procedure to commit/close the database and exit the application.


proc info,edit {} {
   global {}

   gridplus window .edit -modal 1 -deletewindow edit:toolbar,close

   gridplus link .edit.toolbar -style toolbar {
      {:filesave16 "Save Booking" .save} | {:fileclose16 "Close" .close}
   }

   gridplus layout .edit.toolbar_border -style toolbar {
      .edit.toolbar
   }

   gridplus line .edit.line -style inputline

   gridplus entry .edit.details -style input {
      {"Course Title"       .title <}
      {"Location"           .location <}
      {"Date"               .date 12 <}
      {"Booking Reference " .bookingid 12 <}
      {@edit.line:ew}
      {"First Name"         .firstname +}
      {"Last Name"          .lastname}
      {"Company"            .company}
      {"Address"            .address1}
      {""                   .address2}
      {""                   .address3}
      {"Zip Code"           .zipcode 12}
   }

   gridplus layout .edit.main -title "Edit Booking" {
      .edit.toolbar_border:ew
      .edit.details
   }

   set row [mk::select db.bookings bookingid $(.info)]

   array set booking [mk::get db.bookings!$row]

   gpset [list \
      .edit.details,title     [mk::get db.courses![mk::select db.courses courseid $booking(courseid)] title]            \
      .edit.details,location  [mk::get db.locations![mk::select db.locations locationid $booking(locationid)] address1] \
      .edit.details,date      [clock format $booking(time) -format %d/%m/%Y]                                            \
      .edit.details,row       $row                                                                                      \
      .edit.details,bookingid $booking(bookingid)                                                                       \
      .edit.details,firstname $booking(firstname)                                                                       \
      .edit.details,lastname  $booking(lastname)                                                                        \
      .edit.details,company   $booking(company)                                                                         \
      .edit.details,address1  $booking(address1)                                                                        \
      .edit.details,address2  $booking(address2)                                                                        \
      .edit.details,address3  $booking(address3)                                                                        \
      .edit.details,zipcode   $booking(zipcode)                                                                         \
   ]

   pack .edit.main
}

This is a procedure to display the "Edit Booking" screen.


proc info,cancel {} {
   global {}

   set row  [mk::select db.bookings bookingid $(.info)]
   set name [mk::get db.bookings!$row firstname lastname] 

   set action [tk_messageBox -icon warning -title "Cancel Booking" -message "Cancel Booking For \"$name\"" -type yesno]

   if {$action eq "yes"} {
      setStudents $(.info) -
      mk::row delete db.bookings!$row
      updateBookings
      refreshInfo
   }

}

This is a procedure to cancel (delete) a booking.

A confirmation dialog is displayed. If the user presses the "Yes" button, the number of students booked on the course is decremented, the booking is deleted from the database and the display updated to reflect the change.


proc booking:toolbar,save {} {
   global {}

   mk::row append db.bookings                   \
      bookingid  $(.booking.details,bookingid)  \
      courseid   [lindex $(.courses) 0]         \
      locationid $(.booking.details,locationid) \
      time       [lindex $(.dates) 0]           \
      firstname  $(.booking.details,firstname)  \
      lastname   $(.booking.details,lastname)   \
      company    $(.booking.details,company)    \
      address1   $(.booking.details,address1)   \
      address2   $(.booking.details,address2)   \
      address3   $(.booking.details,address3)   \
      zipcode    $(.booking.details,zipcode)

   setStudents $(.booking.details,bookingid) +

   updateBookings
   refreshInfo

   booking:toolbar,close
}

This is a procedure to save a new booking into the database.

After the booking is added to the database the number of students booked on the course is incremented, the display updated to reflect the change and the window is closed using the "booking:toolbar,close" procedure.


proc booking:toolbar,close {} {

   gridplus clear .booking

   destroy .booking
}

This is a procedure to clear the contents of the ".booking" window and to destroy it.


proc getBookingID {} {

   set bookingid [mk::get db.control!0 nextid]

   mk::set db.control!0 nextid [expr $bookingid + 1]
   mk::file commit db

   return $bookingid
}

This is a procedure to get the next booking id from the database and to increment it ready for the next "get".


proc setStudents {bookingid operator} {

   array set booking [mk::get db.bookings![mk::select db.bookings bookingid $bookingid]]

   set row      [mk::select db.dates courseid $booking(courseid) time $booking(time)]
   set students [mk::get db.dates!$row students]

   mk::set db.dates!$row students [expr $students $operator 1]

   mk::file commit db
}

This is a procedure to increment/decrement (depending on the value of "operator") the number of students booked for the course/date associated with "bookingid".


proc refreshCourses {} {
   global {}

   mk::loop row db.courses {
      lappend result [mk::get $row courseid title duration]
   }

   gpset .courses $result 
}

This is a procedure to update/refresh the ".courses" tablelist.


proc refreshCourse {} {
   global {}

   array set course [mk::get db.courses![mk::select db.courses courseid [lindex $(.courses) 0]]]

   gpset .course.students $course(students)

   gpset .course \
"<font helvetica:default><size 10:default><bgcolor lightgray><size +6><b>$course(title)</b></size>
</bgcolor>
<b>Course Code</b><indent 6>$course(courseid)</indent>

<b>Format</b><indent 6>$course(format)</indent>

<b>Duration</b><indent 6>$course(duration)</indent>

<b>Description</b><indent 6>$course(description)</indent>

<b>Prerequisites</b><indent 6>$course(prerequisites)</indent>

<b>Objectives</b><indent 6>$course(objectives)</indent>

<b>Students</b><indent 6>$course(students) (maximum)</indent>
"
}

This is a procedure to update/refresh the ".course" text.

The details of the course are read from the database into the "course" array. The gpset" command is used to set a value for ".course.students" in the global null named array. This item does not have an associated GRIDPLUS widget, but by prefixing the name of the array item with ".course" makes the association obvious and would, if neccessary, allow it to be deleted when the window containing the ".course" item is cleared.

The gpset command is also used to set the contents of the ".course" text. If the text is set to have the tag processing enabled when it is created, gpset will process the tags automatically.


proc courses {} {

   refreshCourse
   refreshDates
   updateLocation
   updateBookings
   refreshInfo
}

This is a procedure to update/refresh the ".dates" tablelist, update/set the "location" and "bookings" global null named array items and update/refresh the ".info" text, when a line is selected in the ".courses" tablelist.


proc dates {} {

   updateLocation
   updateBookings
   refreshInfo
}

This is a procedure to update/set the "location" and "bookings" global null named array items and update/refresh the ".info" text, when a line is selected in the ".dates" tablelist.


proc refreshDates {} {
   global {}

   foreach row [mk::select db.dates courseid [lindex $(.courses) 0]] {
      set dateinfo   [mk::get db.dates!$row time locationid]
      set date       [clock format [lindex $dateinfo 0] -format %d/%m/%Y]
      set location   [mk::get db.locations![mk::select db.locations locationid [lindex $dateinfo 1]] address1]
      lappend result [lappend dateinfo $date $location]
   }

   gpset .dates $result 
}

This is a procedure to update/refresh the contents of the ".dates" tablelist.


proc updateLocation {} {
   global {}

   array set location [mk::get db.locations![mk::select db.locations locationid [lindex $(.dates) 1]]]

   image create photo locationImage -data $location(image)

   set (location) \
"<font helvetica:default><size 10:default><bgcolor lightgray><size +6><b>$location(address1)</b></size>
</bgcolor>
<b>Image</b><indent 6><image locationImage></indent>

<b>Address</b><indent 6>$location(address1)
$location(address2)
$location(address3)
$location(zipcode)</indent>
"
}

This is a procedure to update/set the value of the "location" item in the global null named array.

The image of the location is stored in the database as a base64 encoded GIF. The Tk image is created using the "image create" command. This information will be displayed in the ".info" text when the ".info" text is set to the value of "$(location)".


proc updateBookings {} {
   global {}

   set (bookings) \
"<font helvetica:default><size 10:default><bgcolor lightgray><size +6><b>Bookings: <size +4>[lindex $(.dates) 2]</b></size>
</bgcolor>"

   foreach row [mk::select db.bookings courseid [lindex $(.courses) 0] time [lindex $(.dates) 0]] {
      array set booking [mk::get db.bookings!$row]

      set (bookings) \
"$(bookings)
<image :edit16~edit:$booking(bookingid)> <image :actcross16~cancel:$booking(bookingid)><indent 3>$booking(firstname) $booking(lastname)
$booking(company)
$booking(address1)
$booking(address2)
$booking(address3)
$booking(zipcode)</indent>
"
   }
}

This is a procedure to update/set the value of the "bookings" item in the global null named array.

The heading information is set, then for each booking, the booking information is added to the "(bookings)" array item. The first line of each booking is prefixed with two icons. For example: The "edit" icon is created using the following tag:-

<image :edit16~edit:$booking(bookingid)>

This will display the "edit16" icon from the ICONS package. The icon has an associated command "edit". As the GRIDPLUS text which will contain this icon is called ".info", the name of the procedure invoked by the icon will be "info,edit". The command also has a parameter, in this case the "bookingid". When the icon is clicked the value of "$(.info)" will be set to the value of "$booking(bookingid)" and the "info,edit" invoked.


proc refreshInfo {} {
   global {}

   if {$(showLocation)} {
      gpset .info $(location)
   } else {
      gpset .info $(bookings)
   }
}

This is a procedure to set the contents of the ".info" text depening on the value of the "$(showLocation)" flag.


#----------------------#
# Initialise Variables #
#----------------------#

set (showLocation) 1

#---------------#
# Open Database #
#---------------#

package require Mk4tcl

mk::file open db booking.mk

This is the start of processing. The "(showLocation)" flag is initialised and the database opened.


option add *Font                       {helvetica 8}
option add *Entry.borderWidth          1
option add *Entry.disabledBackground   lightgray
option add *Entry.relief               solid
option add *Gridplus.borderWidth       0
option add *Gridplus.pad               0
option add *Tablelist.labelBackground  lightgray
option add *Tablelist.labelBorderWidth 1

gridplus style toolbar {
   -background   black
   -buttoncolor  /black
   -linkcolor    white
   -space        0
}

gridplus style input {
   -background skyblue1
   -pad        5
   -size       60
}

gridplus style inputline {
   -background steelblue2
}

Sets the option database and styles for the application.


gridplus link .toolbar -style toolbar {
   {:caltoday16 "Make Booking" .book}     | {:callist16 "Show Bookings" .bookings} |\
   {:navhome16 "Show Location" .location} | {:actexit16 "Exit" .exit}
}

gridplus layout .toolbar_border -style toolbar {
   .toolbar
}

Creates a toolbar using GRIDPLUS links.


gridplus tablelist .courses -scroll y -height 8 -width 75 -selectfirst 1 -action single {
   0 Code
   0 Title
   0 Duration
}

gridplus tablelist .dates -scroll y -height 8 -width 45 -selectfirst 1 -sortfirst 1 -action single {
   0 time       hide
   0 locationid hide
   0 Date
   0 Location
}

Creates two tablelists. Both tablelists have the -selectfirst 1 option set. This causes the first row in the tablelist to be automatically selected when the content of the tablelist is set using the gpset command.

Both tablelists also have the -action single option set. This sets a binding such that when a line is selected using a single-click the procedure associated with the tablelist ("courses" or "dates") is also invoked.

The -sortfirst 1 option used for ".dates" makes sure that the dates are displayed in the correct order.


gridplus text .course -scroll y -tags 1 -height 20 -width 75

gridplus text .info -scroll y -tags 1 -height 20 -width 45

Creates two texts. Both have a vertical scrollbar and tags processing enabled.


gridplus layout .main -title "Course Bookings" {
   .toolbar_border:ew -
   .courses           .dates
   .course            .info
}

pack .main

Create and display the GRIDPLUS window layout.


refreshCourses
courses

Initialise the contents of the tablelists and texts.


Copyright © 2004 Adrian Davis.