public Types.cidadesType select(int idEstado)
        {
            SqlConnection con = new SqlConnection(Dados.StringConexao);
            string        SQL = "select * from cidade c " +
                                "join estado e on e.id_estado = c.id_estado " +
                                "where e.id_estado = @idEstado " +
                                "order by c.descricao";

            SqlCommand cmd = new SqlCommand(SQL, con);

            cmd.Parameters.AddWithValue("@idEstado", idEstado);
            con.Open();

            SqlDataReader rd = cmd.ExecuteReader(CommandBehavior.CloseConnection);

            Types.cidadesType cidades = new Types.cidadesType();
            while (rd.Read())
            {
                Types.cidadeType cidade = new Types.cidadeType();

                cidade.idEstado  = rd["id_estado"].ToString();
                cidade.idCidade  = rd["id_cidade"].ToString();
                cidade.Descricao = rd["descricao"].ToString();

                cidades.Add(cidade);
            }
            return(cidades);
        }
        public Types.cidadesType select(int idEstado)
        {
            MySqlConnection con = new MySqlConnection(Dados.StringConexao);
            string SQL = "select * from cidade c " +
                         "join estado e on e.id_estado = c.id_estado " +
                         "where e.id_estado = @idEstado " +
                         "order by c.descricao";

            MySqlCommand cmd = new MySqlCommand(SQL, con);
            cmd.Parameters.AddWithValue("@idEstado", idEstado);
            con.Open();

            MySqlDataReader rd = cmd.ExecuteReader(CommandBehavior.CloseConnection);

            Types.cidadesType cidades = new Types.cidadesType();
            while (rd.Read())
            {
                Types.cidadeType cidade = new Types.cidadeType();

                cidade.idEstado  = rd["id_estado"].ToString();
                cidade.idCidade  = rd["id_cidade"].ToString();
                cidade.Descricao = rd["descricao"].ToString();

                cidades.Add(cidade);
            }
            return cidades;
        }
Beispiel #3
0
        private void cbEstado_SelectedValueChanged(object sender, EventArgs e)
        {
            cbCidade.Enabled    = false;
            cbBairro.Enabled    = false;
            cbCidade.DataSource = null;
            cbBairro.DataSource = null;

            int idEstado;

            try{
                idEstado = Int32.Parse(cbEstado.SelectedValue.ToString());
            }catch (Exception) {
                return;
            }
            cbCidade.Text = "Carregando Cidades...";
            CidadeBLL cidade = new CidadeBLL();

            Types.cidadesType lista    = cidade.select(idEstado);
            Types.cidadeType  emptyRow = new Types.cidadeType();
            emptyRow.Descricao = "Selecione uma Cidade";

            lista.Insert(0, emptyRow);
            cbCidade.DataSource    = lista;
            cbCidade.ValueMember   = "idCidade";
            cbCidade.DisplayMember = "Descricao";
            cbCidade.SelectedIndex = 0;
            cbCidade.Enabled       = true;
        }
Beispiel #4
0
        public Types.cidadeType selectRecord(int idCidade)
        {
            MySqlConnection con = new MySqlConnection(Dados.StringConexao);
            string          SQL = "select * from cidade where id_cidade = @idCidade";

            MySqlCommand cmd = new MySqlCommand(SQL, con);

            cmd.Parameters.AddWithValue("@idCidade", idCidade);
            con.Open();

            MySqlDataReader rd = cmd.ExecuteReader(CommandBehavior.CloseConnection);

            Types.cidadeType cidade = new Types.cidadeType();
            while (rd.Read())
            {
                cidade.idEstado  = rd["id_estado"].ToString();
                cidade.idCidade  = rd["id_cidade"].ToString();
                cidade.Descricao = rd["descricao"].ToString();
            }
            return(cidade);
        }
        private void cbEstado_SelectedValueChanged(object sender, EventArgs e)
        {
            cbCidade.Enabled = false;
            cbBairro.Enabled = false;
            cbCidade.DataSource = null;
            cbBairro.DataSource = null;

            int idEstado;
            try{
                idEstado = Int32.Parse(cbEstado.SelectedValue.ToString());
            }catch (Exception){
                return;
            }
            cbCidade.Text = "Carregando Cidades...";
            CidadeBLL cidade = new CidadeBLL();
            Types.cidadesType lista = cidade.select(idEstado);
            Types.cidadeType emptyRow = new Types.cidadeType();
            emptyRow.Descricao = "Selecione uma Cidade";

            lista.Insert(0, emptyRow);
            cbCidade.DataSource     = lista;
            cbCidade.ValueMember    = "idCidade";
            cbCidade.DisplayMember  = "Descricao";
            cbCidade.SelectedIndex  = 0;
            cbCidade.Enabled = true;
        }