private void lblBuscarProfesor_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) { try { frmProfesoresA pp = new frmProfesoresA(); pp.ShowDialog(); if (pp.pPS != null) { pPS = pp.pPS; txtProfesor.Text = pp.pPS.Nombre.ToString() + " " + pp.pPS.Apellido.ToString(); cbAula.Focus(); p2 = true; if (p1 == true & p2 == true) { btnGuardar.Enabled = true; } } else { MessageBox.Show("Se Produjo un Error, Intentelo Nuevamente", "Registro de Grupos", MessageBoxButtons.OK, MessageBoxIcon.Error); } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
public void Limpiar() { txtNombre.Clear(); txtApellido.Clear(); pPS = null; txtNombre.Focus(); }
public static int ModificarProfesor(Profesores pProfesores) { int Retorno = 0; using (SqlConnection conexion = DBcomun.ObetenerConexion()) { SqlCommand comando = new SqlCommand(string.Format("update Profesores set Nombre = '{0}', Apellido = '{1}' where ID = {2}", pProfesores.Nombre, pProfesores.Apellido, pProfesores.ID), conexion); Retorno = comando.ExecuteNonQuery(); conexion.Close(); } return(Retorno); }
public static int AgregarProfesor(Profesores pProfesor) { int R = 0; using (SqlConnection conexion = DBcomun.ObetenerConexion()) { SqlCommand comando = new SqlCommand(string.Format("Insert into Profesores (Nombre, Apellido) values ('{0}', '{1}')", pProfesor.Nombre, pProfesor.Apellido), conexion); R = comando.ExecuteNonQuery(); conexion.Close(); } return(R); }
private void btnModificar_Click(object sender, EventArgs e) { try { if (txtNombre.Text == string.Empty) { MessageBox.Show("El Nombre esta vacio, Digite uno Valido", "Registro de Docentes", MessageBoxButtons.OK, MessageBoxIcon.Stop); txtNombre.Focus(); } else if (txtApellido.Text == string.Empty) { MessageBox.Show("El Apellido esta Vacio, Digite uno valido", "Registro de Docentes", MessageBoxButtons.OK, MessageBoxIcon.Stop); txtApellido.Focus(); } else { Profesores pP = new Profesores(); if (MessageBox.Show("Seguro que deseea Modificar el Docente?", "Registro de Docentes", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.Yes) { pP.Nombre = txtNombre.Text; pP.Apellido = txtApellido.Text; pP.ID = pPS.ID; int R = ProfesoresDB.ModificarProfesor(pP); if (R > 0) { MessageBox.Show("Docente Modificado Con Exito", "Registro de Docentes", MessageBoxButtons.OK, MessageBoxIcon.Information); Limpiar(); dgvProfesores.DataSource = ProfesoresDB.TodosLosProfesores(); btnRegsitrar.Enabled = true; btnEliminar.Enabled = false; btnModificar.Enabled = false; } else { MessageBox.Show("No se Pudo Modificar el Docente, Intentelo Nuevamente", "Registro de Docentes", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } } } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
public static Profesores ObtenerProfesor(Int32 ID) { Profesores pP = new Profesores(); using (SqlConnection conexion = DBcomun.ObetenerConexion()) { SqlCommand comando = new SqlCommand(string.Format("Select * from Profesores where ID = {0}", ID), conexion); SqlDataReader reader = comando.ExecuteReader(); while (reader.Read()) { pP.ID = reader.GetInt32(0); pP.Nombre = reader.GetString(1); pP.Apellido = reader.GetString(2); } conexion.Close(); } return(pP); }
private void btnSeleccionar_Click(object sender, EventArgs e) { try { if (dgvTabla.SelectedRows.Count == 1) { Int32 ID; ID = Convert.ToInt32(dgvTabla.CurrentRow.Cells[0].Value); pPS = ProfesoresDB.ObtenerProfesor(ID); this.Close(); } else { MessageBox.Show("No se ha Seleccionado un Profesor, Elija uno de la Tabla", "Profesores", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void btnRegsitrar_Click(object sender, EventArgs e) { try { if (txtNombre.Text == string.Empty) { MessageBox.Show("El Nombre esta vacio, Digite uno Valido", "Registro de Docentes", MessageBoxButtons.OK, MessageBoxIcon.Stop); txtNombre.Focus(); } else if (txtApellido.Text == string.Empty) { MessageBox.Show("El Apellido esta Vacio, Digite uno valido", "Registro de Docentes", MessageBoxButtons.OK, MessageBoxIcon.Stop); txtApellido.Focus(); } else { Profesores pP = new Profesores(); pP.Nombre = txtNombre.Text; pP.Apellido = txtApellido.Text; int R = ProfesoresDB.AgregarProfesor(pP); if (R > 0) { MessageBox.Show("Profesor Registrado Con Exito", "Registro de Docentes", MessageBoxButtons.OK, MessageBoxIcon.Information); dgvProfesores.DataSource = ProfesoresDB.TodosLosProfesores(); Limpiar(); } else { MessageBox.Show("No se Pudo Registrar el Docente, Intentelo Nuevamente", "Registro de Docentes", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
public static List <Profesores> BuscarProfesores(string nombre, string apellido) { List <Profesores> list = new List <Profesores>(); using (SqlConnection conexion = DBcomun.ObetenerConexion()) { SqlCommand comando = new SqlCommand(String.Format("Select * from Profesores where Nombre like '{0}%' or Apellido like '{1}%'", nombre, apellido), conexion); SqlDataReader reader = comando.ExecuteReader(); while (reader.Read()) { Profesores pP = new Profesores(); pP.ID = reader.GetInt32(0); pP.Nombre = reader.GetString(1); pP.Apellido = reader.GetString(2); list.Add(pP); } conexion.Close(); } return(list); }
public static List <Profesores> TodosLosProfesores() { List <Profesores> list = new List <Profesores>(); using (SqlConnection conexion = DBcomun.ObetenerConexion()) { SqlCommand comando = new SqlCommand("Select * from Profesores", conexion); SqlDataReader reader = comando.ExecuteReader(); while (reader.Read()) { Profesores pP = new Profesores(); pP.ID = reader.GetInt32(0); pP.Nombre = reader.GetString(1); pP.Apellido = reader.GetString(2); list.Add(pP); } conexion.Close(); } return(list); }