private void btn_add_Click(object sender, EventArgs e)
        {
            if (this.id == 0)
            {
                if (this.tb_name.Text == "" || this.tb_numberOfSeats.Text == "" || this.cb_airlines.Text == "")
                {
                    this.lbl_info.Text = "Missing information.";
                    this.lbl_info.Show();
                    return;
                }
                Airline_company.Airline_companyDao airlineDao = new Airline_company.Airline_companyDaoImplements();

                int airlineId = airlineDao.getAirlineId(this.cb_airlines.Text);
                Airplane.Airplane    plane = new Airplane.Airplane(this.tb_name.Text, this.tb_numberOfSeats.Text, airlineId);
                Airplane.AirplaneDao dao   = new Airplane.AirplaneDaoImplements();
                dao.addAirplane(plane);
            }
            else if (this.id != 0)
            {
                if (this.tb_name.Text == "" || this.tb_numberOfSeats.Text == "" || this.cb_airlines.Text == "")
                {
                    this.lbl_info.Text = "Missing information.";
                    this.lbl_info.Show();
                    return;
                }
                Airline_company.Airline_companyDao airlineDao = new Airline_company.Airline_companyDaoImplements();

                int airlineId = airlineDao.getAirlineId(this.cb_airlines.Text);
                Airplane.Airplane    plane = new Airplane.Airplane(this.id, this.tb_name.Text, Int32.Parse(this.tb_numberOfSeats.Text), airlineId);
                Airplane.AirplaneDao dao   = new Airplane.AirplaneDaoImplements();
                dao.editAirplane(plane);
            }
            this.Close();
        }
        private void AddModifyAirplane_Load(object sender, EventArgs e)
        {
            lbl_info.Text = "";
            Airline_company.Airline_companyDao     airlinesDao = new Airline_company.Airline_companyDaoImplements();
            List <Airline_company.Airline_company> airlines    = airlinesDao.getAllAirlinesData();

            foreach (Airline_company.Airline_company s in airlines)
            {
                this.cb_airlines.Items.Add(new { Text = s.Name, Value = s.Id });
            }
            this.cb_airlines.DisplayMember = "Text";
            this.cb_airlines.ValueMember   = "Value";

            if (this.id == 0)
            {
                lbl_title.Text = "Add airplane";
                btn_add.Text   = "Add";
            }
            else if (this.id != 0)
            {
                lbl_title.Text = "Modify airplane";
                btn_add.Text   = "Save";

                AirplaneDao       airplaneDao = new AirplaneDaoImplements();
                Airplane.Airplane airplane    = airplaneDao.getAirplane(this.id);

                this.tb_name.Text = airplane.Name;

                Airline_company.Airline_company ac = airlinesDao.getAirlineDataForModification(airplane.Airline_company_id);

                this.tb_numberOfSeats.Text    = airplane.Number_of_seats.ToString();
                this.cb_airlines.SelectedItem = new { Text = ac.Name, Value = ac.Id };
            }
        }
Beispiel #3
0
        private void btn_remove_Click(object sender, EventArgs e)
        {
            int          id   = 0;
            ListViewItem item = new ListViewItem();

            if (this.lv_Main.SelectedItems.Count > 0)
            {
                item = this.lv_Main.SelectedItems[0];
            }
            switch (this.category)
            {
            case "flights":
                Fly.FlyDao fly = new Fly.FlyDaoImplements();
                id = Convert.ToInt32(item.SubItems[0].Text);
                fly.removeFlight(id);

                break;

            case "airlines":
                Airline_company.Airline_companyDao line = new Airline_company.Airline_companyDaoImplements();
                int idLine = Convert.ToInt32(item.SubItems[5].Text);

                line.removeAirline(idLine);
                break;

            case "airplanes":
                Airplane.AirplaneDao air = new Airplane.AirplaneDaoImplements();
                int idPlane = Convert.ToInt32(item.SubItems[3].Text);
                air.removeAirplane(idPlane);
                break;
            }
            this.ReloadListView();
        }
