Ejemplo n.º 1
0
 private void btnExcluirAluno_Click(object sender, EventArgs e)
 {
     if (tabControl1.SelectedIndex == 0)
     {
         tabControl1.SelectTab(1);
     }
     if (MessageBox.Show("Confirma exclusão?", "",
                         MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2)
         == DialogResult.Yes)
     {
         Aluno RegAlu = new Aluno();
         RegAlu.Raaluno        = Convert.ToInt16(txtRa.Text);
         RegAlu.Nomealuno      = txtNomeAluno.Text;
         RegAlu.Cidadeidcidade = cbxCidade.SelectedIndex + 1;
         if (RegAlu.ExcluirAluno() > 0)
         {
             MessageBox.Show("Aluno excluído.");
             Aluno A = new Aluno();
             dsAluno.Tables.Clear();
             dsAluno.Tables.Add(A.Listar());
             bnAluno.DataSource = dsAluno.Tables["TBAluno"];
         }
         else
         {
             MessageBox.Show("Erro ao excluir.");
         }
     }
 }
Ejemplo n.º 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");
         txtNomeAluno.DataBindings.Add("TEXT", bnAluno, "nome_aluno");
         Cidade Cid = new Cidade();
         dsCidade.Tables.Add(Cid.Listar());
         cbxCidade.DataSource    = dsCidade.Tables["TbCidade"];
         cbxCidade.DisplayMember = "nome_cidade";
         cbxCidade.ValueMember   = "id_cidade";
         cbxCidade.DataBindings.Add("SelectedValue", bnAluno, "cidade_id_cidade");
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
 }
Ejemplo n.º 3
0
        private void btnSalvarAluno_Click(object sender, EventArgs e)
        {
            if (txtRa.Text == "" || txtNomeAluno.Text == "")
            {
                MessageBox.Show("RA ou Nome inválido.");
            }
            else
            {
                Aluno RegAlu = new Aluno();
                RegAlu.Raaluno        = Convert.ToInt16(txtRa.Text);
                RegAlu.Nomealuno      = txtNomeAluno.Text;
                RegAlu.Cidadeidcidade = cbxCidade.SelectedIndex + 1;
                if (bInclusao)
                {
                    if (RegAlu.SalvarAluno() > 0)
                    {
                        MessageBox.Show("Cidade adicionada.");

                        btnSalvarAluno.Enabled   = false;
                        txtRa.Enabled            = false;
                        txtNomeAluno.Enabled     = false;
                        cbxCidade.Enabled        = false;
                        btnSalvarAluno.Enabled   = false;
                        btnAlterarAluno.Enabled  = true;
                        btnNovoAluno.Enabled     = true;
                        btnExcluirAluno.Enabled  = true;
                        btnCancelarAluno.Enabled = false;
                        bInclusao = false;

                        dsAluno.Tables.Clear();
                        dsAluno.Tables.Add(RegAlu.Listar());
                        bnAluno.DataSource = dsAluno.Tables["TBaluno"];
                    }
                    else
                    {
                        MessageBox.Show("Erro ao gravar.");
                    }
                }
                else
                {
                    if (RegAlu.AlterarAluno() > 0)
                    {
                        MessageBox.Show("Aluno alterado.");

                        dsAluno.Tables.Clear();
                        dsAluno.Tables.Add(RegAlu.Listar());
                        txtRa.Enabled            = false;
                        txtNomeAluno.Enabled     = false;
                        cbxCidade.Enabled        = false;
                        btnSalvarAluno.Enabled   = false;
                        btnAlterarAluno.Enabled  = true;
                        btnNovoAluno.Enabled     = true;
                        btnExcluirAluno.Enabled  = true;
                        btnCancelarAluno.Enabled = false;
                    }
                    else
                    {
                        MessageBox.Show("Erro ao gravar.");
                    }
                }
            }
        }