Home

XPath Sample Application: Bethesda Car Rental

     

Introduction

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 LearningPractical Learning: Introducing Dictionary Collections

  1. Start Microsoft Visual Studio
  2. Create a new Windows Application named BethesdaCarRental2
  3. To add a new form to the project, in the Solution Explorer, right-click BethesdaCarRental1 -> Add -> Windows Form...
  4. Set the Name to RentalRates and press Enter
  5. 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  
  6. 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
  7. Complete the design of the form as follows:
     
    Rental Rates
  8. To add another form to the application, in the Solution Explorer, right- click BethesdaCarRental1 -> Add -> Windows Form...
  9. Set the Name to EmployeeEditor and click Add
  10. Design the form as follows: 
     
    Bethesda Car Rental - Employee Editor
     
    Control (Name) Text Properties
    Label Label   &Employee #:  
    TextBox Text Box txtEmployeeNumber   Modifiers: public
    Label Label   First Name:  
    TextBox Text Box txtFirstName   Modifiers: public
    Label Label   Last Name:  
    TextBox Text Box txtLastName   Modifiers: public
    Label Label   Title:  
    TextBox Text Box txtTitle   Modifiers: public
    Button Button btnOK OK DialogResult: OK
    Button Button btnCancel Cancel DialogResult: Cancel
    Form     AcceptButton: btnOK
    CancelButton: btnCancel
    FormBorderStyle: FixedDialog
    MaximizeBox: False
    MinimizeBox: False
    ShowInTaskbar: False
  11. To add a new form to the application, in the Solution Explorer, right-click BethesdaCarRental1 -> Add -> Windows Form...
  12. Set the Name to Employees and click Add
  13. From the Toolbox, add a ListView to the form
  14. 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
  15. Design the form as follows: 
     
    Bethesda Car Rental - Employees
     
    Control (Name) Text Other Properties
    ListView List View lvwEmployees   Anchor: Top, Bottom, Left, Right
    FullRowSelect: True
    GridLines: True
    View: Details
    Button Button btnNewEmployee New &Employee...  
    Button Button btnClose &Close  
  16. 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();
                }
            }
        }
    }
    
  17. To add a new form to the application, in the Solution Explorer, right-click BethesdaCarRental1 -> Add -> Windows Forms
  18. Set the Name to VehicleEditor and click Add
  19. Design the form as follows: 
     
    Bethesda Car Rental - New Vehicle
    Control (Name) Text Other Properties
    Label Label   Tag Number:  
    TextBox Text Box txtTagNumber    
    Label Label   Make:  
    TextBox Text Box txtMake    
    Label Label   Model:  
    TextBox Text Box txtModel    
    Label Label   Doors  
    TextBox Text Box txtDoors    
    Label Label   Passengers:  
    TextBox Text Box txtPassengers    
    Label Label   Condition:  
    ComboBox ComboBox cbxCondition   Items:
    Good
    Other
    Excellent
    Driveable
    Needs Repair
    Label Label   Category:  
    ComboBox ComboBox cbxCategories   Items:
    SUV
    Truck
    Full Size
    Mini Van
    Compact
    Standard
    Economy
    Passenger Van
    Label Label   Availability  
    ComboBox ComboBox cbxAvailabilities   Items:
    Rented
    Available
    Being Serviced
    PictureBox Picture Box pbxVehicle   SizeMode: Zoom
    Button Button btnSelectPicture &Select Vehicle Picture...  
    Label Label lblPictureName Picture Name  
    Button Button btnSubmit Submit  
    Button Button btnClose Close DialogResult: Cancel
    OpenFileDialog 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
  20. 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";
            }
        }
    }
  21. 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);
        }
    }
  22. Return to the Vehicle Editor form and double-click the Submit button
  23. 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();
    }
  24. Return to the Vehicle Editor form and double-click the Close button
  25. Implement the event as follows:
    private void btnClose_Click(object sender, EventArgs e)
    {
        Close();
    }
  26. To add a new form, on the main menu, click PROJECT -> Add Windows Form ...
  27. Set the Name to Vehicles and click Add
  28. Set the Size to around 765, 524
  29. Press Ctrl + V to paste dsVehicles
  30. From the Containers section of the Toolbox, click Panel and click the form
  31. Set its Dock property to Top
  32. From the Containers section of the Toolbox, click Panel and click the form
  33. Set its Dock property to Bottom
     
    Bethesda Car Rental: Vehicles Inventory
  34. From the Containers section of the Toolbox, click SplitContainer and click the middle-unoccupied area of the form
     
    Bethesda Car Rental: Vehicles Inventory
  35. From the Containers section of the Toolbox, click SplitContainer and click the right panel (Panel2) of the form
  36. In the Properties window, set the Oriantation to Horizontal
     
    Bethesda Car Rental: Vehicles Inventory
  37. Complete the design of the form as follows:
     
    Bethesda Car Rental: Vehicles Inventory
    Control (Name) Text Other Properties
    Label Label   Bethesda Car Rental - Vehicles Inventory ForeColor: Blue
    Label Label   ________________ Anchor: Left, Right
    AutoSize: False
    BackColor: Maroon
    BorderStyle: FixedSingle
    TreeView Tree View tvwVehicles   Dock: Fill
    FullRowSelect: True
    GridLines: True
    View: Details
    ListView List View 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 Picture Box pbxVehicle   Dock: Fill
    SizeMode: Zoom
    Button Button btnNewVehicle New Vehicle...  
    Button Button Close btnClose  
  38. 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();
            }
        }
    }
  39. Return to the Vehicles form and click the list view
  40. On the Properties window, click the Events button and double-click ItemSelectionChanged
  41. 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");
    }
  42. To add a new form to the project, in the Solution Explorer, right-click BethesdaCarRenat1 -> Add -> Windows Form...
  43. Set the Name to NewRentalOrder and press Enter
  44. From the Printing section of the Toolbox, click PrintDocument and click the form
  45. In the Properties window, set its (Name) to docPrint and press Enter
  46. From the Printing section of the Toolbox, click PrintDialog and click the form
  47. In the Properties window, change its Name to dlgPrint
  48. Still in the Properties windows, set its Document property to docPrint
  49. From the Printing section of the Toolbox, click PrintPreviewDialog and click the form
  50. In the Properties window, change its (Name) to dlgPrintPreview
  51. Still in the Properties windows, set its Document property to docPrint
  52. 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:
     
    Bethesda Car Rental - New Rental Order

    Control (Name) Text Other Properties
    Label Label   Processed By: AutoSize: False
    BackColor: Gray
    BorderStyle: FixedSingle
    ForeColor: White
    TextAlign: MiddleLeft
    Label Label   Order Timing AutoSize: False
    BackColor: Gray
    BorderStyle: FixedSingle
    ForeColor: White
    TextAlign: MiddleLeft
    Label Label   Employee #:  
    TextBox Text Box txtEmployeeNumber    
    TextBox Text Box txtEmployeeName    
    Label Label   Date Processed:  
    TextBox Text Box dtpDateProcessed    
    Label Label   Processed For AutoSize: False
    BackColor: Gray
    BorderStyle: FixedSingle
    ForeColor: White
    TextAlign: MiddleLeft
    Label Label   Rent Start Date:  
    DateTimePicker Date Time Picker dtpRentStartDate    
    Label Label   First Name:  
    TextBox Text Box txtCustomerFirstName    
    Label Label   Last Name:  
    TextBox Text Box txtCustomerLastName    
    Label Label   Rent End Date:  
    DateTimePicker Date Time Picker dtpRentEndDate    
    Label Label   Address:  
    TextBox Text Box txtCustomerAddress    
    Label Label   Total Days:  
    TextBox Text Box txtTotalDays 1 TextAlign: Right
    Label Label   City:  
    TextBox Text Box txtCustomerCity    
    Label Label   State:  
    Label Label Order Evaluation   AutoSize: False
    BackColor: Gray
    BorderStyle: FixedSingle
    ForeColor: White
    TextAlign: MiddleLeft
    ComboBox 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 Label   ZIP/Postal Code:  
    TextBox Text Box txtCustomerZIPCode    
    Label Label   Rate Applied:  
    TextBox Text Box txtRateApplied 0.00 TextAlign: Right
    Button Button btnRentalRates Rental Rates  
    Label Label Vehicle Selected   AutoSize: False
    BackColor: Gray
    BorderStyle: FixedSingle
    ForeColor: White
    TextAlign: MiddleLeft
    Label Label   Sub-Total:  
    TextBox Text Box txtSubTotal 0.00 TextAlign: Right
    Label Label   Tag Number:  
    TextBox Text Box txtTagNumber    
    Label Label   Condition:  
    ComboBox ComboBox cbxVehicleConditions   Sorted: True
    Items:
    Bad
    Good
    Other
    Excellent
    Driveable
    Needs Repair
    Label Label   Tax Rate:  
    TextBox Text Box txtTaxRate 7.75 TextAlign: Right
    Label Label   %  
    Label Label   Make:  
    TextBox Text Box txtMake    
    Label Label   Model:  
    TextBox Text Box txtModel    
    Label Label   Tax Amount:  
    TextBox Text Box txtTaxAmount 0.00 TextAlign: Right
    Button Button Print... btnPrint  
    Label Label   Mileage Start:  
    TextBox Text Box txtMileageStart   TextAlign: Right
    Label Label   Tank Level:  
    ComboBox ComboBox cbxTanksLevels   Empty
    1/4 Empty
    Half Tank
    3/4 Full
    Full
    Label Label   Order Total:  
    TextBox Text Box txtOrderTotal 0.00 TextAlign: Right
    Button   btnPrintPreview Print Preview...  
    Label Label   Mileage End:  
    TextBox Text Box txtMileageEnd   TextAlign: Right
    Label Label   Mileage Total:  
    TextBox Text Box txtMileageTotal   TextAlign: Right
    Label Label Order Status    
    ComboBox ComboBox   cbxOrderStatus Items:
    Order Reserved
    Vehicle With Customer
    Rental Order Completed
    Label Label   Notes:  
    TextBox Text Box txtNotes   Multiline: True
    ScrollBars: Vertical
    Label Label Receipt #:    
    TextBox Text Box   txtReceiptNumber  
    Button Button btnOpen Open  
    Button Button btnUpdateRentalOrder Update Rental Order  
    Button Button Close btnClose  
  53. On the New Rental Order form, double-click the Rent Start Date date time picker control
  54. Implement the event as follows:
    private void dtpRentStartDate_ValueChanged(object sender, EventArgs e)
    {
        dtpRentEndDate.Value = dtpRentStartDate.Value;
    }
  55. Return to the New Rental Order form and double-click the Rental Rates button
  56. Implement its event as follows:
    private void btnRentalRates_Click(object sender, EventArgs e)
    {
        RentalRates rates = new RentalRates();
        rates.Show();
    }
  57. Return to the New Rental Order form and, under the form, double-click docPrint
  58. 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);
    }
  59. Return to the New Rental Order form and double-click the Print button
  60. Implement the event as follows:
    private void btnPrint_Click(object sender, EventArgs e)
    {
        if (dlgPrint.ShowDialog() == DialogResult.OK)
            docPrint.Print();
    }
  61. Return to the New Rental Order form and double-click the Print Preview button
  62. Implement the event as follows:
    private void btnPrintPreview_Click(object sender, EventArgs e)
    {
        dlgPrintPreview.ShowDialog();
    }
  63. Return to the New Rental Order form and double-click the Save Rental Order button
  64. 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();
    }
  65. To add a new form to the project, in the Solution Explorer, right-click BethesdaCarRenat1 -> Add -> Windows Form...
  66. Set the Name to UpdateRentalOrder and press Enter
  67. From the Printing section of the Toolbox, click PrintDocument and click the form
  68. In the Properties window, set its (Name) to docPrint and press Enter
  69. From the Printing section of the Toolbox, click PrintDialog and click the form
  70. In the Properties window, change its Name to dlgPrint
  71. Still in the Properties windows, set its Document property to docPrint
  72. From the Printing section of the Toolbox, click PrintPreviewDialog and click the form
  73. In the Properties window, change its (Name) to dlgPrintPreview
  74. Still in the Properties windows, set its Document property to docPrint
  75. Design the form as follows:
     
    Bethesda Car Rental - Rental Orders

    Control (Name) Text Other Properties
    Label Label   Processed By: AutoSize: False
    BackColor: Gray
    BorderStyle: FixedSingle
    ForeColor: White
    TextAlign: MiddleLeft
    Label Label   Order Timing AutoSize: False
    BackColor: Gray
    BorderStyle: FixedSingle
    ForeColor: White
    TextAlign: MiddleLeft
    Label Label   Employee #:  
    TextBox Text Box txtEmployeeNumber    
    TextBox Text Box txtEmployeeName    
    Label Label   Date Processed:  
    TextBox Text Box dtpDateProcessed    
    Label Label   Processed For AutoSize: False
    BackColor: Gray
    BorderStyle: FixedSingle
    ForeColor: White
    TextAlign: MiddleLeft
    Label Label   Rent Start Date:  
    DateTimePicker Date Time Picker dtpRentStartDate    
    Label Label   First Name:  
    TextBox Text Box txtCustomerFirstName    
    Label Label   Last Name:  
    TextBox Text Box txtCustomerLastName    
    Label Label   Rent End Date:  
    DateTimePicker Date Time Picker dtpRentEndDate    
    Label Label   Address:  
    TextBox Text Box txtCustomerAddress    
    Label Label   Total Days:  
    TextBox Text Box txtTotalDays 1 TextAlign: Right
    Label Label   City:  
    TextBox Text Box txtCustomerCity    
    Label Label   State:  
    Label Label Order Evaluation   AutoSize: False
    BackColor: Gray
    BorderStyle: FixedSingle
    ForeColor: White
    TextAlign: MiddleLeft
    ComboBox 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 Label   ZIP/Postal Code:  
    TextBox Text Box txtCustomerZIPCode    
    Label Label   Rate Applied:  
    TextBox Text Box txtRateApplied 0.00 TextAlign: Right
    Button Button btnRentalRates Rental Rates  
    Label Label Vehicle Selected   AutoSize: False
    BackColor: Gray
    BorderStyle: FixedSingle
    ForeColor: White
    TextAlign: MiddleLeft
    Label Label   Sub-Total:  
    TextBox Text Box txtSubTotal 0.00 TextAlign: Right
    Button Button btnCalculate Calculate  
    Label Label   Tag Number:  
    TextBox Text Box txtTagNumber    
    Label Label   Condition:  
    ComboBox ComboBox cbxVehicleConditions   Sorted: True
    Items:
    Bad
    Good
    Other
    Excellent
    Driveable
    Needs Repair
    Label Label   Tax Rate:  
    TextBox Text Box txtTaxRate 7.75 TextAlign: Right
    Label Label   %  
    Label Label   Make:  
    TextBox Text Box txtMake    
    Label Label   Model:  
    TextBox Text Box txtModel    
    Label Label   Tax Amount:  
    TextBox Text Box txtTaxAmount 0.00 TextAlign: Right
    Button Button btnPrint Print...  
    Label Label   Mileage Start:  
    TextBox Text Box txtMileageStart   TextAlign: Right
    Label Label   Tank Level:  
    ComboBox ComboBox cbxTanksLevels   Empty
    1/4 Empty
    Half Tank
    3/4 Full
    Full
    Label Label   Order Total:  
    TextBox Text Box txtOrderTotal 0.00 TextAlign: Right
    Button   btnPrintPreview Print Preview...  
    Label Label   Mileage End:  
    TextBox Text Box txtMileageEnd   TextAlign: Right
    Label Label   Mileage Total:  
    TextBox Text Box txtMileageTotal   TextAlign: Right
    Label Label   Order Status  
    ComboBox ComboBox   cbxOrderStatus Items:
    Order Reserved
    Vehicle With Customer
    Rental Order Completed
    Label Label   Notes:  
    TextBox Text Box txtNotes   Multiline: True
    ScrollBars: Vertical
    Label Label   Receipt #:  
    TextBox Text Box txtReceiptNumber    
    Button Button btnOpen Open  
    Button Button btnUpdateRentalOrder Update Rental Order  
    Button Button btnClose Close  
  76. On the Update Rental Order form, click the Mileage End text box
  77. On the Properties window, click the Events button and double-click Leave
  78. 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();
    }
  79. Return to the Update Rental Order form and double-click the Rent Start Date date time picker control
  80. Implement the event as follows:
    private void dtpRentStartDate_ValueChanged(object sender, EventArgs e)
    {
        dtpRentEndDate.Value = dtpRentStartDate.Value;
    }
  81. Return to the Update Rental Order form and double-click the Rent End Date control
  82. 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
    }
  83. Return to the Update Rental Order form and double-click the Rental Rates button
  84. Implement its event as follows:
    private void btnRentalRates_Click(object sender, EventArgs e)
    {
        RentalRates rates = new RentalRates();
        rates.Show();
    }
  85. Return to the Update Rental Order form and double-click the Calculate button
  86. 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");
    }
  87. Return to the Update Rental Order form and, under the form, double-click docPrint
  88. 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);
    }
  89. Return to the Update Rental Order form and double-click the Print button
  90. Implement the event as follows:
    private void btnPrint_Click(object sender, EventArgs e)
    {
        if (dlgPrint.ShowDialog() == DialogResult.OK)
            docPrint.Print();
    }
  91. Return to the Update Rental Order form and double-click the Print Preview button
  92. Implement the event as follows:
    private void btnPrintPreview_Click(object sender, EventArgs e)
    {
        dlgPrintPreview.ShowDialog();
    }
  93. To add a new form to the application, in the Solution Explorer, right-click BethesdaCarRental1 -> Add -> Windows Form...
  94. Set the Name to RentalOrders and click Add
  95. Design the form as follows:
     

    Bethesda Car Rental: Rental Orders

    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
  96. In the Solution Explorer, right-click Form1.cs and click Rename
  97. Type BethesdaCarRental.cs and press Enter twice
  98. Design the form as follows:
     
    Bethesda Car Rental
    Control Text Name
    Button Button btnRentalOrders Rental Orders...
    Button Button btnVehicles Vehicles...
    Button Button btnEmployees Employees...
    Button Button btnClose Close
  99. 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");
            }
        }
    }
  100. 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();
    }
  101. Return to the Bethesda Car Rental form and double-click the Vehicles button
  102. Implement the event as follows:
    private void btnVehicles_Click(object sender, EventArgs e)
    {
        Vehicles cars = new Vehicles();
        cars.Show();
    }
  103. Return to the Bethesda Car Rental form and double-click the Employees button
  104. Implement the event as follows:
    private void btnEmployees_Click(object sender, EventArgs e)
    {
        Employees staff = new Employees();
        staff.Show();
    }
  105. Return to the Bethesda Car Rental form and double-click the Close button
  106. Implement the event as follows:
    private void btnClose_Click(object sender, EventArgs e)
    {
        Close();
    }
  107. Save all
 
 
 

