Exemple #1
0
        private void bookButton_Click(object sender, EventArgs e)
        {
            try
            {
                String client    = clientNameTextBox.Text;
                String telephone = telephoneTextBox.Text;
                int    nrTickets = int.Parse(nrTicketsTextBox.Text);

                String   TouristAttraction = searchedTripsDataGridView.SelectedRows[0].Cells["TouristAttraction"].Value.ToString();
                String   TransportCompany  = searchedTripsDataGridView.SelectedRows[0].Cells["TransportCompany"].Value.ToString();
                TimeSpan LeavingHour       = TimeSpan.Parse(searchedTripsDataGridView.SelectedRows[0].Cells["LeavingHour"].Value.ToString());
                double   Price             = double.Parse(searchedTripsDataGridView.SelectedRows[0].Cells["Price"].Value.ToString());
                int      NrSeats           = int.Parse(searchedTripsDataGridView.SelectedRows[0].Cells["NrSeats"].Value.ToString());
                int      Id = int.Parse(searchedTripsDataGridView.SelectedRows[0].Cells["Id"].Value.ToString());


                Trip trip = new Trip(Id, TouristAttraction, TransportCompany, LeavingHour, Price, NrSeats);

                if (trip.NrSeats - nrTickets < 0)
                {
                    MessageBox.Show("There are no available seats!", "Error");
                }
                else
                {
                    trip.NrSeats = trip.NrSeats - nrTickets;
                    clientController.UpdateTrip(trip);

                    Reservation reservation = new Reservation(clientController.GetReservationsSize() + 1, nrTickets, client, telephone, AgencyUser.Id, trip.Id);
                    clientController.AddReservation(reservation);

                    clientController.NotifyServer();
                }
            }
            catch (Exception exc)
            {
                MessageBox.Show(exc.Message + '\n' + exc.StackTrace, "Error");
            }
        }