private void btn_update_Click(object sender, EventArgs e)
        {
            // to update data
            Passenger tmp            = new Passenger();
            bool      isPhoneUpdate  = true;
            bool      isFlightUpdate = true;
            bool      both           = true;

            tmp.Name     = cbx_SearchPass.SelectedItem.ToString();
            tmp.Phone    = txt_phone.Text;
            tmp.FlightNo = txt_flight.Text;

            if (PassengersList.ContainsKey(tmp.Name))
            {
                if (tmp.Phone == "")
                {
                    tmp.Phone     = PassengersList[tmp.Name].Phone;
                    isPhoneUpdate = false;
                }
                if (tmp.FlightNo == "")
                {
                    tmp.FlightNo   = PassengersList[tmp.Name].FlightNo;
                    isFlightUpdate = false;
                }
                if (!isFlightUpdate && !isPhoneUpdate)
                {
                    both = false;
                }
                PassengersList[tmp.Name].update(tmp);
                if (both)
                {
                    MessageBox.Show("Updated successfully ", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                else if (isPhoneUpdate && !isFlightUpdate)
                {
                    MessageBox.Show("Phone is Updated successfully ", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                else if (!isPhoneUpdate && isFlightUpdate)
                {
                    MessageBox.Show("Flight Number is Updated successfully ", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                else
                {
                    MessageBox.Show("No Update occured ", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
            else
            {
                MessageBox.Show(" No passenger with this name ", "Warrning", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }

            StartForm.writePass(PassengersList);
        }
Example #2
0
        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();
            }
        }