XPath in .NET

As mentioned earlier, Microsoft supports XPath in the MSXML library and in the .NET Framework. For our application, we will use XPath as it is implemented in the .NET Framework. As you may know already, the .NET Framework provides various classes to support XML. These are the XmlDocument class(which gives access to the whole XML document), the XmlElement class (which represents an element), the XmlNode class (which represents a node), and the XmlNodeList class (which represents a collection of elements), among many other classes. These classes are defined in the  System.Xml namespace. The .NET Framework supports XPath through the System.Xml.XPath namespace.

To provide the ability to use XPath, the XmlNode class is equipped with the overloaded SelectNodes() method. One of the versions takes an XPath expression as a string. If the XmlNode.SelectNodes() method succeeds, it produces an XmlNodeList collection.

Locating the Root of An XML Document

To get to the root of an XML document, pass / as the argument to XmlElement.SelectNodes(string xpath) method as /. An alternative to pass /* or the name of the root preceded by /.

Locating the Child Nodes of the Root

To locate the direct child nodes of the root, pass the argument as /RootName/ChildOfRootName.

Practical LearningPractical Learning: Accessing the Child Nodes of an Element

  1. Display the Employees form and double-click an unoccupied area of its body
  2. Change the document as follows:
    internal void ShowEmployees()
    {
        XmlDocument xdEmployees = new XmlDocument();
        string strFileName = @"C:\Microsoft Visual C# Application Design\Bethesda Car Rental\Employees.xml";
    
        if (File.Exists(strFileName))
        {
            lvwEmployees.Items.Clear();
    
            xdEmployees.Load(strFileName);
            XmlNodeList xnlEmployeesNumbers = xdEmployees.DocumentElement.SelectNodes("/Employees/Employee/EmployeeNumber");
    
            foreach (XmlNode xnEmployee in xnlEmployeesNumbers)
            {
                ListViewItem lviEmployee = new ListViewItem(xnEmployee.InnerText); // Employee Number
    
                lviEmployee.SubItems.Add(xnEmployee.NextSibling.InnerText); // First Name
                lviEmployee.SubItems.Add(xnEmployee.NextSibling.NextSibling.InnerText); // Last Name
                lviEmployee.SubItems.Add(xnEmployee.NextSibling.NextSibling.NextSibling.InnerText); // Title
    
                lvwEmployees.Items.Add(lviEmployee);
            }
        }
    }
    
    private void Employees_Load(object sender, EventArgs e)
    {
        ShowEmployees();
    }
  3. Return to the Employees form and double-click the Close button
  4. Implement the event as follows:
    private void btnClose_Click(object sender, EventArgs e)
    {
        Close();
    }

Locating the Grand-Children of a Node

To access the grandchildren of a node, separate its name and that of the grand-child name with /*/. If you have many elements that share the same name in your XML document, pass their name preceded by //. You can also precede // with a period.

