Example #1
0
 /// <summary>
 /// Overloaded Constructor:
 /// This constructor will accept object of Welcome class, an opened
 /// OdbcConnection and BookingInformation object as input. When this
 /// form is closed, it uses the Welcome object passed on via this
 /// constructor to "show" the hidden Welcome form back to the user.
 /// </summary>
 /// <param name="welcomeForm">WlecomeForm</param>
 /// <param name="odbcConnection">OdbcConnection</param>
 /// <param name="bookingInformation">BookingInformation</param>
 public Booking(Welcome welcomeForm,
                OdbcConnection odbcConnection,
                BookingInformation bookingInformation)
     : this()
 {
     objWelcomeForm           = welcomeForm;
     objectOdbcConnection     = odbcConnection;
     objectBookingInformation = bookingInformation;
 }
Example #2
0
 /// <summary>
 /// Establish the database connection using object of
 /// OdbcConnection class
 /// Get the color status information for all the rooms and
 /// change room colors to reflect the booking status.
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void Welcome_Load(object sender, EventArgs e)
 {
     objectOdbcConnection = new OdbcConnection("DSN=HRS");
     objectOdbcConnection.Open();
     //set check out to next day by default
     checkOutDateTimePicker.Value = DateTime.Today.AddDays(1);
     objectBookingInformation     = new BookingInformation();
     getRoomColorStatus();
     setColorStatusForRooms();
 }
Example #3
0
 /// <summary>
 /// Reset color status for all the rooms and
 /// enable all rooms
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void clearButton_Click(object sender, EventArgs e)
 {
     roomTypeComboBox.SelectedIndex  = -1;
     roomLevelComboBox.SelectedIndex = -1;
     objectBookingInformation        = new BookingInformation();
     foreach (TabPage tb in tabControl1.TabPages)
     {
         foreach (Control ctr in tb.Controls)
         {
             ctr.Enabled = true;
         }
     }
     setColorStatusForRooms();
 }
Example #4
0
        private void okButton_Click(object sender, EventArgs e)
        {
            if (bookingsListView.SelectedIndices.Count > 0)
            {
                BookingInformation objectBookingInformation = new BookingInformation();
                // if only one matching result, open the booking form for that user
                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 guest.guestId = ? and rooms.roomnumber = ? ";
                //ListViewItem li = bookingsListView.
                string guestId    = bookingsListView.SelectedItems[0].SubItems[0].Text;
                string roomNumber = bookingsListView.SelectedItems[0].SubItems[6].Text;


                objectOdbcCommand.Parameters.Add("guestId", OdbcType.NVarChar).Value = guestId;
                objectOdbcCommand.Parameters.Add("roomnumber", OdbcType.Int).Value   = roomNumber;
                //objectOdbcCommand.Parameters.Add("guestLname", OdbcType.NVarChar).Value = textBox2.Text;

                OdbcDataReader dbReader = objectOdbcCommand.ExecuteReader();
                dbReader.Read();
                objectBookingInformation.readBookingObject(dbReader);
                dbReader.Close();
                objectOdbcCommand.Dispose();

                objectBookingForm = new Booking(objectWelcomeForm, objectOdbcConnection, objectBookingInformation);
                objectBookingForm.Show();
                this.Close();
            }
            else
            {
            }
        }
Example #5
0
 public AddCharges(BookingInformation bookingInformation)
     : this()
 {
     objectBookingInformation = bookingInformation;
 }
Example #6
0
 public AddCharges(BookingInformation bookingInformation)
     : this()
 {
     objectBookingInformation = bookingInformation;
 }
Example #7
0
 /// <summary>
 /// Overloaded Constructor: 
 /// This constructor will accept object of Welcome class, an opened 
 /// OdbcConnection and BookingInformation object as input. When this
 /// form is closed, it uses the Welcome object passed on via this
 /// constructor to "show" the hidden Welcome form back to the user.
 /// </summary>
 /// <param name="welcomeForm">WlecomeForm</param>
 /// <param name="odbcConnection">OdbcConnection</param>
 /// <param name="bookingInformation">BookingInformation</param>
 public Booking(Welcome welcomeForm, 
     OdbcConnection odbcConnection,
     BookingInformation bookingInformation)
     : this()
 {
     objWelcomeForm = welcomeForm;
     objectOdbcConnection = odbcConnection;
     objectBookingInformation = bookingInformation;
 }
