コード例 #1
0
        public void deleteBooking(Booking b)
        {
            CarHire car = data.getCarHire(b.BookingReferenceNumber);

            if (car != null)
            {
                data.deleteCarHire(b.BookingReferenceNumber);
            }

            data.deleteGuests(b.BookingReferenceNumber);

            data.deleteBooking(b.BookingReferenceNumber);
        }
コード例 #2
0
        public CarHire getCarHire(int booking_ref)
        {
            bool check = checkCarHireForBooking(booking_ref);

            if (check == false)
            {
                return(null);
            }
            else
            {
                con.Open();
                string sql = String.Format(@"select * from Car
                                            where Car.booking_ref = '{0}'", booking_ref);

                SqlCommand com = new SqlCommand(sql, con);

                CarHire car = new CarHire();

                SqlDataReader sdr = com.ExecuteReader();

                while (sdr.Read())
                {
                    try
                    {
                        car.DriverName = (string)sdr["driver_name"];
                        car.StartDate  = (DateTime)sdr["start_date"];
                        car.EndDate    = (DateTime)sdr["end_date"];
                    }
                    catch (Exception ee)
                    {
                        Console.WriteLine(ee.Message);
                    }
                }
                con.Close();
                return(car);
            }
        }
コード例 #3
0
        public Booking FindBooking(int bookingRef)
        {
            Booking booking = Booking.GetInstance();
            ObservableCollection <Guest>   guestList   = new ObservableCollection <Guest>();
            ObservableCollection <CarHire> carHireList = new ObservableCollection <CarHire>();

            SqlConnection napierchalet = new SqlConnection(connectionString);

            using (napierchalet)
            {
                string bookingQuery = "SELECT * FROM Bookings WHERE Booking_ref=@bookingRef";
                string guestQuery   = "SELECT * FROM Guests WHERE Booking_ref=@bookingRef";
                string carHireQuery = "SELECT * FROM Car_hires WHERE Booking_ref=@bookingRef";

                SqlCommand bookingCmd = new SqlCommand(bookingQuery, napierchalet);
                bookingCmd.Parameters.AddWithValue("@bookingRef", bookingRef);
                SqlCommand guestCmd = new SqlCommand(guestQuery, napierchalet);
                guestCmd.Parameters.AddWithValue("@bookingRef", bookingRef);
                SqlCommand carHireCmd = new SqlCommand(carHireQuery, napierchalet);
                carHireCmd.Parameters.AddWithValue("@bookingRef", bookingRef);

                napierchalet.Open();

                using (SqlDataReader bookingReader = bookingCmd.ExecuteReader())
                {
                    if (!bookingReader.HasRows)
                    {
                        throw new ArgumentException("Booking not found!");
                    }

                    while (bookingReader.Read())
                    {
                        booking.BookingRef     = Convert.ToInt32(bookingReader["Booking_ref"].ToString());
                        booking.CustomerNum    = Convert.ToInt32(bookingReader["Customer_num"].ToString());
                        booking.ChaletID       = Convert.ToInt32(bookingReader["Chalet_id"].ToString());
                        booking.ArrivalDate    = Convert.ToDateTime(bookingReader["Start_date"].ToString());
                        booking.DepartureDate  = Convert.ToDateTime(bookingReader["End_date"].ToString());
                        booking.EveningMeals   = Convert.ToBoolean(bookingReader["Evening_meals"]);
                        booking.BreakfastMeals = Convert.ToBoolean(bookingReader["Breakfast_meals"]);
                    }
                }

                using (SqlDataReader guestReader = guestCmd.ExecuteReader())
                {
                    if (guestReader.HasRows)
                    {
                        while (guestReader.Read())
                        {
                            Guest newGuest = new Guest();

                            newGuest.GuestRef    = Convert.ToInt32(guestReader["Guest_ref"].ToString());
                            newGuest.Name        = guestReader["Name"].ToString();
                            newGuest.PassportNum = guestReader["Passport_num"].ToString();
                            newGuest.Age         = Convert.ToInt32(guestReader["Age"].ToString());

                            guestList.Add(newGuest);
                        }
                    }
                }

                booking.GuestList = guestList;

                using (SqlDataReader carHireReader = carHireCmd.ExecuteReader())
                {
                    if (carHireReader.HasRows)
                    {
                        while (carHireReader.Read())
                        {
                            CarHire newHire = new CarHire();
                            newHire.CarHireRef = Convert.ToInt32(carHireReader["Car_hire_ref"].ToString());
                            newHire.StartDate  = Convert.ToDateTime(carHireReader["Start_date"].ToString());
                            newHire.EndDate    = Convert.ToDateTime(carHireReader["End_date"].ToString());
                            newHire.Driver     = carHireReader["Driver"].ToString();
                            carHireList.Add(newHire);
                        }
                    }
                }

                booking.CarHireList = carHireList;

                napierchalet.Close();
            }

            return(booking);
        }
コード例 #4
0
 /// <summary>
 /// Edit a booking
 /// </summary>
 /// <param name="custBookRef"></param>
 /// <param name="custRefNum"></param>
 /// <param name="arrivalDate"></param>
 /// <param name="departureDate"></param>
 /// <param name="bookingChalet"></param>
 /// <param name="bookingCar"></param>
 /// <param name="guests"></param>
 public void EditBooking(int custBookRef, int custRefNum, DateTime arrivalDate, DateTime departureDate, Chalet bookingChalet, CarHire bookingCar, List <Guest> guests)
 {
     // Loop through each customer in the customer list
     for (int i = 0; i < _customers.Count; i++)
     {
         // If the current customer reference number matches the input customer reference number
         if (_customers[i].RefNumber == custRefNum)
         {
             // Loop through each booking in the current customers list of bookings
             for (int j = 0; j < _customers[i].Bookings.Count; j++)
             {
                 // If the current booking matches the booking reference input provided
                 if (_customers[i].Bookings[j].BookingRef == custBookRef)
                 {
                     // Set the attributes of the booking to the inputs provided
                     _customers[i].Bookings[j].Arrival        = arrivalDate;
                     _customers[i].Bookings[j].Departure      = departureDate;
                     _customers[i].Bookings[j].BookingChalet  = bookingChalet;
                     _customers[i].Bookings[j].BookingCarHire = bookingCar;
                     _customers[i].Bookings[j].BookingGuests.Clear();
                     _customers[i].Bookings[j].BookingGuests  = new List <Guest>(guests);
                     _customers[i].Bookings[j].BookingInvoice = new Invoice(_customers[i].Bookings[j]);
                     break;
                 }
             }
         }
     }
 }
コード例 #5
0
        /// <summary>
        /// Add a new booking
        /// </summary>
        /// <param name="custRefNum"></param>
        /// <param name="arrivalDate"></param>
        /// <param name="departureDate"></param>
        /// <param name="bookingChalet"></param>
        /// <param name="bookingCar"></param>
        /// <param name="guests"></param>
        /// <returns></returns>
        public Booking AddBooking(int custRefNum, DateTime arrivalDate, DateTime departureDate, Chalet bookingChalet, CarHire bookingCar, List <Guest> guests)
        {
            // Create a new booking object using the booking factory method
            Booking book = _bookFactory.FactoryMethod();

            // Set the booking attributes using the inputs provided
            book.Arrival        = arrivalDate;
            book.Departure      = departureDate;
            book.BookingChalet  = bookingChalet;
            book.BookingCarHire = bookingCar;
            book.BookingGuests  = new List <Guest>(guests);
            book.CustomerRef    = custRefNum;
            book.BookingInvoice = new Invoice(book);

            // get all the customers bookings, add to new list, add booking to list, set bookings to new list
            // Create a temporary list of bookings
            List <Booking> tempBookings;

            // Loop through the list of customers
            for (int i = 0; i < _customers.Count; i++)
            {
                // If the current customer reference number matches the input customer reference number
                if (_customers[i].RefNumber == custRefNum)
                {
                    // If the current customer has existing bookings
                    if (_customers[i].Bookings.Count > 0)
                    {
                        // Set the temporary list of bookings to the customer list of bookings
                        tempBookings = new List <Booking>(_customers[i].Bookings);
                    }
                    else
                    {
                        // Create a new list of bookings
                        tempBookings = new List <Booking>();
                    }
                    // Add the newly created booking to the temporary list of bookings
                    tempBookings.Add(book);
                    // Set the customer list of bookings to the temporary list of bookings
                    _customers[i].Bookings = tempBookings;
                    break;
                }
            }
            return(book);
        }
コード例 #6
0
 /// <summary>
 /// Edit a Booking
 /// </summary>
 /// <param name="custBookRef"></param>
 /// <param name="custRefNum"></param>
 /// <param name="arrivalDate"></param>
 /// <param name="departureDate"></param>
 /// <param name="bookingChalet"></param>
 /// <param name="bookingCar"></param>
 /// <param name="guests"></param>
 public void EditBooking(int custBookRef, int custRefNum, DateTime arrivalDate, DateTime departureDate, Chalet bookingChalet, CarHire bookingCar, List <Guest> guests)
 {
     _dataStorage.EditBooking(custBookRef, custRefNum, arrivalDate, departureDate, bookingChalet, bookingCar, guests);
 }
コード例 #7
0
        public void UpdateBooking(Customer customer, List <Guest> guests, Booking booking, CarHire car, int breakfast, int eveningMeal, bool checkCarHire)
        {
            data.updateBookingExtras(booking.BookingReferenceNumber, customer.CustomerReferenceNumber, breakfast, eveningMeal);

            if (checkCarHire == false)
            {
                data.deleteCarHire(booking.BookingReferenceNumber);
            }

            if (car != null && checkCarHire == true)
            {
                data.updateCarHire(booking.BookingReferenceNumber, car.StartDate, car.EndDate, car.DriverName);
            }

            data.deleteGuests(booking.BookingReferenceNumber);

            for (int i = 0; i < guests.Count; i++)
            {
                int guest_id = this.setGuestID();

                data.insertGuest(guest_id, guests[i].Age, guests[i].Name, booking.BookingReferenceNumber, guests[i].PassportNo);
            }
        }
コード例 #8
0
        public void SaveCustomerAndBooking(Customer customer, List <Guest> guests, Booking booking, CarHire car, int breakfast, int eveningMeal, bool addBooking)
        {
            booking.BookingReferenceNumber = this.setBookingReferenceNumber();

            booking.ChaletID = data.setChaletForBooking(booking.ArrivalDate, booking.DepartureDate);


            if (addBooking == false)
            {
                customer.CustomerReferenceNumber = this.setCustomerReferenceNumber();
                data.insertCustomer(customer.CustomerReferenceNumber, customer.Name, customer.Address);
            }

            data.insertBooking(booking.BookingReferenceNumber, booking.ArrivalDate, booking.DepartureDate, booking.ChaletID, customer.CustomerReferenceNumber, breakfast, eveningMeal);


            if (car != null)
            {
                data.insertCarHire(booking.BookingReferenceNumber, car.StartDate, car.EndDate, car.DriverName);
            }

            for (int i = 0; i < guests.Count; i++)
            {
                int guest_id = this.setGuestID();

                data.insertGuest(guest_id, guests[i].Age, guests[i].Name, booking.BookingReferenceNumber, guests[i].PassportNo);
            }
        }