Beispiel #4
0
        private void ReloadListView()
        {
            if (this.selectedNode == "")
            {
                return;
            }

            this.btn_add.Enabled    = false;
            this.btn_remove.Enabled = false;
            this.btn_modify.Enabled = false;

            List <Fly.Fly> listOfFlights = new List <Fly.Fly>();
            ListViewItem   lvi           = new ListViewItem();
            AirplaneDao    airplaneDao   = new AirplaneDaoImplements();

            switch (this.selectedNode)
            {
            case "Flights":
                FlyDao         flightsDao = new FlyDaoImplements();
                List <Fly.Fly> list       = flightsDao.getAllFlights();

                this.btn_add.Enabled = true;
                this.category        = "flights";

                lv_Main.Columns.Clear();
                lv_Main.Items.Clear();
                lv_Main.Columns.Add("id", 0);
                lv_Main.Columns.Add("Destination", 100);
                lv_Main.Columns.Add("Start point", 100);
                lv_Main.Columns.Add("Departure time", 90);
                lv_Main.Columns.Add("Landing time", 90);
                lv_Main.Columns.Add("Airplane", 90);

                foreach (Fly.Fly item in list)
                {
                    Airplane.Airplane airplane = airplaneDao.getAirplane(item.Airplane_id);
                    lvi = new ListViewItem(new[] { item.Id.ToString(), item.Destination, item.Start_point, Convert.ToString(item.Departure_time), Convert.ToString(item.Landing_time), airplane.Name });
                    lv_Main.Items.Add(lvi);
                }

                break;

            case "Airlines":

                this.btn_add.Enabled = true;
                this.category        = "airlines";

                Airline_companyDao airlinesDao = new Airline_companyDaoImplements();
                List <Airline_company.Airline_company> airlines = airlinesDao.getAllAirlinesData();
                lv_Main.Columns.Clear();
                lv_Main.Items.Clear();
                lv_Main.Columns.Add("Name", 90);
                lv_Main.Columns.Add("Country");
                lv_Main.Columns.Add("Address");
                lv_Main.Columns.Add("Telephone", 70);
                lv_Main.Columns.Add("Email");
                lv_Main.Columns.Add("id", 0);
                foreach (Airline_company.Airline_company item in airlines)
                {
                    lvi = new ListViewItem(new[] { item.Name, item.Country, item.Address, Convert.ToString(item.Telephone), Convert.ToString(item.Email), Convert.ToString(item.Id) });
                    lv_Main.Items.Add(lvi);
                }

                break;

            case "Airplanes":

                this.btn_add.Enabled = true;
                this.category        = "airplanes";

                lv_Main.Columns.Clear();
                lv_Main.Items.Clear();
                lv_Main.Columns.Add("Name", 100);
                lv_Main.Columns.Add("Number of seats", 100);
                lv_Main.Columns.Add("Airline", 100);
                lv_Main.Columns.Add("id", 0);


                List <Airplane.Airplane> airplanes = airplaneDao.getAllAirplanes();
                string airlineName = "";
                Airline_company.Airline_companyDao airline = new Airline_company.Airline_companyDaoImplements();
                foreach (Airplane.Airplane planes in airplanes)
                {
                    airlineName = airline.getAirline(planes.Airline_company_id);
                    lvi         = new ListViewItem(new[] { planes.Name, planes.Number_of_seats.ToString(), airlineName, planes.Id.ToString() });
                    lv_Main.Items.Add(lvi);
                }

                break;
            }
        }
Beispiel #5
0
        private void btn_add_Click(object sender, EventArgs e)
        {
            if (this.id == 0)
            {
                lbl_info.Text = "";

                if (this.tb_name.Text == "" || this.tb_country.Text == "" || this.tb_address.Text == "")
                {
                    this.lbl_info.Text = "Missing information.";
                    this.lbl_info.Show();
                    return;
                }
                else
                {
                    Airline_company.Airline_companyDao dao = new Airline_company.Airline_companyDaoImplements();
                    string name      = this.tb_name.Text;
                    string country   = this.tb_country.Text;
                    string address   = this.tb_address.Text;
                    string telephone = null;
                    string email     = null;
                    if (this.tb_telephone.Text != "")
                    {
                        telephone = this.tb_telephone.Text;
                    }
                    if (this.tb_email.Text != "")
                    {
                        email = this.tb_email.Text;
                    }
                    Airline_company.Airline_company airline = new Airline_company.Airline_company(name, country, address, telephone, email);
                    dao.addAirline(airline);
                }
            }
            else if (this.id != 0)
            {
                lbl_info.Text = "";

                if (this.tb_name.Text == "" || this.tb_country.Text == "" || this.tb_address.Text == "")
                {
                    this.lbl_info.Text = "Missing information.";
                    this.lbl_info.Show();
                    return;
                }
                else
                {
                    Airline_company.Airline_companyDao dao = new Airline_company.Airline_companyDaoImplements();
                    string name      = this.tb_name.Text;
                    string country   = this.tb_country.Text;
                    string address   = this.tb_address.Text;
                    string telephone = null;
                    string email     = null;
                    if (this.tb_telephone.Text != "")
                    {
                        telephone = this.tb_telephone.Text;
                    }
                    if (this.tb_email.Text != "")
                    {
                        email = this.tb_email.Text;
                    }

                    Airline_company.Airline_company airline = new Airline_company.Airline_company(name, country, address, telephone, email, this.id);
                    dao.editAirline(airline);
                }
            }
            this.Close();
        }