Practical LearningPractical Learning: Accessing Specific Nodes

  1. Display the Vehicles form and click its title bar to select the form itself (or, in the top combo box of the Properties window, select Vehicles System.Windows.Forms.Form)
  2. On the Properties window, click the Events button and double-click Load
  3. Change the document as follows:
    private void ShowVehicles()
    {
        XmlDocument xdVehicles = new XmlDocument();
        string strFileName = @"C:\Microsoft Visual C# Application Design\Bethesda Car Rental\Vehicles.xml";
    
        if (File.Exists(strFileName))
        {
            tvwVehicles.Nodes.Clear();
            lvwVehicles.Items.Clear();
    
            xdVehicles.Load(strFileName);
            XmlNodeList xnlVehicles = xdVehicles.DocumentElement.SelectNodes("//TagNumber");
            XmlNodeList xnlCategories = xdVehicles.DocumentElement.SelectNodes("//Category");
            XmlNodeList xnlAvailabilities = xdVehicles.DocumentElement.SelectNodes("//Availability");
    
            List lstCategories = new List();
            List lstAvailabilities = new List();
    
            TreeNode nodBCR = tvwVehicles.Nodes.Add("Bethesda Car Rental");
            TreeNode nodCategories = nodBCR.Nodes.Add("Categories");
            TreeNode nodAvailabilities = nodBCR.Nodes.Add("Availabilities");
    
            foreach (XmlNode xnCategory in xnlCategories)
            {
                if (!(lstCategories.Contains(xnCategory.InnerText)))
                    lstCategories.Add(xnCategory.InnerText);
            }
            foreach (XmlNode xnAvailability in xnlAvailabilities)
            {
                if (!(lstAvailabilities.Contains(xnAvailability.InnerText)))
                    lstAvailabilities.Add(xnAvailability.InnerText);
            }
    
            foreach (string strCategory in lstCategories)
                nodCategories.Nodes.Add(strCategory);
            foreach (string strAvailability in lstAvailabilities)
                nodAvailabilities.Nodes.Add(strAvailability);
    
            foreach (XmlNode xnVehicle in xnlVehicles)
            {
                ListViewItem lviVehicle = new ListViewItem(xnVehicle.InnerText); // Tag Number
    
                lviVehicle.SubItems.Add(xnVehicle.NextSibling.InnerText); // Make
                lviVehicle.SubItems.Add(xnVehicle.NextSibling.NextSibling.InnerText); // Model
                lviVehicle.SubItems.Add(xnVehicle.NextSibling.NextSibling.NextSibling.InnerText); // Doors
                lviVehicle.SubItems.Add(xnVehicle.NextSibling.NextSibling.NextSibling.NextSibling.InnerText); // Passengers
                lviVehicle.SubItems.Add(xnVehicle.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.InnerText); // Condition
                lviVehicle.SubItems.Add(xnVehicle.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.InnerText); // Category
                lviVehicle.SubItems.Add(xnVehicle.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.InnerText); // Availability
                lviVehicle.SubItems.Add(xnVehicle.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.InnerText); // Picture File
    
                lvwVehicles.Items.Add(lviVehicle);
            }
        }
    
        pbxVehicle.Image = Image.FromFile(@"C:\Microsoft Visual C# Application Design\Bethesda Car Rental\Vehicle1.jpg");
    }
    
    private void Vehicles_Load(object sender, EventArgs e)
    {
        ShowVehicles();
    }
  4. Return to the Vehicles form and double-click the Close button
  5. Implement the event as follows:
    private void btnClose_Click(object sender, EventArgs e)
    {
        Close();
    }

