Beispiel #1
0
        public Aluno Buscar(string palavra, string filtro)
        {
            Aluno aluno = new Aluno();
            SqlConnection conexao = new ConexaoBd().GetConnection();
            conexao.Open();
            SqlCommand command = new SqlCommand();
            command.Connection = conexao;
            command.CommandText = ("SELECT * from aluno WHERE " + filtro+ "= " + palavra);

            try
            {
                SqlDataReader reader = command.ExecuteReader();
                reader.Read();
                aluno.Id = (int)reader["id"];
                aluno.Nome = (string) reader["nome"];
                aluno.Cpf = (string) reader["cpf"];
                aluno.Rg = (string) reader["rg"];
                aluno.Curso = (int) reader["idCurso"];
                aluno.DataNascimento = (string)reader["dataNascimento"];
                return aluno;
            }
            catch (Exception exception)
            {
                Console.WriteLine(exception.Message);
            }
            finally
            {
                if (conexao.State == System.Data.ConnectionState.Open)
                {
                    conexao.Close();
                }
            }
            return null;
        }
Beispiel #2
0
 public bool Alterar(Aluno aluno, String palavra, String filtro)
 {
     SqlConnection conexao = new ConexaoBd().GetConnection();
     conexao.Open();
     SqlCommand command = new SqlCommand();
     command.Connection = conexao;
     command.CommandText =
         "UPDATE aluno SET nome = @nome , cpf = @cpf, rg = @rg, dataNascimento = @dataNascimento, idCurso = @idCurso WHERE " +
         filtro + "= " + palavra;
     command.Parameters.AddWithValue("@nome", aluno.Nome);
     command.Parameters.AddWithValue("@cpf", aluno.Cpf);
     command.Parameters.AddWithValue("@rg", aluno.Rg);
     command.Parameters.AddWithValue("@dataNascimento", aluno.DataNascimento);
     command.Parameters.AddWithValue("@idCurso", aluno.Curso);
     try
     {
         Console.WriteLine(aluno.DataNascimento);
         command.ExecuteNonQuery();
         return true;
     }
     catch (Exception exception)
     {
         Console.WriteLine(exception.Message);
     }
     finally
     {
         if (conexao.State == System.Data.ConnectionState.Open)
         {
             conexao.Close();
         }
     }
     return false;
 }
Beispiel #3
0
 public bool salvarAluno(Aluno aluno)
 {
     IDaoAluno dao = FactoryDao.GetDaoAluno();
     if (dao.Gravar(aluno))
     {
         return true;
     }
     else {
         return false;
     }
 }
Beispiel #4
0
 public ActionResult Cadastro()
 {
     Aluno aluno = new Aluno
     {
         Nome = "",
         Cpf = "",
         Rg = "",
         DataNascimento = System.DateTime.Now.ToString(),
         Curso = 1
     };
     return View(aluno);
 }
Beispiel #5
0
 public void TestarAlterar()
 {
     IDaoAluno dao = FactoryDao.GetDaoAluno();
     Aluno aluno = new Aluno()
     {
         Nome = "ze",
         Cpf = "2015",
         DataNascimento = "10/10/1987",
         Rg = "30211404",
         Curso = 3
     };
     Assert.IsTrue(dao.Alterar(aluno, "2013", "cpf"));
 }
Beispiel #6
0
 public void TestaGravacao()
 {
     IDaoAluno dao = FactoryDao.GetDaoAluno();
     Aluno aluno = new Aluno()
         {
             Nome = "Ze",
             Cpf = "2013",
             DataNascimento = "10/10/1910",
             Rg = "30211404",
             Curso = 2
         };
     Assert.IsTrue(dao.Gravar(aluno));
 }
Beispiel #7
0
        public List<Aluno> Listar(string palavra, string filtro)
        {
            List<Aluno> lista = new List<Aluno>();
            SqlConnection conexao = new ConexaoBd().GetConnection();
            conexao.Open();
            SqlCommand command = new SqlCommand {
                Connection = conexao,
                CommandText = ("SELECT * from aluno WHERE " + filtro+ " LIKE @palavra")
            };
            //command.Parameters.AddWithValue("@filtro", filtro);
            command.Parameters.AddWithValue("@palavra", String.Format("%{0}%", palavra));

            try
            {
                SqlDataReader reader = command.ExecuteReader();
                while (reader.Read())
                {
                    Aluno aluno = new Aluno()
                        {
                            Id = (int) reader["id"],
                            Nome = (string) reader["nome"],
                            Cpf =  (string)reader["cpf"],
                            Rg =  (string)reader["rg"],
                            Curso = (int) reader["idCurso"],
                            DataNascimento =  reader["dataNascimento"].ToString()
                        };
                    lista.Add(aluno);
                }

                return lista;
            }
            catch (Exception exception)
            {
                Console.WriteLine(exception.Message);
            }
            finally
            {
                if (conexao.State == System.Data.ConnectionState.Open)
                {
                    conexao.Close();
                }
            }
            return null;
        }
Beispiel #8
0
 public bool Gravar(Aluno aluno)
 {
     SqlConnection conexao = new ConexaoBd().GetConnection();
     conexao.Open();
     SqlCommand command = new SqlCommand
         {
             Connection = conexao,
             CommandText =
                 ("INSERT into aluno(nome, cpf, rg, dataNascimento, idCurso ) VALUES (@nome, @cpf, @rg, @dataNascimento, @idCurso );")
         };
     command.Parameters.AddWithValue("@nome", aluno.Nome);
     command.Parameters.AddWithValue("@cpf", aluno.Cpf);
     command.Parameters.AddWithValue("@rg", aluno.Rg);
     command.Parameters.AddWithValue("@dataNascimento", Convert.ToDateTime(aluno.DataNascimento));
     command.Parameters.AddWithValue("@idCurso ", 2);
     try
     {
         command.ExecuteNonQuery();
         return true;
     }
     catch (Exception exception)
     {
         Console.WriteLine(aluno.Nome);
         Console.WriteLine(exception.Message);
     }
     finally
     {
         if (conexao.State == System.Data.ConnectionState.Open)
         {
             conexao.Close();
         }
     }
     return false;
 }