Ejemplo n.º 1
0
        /// <summary>
        /// Retrieve booking information for user.
        /// Display user's information in a list if more than one 
        /// matching results is found. Once a guest is selected from that
        /// list, it will open the booking form with the selected information.
        /// If only one matching result, directly open the booking form for 
        /// the user.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void retrieveBookingButton_Click(object sender, EventArgs e)
        {
            if (lastNameTextBox.Text.Length <= 0)
            {
                MessageBox.Show("Please enter last name of the guest to search for their booking",
                                   "Last Name Required", MessageBoxButtons.OK, MessageBoxIcon.Error);
                lastNameTextBox.Focus();
                return;
            }
            OdbcCommand objectOdbcCommand = objectOdbcConnection.CreateCommand();
            objectOdbcCommand.CommandText = "select * from guest"
                                            + " join Booking"
                                            + " on guest.guestID = Booking.guestID"
                                            + " join Rooms on Booking.roomID = rooms.roomID"
                                            + " join Roomtype on  Roomtype.roomTypeId = rooms.roomTypeId "
                                            + " where ";

            if (firstNameTextBox.Text.Length > 0)
            {
                objectOdbcCommand.CommandText += " guestFName = ? and ";
                objectOdbcCommand.Parameters.Add("guestFname", OdbcType.NVarChar).Value = firstNameTextBox.Text;
            }
            objectOdbcCommand.CommandText += " guestLName = ?";
            objectOdbcCommand.Parameters.Add("guestLname", OdbcType.NVarChar).Value = lastNameTextBox.Text;

            OdbcDataReader dbReader = objectOdbcCommand.ExecuteReader();
            HashSet<BookingInformation> bookings = new HashSet<BookingInformation>();

            while (dbReader.Read())
            {
                BookingInformation objectBookingInformation = new BookingInformation();
                objectBookingInformation.readBookingObject(dbReader);
               bookings.Add(objectBookingInformation);
            }

            dbReader.Close();
            objectOdbcCommand.Dispose();

            switch(bookings.Count)
            {
                case 0:
                    MessageBox.Show("No booking found for this guest");
                    /*
                    BookingInformation objBookingInfo = new BookingInformation();
                    objectBookingForm = new Booking(this, objectOdbcConnection, objBookingInfo);
                    objectBookingForm.Show();
                    this.Hide();*/
                    break;
                case 1:
                    //MessageBox.Show("one booking found");
                    objectBookingForm = new Booking(this, objectOdbcConnection, bookings.ElementAt(0));
                    objectBookingForm.Show();
                    this.Hide();
                    break;
                default:
                    //MessageBox.Show("More than one booking found");
                    objectListBookings = new ListBookings(this, objectOdbcConnection, bookings);
                    objectListBookings.Show();
                    this.Hide();
                    break;
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Retrieve booking information for user.
        /// Display user's information in a list if more than one
        /// matching results is found. Once a guest is selected from that
        /// list, it will open the booking form with the selected information.
        /// If only one matching result, directly open the booking form for
        /// the user.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void retrieveBookingButton_Click(object sender, EventArgs e)
        {
            if (lastNameTextBox.Text.Length <= 0)
            {
                MessageBox.Show("Please enter last name of the guest to search for their booking",
                                "Last Name Required", MessageBoxButtons.OK, MessageBoxIcon.Error);
                lastNameTextBox.Focus();
                return;
            }
            OdbcCommand objectOdbcCommand = objectOdbcConnection.CreateCommand();

            objectOdbcCommand.CommandText = "select * from guest"
                                            + " join Booking"
                                            + " on guest.guestID = Booking.guestID"
                                            + " join Rooms on Booking.roomID = rooms.roomID"
                                            + " join Roomtype on  Roomtype.roomTypeId = rooms.roomTypeId "
                                            + " where ";

            if (firstNameTextBox.Text.Length > 0)
            {
                objectOdbcCommand.CommandText += " guestFName = ? and ";
                objectOdbcCommand.Parameters.Add("guestFname", OdbcType.NVarChar).Value = firstNameTextBox.Text;
            }
            objectOdbcCommand.CommandText += " guestLName = ?";
            objectOdbcCommand.Parameters.Add("guestLname", OdbcType.NVarChar).Value = lastNameTextBox.Text;

            OdbcDataReader dbReader = objectOdbcCommand.ExecuteReader();
            HashSet <BookingInformation> bookings = new HashSet <BookingInformation>();

            while (dbReader.Read())
            {
                BookingInformation objectBookingInformation = new BookingInformation();
                objectBookingInformation.readBookingObject(dbReader);
                bookings.Add(objectBookingInformation);
            }

            dbReader.Close();
            objectOdbcCommand.Dispose();

            switch (bookings.Count)
            {
            case 0:
                MessageBox.Show("No booking found for this guest");

                /*
                 * BookingInformation objBookingInfo = new BookingInformation();
                 * objectBookingForm = new Booking(this, objectOdbcConnection, objBookingInfo);
                 * objectBookingForm.Show();
                 * this.Hide();*/
                break;

            case 1:
                //MessageBox.Show("one booking found");
                objectBookingForm = new Booking(this, objectOdbcConnection, bookings.ElementAt(0));
                objectBookingForm.Show();
                this.Hide();
                break;

            default:
                //MessageBox.Show("More than one booking found");
                objectListBookings = new ListBookings(this, objectOdbcConnection, bookings);
                objectListBookings.Show();
                this.Hide();
                break;
            }
        }