XPath and Arrays

The results of an XPath expression are stored in a collection treated as an array. The positions start at 1. The second is at index 2, until the end. To access an individual result, use the square brackets as done in C-based languages.

 To get only the nodes that have a specific section, pass the name of that section to the square brackets of the parent element.

Practical LearningPractical Learning: Accessing a Node by Value

  1. Display the New Rental Order form and click the Employee # text box
  2. In the Events section of the Properties, double-click Leave and implement the event as follows:
    private void txtEmployeeNumber_Leave(object sender, EventArgs e)
    {
        XmlDocument xdEmployees = new XmlDocument();
        string strFileName = @"C:\Microsoft Visual C# Application Design\Bethesda Car Rental\Employees.xml";
    
        if (File.Exists(strFileName))
        {
            xdEmployees.Load(strFileName);
            XmlNodeList xnlEmployees = xdEmployees.DocumentElement.SelectNodes("/Employees/Employee/EmployeeNumber[.='" + txtEmployeeNumber.Text + "']");
    
            foreach (XmlNode xnEmployee in xnlEmployees)
            {
                txtEmployeeName.Text = xnEmployee.NextSibling.InnerText + " " + xnEmployee.NextSibling.NextSibling.InnerText;
            }
        }
    }
  3. Return to the New Rental Order form and click the Tag Number text box
  4. In the Events section of the Properties, double-click Leave and implement the event as follows:
    private void txtTagNumber_Leave(object sender, EventArgs e)
    {
        XmlDocument xdVehicles = new XmlDocument();
        string strFileName = @"C:\Microsoft Visual C# Application Design\Bethesda Car Rental\Vehicles.xml";
    
        if (File.Exists(strFileName))
        {
            xdVehicles.Load(strFileName);
            XmlNodeList xnlVehicles = xdVehicles.DocumentElement.SelectNodes("/Vehicles/Vehicle/TagNumber[ .= '" + txtTagNumber.Text + "']");
    
            foreach (XmlNode xnVehicle in xnlVehicles)
            {
                txtMake.Text = xnVehicle.NextSibling.InnerText;
                txtModel.Text = xnVehicle.NextSibling.NextSibling.InnerText;
                cbxVehiclesConditions.Text = xnVehicle.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.InnerText;
            }
        }
    }
  5. Display the Update Rental Order form and click the Employee # text box
  6. In the Events section of the Properties, double-click Leave and implement the event as follows:
    private void txtEmployeeNumber_Leave(object sender, EventArgs e)
    {
        XmlDocument xdEmployees = new XmlDocument();
        string strFileName = @"C:\Microsoft Visual C# Application Design\Bethesda Car Rental\Employees.xml";
    
        if (File.Exists(strFileName))
        {
            xdEmployees.Load(strFileName);
            XmlNodeList xnlEmployees = xdEmployees.DocumentElement.SelectNodes("/Employees/Employee/EmployeeNumber[.='" + txtEmployeeNumber.Text + "']");
    
            foreach (XmlNode xnEmployee in xnlEmployees)
            {
                txtEmployeeName.Text = xnEmployee.NextSibling.InnerText + " " + xnEmployee.NextSibling.NextSibling.InnerText;
            }
        }
    }
  7. Return to the Update Rental Order form and click the Tag Number text box
  8. In the Events section of the Properties, double-click Leave and implement the event as follows:
    private void txtTagNumber_Leave(object sender, EventArgs e)
    {
        XmlDocument xdVehicles = new XmlDocument();
        string strFileName = @"C:\Microsoft Visual C# Application Design\Bethesda Car Rental\Vehicles.xml";
    
        if (File.Exists(strFileName))
        {
            xdVehicles.Load(strFileName);
            XmlNodeList xnlVehicles = xdVehicles.DocumentElement.SelectNodes("/Vehicles/Vehicle/TagNumber[ .= '" + txtTagNumber.Text + "']");
    
            foreach (XmlNode xnVehicle in xnlVehicles)
            {
                txtMake.Text = xnVehicle.NextSibling.InnerText;
                txtModel.Text = xnVehicle.NextSibling.NextSibling.InnerText;
                cbxVehiclesConditions.Text = xnVehicle.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.InnerText;
            }
        }
    }

