|
XPath Sample Application: Bethesda Car Rental |
|
|
The XPath language provides flexible techniques to
locate a node within an XML document. The XPath language is standardized by
the W3C organization. The MSXML library and the .NET Framework present
Microsoft implementation of the XPath language.
|
Practical
Learning: Introducing Dictionary Collections
|
|
- Start Microsoft Visual Studio
- Create a new Windows Application named BethesdaCarRental2
- 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:
- 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 |
|
Modifiers: public |
Label |
|
|
First Name: |
|
TextBox |
|
txtFirstName |
|
Modifiers: public |
Label |
|
|
Last Name: |
|
TextBox |
|
txtLastName |
|
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 |
|
- 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 |
Width |
colEmployeeNumber |
Empl # |
45 |
colFirstName |
First Name |
65 |
colLastName |
Last Name |
65 |
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 |
|
|
- Double-click the New Employee button and change the document as
follows:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Xml;
namespace BethesdaCarRental2
{
public partial class Employees : Form
{
public Employees()
{
InitializeComponent();
}
internal void ShowEmployees()
{
}
private void btnNewEmployee_Click(object sender, EventArgs e)
{
XmlDocument xdEmployees = new XmlDocument();
EmployeeEditor editor = new EmployeeEditor();
string strFileName = @"C:\Microsoft Visual C# Application Design\Bethesda Car Rental\Employees.xml";
if (editor.ShowDialog() == DialogResult.OK)
{
if (string.IsNullOrEmpty(editor.txtEmployeeNumber.Text))
{
MessageBox.Show("You must specify the employee number.",
"Bethesda Car Rental",
MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
if (!File.Exists(strFileName))
{
xdEmployees.LoadXml("<?xml version=\"1.0\" encoding=\"utf-8\"?>" +
"<Employees></Employees>");
xdEmployees.Save(strFileName);
}
xdEmployees.Load(strFileName);
// Create an element named Employee
XmlElement elmXML = xdEmployees.CreateElement("Employee");
// Create the XML code of the child element of Employee
elmXML.InnerXml = "<EmployeeNumber>" + editor.txtEmployeeNumber.Text + "</EmployeeNumber>" +
"<FirstName>" + editor.txtFirstName.Text + "</FirstName>" +
"<LastName>" + editor.txtLastName.Text + "</LastName>" +
"<Title>" + editor.txtTitle.Text + "</Title>";
// Append the new element as a child of employees
xdEmployees.DocumentElement.AppendChild(elmXML);
// Save the XML file
xdEmployees.Save(strFileName);
// Since the content of the XML file has just been changed,
// re-display the list of employees
ShowEmployees();
}
}
}
}
- 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 |
|
lblPictureName |
Picture Name |
|
Button |
|
btnSubmit |
Submit |
|
Button |
|
btnClose |
Close |
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 an unoccupied area of the form and change the
document as follows:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Xml;
namespace BethesdaCarRental2
{
public partial class VehicleEditor : Form
{
public VehicleEditor()
{
InitializeComponent();
}
private void VehicleEditor_Load(object sender, EventArgs e)
{
pbxVehicle.Image = Image.FromFile(@"C:\Microsoft Visual C# Application Design\Bethesda Car Rental\Vehicle1.jpg");
lblPictureName.Text = @"C:\Microsoft Visual C# Application Design\Bethesda Car Rental\Vehicle1.jpg";
}
}
}
- Return to the Vehicle Editor form and 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);
}
}
- Return to the Vehicle Editor form and double-click the Submit
button
- Implement the event as follows:
private void btnSubmit_Click(object sender, EventArgs e)
{
XmlDocument xdVehicles = new XmlDocument();
string strFileName = @"C:\Microsoft Visual C# Application Design\Bethesda Car Rental\Vehicles.xml";
if (string.IsNullOrEmpty(txtTagNumber.Text))
{
MessageBox.Show("You must specify the tag number.",
"Bethesda Car Rental",
MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
if (!File.Exists(strFileName))
{
xdVehicles.LoadXml("<?xml version=\"1.0\" encoding=\"utf-8\"?>" +
"<Vehicles></Vehicles>");
xdVehicles.Save(strFileName);
}
xdVehicles.Load(strFileName);
XmlElement elmXML = xdVehicles.CreateElement("Vehicle");
elmXML.InnerXml = "<TagNumber>" + txtTagNumber.Text + "</TagNumber>" +
"<Make>" + txtMake.Text + "</Make>" +
"<Model>" + txtModel.Text + "</Model>" +
"<Doors>" + txtDoors.Text + "</Doors>" +
"<Passengers>" + txtPassengers.Text + "</Passengers>" +
"<Condition>" + cbxConditions.Text + "</Condition>" +
"<Category>" + cbxCategories.Text + "</Category>" +
"<Availability>" + cbxAvailabilities.Text + "</Availability>" +
"<PictureFile>" + lblPictureName.Text + "</PictureFile>";
xdVehicles.DocumentElement.AppendChild(elmXML);
// Save the XML file
xdVehicles.Save(strFileName);
Close();
}
- Return to the Vehicle Editor form and double-click the Close
button
- Implement the event as follows:
private void btnClose_Click(object sender, EventArgs e)
{
Close();
}
- To add a new form, on the main menu, click PROJECT -> Add Windows
Form ...
- Set the Name to Vehicles and click Add
- Set the Size to around 765, 524
- Press Ctrl + V to paste dsVehicles
- From the Containers section of the Toolbox, click Panel and click
the form
- Set its Dock property to Top
- From the Containers section of the Toolbox, click Panel and click
the form
- Set its Dock property to Bottom
- From the Containers section of the Toolbox, click SplitContainer
and click the middle-unoccupied area of the form
- From the Containers section of the Toolbox, click SplitContainer
and click the right panel (Panel2) of the form
- In the Properties window, set the Oriantation to
Horizontal
- Complete the design of the form as follows:
|
Control |
(Name) |
Text |
Other Properties |
Label |
|
|
Bethesda Car Rental - Vehicles Inventory |
ForeColor: Blue |
Label |
|
|
________________ |
Anchor: Left, Right AutoSize: False
BackColor: Maroon BorderStyle: FixedSingle |
TreeView |
|
tvwVehicles |
|
Dock: Fill FullRowSelect: True GridLines:
True View: Details |
ListView |
|
lvwVehicles |
|
Dock: Fill |
|
|
(Name) |
Text |
TextAlign |
Width |
colTagNumber |
Tag # |
|
55 |
colMake |
Make |
|
70 |
colModel |
Model |
|
75 |
colDoors |
Doors |
Right |
40 |
colPassengers |
Passengers |
Right |
68 |
colCondition |
Condition |
|
|
colCategory |
Category |
|
70 |
colAvailability |
Availability |
|
85 |
|
PictureBox |
|
pbxVehicle |
|
Dock: Fill SizeMode: Zoom |
Button |
|
btnNewVehicle |
New Vehicle... |
|
Button |
|
Close |
btnClose |
|
|
- Double-click the New Vehicle button and change the document as
follows:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Xml;
namespace BethesdaCarRental2
{
public partial class Vehicles : Form
{
public Vehicles()
{
InitializeComponent();
}
private void ShowVehicles()
{
}
private void btnNewVehicle_Click(object sender, EventArgs e)
{
VehicleEditor editor = new VehicleEditor();
editor.Text = "Bethesda Car Rental - New Vehicle";
editor.ShowDialog();
ShowVehicles();
}
}
}
- Return to the Vehicles form and click the list view
- On the Properties window, click the Events button and double-click
ItemSelectionChanged
- Implement the event as follows:
private void lvwVehicles_ItemSelectionChanged(object sender, ListViewItemSelectionChangedEventArgs e)
{
string strPictureFile = e.Item.SubItems[8].Text;
if (File.Exists(strPictureFile))
pbxVehicle.Image = Image.FromFile(strPictureFile);
else
pbxVehicle.Image = Image.FromFile(@"C:\Microsoft Visual C# Application Design\Bethesda Car Rental\Vehicle1.jpg");
}
- 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 |
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 |
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 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 rates = new RentalRates();
rates.Show();
}
- Return to the New 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 New 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 New 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();
}
- Return to the New Rental Order form and double-click the Save
Rental Order button
- Implement the event as follows:
private void btnSaveRentalOrder_Click(object sender, EventArgs e)
{
XmlDocument xdRentalOrders = new XmlDocument();
string strFileName = @"C:\Microsoft Visual C# Application Design\Bethesda Car Rental\RentalOrders.xml";
if (string.IsNullOrEmpty( txtReceiptNumber.Text))
{
MessageBox.Show("You must enter a receipt number.",
"Bethesda Car Rental",
MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
if (!File.Exists(strFileName))
{
xdRentalOrders.LoadXml("<?xml version=\"1.0\" encoding=\"utf-8\"?>" +
"<RentalOrders></RentalOrders>");
xdRentalOrders.Save(strFileName);
}
xdRentalOrders.Load(strFileName);
XmlElement xeRentalOrder = xdRentalOrders.CreateElement("RentalOrder");
xeRentalOrder.InnerXml = "<ReceiptNumber>" + txtReceiptNumber.Text + "</ReceiptNumber>" +
"<DateProcessed>" + dtpDateProcessed.Value + "</DateProcessed>" +
"<EmployeeNumber>" + txtEmployeeNumber.Text + "</EmployeeNumber>" +
"<CustomerFirstName>" + txtCustomerFirstName.Text + "</CustomerFirstName>" +
"<CustomerLastName>" + txtCustomerLastName.Text + "</CustomerLastName>" +
"<CustomerAddress>" + txtCustomerAddress.Text + "</CustomerAddress>" +
"<CustomerCity>" + txtCustomerCity.Text + "</CustomerCity>" +
"<CustomerState>" + cbxCustomerStates.Text + "</CustomerState>" +
"<CustomerZIPCode>" + txtCustomerZIPCode.Text + "</CustomerZIPCode>" +
"<VehicleTagNumber>" + txtTagNumber.Text + "</VehicleTagNumber>" +
"<VehicleCondition>" + cbxVehiclesConditions.Text + "</VehicleCondition>" +
"<TankLevel>" + cbxTanksLevels.Text + "</TankLevel>" +
"<MileageStart>" + txtMileageStart.Text + "</MileageStart>" +
"<MileageEnd>" + txtMileageStart.Text + "</MileageEnd>" +
"<MileageTotal>0</MileageTotal>" +
"<RentStartDate>" + dtpRentStartDate.Value + "</RentStartDate>" +
"<RentEndDate>" + dtpRentStartDate.Value + "</RentEndDate>" +
"<TotalDays>1</TotalDays>" +
"<RateApplied>" + txtRateApplied.Text + "</RateApplied>" +
"<SubTotal>0</SubTotal>" +
"<TaxRate>" + txtTaxRate.Text + "</TaxRate>" +
"<TaxAmount>0</TaxAmount>" +
"<OrderTotal>0</OrderTotal>" +
"<OrderStatus>" + cbxOrdersStatus.Text + "</OrderStatus>" +
"<Notes>" + txtNotes.Text + "</Notes>";
xdRentalOrders.DocumentElement.AppendChild(xeRentalOrder);
// Save the XML file
xdRentalOrders.Save(strFileName);
Close();
}
- 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 |
|
btnPrint |
Print... |
|
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 |
|
btnClose |
Close |
|
|
- 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();
// In any case, we will let the clerk specify the actual number of days
}
- Return to the Update Rental Order form and double-click the Rental
Rates button
- Implement its event as follows:
private void btnRentalRates_Click(object sender, EventArgs e)
{
RentalRates rates = new RentalRates();
rates.Show();
}
- Return to the Update Rental Order 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 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 # |
|
|
colProcessedDate |
Date Processed |
Center |
90 |
colEmployee |
Processed By |
|
80 |
colCustomerFirstName |
Customer First Name |
|
110 |
colCustomerLastName |
Last Name |
|
65 |
colCustomerAddress |
Address |
|
160 |
colCustomerCity |
City |
|
70 |
colCustomerState |
State |
|
40 |
colCustomerZIPCode |
ZIP Code |
|
|
colVehicle |
Vehicle |
|
|
colVehicleCondition |
Condition |
|
|
colTank |
Tank Level |
|
70 |
colMileageStart |
Mileage Start |
Right |
75 |
colMileageEnd |
Mileage End |
Right |
75 |
colTotalMileage |
Total Miles |
Right |
65 |
colRentStartDate |
Start Date |
Center |
70 |
colRentEndDate |
End Date |
Center |
70 |
colDaysTotal |
Total Days |
Right |
65 |
colRateApplied |
Rate Applied |
Right |
75 |
colSubTotal |
Sub-Total |
Right |
|
colTaxRate |
Tax Rate |
Right |
|
colTaxAmount |
Tax Amt |
Right |
55 |
colOrderTotal |
Order Total |
Right |
65 |
colOrderStatus |
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 |
|
- In the Solution Explorer, right-click Form1.cs and click Rename
- Type BethesdaCarRental.cs and press Enter twice
- Design the form as follows:
|
Control |
Text |
Name |
Button |
|
btnRentalOrders |
Rental Orders... |
Button |
|
btnVehicles |
Vehicles... |
Button |
|
btnEmployees |
Employees... |
Button |
|
btnClose |
Close |
|
- Double-click an unoccupied area of the form and change the
document as follows:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
namespace BethesdaCarRental2
{
public partial class BethesdaCarRental : Form
{
public BethesdaCarRental()
{
InitializeComponent();
}
private void BethesdaCarRental_Load(object sender, EventArgs e)
{
// If the directory and the sub-directory don't exist, create them
Directory.CreateDirectory(@"C:\Microsoft Visual C# Application Design\Bethesda Car Rental");
}
}
}
- Double-click the Rental Orders button and implement its event as
follows:
private void btnRentalOrders_Click(object sender, EventArgs e)
{
RentalOrders ros = new RentalOrders();
ros.Show();
}
- Return to the Bethesda Car Rental form and double-click the
Vehicles button
- Implement the event as follows:
private void btnVehicles_Click(object sender, EventArgs e)
{
Vehicles cars = new Vehicles();
cars.Show();
}
- Return to the Bethesda Car Rental form and double-click the
Employees button
- Implement the event as follows:
private void btnEmployees_Click(object sender, EventArgs e)
{
Employees staff = new Employees();
staff.Show();
}
- Return to the Bethesda Car Rental form and double-click the Close
button
- Implement the event as follows:
private void btnClose_Click(object sender, EventArgs e)
{
Close();
}
- Save all
|
|