GCHS Yachts

From GCHSWiki
Jump to: navigation, search

Project Information

Gulf Coast High School, with it's proximity to the Gulf Coast, has decided to open a yacht rental business. And baby, business is good! Business is so good - in fact - the head of the Gulf Coast Yachting Club, Herman Von Yachtterschmidt, has commissioned you to develop a program to keep track of the yacht rentals. Having nothing else to do, you agree.

Program Information

Create a project to input chartering information about yachts and print a summary report (to the computer screen) showing the total revenue, number of charters, and average hours per charter.

Menus

The File menu will contain items for Print Summary, Print Yacht Types, and Exit. Place a separator before Exit. The Edit menu should have items for Clear for Next Charter, Add Yacht Type, Remove Yacht Type, and Display Count of Yacht Types. Include a separator after the Clear item. The Help menu will contain an About item that displays an About form.

The Form

  • The form should contain text boxes for responsible party and hours chartered.
  • A drop-down combo box will contain the type of yacht: Ranger, Wavelength, Catalina, Coronado, Hobie, C & C, Hans Christian, and Excalibur. Any items that are added to the text box during processing must be added to the list.
  • A drop-down list will contain the sizes: 22, 24, 30, 32, 36, 38, and 45 (No new sizes can be added during runtime).
  • A Cancel buton will cancel the operation and return the user to the Menu form.
  • An OK button will calculate and display the price and add to the totals. The calculations will require price per hour, Use the following chart:
Yacht Calculations
Size Hourly Rate
22 95.00
24 137.00
30 160.00
32 192.00
36 250.00
38 400.00
45 550.00
  • A Clear button will clear the contents of the screen controls. The functions of the Clear button are the same as for the Clear for Next Charter menu item.
  • Make the OK button the Accept button and the Clear button the form's Cancel button.

Create a Splash form with an image of a yacht.

Create an About Us form with information about the program and programmer (that's you baby!).

Summary Report

The summary report will print the summary information and send the report to a Print Preview dialog box. The summary information will include Number of Charters, Total Revenue, and Average Hours Chartered. Include your name on the report and identifying labels for the summary information.

Yacht Types Report

Display the yacht types in the combo box in the Print Preview dialog box. Include your name and title at the top of the report.

Planning the Project

You want to build this program in small steps. Design your layout before you create your form. Always look for ways the user can crash your program and keep it from happening.


Yes / No Messagebox

if MessageBox.Show("Are you sure you want to remove " & strName & "?", "Delete Warning", MessageBoxButtons.YesNo) = DialogResult.Yes Then
      ----Your remove code here ----
End If


How to Print You will need to add a PrintPreviewDialog control as well as a PrintDocument for the Yacht Summary printing and a PrintDocuemnt for listing the Yacht types.

Under the Print Summary menu item add the following code to your SubRoutine:

'Print the Chater summary
PrintPreviewDialog1.Document = PrintSummary
PrintPreviewDialog1.ShowDialog()

Under the Print Yacht Types menu item add the following code to your SubRoutine:

PrintPreviewDialog1.Document = PrintYachts
PrintPreviewDialog1.ShowDialog()

Rename one of the PrintDocument controls to PrintYachts. Double click on control and dd the following code to print Yacht Types:

       'Handle printing and print previews when printing all

       Dim PrintFont As New Font("Arial", 12)
       Dim LineHeightSingle As Single = PrintFont.GetHeight + 2
       Dim HorizontalPrintLocationSingle As Single = e.MarginBounds.Left
       Dim VerticalPrintLocationSingle As Single = e.MarginBounds.Top
       Dim PrintLineString As String

       'Print the heading
       Using HeadingFont As New Font("Arial", 14, FontStyle.Bold)
           e.Graphics.DrawString("Yacht Types", HeadingFont, Brushes.Black, HorizontalPrintLocationSingle, _
                   VerticalPrintLocationSingle)
       End Using

       'Loop through the entire list
       For intListIndex As Integer = 0 To frmYacht.cboYachts.Items.Count - 1
           'Increment the Y position for the next loop
           VerticalPrintLocationSingle += LineHeightSingle

           'Set up a line
           PrintLineString = frmYacht.cboYachts.Items(intListIndex).ToString()
           'Send the line to the graphics page object
           e.Graphics.DrawString(PrintLineString, PrintFont, Brushes.Black, HorizontalPrintLocationSingle, _
                   VerticalPrintLocationSingle)
       Next intListIndex

Rename the other PrintDocument to PrintSummary. Double click on the control and add the following code to print the Summary Yacht Report:

'Handle printing and print previews when printing selected items

       Dim PrintFont As New Font("Arial", 12)
       Dim HeadingFont As New Font("Arial", 14, FontStyle.Bold)
       Dim LineHeightSingle As Single = PrintFont.GetHeight + 2
       Dim HorizontalPrintLocationSingle As Single = e.MarginBounds.Left
       Dim VerticalPrintLocationSingle As Single = e.MarginBounds.Top
       Dim strPrintLine As String
       Dim decAveHours = gintHours / gintCounter

       'Set up and dispaly heading lines
       strPrintLine = "Summary Information"
       e.Graphics.DrawString(strPrintLine, HeadingFont, Brushes.Black, HorizontalPrintLocationSingle, VerticalPrintLocationSingle)
       strPrintLine = "by Mr. Martin"
       VerticalPrintLocationSingle += LineHeightSingle
       e.Graphics.DrawString(strPrintLine, HeadingFont, Brushes.Black, HorizontalPrintLocationSingle, VerticalPrintLocationSingle)

       'Leave a blank line between the heading and detail line.
       VerticalPrintLocationSingle += LineHeightSingle * 2

       'Set up the selected line
       strPrintLine = "Number of Charters: " & gintCounter
       e.Graphics.DrawString(strPrintLine, PrintFont, Brushes.Black, HorizontalPrintLocationSingle, VerticalPrintLocationSingle)

       VerticalPrintLocationSingle += LineHeightSingle
       strPrintLine = "Total Revenue: " & FormatCurrency(gdecPrice)
       e.Graphics.DrawString(strPrintLine, PrintFont, Brushes.Black, HorizontalPrintLocationSingle, VerticalPrintLocationSingle)

       VerticalPrintLocationSingle += LineHeightSingle
       strPrintLine = "Average Hours Chartered: " & decAveHours.ToString("N2")
       'Send the line to the graphics page object
       e.Graphics.DrawString(strPrintLine, PrintFont, Brushes.Black, HorizontalPrintLocationSingle, VerticalPrintLocationSingle)

Test the printing functions.

Final Assessment

  • Ensure the properties of all objects are set, especially the Name (my pet peeve).
  • Always test the tab order on your forms. Fix it if necessary by changing the TabIndex properties of the controls.
  • Provide visual separation for input fields and output fields and always make it clear to the user which are which. (use labels)
  • Make sure that your forms can be navigated and entered from the keyboard. Always set an Accept Button for every form.
  • To make a label maintain its size regardless of the value of the Text property, set AutoSize to False.
  • To make the text in a text box right justified or centered, set the TextAligned property.
  • Validate your data using the Val Function