XPath Functions

The XPath language provides the position() function. To use it, type it in the square brackets of the node and assign the desired position to it.

To access the last child node of a node, call the last() function.

Practical LearningPractical Learning: Accessing the Last Child Node of a Node

  1. Display the New Rental Order form and double-click an unoccupied area of its body
  2. Change the document as follows:
    private void InitializeNewRentalOrder()
    {
        int iReceiptNumber = 100000;
        XmlDocument xdRentalOrders = new XmlDocument();
        List lstReceiptNumbers = new List();
        string strFileName = @"C:\Microsoft Visual C# Application Design\Bethesda Car Rental\RentalOrders.xml";
    
        if (File.Exists(strFileName))
        {
            xdRentalOrders.Load(strFileName);
            // Get the receipt number of the last rental order
            XmlNodeList xnlRentalOrders = xdRentalOrders.DocumentElement.SelectNodes("/RentalOrders/RentalOrder[last()]/ReceiptNumber");
    
            foreach (XmlNode xnRentalOrder in xnlRentalOrders)
            {
                iReceiptNumber = int.Parse(xnRentalOrder.InnerText);
            }
    
            txtReceiptNumber.Text = (iReceiptNumber + 1).ToString();
        }
    }
    
    private void NewRentalOrder_Load(object sender, EventArgs e)
    {
        InitializeNewRentalOrder();
    }
  3. Return to the New Rental Order form and double-click the Close button
  4. Implement the event as follows:
    private void btnClose_Click(object sender, EventArgs e)
    {
        Close();
    }

Boolean Node Searching

To visit two nodes, add a first combination that includes one of the names of child nodes. Include a second pair of square brackets with the other name. Here is an example:

XmlNodeList xnlVideos = xeVideo.SelectNodes("/videos/video[format][categories]");

An alternative is to write the names of two child nodes separated by the and operator. Here is an example:

XmlNodeList xnlVideos = xeVideo.SelectNodes("//videos/video[format and categories]");

To produce the parent nodes that include one or the other child node, use the or operator. Here is an example:

XmlNodeList xnlVideos = xeVideo.SelectNodes("/videos/video[cast-members or categories]");

To exclude a node or value from a result, use the not function. To use it, pass the name of the node to it. Here is an example:

XmlNodeList xnlVideos = xeVideo.SelectNodes("/videos/video[not(cast-members)]");

Sets Combination

To combine two results into one, use the | operator. Here is an example:

XmlNodeList xnlVideos = xeVideo.SelectNodes("//cast-members[actor='Danny DeVito'] | //cast-members[actor='Eddie Murphy']");

Boolean Operations

The XPath language supports various Boolean operators such as =, < (or &lt;), <= (or &lt=), > (or &gt;), >= )or &gt;=), and !=. These operators can be used on node names and constant values, or among nodes names.

XPath Axes

An XPath axis is a technique to locate a node or a collection of nodes based on a path. This is done using some keywords. The keyword  is followed by ::.

The child keyword is used to locate a child node.

Practical LearningPractical Learning: Accessing a Child Node

  1. Display the Rental Orders form and double-click an unoccupied area of its body
  2. Change the document as follows:
    private void ShowRentalOrders()
    {
        XmlDocument xdEmployees = new XmlDocument();
        XmlDocument xdRentalOrders = new XmlDocument();
        string strRentalOrdersFile = @"C:\Microsoft Visual C# Application Design\Bethesda Car Rental\RentalOrders.xml";
    
        if (File.Exists(strRentalOrdersFile))
        {
            xdRentalOrders.Load(strRentalOrdersFile);
            // The "child" keyword is optional (you can omit it
            XmlNodeList xnlRentalOrders = xdRentalOrders.DocumentElement.SelectNodes("//child::ReceiptNumber");
    
            lvwRentalOrders.Items.Clear();
    
            foreach (XmlNode xnRentalOrder in xnlRentalOrders)
            {
                ListViewItem lviRentalOrder = new ListViewItem(xnRentalOrder.InnerText); // Receipt #
    
                lviRentalOrder.SubItems.Add(xnRentalOrder.NextSibling.InnerText); // Date Processed
                lviRentalOrder.SubItems.Add(xnRentalOrder.NextSibling.NextSibling.InnerText); // Employee Number
                lviRentalOrder.SubItems.Add(xnRentalOrder.NextSibling.NextSibling.NextSibling.InnerText); // Custimer First Name
                lviRentalOrder.SubItems.Add(xnRentalOrder.NextSibling.NextSibling.NextSibling.NextSibling.InnerText); // Customer Last Name
                lviRentalOrder.SubItems.Add(xnRentalOrder.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.InnerText); // Customer Address
                lviRentalOrder.SubItems.Add(xnRentalOrder.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.InnerText); // Customer City
                lviRentalOrder.SubItems.Add(xnRentalOrder.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.InnerText); // Cusomer State
                lviRentalOrder.SubItems.Add(xnRentalOrder.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.InnerText); // Customer ZIP Code
                lviRentalOrder.SubItems.Add(xnRentalOrder.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.InnerText); // Vehicle Tag Number
                lviRentalOrder.SubItems.Add(xnRentalOrder.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.InnerText); // Vehicle Condition
                lviRentalOrder.SubItems.Add(xnRentalOrder.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.InnerText); // Tank Level
                lviRentalOrder.SubItems.Add(xnRentalOrder.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.InnerText); // Mileage Start
                lviRentalOrder.SubItems.Add(xnRentalOrder.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.InnerText); // Mileage End
                lviRentalOrder.SubItems.Add(xnRentalOrder.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.InnerText); // Mileage Total
                lviRentalOrder.SubItems.Add(xnRentalOrder.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.InnerText); // Start Date
                lviRentalOrder.SubItems.Add(xnRentalOrder.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.InnerText); // End Date
                lviRentalOrder.SubItems.Add(xnRentalOrder.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.InnerText); // Total Days
                lviRentalOrder.SubItems.Add(xnRentalOrder.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.InnerText); // Rate Applied
                lviRentalOrder.SubItems.Add(xnRentalOrder.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.InnerText); // Sub-Total
                lviRentalOrder.SubItems.Add(xnRentalOrder.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.InnerText); // Tax Rate
                lviRentalOrder.SubItems.Add(xnRentalOrder.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.InnerText); // Tax Amount
                lviRentalOrder.SubItems.Add(xnRentalOrder.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.InnerText); // Order Total
                lviRentalOrder.SubItems.Add(xnRentalOrder.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.InnerText); // Order Status
    
                lvwRentalOrders.Items.Add(lviRentalOrder);
            }
        }
    }
    
    private void RentalOrders_Load(object sender, EventArgs e)
    {
        ShowRentalOrders();
    }

