private void btnCadastrarTreinamento_Click(object sender, EventArgs e)
        {
            using (TreinamentoNegocio treinamentoNegocio = new TreinamentoNegocio())
            {
                ValidacaoInterfaces validarInterfaces = new ValidacaoInterfaces();
                if (acaoNaTelaInformada == AcaoNaTela.Inserir)
                {
                    if (validarInterfaces.ValidarRadioButton(rbtCadastrarAtivoSim, rbtCadastrarAtivoNao) == true)
                    {
                        return;
                    }
                    if (cbxCadastrarTipoTreinamento.Text == "")
                    {
                        MessageBox.Show("Campo obrigatório nulo: Treinamento", "Aviso", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        cbxCadastrarTipoTreinamento.Focus();
                        return;
                    }
                    if (cbxCadastrarTipoTreinamento.SelectedValue == null)
                    {
                        MessageBox.Show("Tipo de treinamento físico não existe", "Aviso", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        cbxCadastrarTipoTreinamento.Focus();
                        return;
                    }
                    Treinamento treinamentoInserir = new Treinamento()
                    {
                        Ativo = rbtCadastrarAtivoSim.Checked == true ? true : false
                    };
                    treinamentoInserir.TipoTreinamento = new TipoTreinamento()
                    {
                        IDTipoTreinamento = Convert.ToInt32(cbxCadastrarTipoTreinamento.SelectedValue)
                    };

                    treinamentoInserir.Aluno        = new Aluno();
                    treinamentoInserir.Aluno.Pessoa = new Pessoa()
                    {
                        IDPessoa = Convert.ToInt32(txtCodigoAluno.Text)
                    };

                    string retorno = treinamentoNegocio.Inserir(treinamentoInserir);

                    try
                    {
                        int IDTreinamento = Convert.ToInt32(retorno);
                        grpFichaTreinamento.Enabled        = true;
                        grpTreinamentoFisico.Enabled       = false;
                        btnCadastrarTreinamento.Text       = "";
                        txtCadastrarTreinamentoCodigo.Text = IDTreinamento.ToString();
                        cbxCadastrarExercicio.Focus();
                    }
                    catch
                    {
                        MessageBox.Show("Não foi possível cadastrar as informações do treinamento. Detalhes: " + retorno, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        cbxCadastrarTipoTreinamento.Focus();
                        return;
                    }
                }

                else if (acaoNaTelaInformada == AcaoNaTela.Alterar)
                {
                    if (validarInterfaces.ValidarRadioButton(rbtCadastrarAtivoSim, rbtCadastrarAtivoNao) == true)
                    {
                        return;
                    }

                    Treinamento treinamentoAlterar = new Treinamento()
                    {
                        IDTreinamento = Convert.ToInt32(txtCadastrarTreinamentoCodigo.Text),
                        Ativo         = rbtCadastrarAtivoSim.Checked == true? true: false
                    };
                    treinamentoAlterar.TipoTreinamento = new TipoTreinamento()
                    {
                        IDTipoTreinamento = Convert.ToInt32(cbxCadastrarTipoTreinamento.SelectedValue)
                    };

                    treinamentoAlterar.Aluno        = new Aluno();
                    treinamentoAlterar.Aluno.Pessoa = new Pessoa()
                    {
                        IDPessoa = Convert.ToInt32(txtCodigoAluno.Text)
                    };

                    string retorno = treinamentoNegocio.Alterar(treinamentoAlterar);
                    try
                    {
                        int IDTreinamento = Convert.ToInt32(retorno);
                        grpFichaTreinamento.Enabled  = true;
                        grpTreinamentoFisico.Enabled = false;
                        cbxCadastrarExercicio.Focus();
                    }
                    catch
                    {
                        MessageBox.Show("Não foi possível alterar as informações do treinamento. Detalhes: " + retorno, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        cbxCadastrarTipoTreinamento.Focus();
                        return;
                    }
                }
            }
        }
        public void AtualizarGridTreinamento(DialogResult dialogResult)
        {
            using (TreinamentoNegocio treinamentoNegocio = new TreinamentoNegocio())
            {
                ValidacaoInterfaces validarInterfaces = new ValidacaoInterfaces();
                if (dialogResult == DialogResult.Yes)
                {
                    try
                    {
                        ListaTreinamento listaTreinamento = treinamentoNegocio.PesquisarTreinamentoCodigoNomeAluno(null, txtSelecionarCodAluno.Text);
                        this.dgwSelecionarTreinamentoFísico.DataSource = null;
                        this.dgwSelecionarTreinamentoFísico.DataSource = listaTreinamento;
                        this.dgwSelecionarTreinamentoFísico.Update();
                        this.dgwSelecionarTreinamentoFísico.Refresh();
                        txtSelecionarCodAluno.Focus();

                        return;
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show("Não foi possível atualizar, após ter inserido ou alterado treinamento. Detalhes: " + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        return;
                    }
                }
                else if (validarInterfaces.ValidarCampoPesquisar(txtSelecionarCodAluno, "nome do aluno") == true)
                {
                    return;
                }
                else if (txtSelecionarCodAluno.Text.Where(c => char.IsNumber(c)).Count() > 0)
                {
                    try
                    {
                        ListaTreinamento listaTreinamento = treinamentoNegocio.PesquisarTreinamentoCodigoNomeAluno(Convert.ToInt32(txtSelecionarCodAluno.Text), null);
                        if (listaTreinamento.Count() > 0)
                        {
                            this.dgwSelecionarTreinamentoFísico.DataSource = null;
                            this.dgwSelecionarTreinamentoFísico.DataSource = listaTreinamento;
                            this.dgwSelecionarTreinamentoFísico.Update();
                            this.dgwSelecionarTreinamentoFísico.Refresh();
                            txtSelecionarCodAluno.Focus();
                            return;
                        }
                        else
                        {
                            MessageBox.Show("Não existe nenhum aluno com este código: " + txtSelecionarCodAluno.Text, "Aviso", MessageBoxButtons.OK, MessageBoxIcon.Information);
                            txtSelecionarCodAluno.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);
                        txtSelecionarCodAluno.Focus();
                        return;
                    }
                }
                else
                {
                    try
                    {
                        ListaTreinamento listaTreinamento = treinamentoNegocio.PesquisarTreinamentoCodigoNomeAluno(null, txtSelecionarCodAluno.Text);
                        if (listaTreinamento.Count() > 0)
                        {
                            this.dgwSelecionarTreinamentoFísico.DataSource = null;
                            this.dgwSelecionarTreinamentoFísico.DataSource = listaTreinamento;
                            this.dgwSelecionarTreinamentoFísico.Update();
                            this.dgwSelecionarTreinamentoFísico.Refresh();
                            txtSelecionarCodAluno.Focus();
                            return;
                        }
                        else
                        {
                            MessageBox.Show("Não existe nenhum aluno com esse nome: " + txtSelecionarCodAluno.Text, "Avso", MessageBoxButtons.OK, MessageBoxIcon.Information);
                            txtSelecionarCodAluno.Focus();
                            return;
                        }
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show("Não foi possível pesquisar aluno por nome. Detalhes: " + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        txtSelecionarCodAluno.Focus();
                        return;
                    }
                }
            }
        }