Usamos cookies para medir audiência e melhorar sua experiência. Você pode aceitar ou recusar a qualquer momento. Veja sobre o iMasters.
Olá Pessoal, Bom dia!!
Estou com uma dúvida. Estou desenvolvendo uma aplicação, e nela tem cadastro de Departamentos, Setores, Cargos. Os cadastros de Departamento e Setores estão funcionando beleza, só estou com dúvida, no cadastro de Cargos, onde na tela de Cadastro de Cargo, tem informações como Título do Cargo, Salário Base.. e tem 3 ComboBox, Uma para selecionar o Tipo de Cargo, outra pra selecionar o Departamento que este cargo pertence, e o terceiro combo é para informar a qual setor pertence este Cargo
a imagem da tela de Cadastro de Cargo eu postei neste link
http://www.4shared.com/photo/ohsWtztj/cad_cargos.html
precisava que quando selecionava um departamento, ele automaticamente carrega somente os setores do departamento escolhido na combo de departamento, e toda vez que mudasse o departamento, ele atualizava a combo de setores..
Segue o código do form de Cadastro de Cargos
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
using TCC.Manipulacao;
using TCC.Metodos;
using TCC.RegradeNegocio;
namespace Projeto_Principal
{
public partial class frm_cad_cargo : Form
{
public frm_cad_cargo()
{
InitializeComponent();
}
private void frm_cad_cargo_Load(object sender, EventArgs e)
{
CarregaComboTipoCargo();
CarregarComboDep();
CarregaSetores();
}
protected void CarregarComboDep()
{
SqlConnection conexao = new SqlConnection();
conexao.ConnectionString = Dados.StringConexao;
conexao.Open();
try
{
SqlCommand cmd = new SqlCommand("SELECT CODEP,NOMEDEP FROM DEPARTAMENTOS", conexao);
SqlDataReader reader = cmd.ExecuteReader();
DataTable table = new DataTable();
table.Load(reader);
this.cbbDep.DataSource = table;
this.cbbDep.DisplayMember = "NOMEDEP";
this.cbbDep.ValueMember = "CODEP";
reader.Close();
reader.Dispose();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
finally
{
conexao.Close();
conexao.Dispose();
}
}
public void CarregaComboTipoCargo()
{
SqlConnection conexao = new SqlConnection();
conexao.ConnectionString = Dados.StringConexao;
conexao.Open();
try
{
SqlCommand cmd = new SqlCommand("SELECT CODTIPOCARGO,NOMETIPOCARGO FROM TIPOS_CARGO", conexao);
SqlDataReader reader = cmd.ExecuteReader();
DataTable table = new DataTable();
table.Load(reader);
this.cbbTipoCargo.DataSource = table;
this.cbbTipoCargo.DisplayMember = "NOMETIPOCARGO";
this.cbbTipoCargo.ValueMember = "CODTIPOCARGO";
reader.Close();
reader.Dispose();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
finally
{
conexao.Close();
conexao.Dispose();
}
}
public void CarregaSetores()
{
SqlConnection conexao = new SqlConnection();
conexao.ConnectionString = Dados.StringConexao;
conexao.Open();
try
{
SqlCommand cmd = new SqlCommand("SELECT S.CODSETOR,S.NOMESETOR,D.NOMEDEP FROM SETORES S INNER JOIN DEPARTAMENTOS D ON S.CODEP=D.CODEP WHERE D.NOMEDEP=" + cbbDep.DisplayMember, conexao);
SqlDataReader reader = cmd.ExecuteReader();
DataTable table = new DataTable();
table.Load(reader);
this.cbbSetor.DataSource = table;
this.cbbSetor.DisplayMember = "NOMESETOR";
this.cbbSetor.ValueMember = "CODSETOR";
reader.Close();
reader.Dispose();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
finally
{
conexao.Close();
conexao.Dispose();
}
}
private void btnSalvarCargo_Click(object sender, EventArgs e)
{
try
{
MetodosCargo cargo = new MetodosCargo();
cargo.NOMECARGO = txtNomeCargo.Text;
cargo.CODTIPOCARGO = Convert.ToInt32(this.cbbTipoCargo.SelectedValue);
cargo.CODEP = Convert.ToInt32(this.cbbDep.SelectedValue);
cargo.CODSETOR = Convert.ToInt32(this.cbbSetor.SelectedValue);
cargo.ATRIBUICOES = txtAtribuicoes.Text;
cargo.REQUISITOS = txtRequisitos.Text;
cargo.OBS = txtObservacoes.Text;
cargo.SALARIO = Convert.ToDouble(this.txtSalario.Text);
RegraCargo item = new RegraCargo();
item.IncluiCargo(cargo);
MessageBox.Show("Cargo incluído com sucesso");
LimpaCampos.Limpa(this);
txtNomeCargo.Focus();
}
catch (Exception excecao)
{
MessageBox.Show(excecao.Message);
txtNomeCargo.Focus();
}
}
private void cbbTipoCargo_Click(object sender, EventArgs e)
{
}
private void cbbSetor_Click(object sender, EventArgs e)
{
}
}
}
Se puderem me ajudar nisso, fico agradecido..
Att,
Rodrigo!
Carregando comentários...