public static List <Grupos> TodosLosGrupos() { List <Grupos> List = new List <Grupos>(); using (SqlConnection conexion = DBcomun.ObetenerConexion()) { SqlCommand comando = new SqlCommand("Select Grupos.ID as CodigoGrupo, Nivel, Profesor, Aula, Fecha_Inicio, Total_Inscritos, Horarios.Dias + ' ' + Horarios.Hora as Horario from Grupos inner join Horarios on Horarios.ID = Grupos.Codigo_Horario", conexion); SqlDataReader reader = comando.ExecuteReader(); while (reader.Read()) { Grupos pG = new Grupos(); pG.ID = int.Parse(reader["CodigoGrupo"].ToString()); pG.Nivel = reader["Nivel"].ToString(); pG.Profesor = reader["Profesor"].ToString(); pG.Aula = reader["Aula"].ToString(); pG.Horario = reader["Horario"].ToString(); pG.Fecha_Inicio = Convert.ToDateTime(reader["Fecha_Inicio"]).ToString("dd-MM-yyyy"); pG.Total_Inscritos = int.Parse(reader["Total_Inscritos"].ToString()); List.Add(pG); } conexion.Close(); } return(List); }
public static int AgregarGrupo(Grupos pGrupos) { int Grupo = 0; using (SqlConnection conexion = DBcomun.ObetenerConexion()) { SqlCommand comando = new SqlCommand(string.Format("insert into Grupos (Nivel, Profesor, Aula, Codigo_Horario, Fecha_Inicio, Total_Inscritos) values ('{0}', '{1}', '{2}', {3}, '{4}', {5})", pGrupos.Nivel, pGrupos.Profesor, pGrupos.Aula, pGrupos.Horario, pGrupos.Fecha_Inicio, pGrupos.Total_Inscritos), conexion); Grupo = comando.ExecuteNonQuery(); conexion.Close(); } return(Grupo); }
public static int ModificarGrupo(Grupos pGrupos) { int Grupos = 0; using (SqlConnection conexion = DBcomun.ObetenerConexion()) { SqlCommand comando = new SqlCommand(string.Format("update Grupos Set Nivel = '{0}', Profesor = '{1}', Aula = '{2}', Codigo_Horario = {3}, Fecha_Inicio = '{4}' where ID = {5}", pGrupos.Nivel, pGrupos.Profesor, pGrupos.Aula, pGrupos.Horario, pGrupos.Fecha_Inicio, pGrupos.ID), conexion); Grupos = comando.ExecuteNonQuery(); conexion.Close(); } return(Grupos); }
private void btnModificar_Click(object sender, EventArgs e) { try { Grupos pG = new Grupos(); if (pGS != null) { pG.ID = pGS.ID; pG.Nivel = txtNivel.Text; pG.Profesor = txtProfesor.Text; pG.Horario = pHs.ID.ToString(); pG.Fecha_Inicio = dtpFechaInicio.Value.Date.ToString("yyyy-MM-dd"); if (cbAula.SelectedIndex == -1) { MessageBox.Show("No se Ha Seleccionado una Aula, Seleccione uno de la lista", "Registro de Niveles", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } else { object obt = cbAula.SelectedItem; pG.Aula = obt.ToString(); } if (MessageBox.Show("Seguro que desea modificar el Grupo?", "Registro de Grupos", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.Yes) { int G = GruposDB.ModificarGrupo(pG); if (G > 0) { MessageBox.Show("Grupo Modificado con Exito", "Registro de Grupos", MessageBoxButtons.OK, MessageBoxIcon.Information); Limpiar(); } else { MessageBox.Show("No se Pudo Modificar el Grupo, Intentelo Nuevamente", "Registro de Grupos", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } } } else { MessageBox.Show("Seleccione un Horario de la Tabla", "Registro de Grupos", MessageBoxButtons.OK, MessageBoxIcon.Information); } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void btnGuardar_Click(object sender, EventArgs e) { try { if (p1 == true & p2 == true) { Grupos pG = new Grupos(); pG.Nivel = txtNivel.Text; pG.Profesor = txtProfesor.Text; pG.Total_Inscritos = 0; pG.Horario = pHs.ID.ToString(); if (cbAula.SelectedIndex == -1) { MessageBox.Show("No se Ha Seleccionado una Aula, Seleccione uno de la lista", "Registro de Niveles", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } else { object obt = cbAula.SelectedItem; pG.Aula = obt.ToString(); } pG.Fecha_Inicio = dtpFechaInicio.Value.Date.ToString("yyyy-MM-dd"); int G = GruposDB.AgregarGrupo(pG); if (G > 0) { MessageBox.Show("Grupo Registrado con Exito", "Registro de Grupos", MessageBoxButtons.OK, MessageBoxIcon.Information); p1 = false; p2 = false; btnGuardar.Enabled = false; Limpiar(); } else { MessageBox.Show("No se Pudo Registrar el Grupo, Intentelo Nuevamnete", "Registro de Grupos", MessageBoxButtons.OK, MessageBoxIcon.Information); } } else { MessageBox.Show("Complete el Horario y el Profesor, Elija uno valido", "Registro de Grupos", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void btnSeleccionarGrupos_Click(object sender, EventArgs e) { try { if (dgvNiveles.SelectedRows.Count == 1) { Int32 ID; ID = Convert.ToInt32(dgvNiveles.CurrentRow.Cells[0].Value); pGS = GruposDB.ObtenerGrupos(ID); if (pGS != null) { txtProfesor.Text = pGS.Profesor; txtNivel.Text = pGS.Nivel; pHs = HorariosDB.ObtenerHorario(int.Parse(pGS.Horario)); txtHorario.Text = pHs.Dias + " " + pHs.Hora; cbAula.Text = pGS.Aula; string fechaI = dtpFechaInicio.Value.Date.ToString("yyyy-MM-dd"); fechaI = pGS.Fecha_Inicio; btnGuardar.Enabled = false; btnModificar.Enabled = true; btnEliminar.Enabled = true; } else { MessageBox.Show("No se Pudo Cargar el Estudiante, Intentelo Nuevamente", "Registro de Grupos", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } } else { MessageBox.Show("No ha seleccionado un Grupo, Seleccione uno de la Tabla", "Registro de Grupos", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
public static List <Grupos> BuscarGrupos(string nivel, string profesor, string fechaInicio, string aula) { List <Grupos> List = new List <Grupos>(); using (SqlConnection conexion = DBcomun.ObetenerConexion()) { SqlCommand comando = new SqlCommand(string.Format("Select Grupos.ID as CodigoGrupo, Nivel, Profesor, Aula, Fecha_Inicio, Total_Inscritos, Horarios.Dias + ' ' + Horarios.Hora as Horario from Grupos inner join Horarios on Horarios.ID = Grupos.Codigo_Horario where Nivel like '{0}%' and Profesor like '{1}%' and Fecha_Inicio like '{2}%' and Aula like '{3}%'", nivel, profesor, fechaInicio, aula), conexion); SqlDataReader reader = comando.ExecuteReader(); while (reader.Read()) { Grupos pG = new Grupos(); pG.ID = int.Parse(reader["CodigoGrupo"].ToString()); pG.Nivel = reader["Nivel"].ToString(); pG.Profesor = reader["Profesor"].ToString(); pG.Aula = reader["Aula"].ToString(); pG.Horario = reader["Horario"].ToString(); pG.Fecha_Inicio = Convert.ToDateTime(reader["Fecha_Inicio"]).ToString("dd-MM-yyyy"); pG.Total_Inscritos = int.Parse(reader["Total_Inscritos"].ToString()); List.Add(pG); } conexion.Close(); } return(List); }
public static Grupos ObtenerGrupos(Int32 pID) { Grupos pG = new Grupos(); using (SqlConnection conexion = DBcomun.ObetenerConexion()) { SqlCommand comando = new SqlCommand(string.Format("Select Grupos.ID as CodigoGrupo, Nivel, Profesor, Aula, Fecha_Inicio, Total_Inscritos, Horarios.ID as Horario from Grupos inner join Horarios on Horarios.ID = Grupos.Codigo_Horario Where Grupos.ID = {0}", pID), conexion); SqlDataReader reader = comando.ExecuteReader(); while (reader.Read()) { pG.ID = int.Parse(reader["CodigoGrupo"].ToString()); pG.Nivel = reader["Nivel"].ToString(); pG.Profesor = reader["Profesor"].ToString(); pG.Aula = reader["Aula"].ToString(); pG.Horario = reader["Horario"].ToString(); pG.Fecha_Inicio = Convert.ToDateTime(reader["Fecha_Inicio"]).ToString("dd-MM-yyyy"); pG.Total_Inscritos = int.Parse(reader["Total_Inscritos"].ToString()); } conexion.Close(); } return(pG); }