Exemple #1
0
        private void btnAddBooking_Click(object sender, EventArgs e)
        {
            if (ValidateInputs())
            {
                if ((capacity - numberPassengers) >= Convert.ToInt16(txtNumberPassengers.Text))
                {
                    BookingModel bookingModel = new BookingModel();

                    try
                    {
                        bookingModel.InsertBooking(textBox7.Text, textBox8.Text, customerId, textBox1.Text);

                        string message = "Insert Successful !!!";
                        MessageInformation.Success(message);

                        clearSelecion();
                        clearFlightDetails();
                    }
                    catch (SqlException ex)
                    {
                        string message = $"Customer {personModel.FirstName} {personModel.LastName} was already booked.\n" +
                                         $"Flight {flightModel.FlightNumber}.\n" +
                                         $"Destination {flightModel.Destination}";
                        MessageInformation.Error(message);
                    }
                    catch (Exception ex)
                    {
                        string message = "Booking was not added !!!";
                        MessageInformation.Error(message);
                    }
                }
                else
                {
                    string message = $"Flight {textBox1.Text}\n\nIt has not capacity!!!";
                    MessageInformation.Error(message);
                }
            }
            else
            {
                string message = "";

                if (cmbSelectCustomer.SelectedValue == null)
                {
                    message += "- Please select a Customer\n\n";
                }
                else
                {
                    message += "- Please select a flight";
                }

                MessageInformation.Error(message);
            }
        }