Beispiel #1
0
        private void btnSalvar_Click(object sender, EventArgs e)
        {
            if (txtNomeCidade.Text == "")
            {
                MessageBox.Show("Cidade Inválida!");
            }
            else
            {
                Cidade RegCid = new Cidade();
                RegCid.Idcidade   = Convert.ToInt16(txtIdCidade.Text);
                RegCid.Nomecidade = txtNomeCidade.Text;
                RegCid.Ufcidade   = cbEstado.SelectedItem.ToString();
                if (bInclusao)
                {
                    if (RegCid.Salvar() > 0)
                    {
                        MessageBox.Show("Cidade adicionada com sucesso!");

                        btnSalvar.Enabled       = false;
                        txtIdCidade.Enabled     = false;
                        txtNomeCidade.Enabled   = false;
                        cbEstado.Enabled        = false;
                        btnSalvar.Enabled       = false;
                        btnEditar.Enabled       = true;
                        btnNovoRegistro.Enabled = true;
                        btnExcluir.Enabled      = true;
                        btnCancelar.Enabled     = false;

                        bInclusao = false;

                        dsCidade.Tables.Clear();
                        dsCidade.Tables.Add(RegCid.Listar());
                        bnCidade.DataSource = dsCidade.Tables["TBCIDADE"];
                    }
                    else
                    {
                        MessageBox.Show("Erro ao gravar cidade!");
                    }
                }
                else
                {
                    if (RegCid.Alterar() > 0)
                    {
                        MessageBox.Show("Cidade alterada com sucesso!");
                        dsCidade.Tables.Clear();
                        dsCidade.Tables.Add(RegCid.Listar());
                        btnSalvar.Enabled       = false;
                        txtIdCidade.Enabled     = false;
                        txtNomeCidade.Enabled   = false;
                        cbEstado.Enabled        = false;
                        btnSalvar.Enabled       = false;
                        btnEditar.Enabled       = true;
                        btnNovoRegistro.Enabled = true;
                        btnExcluir.Enabled      = true;
                        btnCancelar.Enabled     = false;
                    }
                }
            }
        }
