// Used to insert values into tables that store data about pitch bookings public void AddNewPitchBooking(PitchBooking booking) { OpenConnection(); int numBookings = GetCount("[dbo].[BookingTable]"); 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 (" + 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 PitchBookingsTable VALUES (" + customerID + ", '" + booking.rentedSpace + "', " + (booking.water ? 1 : 0) + ", " + (booking.electricity ? 1 : 0) + ");", sqlConnection); sqlCommand.ExecuteNonQuery(); CloseConnection(); }
// When the user confirms their booking private void ConfirmButton_Click(object sender, EventArgs e) { if (IndefiniteCheckBox.Checked) // If the user has chosen to stay for an indefinite number of nights make the nightsStayed value negative { nightsStayed = -1; // A negative value is recognised by this software as an indefinite number of nights. } // Create a new PitchBooking object to store the details about the booking PitchBooking booking = new PitchBooking(CustomerNameTextBox.Text, StartDateTimePicker.Value, nightsStayed, CalculatePricePerDay(), RefreshPriceLabel(), (int)GroupSizeNumeric.Value, RentedSpaceComboBox.Text, WaterCheckBox.Checked, ElectricityCheckBox.Checked); if (booking.customerName.Length <= 0) // Validate that a customer name has been entered { MessageBox.Show("Please enter a Customer Name"); return; } else if (booking.rentedSpace.Length <= 0) // Validate that a Rented Space Facility has been entered { MessageBox.Show("Please enter a Rented Space"); return; } bookingDAL.AddNewPitchBooking(booking); // Save the booking in the database TaskCompletedMessage message = new TaskCompletedMessage(ConfirmButton); // Creates a new Tick box indiciating a task has been completed message.Disposed += new EventHandler(MessageDisposed); }