MCC - CIS162AD
CS11 File Processing - 15 points![]()
- Modify CS10 Loops and Printing to load and save the changes to the book title combo box to a data file.
- Create a new folder (CS11) and copy all of the contents in the CS10 folder to the new folder. Rename the form and project files inside of Visual Studio. Renaming the files from Windows, will cause the project not to open. It is OK to leave the namespace as CS10.
- Use a combo box with the DropDownStyle set to DropDown for the book titles.
- Allow users to add book titles, remove book titles, clear the book list, display a count of the number of books, print preview and print the book list.
In addition, include an option to allow the user to Load the book titles from a file into the combo box and to Save the book titles in the combo box back to a file.:
File Edit Help Print Preview Add Book About Print Books Remove Book Load Books Clear Book List Save Books Display Book Count Exit- Create the data file (Books.txt) using Notepad and enter the following catalog names on separate lines:
How to Program Introduction to Programming Problem Solving and Programming Object-Oriented Programming Program Design and Data StructuresThe file should be saved in the project's Debug folder which is inside the bin folder.
Folder path: CS11 > bin > Debug
- Delete the entries in the Items.Collection list of the ComboBox.
Hint: Can cut from Items.Collection and Paste into data file Books.txt.
- At the top of program before the statement that declares the namespace, add using System.IO; because this is where the FileStream, StreamReader, and StreamWriter are defined.
using System.IO;
namespace CS11
{
public partial class CS11Form : Form
{
- In the method to handle the menu Load click event, add the code to load the titles from the file. Use a OpenFileDialog control.
- In the method to handle the menu Save click event, add the code to save the changes to the file. Use a SaveFileDialog control.
- Create and code the method that will handle the form closing event.
Use the example (CS11ex) and review pages 302-303 to see the parameters that must be included.
- In the form closing event check if there are any unsaved changes. If so, ask the user if they want to save the changes. If the user selects Yes, call the save file method. If the user selects Cancel, cancel the closing event and return them to the form.
- After writing the method to handle the FormClosing event, its needs to be assigned as the form's FormClosing event handler by doing the following:
- Switch to Design View
- Click on the form one time to select it.
- In the Properties panel there are some buttons to contol how and what is displayed.
- Switch to the Events view by clicking on the "lighting" - 4th button.
- Scroll to the FormClosing event and in the drop-down list box select the method name (frmCS11_FormClosing).
![]()
- Switch back to Properties view by clicking on the 3rd button.
- In the method to handle the menu Exit click event, just call this.Close() to trigger the form closing event.
- A Boolean variable will need to be added at the class-level (cblnIsDataSaved). The flag should be initialized to true and set to false when a catalog is Added, Removed, or Cleared. It should only be set to false if the action is actually performed, so the command needs to be inside the if statement. For example, the Add is only completed if the description is not blank. The flag should be reset to true in the Save method.
- Submit CS11Form.cs, CS11Form.Designer.cs, Books.txt
Revised: 03/25/2010 - www.mesacc.edu/~marquez/cis162ad/cs11_file_processing.html