public static Boolean realizarPago(int idAlumno, String concepto, String conceptoDescuento, float subtotal, float descuento, float total, DateTime date) { try{ //Recibe todos los valores del pago para registrarlo en la BD. Sql con = new Sql(); SqlDataReader r = con.getReader("Select max(id_pago) from pagos"); r.Read(); int id = 0; if (!r.IsDBNull(0)) { id = (int)r[0] + 1; } r.Close(); if (con.executeQuery(String.Format("Insert into pagos values({0:g},'{1:g}',{2:f},{3:f},'{4:g}',{5:f},'{6:yyyy-MM-dd}',{7:g})", id, concepto, subtotal, descuento, conceptoDescuento, total, date, 0))) { if (con.executeQuery(String.Format("Insert into [pago-alumno] values({0:g},{1:g})", id, idAlumno))) { return(true); } } con.closeConnection(); } catch (SqlException) { //Program.log.WriteLine(e.Message); } return(false); }
public static Boolean ModificarAdmin(String Nombre, String Apellido, String oldPass, String newPass) { try { con = new Sql(); if (MessageBox.Show("¿Seguro que desea modificar la contraseña?", "Confirmar", MessageBoxButtons.YesNo) == DialogResult.Yes) { if (con.executeQuery("UPDATE Usuarios SET Password = '******' WHERE Nombre = '" + Nombre + "' AND Apellido = '" + Apellido + "' AND Password = '******'")) { MessageBox.Show("Password modificada con éxito", "Éxito", MessageBoxButtons.OK, MessageBoxIcon.Information); con.closeConnection(); return(true); } else { con.closeConnection(); return(false); } } } catch { //MessageBox.Show(e.Message); } return(false); }
public static Boolean EliminarAdmin(String Password) { try { if (MessageBox.Show("¿Seguro que desea eliminar a este administrador?", "Confirmar", MessageBoxButtons.YesNo) == DialogResult.Yes) { con = new Sql(); if (con.executeQuery(String.Format("DELETE FROM USUARIOS WHERE Password = '******' " , Password))) { MessageBox.Show("Alumno eliminado con éxito", "Éxito", MessageBoxButtons.OK, MessageBoxIcon.Information); con.closeConnection(); return(true); } else { con.closeConnection(); return(false); } } } catch { // } return(false); }
public static Boolean Registro(String Nombre, String Apellido, String Pass) { try { con = new Sql(); r = con.getReader("SELECT MAX(id_Usuarios) FROM Usuarios"); r.Read(); int id_user = 0; if (!r.IsDBNull(0)) { id_user = (int)r[0] + 1; } r.Close(); if (con.executeQuery(String.Format("INSERT INTO USUARIOS VALUES ({0:g},'{1:g}','{2:g}','{3:g}')" , id_user, Nombre, Apellido, Pass))) { MessageBox.Show("Administrador registrado con éxito", "Éxito", MessageBoxButtons.OK, MessageBoxIcon.Information); con.closeConnection(); return(true); } else { con.closeConnection(); return(false); } } catch { // } return(false); }
public static Boolean RegistrarDocumentacion(int idAlumno, bool Acta, bool copyActa, bool copyCartilla, String CURP) { try { if (CURP.Equals("")) { CURP = "No Hay Dato"; } con = new Sql(); if (con.executeQuery("INSERT INTO DOCUMENTACION VALUES ( " + idAlumno + ",'" + Acta + "','" + copyActa + "','" + CURP + "','" + copyCartilla + "')")) { MessageBox.Show("Documentación registrada con éxito", "Éxito", MessageBoxButtons.OK, MessageBoxIcon.Information); con.closeConnection(); return(true); } else { con.closeConnection(); return(false); } } catch { // } return(false); }
public static Boolean ModificarAlumno(Alumno alumno, float adeudos) { try { con = new Sql(); if (MessageBox.Show("¿Seguro que desea modificar los datos de este alumno?", "Confirmar", MessageBoxButtons.YesNo) == DialogResult.Yes) { if (adeudos == 0) { if (con.executeQuery("UPDATE Alumno SET Nombre = '" + alumno.getNombre() + "', Apellido = '" + alumno.getApellido() + "', Nacimiento = '" + alumno.getNacimiento().Year + "/" + alumno.getNacimiento().Month + "/" + alumno.getNacimiento().Day + "', Tipo_Sangre = '" + alumno.getSangre() + "', Calle = '" + alumno.getCalle() + "', Colonia = '" + alumno.getColonia() + "', Telefono = '" + alumno.getTelefono() + "', Grado = " + alumno.getGrado() + ", Grupo = '" + alumno.getGrupo() + "', Modalidad_pago = " + alumno.getModalidad() + " WHERE Id_alumno = " + alumno.getId())) { MessageBox.Show("Datos modificados con éxito", "Éxito", MessageBoxButtons.OK, MessageBoxIcon.Information); con.closeConnection(); return(true); } else { con.closeConnection(); return(false); } } else { MessageBox.Show("No puede modificar los datos de un alumno que presenta adeudos", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return(false); } } } catch { //MessageBox.Show(e.Message); } return(false); }
public static Boolean realizarAbono(int idPago, float monto, DateTime fecha) { try { Sql con = new Sql(); int id = 0; SqlDataReader r = con.getReader(String.Format("Select max(id_abono) from abonos")); r.Read(); if (!r.IsDBNull(0)) { id = (int)r[0] + 1; } r.Close(); if (con.executeQuery(String.Format("Insert into abonos values({0:g},{1:f},'{2:yyyy-MM-dd}')", id, monto, fecha))) { con.executeQuery(String.Format("Insert into pago_abono values({0:g},{1:g})", idPago, id)); } return(true); } catch (SqlException) { } return(false); }
private Boolean actualizarPago(String campo) { try { //Actualizara el pago, pero previamente se debe hacer una busqueda para tener el id. Sql con = new Sql(); int liquidadoBit = (liquidado) ? 1 : 0; //A continuación se genera el query dependiendo del campo que se desea actualizar. String query = ""; if (campo.CompareTo("concepto") == 0) { query = String.Format("Update pagos set {0:g}='{1:g}' where id_pago={2:g}", campo, this.concepto, this.idPago); } else if (campo.CompareTo("subtotal") == 0) { query = String.Format("Update pagos set {0:g}='{1:f}' where id_pago={2:g}", campo, this.subtotal, this.idPago); } else if (campo.CompareTo("descuento") == 0) { query = String.Format("Update pagos set {0:g}='{1:f}' where id_pago={2:g}", campo, this.descuento, this.idPago); } else if (campo.CompareTo("concepto_descuento") == 0) { query = String.Format("Update pagos set {0:g}='{1:g}' where id_pago={2:g}", campo, this.conceptoDescuento, this.idPago); } else if (campo.CompareTo("total") == 0) { query = String.Format("Update pagos set {0:g}='{1:f}' where id_pago={2:g}", campo, this.total, this.idPago); } else if (campo.CompareTo("date") == 0) { query = String.Format("Update pagos set {0:g}='{1:yyyy-MM-dd}' where id_pago={2:g}", campo, this.date, this.idPago); } else { query = String.Format("Update pagos set {0:g}='{1:g}' where id_pago={2:g}", campo, (liquidado ? 1 : 0), this.idPago); } if (con.executeQuery(query)) { MessageBox.Show("Pago actualizado con éxito", "Éxito", MessageBoxButtons.OK, MessageBoxIcon.Information); return(true); } con.closeConnection(); } catch (SqlException) { // Program.log.WriteLine(e.Message); } return(false); }
public static Boolean asignarMadre(int id_Alumno, int id_Madre) { try { con = new Sql(); if (con.executeQuery("UPDATE Alumno SET Id_Madre = " + id_Madre + " WHERE Id_alumno = " + id_Alumno)) { MessageBox.Show("Madre asignada correctamente", "Éxito", MessageBoxButtons.OK, MessageBoxIcon.Information); con.closeConnection(); return(true); } else { con.closeConnection(); return(false); } } catch { return(false); } }
public static Boolean Registro(String Nombre, String Apellido, DateTime Nacimiento, String Sangre, String Calle, String Colonia, String Telefono, int padre, int madre, int grado, String grupo, int mod_pago, bool Acta, bool copyActa, bool copyCartilla, String Curp) { try { con = new Sql(); r = con.getReader("SELECT MAX(Id_alumno) FROM Alumno"); r.Read(); int id_alumno = 0; if (!r.IsDBNull(0)) { id_alumno = (int)r[0] + 1; } r.Close(); if (con.executeQuery(String.Format("INSERT INTO ALUMNO VALUES ({0:g},'{1:g}','{2:g}','{3:yyyy-MM-dd}','{4:g}','{5:g}','{6:g}','{7:g}',NULL, NULL,{10:g},'{11:g}',{12:g}, NULL)" , id_alumno, Nombre, Apellido, Nacimiento, Sangre, Calle, Colonia, Telefono, null, null, grado, grupo, mod_pago, null))) { con.closeConnection(); con = new Sql(); if (con.executeQuery("INSERT INTO DOCUMENTACION VALUES ( " + id_alumno + ",'" + Acta + "','" + copyActa + "','" + Curp + "','" + copyCartilla + "')")) { MessageBox.Show("Alumno registrado con éxito", "Éxito", MessageBoxButtons.OK, MessageBoxIcon.Information); con.closeConnection(); return(true); } else { con.closeConnection(); return(false); } } else { con.closeConnection(); return(false); } } catch { // } return(false); }
public static Boolean inscribirAlumno(int idAlumno) { try { Sql con = new Sql(); SqlDataReader r = con.getReader(String.Format("Select activo from alumno where id_alumno={0:g}", idAlumno)); r.Read(); if (!r.IsDBNull(0)) { if (Convert.ToInt32(r["activo"]) == 1) { r.Close(); r = con.getReader(String.Format("Select fecha from pagos inner join [pago-alumno] on pagos.id_pago=" + "[pago-alumno].id_pago where id_alumno={0:g}", idAlumno)); r.Read(); if (r.GetDateTime(0).Year == DateTime.Now.Year) { MessageBox.Show("Error ese alumno ya pago la inscripción de este año", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return(false); } } } r.Close(); r = con.getReader(String.Format("Select inscripcion from alumno inner join informacion_pago on " + "modalidad_pago=id_modalidad where id_alumno={0:g}", idAlumno)); r.Read(); float pago = (float)Convert.ToDouble(r["inscripcion"]); r.Close(); if (realizarPago(idAlumno, "Inscripción", "Ninguno", pago, 0, pago, DateTime.Now)) { if (con.executeQuery(String.Format("Update alumno set activo=1 where id_alumno={0:g}", idAlumno))) { MessageBox.Show("Inscripción realizada con éxito", "Alumno inscrito", MessageBoxButtons.OK, MessageBoxIcon.Information); return(true); } } } catch (SqlException) { } MessageBox.Show("Error al realizar la inscripción", "Alumno no inscrito", MessageBoxButtons.OK, MessageBoxIcon.Error); return(false); }
public static Boolean realizarAbonosDeLaLista(float monto, List <int> idPagos) { try { Sql con = new Sql(); SqlDataReader r; float total = 0, pagado = 0; Boolean error = false; foreach (int id in idPagos) { r = con.getReader(String.Format("Select total from pagos where id_pago={0:g}", id)); r.Read(); total = (float)Convert.ToDouble(r["total"]); r.Close(); r = con.getReader(String.Format("Select monto from abonos inner join pago_abono on abonos.id_abono=pago_abono.id_abono" + " where id_pago={0:g}", id)); while (r.Read()) { pagado += (float)Convert.ToDouble(r["monto"]); } r.Close(); if ((total - pagado) <= monto) { con.executeQuery(String.Format("Update pagos set liquidado={0:g} where id_pago={1:g}", 1, id)); if (!realizarAbono(id, (total - pagado), DateTime.Now)) { error = true; } } else { realizarAbono(id, monto, DateTime.Now); } monto -= (total - pagado); pagado = 0; } if (error) { return(false); } } catch (SqlException) { } return(true); }
public static Boolean ModificarDocumentacion(int id_Alumno, bool Acta, bool copyActa, bool copyCartilla, String CURP) { try { con = new Sql(); if (con.executeQuery("UPDATE Documentacion SET Acta = '" + Acta + "', Copias_Acta = '" + copyActa + "', Copia_Cartilla = '" + copyCartilla + "', Curp = '" + CURP + "' WHERE Id_alumno = " + id_Alumno)) { MessageBox.Show("Documentación modificada con éxito", "Éxito", MessageBoxButtons.OK, MessageBoxIcon.Information); con.closeConnection(); return(true); } else { con.closeConnection(); return(false); } } catch { //MessageBox.Show(e.Message); } return(false); }
public static Boolean EliminarAlumno(Alumno alumno, float adeudos) { try { if (MessageBox.Show("¿Seguro que desea eliminar a este alumno?", "Confirmar", MessageBoxButtons.YesNo) == DialogResult.Yes) { if (adeudos == 0) { con = new Sql(); if (con.executeQuery(String.Format("DELETE FROM ALUMNO WHERE Id_alumno = {0:g} " , alumno.getId()))) { MessageBox.Show("Alumno eliminado con éxito", "Éxito", MessageBoxButtons.OK, MessageBoxIcon.Information); con.closeConnection(); return(true); } else { con.closeConnection(); return(false); } } else { MessageBox.Show("No puede eliminar a un alumno que presenta adeudos", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return(false); } } } catch { // } return(false); }
private void buttons_Click(object sender, EventArgs e) { if (sender.Equals(b_registrar)) { if (textoVacio()) { MessageBox.Show("Llene todos los campos antes de registrar la referencia"); return; } else if (alumnosVacio()) { MessageBox.Show("Agregue alumnos a la referencia antes de registrarla"); return; } Sql con = new Sql(); SqlDataReader r = con.getReader("SELECT MAX(Id_ref) FROM Referencias"); int id = 0; if (r.Read()) { if (!r.IsDBNull(0)) { id = r.GetInt32(0); } } Sql con2 = new Sql(); Sql con_check = new Sql(); SqlDataReader check = con_check.getReader("SELECT * FROM Referencias WHERE Nombre = '" + txt_nombre.Text + "' AND Apellido = '" + txt_apellido.Text + "' AND Calle = '" + txt_calle.Text + "'"); if (check.Read()) { if (!check.IsDBNull(0)) { MessageBox.Show("Este usuario ya ha sido registrado registrado"); return; } } if (con2.executeQuery("INSERT INTO Referencias VALUES (" + id + ", \'" + txt_nombre.Text + "\',\'" + txt_apellido.Text + "\', \'" + txt_calle.Text + "\', \'" + txt_colonia.Text + "\', \'" + txt_parentesco.Text + "\', \'" + mtxt_telefono.Text + "\', \'" + mtxt_celular.Text + "\')")) { MessageBox.Show("Referencia Registrada"); } else { MessageBox.Show("No se puedo Registrar la Referencia"); } String query = "INSERT INTO [Alumno-Referencia] (Id_alumno, Id_ref) VALUES"; Console.WriteLine("ID" + t1_id_selectlist[0]); for (int i = 0; i < t1_id_selectlist.Count; i++) { if (i == t1_id_selectlist.Count - 1) { query += "(" + t1_id_selectlist[i] + "," + id + ");"; } else { query += "(" + t1_id_selectlist[i] + "," + id + "),"; } } Console.WriteLine(query); Sql con3 = new Sql(); con3.executeQuery(query); } else if (sender.Equals(b_agregarref)) { for (int i = 0; i < chklist_resultados.Items.Count; i++) { if (chklist_resultados.GetItemCheckState(i) == CheckState.Checked) { // Do selected stuff if (!list_agregar.Items.Contains(chklist_resultados.Items[i])) { list_agregar.Items.Add((String)chklist_resultados.Items[i]); t1_id_selectlist.Add(t1_id_list[i]); } } } } else if (sender.Equals(b_buscar)) { chklist_resultados.Items.Clear(); if (txt_buscarnombre.Text == "" && txt_buscarapellido.Text == "") { return; } Sql con = new Sql(); String query = "SELECT * FROM Alumno WHERE Nombre LIKE '%" + txt_buscarnombre.Text + "%'" + " AND Apellido LIKE '%" + txt_buscarapellido.Text + "%'"; Console.WriteLine(query); SqlDataReader r = con.getReader(query); while (r.Read()) { String item = "Id: " + r["Id_alumno"] + " Grado: " + r["Grado"] + " Nombre: " + r["Nombre"] + " Apellido: " + r["Apellido"]; t1_id_list.Add((int)r["Id_alumno"]); if (!chklist_resultados.Items.Contains(item)) { chklist_resultados.Items.Add(item, false); } } } else if (sender.Equals(b2_buscar)) { dataGridView1.Rows.Clear(); if (txt2_buqueda.Text == "") { return; } int selectindex = combo2_busqueda.SelectedIndex; Sql con = new Sql(); Sql con2 = new Sql(); SqlDataReader r = null; if (selectindex == -1) { return; } else if (selectindex == 0) { r = con.getReader("SELECT * FROM Referencias WHERE Nombre LIKE '%" + txt2_buqueda.Text + "%' AND Apellido LIKE '%" + txt2_buscarapellido.Text + "%'"); while (r.Read()) { dataGridView1.Rows.Add(r["Id_ref"], r["Nombre"], r["Apellido"]); } } else if (selectindex == 1) { r = con.getReader("SELECT * FROM Alumno WHERE Nombre LIKE '%" + txt2_buqueda.Text + "%' AND Apellido LIKE '%" + txt2_buscarapellido.Text + "%'"); while (r.Read()) { dataGridView2.Rows.Add(r["Id_alumno"], r["Nombre"], r["Grado"]); } } } else if (sender.Equals(b2_veralum)) { Sql con = new Sql(); SqlDataReader r; dataGridView2.Rows.Clear(); if (dataGridView1.Rows.Count == 0) { return; } int id_ref = (int)dataGridView1.SelectedRows[0].Cells[0].Value; if (id_ref < 0) { return; } Sql con3 = new Sql(); r = con3.getReader("SELECT Alumno.* FROM ALUMNO INNER JOIN [Alumno-Referencia] ON alumno.Id_alumno = [Alumno-Referencia].Id_alumno INNER JOIN Referencias ON Referencias.Id_ref = [Alumno-Referencia].Id_ref WHERE Referencias.Id_ref = " + id_ref); while (r.Read()) { dataGridView2.Rows.Add(r["Id_alumno"], r["Nombre"] + " " + r["Apellido"], r["Grado"]); } } else if (sender.Equals(b2_verref)) { Sql con = new Sql(); SqlDataReader r; dataGridView1.Rows.Clear(); if (dataGridView2.Rows.Count == 0) { return; } int id_alum = (int)dataGridView2.SelectedRows[0].Cells[0].Value; if (id_alum < 0) { return; } Sql con3 = new Sql(); r = con3.getReader("SELECT * FROM Referencias, [Alumno-Referencia]" + "WHERE [Alumno-Referencia].Id_alumno = " + id_alum + " AND Referencias.Id_ref = [Alumno-Referencia].Id_ref"); while (r.Read()) { dataGridView1.Rows.Add(r["Id_ref"], r["Nombre"], r["Apellido"]); } } else if (sender.Equals(b2_elimref)) { Sql con = new Sql(); dataGridView2.Rows.Clear(); int id_ref = (int)dataGridView1.SelectedRows[0].Cells[0].Value; if (id_ref < 0) { return; } if (con.executeQuery("DELETE FROM Referencias WHERE Id_ref = " + id_ref + "; DELETE FROM [Alumno-Referencia] WHERE Id_ref = " + id_ref)) { MessageBox.Show("Registro Eliminado"); } else { MessageBox.Show("No se pudo eliminar el registro"); } MessageBox.Show("Referencia Eliminada"); } else if (sender.Equals(b2_cargaref)) { tabc_ref.SelectedIndex = 0; int id_ref = (int)dataGridView1.SelectedRows[0].Cells[0].Value; if (id_ref < 0) { return; } Sql con = new Sql(); SqlDataReader r = con.getReader("SELECT * FROM Referencias WHERE Id_ref = " + id_ref); r.Read(); txt_nombre.Text = r["Nombre"].ToString(); txt_apellido.Text = (string)r["Apellido"].ToString(); txt_calle.Text = (string)r["Calle"].ToString(); txt_colonia.Text = (string)r["Colonia"].ToString(); mtxt_celular.Text = (string)r["Celular"].ToString(); mtxt_telefono.Text = (string)r["Telefono"].ToString(); txt_parentesco.Text = (string)r["Parentesco"].ToString(); } else if (sender.Equals(b1_actref)) { if (textoVacio()) { MessageBox.Show("Llene todos los campos antes de registrar la referencia"); return; } else if (dataGridView1.Rows.Count == 0) { MessageBox.Show("Selecciona en la ventana de Busqueda, a la referencia a reemplazar"); } int id_ref = (int)dataGridView1.SelectedRows[0].Cells[0].Value; if (id_ref < 0) { MessageBox.Show("Selecciona una referencia en la pestaña de busquedas"); tabc_ref.SelectedIndex = 1; return; } Sql con = new Sql(); Console.WriteLine("UPDATE Referencias SET " + "Nombre = \'" + txt_nombre.Text + "\', " + "Apellido = \'" + txt_apellido.Text + "\', " + "Calle = \'" + txt_calle.Text + "\', " + "Colonia = \'" + txt_colonia.Text + "\', " + "Parentesco = \'" + txt_parentesco.Text + "\', " + "Telefono = \'" + mtxt_telefono.Text + "\', " + "Apellido = \'" + mtxt_celular.Text + "\' " + "WHERE Id_ref = " + id_ref); if (con.executeQuery("UPDATE Referencias SET " + "Nombre = \'" + txt_nombre.Text + "\', " + "Apellido = \'" + txt_apellido.Text + "\', " + "Calle = \'" + txt_calle.Text + "\', " + "Colonia = \'" + txt_colonia.Text + "\', " + "Parentesco = \'" + txt_parentesco.Text + "\', " + "Telefono = \'" + mtxt_telefono.Text + "\', " + "Celular = \'" + mtxt_celular.Text + "\' " + "WHERE Id_ref = " + id_ref)) { MessageBox.Show("Referencia Actualizada"); } else { MessageBox.Show("No se pudo actualizar el registro"); } } }
private void buttons_Click(object sender, EventArgs e) { if (sender.Equals(b1_registrar)) { Padres parent = new Padres(txt1_nombre.Text, txt1_apellido.Text, txt1_ocupacion.Text, txt1_empresa.Text, mtxt_telefono.Text, mtxt_celular.Text, txt1_email.Text); if (parent.areFieldsEmpty()) { MessageBox.Show("Llene todos los campos"); return; } else if (!parent.isValidEmail()) { MessageBox.Show("El email que ingresaste no es valido"); } Sql con = new Sql(); String query = "", query2 = "", query3 = ""; if (cmb1_MH.SelectedIndex == 0) { query = "SELECT MAX(Id_madre) FROM Madres_alumno"; query2 = "INSERT INTO Madres_alumno "; query3 = "SELECT * FROM Madres_alumno "; } else { query = "SELECT MAX(Id_padre) FROM Padres_alumno "; query2 = "INSERT INTO Padres_alumno"; query3 = "SELECT * FROM Padres_alumno "; } SqlDataReader r = con.getReader(query); r.Read(); int id = 0; if (r.Read()) { if (!r.IsDBNull(0)) { id = r.GetInt32(0); } } Sql con_check = new Sql(); Console.WriteLine(query3 + "WHERE Nombre = '" + txt1_nombre.Text + "' " + "AND Apellido = '" + txt1_apellido.Text + "' AND Email = '" + txt1_email.Text + "'"); SqlDataReader check = con_check.getReader(query3 + "WHERE Nombre = '" + txt1_nombre.Text + "' " + "AND Apellido = '" + txt1_apellido.Text + "' AND Email = '" + txt1_email.Text + "'"); if (check.Read()) { if (!check.IsDBNull(0)) { MessageBox.Show("Este usuario ya ha sido registrado registrado"); return; } } Sql con2 = new Sql(); if (con2.executeQuery(query2 + " VALUES (" + id + ", \'" + parent.getNombre() + "\',\'" + parent.getApellido() + "\', \'" + parent.getOcupacion() + "\', \'" + parent.getEmpresa() + "\', \'" + parent.getTelefono() + "\', \'" + parent.getCelular() + "\', \'" + parent.getEmail() + "\')")) { MessageBox.Show("Padre Registrado"); } else { MessageBox.Show("No se pudo registrar el padre"); } } else if (sender.Equals(b1_actualizar)) { Padres parent = new Padres(txt1_nombre.Text, txt1_apellido.Text, txt1_ocupacion.Text, txt1_empresa.Text, mtxt_telefono.Text, mtxt_celular.Text, txt1_email.Text); if (parent.areFieldsEmpty()) { MessageBox.Show("Llene todos los campos"); return; } else if (!parent.isValidEmail()) { MessageBox.Show("El email que ingresaste no es valido"); } int id_ref = (int)dataGridView1.SelectedRows[0].Cells[0].Value; Sql con = new Sql(); if (madre_o_padre == 0) { if (con.executeQuery("UPDATE Padres_alumno SET " + "Nombre = \'" + parent.getNombre() + "\', " + "Apellido = \'" + parent.getApellido() + "\', " + "Ocupacion = \'" + parent.getOcupacion() + "\', Empresa = \'" + parent.getEmpresa() + "\', " + "Telefono = \'" + parent.getTelefono() + "\', Celular = \'" + parent.getCelular() + "\', " + "Email = \'" + parent.getEmail() + "\' " + "WHERE Id_padre = " + id_ref)) { MessageBox.Show("Se ha actualizado el padre"); } } else { if (con.executeQuery("UPDATE Madres_alumno SET " + "Nombre = \'" + parent.getNombre() + "\', " + "Apellido = \'" + parent.getApellido() + "\', " + "Ocupacion = \'" + parent.getOcupacion() + "\', Empresa = \'" + parent.getEmpresa() + "\', " + "Telefono = \'" + parent.getTelefono() + "\', Celular = \'" + parent.getCelular() + "\', " + "Email = \'" + parent.getEmail() + "\' " + "WHERE Id_madre = " + id_ref)) { MessageBox.Show("Se ha actualizado la madre"); } } } else if (sender.Equals(b2_buscar)) { dataGridView1.Rows.Clear(); Sql con = new Sql(); String table = "", id = ""; if (cmb2_selec.SelectedIndex == 0) { table = "Madres_Alumno"; id = "Id_madre"; } else if (cmb2_selec.SelectedIndex == 1) { table = "Padres_Alumno"; id = "Id_padre"; } else if (cmb2_selec.SelectedIndex == 2) { Sql con2 = new Sql(); SqlDataReader r = con.getReader("SELECT P.Id_padre, P.Nombre, P.Apellido, P.Telefono, P.Celular, " + "P.Email FROM Alumno , Padres_alumno AS P WHERE Alumno.Id_padre = P.Id_padre " + "AND Alumno.Nombre LIKE '%" + txt2_buscarnombre.Text + "%' AND Alumno.Apellido LIKE " + "'%" + txt2_buscarapellido.Text + "%'"); SqlDataReader r2 = con2.getReader("SELECT M.Id_madre, M.Nombre, M.Apellido, M.Telefono, M.Celular, " + "M.Email FROM Alumno , Madres_alumno AS M WHERE Alumno.Id_madre = M.Id_madre " + "AND Alumno.Nombre LIKE '%" + txt2_buscarnombre.Text + "%' AND Alumno.Apellido LIKE " + "'%" + txt2_buscarapellido.Text + "%'"); while (r.Read()) { dataGridView1.Rows.Add(r["Id_padre"], r["Nombre"] + " " + r["Apellido"], r["Telefono"], r["Celular"], r["Email"]); } while (r2.Read()) { dataGridView1.Rows.Add(r2["Id_madre"], r2["Nombre"] + " " + r2["Apellido"], r2["Telefono"], r2["Celular"], r2["Email"]); } return; } SqlDataReader rn = con.getReader("SELECT * FROM " + table + " WHERE Nombre LIKE '%" + txt2_buscarnombre.Text + "%'" + " AND Apellido LIKE '%" + txt2_buscarapellido.Text + "%'"); while (rn.Read()) { dataGridView1.Rows.Add(rn[id], rn["Nombre"], rn["Apellido"], rn["Telefono"], rn["Celular"], rn["Email"]); } }//end of buscar else if (sender.Equals(b2_cargardatos)) { if (dataGridView1.Rows.Count == 0) { MessageBox.Show("Selecciona una fila válida"); return; } tabControl1.SelectedIndex = 0; int id_ref = (int)dataGridView1.SelectedRows[0].Cells[0].Value; String email = dataGridView1.SelectedRows[0].Cells[4].Value.ToString(); Sql con = new Sql(); Sql con2 = new Sql(); SqlDataReader r = null; if (cmb2_selec.SelectedIndex == 0) { r = con.getReader("SELECT * FROM Madres_alumno WHERE Id_madre = " + id_ref); madre_o_padre = 1; } else if (cmb2_selec.SelectedIndex == 1) { r = con.getReader("SELECT * FROM Padres_alumno WHERE Id_padre = " + id_ref); madre_o_padre = 0; } else if (cmb2_selec.SelectedIndex == 2) { r = con.getReader("SELECT * FROM Padres_alumno WHERE Email = '" + email + "'"); madre_o_padre = 0; if (!r.Read()) { r = null; r = con2.getReader("SELECT * FROM Madres_alumno WHERE Id_madre = " + id_ref); madre_o_padre = 1; } } r.Read(); txt1_nombre.Text = r["Nombre"].ToString(); txt1_apellido.Text = r["Apellido"].ToString(); txt1_ocupacion.Text = r["Ocupacion"].ToString(); txt1_empresa.Text = r["Empresa"].ToString(); txt1_email.Text = r["Email"].ToString(); mtxt_celular.Text = r["Celular"].ToString(); mtxt_telefono.Text = r["Telefono"].ToString(); } else if (sender.Equals(b2_eliminar))//else if its button eliminar { if (dataGridView1.Rows.Count == 0) { MessageBox.Show("Selecciona una fila válida"); return; } int id_ref = (int)dataGridView1.SelectedRows[0].Cells[0].Value; String email = dataGridView1.SelectedRows[0].Cells[4].Value.ToString(); Sql con = new Sql(); Sql con2 = new Sql(); SqlDataReader r = null; if (cmb2_selec.SelectedIndex == 0) { madre_o_padre = 0; } else if (cmb2_selec.SelectedIndex == 1) { madre_o_padre = 1; } else//tiene seleccionado alumnos { r = con.getReader("SELECT * FROM Padres_alumno WHERE Email = '" + email + "'"); madre_o_padre = 0; if (!r.Read()) { r = null; r = con2.getReader("SELECT * FROM Madres_alumno WHERE Id_madre = " + id_ref); madre_o_padre = 1; } } if (madre_o_padre == 0) { if (con.executeQuery("DELETE FROM Madres_alumno WHERE Id_madre = " + id_ref)) { MessageBox.Show("Registro eliminado"); } else { MessageBox.Show("No se pudo eliminar el registro"); } } else if (madre_o_padre == 1) { if (con.executeQuery("DELETE FROM Padres_alumno WHERE Id_padre = " + id_ref)) { MessageBox.Show("Registro eliminado"); } else { MessageBox.Show("No se pudo eliminar el registro"); } } dataGridView1.Rows.Clear(); }//fin del eliminar }