private void btnAlunoCadastrar_Click(object sender, EventArgs e) { using (AlunoNegocio alunoNegocio = new AlunoNegocio()) { ValidacaoInterfaces validar = new ValidacaoInterfaces(); if (validar.validarCampoCadastrar(this.grpIdentificacao.Controls) == true) { return; } else if (validar.ValidarRadioButton(this.rbtCadastrarSexoMasculino, this.rbtCadastrarSexoFeminino) == true) { return; } else if (validar.ValidarRadioButton(this.rbtCadastrarAtivoSim, rbtCadastrarAtivoNao) == true) { return; } else if (validar.validarCampoCadastrar(this.grpLocalizacao.Controls) == true) { return; } else if (validar.validarCampoCadastrar(this.grpContato.Controls) == true) { return; } else if (validar.validarCampoCadastrar(this.grpObjetivo.Controls) == true) { return; } else if (validar.validarCampoCadastrar(this.grpLogin.Controls) == true) { return; } if (acaoNaTelaInformada == AcaoNaTela.Inserir) { Aluno alunoInserir = new Aluno() { Status = this.txtCadastrarStatus.Text, }; alunoInserir.Pessoa = new Pessoa() { Nome = this.txtCadastrarNome.Text, RG = this.txtCadastrarRG.Text, CPF = this.mskCadastrarCPF.Text, DataNascimento = this.dtpCadastrarDataNascimento.Value, Ativo = this.rbtCadastrarAtivoSim.Checked == true ? true : false, Sexo = this.rbtCadastrarSexoMasculino.Checked == true ? true : false, Email = this.txtCadastrarEmail.Text, Usuario = this.txtCadastrarUsuario.Text, Senha = this.txtCadastrarSenha.Text, TelefoneCelular = this.mskCadastrarTelefoneCelular.Text, TelefoneResidencial = this.mskCadastrarTelefoneResidencial.Text }; alunoInserir.Pessoa.Endereco = new Endereco() { CEP = this.txtCadastrarCEP.Text, Rua = this.txtCadastrarRua.Text, Numero = Convert.ToInt32(this.txtCadastrarNumero.Text), Complemento = this.txtCadastrarComplemento.Text, Bairro = this.txtCadastrarBairro.Text, Cidade = this.txtCadastrarCidade.Text, UF = this.cmbCadastrarUF.Text }; alunoInserir.Objetivo = new Objetivo() { IDObjetivo = Convert.ToInt32(this.cmbCadastrarDescricao.SelectedValue) }; string retorno = alunoNegocio.Inserir(alunoInserir); try { int codigo = Convert.ToInt32(retorno); MessageBox.Show("Aluno cadastrado com sucesso. Código: " + codigo.ToString(), "Aviso", MessageBoxButtons.OK, MessageBoxIcon.Information); this.DialogResult = System.Windows.Forms.DialogResult.Yes; } catch { MessageBox.Show("Não foi possível cadastrar o aluno. Detalhes: " + retorno, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } } else if (acaoNaTelaInformada == AcaoNaTela.Alterar) { Aluno alunoAlterar = new Aluno() { Status = this.txtCadastrarStatus.Text }; alunoAlterar.Pessoa = new Pessoa() { IDPessoa = Convert.ToInt32(this.txtCadastrarCodigo.Text), Nome = this.txtCadastrarNome.Text, RG = this.txtCadastrarRG.Text, CPF = this.mskCadastrarCPF.Text, DataNascimento = this.dtpCadastrarDataNascimento.Value, Ativo = this.rbtCadastrarAtivoSim.Checked == true ? true : false, Sexo = this.rbtCadastrarSexoMasculino.Checked == true ? true : false, Email = this.txtCadastrarEmail.Text, Usuario = this.txtCadastrarUsuario.Text, Senha = this.txtCadastrarSenha.Text, TelefoneCelular = this.mskCadastrarTelefoneCelular.Text, TelefoneResidencial = this.mskCadastrarTelefoneResidencial.Text }; alunoAlterar.Pessoa.Endereco = new Endereco() { CEP = this.txtCadastrarCEP.Text, Rua = this.txtCadastrarRua.Text, Numero = Convert.ToInt32(this.txtCadastrarNumero.Text), Complemento = this.txtCadastrarComplemento.Text, Bairro = this.txtCadastrarBairro.Text, Cidade = this.txtCadastrarCidade.Text, UF = this.cmbCadastrarUF.Text }; alunoAlterar.Objetivo = new Objetivo() { IDObjetivo = Convert.ToInt32(this.cmbCadastrarDescricao.SelectedValue) }; string retorno = alunoNegocio.Alterar(alunoAlterar); try { int codigo = Convert.ToInt32(retorno); MessageBox.Show("Aluno alterado com sucesso. Código: " + codigo.ToString(), "Aviso", MessageBoxButtons.OK, MessageBoxIcon.Information); this.DialogResult = System.Windows.Forms.DialogResult.Yes; } catch { MessageBox.Show("Não foi possível alterar o aluno. Detalhes: " + retorno, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } } } }
public void AtualizarGridAluno(DialogResult dialogResult) { using (AlunoNegocio alunoNegocio = new AlunoNegocio()) { ValidacaoInterfaces validarInterfaces = new ValidacaoInterfaces(); if (dialogResult == DialogResult.Yes) { try { ListaAluno listaAluno = alunoNegocio.PesquisarAlunoNomeOuCodigo(null, "%"); dgwSelecionarAluno.DataSource = null; dgwSelecionarAluno.DataSource = listaAluno; dgwSelecionarAluno.Update(); dgwSelecionarAluno.Refresh(); txtSelecionarAlunoCodNome.Focus(); txtSelecionarAlunoCodNome.Clear(); return; } catch (Exception ex) { MessageBox.Show("Não foi possível pesquisar apos ter inserido um novo aluno. Detalhes: " + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Information); txtSelecionarAlunoCodNome.Focus(); return; } } else if (validarInterfaces.ValidarCampoPesquisar(this.txtSelecionarAlunoCodNome, "nome") == true) { return; } else if (txtSelecionarAlunoCodNome.Text.Where(c => char.IsNumber(c)).Count() > 0) { try { ListaAluno listaAluno = alunoNegocio.PesquisarAlunoNomeOuCodigo(Convert.ToInt32(txtSelecionarAlunoCodNome.Text), null); if (listaAluno.Count() > 0) { dgwSelecionarAluno.DataSource = null; dgwSelecionarAluno.DataSource = listaAluno; dgwSelecionarAluno.Update(); dgwSelecionarAluno.Refresh(); txtSelecionarAlunoCodNome.Focus(); return; } else { MessageBox.Show("Não existe nenhum aluno com esse código: " + txtSelecionarAlunoCodNome.Text, "Aviso", MessageBoxButtons.OK, MessageBoxIcon.Information); txtSelecionarAlunoCodNome.Focus(); return; } } catch (Exception ex) { MessageBox.Show("Não foi possível pesquisar aluno por código. Detalhes: " + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Information); txtSelecionarAlunoCodNome.Focus(); return; } } else { try { ListaAluno listaAluno = alunoNegocio.PesquisarAlunoNomeOuCodigo(null, txtSelecionarAlunoCodNome.Text); if (listaAluno.Count() > 0) { dgwSelecionarAluno.DataSource = null; dgwSelecionarAluno.DataSource = listaAluno; dgwSelecionarAluno.Update(); dgwSelecionarAluno.Refresh(); txtSelecionarAlunoCodNome.Focus(); return; } else { MessageBox.Show("Não existe nenhum aluno com esse nome: " + txtSelecionarAlunoCodNome.Text, "Aviso", MessageBoxButtons.OK, MessageBoxIcon.Information); txtSelecionarAlunoCodNome.Focus(); return; } } catch (Exception ex) { MessageBox.Show("Não foi possível pesquisae aluno por nome. Detalhes: " + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Information); txtSelecionarAlunoCodNome.Focus(); return; } } } }