Assignment 9: A Standard GUI App

In this assignment, we're going to put together a standard GUI frontend for our book data. Create a new Windows Forms project and bring in your Assignment 8 binary search tree code to use (you can also use the Lab 9 binary tree code if you had trouble with Assignment 8).

Your app will have three tabs:

  • File: to save and load the books to file
  • Display: to view the books
  • Add: to add new books

As before, please omit the bin and obj directories when you commit, but commit all other files. The repo is here:

https://cssvn.utrgv.edu/svn_etomai/201810_3328/assn09_bookapp/<username>

Form

Create your main form and add a TabControl to give you separate panes to work with. Create three tabs and name them File, Display and Add.

File

This app will work with a tree of Book objects. When it starts up, the tree should be empty, until you either manually start adding Books, or load a saved tree from a file.

On this tab, display a TextBox and two Buttons, labeled Load and New.

  • If the user types in a filename and pushes Load, load the Books tree from that file
  • If the user types in a filename and pushes New, create a new Books tree
  • In either case, keep the filename for saving later
  • If the user doesn't give a filename, or the file to load doesn't exist, show an error as a Label on the form

Once a file is loaded (or a new tree made), the form should show a Label with the loaded/new filename, and an overwrite Button to save the current tree into that file. This button should only be active if new Books have been added to the tree since it was loaded.

We went over saving and loading files using BinaryFormatter serialization in class.

Display

On this tab, display all the books in a list, one book on each line. You can just use your ToString method to format the books so that the author name, title and year are all displayed. They should be sorted by title. There are a number of built-in controls that can show multi-line text with scrolling, so don't reinvent the wheel.

At the top of the tab, add two Buttons and a TextBox.

  • The first button sorts the list by author last name instead
  • The second button returns to sorting by title
  • The textbox allows the user to type a string and display only the books that have the string in the textbox as part of their title. It should update the display on every keystroke, like modern search boxes do.

The sorting and filtering is very easy using LINQ, so I'd recommend that route. You'll need your tree set up to implement the yield return IEunmerable. Pay attention to the methods available in the String class to see how to do partial string matching.

Add

Finally, this tab has textboxes to enter the author's name, title and year, and a button to add the new book. It should show an error (as a Label on the form) if anything is left blank, or if the title is a duplicate to what is already in the tree.