Home

Creating a Client Server Application

   

Practical LearningPractical Learning: Processing Orders

  1. To add a new class to the project, in the Class View, right-click BethesdaCarRental1 -> Add -> Class...
  2. Set the Class Name to RentalOrder and press Enter
  3. Access the RentalOrder.cs file and change it as follows:
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    
    namespace BethesdaCarRental1
    {
        [Serializable]
        public class RentalOrder
        {
            public string EmployeeNumber;
            // The following flag will allow us to update/know whether
            // * The car is currently being used by the customer.
            //   That is, if the car has been picked up by the customer
            // * The customer has brought the car back
            public string OrderStatus;
            // Because every car has a tag number
            // and that tag number will not change
            // during the lifetime of a car (while the car remains with our
            // car rental company, we will 
            // use only the tag number here.
            // The other pieces of information will 
            // be retrieved from the list of cars
            public string CarTagNumber;
            // We will identify the customer by the number
            // and the name on his or her driver's license
            public string CustomerDrvLicNbr;
            public string CustomerName;
            // Although he or she may keep the same driver's 
            // license number for a lifetime, a customer who 
            // rents cars at different times with this company 
            // over months or years may have different addresses.
            // Therefore, although we will primarily retrieve the 
            // customer's address from the list of customers,
            // we will give the clerk the ability to change this 
            // information on a rental order. This means that the 
            // same customer could have different information on 
            // different rental orders.
            // For this reason, each rental order will its own set
            // of these pieces of information
            public string CustomerAddress;
            public string CustomerCity;
            public string CustomerState;
            public string CustomerZIPCode;
            public string CarCondition;
            public string TankLevel;
            // This information will be entered when the car is being rented
            public int MileageStart;
            // This information will be entered when the car is brought back
            public int MileageEnd;
            // This information will be entered when the car is being rented
            public DateTime DateStart;
            // This information will be entered when the car is brought back
            public DateTime DateEnd;
            public int Days;
            // This information will be entered when the car is being rented
            public double RateApplied;
            // This calculation should occur when the car is brought back
            public double SubTotal;
            public double TaxRate;
            public double TaxAmount;
            public double OrderTotal;
        }
    }
  4. To add a new form to the project, in the Solution Explorer, right-click BethesdaCarRenat1 -> Add -> Windows Form...
  5. Set the Name to OrderProcessing and press Enter
  6. Display the Central form
  7. Double-click the Rental Orders button
  8. Implement its event as follows:
    private void btnRentalOrders_Click(object sender, EventArgs e)
    {
        OrderProcessing dlgOrder = new OrderProcessing();
        dlgOrder.ShowDialog();
    }
  9. Return to the Central form
  10. Double-click the Close button
  11. Implement the event as follows:
    private void btnClose_Click(object sender, EventArgs e)
    {
        Close();
    }
  12. Display the Order Processing form
  13. Design the form as follows:
     
    Rental Orders
    Control Text Name Other Properties
    Label Processed By:   AutoSize: False
    BackColor: Gray
    BorderStyle: FixedSingle
    ForeColor: White
    TextAlign: MiddleLeft
    Label Employee #:    
    MaskedTextBox   txtEmployeeNumber Mask: 00-000
    Label Employee Name:    
    TextBox   txtEmployeeName  
    Label Processed For   AutoSize: False
    BackColor: Gray
    BorderStyle: FixedSingle
    ForeColor: White
    TextAlign: MiddleLeft
    Label Driver's Lic #:    
    TextBox   txtDrvLicNumber  
    Label Cust Name:    
    TextBox   txtCustomerName  
    Label Address:    
    TextBox   txtCustomerAddress  
    Label City:    
    TextBox   txtCustomerCity  
    Label State:    
    ComboBox   cbxCustomerStates DropDownStyle: DropDownList
    Sorted: True
    Items: AL, AK, AZ, AR, CA, CO, CT, DE, DC, FL, GA, HI, ID, IL, IN, IA, KS, KY, LA, ME, MD, MA, MI, MN, MS, MO, MT, NE, NV, NH, NJ, NM, NY, NC, ND, OH, OK, OR, PA, RI, SC, SD, TN, TX, UT, VT, VA, WA, WV, WI, WY
    Label ZIP Code    
    TextBox   txtCustomerZIPCode  
    Label Car Selected   AutoSize: False
    BackColor: Gray
    BorderStyle: FixedSingle
    ForeColor: White
    TextAlign: MiddleLeft
    Label Tag Number:    
    TextBox   txtTagNumber  
    Label Car Condition:    
    ComboBox   cbxCarConditions Sorted: True
    Items:
    Needs Repair
    Drivable
    Excellent
    Label Make:    
    TextBox   txtMake  
    Label Model:    
    TextBox   txtModel  
    Label Year:    
    TextBox   txtCarYear  
    label Tank Level:    
    ComboBox   cbxTankLevels Empty
    1/4 Empty
    1/2 Full
    3/4 Full
    Full
    Label Mileage Start:    
    TextBox   txtMileageStart TextAlign: Right
    Label Mileage End:    
    TextBox   txtMileageEnd TextAlign: Right
    Label Order Timing   AutoSize: False
    BackColor: Gray
    BorderStyle: FixedSingle
    ForeColor: White
    TextAlign: MiddleLeft
    Label Start Date:    
    DateTimePicker   dtpStartDate  
    Label End Date:    
    DateTimePicker   dtpEndDate  
    Label Days:    
    TextBox 0 txtDays TextAlign: Right
    Label Order Status    
    ComboBox   cbxOrderStatus Items:
    Car On Road
    Car Returned
    Order Reserved
    Label Order Evaluation   AutoSize: False
    BackColor: Gray
    BorderStyle: FixedSingle
    ForeColor: White
    TextAlign: MiddleLeft
    Label Rate Applied:    
    TextBox 0.00 txtRateApplied TextAlign: Right
    Button Rental Rates btnRentalRates  
    Label Sub-Total:    
    TextBox 0.00 txtSubTotal TextAlign: Right
    Button Calculate btnCalculate  
    Label Tax Rate:    
    TextBox 7.75 txtTaxRate TextAlign: Right
    Label %    
    Button Save btnSave  
    Label Tax Amount:    
    TextBox 0.00 txtTaxAmount TextAlign: Right
    Button Print... btnPrint  
    Label Order Total:    
    TextBox 0.00 txtOrderTotal TextAlign: Right
    Button Print Preview... btnPrintPreview  
    Label Receipt #:    
    TextBox 0 txtReceiptNumber  
    Button Open btnOpen  
    Button New Rental Order/Reset btnNewRentalOrder  
    Button Close btnClose  
  14. To add a new form to the project, in the Solution Explorer, right-click BethesdaCarRental1 -> Add -> Windows Form...
  15. Set the Name to RentalRates and press Enter
  16. 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  
  17. 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
  18. Complete the design of the form as follows:
     
    Rental Rates
  19. In the Solution Explorer, right-click OrderProcessing.cs and click View Code
  20. Make the following changes:
    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.Runtime.Serialization.Formatters.Binary;
    
    namespace BethesdaCarRental1
    {
        public partial class OrderProcessing : Form
        {
            int ReceiptNumber;
            Dictionary<int, RentalOrder> ListOfRentalOrders;
    
            public OrderProcessing()
            {
                InitializeComponent();
            }
        }
    }
  21. On the Order Processing form, click the Employee Number text box
  22. In the Events section of the Properties window, double-click Leave and implement the event as follows:
    private void txtEmployeeNumber_Leave(object sender, EventArgs e)
    {
        Employee clerk;
        string strEmployeeNumber = txtEmployeeNumber.Text;
    
        if (strEmployeeNumber.Length == 0)
        {
            MessageBox.Show("You must enter the employee's number",
                            "Bethesda Car Rental",
                            MessageBoxButtons.OK, MessageBoxIcon.Information);
            txtEmployeeNumber.Focus();
            return;
        }
    
        Dictionary<string, Employee> LstOfEmployees = 
        	new Dictionary<string, Employee>();
        BinaryFormatter bfmEmployees = new BinaryFormatter();
    
        string strFilename = @"\\EXPRESSION\Bethesda Car Rental\Employees.cre";
    
        if (File.Exists(strFilename))
        {
            FileStream stmEmployees = new FileStream(strFilename,
                                                     FileMode.Open,
                                                     FileAccess.Read,
                                                     FileShare.Read);
            try
            {
                // Retrieve the list of employees
                LstOfEmployees = (Dictionary<string, 
                		Employee>)bfmEmployees.Deserialize(stmEmployees);
    
                if (LstOfEmployees.TryGetValue(strEmployeeNumber, out clerk))
                {
                    txtEmployeeName.Text = clerk.FullName;
                }
                else
                {
                    txtEmployeeName.Text = "";
                    MessageBox.Show("There is no employee with that number",
                                    "Bethesda Car Rental",
                                    MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }
            }
            finally
            {
                stmEmployees.Close();
            }
        }
    }
  23. Return to the Order Processing form
  24. On the form, click the Driver's Lic # text box
  25. In the Properties window, click the Events button and, in the Events section, double-click Leave
  26. Implement the event as follows:
    private void txtDrvLicNumber_Leave(object sender, EventArgs e)
    {
        Customer renter = null;
        string strDrvLicNumber = txtDrvLicNumber.Text;
    
        if (strDrvLicNumber.Length == 0)
        {
            MessageBox.Show("You must enter the renter's " +
                            "driver's license number",
                            "Bethesda Car Rental",
                            MessageBoxButtons.OK, MessageBoxIcon.Information);
            txtDrvLicNumber.Focus();
            return;
        }
    
        Dictionary<string, Customer> ListOfCustomers = 
        				new Dictionary<string, Customer>();
        BinaryFormatter bfmCustomers = new BinaryFormatter();
    
        string strFilename = @"\\EXPRESSION\Bethesda Car Rental\Customers.crc";
    
        if (File.Exists(strFilename))
        {
            FileStream stmCustomers = new FileStream(strFilename,
                                                     FileMode.Open,
                                                     FileAccess.Read,
                                                     FileShare.Read);
    
            try
            {
                // Retrieve the list of customers
                listOfCustomers = (Dictionary<string, 
                		Customer>)bfmCustomers.Deserialize(stmCustomers);
    
                if (listOfCustomers.ContainsKey(strDrvLicNumber) == true)
                {
                    foreach (KeyValuePair<string, Customer> cust in listOfCustomers)
                    {
                        if (cust.Key == strDrvLicNumber)
                        {
                            renter = cust.Value;
                            txtCustomerName.Text = renter.FullName;
                            txtCustomerAddress.Text = renter.Address;
                            txtCustomerCity.Text = renter.City;
                            cbxCustomerStates.Text = renter.State;
                            txtCustomerZIPCode.Text = renter.ZIPCode;
                        }
                    }
                }
                else
                {
                    txtCustomerName.Text = "";
                    txtCustomerAddress.Text = "";
                    txtCustomerCity.Text = "";
                    cbxCustomerStates.Text = "";
                    txtCustomerZIPCode.Text = "";
                    MessageBox.Show("There is no customer with that driver's " +
                                    "license number in our database",
                                    "Bethesda Car Rental",
                                    MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }
            }
            finally
            {
                stmCustomers.Close();
            }
        }
    }
  27. Return to the Order Processing form
  28. Click the Tag Number text box
  29. In the Events section of the Properties window, double-click Leave and implement the event as follows:
    private void txtTagNumber_Leave(object sender, EventArgs e)
    {
        Car selected;
        string strTagNumber = txtTagNumber.Text;
    
        if (strTagNumber.Length == 0)
        {
            MessageBox.Show("You must enter the car's tag number",
                            "Bethesda Car Rental",
                            MessageBoxButtons.OK, MessageBoxIcon.Information);
            txtTagNumber.Focus();
            return;
        }
    
        Dictionary<string, Car> LstOfCars =
                    new Dictionary<string, Car>();
        BinaryFormatter bfmCars = new BinaryFormatter();
    
        string strFilename = @"\\EXPRESSION\Bethesda Car Rental\Cars.crs";
    
        if (File.Exists(strFilename))
        {
            FileStream stmCars = new FileStream(strFilename,
                                                FileMode.Open,
                                                FileAccess.Read,
                                                FileShare.Read);
            try
            {
                // Retrieve the list of employees from file
                LstOfCars =
                    (Dictionary<string, Car>)
                            bfmCars.Deserialize(stmCars);
                if (LstOfCars.TryGetValue(strTagNumber, out selected))
                {
                    txtMake.Text = selected.Make;
                    txtModel.Text = selected.Model;
                    txtCarYear.Text = selected.Year.ToString();
                }
                else
                {
                    txtMake.Text = "";
                    txtModel.Text = "";
                    txtCarYear.Text = "";
                    MessageBox.Show("There is no car with that tag " +
                                    "number in our database",
                            "Bethesda Car Rental",
                            MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }
            }
            finally
            {
                stmCars.Close();
            }
        }
    }
  30. Return to the Order Processing form
  31. Double-click the Start Date control
  32. Implement the event as follows:
    private void dtpStartDate_ValueChanged(object sender, EventArgs e)
    {
        dtpEndDate.Value = dtpStartDate.Value;
    }
  33. Return to the Order Processing form
  34. Double-click the End Date control
  35. 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 dtpEndDate_ValueChanged(object sender, EventArgs e)
    {
        int days;
    
        DateTime dteStart = this.dtpStartDate.Value;
        DateTime dteEnd = this.dtpEndDate.Value;
    
        // Let's calculate the difference in days
        TimeSpan tme = dteEnd - dteStart;
        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;
    
        txtDays.Text = days.ToString();
        // At any case, we will let the clerk specify the actual number of days
    }
  36. Return to the Order Processing form
  37. Double-click the Rental Rates button
  38. Implement its event as follows:
    private void btnRentalRates_Click(object sender, EventArgs e)
    {
        RentalRates wndRates = new RentalRates();
        wndRates.Show();
    }
  39. Return to the Order Processing form
  40. Double-click the Calculate button
  41. 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(this.txtDays.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");
    }
  42. Return to the Order Processing form
  43. Double-click the Save button and implement its event as follows:
    private void btnSave_Click(object sender, EventArgs e)
    {
        if (txtReceiptNumber.Text == "")
        {
            MessageBox.Show("The receipt number is missing",
                            "Bethesda Car Rental",
                            MessageBoxButtons.OK, MessageBoxIcon.Information);
            return;
        }
    
        // Don't save this rental order if we don't
        // know who processed it
        if (txtEmployeeNumber.Text == "")
        {
            MessageBox.Show("You must enter the employee number or the " +
                            "clerk who processed this order.",
                            "Bethesda Car Rental",
                            MessageBoxButtons.OK, MessageBoxIcon.Information);
            return;
        }
    
        // Don't save this rental order if we don't
        // know who is renting the car
        if (txtDrvLicNumber.Text == "")
        {
            MessageBox.Show("You must specify the driver's license number " +
                            "of the customer who is renting the car",
                            "Bethesda Car Rental",
                            MessageBoxButtons.OK, MessageBoxIcon.Information);
            return;
        }
    
        // Don't save the rental order if we don't
        // know what car is being rented
        if (txtTagNumber.Text == "")
        {
            MessageBox.Show("You must enter the tag number " +
                            "of the car that is being rented",
                            "Bethesda Car Rental",
                            MessageBoxButtons.OK, MessageBoxIcon.Information);
            return;
        }
    
        // Create a rental order based on the information on the form
        RentalOrder CurrentOrder = new RentalOrder();
    
        CurrentOrder.EmployeeNumber = txtEmployeeNumber.Text;
        CurrentOrder.OrderStatus = cbxOrderStatus.Text;
        CurrentOrder.CarTagNumber = txtTagNumber.Text;
        CurrentOrder.CustomerDrvLicNbr = txtDrvLicNumber.Text;
        CurrentOrder.CustomerName = txtCustomerName.Text;
        CurrentOrder.CustomerAddress = txtCustomerAddress.Text;
        CurrentOrder.CustomerCity = txtCustomerCity.Text;
        CurrentOrder.CustomerState = cbxCustomerStates.Text;
        CurrentOrder.CustomerZIPCode = txtCustomerZIPCode.Text;
        CurrentOrder.CarCondition = cbxCarConditions.Text;
        CurrentOrder.TankLevel = cbxTankLevels.Text;
    
        try
        {
            CurrentOrder.MileageStart = int.Parse(txtMileageStart.Text);
        }
        catch (FormatException)
        {
            MessageBox.Show("Invalid mileage start value",
                            "Bethesda Car Rental",
                            MessageBoxButtons.OK, MessageBoxIcon.Information);
        }
    
        try
        {
            CurrentOrder.MileageEnd = int.Parse(txtMileageEnd.Text);
        }
        catch (FormatException)
        {
            MessageBox.Show("Invalid mileage end value",
                            "Bethesda Car Rental",
                            MessageBoxButtons.OK, MessageBoxIcon.Information);
        }
    
        try
        {
            CurrentOrder.DateStart = dtpStartDate.Value;
        }
        catch (FormatException)
        {
            MessageBox.Show("Invalid start date",
                            "Bethesda Car Rental",
                            MessageBoxButtons.OK, MessageBoxIcon.Information);
        }
    
        try
        {
            CurrentOrder.DateEnd = dtpEndDate.Value;
        }
        catch (FormatException)
        {
            MessageBox.Show("Invalid end date",
                            "Bethesda Car Rental",
                            MessageBoxButtons.OK, MessageBoxIcon.Information);
        }
    
        try
        {
            CurrentOrder.Days = int.Parse(txtDays.Text);
        }
        catch (FormatException)
        {
            MessageBox.Show("Invalid number of days",
                            "Bethesda Car Rental",
                            MessageBoxButtons.OK, MessageBoxIcon.Information);
        }
    
        try
        {
            CurrentOrder.RateApplied = double.Parse(txtRateApplied.Text);
        }
        catch (FormatException)
        {
            MessageBox.Show("Invalid rate value",
                            "Bethesda Car Rental",
                            MessageBoxButtons.OK, MessageBoxIcon.Information);
        }
    
        CurrentOrder.SubTotal = double.Parse(txtSubTotal.Text);
    
        try
        {
            CurrentOrder.TaxRate = double.Parse(txtTaxRate.Text);
        }
        catch (FormatException)
        {
            MessageBox.Show("Inavlid tax rate",
                            "Bethesda Car Rental",
                            MessageBoxButtons.OK, MessageBoxIcon.Information);
        }
    
        CurrentOrder.TaxAmount = double.Parse(txtTaxAmount.Text);
        CurrentOrder.OrderTotal = double.Parse(txtOrderTotal.Text);
        // The rental order is ready
    
        // Get the receipt number from its text box
        try
        {
            ReceiptNumber = int.Parse(txtReceiptNumber.Text);
        }
        catch (FormatException)
        {
            MessageBox.Show("You must provide a receipt number",
                            "Bethesda Car Rental",
                            MessageBoxButtons.OK, MessageBoxIcon.Information);
        }
    
        // Get the list of rental orders and 
        // check if there is already one with the current receipt number
        // If there is already a receipt number like that...
        if (ListOfRentalOrders.ContainsKey(ReceiptNumber) == true)
        {
            // Simply update its value
            ListOfRentalOrders[ReceiptNumber] = CurrentOrder;
        }
        else
        {
            // If there is no order with that receipt,
            // then create a new rental order
            ListOfRentalOrders.Add(ReceiptNumber, CurrentOrder);
        }
    
        // The list of rental orders
        string strFilename = @"\\EXPRESSION\Bethesda Car Rental\RentalOrders.cro";
        FileStream bcrStream = new FileStream(strFilename,
                                              FileMode.Create,
                                              FileAccess.Write,
                                              FileShare.Write);
        BinaryFormatter bcrBinary = new BinaryFormatter();
    
        try
        {
            bcrBinary.Serialize(bcrStream, ListOfRentalOrders);
        }
        finally
        {
            bcrStream.Close();
        }
    }
  44. Return to the Order Processing form

 

 

 

 
 
 
  1. From the Printing section of the Toolbox, click PrintDocument and click the form
  2. In the Properties window, set its (Name) to docPrint and press Enter
  3. Under the form, double-click docPrint and 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 fntString = new Font("Times New Roman", 28,
                            FontStyle.Bold);
        e.Graphics.DrawString(strDisplay, fntString,
                            Brushes.Black, 240, 100);
    
        strDisplay = "Car Rental Order";
        fntString = new System.Drawing.Font("Times New Roman", 22,
                            FontStyle.Regular);
        e.Graphics.DrawString(strDisplay, fntString,
                            Brushes.Black, 320, 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);
    
        fntString = new System.Drawing.Font("Times New Roman", 12,
                    FontStyle.Bold);
        e.Graphics.DrawString("Receipt #:  ", fntString,
                    Brushes.Black, 100, 220);
        fntString = new System.Drawing.Font("Times New Roman", 12,
                    FontStyle.Regular);
        e.Graphics.DrawString(txtReceiptNumber.Text, fntString,
                                      Brushes.Black, 260, 220);
        e.Graphics.DrawLine(new Pen(Color.Black, 1), 100, 240, 380, 240);
    
        fntString = new System.Drawing.Font("Times New Roman", 12,
                    FontStyle.Bold);
        e.Graphics.DrawString("Processed By:  ", fntString,
                    Brushes.Black, 420, 220);
        fntString = new System.Drawing.Font("Times New Roman", 12,
                    FontStyle.Regular);
        e.Graphics.DrawString(txtEmployeeName.Text, fntString,
                                      Brushes.Black, 550, 220);
        e.Graphics.DrawLine(new Pen(Color.Black, 1), 420, 240, 720, 240);
    
        fntString = new Font("Times New Roman", 12, FontStyle.Bold);
    
        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", fntString,
                                      Brushes.White, 100, 260);
    
        fntString = new Font("Times New Roman", 12, FontStyle.Bold);
        e.Graphics.DrawString("Driver's License #: ", fntString,
                                      Brushes.Black, 100, 300);
        e.Graphics.DrawString("Name: ", fntString,
                                     Brushes.Black, 420, 300);
        fntString = new Font("Times New Roman", 12, FontStyle.Regular);
        e.Graphics.DrawString(txtDrvLicNumber.Text, fntString,
                                      Brushes.Black, 260, 300);
        e.Graphics.DrawString(txtCustomerName.Text, fntString,
                                      Brushes.Black, 540, 300);
        e.Graphics.DrawLine(new Pen(Color.Black, 1), 100, 320, 720, 320);
    
        fntString = new Font("Times New Roman", 12, FontStyle.Bold);
        e.Graphics.DrawString("Address: ", fntString,
                                      Brushes.Black, 100, 330);
        fntString = new Font("Times New Roman", 12, FontStyle.Regular);
        e.Graphics.DrawString(txtCustomerAddress.Text, fntString,
                                      Brushes.Black, 260, 330);
        e.Graphics.DrawLine(new Pen(Color.Black, 1), 100, 350, 720, 350);
    
        strDisplay = txtCustomerCity.Text + " " +
                             cbxCustomerStates.Text + " " +
                             txtCustomerZIPCode.Text;
        fntString = new System.Drawing.Font("Times New Roman",
     		12, FontStyle.Regular);
        e.Graphics.DrawString(strDisplay, fntString,
                                      Brushes.Black, 260, 360);
        e.Graphics.DrawLine(new Pen(Color.Black, 1), 260, 380, 720, 380);
    
        fntString = new Font("Times New Roman", 12, FontStyle.Bold);
    
        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", fntString,
                                      Brushes.White, 100, 410);
    
        fntString = new Font("Times New Roman", 12, FontStyle.Bold);
        e.Graphics.DrawString("Tag #: ", fntString,
                                      Brushes.Black, 100, 450);
        fntString = new Font("Times New Roman", 12, FontStyle.Regular);
        e.Graphics.DrawString(txtTagNumber.Text, fntString,
                                      Brushes.Black, 260, 450);
        e.Graphics.DrawLine(new Pen(Color.Black, 1), 100, 470, 380, 470);
    
        fntString = new Font("Times New Roman", 12, FontStyle.Bold);
        e.Graphics.DrawString("Year: ", fntString,
                                      Brushes.Black, 420, 450);
        fntString = new Font("Times New Roman", 12, FontStyle.Regular);
        e.Graphics.DrawString(txtCarYear.Text, fntString,
                                      Brushes.Black, 530, 450);
        e.Graphics.DrawLine(new Pen(Color.Black, 1), 420, 470, 720, 470);
    
        fntString = new Font("Times New Roman", 12, FontStyle.Bold);
        e.Graphics.DrawString("Make: ", fntString,
                                      Brushes.Black, 100, 480);
        fntString = new Font("Times New Roman", 12, FontStyle.Regular);
        e.Graphics.DrawString(txtMake.Text, fntString,
                                      Brushes.Black, 260, 480);
        e.Graphics.DrawLine(new Pen(Color.Black, 1), 100, 500, 380, 500);
    
        fntString = new Font("Times New Roman", 12, FontStyle.Bold);
        e.Graphics.DrawString("Model: ", fntString,
                                      Brushes.Black, 420, 480);
        fntString = new Font("Times New Roman", 12, FontStyle.Regular);
        e.Graphics.DrawString(txtModel.Text, fntString,
                                      Brushes.Black, 530, 480);
        e.Graphics.DrawLine(new Pen(Color.Black, 1), 420, 500, 720, 500);
    
        fntString = new Font("Times New Roman", 12, FontStyle.Bold);
        e.Graphics.DrawString("Car Condition: ", fntString,
                                      Brushes.Black, 100, 510);
        fntString = new Font("Times New Roman", 12, FontStyle.Regular);
        e.Graphics.DrawString(cbxCarConditions.Text, fntString,
                                      Brushes.Black, 260, 510);
        e.Graphics.DrawLine(new Pen(Color.Black, 1), 100, 530, 380, 530);
    
        fntString = new Font("Times New Roman", 12, FontStyle.Bold);
        e.Graphics.DrawString("Tank Level: ", fntString,
                                      Brushes.Black, 420, 510);
        fntString = new Font("Times New Roman", 12, FontStyle.Regular);
        e.Graphics.DrawString(cbxTankLevels.Text, fntString,
                                      Brushes.Black, 530, 510);
        e.Graphics.DrawLine(new Pen(Color.Black, 1), 420, 530, 720, 530);
    
        fntString = new Font("Times New Roman", 12, FontStyle.Bold);
        e.Graphics.DrawString("Mileage Start:", fntString,
                                      Brushes.Black, 100, 540);
        fntString = new Font("Times New Roman", 12, FontStyle.Regular);
        e.Graphics.DrawString(txtMileageStart.Text, fntString,
                                      Brushes.Black, 260, 540);
        e.Graphics.DrawLine(new Pen(Color.Black, 1), 
    				100, 560, 380, 560);
    
        fntString = new Font("Times New Roman", 12, FontStyle.Bold);
        e.Graphics.DrawString("Mileage End:", fntString,
                              Brushes.Black, 420, 540);
        fntString = new Font("Times New Roman", 12, FontStyle.Regular);
        e.Graphics.DrawString(txtMileageEnd.Text, fntString,
                              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));
    
        fntString = new Font("Times New Roman", 12, FontStyle.Bold);
        e.Graphics.DrawString("Order Timing Information", fntString,
                              Brushes.White, 100, 590);
    
        fntString = new Font("Times New Roman", 12, FontStyle.Bold);
        e.Graphics.DrawString("Start Date:", fntString,
                               Brushes.Black, 100, 620);
        fntString = new Font("Times New Roman", 12, FontStyle.Regular);
        e.Graphics.DrawString(dtpStartDate.Value.ToString("D"),
    			  fntString, Brushes.Black, 260, 620);
        e.Graphics.DrawLine(new Pen(Color.Black, 1),
    			100, 640, 720, 640);
    
        fntString = new Font("Times New Roman", 12, FontStyle.Bold);
        e.Graphics.DrawString("End Date:", fntString,
                              Brushes.Black, 100, 650);
        fntString = new Font("Times New Roman", 12, FontStyle.Regular);
        e.Graphics.DrawString(dtpEndDate.Value.ToString("D"), fntString,
                              Brushes.Black, 260, 650);
        e.Graphics.DrawLine(new Pen(Color.Black, 1),
    			100, 670, 520, 670);
    
        fntString = new Font("Times New Roman", 12, FontStyle.Bold);
        e.Graphics.DrawString("Days:", fntString,
                              Brushes.Black, 550, 650);
        fntString = new Font("Times New Roman", 12, FontStyle.Regular);
        e.Graphics.DrawString(txtDays.Text, fntString,
                                      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));
    
        fntString = new Font("Times New Roman", 12, FontStyle.Bold);
        e.Graphics.DrawString("Order Evaluation", fntString,
                              Brushes.White, 100, 700);
    
        StringFormat fmtString = new StringFormat();
        fmtString.Alignment = StringAlignment.Far;
    
        fntString = new Font("Times New Roman", 12, FontStyle.Bold);
        e.Graphics.DrawString("Rate Applied:", fntString,
                              Brushes.Black, 100, 740);
        fntString = new Font("Times New Roman", 12, FontStyle.Regular);
        e.Graphics.DrawString(txtRateApplied.Text, fntString,
                              Brushes.Black, 300, 740, fmtString);
        e.Graphics.DrawLine(new Pen(Color.Black, 1),
    			100, 760, 380, 760);
    
        fntString = new Font("Times New Roman", 12, FontStyle.Bold);
        e.Graphics.DrawString("Tax Rate:", fntString,
                              Brushes.Black, 420, 740);
        fntString = new Font("Times New Roman", 12, FontStyle.Regular);
        e.Graphics.DrawString(txtTaxRate.Text, fntString,
                              Brushes.Black, 640, 740, fmtString);
        e.Graphics.DrawString("%", fntString,
                              Brushes.Black, 640, 740);
        e.Graphics.DrawLine(new Pen(Color.Black, 1),
    			420, 760, 720, 760);
    
        fntString = new Font("Times New Roman", 12, FontStyle.Bold);
        e.Graphics.DrawString("Sub-Total:", fntString,
                              Brushes.Black, 100, 770);
        fntString = new Font("Times New Roman", 12, FontStyle.Regular);
        e.Graphics.DrawString(txtSubTotal.Text, fntString,
                              Brushes.Black, 300, 770, fmtString);
        e.Graphics.DrawLine(new Pen(Color.Black, 1),
    			100, 790, 380, 790);
    
        fntString = new Font("Times New Roman", 12, FontStyle.Bold);
        e.Graphics.DrawString("Tax Amount:", fntString,
                                      Brushes.Black, 420, 770);
        fntString = new Font("Times New Roman", 12, FontStyle.Regular);
        e.Graphics.DrawString(txtTaxAmount.Text, fntString,
                              Brushes.Black, 640, 770, fmtString);
        e.Graphics.DrawLine(new Pen(Color.Black, 1),
    			420, 790, 720, 790);
    
        fntString = new Font("Times New Roman", 12, FontStyle.Bold);
        e.Graphics.DrawString("Order Total:", fntString,
                                      Brushes.Black, 420, 800);
        fntString = new Font("Times New Roman", 12, FontStyle.Regular);
        e.Graphics.DrawString(txtOrderTotal.Text, fntString,
                              Brushes.Black, 640, 800, fmtString);
        e.Graphics.DrawLine(new Pen(Color.Black, 1),
    			420, 820, 720, 820);
    }
  4. Return to the Order Processing form
  5. From the Printing section of the Toolbox, click PrintDialog and click the form
  6. In the Properties window, change its Name to dlgPrint
  7. Still in the Properties windows, set its Document property to docPrint
  8. On the Order Processing form, double-click the Print button and implement its event as follows:
    private void btnPrint_Click(object sender, EventArgs e)
    {
        if (dlgPrint.ShowDialog() == DialogResult.OK)
            docPrint.Print();
    }
  9. Return to the Order Processing form
  10. From the Printing section of the Toolbox, click PrintPreviewDialog and click the form
  11. In the Properties window, change its (Name) to dlgPrintPreview
  12. Still in the Properties windows, set its Document property to docPrint
  13. On the Order Processing form, double-click the Print Preview button
  14. Implement the event as follows:
    private void btnPrintPreview_Click(object sender, EventArgs e)
    {
        dlgPrintPreview.ShowDialog();
    }
  15. Return to the Order Processing form
  16. Double-click the Open button
  17. Implement its event as follows:
    private void btnOpen_Click(object sender, EventArgs e)
    {
        RentalOrder order = null;
    
        if (txtReceiptNumber.Text == "")
        {
            MessageBox.Show("You must enter a receipt number");
            return;
        }
    
        ReceiptNumber = int.Parse(txtReceiptNumber.Text);
    
        if (ListOfRentalOrders.TryGetValue(ReceiptNumber, out order))
        {
            txtEmployeeNumber.Text = order.EmployeeNumber;
            txtEmployeeNumber_Leave(sender, e);
            cbxOrderStatus.Text = order.OrderStatus;
            txtTagNumber.Text = order.CarTagNumber;
            txtTagNumber_Leave(sender, e);
            txtDrvLicNumber.Text = order.CustomerDrvLicNbr;
            txtCustomerName.Text = order.CustomerName;
            txtCustomerAddress.Text = order.CustomerAddress;
            txtCustomerCity.Text = order.CustomerCity;
            cbxCustomerStates.Text = order.CustomerState;
            txtCustomerZIPCode.Text = order.CustomerZIPCode;
            cbxCarConditions.Text = order.CarCondition;
            cbxTankLevels.Text = order.TankLevel;
            txtMileageStart.Text = order.MileageStart.ToString();
            txtMileageEnd.Text = order.MileageEnd.ToString();
            dtpStartDate.Value = order.DateStart;
            dtpEndDate.Value = order.DateEnd;
            txtDays.Text = order.Days.ToString();
            txtRateApplied.Text = order.RateApplied.ToString("F");
            txtSubTotal.Text = order.SubTotal.ToString("F");
            txtTaxRate.Text = order.TaxRate.ToString("F");
            txtTaxAmount.Text = order.TaxAmount.ToString("F");
            txtOrderTotal.Text = order.OrderTotal.ToString("F");
        }
        else
        {
            MessageBox.Show("There is no rental order with that receipt number");
            return;
        }
    }
  18. Return to the Order Processing form
  19. Double-click the New Rental Order/Reset button
  20. Implement the event as follows:
    private void btnNewRentalOrder_Click(object sender, EventArgs e)
    {
        txtEmployeeNumber.Text = "";
        txtEmployeeName.Text = "";
        txtDrvLicNumber.Text = "";
        txtCustomerName.Text = "";
        txtCustomerAddress.Text = "";
        txtCustomerCity.Text = "";
        cbxCustomerStates.Text = "";
        txtCustomerZIPCode.Text = "";
        txtTagNumber.Text = "";
        cbxCarConditions.Text = "";
        txtMake.Text = "";
        txtModel.Text = "";
        txtCarYear.Text = "";
        cbxTankLevels.Text = "Empty";
        txtMileageStart.Text = "0";
        txtMileageEnd.Text = "0";
        dtpStartDate.Value = DateTime.Today;
        dtpEndDate.Value = DateTime.Today;
        txtDays.Text = "";
        cbxOrderStatus.Text = "";
        txtRateApplied.Text = "0.00";
        txtSubTotal.Text = "0.00";
        txtTaxRate.Text = "7.75";
        txtTaxAmount.Text = "0.00";
        txtOrderTotal.Text = "0.00";
    
        BinaryFormatter bfmRentalOrders = new BinaryFormatter();
    
        string strFilename = 
        		@"\\EXPRESSION\Bethesda Car Rental\RentalOrders.cro";
    
        if (File.Exists(strFilename))
        {
            FileStream stmRentalOrders = new FileStream(strFilename,
                                                        FileMode.Open,
                                                        FileAccess.Read,
                                                        FileShare.Read);
    
            try
            {
                ListOfRentalOrders = (Dictionary<int, 
                	RentalOrder>)bfmRentalOrders.Deserialize(stmRentalOrders);
                foreach (KeyValuePair<int, 
                		RentalOrder> order in ListOfRentalOrders)
                    ReceiptNumber = order.Key + 1;
            }
            finally
            {
                stmRentalOrders.Close();
            }
        }
        else
        {
            ReceiptNumber = 100001;
            ListOfRentalOrders = new Dictionary<int, RentalOrder>();
        }
    
        txtReceiptNumber.Text = ReceiptNumber.ToString();
    }
  21. Return to the Order Processing form
  22. Double-click an unoccupied area of its body
  23. Implement the Load event as follows:
    private void OrderProcessing_Load(object sender, EventArgs e)
    {
        btnNewRentalOrder_Click(sender, e);
    }
  24. Return to the Order Processing form
  25. Double-click the Close button and implement its event as follows:
    private void btnClose_Click(object sender, EventArgs e)
    {
        Close();
    }
  26. To save the project, on the Standard toolbar, click the Save All button
 
 
   
 

Previous Copyright © 2010-2016, FunctionX Next