|
Dictionary-Based Collections Application: Bethesda
Car Rental |
|
|
A dictionary is a list of items with the following two
rules:
- Each item is a combination of a key and a value. An item can be made
of three parts: a key, a value, and a correspondence between them. The
correspondence can be represented by the assignment operator:
Key=Value. In some environments, the = operator is used. In some
others, the : operator is used. Yet in some others, there is no actual
operator that joins both sides but you must know that the key and the
value go in pair
- As each item is a combination of a key and a value, each key must be
unique. The list of items in the dictionary can be very huge, sometimes
in the thousands or even millions. Among the items, each key must be
distinct from any other key in the dictionary
|
In some cases, in addition to these two rules, the
items should - in some cases must - be ordered. To order the items, the
keys are used. Because in most cases a dictionary is made of words, the
keys are ordered in alphabetical order. A dictionary can also be made of
items whose keys are date values. In this case, the items would be ordered
in chronological order.
There are various types of dictionary types of list
used in daily life. The word "dictionary" here does not imply the
traditional dictionary that holds the words and their meanings in the
English language. The concept is applied in various scenarios.
To illustrate dictionary-based collections, we will
create an application used to run a car-rental bompany.
Practical
Learning: Introducing Dictionary Collections
|
|
- Start Microsoft Visual Studio
- To create a new application, on the main menu, click FILE -> New
-> Project...
- In the middle list, click Windows Forms Application and set the
Name to BethesdaCarRental1
- Click OK
- Save the following picture to your computer
Because customers have many needs, a car rental
company has various types of vehicles, small, medium, big, trucks,
passenger-oriented, etc. as a result, not all cars cost the same to rent.
To make our application interesting, we will also use different ways to
set the rental cost depending on whether the car will be rented during the
week, during a weekend, or for a whole month.
Practical
Learning: Setting the Rental Rates
|
|
- To add a new form to the project, in the Solution Explorer,
right-click BethesdaCarRental1 -> Add -> Windows Form...
- Set the Name to RentalRates and press Enter
- Add a ListView to the form and create its Columns as follows:
(Name) |
Text |
TextAlign |
Width |
colCategory |
Category |
|
90 |
colDaily |
Daily |
Right |
|
colWeekly |
Weekly |
Right |
|
colMonthly |
Monthly |
Right |
|
colWeekend |
Weekend |
Right |
|
- Create its Items as follows:
ListViewItem |
SubItems |
SubItems |
SubItems |
SubItems |
|
Text |
Text |
Text |
Text |
Economy |
35.95 |
32.75 |
28.95 |
24.95 |
Compact |
39.95 |
35.75 |
32.95 |
28.95 |
Standard |
45.95 |
39.75 |
35.95 |
32.95 |
Full Size |
49.95 |
42.75 |
38.95 |
35.95 |
Mini Van |
55.95 |
50.75 |
45.95 |
42.95 |
SUV |
55.95 |
50.75 |
45.95 |
42.95 |
Truck |
42.75 |
38.75 |
35.95 |
32.95 |
Van |
69.95 |
62.75 |
55.95 |
52.95 |
- Complete the design of the form as follows:
- Save all
The employees, also called clerks, of a car rental
company register new customers, allocate cars to them, perform the rental
process, and complete the renting when a customer brings the car back.
To deal with the employees of our company, we will
create a class named Employee. We will keep information
to a minimum.
Practical
Learning: Creating the Employees
|
|
- To add a new class to the project, in the Class View, right-click
BethesdaCarRental1 -> Add -> Class...
- Set the Class Name to Employee and click Add
- Change the Employee.cs file as follows:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace BethesdaCarRental1
{
[Serializable]
public class Employee
{
public string FirstName { get; set; }
public string LastName { get; set; }
public string Title { get; set; }
public string EmployeeName
{
get { return LastName + ", " + FirstName; }
}
public Employee()
{
FirstName = "Unknown";
LastName = "Unknown";
Title = "N/A";
}
public Employee(string fname, string lname, string title)
{
FirstName = fname;
LastName = lname;
Title = title;
}
}
}
- To add a new form to the application, in the Solution Explorer,
right-click BethesdaCarRental1 -> Add -> Windows Form...
- Set the Name to Employees and click Add
- From the Toolbox, add a ListView to the form
- While the new list view is still selected, in the Properties
window, click the ellipsis button of the Columns field and create the
columns as follows:
(Name) |
Text |
TextAlign |
Width |
colEmployeeNumber |
Empl # |
|
45 |
colFirstName |
First Name |
|
65 |
colLastName |
Last Name |
|
65 |
colEmployeeName |
Employee Name |
|
140 |
colTitle |
Title |
|
120 |
- Design the form as follows:
|
Control |
(Name) |
Text |
Other Properties |
ListView |
|
lvwEmployees |
|
Anchor: Top, Bottom, Left, Right
FullRowSelect: True GridLines: True View:
Details |
Button |
|
btnNewEmployee |
New &Employee... |
|
Button |
|
btnClose |
&Close |
|
|
- To add another form to the application, in the Solution Explorer,
right- click BethesdaCarRental1 -> Add -> Windows Form...
- Set the Name to EmployeeEditor and click Add
- Design the form as follows:
|
Control |
(Name) |
Text |
Properties |
Label |
|
|
&Employee #: |
|
TextBox |
|
txtEmployeeNumber |
|
Mask: 00-000 Modifiers: public |
Label |
|
|
First Name: |
|
TextBox |
|
txtFirstName |
|
Modifiers: public |
Label |
|
|
Last Name: |
|
TextBox |
|
txtLastName |
|
Modifiers: public |
Label |
|
|
Employee Name: |
|
TextBox |
|
txtEmployeeName |
|
Enabled: False Modifiers: public |
Label |
|
|
Title: |
|
TextBox |
|
txtTitle |
|
Modifiers: public |
Button |
|
btnOK |
OK |
DialogResult: OK |
Button |
|
btnCancel |
Cancel |
DialogResult: Cancel |
Form |
|
|
AcceptButton: btnOK CancelButton: btnCancel
FormBorderStyle: FixedDialog MaximizeBox: False
MinimizeBox: False ShowInTaskbar: False |
|
- Click the Last Name text box
- In the Properties window, click the Events button and double-click
Leave
- Implement the event as follows:
// This code is used to create and display the customer's full name
private void txtLastName_Leave(object sender, EventArgs e)
{
string strFirstName = txtFirstName.Text;
string strLastName = txtLastName.Text;
string strEmployeeName;
if (strFirstName.Length == 0)
strEmployeeName = strLastName;
else
strEmployeeName = strLastName + ", " + strFirstName;
txtEmployeeName.Text = strEmployeeName;
}
- Save all
The purpose of a car rental company is to rent
vehicles. A vehicle record contains such information as the tag number,
the make, the model, the category, etc. The tag number be unique.
Practical
Learning: Creating the Vehicles Records
|
|
- To add a new class to the project, in the Class View, right-click
BethedaCarRental1 -> Add -> Class...
- Set the Class Name to Vehicle and click Add
- Change the file as follows:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace BethesdaCarRental1
{
[Serializable]
public class Vehicle
{
public string Make { get; set; }
public string Model { get; set; }
public int Doors { get; set; }
public int Passengers { get; set; }
public string Condition { get; set; }
public string Category { get; set; }
public string Availability { get; set; }
public Vehicle()
{
Make = "";
Model = "";
Doors = 4;
Passengers = 4;
Condition = "Excellent";
Category = "Compact";
Availability = "Available";
}
public Vehicle(string make, string model,
int doors, int passengers, string condition,
string category, string available)
{
Make = make;
Model = model;
Doors = doors;
Passengers = passengers;
Condition = condition;
Category = category;
Availability = available;
}
}
}
- To add a new form to the application, in the Solution Explorer,
right-click BethesdaCarRental1 -> Add -> Windows Forms
- Set the Name to VehicleEditor and click Add
- Design the form as follows:
|
Control |
(Name) |
Text |
Other Properties |
Label |
|
|
Tag Number: |
|
TextBox |
|
txtTagNumber |
|
|
Label |
|
|
Make: |
|
TextBox |
|
txtMake |
|
|
Label |
|
|
Model: |
|
TextBox |
|
txtModel |
|
|
Label |
|
|
Doors |
|
TextBox |
|
txtDoors |
|
|
Label |
|
|
Passengers: |
|
TextBox |
|
txtPassengers |
|
|
Label |
|
|
Condition: |
|
ComboBox |
|
cbxCondition |
|
Items: Good Other
Excellent Driveable Needs Repair |
Label |
|
|
Category: |
|
ComboBox |
|
cbxCategories |
|
Items: SUV Truck Full
Size Mini Van Compact Standard Economy
Passenger Van |
Label |
|
|
Availability |
|
ComboBox |
|
|
cbxAvailabilities |
Items: Rented Available
Being Serviced |
PictureBox |
|
pbxVehicle |
|
SizeMode: Zoom |
Button |
|
btnSelectPicture |
&Select Vehicle Picture... |
|
Label |
|
Picture Name |
lblPictureName |
|
Button |
|
Submit |
btnSubmit |
|
Button |
|
Close |
btnClose |
DialogResult: Cancel |
OpenFileDialog |
|
(Name): dlgOpen
Title: Select Item Picture DefaultExt: jpg
Filter: JPEG Files (*.jpg,*.jpeg)|*.jpg|GIF Files
(*.gif)|*.gif|Bitmap Files (*.bmp)|*.bmp|PNG Files
(*.png)|*.png |
Form |
|
|
FormBorderStyle: FixedDialog
MaximizeBox: False MinimizeBox: False
ShowInTaskbar: False |
|
- Double-click the Select Vehicle Picture button and implement its
event as follows:
private void btnSelectPicture_Click(object sender, EventArgs e)
{
if (dlgPicture.ShowDialog() == DialogResult.OK)
{
lblPictureName.Text = dlgPicture.FileName;
pbxVehicle.Image = Image.FromFile(lblPictureName.Text);
}
}
- Save all
A rental order is a contract that describes the
transaction between the car-rental company and the customer. The contract
contains the customer information, the car information, and other related
pieces of information. A rental order must be uniquely identified. This is
usually done by a receive number (or an invoice number).
Practical
Learning: Creating the Vehicles Records
|
|
- To add a new class to the project, in the Class View, right-click
BethesdaCarRental -> Add -> Class...
- Set the Class Name to RentalOrder and press Enter
- Access the RentalOrder.cs file and change it as follows:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace BethesdaCarRental1
{
[Serializable]
public class RentalOrder
{
public DateTime DateProcessed { get; set; }
public string ClerkNumber { get; set; }
public string CustomerFirstName { get; set; }
public string CustomerLastName { get; set; }
public string CustomerAddress { get; set; }
public string CustomerCity { get; set; }
public string CustomerState { get; set; }
public string CustomerZIPCode { get; set; }
public string VehicleTagNumber { get; set; }
public string VehicleCondition { get; set; }
public string TankLevel { get; set; }
public int MileageStart { get; set; }
public int MileageEnd { get; set; }
public int MileageTotal { get; set; }
public DateTime RentStartDate { get; set; }
public DateTime RentEndDate { get; set; }
public int TotalDays { get; set; }
public double RateApplied { get; set; }
public double SubTotal { get; set; }
public double TaxRate { get; set; }
public double TaxAmount { get; set; }
public double OrderTotal { get; set; }
public double OrderStatus { get; set; }
public string Notes { get; set; }
}
}
- To add a new form to the project, in the Solution Explorer,
right-click BethesdaCarRenat1 -> Add -> Windows Form...
- Set the Name to UpdateRentalOrder and press Enter
- From the Printing section of the Toolbox, click PrintDocument and
click the form
- In the Properties window, set its (Name) to docPrint and
press Enter
- From the Printing section of the Toolbox, click PrintDialog and
click the form
- In the Properties window, change its Name to dlgPrint
- Still in the Properties windows, set its Document property to
docPrint
- From the Printing section of the Toolbox, click PrintPreviewDialog
and click the form
- In the Properties window, change its (Name) to dlgPrintPreview
- Still in the Properties windows, set its Document property to
docPrint
- Design the form as follows:
|
Control |
(Name) |
Text |
Other Properties |
Label |
|
|
Processed By: |
AutoSize: False BackColor: Gray BorderStyle:
FixedSingle ForeColor: White TextAlign:
MiddleLeft |
Label |
|
|
Order Timing |
AutoSize: False BackColor: Gray BorderStyle:
FixedSingle ForeColor: White TextAlign:
MiddleLeft |
Label |
|
|
Employee #: |
|
TextBox |
|
txtEmployeeNumber |
|
|
TextBox |
|
txtEmployeeName |
|
|
Label |
|
|
Date Processed: |
|
TextBox |
|
dtpDateProcessed |
|
|
Label |
|
|
Processed For |
AutoSize: False BackColor: Gray BorderStyle:
FixedSingle ForeColor: White TextAlign:
MiddleLeft |
Label |
|
|
Rent Start Date: |
|
DateTimePicker |
|
dtpRentStartDate |
|
|
Label |
|
|
First Name: |
|
TextBox |
|
txtCustomerFirstName |
|
|
Label |
|
|
Last Name: |
|
TextBox |
|
txtCustomerLastName |
|
|
Label |
|
|
Rent End Date: |
|
DateTimePicker |
|
dtpRentEndDate |
|
|
Label |
|
|
Address: |
|
TextBox |
|
txtCustomerAddress |
|
|
Label |
|
|
Total Days: |
|
TextBox |
|
txtTotalDays |
1 |
TextAlign: Right |
Label |
|
|
City: |
|
TextBox |
|
txtCustomerCity |
|
|
Label |
|
|
State: |
|
Label |
|
Order Evaluation |
|
AutoSize: False BackColor: Gray BorderStyle:
FixedSingle ForeColor: White TextAlign:
MiddleLeft |
ComboBox |
|
cbxCustomerStates |
|
DropDownStyle: DropDownList Sorted: True
Items: AB, AL, AK, AZ, AR, BC, CA, CO, CT, DE, DC, FL,
GA, HI, ID, IL, IN, IA, KS, KY, LA, ME, MD, MA, MI,
MN, MS, MO, MT, NB, NE, NV, NH, NJ, NL, NM, NS, NY,
NC, ND, OH, OK, ON, OR, PA, PE, QC, RI, SC, SD, SK,
TN, TX, UT, VT, VA, WA, WV, WI, WY |
Label |
|
|
ZIP/Postal Code: |
|
TextBox |
|
txtCustomerZIPCode |
|
|
Label |
|
|
Rate Applied: |
|
TextBox |
|
txtRateApplied |
0.00 |
TextAlign: Right |
Button |
|
btnRentalRates |
Rental Rates |
|
Label |
|
Vehicle Selected |
|
AutoSize: False BackColor: Gray BorderStyle:
FixedSingle ForeColor: White TextAlign:
MiddleLeft |
Label |
|
|
Sub-Total: |
|
TextBox |
|
txtSubTotal |
0.00 |
TextAlign: Right |
Button |
|
btnCalculate |
Calculate |
|
Label |
|
|
Tag Number: |
|
TextBox |
|
txtTagNumber |
|
|
Label |
|
|
Condition: |
|
ComboBox |
|
cbxVehicleConditions |
|
Sorted: True Items: Bad Good Other
Excellent Driveable Needs Repair |
Label |
|
|
Tax Rate: |
|
TextBox |
|
txtTaxRate |
7.75 |
TextAlign: Right |
Label |
|
|
% |
|
Label |
|
|
Make: |
|
TextBox |
|
txtMake |
|
|
Label |
|
|
Model: |
|
TextBox |
|
txtModel |
|
|
Label |
|
|
Tax Amount: |
|
TextBox |
|
txtTaxAmount |
0.00 |
TextAlign: Right |
Button |
|
Print... |
btnPrint |
|
Label |
|
|
Mileage Start: |
|
TextBox |
|
txtMileageStart |
|
TextAlign: Right |
Label |
|
|
Tank Level: |
|
ComboBox |
|
cbxTanksLevels |
|
Empty 1/4 Empty Half Tank 3/4 Full
Full |
Label |
|
|
Order Total: |
|
TextBox |
|
txtOrderTotal |
0.00 |
TextAlign: Right |
Button |
|
btnPrintPreview |
Print Preview... |
|
Label |
|
|
Mileage End: |
|
TextBox |
|
txtMileageEnd |
|
TextAlign: Right |
Label |
|
|
Mileage Total: |
|
TextBox |
|
txtMileageTotal |
|
TextAlign: Right |
Label |
|
Order Status |
|
|
ComboBox |
|
|
cbxOrderStatus |
Items: Order Reserved Vehicle With Customer
Rental Order Completed |
Label |
|
|
Notes: |
|
TextBox |
|
txtNotes |
|
Multiline: True ScrollBars: Vertical |
Label |
|
Receipt #: |
|
|
TextBox |
|
|
txtReceiptNumber |
|
Button |
|
btnOpen |
Open |
|
Button |
|
btnUpdateRentalOrder |
Update Rental Order |
|
Button |
|
Close |
btnClose |
|
|
- On the Update Rental Order form, click the Mileage End text box
- On the Properties window, click the Events button and double-click
Leave
- Implement the event as follows:
private void txtMileageEnd_Leave(object sender, EventArgs e)
{
int mileageStart = 0, mileageEnd = 0;
try
{
mileageStart = int.Parse(txtMileageStart.Text);
}
catch (FormatException fe)
{
MessageBox.Show("There was a problem with the mileage start value.\n" +
"Please report the error as\n" +
fe.Message,
"Bethesda Car Rental",
MessageBoxButtons.OK, MessageBoxIcon.Information);
}
try
{
mileageEnd = int.Parse(txtMileageEnd.Text);
}
catch (FormatException fe)
{
MessageBox.Show("There was a problem with the mileage end value.\n" +
"Please report the error as\n" +
fe.Message,
"Bethesda Car Rental",
MessageBoxButtons.OK, MessageBoxIcon.Information);
}
txtMileageTotal.Text = (mileageEnd - mileageStart).ToString();
}
- Return to the Update Rental Order form and double-click the Rent
Start Date date time picker control
- Implement the event as follows:
private void dtpRentStartDate_ValueChanged(object sender, EventArgs e)
{
dtpRentEndDate.Value = dtpRentStartDate.Value;
}
- Return to the Update Rental Order form and double-click the Rent
End Date control
- Implement its Click event as follows:
// This event approximately evaluates the number of days as a
// difference between the end date and the starting date
private void dtpRentEndDate_ValueChanged(object sender, EventArgs e)
{
DateTime dteStart = dtpRentStartDate.Value;
DateTime dteEnd = dtpRentEndDate.Value;
// Let's calculate the difference in days
TimeSpan tme = dteEnd - dteStart;
int days = tme.Days;
// If the customer returns the car the same day,
// we consider that the car was rented for 1 day
if (days == 0)
days = 1;
txtTotalDays.Text = days.ToString();
// At any case, we will let the clerk specify the actual number of days
}
- Return to the Order Processing form and double-click the Rental
Rates button
- Implement its event as follows:
private void btnRentalRates_Click(object sender, EventArgs e)
{
RentalRates wndRates = new RentalRates();
wndRates.Show();
}
- Return to the Order Processing form and double-click the Calculate
button
- Implement its event as follows:
private void btnCalculate_Click(object sender, EventArgs e)
{
int Days = 0;
double RateApplied = 0.00;
double SubTotal = 0.00;
double TaxRate = 0.00;
double TaxAmount = 0.00;
double OrderTotal = 0.00;
try
{
Days = int.Parse(txtTotalDays.Text);
}
catch (FormatException)
{
MessageBox.Show("Invalid Number of Days",
"Bethesda Car Rental",
MessageBoxButtons.OK, MessageBoxIcon.Information);
}
try
{
RateApplied = double.Parse(txtRateApplied.Text);
}
catch (FormatException)
{
MessageBox.Show("Invalid Amount for Rate Applied",
"Bethesda Car Rental",
MessageBoxButtons.OK, MessageBoxIcon.Information);
}
SubTotal = Days * RateApplied;
txtSubTotal.Text = SubTotal.ToString("F");
try
{
TaxRate = double.Parse(txtTaxRate.Text);
}
catch (FormatException)
{
MessageBox.Show("Invalid Tax Rate",
"Bethesda Car Rental",
MessageBoxButtons.OK, MessageBoxIcon.Information);
}
TaxAmount = SubTotal * TaxRate / 100;
txtTaxAmount.Text = TaxAmount.ToString("F");
OrderTotal = SubTotal + TaxAmount;
txtOrderTotal.Text = OrderTotal.ToString("F");
}
- Return to the Update Rental Order form and, under the form,
double-click docPrint
- Implement its event as follows:
private void docPrint_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
{
e.Graphics.DrawLine(new Pen(Color.Black, 2), 80, 90, 750, 90);
e.Graphics.DrawLine(new Pen(Color.Black, 1), 80, 93, 750, 93);
string strDisplay = "Bethesda Car Rental";
System.Drawing.Font fntBoldString = new Font("Times New Roman", 28, FontStyle.Bold);
e.Graphics.DrawString(strDisplay, fntBoldString, Brushes.Black, 240, 100);
strDisplay = "Vehicle Rental Order";
System.Drawing.Font fntRegularString = new System.Drawing.Font("Times New Roman", 22, FontStyle.Regular);
e.Graphics.DrawString(strDisplay, fntRegularString, Brushes.Black, 280, 150);
e.Graphics.DrawLine(new Pen(Color.Black, 1), 80, 187, 750, 187);
e.Graphics.DrawLine(new Pen(Color.Black, 2), 80, 190, 750, 190);
fntBoldString = new Font("Times New Roman", 12, FontStyle.Bold);
fntRegularString = new System.Drawing.Font("Times New Roman", 12, FontStyle.Regular);
e.Graphics.DrawString("Receipt #: ", fntBoldString, Brushes.Black, 100, 220);
e.Graphics.DrawString(txtReceiptNumber.Text, fntRegularString, Brushes.Black, 260, 220);
e.Graphics.DrawLine(new Pen(Color.Black, 1), 100, 240, 380, 240);
e.Graphics.DrawString("Processed By: ", fntBoldString, Brushes.Black, 420, 220);
e.Graphics.DrawString(txtEmployeeName.Text, fntRegularString, Brushes.Black, 550, 220);
e.Graphics.DrawLine(new Pen(Color.Black, 1), 420, 240, 720, 240);
e.Graphics.FillRectangle(Brushes.Gray, new Rectangle(100, 260, 620, 20));
e.Graphics.DrawRectangle(Pens.Black, new Rectangle(100, 260, 620, 20));
e.Graphics.DrawString("Customer", fntBoldString, Brushes.White, 100, 260);
e.Graphics.DrawString("First Name: ", fntBoldString, Brushes.Black, 100, 300);
e.Graphics.DrawString(txtCustomerFirstName.Text, fntBoldString, Brushes.Black, 260, 300);
e.Graphics.DrawString("Last Name: ", fntBoldString, Brushes.Black, 420, 300);
e.Graphics.DrawString(txtCustomerLastName.Text, fntBoldString, Brushes.Black, 540, 300);
e.Graphics.DrawLine(new Pen(Color.Black, 1), 100, 320, 720, 320);
e.Graphics.DrawString("Address: ", fntBoldString, Brushes.Black, 100, 330);
e.Graphics.DrawString(txtCustomerAddress.Text, fntRegularString, Brushes.Black, 260, 330);
e.Graphics.DrawLine(new Pen(Color.Black, 1), 100, 350, 720, 350);
strDisplay = txtCustomerCity.Text + " " + cbxCustomerStates.Text + " " + txtCustomerZIPCode.Text;
e.Graphics.DrawString(strDisplay, fntRegularString, Brushes.Black, 260, 360);
e.Graphics.DrawLine(new Pen(Color.Black, 1), 260, 380, 720, 380);
e.Graphics.FillRectangle(Brushes.Gray, new Rectangle(100, 410, 620, 20));
e.Graphics.DrawRectangle(Pens.Black, new Rectangle(100, 410, 620, 20));
e.Graphics.DrawString("Car Information", fntBoldString, Brushes.White, 100, 410);
e.Graphics.DrawString("Tag #: ", fntBoldString, Brushes.Black, 100, 450);
e.Graphics.DrawString(txtTagNumber.Text, fntRegularString, Brushes.Black, 260, 450);
e.Graphics.DrawLine(new Pen(Color.Black, 1), 100, 470, 380, 470);
e.Graphics.DrawString("Condition: ", fntBoldString, Brushes.Black, 420, 450);
e.Graphics.DrawString(cbxVehiclesConditions.Text, fntRegularString, Brushes.Black, 530, 450); // ?
e.Graphics.DrawLine(new Pen(Color.Black, 1), 420, 470, 720, 470);
e.Graphics.DrawString("Make: ", fntBoldString, Brushes.Black, 100, 480);
e.Graphics.DrawString(txtMake.Text, fntRegularString, Brushes.Black, 260, 480);
e.Graphics.DrawLine(new Pen(Color.Black, 1), 100, 500, 380, 500);
e.Graphics.DrawString("Model: ", fntBoldString, Brushes.Black, 420, 480);
e.Graphics.DrawString(txtModel.Text, fntRegularString, Brushes.Black, 530, 480);
e.Graphics.DrawLine(new Pen(Color.Black, 1), 420, 500, 720, 500);
e.Graphics.DrawString("Vehicle Condition: ", fntBoldString, Brushes.Black, 100, 510);
e.Graphics.DrawString(cbxVehiclesConditions.Text, fntRegularString, Brushes.Black, 260, 510);
e.Graphics.DrawLine(new Pen(Color.Black, 1), 100, 530, 380, 530);
e.Graphics.DrawString("Tank Level: ", fntBoldString, Brushes.Black, 420, 510);
e.Graphics.DrawString(cbxTanksLevels.Text, fntRegularString, Brushes.Black, 530, 510);
e.Graphics.DrawLine(new Pen(Color.Black, 1), 420, 530, 720, 530);
e.Graphics.DrawString("Mileage Start:", fntBoldString, Brushes.Black, 100, 540);
e.Graphics.DrawString(txtMileageStart.Text, fntRegularString, Brushes.Black, 260, 540);
e.Graphics.DrawLine(new Pen(Color.Black, 1), 100, 560, 380, 560);
e.Graphics.DrawString("Mileage End:", fntBoldString, Brushes.Black, 420, 540);
e.Graphics.DrawString(txtMileageEnd.Text, fntRegularString, Brushes.Black, 530, 540);
e.Graphics.DrawLine(new Pen(Color.Black, 1), 420, 560, 720, 560);
e.Graphics.FillRectangle(Brushes.Gray, new Rectangle(100, 590, 620, 20));
e.Graphics.DrawRectangle(Pens.Black, new Rectangle(100, 590, 620, 20));
e.Graphics.DrawString("Order Timing Information", fntBoldString, Brushes.White, 100, 590);
e.Graphics.DrawString("Start Date:", fntBoldString, Brushes.Black, 100, 620);
e.Graphics.DrawString(dtpRentStartDate.Value.ToString("D"), fntRegularString, Brushes.Black, 260, 620);
e.Graphics.DrawLine(new Pen(Color.Black, 1), 100, 640, 720, 640);
e.Graphics.DrawString("End Date:", fntBoldString, Brushes.Black, 100, 650);
e.Graphics.DrawString(dtpRentEndDate.Value.ToString("D"), fntRegularString, Brushes.Black, 260, 650);
e.Graphics.DrawLine(new Pen(Color.Black, 1), 100, 670, 520, 670);
e.Graphics.DrawString("Total Days:", fntBoldString, Brushes.Black, 550, 650);
e.Graphics.DrawString(txtTotalDays.Text, fntRegularString, Brushes.Black, 640, 650);
e.Graphics.DrawLine(new Pen(Color.Black, 1), 550, 670, 720, 670);
e.Graphics.FillRectangle(Brushes.Gray, new Rectangle(100, 700, 620, 20));
e.Graphics.DrawRectangle(Pens.Black, new Rectangle(100, 700, 620, 20));
e.Graphics.DrawString("Order Evaluation", fntBoldString, Brushes.White, 100, 700);
StringFormat fmtString = new StringFormat();
fmtString.Alignment = StringAlignment.Far;
e.Graphics.DrawString("Rate Applied:", fntBoldString, Brushes.Black, 100, 740);
e.Graphics.DrawString(txtRateApplied.Text, fntRegularString, Brushes.Black, 300, 740, fmtString);
e.Graphics.DrawLine(new Pen(Color.Black, 1), 100, 760, 380, 760);
e.Graphics.DrawString("Tax Rate:", fntBoldString, Brushes.Black, 420, 740);
e.Graphics.DrawString(txtTaxRate.Text, fntRegularString, Brushes.Black, 640, 740, fmtString);
e.Graphics.DrawLine(new Pen(Color.Black, 1), 420, 760, 720, 760);
e.Graphics.DrawString("Sub-Total:", fntBoldString, Brushes.Black, 100, 770);
e.Graphics.DrawString(txtSubTotal.Text, fntRegularString, Brushes.Black, 300, 770, fmtString);
e.Graphics.DrawLine(new Pen(Color.Black, 1), 100, 790, 380, 790);
e.Graphics.DrawString("Tax Amount:", fntBoldString, Brushes.Black, 420, 770);
e.Graphics.DrawString(txtTaxAmount.Text, fntRegularString, Brushes.Black, 640, 770, fmtString);
e.Graphics.DrawLine(new Pen(Color.Black, 1), 420, 790, 720, 790);
e.Graphics.DrawString("Order Total:", fntBoldString, Brushes.Black, 420, 800);
e.Graphics.DrawString(txtOrderTotal.Text, fntRegularString, Brushes.Black, 640, 800, fmtString);
e.Graphics.DrawLine(new Pen(Color.Black, 1), 420, 820, 720, 820);
}
- Return to the Update Rental Order form and double-click the Print
button
- Implement the event as follows:
private void btnPrint_Click(object sender, EventArgs e)
{
if (dlgPrint.ShowDialog() == DialogResult.OK)
docPrint.Print();
}
- Return to the Update Rental Order form and double-click the Print
Preview button
- Implement the event as follows:
private void btnPrintPreview_Click(object sender, EventArgs e)
{
dlgPrintPreview.ShowDialog();
}
- To add a new form to the project, in the Solution Explorer,
right-click BethesdaCarRenat1 -> Add -> Windows Form...
- Set the Name to NewRentalOrder and press Enter
- From the Printing section of the Toolbox, click PrintDocument and
click the form
- In the Properties window, set its (Name) to docPrint and
press Enter
- From the Printing section of the Toolbox, click PrintDialog and
click the form
- In the Properties window, change its Name to dlgPrint
- Still in the Properties windows, set its Document property to
docPrint
- From the Printing section of the Toolbox, click PrintPreviewDialog
and click the form
- In the Properties window, change its (Name) to dlgPrintPreview
- Still in the Properties windows, set its Document property to
docPrint
- Set the dimensions to those of the Update Rental Order form, then
copy all controls from the Update Rental Order form and paste them on
the New Rental Order form.
Design the form as follows:
|
Control |
(Name) |
Text |
Other Properties |
Button |
|
btnSaveRentalOrder |
Save Rental Order |
|
Button |
|
Close |
btnClose |
|
|
- On the New Rental Order form, double-click the Rent Start Date
date time picker control
- Implement the event as follows:
private void dtpRentStartDate_ValueChanged(object sender, EventArgs e)
{
dtpRentEndDate.Value = dtpRentStartDate.Value;
}
- Return to the New Rental Order form and double-click the Rental
Rates button
- Implement its event as follows:
private void btnRentalRates_Click(object sender, EventArgs e)
{
RentalRates wndRates = new RentalRates();
wndRates.Show();
}
- Return to the Order Processing form and, under the form,
double-click docPrint
- Implement its event as follows:
private void docPrint_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
{
e.Graphics.DrawLine(new Pen(Color.Black, 2), 80, 90, 750, 90);
e.Graphics.DrawLine(new Pen(Color.Black, 1), 80, 93, 750, 93);
string strDisplay = "Bethesda Car Rental";
System.Drawing.Font fntBoldString = new Font("Times New Roman", 28, FontStyle.Bold);
e.Graphics.DrawString(strDisplay, fntBoldString, Brushes.Black, 240, 100);
strDisplay = "Vehicle Rental Order";
System.Drawing.Font fntRegularString = new System.Drawing.Font("Times New Roman", 22, FontStyle.Regular);
e.Graphics.DrawString(strDisplay, fntRegularString, Brushes.Black, 280, 150);
e.Graphics.DrawLine(new Pen(Color.Black, 1), 80, 187, 750, 187);
e.Graphics.DrawLine(new Pen(Color.Black, 2), 80, 190, 750, 190);
fntBoldString = new Font("Times New Roman", 12, FontStyle.Bold);
fntRegularString = new System.Drawing.Font("Times New Roman", 12, FontStyle.Regular);
e.Graphics.DrawString("Receipt #: ", fntBoldString, Brushes.Black, 100, 220);
e.Graphics.DrawString(txtReceiptNumber.Text, fntRegularString, Brushes.Black, 260, 220);
e.Graphics.DrawLine(new Pen(Color.Black, 1), 100, 240, 380, 240);
e.Graphics.DrawString("Processed By: ", fntBoldString, Brushes.Black, 420, 220);
e.Graphics.DrawString(txtEmployeeName.Text, fntRegularString, Brushes.Black, 550, 220);
e.Graphics.DrawLine(new Pen(Color.Black, 1), 420, 240, 720, 240);
e.Graphics.FillRectangle(Brushes.Gray, new Rectangle(100, 260, 620, 20));
e.Graphics.DrawRectangle(Pens.Black, new Rectangle(100, 260, 620, 20));
e.Graphics.DrawString("Customer", fntBoldString, Brushes.White, 100, 260);
e.Graphics.DrawString("First Name: ", fntBoldString, Brushes.Black, 100, 300);
e.Graphics.DrawString(txtCustomerFirstName.Text, fntBoldString, Brushes.Black, 260, 300);
e.Graphics.DrawString("Last Name: ", fntBoldString, Brushes.Black, 420, 300);
e.Graphics.DrawString(txtCustomerLastName.Text, fntBoldString, Brushes.Black, 540, 300);
e.Graphics.DrawLine(new Pen(Color.Black, 1), 100, 320, 720, 320);
e.Graphics.DrawString("Address: ", fntBoldString, Brushes.Black, 100, 330);
e.Graphics.DrawString(txtCustomerAddress.Text, fntRegularString, Brushes.Black, 260, 330);
e.Graphics.DrawLine(new Pen(Color.Black, 1), 100, 350, 720, 350);
strDisplay = txtCustomerCity.Text + " " + cbxCustomerStates.Text + " " + txtCustomerZIPCode.Text;
e.Graphics.DrawString(strDisplay, fntRegularString, Brushes.Black, 260, 360);
e.Graphics.DrawLine(new Pen(Color.Black, 1), 260, 380, 720, 380);
e.Graphics.FillRectangle(Brushes.Gray, new Rectangle(100, 410, 620, 20));
e.Graphics.DrawRectangle(Pens.Black, new Rectangle(100, 410, 620, 20));
e.Graphics.DrawString("Car Information", fntBoldString, Brushes.White, 100, 410);
e.Graphics.DrawString("Tag #: ", fntBoldString, Brushes.Black, 100, 450);
e.Graphics.DrawString(txtTagNumber.Text, fntRegularString, Brushes.Black, 260, 450);
e.Graphics.DrawLine(new Pen(Color.Black, 1), 100, 470, 380, 470);
e.Graphics.DrawString("Condition: ", fntBoldString, Brushes.Black, 420, 450);
e.Graphics.DrawString(cbxVehiclesConditions.Text, fntRegularString, Brushes.Black, 530, 450); // ?
e.Graphics.DrawLine(new Pen(Color.Black, 1), 420, 470, 720, 470);
e.Graphics.DrawString("Make: ", fntBoldString, Brushes.Black, 100, 480);
e.Graphics.DrawString(txtMake.Text, fntRegularString, Brushes.Black, 260, 480);
e.Graphics.DrawLine(new Pen(Color.Black, 1), 100, 500, 380, 500);
e.Graphics.DrawString("Model: ", fntBoldString, Brushes.Black, 420, 480);
e.Graphics.DrawString(txtModel.Text, fntRegularString, Brushes.Black, 530, 480);
e.Graphics.DrawLine(new Pen(Color.Black, 1), 420, 500, 720, 500);
e.Graphics.DrawString("Vehicle Condition: ", fntBoldString, Brushes.Black, 100, 510);
e.Graphics.DrawString(cbxVehiclesConditions.Text, fntRegularString, Brushes.Black, 260, 510);
e.Graphics.DrawLine(new Pen(Color.Black, 1), 100, 530, 380, 530);
e.Graphics.DrawString("Tank Level: ", fntBoldString, Brushes.Black, 420, 510);
e.Graphics.DrawString(cbxTanksLevels.Text, fntRegularString, Brushes.Black, 530, 510);
e.Graphics.DrawLine(new Pen(Color.Black, 1), 420, 530, 720, 530);
e.Graphics.DrawString("Mileage Start:", fntBoldString, Brushes.Black, 100, 540);
e.Graphics.DrawString(txtMileageStart.Text, fntRegularString, Brushes.Black, 260, 540);
e.Graphics.DrawLine(new Pen(Color.Black, 1), 100, 560, 380, 560);
e.Graphics.DrawString("Mileage End:", fntBoldString, Brushes.Black, 420, 540);
e.Graphics.DrawString(txtMileageEnd.Text, fntRegularString, Brushes.Black, 530, 540);
e.Graphics.DrawLine(new Pen(Color.Black, 1), 420, 560, 720, 560);
e.Graphics.FillRectangle(Brushes.Gray, new Rectangle(100, 590, 620, 20));
e.Graphics.DrawRectangle(Pens.Black, new Rectangle(100, 590, 620, 20));
e.Graphics.DrawString("Order Timing Information", fntBoldString, Brushes.White, 100, 590);
e.Graphics.DrawString("Start Date:", fntBoldString, Brushes.Black, 100, 620);
e.Graphics.DrawString(dtpRentStartDate.Value.ToString("D"), fntRegularString, Brushes.Black, 260, 620);
e.Graphics.DrawLine(new Pen(Color.Black, 1), 100, 640, 720, 640);
e.Graphics.DrawString("End Date:", fntBoldString, Brushes.Black, 100, 650);
e.Graphics.DrawString(dtpRentEndDate.Value.ToString("D"), fntRegularString, Brushes.Black, 260, 650);
e.Graphics.DrawLine(new Pen(Color.Black, 1), 100, 670, 520, 670);
e.Graphics.DrawString("Total Days:", fntBoldString, Brushes.Black, 550, 650);
e.Graphics.DrawString(txtTotalDays.Text, fntRegularString, Brushes.Black, 640, 650);
e.Graphics.DrawLine(new Pen(Color.Black, 1), 550, 670, 720, 670);
e.Graphics.FillRectangle(Brushes.Gray, new Rectangle(100, 700, 620, 20));
e.Graphics.DrawRectangle(Pens.Black, new Rectangle(100, 700, 620, 20));
e.Graphics.DrawString("Order Evaluation", fntBoldString, Brushes.White, 100, 700);
StringFormat fmtString = new StringFormat();
fmtString.Alignment = StringAlignment.Far;
e.Graphics.DrawString("Rate Applied:", fntBoldString, Brushes.Black, 100, 740);
e.Graphics.DrawString(txtRateApplied.Text, fntRegularString, Brushes.Black, 300, 740, fmtString);
e.Graphics.DrawLine(new Pen(Color.Black, 1), 100, 760, 380, 760);
e.Graphics.DrawString("Tax Rate:", fntBoldString, Brushes.Black, 420, 740);
e.Graphics.DrawString(txtTaxRate.Text, fntRegularString, Brushes.Black, 640, 740, fmtString);
e.Graphics.DrawLine(new Pen(Color.Black, 1), 420, 760, 720, 760);
e.Graphics.DrawString("Sub-Total:", fntBoldString, Brushes.Black, 100, 770);
e.Graphics.DrawString(txtSubTotal.Text, fntRegularString, Brushes.Black, 300, 770, fmtString);
e.Graphics.DrawLine(new Pen(Color.Black, 1), 100, 790, 380, 790);
e.Graphics.DrawString("Tax Amount:", fntBoldString, Brushes.Black, 420, 770);
e.Graphics.DrawString(txtTaxAmount.Text, fntRegularString, Brushes.Black, 640, 770, fmtString);
e.Graphics.DrawLine(new Pen(Color.Black, 1), 420, 790, 720, 790);
e.Graphics.DrawString("Order Total:", fntBoldString, Brushes.Black, 420, 800);
e.Graphics.DrawString(txtOrderTotal.Text, fntRegularString, Brushes.Black, 640, 800, fmtString);
e.Graphics.DrawLine(new Pen(Color.Black, 1), 420, 820, 720, 820);
}
- Return to the Order Processing form and double-click the Print
button
- Implement the event as follows:
private void btnPrint_Click(object sender, EventArgs e)
{
if (dlgPrint.ShowDialog() == DialogResult.OK)
docPrint.Print();
}
- Return to the Order Processing form and double-click the Print
Preview button
- Implement the event as follows:
private void btnPrintPreview_Click(object sender, EventArgs e)
{
dlgPrintPreview.ShowDialog();
}
- To add a new form to the application, in the Solution Explorer,
right-click BethesdaCarRental1 -> Add -> Windows Form...
- Set the Name to RentalOrders and click Add
- Design the form as follows:
|
Control |
(Name) |
Text |
Other Properties |
ListView |
lvwRentalOrders |
|
Anchor: Top, Bottom, Left, Right |
|
(Name) |
Text |
TextAlign |
Width |
colReceiptOrderNumber |
Receipt # |
|
65 |
colProcessedDate |
Date Processed |
Center |
90 |
colEmployee |
Employee |
|
140 |
colCustomer |
Customer |
|
120 |
colVehicle |
Vehicle |
|
140 |
colCarCondition |
Condition |
|
|
colTank |
Tank Level |
|
70 |
colStartingMileage |
Mileage Start |
Right |
75 |
colEndingMileage |
Mileage End |
Right |
75 |
colTotalMileage |
Total |
Right |
45 |
colRentStartingDate |
Start Date |
Center |
|
colRentEndingDate |
End Date |
Center |
|
colDaysTotal |
Total |
Right |
45 |
colDailyRate |
Cost |
Right |
50 |
colDailySubTotal |
Sub-Total |
Right |
|
colTaxPercentage |
Tax Rate |
Right |
|
colTaxPaid |
Tax Amt |
Right |
55 |
colTotalOrder |
Total Order |
Right |
65 |
colStatusOfOrder |
Order Status |
|
150 |
|
Button |
btnNewRentalOrder |
New Rental Order ... |
Anchor: Bottom, Right |
Button |
btnUpdateRentalOrder |
Update Rental Order ... |
Anchor: Bottom, Right |
Button |
btnClose |
Close |
Anchor: Bottom, Right |
|
- Save all
|
|