Parent Nodes

The parent keyword is used to get the parent of an element.

Practical LearningPractical Learning: Accessing a Parent Node

  1. Display the Update Rental Orders form and double-click the Open Rental Order button
  2. Implement the event as follows:
    private void btnOpen_Click(object sender, EventArgs e)
    {
        XmlDocument xdEmployees = new XmlDocument();
        XmlDocument xdRentalOrders = new XmlDocument();
        string strRentalOrdersFile = @"C:\Microsoft Visual C# Application Design\Bethesda Car Rental\RentalOrders.xml";
    
        if (string.IsNullOrEmpty(txtReceiptNumber.Text))
        {
            MessageBox.Show("You must provide a receipt number.",
                            "Bethesda Car Rental",
                            MessageBoxButtons.OK, MessageBoxIcon.Information);
            return;
        }
    
        if (File.Exists(strRentalOrdersFile))
        {
            xdRentalOrders.Load(strRentalOrdersFile);
            // The "parent" keyword is optional (you can omit it
            XmlNodeList xnlRentalOrders = xdRentalOrders.DocumentElement.SelectNodes("//parent::ReceiptNumber[.='" + txtReceiptNumber.Text + "']");
    
            foreach (XmlNode xnRentalOrder in xnlRentalOrders)
            {
                dtpDateProcessed.Value = DateTime.Parse(xnRentalOrder.NextSibling.InnerText);
                txtEmployeeNumber.Text = xnRentalOrder.NextSibling.NextSibling.InnerText;
                
                txtEmployeeNumber_Leave(sender, e);
                
                txtCustomerFirstName.Text = xnRentalOrder.NextSibling.NextSibling.NextSibling.InnerText;
                txtCustomerLastName.Text = xnRentalOrder.NextSibling.NextSibling.NextSibling.NextSibling.InnerText;
                txtCustomerAddress.Text = xnRentalOrder.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.InnerText;
                txtCustomerCity.Text = xnRentalOrder.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.InnerText;
                cbxCustomerStates.Text = xnRentalOrder.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.InnerText;
                txtCustomerZIPCode.Text = xnRentalOrder.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.InnerText;
                txtTagNumber.Text = xnRentalOrder.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.InnerText;
                        
                txtTagNumber_Leave(sender, e);
    
                cbxVehiclesConditions.Text = xnRentalOrder.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.InnerText;
                cbxTanksLevels.Text = xnRentalOrder.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.InnerText;
                txtMileageStart.Text = xnRentalOrder.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.InnerText;
                txtMileageEnd.Text = xnRentalOrder.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.InnerText;
                        
                txtMileageEnd_Leave(sender, e);
    
                dtpRentStartDate.Value = DateTime.Parse(xnRentalOrder.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.InnerText);
                dtpRentEndDate.Value = DateTime.Parse(xnRentalOrder.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.InnerText);
    
                dtpRentEndDate_ValueChanged(sender, e);
    
                txtRateApplied.Text = xnRentalOrder.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.InnerText; //
                txtTaxRate.Text = xnRentalOrder.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.InnerText;
                
                btnCalculate_Click(sender, e);
                
                cbxOrderStatus.Text = xnRentalOrder.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.InnerText;
                txtNotes.Text = xnRentalOrder.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.InnerText;
            }
        }
    }

The Ancestors of a Node

To get the ancestors of a node, precede its name with the ancestor keyword. Here is an example:

The Descendants of a Node

 To get the descendants of a node, precede its name with the descendant keyword.