Example #8
0
 /// <summary>
 /// Establish the database connection using object of
 /// OdbcConnection class
 /// Get the color status information for all the rooms and
 /// change room colors to reflect the booking status.
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void Welcome_Load(object sender, EventArgs e)
 {
     objectOdbcConnection = new OdbcConnection("DSN=HRS");
     objectOdbcConnection.Open();
     //set check out to next day by default
     checkOutDateTimePicker.Value = DateTime.Today.AddDays(1);
     objectBookingInformation = new BookingInformation();
     getRoomColorStatus();
     setColorStatusForRooms();
 }
Example #9
0
        /// <summary>
        /// Open the booking form for the room. The code automatically 
        /// detects whether the room has an existing booking or not. It
        /// creates the BookingInformation object accordingly and pass
        /// on to the Booking form as an argument. The booking form will
        /// update the controls based on the information in the 
        /// BookingInformation object.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Room_Click(object sender, EventArgs e)
        {
            //Open the booking form for this room for current day
            Button roomButton = (Button)sender;
            if (objectBookingInformation != null &&
                objectBookingInformation.bookedRoom.roomNumber != null &&
                objectBookingInformation.bookedRoom.roomNumber != roomButton.Text.Substring(0, 3))
            {
                /** BookingInformation contains info for a room which is not current room.
                 *  Invalidate this information and recreate BookingInformation object.
                 */
                objectBookingInformation = new BookingInformation();
            }
            objectBookingInformation.bookedRoom.roomNumber = roomButton.Text.Substring(0, 3);
               //Populate booking info with current booking on this room
            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  roomnumber = ? "
                                            + " and Booking.status != 'CHECKED OUT' "
                                            + " and ((Booking.checkIn = ? and Booking.checkOut >= ?) "
                                            + " or Booking.checkOut <= getdate())";

            objectOdbcCommand.Parameters.Add("roomnumber", OdbcType.Int).Value
                                        = objectBookingInformation.bookedRoom.roomNumber;
            objectOdbcCommand.Parameters.Add("checkIn", OdbcType.Date).Value
                = objectBookingInformation.checkInDate;
            objectOdbcCommand.Parameters.Add("checkOut", OdbcType.Date).Value
                = objectBookingInformation.checkOutDate;
            OdbcDataReader dbReader = objectOdbcCommand.ExecuteReader();
            if (dbReader.HasRows)
            {
                // Booking exist for this, read BookingInformation object
                objectBookingInformation.readBookingObject(dbReader);
            }
            else
            {
                // Booking doesn't exist, but update Room object in BookingInformation
                dbReader.Close();
                objectOdbcCommand.Parameters.Clear();
                objectOdbcCommand.CommandText = "Select * from Rooms "
                                + " join Roomtype on  Roomtype.roomTypeId = rooms.roomTypeId "
                                + " where  roomnumber = ? ";
                objectOdbcCommand.Parameters.Add("roomnumber", OdbcType.Int).Value
                                      = objectBookingInformation.bookedRoom.roomNumber;
                dbReader = objectOdbcCommand.ExecuteReader();
                dbReader.Read();
                if (dbReader.HasRows)
                {
                    objectBookingInformation.bookedRoom.roomId = dbReader["roomId"].ToString();
                    objectBookingInformation.bookedRoom.roomRate = Convert.ToDouble(dbReader["roomPrice"].ToString());
                    objectBookingInformation.bookedRoom.roomType = dbReader["roomType"].ToString();
                    objectBookingInformation.bookedRoom.roomFloor = dbReader["roomFloor"].ToString();
                    objectBookingInformation.bookedRoom.roomDescription = dbReader["roomDescription"].ToString();
                }
            }

            dbReader.Close();
            objectBookingForm = new Booking(this, objectOdbcConnection, objectBookingInformation);
            objectBookingForm.Show();
            this.Hide();
        }
