private void adicionar_Click(object sender, EventArgs e) { #region Validação dos componentes do cadastro if (comboGrupoMuscular.SelectedIndex == -1) { MessageBox.Show("Selecione um grupo muscular.", "Alerta", MessageBoxButtons.OK, MessageBoxIcon.Information); comboObjetivo.Focus(); return; } if (comboExercicio.SelectedIndex == -1) { MessageBox.Show("Selecione um exercício.", "Alerta", MessageBoxButtons.OK, MessageBoxIcon.Information); comboObjetivo.Focus(); return; } if (numericSeries.Value.Equals("") || numericSeries.Value == 0) { MessageBox.Show("Digite um número de série válido.", "Alerta", MessageBoxButtons.OK, MessageBoxIcon.Information); numericSeries.Focus(); return; } if (numericRepeticoes.Value.Equals("") || numericRepeticoes.Value == 0) { MessageBox.Show("Digite um número de repetições válido.", "Alerta", MessageBoxButtons.OK, MessageBoxIcon.Information); numericRepeticoes.Focus(); return; } if (numericCarga.Value.Equals("")) { MessageBox.Show("Digite um número de carga válido.", "Alerta", MessageBoxButtons.OK, MessageBoxIcon.Information); numericCarga.Focus(); return; } #endregion #region Salva o exercicio #region Verifica se o nome da ficha de treino ja esta sendo utilizada //Verifica se o nome da ficha de treino ja esta sendo utilizada FichaDetalhe fichaD = new FichaDetalhe(); DataTable dt = new DataTable(); dt = fichaD.verificaTreino(" where d.idExercicio = " + comboExercicio.SelectedValue + " and f.nomeFicha = '" + comboFichaAluno.Text.ToString() + "' and p.idAluno = " + comboAluno.SelectedValue + " and f.situacao = 1 and p.situacao = 1;"); //MessageBox.Show("" + comboExercicio.SelectedValue + "" + comboFichaAluno.Text.ToString() + "" + comboAluno.SelectedValue); if (dt.Rows.Count >= 1) { MessageBox.Show("Esta ficha de treino já possui este exercício.", "Alerta", MessageBoxButtons.OK, MessageBoxIcon.Information); comboGrupoMuscular.Focus(); //comboNomeFicha.SelectedIndex = -1; return; } #endregion #region Adiciona na dataGrid //dataGridExercicios.Rows.Add(count, comboGrupoMuscular.Text, comboExercicio.Text, numericSeries.Value, numericRepeticoes.Value, numericCarga.Value, comboExercicio.SelectedValue, comboFichaAluno.SelectedValue); //count++; FichaDetalhe detalhe = new FichaDetalhe(); detalhe.IdFichaTreino = Convert.ToInt16(comboFichaAluno.SelectedValue); detalhe.IdExercicio = Convert.ToInt16(comboExercicio.SelectedValue); detalhe.Series = Convert.ToInt16(numericSeries.Value); detalhe.Repeticoes = Convert.ToInt16(numericRepeticoes.Value); detalhe.Carga = Convert.ToInt16(numericCarga.Value); detalhe.insert(); #endregion #region Limpar os componentes comboGrupoMuscular.SelectedIndex = -1; comboExercicio.SelectedIndex = -1; numericSeries.Value = 0; numericRepeticoes.Value = 0; numericCarga.Value = 0; comboGrupoMuscular.Focus(); #endregion try { int n = Convert.ToInt16(comboFichaAluno.SelectedValue); if (n > 0) { // MessageBox.Show("" + comboFichaAluno.SelectedValue); FichaDetalhe fichaDet = new FichaDetalhe(); dataGridExercicios.DataSource = fichaDet.select(" where f.idFichaTreino=" + comboFichaAluno.SelectedValue); } else { } } catch (Exception ex) { } #endregion //#region Adiciona o exercicio na dataGrid //FichaDetalhe fichaDet = new FichaDetalhe(); //dataGridExercicios.Rows.Add(count, comboGrupoMuscular.Text, comboExercicio.Text, numericSeries.Value, numericRepeticoes.Value, numericCarga.Value, comboExercicio.SelectedValue); //count++; //#endregion #region Limpa os componentes comboGrupoMuscular.SelectedIndex = -1; comboExercicio.SelectedIndex = -1; numericSeries.Value = 0; numericRepeticoes.Value = 0; numericCarga.Value = 0; comboGrupoMuscular.Focus(); #endregion }