Practical LearningPractical Learning: Accessing the Descendants of a Node

  1. Display the Vehicles form and click the tree view
  2. On the Properties window, click Events and double-click NodeMouseClick
  3. Implement the event as follows:
    private void tvwVehicles_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e)
    {
        XmlDocument xdVehicles = new XmlDocument();
        string strFileName = @"C:\Microsoft Visual C# Application Design\Bethesda Car Rental\Vehicles.xml";
    
        xdVehicles.Load(strFileName);
        lvwVehicles.Items.Clear();
    
        if ((e.Node.Text == "Bethesda Car Rental") ||
            (e.Node.Text == "Categories") ||
            (e.Node.Text == "Availabilities"))
        {
            // The descendant:: axis is optional
            XmlNodeList xnlVehicles = xdVehicles.DocumentElement.SelectNodes("/descendant::TagNumber"); // /descendant::TagNumber[.='" + e.Item.Text + "']");
    
            foreach (XmlNode xnVehicle in xnlVehicles)
            {
                ListViewItem lviVehicle = new ListViewItem(xnVehicle.InnerText); // Tag Number
    
                lviVehicle.SubItems.Add(xnVehicle.NextSibling.InnerText); // Make
                lviVehicle.SubItems.Add(xnVehicle.NextSibling.NextSibling.InnerText); // Model
                lviVehicle.SubItems.Add(xnVehicle.NextSibling.NextSibling.NextSibling.InnerText); // Doors
                lviVehicle.SubItems.Add(xnVehicle.NextSibling.NextSibling.NextSibling.NextSibling.InnerText); // Passengers
                lviVehicle.SubItems.Add(xnVehicle.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.InnerText); // Condition
                lviVehicle.SubItems.Add(xnVehicle.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.InnerText); // Category
                lviVehicle.SubItems.Add(xnVehicle.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.InnerText); // Availability
                lviVehicle.SubItems.Add(xnVehicle.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.InnerText); // Picture File
                lvwVehicles.Items.Add(lviVehicle);
            }
        }
        else
        {
            try
            {
                if (e.Node.Parent.Text == "Categories")
                {
                    XmlNodeList xnlVehicles = xdVehicles.DocumentElement.SelectNodes("/Vehicles/Vehicle/descendant::Category[.='" + e.Node.Text + "']");
    
                    foreach (XmlNode xnVehicle in xnlVehicles)
                    {
                        ListViewItem lviVehicle = new ListViewItem(xnVehicle.PreviousSibling.PreviousSibling.PreviousSibling.PreviousSibling.PreviousSibling.PreviousSibling.InnerText); // Tag Number
    
                        lviVehicle.SubItems.Add(xnVehicle.PreviousSibling.PreviousSibling.PreviousSibling.PreviousSibling.PreviousSibling.InnerText); // Make
                        lviVehicle.SubItems.Add(xnVehicle.PreviousSibling.PreviousSibling.PreviousSibling.PreviousSibling.InnerText); // Model
                        lviVehicle.SubItems.Add(xnVehicle.PreviousSibling.PreviousSibling.PreviousSibling.InnerText); // Doors
                        lviVehicle.SubItems.Add(xnVehicle.PreviousSibling.PreviousSibling.InnerText); // Passengers
                        lviVehicle.SubItems.Add(xnVehicle.PreviousSibling.InnerText); // Category
                        lviVehicle.SubItems.Add(xnVehicle.InnerText); // Condition
                        lviVehicle.SubItems.Add(xnVehicle.NextSibling.InnerText); // Availability
                        lviVehicle.SubItems.Add(xnVehicle.NextSibling.NextSibling.InnerText); // Picture File
    
                        lvwVehicles.Items.Add(lviVehicle);
                    }
                }
                else if (e.Node.Parent.Text == "Availabilities")
                {
                    XmlNodeList xnlVehicles = xdVehicles.DocumentElement.SelectNodes("/Vehicles/Vehicle/descendant::Availability[.='" + e.Node.Text + "']");
    
                    foreach (XmlNode xnVehicle in xnlVehicles)
                    {
                        ListViewItem lviVehicle = new ListViewItem(xnVehicle.PreviousSibling.PreviousSibling.PreviousSibling.PreviousSibling.PreviousSibling.PreviousSibling.PreviousSibling.InnerText); // Tag Number
                        lviVehicle.SubItems.Add(xnVehicle.PreviousSibling.PreviousSibling.PreviousSibling.PreviousSibling.PreviousSibling.PreviousSibling.InnerText); // Make
                        lviVehicle.SubItems.Add(xnVehicle.PreviousSibling.PreviousSibling.PreviousSibling.PreviousSibling.PreviousSibling.InnerText); // Model
                        lviVehicle.SubItems.Add(xnVehicle.PreviousSibling.PreviousSibling.PreviousSibling.PreviousSibling.InnerText); // Doors
                        lviVehicle.SubItems.Add(xnVehicle.PreviousSibling.PreviousSibling.PreviousSibling.InnerText); // Passengers
                        lviVehicle.SubItems.Add(xnVehicle.PreviousSibling.PreviousSibling.InnerText); // Category
                        lviVehicle.SubItems.Add(xnVehicle.PreviousSibling.InnerText); // Condition
                        lviVehicle.SubItems.Add(xnVehicle.InnerText); // Availability
                        lviVehicle.SubItems.Add(xnVehicle.NextSibling.InnerText); // Picture File
    
                        lvwVehicles.Items.Add(lviVehicle);
                    }
                }
            }
            catch (System.NullReferenceException nre)
            {
                MessageBox.Show(nre.Message);
            }
        }
    
        pbxVehicle.Image = Image.FromFile(@"C:\Microsoft Visual C# Application Design\Vehicle1.jpg");
    }
  4. Return to the Vehicles form and double-click the Close button
  5. Implement the event as follows:
    private void btnClose_Click(object sender, EventArgs e)
    {
        Close();
    }

The Previous Sibling of a Node

 To get the collection of nodes that come before a certain node, precede its name with the preceding keyword. If you want to exclude the node itself from the result, in other words if you want to get only the next sibliing of the same level, use the preceding-sibling keyword.

The Next Sibling a Node

The following keyword is used to get the next node(s) that come after the referenced one but of the same tree level.

