Exemplo n.º 1
0
        public void RecarregarData()
        {
            dataGridView1.Rows.Clear();
            List <List <object> > exercicios = ExercicioController.BuscarExercicios();
            Exercicios            a          = new Exercicios();
            ExerciciosProgramados b          = new ExerciciosProgramados();

            for (int i = 0; i < exercicios.Count; i++)
            {
                a = (Exercicios)exercicios[i][0];
                b = (ExerciciosProgramados)exercicios[i][1];
                dataGridView1.Rows.Add(a.Nome, b.DiasDaSemana, a.Especificacoes, b.Qtde, b.DataInicio, b.DataTermino);
            }
        }
Exemplo n.º 2
0
        public static List <List <object> > RetornaExercicios(string CPFProfessor)
        {
            SqlConnection conexao = new SqlConnection();

            conexao.ConnectionString = Configuracao.ConnectionString;
            try
            {
                conexao.Open();
            }
            catch
            {
                throw new Exception("Erro na conexão com o banco de dados");
            }

            SqlCommand    comando = new SqlCommand();
            SqlDataReader reader  = null;

            comando.Connection = conexao;
            List <object>                Exercicios                 = new List <object>();
            List <Exercicios>            ExerciciosCopia            = new List <Exercicios>();
            List <ExerciciosProgramados> ExerciciosProgramadosCopia = new List <ExerciciosProgramados>();
            List <List <object> >        listaExercicios            = new List <List <object> >();
            List <int>            IDExercicios = new List <int>();
            Exercicios            a1           = new Exercicios();
            ExerciciosProgramados a2           = new ExerciciosProgramados();

            comando.CommandText = "select*from ExerciciosProgramados where Professor= '" + CPFProfessor + "' ;";
            reader = comando.ExecuteReader();
            while (reader.Read())
            {
                IDExercicios.Add((int)reader["Exercicio"]);
                a2              = new ExerciciosProgramados();
                a2.DataInicio   = (DateTime)reader["DataInicio"];
                a2.DataTermino  = (DateTime)reader["DataTermino"];
                a2.Qtde         = (int)reader["Qtde"];
                a2.DiasDaSemana = reader["DiasSemana"].ToString();
                ExerciciosProgramadosCopia.Add(a2);
            }
            reader.Close();


            comando.CommandText = "select*from Exercicios;";
            reader = comando.ExecuteReader();
            while (reader.Read())
            {
                for (int i = 0; i < IDExercicios.Count; i++)
                {
                    if (IDExercicios[i] == (int)reader["ID"])
                    {
                        a1                = new Exercicios();
                        a1.Nome           = reader["Nome"].ToString();
                        a1.Especificacoes = reader["Spec"].ToString();
                        ExerciciosCopia.Add(a1);
                    }
                }
            }
            for (int i = 0; i < ExerciciosProgramadosCopia.Count; i++)
            {
                Exercicios = new List <object>();
                Exercicios.Add(ExerciciosCopia[i]);
                Exercicios.Add(ExerciciosProgramadosCopia[i]);
                listaExercicios.Add(Exercicios);
            }
            reader.Close();
            conexao.Close();

            return(listaExercicios);
        }