public string TraerCarreras(String Usuario) { String sql = "SELECT * FROM carrera"; MySqlConnection connection = null; MySqlDataReader lector = null; GestorCarreras carreras = new GestorCarreras(); try { MySqlCommand cmd = new MySqlCommand(); connection = Conexion.getConexion(); cmd.Connection = connection; cmd.CommandType = System.Data.CommandType.Text; cmd.CommandText = sql; //asigna el sql que voy a consultar cmd.CommandTimeout = 240; connection.Open(); lector = cmd.ExecuteReader(); //lector es un puntero a las filas. Se para en el principio. while (lector.Read()) { Console.WriteLine(lector); } } catch (Exception ex) { System.Diagnostics.Debug.WriteLine("SQL ERROR: " + sql); System.Diagnostics.Debug.WriteLine("Error: " + ex.Message); } if (connection != null) { connection.Close(); } return(lector.ToString()); }
public GestorCarreras ObtenerCarreras(String sql) { MySqlConnection connection = null; MySqlDataReader lector = null; System.Diagnostics.Debug.WriteLine("ListarWS.ObtenerRegistros SQL : " + sql); GestorCarreras carreras = new GestorCarreras(); try { connection = Conexion.getConexion(); MySqlCommand cmd = new MySqlCommand(sql, connection); cmd.CommandType = System.Data.CommandType.Text; connection.Open(); cmd.CommandTimeout = 240; lector = cmd.ExecuteReader(); if (lector.HasRows) { while (lector.Read()) { Carrera carrera = new Carrera(); carrera.idCarrera = lector.GetInt32(lector.GetOrdinal("idCarrera")); carrera.nombreCarrera = lector.GetString(lector.GetOrdinal("nombre")); carreras.lstCarreras.Add(carrera); //registros += "{\"idCarrera\":\"" + lector.GetValue(0).ToString() + "\",\"nombreCarrera\":\"" + lector.GetValue(1).ToString() + "\"}"; } } lector.Close(); } // while (lector.Read()) // { // registros += "{\"idCarrera\":\"" + lector.GetValue(0).ToString() + "\",\"nombreCarrera\":\"" + lector.GetValue(1).ToString() + "\"}"; // //reg = "id"; // //coma = ""; // //for (int i = 0; i < lector.FieldCount; i++) // //{ // // reg += coma + "\"" + lector.GetValue(i).ToString() + "\""; // // if (i == 0) coma = ","; // //} // //registros += coma_lista + "[" + reg + "]"; // //coma_lista = ","; // } // // registros = "{\"registros\":[" + registros + "]}"; // lector.Close(); //} //catch (Exception ex) //{ // registros = "{\"registros\":[]}"; // System.Diagnostics.Debug.WriteLine("SQL ERROR: " + sql); // System.Diagnostics.Debug.WriteLine("Error: " + ex.Message); //} //if (connection != null) connection.Close(); //return registros; catch (Exception ex) { System.Diagnostics.Debug.WriteLine("Error durante la generación automática del examen!" + ex.Message); } finally { if (lector != null) { lector.Close(); } if (connection != null) { connection.Close(); } } return(carreras); }
public string CorregirExamen(string id, string fecha) { MySqlConnection connection = null; MySqlDataReader lector = null; System.Diagnostics.Debug.WriteLine("fecha traidad del js " + fecha); int cantidadCorrectas = 0; string fecha1 = fecha.Replace('-', '/'); String registros = "", reg = "", coma_lista = ""; String fechi = ""; DateTime fechaTraida = new DateTime(); String fechaSql; fechaTraida = Funciones.deFechaStringADateTime(fecha1); fechaSql = Funciones.deFechaDateTimeAstringSQL(fechaTraida); int idCarrera = Int32.Parse(id); List <String> Legajos = new List <String>(); int modeloExamen = 0; GestorCarreras carreras = new GestorCarreras(); string consulta1 = "SELECT alumno.nroLegajo , modeloexamen.idModeloExamen FROM alumno " + " INNER JOIN examen on alumno.idAlumno = examen.idAlumno " + "INNER join instanciaexamen on examen.idInstanciaExamen = instanciaexamen.idInstanciaExamen " + "inner join modeloexamen on instanciaexamen.idModeloExamen = modeloexamen.idModeloExamen " + "where instanciaexamen.fecha = '" + fechaSql + "' and modeloexamen.idCarrera = '" + idCarrera + "'"; //string fechaConsulta = "SELECT STR_TO_DATE('" + fecha1 + "', '%d/%m/%Y') as fecha"; try { MySqlCommand cmd = new MySqlCommand(); connection = Conexion.getConexion(); cmd.Connection = connection; cmd.CommandType = System.Data.CommandType.Text; cmd.CommandTimeout = 240; connection.Open(); cmd.CommandText = consulta1; lector = cmd.ExecuteReader(); if (lector.HasRows) { while (lector.Read()) { Legajos.Add(lector.GetString(0)); //// fecha=Funciones.(lector.GetMySqlDateTime(1)); modeloExamen = lector.GetInt32(1); //System.Diagnostics.Debug.WriteLine(Legajos); } } if (lector != null) { lector.Close(); } //////////////////////////////////////FOR DE SEGUNDA PARTE ////////////////////////////////// foreach (string legajo in Legajos) { String consulta2 = "SELECT alumno.idAlumno ,rtapregunta.idPregunta, rtaalumno.nroRespuesta 'elegida', rtapregunta.idRespuesta as 'respuestaVerdadera' ,COUNT(*) " + "FROM alumno, examen, rtaalumno, instanciaexamen, modeloexamen, examenpregunta, pregunta, rtapregunta " + "where alumno.idAlumno = examen.idAlumno and examen.idExamen = rtaalumno.idExamen " + "and examen.idInstanciaExamen = instanciaexamen.idInstanciaExamen " + "and instanciaexamen.idModeloExamen = modeloexamen.idModeloExamen " + "and modeloexamen.idModeloExamen = examenpregunta.idModeloExamen " + "and examenpregunta.idPregunta = pregunta.idPregunta " + "and pregunta.idPregunta = rtapregunta.idPregunta " + "and examen.fecha = '" + fechaSql + "'" + "and alumno.nroLegajo = '" + legajo + "' " + "and modeloexamen.idCarrera ='" + idCarrera + "' " + "and rtapregunta.correcta = 1 and rtaalumno.nroRespuesta = rtapregunta.idRespuesta"; cmd.CommandText = consulta2; lector = cmd.ExecuteReader(); if (lector.HasRows) { while (lector.Read()) { reg = "\"" + legajo + "\":" + "" + lector.GetValue(4).ToString() + ""; registros += coma_lista + "" + reg + ""; coma_lista = ","; //reg = "\"" + legajo + "\":" + "\"" + lector.GetValue(4).ToString() + "\""; //registros += coma_lista + "{" + reg + "}"; //coma_lista = ","; //Legajos.Add(lector.GetString(0)); ////// fecha=Funciones.(lector.GetMySqlDateTime(1)); //modeloExamen = lector.GetInt32(1); ////System.Diagnostics.Debug.WriteLine(Legajos); } } if (lector != null) { lector.Close(); } } registros = "{" + registros + "}"; ///////////////////////////// 2da parte ///////////////////////////////////////////// } catch (Exception ex) { System.Diagnostics.Debug.WriteLine("Error durante la correccion" + ex.Message); registros = "{\"registros\":[]}"; } finally { if (lector != null) { lector.Close(); } if (connection != null) { connection.Close(); } } System.Diagnostics.Debug.WriteLine(modeloExamen); return(registros); }
public List <DateTime> ObtenerFechasExamen(String id) { MySqlConnection connection = null; MySqlDataReader lector = null; System.Diagnostics.Debug.WriteLine("ListarWS.ObtenerRegistros SQL : " + id); List <DateTime> listFechas = new List <DateTime>(); List <String> listFechasString = new List <String>(); int idCarrera = Int32.Parse(id); GestorCarreras carreras = new GestorCarreras(); try { connection = Conexion.getConexion(); String consulta = "SELECT instanciaexamen.fecha FROM instanciaexamen INNER JOIN modeloexamen on instanciaexamen.idModeloExamen = modeloexamen.idModeloExamen WHERE modeloexamen.idCarrera= '" + idCarrera + "'"; MySqlCommand cmd = new MySqlCommand(consulta, connection); cmd.CommandType = System.Data.CommandType.Text; connection.Open(); cmd.CommandTimeout = 240; lector = cmd.ExecuteReader(); System.Diagnostics.Debug.WriteLine(consulta); if (lector.HasRows) { while (lector.Read()) { DateTime fecha = new DateTime(); String fechaS = ""; // fecha=Funciones.(lector.GetMySqlDateTime(1)); fecha = lector.GetDateTime("fecha"); System.Diagnostics.Debug.WriteLine(fecha); listFechas.Add(fecha); //carreras.lstCarreras.Add(carrera); //registros += "{\"idCarrera\":\"" + lector.GetValue(0).ToString() + "\",\"nombreCarrera\":\"" + lector.GetValue(1).ToString() + "\"}"; } } lector.Close(); } catch (Exception ex) { System.Diagnostics.Debug.WriteLine("Error durante la generación automática del examen!" + ex.Message); } finally { if (lector != null) { lector.Close(); } if (connection != null) { connection.Close(); } } return(listFechas); }