Practical LearningPractical Learning: Following a Node

  1. Return to the Update Rental Orders form and double-click the Update Rental Order button
  2. Implement the event as follows:
    private void btnUpdateRentalOrder_Click(object sender, EventArgs e)
    {
        XmlDocument xdEmployees = new XmlDocument();
        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 provide a receipt number.",
                            "Bethesda Car Rental",
                            MessageBoxButtons.OK, MessageBoxIcon.Information);
            return;
        }
    
        if (File.Exists(strFileName))
        {
            xdRentalOrders.Load(strFileName);
            // The "following" keyword is optional (you can omit it
            XmlNodeList xnlRentalOrders = xdRentalOrders.DocumentElement.SelectNodes("//following::ReceiptNumber[.='" + txtReceiptNumber.Text + "']");
    
            foreach (XmlNode xnRentalOrder in xnlRentalOrders)
            {
                xnRentalOrder.ParentNode.InnerXml = "<ReceiptNumber>" + txtReceiptNumber.Text + "</ReceiptNumber>" +
                                                    "<DateProcessed>" + dtpDateProcessed.Value.ToShortDateString() + "</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>" + txtMileageEnd.Text + "</MileageEnd>" +
                                                    "<MileageTotal>" + txtMileageTotal.Text + "</MileageTotal>" +
                                                    "<RentStartDate>" + dtpRentStartDate.Value.ToShortDateString() + "</RentStartDate>" +
                                                    "<RentEndDate>" + dtpRentStartDate.Value.ToShortDateString() + "</RentEndDate>" +
                                                    "<TotalDays>" + txtTotalDays.Text + "</TotalDays>" +
                                                    "<RateApplied>" + txtRateApplied.Text +  "</RateApplied>" +
                                                    "<SubTotal>" + txtSubTotal.Text + "</SubTotal>" +
                                                    "<TaxRate>" + txtTaxRate.Text +  "</TaxRate>" +
                                                    "<TaxAmount>" + txtTaxAmount.Text + "</TaxAmount>" +
                                                    "<OrderTotal>" + txtOrderTotal.Text + "</OrderTotal>" +
                                                    "<OrderStatus>" + cbxOrdersStatus.Text +  "</OrderStatus>" +
                                                    "<Notes>" + txtNotes.Text +  "</Notes>";
            }
    
            xdRentalOrders.Save(strFileName);
            Close();
        }
    }
  3. Return to the Update Rental Order form and double-click the Close button
  4. Implement the event as follows:
    private void btnClose_Click(object sender, EventArgs e)
    {
        Close();
    }
  5. Display the Rental Orders form and double-click the New Rental Order button
  6. Return to the Rental Orders form and double-click the Update Rental Order button
  7. Return to the Update Rental Order form and double-click the Close button
  8. Implement the events as follows:
    private void btnNewRentalOrder_Click(object sender, EventArgs e)
    {
        NewRentalOrder nro = new NewRentalOrder();
        nro.ShowDialog();
        ShowRentalOrders();
    }
    
    private void btnUpdateRentalOrder_Click(object sender, EventArgs e)
    {
        UpdateRentalOrder uro = new UpdateRentalOrder();
        uro.ShowDialog();
        ShowRentalOrders();
    }
    
    private void btnClose_Click(object sender, EventArgs e)
    {
        Close();
    }
 
 
  1. Execute the application
  2. Click the Vehicles button

    Bethesda Car Rental - Vehicles

  3. Create a few vehicles records as follows:
     
    Tag # Make Model Doors Passengers Condition Category Availability
    2AM9952 Ford Fiesta SE 4 5 Driveable Economy Available
    6AD8274 Mazda CX-9 4 5 Excellent Mini Van Available
    8AG3584 Toyota Sienna LE FWD 4 8 Excellent Passenger Van Available
    KER204 Ford Focus SF 4 5 Excellent Compact Being Serviced
    3AD9283 Kia Rio EX 4 5 Excellent Economy Rented
    8AE9294 Lincoln MKT 3.5L 4 5 Excellent Full Size Available
    KLT840 Ford E-350 XL 3 15 Driveable Passenger Van Available
    8AL8033 Toyota Corolla LE 4 5 Excellent Compact Available
    4AF9284 Toyota Tacoma 2 2 Needs Repair Pickup Truck Available
    ADG279 GMC Acadia SLE 4 5 Excellent SUV Rented
    1AD8049 Dodge Charger SXT 4 5 Excellent Standard Being Serviced
    9MD3974 Toyota Sienna LE FWD 4 8 Driveable Passenger Van Rented
    5AJ9274 BMW 528i 4 5 Excellent Full Size Available
    GTH295 Kia Rio5 4 5 Excellent Economy Available
    8AT2408 Mazda Miata MX-5 2 2 Excellent Compact Available
    6AP2486 Fiat 500 2 4 Excellent Economy Available
    2AL9485 Chrysler 200 2 2 Excellent Compact Available
    DFP924 Toyota Sienna LE FWD 4 8 Driveable Passenger Van Available
    2MD8382 Toyota RAV4 I4 4X4 4 5 Excellent SUV Available
    8AR9374 Honda Accord LX 4 5 Excellent Standard Rented
    5MD2084 Chevrolet Equinox LS 4 5 Driveable Mini Van Available
    BND927 Ford Fiesta SE 4 5 Driveable Economy Available
    6AP2749 Toyota Corolla LE 4 5 Excellent Compact Rented
    8AL7394 Ford F-250 SD Reg Cab 4X4 2 2 Excellent Pickup Truck Available
    4MD2840 Chevrolet 2500 LS 3 15 Excellent Passenger Van Rented
    G249580 Nissan Sentra SR 4 5 Excellent Compact Available
    3AK7397 Chrysler 200 2 2 Excellent Compact Available
    VGT927 Toyota Tundra Dbl Cab 4X4 2 5 Excellent Pickup Truck Available
    2AT9274 Ford Focus SF 4 5 Excellent Compact Available
    6AH8429 Lincoln MKT 3.5L 4 5 Needs Repair Full Size Available
    8MD9284 Ford Escape SE I4 4 5 Excellent Mini Van Available
    PLD937 Chevrolet Imapala LT 4 5 Excellent Compact Being Serviced
    5AK2974 Fiat 500 2 4 Excellent Economy Available
    1MD9284 Ford Escape SE I4 4 5 Excellent Mini Van Being Serviced
    SDG624 Chevrolet Volt 4 5 Excellent Standard Available
    2AR9274 Kia Rio SX 4 5 Excellent Economy Available
    JWJ814 Cadillac CTS-V 4 5 Excellent Full Size Available
    7MD9794 Ford Focus SF 4 5 Excellent Compact Rented
    UQW118 Chevrolet 2500 LS 3 15 Needs Repair Passenger Van Available
    2MD9247 Toyota RAV4 I4 4X4 4 5 Excellent SUV Available

    Bethesda Car Rental - Vehicles

    Bethesda Car Rental - Vehicles

  4. Click the Employees button
  5. Create a few employees as follows:
     
    Employee # First Name Last Name Title
    92735 Jeffrey Leucart General Manager
    29268 Catherine Rawley Administrative Assistant
    73948 Allison Garlow Rental Associate
    40508 David Stillson Technician
    24793 Michelle Taylor Accounts Manager
    20480 Peter Futterman Rental Associate
    72084 Georgia Rosen Customer Service Representative
    38240 Karen Blackney Rental Associate
  6. Close the Employees form
  7. Create new rental orders as follows:
     
    Receipt # RPPB First Name Last Name Address City State ZIP Code Tag # Car Condition Tank Level Mileage Start Start Date Rate Applied Order Status
    100001 20480 Marcel Buhler 6800 Haxell Crt Alexandria VA 22314 8AG3584 Excellent Empty 12728 7/14/2014 69.95 Vehicle With Customer
    100002 24793 Joan Altman 3725 South Dakota Ave NW Washington DC 20012 KER204 Good 3/4 Full 24715 7/18/2014 62.95 Vehicle With Customer
    100003 38240 Thomas Filder 4905 Herrenden St Arlington VA 22204 8AL8033 Excellent 1/4 Empty 6064 7/18/2014 34.95 Vehicle With Customer

    Bethesda Car Rental: Rental Order

  8. Update the following rental orders (make sure you click Calculate:
     
    Receipt # to Open Tank Level Mileage End End Date Total Days Rate Applied Sub-Total Tax Rate Tax Amount Order Total Order Status
    100001 Half Tank 13022 7/19/2014 5 69.95 349.75 7.75% 27.11 376.86 Rental Order Complete
    100003 Full 6229 7/21/2014 3 34.95 104.85 7.75% 8.13 112.98 Rental Order Complete

    Bethesda Car Rental: Rental Order

  9. Create a new rental order as follows:
     
    Receipt # RPPB First Name Last Name Address City State ZIP Code Tag # Car Condition Tank Level Mileage Start Start Date Rate Applied Order Status
    100004 73948 Gregory Strangeman 5530 Irving St College Park MD 20740 2AT9274 Excellent 1/2 Tank 8206 7/21/2014 28.95 Vehicle With Customer
  10. Update the following rental order:
     
    Receipt # to Open Tank Level Mileage End End Date Total Days Rate Applied Sub-Total Tax Rate Tax Amount Order Total Order Status
    100002 Full 25694 7/22/2014 4 62.95 251.8 7.75% 19.39 271.19 Rental Order Complete
  11. Create a new rental order as follows:
     
    Receipt # RPPB First Name Last Name Address City State ZIP Code Tag # Car Condition Tank Level Mileage Start Start Date Rate Applied Order Status
    100005 38240 Michelle Russell 10070 Weatherwood Drv Rockville MD 20853 8AE9294 Excellent Full 3659 7/22/2014 38.95 Vehicle With Customer
  12. Update the following rental orders:
     
    Receipt # to Open Tank Level Mileage End End Date Total Days Rate Applied Sub-Total Tax Rate Tax Amount Order Total Order Status
    100005 Full 3806 7/23/2014 1 38.95 38.95 7.75% 3.00 41.95 Rental Order Complete
    100004 3/4 Full 8412 7/25/2014 2 28.95 57.9 7.75% 4.46 62.36 Rental Order Complete
  13. Close the forms and return to your programming environment

Application

 
 

Home Copyright © 2014, FunctionX