Ejemplo n.º 1
0
 public static List <Sessao> getSessoes(int aluno)
 {
     using (SqlConnection connection = new SqlConnection(dataconn)) {
         try {
             connection.Open();
             using (SqlCommand command = new SqlCommand(
                        "SELECT * FROM Sessao where aluno='" + aluno + "'", connection)) {
                 using (SqlDataReader reader = command.ExecuteReader()) {
                     List <Sessao> sessoes = new List <Sessao>();
                     while (reader.Read())
                     {
                         int      idsessao = reader.GetInt32(0);
                         DateTime data     = reader.GetDateTime(1);
                         Sessao   s        = new Sessao(idsessao, data);
                         AlunoDAO.getRecords(s);
                         sessoes.Add(s);
                     }
                     return(sessoes.OrderByDescending(s => s.data).ToList());
                 }
             }
         }
         catch (SqlException ex) {
             MessageBox.Show(ex.Message, "Erro SQL! getsessoes", MessageBoxButtons.OK, MessageBoxIcon.Error);
             return(null);
         }
     }
 }
Ejemplo n.º 2
0
 public static int putAluno(Aluno a)
 {
     using (SqlConnection connection = new SqlConnection(dataconn)) {
         try {
             if (AlunoDAO.alunoExiste(a.nome))
             {
                 return(0);
             }
             else
             {
                 connection.Open();
                 string alunoquery = "INSERT ALUNO (nome,pontosSoma,pontosSub,pontosMult,pontosDiv) OUTPUT INSERTED.ID ";
                 alunoquery += "VALUES (\'" + a.nome + "\'," + a.pontosSoma + "," + a.pontosSub + "," + a.pontosMult + "," + a.pontosDiv + ")";
                 using (SqlCommand command = connection.CreateCommand()) {
                     command.CommandText = alunoquery;
                     return((int)command.ExecuteScalar());
                 }
             }
         }
         catch (SqlException ex) {
             MessageBox.Show(ex.Message, "Erro SQL!", MessageBoxButtons.OK, MessageBoxIcon.Error);
             return(0);
         }
     }
 }