Exemple #1
0
        private void btnExcluir_Click(object sender, EventArgs e)
        {
            if (TabControl1.SelectedIndex == 0)
            {
                TabControl1.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.ToInt32(txtRa.Text);
                RegAlu.Nomealuno      = txtNomeAluno.Text;
                RegAlu.Cidadeidcidade = Convert.ToInt32(cbxCidade.SelectedValue);

                if (RegAlu.Excluir() > 0)
                {
                    MessageBox.Show("Aluno excluído com sucesso!");
                    Aluno R = new Aluno();
                    dsAluno.Tables.Clear();
                    dsAluno.Tables.Add(R.Listar());
                    bnAluno.DataSource = dsAluno.Tables["TBAluno"];
                }
                else
                {
                    MessageBox.Show("Erro ao excluir Aluno!");
                }
            }
        }
Exemple #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;
                // buscar no BD
                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 mostrado para o usuario
                cbxCidade.DisplayMember = "nome_cidade";

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

                // quando linkar os componentes com o Binding Source,
                // linkar tambem o combobox da cidade
                cbxCidade.DataBindings.Add("SelectedValue", bnAluno, "cidade_id_cidade");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Exemple #3
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);
            }
        }
Exemple #4
0
        private void btnSalvar_Click(object sender, EventArgs e)

        {
            // validar os dados

            if (txtNomeAluno.Text == "")
            {
                MessageBox.Show("Nome do Aluno inválido!");
            }

            else if (Int32.TryParse(txtRa.Text, out int ra) && ra > 0)

            {
                Aluno RegAlu = new Aluno();



                RegAlu.Raaluno = ra;

                RegAlu.Nomealuno = txtNomeAluno.Text;

                RegAlu.Cidadeidcidade = Convert.ToInt32(cbxCidade.SelectedValue);



                if (bInclusao)

                {
                    if (RegAlu.Salvar() > 0)

                    {
                        MessageBox.Show("Aluno adicionada com sucesso!");



                        btnSalvar.Enabled = false;

                        txtRa.Enabled = false;

                        txtNomeAluno.Enabled = false;

                        cbxCidade.Enabled = false;

                        btnSalvar.Enabled = false;

                        btnAlterar.Enabled = true;

                        btnNovoRegistro.Enabled = true;

                        btnExcluir.Enabled = true;

                        btnCancelar.Enabled = false;



                        bInclusao = false;



                        // recarrega o grid

                        dsAluno.Tables.Clear();

                        dsAluno.Tables.Add(RegAlu.Listar());

                        bnAluno.DataSource = dsAluno.Tables["TBALUNO"];
                    }
                    else

                    {
                        MessageBox.Show("Erro ao gravar aluno!");
                    }
                }
                else

                {
                    if (RegAlu.Alterar() > 0)

                    {
                        MessageBox.Show("Aluno alterado com sucesso!");

                        dsAluno.Tables.Clear();
                        dsAluno.Tables.Add(RegAlu.Listar());
                        txtRa.Enabled = false;

                        txtNomeAluno.Enabled = false;
                        cbxCidade.Enabled    = false;
                        btnSalvar.Enabled    = false;

                        btnAlterar.Enabled      = true;
                        btnNovoRegistro.Enabled = true;
                        btnExcluir.Enabled      = true;

                        btnCancelar.Enabled = false;
                    }
                    else
                    {
                        MessageBox.Show("Erro ao gravar aluno!");
                    }
                }
            }
            else
            {
                MessageBox.Show("RA Inválido!");
            }
        }