Home

Collection-Based Example Application: The Ceil Inn Hotel Management

     

Introduction

The .NET Framework provides two abstract classes named Collection and KeyedCollection. They are defined in the System.Collections.ObjectModel namespace. The System.Collections.ObjectModel.Collection class can be used to derive a class and create a custom collection.

To explore the System.Collections.ObjectModel.Collection class, we are going to create an application used to manage transaction for a hotel.

ApplicationTopic Applied: Introducing the Collection Class

  1. Start Microsoft Visual C#
  2. To create a new application, on the main menu, click FILE -> New Project
  3. In the middle list, click Windows Forms Application
  4. Change the Name to CeilInn1
  5. Click OK
  6. To create a new class, on the main menu, click PROJECT -> Add Class...
  7. Set the Name to Customer
  8. Click Add
  9. Change the file as follows:
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    
    namespace CeilInn1
    {
        [Serializable]
        public class Customer
        {
            public string AccountNumber  { get; set; }
            public string FirstName      { get; set; }
    	public string LastName       { get; set; }
            public string PhoneNumber    { get; set; }
            public string EmergencyName  { get; set; }
            public string EmergencyPhone { get; set; }
    
            public override bool Equals(object obj)
            {
                Customer client = (Customer)obj;
    
                if (client.AccountNumber.Equals(this.AccountNumber))
                    return true;
                else
                    return false;
            }
    
            public override int GetHashCode()
            {
                return base.GetHashCode();
            }
        }
    }
  10. To create a new form, on the main menu, click PROJECT -> Add Windows Form...
  11. Set the name to CustomerEditor
  12. Click Add
  13. Design the form as follows:
     
    Ceil Inn - Customer Editor
    Control (Name) Text Modifiers Other Properties
    Label Label   Account Number:    
    TextBox Text Box txtAccountNumber   Public  
    Label Label   First Name:    
    TextBox Text Box txtFirstName   Public  
    Label Label   Last Name:    
    TextBox Text Box txtLastName   Public  
    Label Label   Phone Number:    
    TextBox Text Box txtPhoneNumber   Public  
    Label Label   Emergency Name:    
    TextBox Text Box txtEmergencyName   Public  
    Label Label   Emergency Phone:    
    TextBox Text Box txtEmergencyPhone   Public  
    Button btnOK OK   DialogResult: OK
    Button btnCancel Cancel   DialogResult: Cancel
    Form
    FormBorderStyle: FixedDialog
    Text: Ceil Inn - Customer Editor
    StartPosition: CenterScreen
    AcceptButton: btnOK
    CancelButton: btnCancel
    MaximizeBox: False
    MinimizeBox: False
    ShowInTaskBar: False
  14. To create a new class, on the main menu, click PROJECT -> Add Class...
  15. Set the Name to Employee
  16. Click Add
  17. Change the file as follows:
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    
    namespace CeilInn1
    {
        [Serializable]
        public class Employee
        {
            public string EmployeeNumber { get; set; }
            public string FirstName      { get; set; }
            public string LastName       { get; set; }
            public string Title          { get; set; }
    
            public override bool Equals(object obj)
            {
                Employee clerk = (Employee)obj;
    
                if( clerk.EmployeeNumber.Equals(this.EmployeeNumber))
                    return true;
                else
                    return false;
            }
    
            public override int GetHashCode()
            {
                return base.GetHashCode();
            }
        }
    }
  18. To create a new form, on the main menu, click PROJECT -> Add Windows Form...
  19. Set the name to EmployeeEditor
  20. Click Add
  21. Design the form as follows:
     
    Ceil Inn - Employee Editor
    Control (Name) Text Modifiers Other Properties
    Label Label   Employee Number:    
    TextBox Text Box txtEmployeeNumber   Public  
    Label Label   First Name:    
    TextBox Text Box txtFirstName   Public  
    Label Label   Last Name:    
    TextBox Text Box txtLastName   Public  
    Label Label   Title:    
    TextBox Text Box txtTitle   Public  
    Button btnOK OK   DialogResult: OK
    Button btnCancel Cancel   DialogResult: Cancel
    Form
    FormBorderStyle: FixedDialog
    Text: Ceil Inn - Employee Editor
    StartPosition: CenterScreen
    AcceptButton: btnOK
    CancelButton: btnCancel
    MaximizeBox: False
    MinimizeBox: False
    ShowInTaskBar: False
  22. To create a new class, on the main menu, click PROJECT -> Add Class...
  23. Set the Name to Room
  24. Click Add
  25. Change the file as follows:
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    
    namespace CeilInn1
    {
        [Serializable]
        public class Room
        {
            public string RoomNumber      { get; set; }
            public string RoomType        { get; set; }
            public string BedType         { get; set; }
            public double Rate            { get; set; }
    	public string OccupancyStatus { get; set; }
    
            public override bool Equals(object obj)
            {
                Room rm = (Room)obj;
    
                if (rm.RoomNumber == this.RoomNumber)
                    return true;
                else
                    return false;
            }
    
            public override int GetHashCode()
            {
                return base.GetHashCode();
            }
        }
    }
    
  26. To create a new form, on the main menu, click PROJECT -> Add Windows Form...
  27. Set the name to RoomEditor
  28. Click Add
  29. Design the form as follows:
     
    Ceil Inn - Room Editor
    Control (Name) Text Modifiers Other Properties
    Label Label   Room Number:    
    TextBox Text Box txtRoomNumber      
    Label Label   Room Type:    
    ComboBox ComboBox cbxRoomTypes   Public DroptStyle: DropDownList
    Items:
    Bedroom
    Conference Room
    Other
    Label Label   Bed Type:    
    ComboBox ComboBox cbxBedTypes   Public DroptStyle: DropDownList
    Items:
    King
    Queen
    Double
    Other
    Label Label   Rate:    
    TextBox Text Box txtRate 0.00 Public TextAlign: Right
    Label Label   Status:    
    CheckBox Check Box cbxOccupanciesStatus   Public DroptStyle: DropDownList
    Items
    Other
    Available
    Occupied
    Button btnOK OK   DialogResult: OK
    Button btnCancel Cancel   DialogResult: Cancel
    Form
    FormBorderStyle: FixedDialog
    Text: Ceil Inn - Employee Editor
    StartPosition: CenterScreen
    AcceptButton: btnOK
    CancelButton: btnCancel
    MaximizeBox: False
    MinimizeBox: False
    ShowInTaskBar: False
  30. To create a new class, on the main menu, click PROJECT -> Add Class...
  31. Set the Name to Occupancy
  32. Click Add
  33. Change the file as follows:
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    
    namespace CeilInn2
    {
        [Serializable]
        public class Occupancy
        {
            public string OccupancyNumber { get; set; }
            public DateTime DateOccupied  { get; set; }
            public string ProcessedBy     { get; set; }
            public string ProcessedFor    { get; set; }
            public string RoomOccupied    { get; set; }
            public double RateApplied     { get; set; }
            public double PhoneUse        { get; set; }
    
            public override bool Equals(object obj)
            {
                Occupancy rental = (Occupancy)obj;
    
                if( rental.OccupancyNumber == this.OccupancyNumber)
                    return true;
                else
                    return false;
            }
    
            public override int GetHashCode()
            {
                return base.GetHashCode();
            }
        }
    }
  34. To create a new form, on the main menu, click PROJECT -> Add Windows Form...
  35. Set the name to OccupancyEditor
  36. Click Add
  37. Design the form as follows:
     
    Ceil Inn - Occupancy Editor
    Control (Name) Text Modifiers Other Properties
    Label Label   Date Occupied:    
    DateTimePicker DateTimePicker dtpDateOccupied   Public  
    Label Label   Processed by ____    
    Label Label   Employee #:    
    TextBox Text Box txtEmployeNumber   Public  
    TextBox Text Box txtEmployeNme   Public  
    Label Label   Processed for ___    
    Label Label   Customer #:    
    TextBox Text Box txtCustomerNumber   Public  
    TextBox Text Box txtCustomerName   Public  
    Label Label   Room Rented ____    
    Label Label   Room Number:    
    TextBox Text Box txtRoomNumber   Public  
    TextBox Text Box txtRoomDescription   Public  
    Label Label   Rate Applied:    
    TextBox Text Box txtRateApplied 0.00 Public TextAlign: Right
    Label Label   Phone Use:    
    TextBox Text Box txtPhoneUse 0.00 Public TextAlign: Right
    Label Label   _______________    
    Label Label   Occupany #:    
    MaskTextBox Mask Text Box txtOccupanyNumber     Mask: 000-000-0000
    Button btnOK OK   DialogResult: OK
    Button btnCancel Cancel   DialogResult: Cancel
    Form
    FormBorderStyle: FixedDialog
    Text: Ceil Inn - Employee Editor
    StartPosition: CenterScreen
    AcceptButton: btnOK
    CancelButton: btnCancel
    MaximizeBox: False
    MinimizeBox: False
    ShowInTaskBar: False
  38. To create a new class, on the main menu, click PROJECT -> Add Class...
  39. Set the Name to Payment
  40. Click Add
  41. Change the file as follows:
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    
    namespace CeilInn1
    {
        [Serializable]
        public class Payment
        {
            public int      ReceiptNumber    { get; set; }
            public string   EmployeeNumber   { get; set; }
            public DateTime PaymentDate      { get; set; }
           	public string   AccountNumber    { get; set; }
            public DateTime	FirstDayOccupied { get; set; }
            public DateTime	LastDayOccupied  { get; set; }
           	public int      TotalNights      { get; set; }
            public double	AmountCharged    { get; set; }
            public double	SubTotal         { get; set; }
            public double	TaxRate          { get; set; }
            public double	TaxAmount        { get; set; }
            public double   TotalAmountPaid  { get; set; }
        }
    }
  42. To create a new form, on the main menu, click PROJECT -> Add Windows Form...
  43. Set the name to PaymentEditor
  44. Click Add
  45. Design the form as follows:
     
    Ceil Inn - Payment Editor
    Control (Name) Text Modifiers Other Properties
    Label Label   Payment Date:    
    DateTimePicker DateTimePicker dtpPaymentDate   Public  
    Label Label   Payment Processed by ____    
    Label Label   Employee #:    
    TextBox Text Box txtEmployeNumber   Public  
    TextBox Text Box txtEmployeNme      
    Label Label   Processed for Customer ___    
    Label Label   Occupancy #:    
    TextBox Text Box txtOccupancyNumber   Public  
    TextBox Text Box txtOccupancyDetails      
    Label Label   Room Occupied From:    
    DateTimePicker DateTimePicker dtpFirstDateOccupied   Public  
    Label Label   To:    
    DateTimePicker DateTimePicker dtpLastDateOccupied   Public  
    Label Label   Total Nights:    
    TextBox Text Box txtTotalNights 1 Public TextAlign: Right
    Label Label   Payment___    
    Label Label   Phone Use:    
    TextBox Text Box txtPhoneUse 0.00 Public TextAlign: Right
    Label Label   Amt Charged:    
    TextBox Text Box txtAmountCharged 0.00 Public TextAlign: Right
    Label Label   /night    
    Label Label   Sub-Total:    
    TextBox Text Box txtSubTotal 0.00 Public TextAlign: Right
    Button btnCalculate Calculate    
    Label Label   Tax Rate:    
    TextBox Text Box txtTaxRate 7.70 Public TextAlign: Right
    Label Label   %    
    Label Label   Tax Amount:    
    TextBox Text Box txtTaxAmount 0.00 Public TextAlign: Right
    Label Label   Amount Paid:    
    TextBox Text Box txtTotalAmountPaid 0.00 Public TextAlign: Right
    Label Label   _______________    
    Label Label   Receipt #:    
    TextBox Text Box txtReceiptNumber      
    Button btnOK OK   DialogResult: OK
    Button btnCancel Cancel   DialogResult: Cancel
    Form
    FormBorderStyle: FixedDialog
    Text: Ceil Inn - Payment Editor
    StartPosition: CenterScreen
    AcceptButton: btnOK
    CancelButton: btnCancel
    MaximizeBox: False
    MinimizeBox: False
    ShowInTaskBar: False
  46. Double-click the Calculate button and implement the event as follows:
    private void btnCalculate_Click(object sender, EventArgs e)
    {
        // If there is no payment amount, don't do anything
        if (string.IsNullOrEmpty(txtAmountCharged.Text))
            return;
    
        txtSubTotal.Text = ((Convert.ToInt16(txtTotalNights.Text) * Convert.ToDouble(txtAmountCharged.Text)) + Convert.ToDouble(txtPhoneUse.Text)).ToString("F");
        txtTaxAmount.Text = (Convert.ToDouble(txtSubTotal.Text) * Convert.ToDouble(txtTaxRate.Text) / 100).ToString("F");
        txtAmountPaid.Text = (Convert.ToDouble(txtSubTotal.Text) + Convert.ToDouble(txtTaxAmount.Text)).ToString("F");
    }
  47. Save all
 
 
 

