public static string agregarClase(Clase clase, MySqlConnection conn) { clases.Add(clase); string sql = "Insert into clase(idclase,idcurso,idhorario,cantidadMatriculados,cantidadReservados,cantidadRetirados,estado,fechaInicio,fechaFin) values('" + clase.IdClase + "','" + clase.Curso.IdCurso + "','" + clase.Horario.IdHorario + "','" + clase.CantidadMatriculados + "','" + clase.CantidadReserva + "','" + clase.CantidadRetirados + "','" + clase.Estado + "','" + clase.FechaInicio + "','" + clase.FechaFin + "');"; try { MySqlCommand command = new MySqlCommand(sql, conn); //MySqlDataReader reader = command.ExecuteReader(); command.ExecuteNonQuery(); command.Dispose(); return "0"; } catch (Exception ex) { Console.WriteLine(ex.ToString()); } return "-1"; }
private void comboBox1_TextChanged(object sender, EventArgs e) { int codigo = int.Parse(comboBox1.Text.Split('-')[0]); claseAux = GestorClases.buscarClaseCod(codigo); textBox1.Text = claseAux.Horario.HoraInicio + "-" + claseAux.Horario.HoraFin; }
private void button1_Click(object sender, EventArgs e) { cursoMatricula = claseAux; this.Close(); }
private void comboBox1_SelectionChangeCommitted(object sender, System.EventArgs e) { claseSeleccionada = GestorClases.Clases.Find((cl) => cl.NombreClase() == comboBox1.Text); }
public static void inicializar(MySqlConnection conn) { string sql = "Select * from clase;"; try { MySqlCommand command = new MySqlCommand(sql, conn); MySqlDataReader reader = command.ExecuteReader(); while (reader.Read()) { int codigo = reader.GetInt32("idclase"); int curso = reader.GetInt32("idcurso"); int horario = reader.GetInt32("idhorario"); int cantM = reader.GetInt32("cantidadMatriculados"); int cantRes = reader.GetInt32("cantidadReserva"); int cantRet = reader.GetInt32("cantidadRetirados"); string estado = reader.GetString("estado"); DateTime fechaInicio = reader.GetDateTime("fechaInicio"); DateTime fechaFin = reader.GetDateTime("fechaFin"); Curso cu = GestorCursos.buscarCurso(curso); Horario h = GestorHorarios.buscarHorario(horario); Clase c = new Clase(codigo, fechaInicio, fechaFin); c.Curso = cu; c.Horario = h; c.CantidadMatriculados = cantM; c.CantidadReserva = cantRes; c.CantidadRetirados = cantRet; c.Estado = estado; clases.Add(c); } reader.Close(); command.Dispose(); } catch (Exception ex) { Console.WriteLine(ex.ToString()); } /*FileStream fs = null; try { fs = new FileStream("GestorClases.dat", FileMode.Open); } catch (FileNotFoundException e) { return; } try { BinaryFormatter formatter = new BinaryFormatter(); // Deserialize the hashtable from the file and // assign the reference to the local variable. clases = (List<Clase>)formatter.Deserialize(fs); } catch (SerializationException e) { Console.WriteLine("Failed to deserialize. Reason: " + e.Message); throw; } finally { fs.Close(); }*/ }