コード例 #1
0
        private void btnSalvar_Click(object sender, EventArgs e)
        {
            if (txtNome.Text == "" || txtRA.Text == "")
            {
                MessageBox.Show("Dados inválidos!");
            }
            else
            {
                Aluno RegAluno = new Aluno();
                RegAluno.RaAluno        = Convert.ToInt32(txtRA.Text);
                RegAluno.NomeAluno      = txtNome.Text;
                RegAluno.CidadeIdcidade = Convert.ToInt16(cbAlunoCidade.SelectedValue);
                if (bInclusao)
                {
                    if (RegAluno.Salvar() > 0)
                    {
                        MessageBox.Show("Aluno adicionado com sucesso!");

                        btnSalvar.Enabled       = false;
                        txtRA.Enabled           = false;
                        txtNome.Enabled         = false;
                        cbAlunoCidade.Enabled   = false;
                        btnSalvar.Enabled       = false;
                        btnEditar.Enabled       = true;
                        btnNovoRegistro.Enabled = true;
                        btnExcluir.Enabled      = true;
                        btnCancelar.Enabled     = false;

                        bInclusao = false;

                        dsAluno.Tables.Clear();
                        dsAluno.Tables.Add(RegAluno.Listar());
                        bnAluno.DataSource = dsAluno.Tables["TBALUNO"];
                    }
                    else
                    {
                        MessageBox.Show("Erro ao gravar aluno!");
                    }
                }
                else
                {
                    if (RegAluno.Alterar() > 0)
                    {
                        MessageBox.Show("Aluno alterada com sucesso!");
                        dsAluno.Tables.Clear();
                        dsAluno.Tables.Add(RegAluno.Listar());
                        btnSalvar.Enabled       = false;
                        txtRA.Enabled           = false;
                        txtNome.Enabled         = false;
                        cbAlunoCidade.Enabled   = false;
                        btnSalvar.Enabled       = false;
                        btnEditar.Enabled       = true;
                        btnNovoRegistro.Enabled = true;
                        btnExcluir.Enabled      = true;
                        btnCancelar.Enabled     = false;
                    }
                }
            }
        }
コード例 #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);
            }
        }
コード例 #3
0
 private void btnExcluir_Click(object sender, EventArgs e)
 {
     if (tbAluno.SelectedIndex == 0)
     {
         tbAluno.SelectTab(1);
     }
     if (MessageBox.Show("Confirma exclusão?", "Yes or No", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) == DialogResult.Yes)
     {
         Aluno RegAluno = new Aluno();
         RegAluno.RaAluno        = Convert.ToInt32(txtRA.Text);
         RegAluno.NomeAluno      = txtNome.Text;
         RegAluno.CidadeIdcidade = Convert.ToInt16(cbAlunoCidade.SelectedValue);
         if (RegAluno.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!");
         }
     }
 }
コード例 #4
0
ファイル: frmAluno.cs プロジェクト: Wendell182/LP2
        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);
            }
        }
コード例 #5
0
ファイル: frmAluno.cs プロジェクト: gsabino1/LP2
        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);
            }
        }
コード例 #6
0
ファイル: frmAluno.cs プロジェクト: gsabino1/LP2
        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!");
            }
        }
コード例 #7
0
ファイル: frmAluno.cs プロジェクト: Wendell182/LP2
        private void btnSalvar_Click_1(object sender, EventArgs e)
        {
            if (txtNomeAluno.Text == "")
            {
                MessageBox.Show("Nome inválido!");
            }
            else
            {
                Aluno RegAlu = new Aluno();

                RegAlu.RaAluno        = Convert.ToInt32(txtRa.Text);
                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;
                        btnExcluir.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());
                        txtNomeAluno.Enabled = false;
                        txtRa.Enabled        = false;
                        cbxCidade.Enabled    = false;
                        btnSalvar.Enabled    = false;
                        btnAlterar.Enabled   = true;
                        btnExcluir.Enabled   = true;
                        btnExcluir.Enabled   = true;
                        btnCancelar.Enabled  = false;
                    }
                    else
                    {
                        MessageBox.Show("Erro ao gravar aluno!");
                    }
                }
            }
        }