Example #10
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;
            }
        }
Example #11
0
 /// <summary>
 /// Reset color status for all the rooms and
 /// enable all rooms
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void clearButton_Click(object sender, EventArgs e)
 {
     roomTypeComboBox.SelectedIndex = -1;
     roomLevelComboBox.SelectedIndex = -1;
     objectBookingInformation = new BookingInformation();
     foreach (TabPage tb in tabControl1.TabPages)
         foreach (Control ctr in tb.Controls)
             ctr.Enabled = true;
     setColorStatusForRooms();
 }
Example #12
0
        /// <summary>
        /// Check a rooms availability based on user's preference.
        /// All the rooms which doesn't fulfill user's preference
        /// will be disable. Booking can be made only on the rooms
        /// with "Green" color status
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void checkAvailabilityButton_Click(object sender, EventArgs e)
        {
            string type = roomTypeComboBox.Text;
            string roomLevel = roomLevelComboBox.Text;
            string checkInDate = checkInDateTimePicker.Text;
            string checkOutDate = checkOutDateTimePicker.Text;

            HashSet<string> hashSet = new HashSet<string>();
            objectBookingInformation = new BookingInformation();

            //Initialize connection for ODBC
            OdbcCommand objectOdbcCommand = objectOdbcConnection.CreateCommand();
            string strCommand = "select * from Rooms left join RoomType on "
                                            + "rooms.roomTypeID = RoomType.roomTypeID "
                                            + "left join Booking on "
                                            + "rooms.roomID = Booking.roomId where "
                                            + "(BookingID is null or "
                                            + " Booking.status = 'CHECKED OUT' or "
                                            + " not (checkIn between ? and ? ) "
                                            + " and not (checkOut between ? and ?))";

            objectOdbcCommand.Parameters.Add("DATE", OdbcType.Date).Value = checkInDateTimePicker.Value;
            objectOdbcCommand.Parameters.Add("DATE", OdbcType.Date).Value = checkOutDateTimePicker.Value;
            objectOdbcCommand.Parameters.Add("DATE", OdbcType.Date).Value = checkInDateTimePicker.Value;
            objectOdbcCommand.Parameters.Add("DATE", OdbcType.Date).Value = checkOutDateTimePicker.Value;

            objectBookingInformation.checkInDate = checkInDateTimePicker.Value;
            objectBookingInformation.checkOutDate = checkOutDateTimePicker.Value;

            if (type.Length > 0)
            {
                strCommand += " and roomtype = ?";
                objectOdbcCommand.Parameters.Add("roomtpe", OdbcType.NVarChar).Value = type;
                objectBookingInformation.bookedRoom.roomType = type;
            }
            if (roomLevel.Length > 0)
            {
                strCommand += " and roomFloor = ?";
                objectOdbcCommand.Parameters.Add("roomLevel", OdbcType.Int).Value = roomLevel;
                //objectBookingInformation.bookedRoom.roomLevel = roomLevel;
            }
            objectOdbcCommand.CommandText = strCommand;
            OdbcDataReader dbReader = objectOdbcCommand.ExecuteReader();

            while (dbReader.Read())
            {
                string roomNumber = dbReader["roomNumber"].ToString().Trim();
                hashSet.Add(roomNumber);

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

            //Following is logic to enable/disable
            if (roomLevelComboBox.Text.Length > 0)
            {
                int floor = int.Parse(roomLevelComboBox.Text) - 1;
                tabControl1.SelectedIndex = floor;
            }
            //Iterate thru all the TabPages and then controls on each TabPage
            foreach (TabPage tb in tabControl1.TabPages)
                foreach (Control ctr in tb.Controls)
                {
                    try
                    {
                        if (hashSet.Contains(ctr.Text.Substring(0, 3)))
                        {
                            ctr.Enabled = true;
                            setColorStatusForRoom((Button)ctr);
                        }
                        else
                        {
                            ctr.Enabled = false;
                            ctr.BackColor = Color.WhiteSmoke;
                        }
                    }
                    catch
                    {
                        ctr.Enabled = false;
                    }

                }
            hashSet.Clear();
        }
Example #13
0
        private void okButton_Click(object sender, EventArgs e)
        {
            if(bookingsListView.SelectedIndices.Count > 0)
            {
                BookingInformation objectBookingInformation = new BookingInformation();
                // if only one matching result, open the booking form for that user
                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 guest.guestId = ? and rooms.roomnumber = ? ";
                //ListViewItem li = bookingsListView.
                string guestId = bookingsListView.SelectedItems[0].SubItems[0].Text;
                string roomNumber = bookingsListView.SelectedItems[0].SubItems[6].Text;

                objectOdbcCommand.Parameters.Add("guestId", OdbcType.NVarChar).Value = guestId;
                objectOdbcCommand.Parameters.Add("roomnumber", OdbcType.Int).Value = roomNumber;
                //objectOdbcCommand.Parameters.Add("guestLname", OdbcType.NVarChar).Value = textBox2.Text;

                OdbcDataReader dbReader = objectOdbcCommand.ExecuteReader();
                dbReader.Read();
                objectBookingInformation.readBookingObject(dbReader);
                dbReader.Close();
                objectOdbcCommand.Dispose();

                objectBookingForm = new Booking(objectWelcomeForm, objectOdbcConnection, objectBookingInformation);
                objectBookingForm.Show();
                this.Close();
            }
            else{
            }
        }
Example #14
0
        /// <summary>
        /// Open the booking form for the room. The code automatically
        /// detects whether the room has an existing booking or not. It
        /// creates the BookingInformation object accordingly and pass
        /// on to the Booking form as an argument. The booking form will
        /// update the controls based on the information in the
        /// BookingInformation object.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Room_Click(object sender, EventArgs e)
        {
            //Open the booking form for this room for current day
            Button roomButton = (Button)sender;

            if (objectBookingInformation != null &&
                objectBookingInformation.bookedRoom.roomNumber != null &&
                objectBookingInformation.bookedRoom.roomNumber != roomButton.Text.Substring(0, 3))
            {
                /** BookingInformation contains info for a room which is not current room.
                 *  Invalidate this information and recreate BookingInformation object.
                 */
                objectBookingInformation = new BookingInformation();
            }
            objectBookingInformation.bookedRoom.roomNumber = roomButton.Text.Substring(0, 3);
            //Populate booking info with current booking on this room
            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  roomnumber = ? "
                                            + " and Booking.status != 'CHECKED OUT' "
                                            + " and ((Booking.checkIn = ? and Booking.checkOut >= ?) "
                                            + " or Booking.checkOut <= getdate())";

            objectOdbcCommand.Parameters.Add("roomnumber", OdbcType.Int).Value
                = objectBookingInformation.bookedRoom.roomNumber;
            objectOdbcCommand.Parameters.Add("checkIn", OdbcType.Date).Value
                = objectBookingInformation.checkInDate;
            objectOdbcCommand.Parameters.Add("checkOut", OdbcType.Date).Value
                = objectBookingInformation.checkOutDate;
            OdbcDataReader dbReader = objectOdbcCommand.ExecuteReader();

            if (dbReader.HasRows)
            {
                // Booking exist for this, read BookingInformation object
                objectBookingInformation.readBookingObject(dbReader);
            }
            else
            {
                // Booking doesn't exist, but update Room object in BookingInformation
                dbReader.Close();
                objectOdbcCommand.Parameters.Clear();
                objectOdbcCommand.CommandText = "Select * from Rooms "
                                                + " join Roomtype on  Roomtype.roomTypeId = rooms.roomTypeId "
                                                + " where  roomnumber = ? ";
                objectOdbcCommand.Parameters.Add("roomnumber", OdbcType.Int).Value
                         = objectBookingInformation.bookedRoom.roomNumber;
                dbReader = objectOdbcCommand.ExecuteReader();
                dbReader.Read();
                if (dbReader.HasRows)
                {
                    objectBookingInformation.bookedRoom.roomId          = dbReader["roomId"].ToString();
                    objectBookingInformation.bookedRoom.roomRate        = Convert.ToDouble(dbReader["roomPrice"].ToString());
                    objectBookingInformation.bookedRoom.roomType        = dbReader["roomType"].ToString();
                    objectBookingInformation.bookedRoom.roomFloor       = dbReader["roomFloor"].ToString();
                    objectBookingInformation.bookedRoom.roomDescription = dbReader["roomDescription"].ToString();
                }
            }


            dbReader.Close();
            objectBookingForm = new Booking(this, objectOdbcConnection, objectBookingInformation);
            objectBookingForm.Show();
            this.Hide();
        }
Example #15
0
        /// <summary>
        /// Check a rooms availability based on user's preference.
        /// All the rooms which doesn't fulfill user's preference
        /// will be disable. Booking can be made only on the rooms
        /// with "Green" color status
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void checkAvailabilityButton_Click(object sender, EventArgs e)
        {
            string type         = roomTypeComboBox.Text;
            string roomLevel    = roomLevelComboBox.Text;
            string checkInDate  = checkInDateTimePicker.Text;
            string checkOutDate = checkOutDateTimePicker.Text;

            HashSet <string> hashSet = new HashSet <string>();

            objectBookingInformation = new BookingInformation();

            //Initialize connection for ODBC
            OdbcCommand objectOdbcCommand = objectOdbcConnection.CreateCommand();
            string      strCommand        = "select * from Rooms left join RoomType on "
                                            + "rooms.roomTypeID = RoomType.roomTypeID "
                                            + "left join Booking on "
                                            + "rooms.roomID = Booking.roomId where "
                                            + "(BookingID is null or "
                                            + " Booking.status = 'CHECKED OUT' or "
                                            + " not (checkIn between ? and ? ) "
                                            + " and not (checkOut between ? and ?))";

            objectOdbcCommand.Parameters.Add("DATE", OdbcType.Date).Value = checkInDateTimePicker.Value;
            objectOdbcCommand.Parameters.Add("DATE", OdbcType.Date).Value = checkOutDateTimePicker.Value;
            objectOdbcCommand.Parameters.Add("DATE", OdbcType.Date).Value = checkInDateTimePicker.Value;
            objectOdbcCommand.Parameters.Add("DATE", OdbcType.Date).Value = checkOutDateTimePicker.Value;

            objectBookingInformation.checkInDate  = checkInDateTimePicker.Value;
            objectBookingInformation.checkOutDate = checkOutDateTimePicker.Value;

            if (type.Length > 0)
            {
                strCommand += " and roomtype = ?";
                objectOdbcCommand.Parameters.Add("roomtpe", OdbcType.NVarChar).Value = type;
                objectBookingInformation.bookedRoom.roomType = type;
            }
            if (roomLevel.Length > 0)
            {
                strCommand += " and roomFloor = ?";
                objectOdbcCommand.Parameters.Add("roomLevel", OdbcType.Int).Value = roomLevel;
                //objectBookingInformation.bookedRoom.roomLevel = roomLevel;
            }
            objectOdbcCommand.CommandText = strCommand;
            OdbcDataReader dbReader = objectOdbcCommand.ExecuteReader();

            while (dbReader.Read())
            {
                string roomNumber = dbReader["roomNumber"].ToString().Trim();
                hashSet.Add(roomNumber);
            }
            dbReader.Close();
            objectOdbcCommand.Dispose();

            //Following is logic to enable/disable
            if (roomLevelComboBox.Text.Length > 0)
            {
                int floor = int.Parse(roomLevelComboBox.Text) - 1;
                tabControl1.SelectedIndex = floor;
            }
            //Iterate thru all the TabPages and then controls on each TabPage
            foreach (TabPage tb in tabControl1.TabPages)
            {
                foreach (Control ctr in tb.Controls)
                {
                    try
                    {
                        if (hashSet.Contains(ctr.Text.Substring(0, 3)))
                        {
                            ctr.Enabled = true;
                            setColorStatusForRoom((Button)ctr);
                        }
                        else
                        {
                            ctr.Enabled   = false;
                            ctr.BackColor = Color.WhiteSmoke;
                        }
                    }
                    catch
                    {
                        ctr.Enabled = false;
                    }
                }
            }
            hashSet.Clear();
        }
Example #16
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;
            }
        }