Aerolinea.frmcontrolLocalizaciones.btnGuardarAvion_Click C# (CSharp) Method

btnGuardarAvion_Click() private method

private btnGuardarAvion_Click ( object sender, EventArgs e ) : void
sender object
e System.EventArgs
return void
        private void btnGuardarAvion_Click(object sender, EventArgs e)
        {
            if (tabLocalizacion.SelectedIndex==0)
            {
                try
                {
                    int ifilas;
                    int icodigoLocalizacion;
                    if (txtLugar.Text != "")
                    {
                        using (clasconexion.funobtenerConexion())
                        {
                            //PROGRAMADOR Y ANALISTA: Pamela Jacqueline Selman David
                            string squery = "SELECT COUNT(*) As Cant FROM AEROLINEA.TrDESTINO ";
                            MySqlCommand cmd = new MySqlCommand(squery, clasconexion.funobtenerConexion());
                            ifilas = Convert.ToInt32(cmd.ExecuteScalar());
                            icodigoLocalizacion = ifilas + 1;

                            //PROGRAMADOR Y ANALISTA: Jose Alberto Oxcal Ley
                            string sinsertaravion = "INSERT INTO AEROLINEA.TrDESTINO (ncodtipodestino,vdescripcion) VALUES(" + icodigoLocalizacion + ",'" + txtLugar.Text + "')";
                            MySqlCommand cmd1 = new MySqlCommand(sinsertaravion, clasconexion.funobtenerConexion());
                            MySqlDataReader MyReader;
                            MyReader = cmd1.ExecuteReader();
                            MessageBox.Show("LOCACION ALMACENADA");
                            clasconexion.funobtenerConexion().Close();
                            funlimpiar();
                            funconsultarLugares();
                        }
                    }
                    else { MessageBox.Show("Ingrese Lugar"); }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
            else if (tabLocalizacion.SelectedIndex == 1)
            {

                try
                {
                    if ((txtAeropuerto.Text != "") && (cmbLugar.Text != ""))
                    {
                        using (clasconexion.funobtenerConexion())
                        {
                            int idestino;
                            int icodigoAeropuerto;
                            string scodigo = "SELECT ncodtipodestino as destino FROM AEROLINEA.TrDESTINO WHERE vdescripcion='" + cmbLugar.Text + "'";
                            MySqlCommand ccod = new MySqlCommand(scodigo, clasconexion.funobtenerConexion());
                            idestino = Convert.ToInt32(ccod.ExecuteScalar());

                            string sposicion = "SELECT COUNT(*) As Cant FROM AEROLINEA.MaAEROPUERTO";
                            MySqlCommand cpos = new MySqlCommand(sposicion, clasconexion.funobtenerConexion());
                            icodigoAeropuerto = (Convert.ToInt32(cpos.ExecuteScalar())) + 1;

                            string sinsertaraeropuerto = "INSERT INTO AEROLINEA.MaAEROPUERTO (ncodaeropuerto,vnombreaeropuerto,ncodtipodestino) VALUES(" + icodigoAeropuerto + ",'" + txtAeropuerto.Text + "'," + idestino + ")";
                            MySqlCommand cinsertar = new MySqlCommand(sinsertaraeropuerto, clasconexion.funobtenerConexion());
                            MySqlDataReader Myguardar;
                            Myguardar = cinsertar.ExecuteReader();
                            MessageBox.Show("AEROPUERTO ALMACENADO");
                            clasconexion.funobtenerConexion().Close();
                            funlimpiar();
                            funconsultarAeropuerto();

                        }
                    }
                    else { MessageBox.Show("Ingrese Lugar y Aeropuerto"); }
                }
                catch (Exception ex) { MessageBox.Show(ex.Message); }
            }
        }