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 { } }
/// <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(); }
/// <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; } }
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{ } }
/// <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; } }