Starting a Collection Class

The Collection<> class starts as follows:

public class Collection<T> : IList<T>, 
    			     ICollection<T>,
    			     IEnumerable<T>,
    			     IList, ICollection,
    			     IEnumerable

The Collection<> class is used to create a custom collection class that impliments some needed behaviors. At a minimum, you can simply derive your class from it. If you do, the Collection<> class provides some primary functionality such as the ability to add an object to the collection. It also provides the ability to get the number of objects in the collection, to check whether the collection contains a certain object, or to delete an object.

ApplicationTopic Applied: Using a Collection Class

  1. To create a new form, in the Solution Explorer, right-click CeilInn1 -> Add -> Windows Form...
  2. Set the name to Customers
  3. Click Add
  4. In the Toolbox, click ListView and click the form
  5. Right-click it and click Edit Columns
  6. Create the columns as follows:
     
    (Name) Text Width
    colAccountNumber Account # 70
    colFirstName First Name 65
    colLastName Last Name 65
    colPhoneNumber Phone # 80
    colEmergencyName Emergency Name 100
    colEmergencyPhone Emergency Phone 100
  7. Click OK
  8. Design the form as follows:
     
    Ceil Inn - Customers Records
    Control (Name) Text Other Properties
    ListView List View lvwCustomers   FullRowSelect: True
    GridLines: True
    View: Details
    Button btnNewCustomer New Customer...  
    Button btnClose Close  
  9. Double-click an unoccupied area of the form and 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.Collections.ObjectModel;
    using System.Runtime.Serialization.Formatters.Binary;
    
    namespace CeilInn1
    {
        public partial class Customers : Form
        {
            public Customers()
            {
                InitializeComponent();
            }
    
            private void ShowCustomers()
            {
                BinaryFormatter bfCustomers = new BinaryFormatter();
                Collection<Customer> lstCustomers = new Collection<Customer>();
                string strFileName = @"C:\Microsoft Visual C# Application Design\Ceil Inn\Customers.cst";
    
                // Make sure the file exists
                if (File.Exists(strFileName) == true)
                {
                    // if so, create a file stream
                    using( FileStream fsCustomers = new FileStream(strFileName,
                                                                   FileMode.Open,
                                                                   FileAccess.Read))
                    {
                        // If some customers records were created already,
                        // get them and store them in the collection
                        lstCustomers = (Collection<Customer>)bfCustomers.Deserialize(fsCustomers);
    
                        // First, empty the list view
                        lvwCustomers.Items.Clear();
    
                        // Visit each customer in the collection and add it to the list view
                        foreach (Customer client in lstCustomers)
                        {
                            ListViewItem lviCustomer = new ListViewItem(client.AccountNumber);
    
                            lviCustomer.SubItems.Add(client.FirstName);
                            lviCustomer.SubItems.Add(client.LastName);
                            lviCustomer.SubItems.Add(client.PhoneNumber);
                            lviCustomer.SubItems.Add(client.EmergencyName);
                            lviCustomer.SubItems.Add(client.EmergencyPhone);
    
                            lvwCustomers.Items.Add(lviCustomer);
                        }
                    }
                }
            }
    
            private void Customers_Load(object sender, EventArgs e)
            {
                ShowCustomers();
            }
        }
    }
  10. Return to the Customers form and double-click the New Customer button
  11. Implement its event as follows:
    private void btnNewCustomer_Click(object sender, EventArgs e)
    {
        CustomerEditor editor = new CustomerEditor();
        BinaryFormatter bfCustomers = new BinaryFormatter();
        Collection<Customer> lstCustomers = new Collection<Customer>();
    
        // Get a reference to the file that holds the customers records
        string strFileName = @"C:\Microsoft Visual C# Application Design\Ceil Inn\Customers.cst";
    
        // First check if the file was previously created
        if (File.Exists(strFileName) == true)
        {
            // If the list of customers exists already,
            // get it and store it in a file stream
            using (FileStream fsCustomers = new FileStream(strFileName,
                                                    FileMode.Open,
                                                    FileAccess.Read))
            {
                // Store the list of customers in the collection
                lstCustomers = (Collection<Customer>)bfCustomers.Deserialize(fsCustomers);
            }  // Close the file stream
        }
    
        if (editor.ShowDialog() == DialogResult.OK)
        {
            Customer client = new Customer();
    
            client.AccountNumber = editor.txtAccountNumber.Text;
            client.FirstName = editor.txtFirstName.Text;
            client.LastName = editor.txtLastName.Text;
            client.PhoneNumber = editor.txtPhoneNumber.Text;
            client.EmergencyName = editor.txtEmergencyName.Text;
            client.EmergencyPhone = editor.txtEmergencyPhone.Text;
    
            // Add the customer in the collection
            lstCustomers.Add(client);
    
            // Create a file stream to hold the list of customers
            using (FileStream fsCustomers = new FileStream(strFileName,
                                                        FileMode.Create,
                                                        FileAccess.Write))
            {
                // Serialize the list of customers
                bfCustomers.Serialize(fsCustomers, lstCustomers);
            }
    
            // Show the list of properties
            ShowCustomers();
        }
    }
  12. Return to the Customers form and double-click the Close button
  13. Implement it as follows:
    private void btnClose_Click(object sender, EventArgs e)
    {
        Close();
    }
  14. To create a new form, on the main menu, click PROJECT -> Add Windows Form...
  15. Set the name to Employees
  16. Click Add
  17. Add a list view to the form and create the columns as follows:
     
    (Name) Text Width
    colEmployeeNumber Employee # 70
    colFirstName First Name 80
    colLastName Last Name 80
    colTitle Title 120
  18. Click OK
  19. Design the form as follows:
     
    Ceil Inn - Employees Records
    Control (Name) Text Other Properties
    ListView List View lvwEmployees   FullRowSelect: True
    GridLines: True
    View: Details
    Button btnNewEmployee New Employee...  
    Button btnClose Close  
  20. Double-click an unoccupied area of the form and 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.Collections.ObjectModel;
    using System.Runtime.Serialization.Formatters.Binary;
    
    namespace CeilInn1
    {
        public partial class Employees : Form
        {
            public Employees()
            {
                InitializeComponent();
            }
    
            private void ShowEmployees()
            {
                Collection<Employee> lstEmployees;
                BinaryFormatter bfEmployees = new BinaryFormatter();
                string strFileName = @"C:\Microsoft Visual C# Application Design\Ceil Inn\Employees.mpl";
    
                if (File.Exists(strFileName) == true)
                {
                    using (FileStream fsEmployees = new FileStream(strFileName,
                                                                   FileMode.Open,
                                                                   FileAccess.Read))
                    {
                        lstEmployees = (Collection<Employee>)bfEmployees.Deserialize(fsEmployees);
    
                        lvwEmployees.Items.Clear();
    
                        foreach (Employee clerk in lstEmployees)
                        {
                            ListViewItem lviEmployee = new ListViewItem(clerk.EmployeeNumber);
    
                            lviEmployee.SubItems.Add(clerk.FirstName);
                            lviEmployee.SubItems.Add(clerk.LastName);
                            lviEmployee.SubItems.Add(clerk.Title);
    
                            lvwCustomers.Items.Add(lviEmployee);
                        }
                    }
                }
            }
    
            private void Employees_Load(object sender, EventArgs e)
            {
                ShowEmployees();
            }
        }
    }
  21. Return to the Employees form and double-click the New Employee button
  22. Implement its event as follows:
    private void btnNewEmployee_Click(object sender, EventArgs e)
    {
        Collection<Employee> lstEmployees = new Collection<Employee>();
        EmployeeEditor editor = new EmployeeEditor();
        BinaryFormatter bfEmployees = new BinaryFormatter();
    
        string strFileName = @"C:\Microsoft Visual C# Application Design\Ceil Inn\Employees.mpl";
    
        if (File.Exists(strFileName) == true)
        {
            using (FileStream fsEmployees = new FileStream(strFileName,
                                                        FileMode.Open,
                                                        FileAccess.Read))
            {
                lstEmployees = (Collection<Employee>)bfEmployees.Deserialize(fsEmployees);
            }
        }
    
        if (editor.ShowDialog() == DialogResult.OK)
        {
            Employee clerk = new Employee();
    
            clerk.EmployeeNumber = editor.txtEmployeeNumber.Text;
            clerk.FirstName = editor.txtFirstName.Text;
            clerk.LastName = editor.txtLastName.Text;
            clerk.Title = editor.txtTitle.Text;
    
            lstEmployees.Add(clerk);
    
            using (FileStream fsEmployees = new FileStream(strFileName,
                                                        FileMode.Create,
                                                        FileAccess.Write))
            {
                bfEmployees.Serialize(fsEmployees, lstEmployees);
            }
    
            ShowEmployees();
        }
    }
  23. Return to the Employees form and double-click the Close button
  24. Implement it as follows:
    private void btnClose_Click(object sender, EventArgs e)
    {
        Close();
    }
  25. To create a new form, on the main menu, click PROJECT -> Add Windows Form...
  26. Set the name to Rooms
  27. Click Add
  28. Add a list view to the form and create the columns as follows:
     
    (Name) Text TextAlign Width
    colRoomNumber Room #    
    colRoomType Room Type   100
    colBedType Bed Type   80
    colRate Rate Right  
    colAvailable Available? Center 65
  29. Click OK
  30. Design the form as follows:
     
    Ceil Inn - Rooms Records
    Control (Name) Text Other Properties
    ListView List View lvwRooms   FullRowSelect: True
    GridLines: True
    View: Details
    Button btnNewRoom New Room...  
    Button btnClose Close  
  31. Double-click an unoccupied area of the form and 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.Collections.ObjectModel;
    using System.Runtime.Serialization.Formatters.Binary;
    
    namespace CeilInn1
    {
        public partial class Rooms : Form
        {
            public Rooms()
            {
                InitializeComponent();
            }
    
            private void ShowRooms()
            {
                BinaryFormatter bfRooms = new BinaryFormatter();
                Collection<Room> lstRooms = new Collection<Room>();
                string strFileName = @"C:\Microsoft Visual C# Application Design\Ceil Inn\Rooms.rms";
    
                if (File.Exists(strFileName) == true)
                {
                    using (FileStream fsRooms = new FileStream(strFileName,
                                                                   FileMode.Open,
                                                                   FileAccess.Read))
                    {
                        lstRooms = (Collection<Room>)bfRooms.Deserialize(fsRooms);
    
                        lvwRooms.Items.Clear();
    
                        foreach (Room rm in lstRooms)
                        {
                            ListViewItem lviRoom = new ListViewItem(rm.RoomNumber);
    
                            lviRoom.SubItems.Add(rm.RoomType);
                            lviRoom.SubItems.Add(rm.BedType);
                            lviRoom.SubItems.Add(rm.Rate.ToString("F"));
                            lviRoom.SubItems.Add(rm.OccupancyStatus);
    
                            lvwRooms.Items.Add(lviRoom);
                        }
                    }
                }
            }
    
            private void Rooms_Load(object sender, EventArgs e)
            {
                ShowRooms();
            }
        }
    }
  32. Return to the Rooms form and double-click the New Room button
  33. Implement its event as follows:
    private void btnNewRoom_Click(object sender, EventArgs e)
    {
        RoomEditor editor = new RoomEditor();
        BinaryFormatter bfRooms = new BinaryFormatter();
        Collection<Room> lstRooms = new Collection<Room>();
    
        string strFileName = @"C:\Microsoft Visual C# Application Design\Ceil Inn\Rooms.rms";
    
        if (File.Exists(strFileName) == true)
        {
            using (FileStream fsRooms = new FileStream(strFileName,
                                                    FileMode.Open,
                                                    FileAccess.Read))
            {
                // Store the list of customers in the collection
                lstRooms = (Collection<Room>)bfRooms.Deserialize(fsRooms);
            }  // Close the file stream
        }
    
        if (editor.ShowDialog() == DialogResult.OK)
        {
            Room rm = new Room();
    
            rm.RoomNumber = editor.txtRoomNumber.Text;
            rm.RoomType = editor.cbxRoomTypes.Text;
            rm.BedType = editor.cbxBedTypes.Text;
            rm.Rate = double.Parse(editor.txtRate.Text);
            rm.OccupancyStatus = editor.cbxOccupanciesStatus.Text;
    
            lstRooms.Add(rm);
    
            using (FileStream fsCustomers = new FileStream(strFileName,
                                                        FileMode.Create,
                                                        FileAccess.Write))
            {
                // Serialize the list of properties
                bfRooms.Serialize(fsCustomers, lstRooms);
            }
    
            // Show the list of properties
            ShowRooms();
        }
    }
  34. Return to the Room form and double-click the Close button
  35. Implement it as follows:
    private void btnClose_Click(object sender, EventArgs e)
    {
        Close();
    }
  36. Display the Occupany Editor dialog box and double-click an unoccupied area of its body
  37. 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.Collections.ObjectModel;
    using System.Runtime.Serialization.Formatters.Binary;
    
    namespace CeilInn1
    {
        public partial class OccupancyEditor : Form
        {
            public OccupancyEditor()
            {
                InitializeComponent();
            }
    
            private void OccupancyEditor_Load(object sender, EventArgs e)
            {
                int iOccupancyNumber = 100000;
                BinaryFormatter bfOccupancies = new BinaryFormatter();
                Collection<Occupancy> lstOccupancies = new Collection<Occupancy>();
                string strFileName = @"C:\Microsoft Visual C# Application Design\Ceil Inn\Occupancies.ocp";
    
                if (File.Exists(strFileName) == true)
                {
                    using (FileStream fsOccupancies = new FileStream(strFileName,
                                                             FileMode.Open,
                                                         FileAccess.Read))
                    {
    
                        lstOccupancies = (Collection<Occupancy>)bfOccupancies.Deserialize(fsOccupancies);
    
                        foreach (Occupancy order in lstOccupancies)
                        {
                            iOccupancyNumber = order.OccupancyNumber;
                        }
                    }
                }
    
                txtOccupancyNumber.Text = (iOccupancyNumber + 1).ToString();
            }
        }
    }
  38. Return to the Occupancy Editor and click the Employee # text box
  39. On the Properties window, click the Events button and double-click Leave
  40. Change the document as follows:
     private void txtEmployeeNumber_Leave(object sender, EventArgs e)
    {
        Collection<Employee> lstEmployees;
        BinaryFormatter bfEmployees = new BinaryFormatter();
        string strFileName = @"C:\Microsoft Visual C# Application Design\Ceil Inn\Employees.mpl";
    
        if (File.Exists(strFileName) == true)
        {
            using (FileStream fsEmployees = new FileStream(strFileName,
                                                           FileMode.Open,
                                                           FileAccess.Read))
            {
                lstEmployees = (Collection<Employee>)bfEmployees.Deserialize(fsEmployees);
    
                foreach (Employee empl in lstEmployees)
                {
                    if (empl.EmployeeNumber == txtEmployeeNumber.Text)
                        txtEmployeeName.Text = empl.LastName + ", " + empl.FirstName;
                }
            }
        }
    }
  41. Return to the Occupancy Editor dialog box and click the Customer # text box
  42. In the Events section of the Properties window, double-click Leave
  43. Implement the event as follows:
    private void txtAccountNumber_Leave(object sender, EventArgs e)
    {
        BinaryFormatter bfCustomers = new BinaryFormatter();
        Collection<Customer> lstCustomers = new Collection<Customer>();
        string strFileName = @"C:\Microsoft Visual C# Application Design\Ceil Inn\Customers.cst";
    
        if (File.Exists(strFileName) == true)
        {
            using (FileStream fsCustomers = new FileStream(strFileName,
                                                           FileMode.Open,
                                                           FileAccess.Read))
            {
                lstCustomers = (Collection<Customer>)bfCustomers.Deserialize(fsCustomers);
    
                foreach (Customer client in lstCustomers)
                {
                    if( client.AccountNumber == txtAccountNumber.Text )
                        txtCustomerName.Text = client.LastName + ", " + client.FirstName;
                }
            }
        }
    }
  44. Return to the Occupancy Editor dialog box and click the Room Number text box
  45. In the Events section of the Properties window, double-click Leave
  46. Implement the event as follows:
    private void txtRoomNumber_Leave(object sender, EventArgs e)
    {
        BinaryFormatter bfRooms = new BinaryFormatter();
        Collection<Room> lstRooms = new Collection<Room>();
        string strFileName = @"C:\Microsoft Visual C# Application Design\Ceil Inn\Rooms.rms";
    
        if (File.Exists(strFileName) == true)
        {
            using (FileStream fsRooms = new FileStream(strFileName,
                                                           FileMode.Open,
                                                           FileAccess.Read))
            {
                lstRooms = (Collection<Room>)bfRooms.Deserialize(fsRooms);
    
                foreach (Room rm in lstRooms)
                {
                    if (rm.RoomNumber == txtRoomNumber.Text)
                        txtRoomDescription.Text = "Room type: " + rm.RoomType +
                                                  ", Bed type: " + rm.BedType +
                                                  ", Rate = " + rm.Rate.ToString("F") + "/night";
                }
            }
        }
    }
  47. To create a new form, on the main menu, click PROJECT -> Add Windows Form...
  48. Set the name to Occupancies
  49. Click Add
  50. Add a list viiew to the form and create the columns as follows:
     
    (Name) Text TextAlign Width
    colOccupancyNumber Occupancy #   80
    colDateOccupied Date Occupied   150
    colProcessedBy Processed By   140
    colProcessedFor Processed For   140
    colRoomOccupied Room Occupied   180
    colRateApplied Rate Applied Right 80
    colPhoneUse Phone Use Right 65
  51. Click OK
  52. Design the form as follows:
     

    Ceil Inn - Rooms Occupancies

    Control (Name) Text Other Properties
    ListView List View lvwOccupancies   FullRowSelect: True
    GridLines: True
    View: Details
    Button btnNewOccupancy New Occupancy...  
    Button btnClose Close  
  53. Double-click an unoccupied area of the form and 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.Collections.ObjectModel;
    using System.Runtime.Serialization.Formatters.Binary;
    
    namespace CeilInn1
    {
        public partial class Occupancies : Form
        {
            public Occupancies()
            {
                InitializeComponent();
            }
    
            private void ShowOccupancies()
            {
                Collection<Employee> lstEmployees;
                BinaryFormatter bfRooms = new BinaryFormatter();
                Collection<Room> lstRooms = new Collection<Room>();
                BinaryFormatter bfEmployees = new BinaryFormatter();
                BinaryFormatter bfCustomers = new BinaryFormatter();
                BinaryFormatter bfOccupancies = new BinaryFormatter();
                string strEmployee = "", strCustomer = "", strRoom = "";
                Collection<Customer> lstCustomers = new Collection<Customer>();
                Collection<Occupancy> lstOccupancies = new Collection<Occupancy>();
                string strRoomsFile = @"C:\Microsoft Visual C# Application Design\Ceil Inn\Rooms.rms";
                string strCustomersFile = @"C:\Microsoft Visual C# Application Design\Ceil Inn\Customers.cst";
                string strEmployeesFile = @"C:\Microsoft Visual C# Application Design\Ceil Inn\Employees.mpl";
                string strOccupanciesFile = @"C:\Microsoft Visual C# Application Design\Ceil Inn\Occupancies.ocp";
    
                if (File.Exists(strOccupanciesFile) == true)
                {
                    using (FileStream fsOccupancies = new FileStream(strOccupanciesFile,
                                                             FileMode.Open,
                                                         FileAccess.Read))
                    {
                        lstOccupancies = (Collection<Occupancy>)bfOccupancies.Deserialize(fsOccupancies);
    
                        lvwOccupancies.Items.Clear();
    
                        foreach (Occupancy order in lstOccupancies)
                        {
                            ListViewItem lviOccupancy = new ListViewItem(order.OccupancyNumber.ToString());
    
                            lviOccupancy.SubItems.Add(order.DateOccupied.ToLongDateString());
                            using (FileStream fsEmployees = new FileStream(strEmployeesFile,
                                                                           FileMode.Open,
                                                                           FileAccess.Read))
                            {
                                lstEmployees = (Collection<Employee>)bfEmployees.Deserialize(fsEmployees);
                                
                                foreach (Employee clerk in lstEmployees)
                                {
                                    if(clerk.EmployeeNumber == order.ProcessedBy)
                                        strEmployee = clerk.EmployeeNumber + ": " +
                                                      clerk.FirstName + " " +
                                                      clerk.LastName;
                                }
                            }
    
                            lviOccupancy.SubItems.Add(strEmployee);
    
                            using (FileStream fsCustomers = new FileStream(strCustomersFile,
                                                                           FileMode.Open,
                                                                           FileAccess.Read))
                            {
                                lstCustomers = (Collection<Customer>)bfCustomers.Deserialize(fsCustomers);
                                
                                foreach (Customer client in lstCustomers)
                                {
                                    if( client.AccountNumber == order.ProcessedFor )
                                        strCustomer = client.AccountNumber + ": " +
                                                      client.FirstName + " " +
                                                      client.LastName;
                                }
                            }
    
                            lviOccupancy.SubItems.Add(strCustomer);
    
                            if (File.Exists(strRoomsFile) == true)
                            {
                                using (FileStream fsRooms = new FileStream(strRoomsFile,
                                                                               FileMode.Open,
                                                                               FileAccess.Read))
                                {
                                    lstRooms = (Collection<Room>)bfRooms.Deserialize(fsRooms);
    
                                    foreach (Room rm in lstRooms)
                                        if(rm.RoomNumber == order.RoomOccupied )
                                            strRoom = rm.RoomNumber + ": " +
                                                      rm.RoomType + ", " +
                                                      rm.BedType + ", " +
                                                      rm.Rate.ToString("F") + "/day";
                                }
                            }
                            lviOccupancy.SubItems.Add(strRoom);
                            lviOccupancy.SubItems.Add(order.RateApplied.ToString("F"));
                            lviOccupancy.SubItems.Add(order.PhoneUse.ToString("F"));
    
                            lvwOccupancies.Items.Add(lviOccupancy);
                        }
                    }
                }
            }
    
            private void Occupancies_Load(object sender, EventArgs e)
            {
                ShowOccupancies();
            }
        }
    }
  54. Return to the Occupancies form and double-click the New Occupancy button
  55. Implement its event as follows:
    private void btnNewOccupancy_Click(object sender, EventArgs e)
    {
        OccupancyEditor editor = new OccupancyEditor();
        BinaryFormatter bfmOccupancies = new BinaryFormatter();
        Collection<Occupancy> lstOccupancies = new Collection<Occupancy>();
    
        string strFileName = @"C:\Microsoft Visual C# Application Design\Ceil Inn\Occupancies.ocp";
    
        if (File.Exists(strFileName) == true)
        {
            using (FileStream fsOccupancies = new FileStream(strFileName,
                                                        FileMode.Open,
                                                        FileAccess.Read))
            {
                lstOccupancies = (Collection<Occupancy>)bfmOccupancies.Deserialize(fsOccupancies);
            }
        }
    
        if (editor.ShowDialog() == DialogResult.OK)
        {
            Occupancy occupy = new Occupancy();
    
            occupy.OccupancyNumber = editor.txtOccupancyNumber.Text;
            occupy.DateOccupied = editor.dtpDateOccupied.Value;
            occupy.ProcessedBy = editor.txtEmployeeNumber.Text;
            occupy.ProcessedFor = editor.txtAccountNumber.Text;
            occupy.RoomOccupied = editor.cbxRoomsNumbers.Text;
            occupy.RateApplied = double.Parse(editor.txtRateApplied.Text);
            occupy.PhoneUse = double.Parse(editor.txtPhoneUse.Text);
    
            lstOccupancies.Add(occupy);
    
            using (FileStream fsOccupancies = new FileStream(strFileName,
                                                        FileMode.Create,
                                                        FileAccess.Write))
            {
                bfmOccupancies.Serialize(fsOccupancies, lstOccupancies);
            }
        }
        
        ShowOccupancies();
    }
  56. Return to the form and double-click the Close button
  57. Implement it as follows:
    private void btnClose_Click(object sender, EventArgs e)
    {
        Close();
    }
  58. Display the Payment Editor dialog box and double-click an unoccupied area of its body
  59. 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.Collections.ObjectModel;
    using System.Runtime.Serialization.Formatters.Binary;
    
    namespace CeilInn1
    {
        public partial class PaymentEditor : Form
        {
            public PaymentEditor()
            {
                InitializeComponent();
            }
    
            private void btnCalculate_Click(object sender, EventArgs e)
            {
                // If there is no payment amount, don't do anything
                if (string.IsNullOrEmpty(txtAmountCharged.Text))
                    return;
    
                txtSubTotal.Text = (Convert.ToInt16(txtTotalNights.Text) * Convert.ToDouble(txtAmountCharged.Text)).ToString("F");
                txtTaxAmount.Text = (Convert.ToDouble(txtSubTotal.Text) * Convert.ToDouble(txtTaxRate.Text) / 100).ToString("F");
                txtAmountPaid.Text = (Convert.ToDouble(txtSubTotal.Text) + Convert.ToDouble(txtTaxAmount.Text)).ToString("F");
            }
    
            private void PaymentEditor_Load(object sender, EventArgs e)
            {
                int iReceiptNumber = 1000;
                BinaryFormatter bfPayments = new BinaryFormatter();
                Collection<Payment> lstPaymentes = new Collection<Payment>();
                string strFileName = @"C:\Microsoft Visual C# Application Design\Ceil Inn\Payments.pmt";
    
                if (File.Exists(strFileName) == true)
                {
                    using (FileStream fsPayments = new FileStream(strFileName,
                                                             FileMode.Open,
                                                         FileAccess.Read))
                    {
    
                        lstPaymentes = (Collection<Payment>)bfPayments.Deserialize(fsPayments);
    
                        foreach (Payment pmt in lstPaymentes)
                        {
                            iReceiptNumber = pmt.ReceiptNumber;
                        }
                    }
                }
    
                txtReceiptNumber.Text = (iReceiptNumber + 1).ToString();
            }
        }
    }
  60. Return to the Payment Editor and click the Employee # text box
  61. On the Properties window, click the Events button and double-click Leave
  62. Change the document as follows:
    private void txtEmployeeNumber_Leave(object sender, EventArgs e)
    {
        Collection<Employee> lstEmployees;
        BinaryFormatter bfEmployees = new BinaryFormatter();
        string strFileName = @"C:\Microsoft Visual C# Application Design\Ceil Inn\Employees.mpl";
    
        if (File.Exists(strFileName) == true)
        {
            using (FileStream fsEmployees = new FileStream(strFileName,
                                                           FileMode.Open,
                                                           FileAccess.Read))
            {
                lstEmployees = (Collection<Employee>)bfEmployees.Deserialize(fsEmployees);
    
                foreach (Employee empl in lstEmployees)
                {
                    if (empl.EmployeeNumber == txtEmployeeNumber.Text)
                        txtEmployeeName.Text = empl.LastName + ", " + empl.FirstName;
                }
            }
        }
    }
  63. Return to the Payment Editor dialog box and click the Account # text box
  64. In the Events section of the Properties window, double-click Leave
  65. Implement the event as follows:
    private void txtAccountNumber_Leave(object sender, EventArgs e)
    {
        BinaryFormatter bfCustomers = new BinaryFormatter();
        Collection<Customer> lstCustomers = new Collection<Customer>();
        string strFileName = @"C:\Microsoft Visual C# Application Design\Ceil Inn\Customers.cst";
    
        if (File.Exists(strFileName) == true)
        {
            using (FileStream fsCustomers = new FileStream(strFileName,
                                                           FileMode.Open,
                                                           FileAccess.Read))
            {
                lstCustomers = (Collection<Customer>)bfCustomers.Deserialize(fsCustomers);
    
                foreach (Customer client in lstCustomers)
                {
                    if( client.AccountNumber == txtAccountNumber.Text )
                        txtAccountDetails.Text = client.LastName + ", " + client.FirstName;
                }
            }
        }
    }
  66. To create a new form, on the main menu, click PROJECT -> Add Windows Form...
  67. Set the name to Payments
  68. Click Add
  69. Add a list viiew to the form and create the columns as follows:
     
    (Name) Text TextAlign Width
    colReceiptNumber Receipt #    
    colProcessedBy Processed By   140
    colPaymentDate Payment Date   130
    colAccountNumber Processed For   140
    colFirstDayOccupied First Day Occupied   140
    colLastDayOccupied Last Day Occupied   140
    colTotalNights Total Nights Right 70
    colAmountCharged Amt Charged Right 75
    colPhoneUse Phone Use Right 65
    colSubTotal Sub-Total Right  
    colTaxRate Tax Rate Right  
    colTaxAmount Tax Amt Right 55
    colTotalAmountPaid Amt Paid Right  
  70. Click OK
  71. Design the form as follows:
     

    Ceil Inn - Payments

    Control (Name) Text Other Properties
    ListView List View lvwPayments   FullRowSelect: True
    GridLines: True
    View: Details
    Button btnNewPayment New Payment...  
    Button btnClose Close  
  72. Double-click an unoccupied area of the form and 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.Collections.ObjectModel;
    using System.Runtime.Serialization.Formatters.Binary;
    
    namespace CeilInn1
    {
        public partial class Payments : Form
        {
            public Payments()
            {
                InitializeComponent();
            }
    
            private void ShowPayments()
            {
                Collection<Employee> employees;
                PaymentEditor editor = new PaymentEditor();
                BinaryFormatter bfPayments = new BinaryFormatter();
                BinaryFormatter bfEmployees = new BinaryFormatter();
                BinaryFormatter bfCustomers = new BinaryFormatter();
                string strEmployee = "", strCustomer = "";
                Collection<Payment> payments = new Collection<Payment>();
                Collection<Customer> customers = new Collection<Customer>();
                string strPaymentsFile = @"C:\Microsoft Visual C# Application Design\Ceil Inn\Payments.pmt";
                string strCustomersFile = @"C:\Microsoft Visual C# Application Design\Ceil Inn\Customers.cst";
                string strEmployeesFile = @"C:\Microsoft Visual C# Application Design\Ceil Inn\Employees.mpl";
    
                if (File.Exists(strPaymentsFile) == true)
                {
                    using (FileStream fsPayments = new FileStream(strPaymentsFile,
                                                                  FileMode.Open,
                                                                  FileAccess.Read))
                    {
                        payments = (Collection<Payment>)bfPayments.Deserialize(fsPayments);
    
                        lvwPayments.Items.Clear();
    
                        foreach (Payment pmt in payments)
                        {
                            ListViewItem lviPayment = new ListViewItem(pmt.ReceiptNumber.ToString());
    
                            using (FileStream fsEmployees = new FileStream(strEmployeesFile,
                                                                           FileMode.Open,
                                                                           FileAccess.Read))
                            {
                                employees = (Collection<Employee>)bfEmployees.Deserialize(fsEmployees);
    
                                foreach (Employee clerk in employees)
                                {
                                    if (clerk.EmployeeNumber == pmt.EmployeeNumber)
                                        strEmployee = clerk.EmployeeNumber + ": " +
                                                      clerk.FirstName + " " +
                                                      clerk.LastName;
                                }
                            }
    
                            lviPayment.SubItems.Add(strEmployee);
    
                            lviPayment.SubItems.Add(pmt.PaymentDate.ToLongDateString());
    
                            using (FileStream fsCustomers = new FileStream(strCustomersFile,
                                                                           FileMode.Open,
                                                                           FileAccess.Read))
                            {
                                customers = (Collection<Customer>)bfCustomers.Deserialize(fsCustomers);
    
                                foreach (Customer client in customers)
                                {
                                    if (client.AccountNumber == pmt.AccountNumber)
                                        strCustomer = client.AccountNumber + ": " +
                                                      client.FirstName + " " +
                                                      client.LastName;
                                }
                            }
    
                            lviPayment.SubItems.Add(strCustomer);
                            lviPayment.SubItems.Add(pmt.FirstDayOccupied.ToLongDateString());
                            lviPayment.SubItems.Add(pmt.LastDayOccupied.ToLongDateString());
                            lviPayment.SubItems.Add(pmt.TotalNights.ToString());
                            lviPayment.SubItems.Add(pmt.AmountCharged.ToString("F"));
                            lviPayment.SubItems.Add(pmt.PhoneUse.ToString("F"));
                            lviPayment.SubItems.Add(pmt.SubTotal.ToString("F"));
                            lviPayment.SubItems.Add((pmt.TaxRate / 100).ToString("P"));
                            lviPayment.SubItems.Add(pmt.TaxAmount.ToString("F"));
                            lviPayment.SubItems.Add(pmt.TotalAmountPaid.ToString("F"));
                            lvwPayments.Items.Add(lviPayment);
                        }
                    }
                }
            }
    
            private void Payments_Load(object sender, EventArgs e)
            {
                ShowPayments();
            }
        }
    }
  73. Return to the form and double-click the New Payment button
  74. Implement its event as follows:
    private void btnNewPayment_Click(object sender, EventArgs e)
    {
        PaymentEditor editor = new PaymentEditor();
        BinaryFormatter bfPayments = new BinaryFormatter();
        Collection<Payment> payments = new Collection<Payment>();
        string strPaymentsFile = @"C:\Microsoft Visual C# Application Design\Ceil Inn\Payments.pmt";
    
        if (editor.ShowDialog() == System.Windows.Forms.DialogResult.OK)
        {
            if (File.Exists(strPaymentsFile) == true)
            {
                using (FileStream fsPayments = new FileStream(strPaymentsFile,
                                                                FileMode.Open,
                                                                FileAccess.Read))
                {
                    payments = (Collection<Payment>)bfPayments.Deserialize(fsPayments);
                }
            }
                     
            Payment pmt = new Payment();
                    
            pmt.ReceiptNumber = int.Parse(editor.txtReceiptNumber.Text);
            pmt.EmployeeNumber = editor.txtEmployeeNumber.Text;
            pmt.PaymentDate = editor.dtpPaymentDate.Value;
            pmt.AccountNumber = editor.txtAccountNumber.Text;
            pmt.FirstDayOccupied = editor.dtpFirstDateOccupied.Value;
            pmt.LastDayOccupied  = editor.dtpLastDateOccupied.Value;
            pmt.TotalNights = int.Parse(editor.txtTotalNights.Text);
            pmt.AmountCharged = double.Parse(editor.txtAmountCharged.Text);
            pmt.PhoneUse  = double.Parse(editor.txtPhoneUse.Text);
            pmt.SubTotal = double.Parse(editor.txtSubTotal.Text);
            pmt.TaxRate = double.Parse(editor.txtTaxRate.Text);
            pmt.TaxAmount  = double.Parse(editor.txtTaxAmount.Text);
            pmt.TotalAmountPaid = double.Parse(editor.txtTotalAmountPaid.Text);
                    
            payments.Add(pmt);
                    
            using (FileStream fsPayments = new FileStream(strPaymentsFile,
                                                            FileMode.Create,
                                                            FileAccess.Write))
            {
                bfPayments.Serialize(fsPayments, payments);
            }
        }
    
        ShowPayments();
    }
  75. Return to the form and double-click the Close button
  76. Implement it as follows:
    private void btnClose_Click(object sender, EventArgs e)
    {
        Close();
    }
  77. In the Solution Explorer, right-click Form1.cs and click Rename
  78. Type CeilInn.cs and press Enter twice to display the form
  79. Design the form as follows:
     
    Altair Realtors
    Control (Name) Text 
    Button btnCustomers Customers...
    Button btnOcupancies Occupancies...
    Button btnRooms Rooms...
    Button btnPayments Payments...
    Button btnEmployees Employees...
    Button btnClose  Close
  80. Double-click an unoccupied area of the body of the form
  81. 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 CeilInn2
    {
        public partial class CeilInn : Form
        {
            public CeilInn()
            {
                InitializeComponent();
            }
    
            private void CeilInn_Load(object sender, EventArgs e)
            {
                Directory.CreateDirectory(@"C:\Microsoft Visual C# Application Design\Ceil Inn");
            }
        }
    }
  82. Return to the Ceil Inn form and double-click the Customers button
  83. Implement its event as follows:
    private void btnCustomers_Click(object sender, EventArgs e)
    {
        Customers clients = new Customers();
        clients.ShowDialog();
    }
  84. Return to the Ceil Inn fform and double-click the Occupancies button
  85. Implement the event as follows:
    private void btnOccupancies_Click(object sender, EventArgs e)
    {
        Occupancies rentals = new Occupancies();
        rentals.ShowDialog();
    }
  86. Return to the Ceil Inn fform and double-click the Rooms button
  87. Implement the event as follows:
    private void btnRooms_Click(object sender, EventArgs e)
    {
        Rooms rms = new Rooms();
        rms.ShowDialog();
    }
  88. Return to the Ceil Inn form and double-click the Payments button
  89. Implement its event as follows:
    private void btnPayments_Click(object sender, EventArgs e)
    {
        Payments pmts = new Payments();
        pmts.Show();
    }
  90. Return to the Ceil Inn form and double-click the Employees button
  91. Implement its event as follows:
    private void btnEmployees_Click(object sender, EventArgs e)
    {
        Employees staff = new Employees();
        staff.ShowDialog();
    }
  92. Return to the form and double-click the Close button
  93. Implement its event as follows:
    private void btnClose_Click(object sender, EventArgs e)
    {
        Close();
    }
  94. To execute, press Ctrl + F5
  95. Click the Customers button
  96. In the Customers form, click New Customer...
  97. Create each record as follows and click OK at then end of each:
     
    Account # First Name Last Name Phone # Emergency Name Emergency Phone
    100752 Caroline Lomey 301-652-0700 Albert Lomey 301-412-5055
    946090 Peter Carney 990-585-1886 Spencer Miles 990-750-8666
    474065 Peter Carney 990-585-1886 Spencer Miles 990-750-8666
    204795 Juliette Beckins 410-944-1440 Bernard Brodsky 410-385-2235
    208405 Peter Carney 990-585-1886 Spencer Miles 990-750-8666
    284085 Lucy Chen 425-979-7413 Edward Lamb 425-720-9247
    294209 Doris Wilson 703-416-0934 Gabriela Dawson 703-931-1000
    383084 Peter Carney 990-585-1886 Spencer Miles 990-750-8666
    902840 Daniel Peters 624-802-1686 Grace Peters 877-490-9333
    608502 Caroline Lomey 301-652-0700 Albert Lomey 301-412-5055
    180204 Randy Whittaker 703-631-1200 Bryan Rattner 703-506-9200
    629305 Joan Davids 202-789-0500 Rebecca Boiron 202-399-3600
    660820 Anne Sandt 953-172-9347 William Sandt 953-279-2475
    260482 Caroline Lomey 301-652-0700 Albert Lomey 301-412-5055
    608208 Alfred Owens 804-798-3257 Jane Owens 240-631-1445
    640800 Randy Whittaker 703-631-1200 Bryan Rattner 703-506-9200
  98. Close the Customers form
  99. Click the Employees button
  100. Click the New Employee button and create each new employee as follows (click OK after each):
      
    Employee # First Name Last Name Title
    22958 Andrew Laskin General Manager
    24095 Fred Barclay Accounts Associate
    27049 Harriett Dovecot Accounts Associate
    28405 Peggy Thompson Accounts Associate
    20429 Lynda Fore Shift Manager
    22947 Sheryl Shegger Intern
  101. Close the Employees form
  102. Click the Rooms button
  103. Continuously click New Room... and create the following records:
     
    Room # Room Type Bed Type Rate Room Status
    104 Bedroom Queen 75.85 Occupied
    105 Bedroom King 92.75 Available
    106 Bedroom Queen 75.85 Available
    107 Bedroom King 92.75 Occupied
    108 Bedroom Queen 75.85 Available
    110 Conference 450.00 Available
    112 Conference 650.00 Available
    114 Bedroom King 92.75 Available
    115 Bedroom King 92.75 Available
    116 Bedroom Queen 75.85 Available
    117 Bedroom Queen 75.85 Available
    118 Bedroom King 85.75 Available
    120 Studio King 98.95 Available
    122 Conference 725.00 Available
    125 Bedroom King 95.50 Available
    126 Studio King 98.95 Available
    127 Bedroom Double 79.90 Available
    202 Studio King 98.95 Other
    203 Studio Queen 94.50 Available
    204 Bedroom Double 96.60 Available
    205 Bedroom Queen 75.85 Available
    206 Bedroom King 92.75 Occupied
    207 Bedroom Queen 75.85 Available
    208 Bedroom Queen 75.85 Available
    209 Studio King 98.95 Available
    210 Studio Queen 94.50 Available
    211 Bedroom Double 79.90 Available
    212 Bedroom Queen 96.60 Available
    213 Bedroom King 95.50 Occupied
    214 Bedroom Queen 96.60 Available
    215 Bedroom Queen 96.60 Available
    216 Bedroom King 95.50 Available
    217 Bedroom Queen 96.60 Available
    218 Bedroom Queen 96.60 Available
    219 Bedroom Queen 96.60 Available
    220 Bedroom Queen 96.60 Available
  104. Close the Rooms form
  105. Click Occupancies
  106. Create the following records:
     
    Occupancy # Processed By Date Occupied Processed For Room Occupied Rate Applied Phone Charge
    100001 24095 6/16/2014 100752 106    
    100002 6/17/2014 100752 106 75.85  
    100003 6/18/2014 100752 106 75.85  
    100004 6/19/2014 100752 106 75.85  
    100005 28405 6/20/2014 100752 106 75.85  
    100006 28405 6/21/2014 946090 112   3.55
    100007 28405 6/21/2014 474065 110 450  
    100008 27049 6/21/2014 204795 104    
    100009 28405 6/22/2014 946090 112 98.95 28.86
    100010 24095 6/22/2014 204795 104 75.85  
    100011 24095 6/23/2014 208405 203    
    100012 24095 6/23/2014 284085 106    
    100013 24095 6/23/2014 294209 205    
    100014 6/24/2014 208405 203 94.5  
    100015 6/24/2014 284085 106 75.85  
    100016 6/24/2014 294209 205 75.85  
    100017 6/25/2014 208405 203 94.5 2.25
    100018 6/25/2014 284085 106 75.85  
    100019 6/25/2014 294209 205 75.85  
    100020 6/26/2014 208405 203 94.5  
    100021 6/26/2014 284085 106 75.85 3.15
    100022 6/26/2014 294209 205 75.85  
    100023 6/27/2014 208405 203 94.5 4.05
    100024 6/27/2014 284085 106 75.85 5.52
    100025 6/27/2014 294209 205 75.85
    100026 28405 6/28/2014 208405 203 94.5
    100027 20429 6/28/2014 383084 112 650 22.64
    100028 28405 6/28/2014 284085 106 75.85  
    100029 24095 6/28/2014 294209 205 75.85  
    100030 28405 6/28/2014 902840 107    
    100031 6/28/2014 608502 120   4.26
    100032 6/28/2014 180204 126    
    100033 6/28/2014 629305 122 725  
    100034 28405 6/28/2014 660820 105    
    100035 27049 6/29/2014 902840 107 85.75  
    100036 27049 6/29/2014 608502 120 98.85 8.48
    100037 28405 6/29/2014 180204 126 98.85  
    100038 20429 6/29/2014 260482 110 450  
    100039 6/29/2014 660820 105 92.75  
    100040 28405 6/30/2014 660820 105 92.75  
    100041 28405 7/2/2014 608208 114    
    100042 28405 7/3/2014 608208 114 92.75 6.82
    100043 20429 7/4/2014 608208 114 92.75  
    100044 28405 7/4/2014 640800 204    
    100045 7/5/2014 640800 204 96.6  
    100046 27049 7/6/2014 640800 204 96.6  
  107. Close the Occupancies form
  108. Click the Payments button and create a few payments as follows:
     
    Processed By Pmt Date Account # Occupied from To Total Nights Amt Charged Phone Use Tax Rate
    28405 6/20/2014 100752 6/16/2014 6/20/2014 4 75.85 0 7.70
    28405 6/22/2014 946090 6/21/2014 6/22/2014 1 98.95 32.41 7.70
    20429 6/23/2014 474065 6/21/2014 6/21/2014 1 450 0 7.70
    24095 6/24/2014 204795 6/21/2014 6/22/2014 1 75.85 0 7.70
    28405 6/28/2014 208405 6/23/2014 6/28/2014 5 94.50 2.25 7.70
    28405 6/28/2014 284085 6/23/2014 6/28/2014 5 75.85 8.67 7.70
    24095 6/28/2014 294209 6/23/2014 6/28/2014 5 75.85 0 7.70
    28405 7/2/2014 180204 6/28/2014 6/29/2014 1 98.85 0 7.70
    20429 7/5/2014 260482 6/29/2014 6/29/2014 1 450 0 7.70
    20429 7/6/2014 383084 6/28/2014 6/28/2014 1 650 22.64 7.70
    27049 7/6/2014 640800 7/4/2014 7/6/2014 2 93.65 0 7.70
    20429 7/11/2014 608208 7/2/2014 7/4/2014 2 92.75 6.82 7.70
  109. Close the forms and return to your programming environment

Application

 
 
   
 

Home Copyright © 2014-2016, FunctionX