Beispiel #2
0
        private void FrmAluno_Load(object sender, EventArgs e)
        {
            try
            {
                Aluno Alu = new Aluno();
                dsAluno.Tables.Add(Alu.Listar());
                bnAluno.DataSource     = dsAluno.Tables["TBALUNO"];
                dgvAluno.DataSource    = bnAluno;
                bnvAluno.BindingSource = bnAluno;

                txtRA.DataBindings.Add("TEXT", bnAluno, "RA_ALUNO");
                txtNome.DataBindings.Add("TEXT", bnAluno, "NOME_ALUNO");

                Cidade Cid = new Cidade();
                dsCidade.Tables.Add(Cid.Listar());
                cbAlunoCidade.DataSource    = dsCidade.Tables["TBCIDADE"];
                cbAlunoCidade.DisplayMember = "NOME_CIDADE";
                cbAlunoCidade.ValueMember   = "ID_CIDADE";
                cbAlunoCidade.DataBindings.Add("SelectedValue", bnAluno, "CIDADE_ID_CIDADE");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Beispiel #3
0
 private void btnExcluir_Click(object sender, EventArgs e)
 {
     if (tbCidade.SelectedIndex == 0)
     {
         tbCidade.SelectTab(1);
     }
     if (MessageBox.Show("Confirma exclusão?", "Yes or No", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) == DialogResult.Yes)
     {
         Cidade RegCid = new Cidade();
         RegCid.Idcidade   = Convert.ToInt16(txtIdCidade.Text);
         RegCid.Nomecidade = txtNomeCidade.Text;
         RegCid.Ufcidade   = cbEstado.SelectedItem.ToString();
         if (RegCid.Excluir() > 0)
         {
             MessageBox.Show("Cidade excluída com sucesso!");
             Cidade R = new Cidade();
             dsCidade.Tables.Clear();
             dsCidade.Tables.Add(R.Listar());
             bnCidade.DataSource = dsCidade.Tables["TBCIDADE"];
         }
         else
         {
             MessageBox.Show("Erro ao excluir cidade!");
         }
     }
 }
Beispiel #4
0
        private void btnExcluir_Click_1(object sender, EventArgs e)
        {
            if (tabControlAluno.SelectedIndex == 0)
            {
                tabControlAluno.SelectTab(1);
            }


            if (MessageBox.Show("Confirma exclusão?", "Yes or No", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) == DialogResult.Yes)
            {
                Aluno RegAlu = new Aluno();

                RegAlu.RaAluno   = Convert.ToInt16(txtRa.Text);
                RegAlu.NomeAluno = txtNomeAluno.Text;
                MessageBox.Show(cbxCidade.SelectedItem.ToString());
                RegAlu.CidadeIdCidade = Convert.ToInt16(cbxCidade.SelectedValue);

                if (RegAlu.Excluir() > 0)
                {
                    MessageBox.Show("Aluno excluído com sucesso!");
                    Cidade R = new Cidade();
                    dsAluno.Tables.Clear();
                    dsAluno.Tables.Add(R.Listar());
                    bnAluno.DataSource = dsAluno.Tables["TBAluno"];
                }
                else
                {
                    MessageBox.Show("Erro ao excluir aluno!");
                }
            }
        }
Beispiel #5
0
        private void frmAluno_Load(object sender, EventArgs e)
        {
            try
            {
                Aluno Alu = new Aluno();
                dsAluno.Tables.Add(Alu.Listar());
                bnAluno.DataSource     = dsAluno.Tables["TbAluno"];
                dgvAluno.DataSource    = bnAluno;
                bnvAluno.BindingSource = bnAluno;

                txtRa.DataBindings.Add("TEXT", bnAluno, "ra_aluno");
                txtNomeAluno.DataBindings.Add("TEXT", bnAluno, "nome_aluno");

                Cidade Cid = new Cidade();
                dsCidade.Tables.Add(Cid.Listar());

                cbxCidade.DataSource = dsCidade.Tables["TbCidade"];

                //campo que será mostrado para o usuario
                cbxCidade.DisplayMember = "nome_cidade";

                //campo que é a chave da tabela cidade e que liga com a tabela do aluno
                cbxCidade.ValueMember = "id_cidade";

                //no momento de loinkar os componentes com o Binding Source linkar tbm o combobox
                cbxCidade.DataBindings.Add("SelectedValue", bnAluno, "cidade_id_cidade");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Beispiel #6
0
        private void FrmCidade_Load(object sender, EventArgs e)
        {
            try
            {
                Cidade Cid = new Cidade();
                dsCidade.Tables.Add(Cid.Listar());
                bnCidade.DataSource     = dsCidade.Tables["TBCIDADE"];
                dgvCidade.DataSource    = bnCidade;
                bnvCidade.BindingSource = bnCidade;

                txtIdCidade.DataBindings.Add("TEXT", bnCidade, "ID_CIDADE");
                txtNomeCidade.DataBindings.Add("TEXT", bnCidade, "NOME_CIDADE");
                cbEstado.DataBindings.Add("SelectedItem", bnCidade, "UF_CIDADE");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Beispiel #7
0
        private void frmCidade_Load(object sender, EventArgs e)
        {
            try
            {
                Cidade Cid = new Cidade();
                dsCidade.Tables.Add(Cid.Listar());
                bnCidade.DataSource     = dsCidade.Tables["TBCidade"];
                dgvCidade.DataSource    = bnCidade;
                bnvCidade.BindingSource = bnCidade;

                txtId.DataBindings.Add("TEXT", bnCidade, "id_cidade");
                txtNomeCidade.DataBindings.Add("TEXT", bnCidade, "nome_cidade");
                cbxEstado.DataBindings.Add("SelectedItem", bnCidade, "uf_cidade"); // AJUSTAR DROPDOWNSTYLE PARA DropDownList PARA NAO DEIXAR INCLUIR
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Beispiel #8
0
        private void FrmCidade_Load(object sender, EventArgs e)
        {
            try
            {
                Cidade Cid = new Cidade();

                dsCidade.Tables.Add(Cid.Listar());
                bnCidade.DataSource     = dsCidade.Tables["TBCidade"];
                dvgCidade.DataSource    = bnCidade;
                bnvCidade.BindingSource = bnCidade;

                txtId.DataBindings.Add("TEXT", bnCidade, "id_cidade");
                txtCidade.DataBindings.Add("TEXT", bnCidade, "nome_cidade");
                cbxEstado.DataBindings.Add("SelectedItem", bnCidade, "uf_cidade");
            }
            catch (Exception err)
            {
                MessageBox.Show(err.Message);
            }
        }
Beispiel #9
0
        private void frmAluno_Load(object sender, EventArgs e)
        {
            try
            {
                Aluno Alu = new Aluno();
                dsAluno.Tables.Add(Alu.Listar());
                bnAluno.DataSource     = dsAluno.Tables["TBALUNO"];
                dgvAluno.DataSource    = bnAluno;
                bnvAluno.BindingSource = bnAluno;

                txtRa.DataBindings.Add("TEXT", bnAluno, "ra_aluno");
                txtNomeAluno.DataBindings.Add("TEXT", bnAluno, "nome_aluno");


                // tbcidade : id_cidade --> tbaluno : cidade_id_cidade

                Cidade Cid = new Cidade();
                dsCidade.Tables.Add(Cid.Listar());

                cbxCidade.DataSource = dsCidade.Tables["TbCidade"];

                //CAMPO QUE SERÁ MOSTRADO PARA O USUÁRIO

                cbxCidade.DisplayMember = "nome_cidade";

                //CAMPO QUE É A CHAVE DA TABELA CIDADE E QUE LIGA COM A TABELA DE ALUNO

                cbxCidade.ValueMember = "id_cidade";


                //No momento de linkar os componentes com o Binding Source linkar também o combox da cidade

                cbxCidade.DataBindings.Add("SelectedValue", bnAluno, "cidade_id_cidade"); // AJUSTAR DROPDOWNSTYLE PARA DropDownList PARA NAO DEIXAR INCLUIR
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }