private void addFlight_Click(object sender, EventArgs e) { if (txt_flightNumber.Text == "" || txt_arrivalDate.Text == "" || txt_destination.Text == "") { MessageBox.Show("Please enter the required Info", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning); } if (txt_flightNumber.Text.Length > Flight.FlightNo_len) { MessageBox.Show("Maximum lenght of flight number is " + Flight.FlightNo_len, "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning); txt_flightNumber.Clear(); } if (txt_destination.Text.Length > Flight.Destination_len) { MessageBox.Show("Maximum lenght of flight number is " + Flight.Destination_len, "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning); txt_flightNumber.Clear(); } if (txt_arrivalDate.Text.Length > Flight.arrivalDate_len) { MessageBox.Show("Maximum lenght of flight number is " + Flight.arrivalDate_len, "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning); txt_flightNumber.Clear(); } bool found = false; char[] ch = new char[Flight.FlightNo_len]; txt_flightNumber.Text.CopyTo(0, ch, 0, txt_flightNumber.Text.Length); for (int j = txt_flightNumber.Text.Length; j < ch.Length; ++j) { ch[j] = ' '; } string str = new string (ch); for (int i = 0; i < FlightsList.Count; ++i) { for (int j = 0; j < FlightsList.ElementAt(i).Value.Count; ++j) { if (FlightsList.ElementAt(i).Value.ElementAt(j).FlightNo == str) { MessageBox.Show("This Flight already exists", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning); txt_flightNumber.Clear(); txt_destination.Clear(); txt_arrivalDate.Clear(); found = true; break; } } if (found) { break; } } if (!found) { Flight flight = new Flight(); flight.arrivalDate = txt_arrivalDate.Text; flight.Destination = txt_destination.Text; flight.FlightNo = txt_flightNumber.Text; if (!FlightsList.ContainsKey(flight.Destination)) { List <Flight> flights = new List <Flight>(); FlightsList.Add(flight.Destination, flights); } FlightsList[flight.Destination].Add(flight); StartForm.writePass(PassengersList); StartForm.writeFly(FlightsList); this.Close(); } }