Beispiel #1
0
        private void cbPais_SelectedValueChanged(object sender, EventArgs e)
        {
            cbEstado.Enabled    = false;
            cbCidade.Enabled    = false;
            cbBairro.Enabled    = false;
            cbEstado.DataSource = null;
            cbCidade.DataSource = null;
            cbBairro.DataSource = null;

            int idPais;

            try{
                idPais = Int32.Parse(cbPais.SelectedValue.ToString());
            }catch (Exception) {
                return;
            }

            cbEstado.Text = "Carregando Estados...";
            EstadoBLL estado = new EstadoBLL();

            Types.EstadosType lista    = estado.select(idPais);
            Types.EstadoType  emptyRow = new Types.EstadoType();
            emptyRow.Descricao = "Selecione um Estado";

            lista.Insert(0, emptyRow);
            cbEstado.DataSource    = lista;
            cbEstado.ValueMember   = "idEstado";
            cbEstado.DisplayMember = "Descricao";
            cbEstado.SelectedIndex = 0;
            cbEstado.Enabled       = true;
        }
        public Types.EstadosType select(int idPais)
        {
            SqlConnection con = new SqlConnection(Dados.StringConexao);
            string        SQL = "select * from estado e " +
                                "join pais p on p.id_pais = e.id_pais " +
                                "where p.id_pais = @idPais " +
                                "order by e.descricao";

            SqlCommand cmd = new SqlCommand(SQL, con);

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

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

            Types.EstadosType estados = new Types.EstadosType();
            while (rd.Read())
            {
                Types.EstadoType estado = new Types.EstadoType();

                estado.idPais    = rd["id_pais"].ToString();
                estado.idEstado  = rd["id_estado"].ToString();
                estado.Sigla     = rd["sigla"].ToString();
                estado.Descricao = rd["descricao"].ToString();

                estados.Add(estado);
            }
            return(estados);
        }
        public Types.EstadosType select(int idPais)
        {
            MySqlConnection con = new MySqlConnection(Dados.StringConexao);
            string SQL = "select * from estado e "+
                         "join pais p on p.id_pais = e.id_pais "+
                         "where p.id_pais = @idPais " +
                         "order by e.descricao";

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

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

            Types.EstadosType estados = new Types.EstadosType();
            while (rd.Read())
            {
                Types.EstadoType estado = new Types.EstadoType();

                estado.idPais    = rd["id_pais"].ToString();
                estado.idEstado  = rd["id_estado"].ToString();
                estado.Sigla     = rd["sigla"].ToString();
                estado.Descricao = rd["descricao"].ToString();

                estados.Add(estado);
            }
            return estados;
        }
        public Types.EstadoType selectRecord(int idEstado)
        {
            MySqlConnection con = new MySqlConnection(Dados.StringConexao);
            string          SQL = "select * from estado where id_estado = @idEstado";

            MySqlCommand cmd = new MySqlCommand(SQL, con);

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

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

            Types.EstadoType estado = new Types.EstadoType();
            while (rd.Read())
            {
                estado.idEstado  = rd["id_estado"].ToString();
                estado.idPais    = rd["id_pais"].ToString();
                estado.Descricao = rd["descricao"].ToString();
                estado.Sigla     = rd["sigla"].ToString();
            }
            return(estado);
        }
        private void cbPais_SelectedValueChanged(object sender, EventArgs e)
        {
            cbEstado.Enabled = false;
            cbCidade.Enabled = false;
            cbBairro.Enabled = false;
            cbEstado.DataSource = null;
            cbCidade.DataSource = null;
            cbBairro.DataSource = null;

            int idPais;
            try{
                idPais = Int32.Parse(cbPais.SelectedValue.ToString());
            }catch (Exception){
                return;
            }

            cbEstado.Text    = "Carregando Estados...";
            EstadoBLL estado = new EstadoBLL();

            Types.EstadosType lista = estado.select(idPais);
            Types.EstadoType emptyRow = new Types.EstadoType();
            emptyRow.Descricao = "Selecione um Estado";

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