// Used to insert values into tables that store data about camping (Caravan/Tent) bookings public void AddNewCampingBooking(CampingBooking booking) { OpenConnection(); int numBookings = GetCount("[dbo].[BookingTable]"); int numHistoryBookings = GetCount("[dbo].[BookingHistoryTable]"); int customerID = GetCount("[dbo].[CustomerTable]"); // Insert data about Customers into the CustomerTable sqlCommand = new SqlCommand("Insert Into CustomerTable VALUES (" + customerID + ", '" + booking.customerName + "', " + booking.groupSize + ");", sqlConnection); sqlCommand.ExecuteNonQuery(); // Insert data about BookingTable into the CustomerTable sqlCommand = new SqlCommand("Insert Into BookingTable VALUES (" + (numHistoryBookings + numBookings) + ", '" + customerID + "', '" + string.Format("{0:MM-dd-yy}", booking.startDate.Date) + "', " + booking.nightsStayed + ", " + booking.GetPricePerNight() + ", " + booking.GetTotalPrice() + ");", sqlConnection); sqlCommand.ExecuteNonQuery(); // Insert data about CampingBookingsTable into the CustomerTable sqlCommand = new SqlCommand("Insert Into CampingBookingsTable VALUES (" + (numHistoryBookings + numBookings) + ", '" + booking.type + "', '" + booking.rating + "' );", sqlConnection); sqlCommand.ExecuteNonQuery(); CloseConnection(); }
// When the confirm button is clicked private void ConfirmBookingButton_Click(object sender, EventArgs e) { if (IndefiniteCheckBox.Checked) // If the number of nights stayed is indefinite then make nightsStayed a negative value { nightsStayed = -1; // A negative value is recognised by this software as an indefinite number of nights. } // Create a new CampingBooking object to store the details about the booking CampingBooking booking = new CampingBooking( CustomerNameTextBox.Text, StartDateTimePicker.Value, nightsStayed, CalculatePricePerDay(), RefreshPriceLabel(), rating, RentedItemComboBox.Text, (int)GroupSizeNumeric.Value); if (booking.customerName.Length <= 0) // Validate that a customer name has been entered { MessageBox.Show("Please enter a Customer Name"); return; } else if(booking.type.Length <= 0) // Validate that a Rented Facility has been entered { MessageBox.Show("Please enter a Rented Facility"); return; } bookingDAL.AddNewCampingBooking(booking); // Save the booking in the database TaskCompletedMessage message = new TaskCompletedMessage(ConfirmBookingButton); // Creates a new Tick box indiciating a task has been completed message.Disposed += new EventHandler(MessageDisposed); }