public IActionResult AdicionarExercicioSocio(string IdPlano)
        {
            if (IdPlano == null)
            {
                return(NotFound());
            }
            ViewBag.PlanoId = IdPlano;
            PlanoTreino plano = _context.PlanosTreino.Include(x => x.Contem).SingleOrDefault(x => x.IdPlano == Convert.ToInt32(IdPlano));

            List <Exercicio> Lista = _context.Exercicios.ToList();

            foreach (Contem item in plano.Contem)
            {
                if (Lista.Contains(_context.Exercicios.SingleOrDefault(p => p.IdExercicio == item.IdExercicio)))
                {
                    Lista.Remove(_context.Exercicios.SingleOrDefault(p => p.IdExercicio == item.IdExercicio));
                }
            }

            ViewBag.Exercicios = Lista.Select(e => new SelectListItem()
            {
                Text  = e.Nome,
                Value = e.IdExercicio.ToString()
            });

            return(View(nameof(AdicionarExercicioSocio)));
        }
        private void FrmCadTreino_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (verificaClose == 0)
            {
                try
                {
                    FichaTreino fichas = new FichaTreino();
                    int         id;
                    id = fichas.getIdPlanoTreino();
                    if (id > 0)
                    {
                        PlanoTreino plano = new PlanoTreino();
                        plano.Id = Convert.ToInt16(id);
                        plano.updateDelete();

                        FichaTreino ficha = new FichaTreino();
                        ficha.IdPlanoTreino = Convert.ToInt16(id);
                        ficha.updateDelete();
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }

            //this.Close();
        }
        private void btCancelar_Click(object sender, EventArgs e)
        {
            try
            {
                FichaTreino fichas = new FichaTreino();
                int         id;
                id = fichas.getIdPlanoTreino();

                if (id > 0)
                {
                    PlanoTreino plano = new PlanoTreino();
                    plano.Id = Convert.ToInt16(id);
                    plano.updateDelete();

                    FichaTreino ficha = new FichaTreino();
                    ficha.IdPlanoTreino = Convert.ToInt16(id);
                    ficha.updateDelete();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }

            this.Close();
        }
        public IActionResult AdicionarExercicioSocio(IFormCollection data)
        {
            if (ModelState.IsValid)
            {
                PlanoTreino plano     = _context.PlanosTreino.Include(x => x.Contem).Include(p => p.NumSocioNavigation).Include(p => p.NumProfessorNavigation).SingleOrDefault(p => p.IdPlano == Convert.ToInt32(data["PlanoId"]));
                Exercicio   exercicio = _context.Exercicios.SingleOrDefault(e => e.IdExercicio == Convert.ToInt32(data["ExercicioEscolhido"]));
                Contem      c         = new Contem()
                {
                    IdExercicio      = Convert.ToInt32(data["ExercicioEscolhido"]),
                    IdPlano          = Convert.ToInt32(data["PlanoId"]),
                    NumRepeticoes    = Convert.ToInt32(data["NumRepeticoes"]),
                    PeriodoDescanso  = Convert.ToInt32(data["PeriodoDescanso"]),
                    QuantidadeSeries = Convert.ToInt32(data["QuantidadeSeries"])
                };
                plano.Contem.Add(c);
                _context.PlanosTreino.Update(plano);
                _context.SaveChanges();

                return(RedirectToAction(nameof(Index)));
            }
            List <Exercicio> Lista = _context.Exercicios.ToList();

            ViewBag.Exercicios = Lista.Select(e => new SelectListItem()
            {
                Text  = e.Nome,
                Value = e.IdExercicio.ToString()
            });

            return(RedirectToAction(nameof(Index)));
        }
        public ArrayList selectArray(string options = "")
        {
            ArrayList       dados = new ArrayList();
            MySqlConnection cn    = new MySqlConnection(dbConnection.Conecta);

            cn.Open();

            MySqlCommand    cmd = new MySqlCommand("select * from planoTreino " + options, cn);
            MySqlDataReader dr  = cmd.ExecuteReader();

            while (dr.Read())
            {
                PlanoTreino plano = new PlanoTreino();

                plano.Id          = Convert.ToInt16(dr["id_planoTreino"]);
                plano.IdAluno     = Convert.ToInt16(dr["idAluno"]);
                plano.IdTreinador = Convert.ToInt16(dr["idTreinador"]);
                plano.IdObjetivo  = Convert.ToInt16(dr["idObjetivo"]);
                plano.DataInicio  = dr["dataInicio"].ToString();
                plano.VezesSemana = Convert.ToInt16(dr["vezesSemana"]);
                plano.Situacao    = Convert.ToBoolean(dr["situacao"]);

                dados.Add(plano);
            }

            dr.Close();
            cn.Close();
            return(dados);
        }
        public async Task <IActionResult> DeleteConfirmed(int IdPlano)
        {
            PlanoTreino planoTreino = await _context.PlanosTreino.FindAsync(IdPlano);

            _context.PlanosTreino.Remove(planoTreino);
            await _context.SaveChangesAsync();

            return(RedirectToAction(nameof(Index)));
        }
Beispiel #7
0
        public ActionResult <string> SetPlano([FromBody] dynamic rec)
        {
            lock (_system)
            {
                var jobject = JObject.Parse(JsonSerializer.Serialize(rec));
                ActionResult <string> ret = BadRequest("Impossível inserir plano de treino");
                if (!_system.isUserOnline(jobject.valueST.ToString()))
                {
                    return(Unauthorized("Client Offline"));
                }

                string email = jobject.GetValue("email");


                JObject          plano = jobject.GetValue("planotreino");
                List <Exercicio> lista = new List <Exercicio>();

                JArray ja = plano.GetValue("lista_exercicios").ToObject <JArray>();
                try
                {
                    if (email.Equals(""))
                    {
                        throw new Exception("EMAIL BROKEN");
                    }
                    foreach (JObject v in ja)
                    {
                        Exercicio ex = new Exercicio(v.GetValue("nome").ToString(),
                                                     int.Parse(v.GetValue("nm_repeticoes").ToString()),
                                                     int.Parse(v.GetValue("nm_series").ToString())
                                                     );
                        lista.Add(ex);
                    }

                    PlanoTreino pt = new PlanoTreino(
                        plano.GetValue("nome").ToString(),
                        DateTime.Parse(plano.GetValue("data_fim").ToString()),
                        plano.GetValue("grupos_musculares").ToString(),
                        plano.GetValue("frequencia").ToString(),
                        email,
                        lista
                        );
                    if (_system.AddPlano(pt))
                    {
                        ret = Ok();
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.ToString());
                }

                return(ret);
            }
        }
        public IActionResult TornarPlanoAtivo(string IdPlano)
        {
            PlanoTreino plano = _context.PlanosTreino.Include(p => p.NumSocioNavigation).SingleOrDefault(p => p.IdPlano == Convert.ToInt32(IdPlano));
            Socio       socio = _context.Socios.Include(x => x.PlanoTreino).ThenInclude(p => p.NumProfessorNavigation).ThenInclude(x => x.NumProfessorNavigation).SingleOrDefault(p => p.NumCC == plano.NumSocio);

            socio.TornarPlanosInativos();
            plano.Ativo = true;
            _context.PlanosTreino.Update(plano);
            _context.Socios.Update(socio);
            _context.SaveChanges();
            return(PartialView("Index_Filtered", socio.PlanoTreino.OrderBy(x => x.Descricao)));
        }
        private void btAdicionar_Click(object sender, EventArgs e)
        {
            //Verifica se componente esta vazio
            if (maskedVezesSemana.Text.Trim().Length < 1)
            {
                MessageBox.Show("Digite uma quantidade de vezes na semana válido.", "Alerta", MessageBoxButtons.OK, MessageBoxIcon.Information);
                maskedVezesSemana.Focus();
                return;
            }

            //Verifica se componente esta vazio
            if (comboNomeFicha.SelectedIndex == -1)
            {
                MessageBox.Show("Digite um nome para ficha válido.", "Alerta", MessageBoxButtons.OK, MessageBoxIcon.Information);
                comboNomeFicha.Focus();
                return;
            }

            #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
            PlanoTreino planos = new PlanoTreino();
            DataTable   dt     = new DataTable();

            dt = planos.verificacaoNomeTreino(" where p.idAluno = " + comboAluno.SelectedValue + " and f.nomeFicha = '" + comboNomeFicha.SelectedItem.ToString() + "' and p.situacao = 1 and f.situacao = 1;");

            if (dt.Rows.Count >= 1)
            {
                MessageBox.Show("Este nome da ficha já esta sendo utilizado.", "Alerta", MessageBoxButtons.OK, MessageBoxIcon.Information);
                comboNomeFicha.Focus();
                //comboNomeFicha.SelectedIndex = -1;
                return;
            }
            #endregion

            FichaTreino ficha = new FichaTreino();
            int         id;
            id = ficha.getIdPlanoTreino();

            ficha.IdPlanoTreino           = id;
            ficha.NomeFicha               = Convert.ToChar(comboNomeFicha.SelectedItem.ToString());
            ficha.NumeroTreinosRealizados = 0;
            ficha.Situacao = true;
            //MessageBox.Show("" + id);
            ficha.insert();

            groupBoxFichasAluno.Enabled     = true;
            groupBoxListaExercicios.Enabled = true;
            groupBoxFichaDetalhe.Enabled    = true;
            comboNomeFicha.SelectedIndex    = -1;
            carregarFichas();
        }
        // GET: PlanoTreinos/Details/5
        public async Task <IActionResult> Details(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            PlanoTreino planoTreino = await _context.PlanosTreino
                                      .Include(p => p.NumProfessorNavigation)
                                      .Include(p => p.NumSocioNavigation)
                                      .FirstOrDefaultAsync(m => m.IdPlano == id);

            if (planoTreino == null)
            {
                return(NotFound());
            }

            return(View(planoTreino));
        }
        private void btDeletar_Click(object sender, EventArgs e)
        {
            try
            {
                DialogResult resposta = MessageBox.Show("Excluir o Treino '" + dataGridViewTreinos.CurrentRow.Cells[0].Value.ToString() + "' ?", "Atenção", MessageBoxButtons.YesNo, MessageBoxIcon.Question);

                if (resposta == DialogResult.Yes)
                {
                    try
                    {
                        PlanoTreino plano = new PlanoTreino();
                        plano.Id = Convert.ToInt16(dataGridViewTreinos.CurrentRow.Cells[0].Value);
                        plano.updateDelete();

                        //Geracao de log
                        Logs   logs = new Logs();
                        string linha;

                        using (StreamReader reader = new StreamReader("user.txt"))
                        {
                            linha = reader.ReadLine();
                        }

                        logs.IdUsuario = Convert.ToInt16(linha.ToString());
                        logs.IdAcao    = 25;
                        logs.Data      = DateTime.Today.ToString("dd/MM/yyyy");
                        logs.Hora      = DateTime.Now.ToString("HH:mm");
                        logs.insert();

                        FrmTabTreinos_Activated(sender, e);
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message);
                    }
                }
            }
            catch
            {
                MessageBox.Show("Não há Treinos cadastrados.", "Alerta", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
        public async Task <IActionResult> Create([Bind("IdPlano,NumSocio,NumProfessor,Ativo,Descricao")] PlanoTreino planoTreino)
        {
            if (ModelState.IsValid)
            {
                planoTreino.NumProfessor = HttpContext.Session.GetString("UserId");
                planoTreino.Ativo        = false;
                _context.Add(planoTreino);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            // lista de socios nao suspensos
            List <Socio> Lista = _context.Socios.Include(s => s.NumSocioNavigation).Where(s => s.DataSuspensao == null && s.Motivo == null).ToList();

            ViewBag.Socios = Lista.Select(s => new SelectListItem()
            {
                Text  = "CC: " + s.NumCC + " | " + s.NumSocioNavigation.Nome,
                Value = s.NumCC
            });

            return(View(planoTreino));
        }
        private void btOk_Click(object sender, EventArgs e)
        {
            if (comboAluno.SelectedIndex == -1)
            {
                MessageBox.Show("Selecione um aluno.", "Alerta", MessageBoxButtons.OK, MessageBoxIcon.Information);
                comboAluno.Focus();
                return;
            }

            //Verifica se componente esta vazio
            if (comboTreinador.SelectedIndex == -1)
            {
                MessageBox.Show("Selecione um Treinador.", "Alerta", MessageBoxButtons.OK, MessageBoxIcon.Information);
                comboTreinador.Focus();
                return;
            }

            //Verifica se componente esta vazio
            if (comboObjetivo.SelectedIndex == -1)
            {
                MessageBox.Show("Selecione um objetivo.", "Alerta", MessageBoxButtons.OK, MessageBoxIcon.Information);
                comboObjetivo.Focus();
                return;
            }

            //Verifica se componente esta vazio
            if (dateInicio.Text.Trim().Length < 10)
            {
                MessageBox.Show("Digite uma data válida.", "Alerta", MessageBoxButtons.OK, MessageBoxIcon.Information);
                dateInicio.Focus();
                return;
            }

            //Verifica se componente esta vazio
            if (maskedVezesSemana.Text.Trim().Length < 1)
            {
                MessageBox.Show("Digite uma quantidade de vezes na semana válido.", "Alerta", MessageBoxButtons.OK, MessageBoxIcon.Information);
                maskedVezesSemana.Focus();
                return;
            }

            //Verifica se o numero de vezes da semana é maior que 7
            if (Convert.ToInt16(maskedVezesSemana.Text) > 7)
            {
                MessageBox.Show("O número de vezes na semana não pode ser maior que 7.", "Alerta", MessageBoxButtons.OK, MessageBoxIcon.Information);
                maskedVezesSemana.Focus();
                return;
            }

            #region Verifica se o nome do aluno ja esta sendo utilizada
            //Verifica se o nome da ficha de treino ja esta sendo utilizada
            PlanoTreino planoD = new PlanoTreino();
            DataTable   dt     = new DataTable();

            dt = planoD.verificacaoNomeAluno(" where idAluno = " + comboAluno.SelectedValue + " and situacao = 1;");

            if (dt.Rows.Count >= 1)
            {
                MessageBox.Show("Este aluno já possui uma ficha de treino.", "Alerta", MessageBoxButtons.OK, MessageBoxIcon.Information);
                comboAluno.Focus();
                //comboNomeFicha.SelectedIndex = -1;
                return;
            }
            #endregion

            groupBoxDados.Enabled     = false;
            groupBoxNovaFicha.Enabled = true;
            comboNomeFicha.Focus();

            PlanoTreino plano = new PlanoTreino();
            plano.IdAluno     = Convert.ToInt16(comboAluno.SelectedValue);
            plano.IdTreinador = Convert.ToInt16(comboTreinador.SelectedValue);
            plano.IdObjetivo  = Convert.ToInt16(comboObjetivo.SelectedValue);
            plano.DataInicio  = dateInicio.Text.Trim();
            plano.VezesSemana = Convert.ToInt16(maskedVezesSemana.Text.Trim());
            plano.Situacao    = true;
            plano.insert();
        }
        private void FrmTabTreinos_Activated(object sender, EventArgs e)
        {
            PlanoTreino plano = new PlanoTreino();

            dataGridViewTreinos.DataSource = plano.selectAll();
        }
        private void textPesquisa_TextChanged(object sender, EventArgs e)
        {
            PlanoTreino plano = new PlanoTreino();

            dataGridViewTreinos.DataSource = plano.selectPesquisa(" WHERE planoTreino.situacao = 1 and alunos.nome like '%" + textPesquisa.Text + "%' group by id_planoTreino order by id_planoTreino");
        }
Beispiel #16
0
        public FrmAltTreino(int idPlanoTreino, int idFichaTreino, int idExercicio)
        {
            InitializeComponent();
            deletaExercicio    = new ArrayList();
            this.idPlanoTreino = idPlanoTreino;
            this.idFichaTreino = idFichaTreino;
            comboGrupoMuscular.SelectedIndex = -1;
            comboExercicio.SelectedIndex     = -1;
            FichaDetalhe ficha = new FichaDetalhe();

            count = ficha.getIdFichaDetalhe() + 1;

            PlanoTreino planoTreino = new PlanoTreino();

            foreach (PlanoTreino plano in planoTreino.selectArray("where id_planoTreino = " + idPlanoTreino))
            {
                dateInicio.Text        = plano.DataInicio;
                maskedVezesSemana.Text = "" + plano.VezesSemana;
                idAluno     = plano.IdAluno;
                idTreinador = plano.IdTreinador;
                idObjetivo  = plano.IdObjetivo;
            }

            FichaTreino fichaTreino = new FichaTreino();

            foreach (FichaTreino fichaDet in fichaTreino.selectArray("where idPlanoTreino = " + idPlanoTreino))
            {
                //maskedNomeFicha.Text = ""+ficha.NomeFicha;
                //comboFichaAluno.SelectedItem = "" + fichaDet.NomeFicha;
                //textNumeroTreinosR.Text = "" + fichaDet.NumeroTreinosRealizados;
            }

            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)
            {
            }

            //carregarExercicios(idFichaTreino);

            try
            {
                FichaTreino ficha1 = new FichaTreino();
                ArrayList   array  = ficha1.selectArray1(Convert.ToString(idPlanoTreino) + " order by nomeFicha");
                comboFichaAluno.DataSource    = array;
                comboFichaAluno.DisplayMember = "nomeFicha";
                comboFichaAluno.ValueMember   = "id";
            }
            catch
            {
            }
        }
Beispiel #17
0
        private void btSalvar_Click(object sender, EventArgs e)
        {
            #region Validação dos componentes do cadastro
            if (comboAluno.SelectedIndex == -1)
            {
                MessageBox.Show("Selecione um aluno.", "Alerta", MessageBoxButtons.OK, MessageBoxIcon.Information);
                comboAluno.Focus();
                return;
            }

            if (comboTreinador.SelectedIndex == -1)
            {
                MessageBox.Show("Selecione um Treinador.", "Alerta", MessageBoxButtons.OK, MessageBoxIcon.Information);
                comboTreinador.Focus();
                return;
            }

            if (comboObjetivo.SelectedIndex == -1)
            {
                MessageBox.Show("Selecione um objetivo.", "Alerta", MessageBoxButtons.OK, MessageBoxIcon.Information);
                comboObjetivo.Focus();
                return;
            }

            if (dateInicio.Text.Trim().Length < 10)
            {
                MessageBox.Show("Digite uma data válida.", "Alerta", MessageBoxButtons.OK, MessageBoxIcon.Information);
                dateInicio.Focus();
                return;
            }

            if (maskedVezesSemana.Text.Trim().Length < 1)
            {
                MessageBox.Show("Digite uma quantidade de vezes na semana válido.", "Alerta", MessageBoxButtons.OK, MessageBoxIcon.Information);
                maskedVezesSemana.Focus();
                return;
            }

            if (comboFichaAluno.SelectedIndex == -1)
            {
                MessageBox.Show("Digite um nome para ficha válido.", "Alerta", MessageBoxButtons.OK, MessageBoxIcon.Information);
                comboFichaAluno.Focus();
                return;
            }

            if (dataGridExercicios.RowCount == 0)
            {
                MessageBox.Show("Insira algum exercício no treino.", "Alerta", MessageBoxButtons.OK, MessageBoxIcon.Information);
                comboGrupoMuscular.Focus();
                return;
            }
            #endregion

            #region Alterar os dados
            PlanoTreino plano = new PlanoTreino();
            plano.Id          = idPlanoTreino;
            plano.IdAluno     = Convert.ToInt16(comboAluno.SelectedValue);
            plano.IdTreinador = Convert.ToInt16(comboTreinador.SelectedValue);
            plano.IdObjetivo  = Convert.ToInt16(comboObjetivo.SelectedValue);
            plano.DataInicio  = dateInicio.Text.Trim();
            plano.VezesSemana = Convert.ToInt16(maskedVezesSemana.Text.Trim());
            plano.Situacao    = true;
            plano.update();

            FichaTreino ficha = new FichaTreino();
            ficha.Id = idFichaTreino;
            //ficha.NomeFicha = Convert.ToChar(comboFichaAluno.SelectedItem.ToString());
            ficha.Situacao = true;
            ficha.update();
            //ficha.insertIdPlanoTreino();

            FichaDetalhe detalhe = new FichaDetalhe();

            for (int i = 0; i < dataGridExercicios.RowCount; i++)
            {
                //MessageBox.Show("6- " + dataGridExercicios.Rows[i].Cells["ColumnIdExercicio"].Value.ToString());
                //MessageBox.Show("4- " + Convert.ToInt16(dataGridExercicios.Rows[i].Cells[""].Value.ToString()));
                //MessageBox.Show("5- " + Convert.ToInt16(dataGridExercicios.Rows[i].Cells[5].Value.ToString()));
                ////MessageBox.Show("3- " + Convert.ToInt16(dataGridExercicios.Rows[i].Cells[3].Value.ToString()));

                detalhe.IdExercicio = Convert.ToInt16(dataGridExercicios.Rows[i].Cells["ColumnIdExercicios"].Value.ToString());
                detalhe.Series      = Convert.ToInt16(dataGridExercicios.Rows[i].Cells["ColumnSeries"].Value.ToString());
                detalhe.Repeticoes  = Convert.ToInt16(dataGridExercicios.Rows[i].Cells["ColumnRepeticoes"].Value.ToString());
                detalhe.Carga       = Convert.ToInt16(dataGridExercicios.Rows[i].Cells["ColumnCarga"].Value.ToString());
                detalhe.update();
            }

            MessageBox.Show("Treino Alterado com Sucesso.");
            #endregion

            #region Gravar o log
            //Geracao do log
            Logs   logs = new Logs();
            string linha;

            using (StreamReader reader = new StreamReader("user.txt"))
            {
                linha = reader.ReadLine();
            }

            logs.IdUsuario = Convert.ToInt16(linha.ToString());
            logs.IdAcao    = 16;
            logs.Data      = DateTime.Today.ToString("dd/MM/yyyy");
            logs.Hora      = DateTime.Now.ToString("HH:mm");
            logs.insert();
            #endregion

            this.Close();
        }
Beispiel #18
0
        public bool InsertPlanoTreino(PlanoTreino pt)
        {
            bool r = false;

            try
            {
                if (connection.State == ConnectionState.Closed)
                {
                    connection.Open();
                }

                string sqlCommand = "insert into Plano_Treino (nome, data_Fim, grupo_muscular, frequencia) " +
                                    "values(" + pt.ToSql() + ")";
                MySqlCommand command = new MySqlCommand(sqlCommand, connection);

                pt.InitParam(command);

                if (command.ExecuteNonQuery() > 0)
                {
                    r = true;
                }

                command = new MySqlCommand("select LAST_INSERT_ID()", connection);
                int idPlano_Treino = Convert.ToInt32(command.ExecuteScalar());

                for (int i = 0; i < pt.exercicios.Count; i++)
                {
                    sqlCommand = "insert into Exercicio (nome, repetiçoes, series) values(" + pt.exercicios[i].ToSql() + ")";
                    command    = new MySqlCommand(sqlCommand, connection);

                    pt.exercicios[i].InitParam(command);

                    command.ExecuteScalar();

                    command = new MySqlCommand("select LAST_INSERT_ID()", connection);
                    int idExercicio = Convert.ToInt32(command.ExecuteScalar());

                    sqlCommand = "insert into Exercicio_do_Plano_Treino values(@IDEX, @IDPLANO_TREINO)";
                    command    = new MySqlCommand(sqlCommand, connection);

                    command.Parameters.Add("@IDEX", MySqlDbType.Int16);
                    command.Parameters["@IDEX"].Value = idExercicio;

                    command.Parameters.Add("@IDPLANO_TREINO", MySqlDbType.Int16);
                    command.Parameters["@IDPLANO_TREINO"].Value = idPlano_Treino;

                    command.ExecuteScalar();
                }

                sqlCommand = "insert into PlanoTreino_do_Cliente values(@ID, @CLIENTE_EMAIL)";
                command    = new MySqlCommand(sqlCommand, connection);

                command.Parameters.Add("@ID", MySqlDbType.Int16);
                command.Parameters["@ID"].Value = idPlano_Treino;

                command.Parameters.Add("@CLIENTE_EMAIL", MySqlDbType.VarChar);
                command.Parameters["@CLIENTE_EMAIL"].Value = pt.cliente_email;

                // Verifica se foi atribuido o plano ao cliente
                if (command.ExecuteNonQuery() > 0)
                {
                    r = true;
                }
                else
                {
                    r = false;
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.ToString());
            }
            finally
            {
                connection.Close();
            }

            return(r);
        }
Beispiel #19
0
        public List <PlanoTreino> GetPlanoTreino(string cliente_email)
        {
            List <PlanoTreino> planos = new List <PlanoTreino>();

            try
            {
                if (connection.State == ConnectionState.Closed)
                {
                    connection.Open();
                }

                string sqlCommand = "select idPlano_Treino from PlanoTreino_do_Cliente where Cliente_email = @CLIENTE_EMAIL";

                MySqlCommand command = new MySqlCommand(sqlCommand, connection);

                command.Parameters.Add("@CLIENTE_EMAIL", MySqlDbType.VarChar);
                command.Parameters["@CLIENTE_EMAIL"].Value = cliente_email;

                MySqlDataReader reader = command.ExecuteReader();

                List <int> listaIdPlanos = new List <int>();

                while (reader.Read())
                {
                    listaIdPlanos.Add(reader.GetInt16(0));
                }

                reader.Close();

                DateTime now = DateTime.Now.Date;

                for (int i = 0; i < listaIdPlanos.Count; i++)
                {
                    string sqlCommandPlanoTreino = "select * from Plano_Treino where idPlano_Treino = @ID and " +
                                                   "data_Fim > @DATA";
                    MySqlCommand commandPlanoTreino = new MySqlCommand(sqlCommandPlanoTreino, connection);

                    string sqlCommandExercicio = "select * from Exercicio e left join Exercicio_do_Plano_Treino ept " +
                                                 "on e.idExercicio = ept.idExercicio where ept.idPlano_Treino = @ID";
                    MySqlCommand commandExercicio = new MySqlCommand(sqlCommandExercicio, connection);

                    commandPlanoTreino.Parameters.Add("@ID", MySqlDbType.Int16);
                    commandPlanoTreino.Parameters["@ID"].Value = listaIdPlanos[i];

                    commandPlanoTreino.Parameters.Add("@DATA", MySqlDbType.Date);
                    commandPlanoTreino.Parameters["@DATA"].Value = now;

                    reader = commandPlanoTreino.ExecuteReader();

                    reader.Read();

                    PlanoTreino pt = null;

                    if (reader.HasRows)
                    {
                        pt = new PlanoTreino(reader.GetString(1), reader.GetDateTime(2), reader.GetString(3),
                                             reader.GetString(4), cliente_email, new List <Exercicio>());

                        commandExercicio.Parameters.Add("@ID", MySqlDbType.Int16);
                        commandExercicio.Parameters["@ID"].Value = listaIdPlanos[i];

                        reader.Close();

                        reader = commandExercicio.ExecuteReader();

                        while (reader.HasRows && reader.Read())
                        {
                            Exercicio e = new Exercicio(reader.GetString(1), reader.GetInt16(2),
                                                        reader.GetInt16(3));

                            pt.exercicios.Add(e);
                        }

                        reader.Close();
                    }

                    reader.Close();

                    if (pt != null)
                    {
                        planos.Add(pt);
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.ToString());
            }
            finally
            {
                connection.Close();
            }

            return(planos);
        }