private void BtnIncluir_Click(object sender, EventArgs e) { if (btnIncluir.Text.Equals("Inserir")) { btnIncluir.Text = "Guardar"; LimpaFormulario(); txtID.Enabled = false; txtNome.Focus(); } else if (btnIncluir.Text.Equals("Guardar")) { btnIncluir.Text = "Inserir"; txtID.Enabled = true; try { Aluno aluno = new Aluno(); aluno.Nome = txtNome.Text; aluno.Endereco = txtEndereco.Text; aluno.Email = txtEmail.Text; aluno.Telefone = txtTelefone.Text; DalHelper.Add(aluno); CarregaDados(); } catch (Exception ex) { MessageBox.Show("Erro : " + ex.Message); } } }
private void CarregaDados() { cboAlunos.DataSource = DalHelper.GetAlunos(); cboAlunos.ValueMember = "AlunoId"; cboAlunos.DisplayMember = "Nome"; cboAlunos.Text = "Selecione o aluno"; LimpaFormulario(); }
private void CboAlunos_SelectedIndexChanged(object sender, EventArgs e) { Aluno aluno = new Aluno(); codigoAluno = Convert.ToInt32(((DataRowView)cboAlunos.SelectedItem)["AlunoId"]); aluno = DalHelper.GetAluno(codigoAluno); PreencheDados(aluno); }
private void BtnExcluir_Click(object sender, EventArgs e) { try { DalHelper.Delete(codigoAluno); CarregaDados(); } catch (Exception ex) { MessageBox.Show("Erro : " + ex.Message); } }
private void BtnAlterar_Click(object sender, EventArgs e) { try { Aluno aluno = new Aluno(); aluno.AlunoId = Convert.ToInt32(txtID.Text); aluno.Nome = txtNome.Text; aluno.Endereco = txtEndereco.Text; aluno.Email = txtEmail.Text; aluno.Telefone = txtTelefone.Text; DalHelper.Update(aluno); CarregaDados(); } catch (Exception ex) { MessageBox.Show("Erro : " + ex.Message); } }