Ejemplo n.º 1
0
 public static List <Pagos> getAllPagosByDate(DateTime date)
 {
     //Obtiene los pagos de una fecha en especifico y devuelve la lista.
     try
     {
         Sql           con = new Sql();
         SqlDataReader r   = con.getReader(String.Format("Select id_pago from pagos where fecha='{0:yyyy-MM-dd}'", date));
         List <Pagos>  tmp = new List <Pagos>();
         while (r.Read())
         {
             Pagos pago = getInformation((int)r["id_pago"]);
             if (pago != null) //Se valida que la función si este devolviendo un pago correcto.
             {
                 tmp.Add(pago);
             }
         }
         con.closeConnection();
         if (tmp.Count > 0)
         {
             return(tmp);
         }
     }
     catch (SqlException e)
     {
         Console.WriteLine(e.Message);
     }
     return(null);
 }
Ejemplo n.º 2
0
 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);
 }
Ejemplo n.º 3
0
 public static List <Pagos> getAllPagosInRange(DateTime first, DateTime final)
 {
     //Esta función devuelve los pagos en un rango determinado de fechas, puede usarse para ver los pagos que van del mes en curso.
     try
     {
         Sql           con = new Sql();
         SqlDataReader r   = con.getReader(String.Format("Select id_pago from pagos where fecha>='{0:yyyy-MM-dd}' and fecha<='{01:yyyy-MM-dd}'", first, final));
         List <Pagos>  tmp = new List <Pagos>();
         while (r.Read())
         {
             Pagos pago = getInformation((int)r["id_pago"]);
             if (pago != null)
             {
                 tmp.Add(pago);
             }
         }
         con.closeConnection();
         if (tmp.Count > 0)
         {
             return(tmp);
         }
     }
     catch (SqlException)
     {
         //Program.log.WriteLine(e.Message);
     }
     return(null);
 }
Ejemplo n.º 4
0
 public static String[] obtenerDocumentacion(int id_Alumno)
 {
     try
     {
         con = new Sql();
         r   = con.getReader("SELECT Acta, Copias_Acta, Copia_Cartilla, Curp FROM Documentacion WHERE Id_alumno = " + id_Alumno);
         r.Read();
         String Acta = "No Entregada", Copy_Acta = "No Entregada", Copy_Cartilla = "No Entregada", Curp = "Entregada";
         if ((bool)r["Acta"])
         {
             Acta = "Entregada";
         }
         if ((bool)r["Copias_Acta"])
         {
             Copy_Acta = "Entregada";
         }
         if ((bool)r["Copia_Cartilla"])
         {
             Copy_Cartilla = "Entregada";
         }
         Curp = r["Curp"].Equals("") ? "No Hay Datos" : (String)r["Curp"];
         String[] datos = { Acta, Copy_Acta, Copy_Cartilla, Curp };
         con.closeConnection();
         r.Close();
         return(datos);
     }
     catch
     {
     }
     return(null);
 }
Ejemplo n.º 5
0
 public static Boolean[] obtenerDocuBool(int id_Alumno)
 {
     try
     {
         con = new Sql();
         r   = con.getReader("SELECT Acta, Copias_Acta, Copia_Cartilla FROM Documentacion WHERE Id_alumno = " + id_Alumno);
         r.Read();
         Boolean Acta = false, Copy_Acta = false, Copy_Cartilla = false;
         if ((bool)r["Acta"])
         {
             Acta = true;
         }
         if ((bool)r["Copias_Acta"])
         {
             Copy_Acta = true;
         }
         if ((bool)r["Copia_Cartilla"])
         {
             Copy_Cartilla = true;
         }
         Boolean [] datos = { Acta, Copy_Acta, Copy_Cartilla };
         con.closeConnection();
         return(datos);
     }
     catch
     {
     }
     return(null);
 }
Ejemplo n.º 6
0
 public static Pagos getInformation(int id)
 {
     try
     {
         Sql           con = new Sql();
         SqlDataReader r   = con.getReader(String.Format("Select * from pagos where id_pago={0:g}", id));
         r.Read();
         Pagos pago = new Pagos();
         pago.idPago            = Convert.ToInt32(r["id_pago"]);
         pago.concepto          = "" + r["concepto"];
         pago.conceptoDescuento = "" + r["concepto_descuento"];
         pago.subtotal          = (float)Convert.ToDouble(r["subtotal"]);
         pago.descuento         = (float)Convert.ToDouble(r["descuento"]);
         pago.total             = (float)Convert.ToDouble(r["total"]);
         pago.date      = r.GetDateTime(6);
         pago.liquidado = (Convert.ToInt32(r["liquidado"]) == 1) ? true : false;
         return(pago);
     }
     catch (SqlException)
     {
         // Program.log.WriteLine(e.Message);
     }
     //Devolvería nulo solo en caso de que se lanze una excepción entonces no se agregaría.
     return(null);
 }
Ejemplo n.º 7
0
 public static String[] obtenerMadre(int id_Madre)
 {
     if (id_Madre == 0)
     {
         return(null);
     }
     try
     {
         con = new Sql();
         r   = con.getReader("SELECT Nombre, Apellido, Celular FROM Madres_Alumno WHERE Id_madre = " + id_Madre);
         r.Read();
         String tel = "";
         if (r["Celular"].ToString().Equals(""))
         {
             tel = "No hay dato";
         }
         else
         {
             tel = r["Celular"].ToString();
         }
         String[] datos = { r["Nombre"].ToString(), r["Apellido"].ToString(), tel };
         con.closeConnection();
         return(datos);
     }
     catch
     {
     }
     return(null);
 }
Ejemplo n.º 8
0
 public static List <Pagos> getAllPagosFromStudent(int id)
 {
     //Buscara todos los Pagos de un estudiante.
     try
     {
         Sql           con = new Sql();
         SqlDataReader r   = con.getReader(String.Format("Select id_pago from [pago-alumno] where id_alumno={0:g}", id));
         List <Pagos>  tmp = new List <Pagos>();
         while (r.Read())
         {
             Pagos pago = getInformation((int)r["id_pago"]);
             if (pago != null)
             {
                 tmp.Add(pago);
             }
         }
         con.closeConnection();
         if (tmp.Count > 0)
         {
             return(tmp);
         }
     }
     catch (SqlException)
     {
         //Program.log.WriteLine(e.Message);
     }
     return(null);
 }
Ejemplo n.º 9
0
        public static String ObtenerModalidadPago(int mod)
        {
            try
            {
                con = new Sql();
                r   = con.getReader("SELECT * FROM Informacion_pago WHERE Id_Modalidad = " + mod);
                r.Read();
                String modalidad = "";
                int    i         = 0;
                do
                {
                    if (i == 0 || i == 1)
                    {
                        modalidad = "Prekinder. Inscripción: $" + r["Inscripcion"] + " Colegiatura: $" + r["Colegiatura"];
                    }

                    else
                    {
                        modalidad = "Kinder. Inscripción: $" + r["Inscripcion"] + " Colegiatura: $" + r["Colegiatura"];
                    }
                    i++;
                } while (r.Read());
                r.Close(); // oJO
                con.closeConnection();
                return(modalidad);
            }
            catch
            {
            }

            return("");
        }
Ejemplo n.º 10
0
 public static List <Pagos> getAllPagosFromStudentInRange(int id, DateTime first, DateTime final)
 {
     //Buscara todos los pagos de un estudiante en un rango de fechas.
     try
     {
         Sql con = new Sql();
         //Primero hacemos una consulta en la tabla de cruce.
         SqlDataReader r    = con.getReader(String.Format("Select id_pago from [pago-alumno] where id_alumno={0:g}", id));
         Sql           con1 = new Sql();
         List <Pagos>  tmp  = new List <Pagos>();
         while (r.Read())
         {
             //Posteriormente comprobamos que dicho pago este en el rango de fechas solicitado.
             SqlDataReader r1 = con1.getReader(String.Format("Select id_pago from pagos where id_pago={0:g} and fecha>='{1:yyyy-MM-dd}' and fecha<='{2:yyyy-MM-dd}'",
                                                             r["id_pago"], first, final));
             if (r1.Read())
             {
                 Pagos pago = getInformation((int)r1["id_pago"]);
                 tmp.Add(pago);
             }
         }
         if (tmp.Count > 0)
         {
             return(tmp);
         }
     }
     catch (SqlException)
     {
         // Program.log.WriteLine(e.Message);
     }
     return(null);
 }
Ejemplo n.º 11
0
        public RegistrarUsuario()
        {
            InitializeComponent();
            Sql           con = new Sql();
            SqlDataReader r   = con.getReader("SELECT * FROM Informacion_pago");

            r.Read();
            String[] pagos = new String[4];
            int      i     = 0;

            do
            {
                if (i == 0 || i == 1)
                {
                    pagos[i] = "Prekinder. Inscripción: $" + r["Inscripcion"] + " Colegiatura: $" + r["Colegiatura"];
                }

                else
                {
                    pagos[i] = "Kinder. Inscripción: $" + r["Inscripcion"] + " Colegiatura: $" + r["Colegiatura"];
                }
                i++;
            } while (r.Read());

            this.cmbPago.Items.AddRange(new object[] {
                pagos[0], pagos[1], pagos[2], pagos[3]
            });
            r.Close();
            con.closeConnection();
            reestablecer_Controles();
        }
Ejemplo n.º 12
0
        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);
        }
Ejemplo n.º 13
0
 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);
 }
Ejemplo n.º 14
0
 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);
 }
Ejemplo n.º 15
0
        private void btnBuscarMadre_Click(object sender, EventArgs e)
        {
            txtNombreMadre.Focus();
            cmbMadre.SelectedIndex = -1;
            cmbMadre.Items.Clear();

            if (this.txtNombreMadre.Text == "" || this.txtApellidoMadre.Text == "")
            {
                return;
            }
            r = con.getReader("SELECT * FROM Madres_Alumno WHERE Nombre LIKE '%" + txtNombreMadre.Text + "%'" + " AND Apellido LIKE '%" + txtApellidoMadre.Text + "%'");
            while (r.Read())
            {
                cmbMadre.Items.Add(r["Id_madre"] + " - " + r["Apellido"] + " , " + r["Nombre"]);
            }
            if (cmbMadre.Items.Count == 0)
            {
                cmbMadre.Items.Add("Sin Resultado");
            }
            cmbMadre.SelectedIndex = 0;
            r.Close();
        }
Ejemplo n.º 16
0
 public static float obtenerRestanteDelEstadoDeCuenta(int idPago, float total)
 {
     try {
         Sql           con = new Sql();
         SqlDataReader 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}", idPago));
         float monto = 0;
         while (r.Read())
         {
             monto += (float)Convert.ToDouble(r["monto"]);
         }
         return(total - monto);
     } catch (SqlException) { }
     return(total);
 }
Ejemplo n.º 17
0
 public void checarUsuario()
 {
     con = new Sql();
     r   = con.getReader("SELECT * FROM Usuarios WHERE Password = '******'");
     r.Read();
     if (!r.HasRows)
     {
         MessageBox.Show("Permiso denegado. Intente nuevamente", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
         r.Close();
         txtPass.Text = "";
         return;
     }
     else
     {
         Dispose();
         VentanaPrincipal.Interfaz.Controls.Add(new Menu());
     }
 }
Ejemplo n.º 18
0
 public static List <Pagos> obtenerEstadoDeCuenta(int idAlumno)
 {
     try {
         Sql           con = new Sql();
         List <Pagos>  tmp = new List <Pagos> ();
         SqlDataReader r   = con.getReader(String.Format("Select pagos.id_pago from pagos inner join [pago-alumno] on " +
                                                         "pagos.id_pago=[pago-alumno].id_pago where id_alumno={0:g} and fecha<='{1:yyyy-MM-dd}' and liquidado={2:g}", idAlumno,
                                                         new DateTime(2014, 06, 15) /*DateTime.Now*/, 0));
         while (r.Read())
         {
             tmp.Add(Pagos.getInformation((int)r[0]));
         }
         if (tmp.Count > 0)
         {
             return(tmp);
         }
     } catch (SqlException) { }
     return(null);
 }
Ejemplo n.º 19
0
        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);
        }
Ejemplo n.º 20
0
        public static Boolean generarPagosAnuales()
        {
            Sql con = new Sql(), con1 = new Sql();

            try {
                SqlDataReader r = con.getReader(String.Format("Select * from alumno inner join informacion_pago on " +
                                                              "modalidad_pago=id_modalidad"));
                while (r.Read())
                {
                    if (r.IsDBNull(13) || !r.GetBoolean(13))
                    {
                        continue;                                           //  Comprueba que haya pagado la inscripción.
                    }
                    int lim = 0;
                    //  Se obtiene cuantos pagos se harán al año.
                    if ((int)r["id_modalidad"] == 0 || (int)r["id_modalidad"] == 2)
                    {
                        lim = 11;
                    }
                    else
                    {
                        lim = 10;
                    }
                    //  Va a generar cada uno de los pagos que se deberán a hacer en el año.
                    for (int i = 0, mes = 8, year = DateTime.Now.Year; i < lim; i++, mes++)
                    {
                        DateTime fecha = new DateTime(year, mes, 1);
                        realizarPago(Convert.ToInt32(r["id_alumno"]), "Colegiatura", "Ninguno", (float)Convert.ToDouble(r["colegiatura"]), 0,
                                     (float)Convert.ToDouble(r["colegiatura"]), fecha);
                        if (mes == 12)
                        {
                            mes = 0;
                            year++;
                        }
                    }
                }
                con.closeConnection();
                con1.closeConnection();
                return(true);
            } catch (SqlException) { }
            return(false);
        }
Ejemplo n.º 21
0
 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);
 }
Ejemplo n.º 22
0
        public Alumno(int id_Alumno)
        {
            Sql con = new Sql();
            SqlDataReader r = con.getReader("SELECT * FROM Alumno WHERE Id_Alumno = " + id_Alumno);
            r.Read();
            int id_madre;
            int id_padre;
            if (r.IsDBNull(8))
                id_padre = 0;
            else
                id_padre = (int)r["Id_padre"];

            if (r.IsDBNull(9))
                id_madre = 0;
            else
                id_madre = (int)r["Id_madre"];

            init((int)r["Id_alumno"], (String)r["Nombre"], (String)r["Apellido"], Convert.ToDateTime(r["Nacimiento"]), (String)r["Tipo_Sangre"], (String)r["Calle"], (String)r["Colonia"], (String)r["Telefono"], id_padre, id_madre, (int)r["Grado"], (String)r["Grupo"], (int)r["Modalidad_pago"]);
            r.Close();
        }
Ejemplo n.º 23
0
        public static List <Alumno> ReporteAlumnos(int grado, String grupo)
        {
            con = new Sql();
            r   = con.getReader("SELECT Id_Alumno FROM Alumno WHERE Grado = " + grado + " AND Grupo = '" + grupo + "' ORDER BY (Apellido)");
            List <Alumno> nuevo = new List <Alumno>();

            while (r.Read())
            {
                Alumno alumno = new Alumno((int)r["Id_Alumno"]);
                nuevo.Add(alumno);
            }
            r.Close();
            if (nuevo.Count > 0)
            {
                return(nuevo);
            }
            else
            {
                return(null);
            }
        }
Ejemplo n.º 24
0
        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
        }
Ejemplo n.º 25
0
        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");
                }
            }
        }
Ejemplo n.º 26
0
        public EditarUsuario(Alumno alumno, float adeudos)
        {
            InitializeComponent();
            this.alumno  = alumno;
            this.adeudos = adeudos;
            Sql           con = new Sql();
            SqlDataReader r   = con.getReader("SELECT * FROM Informacion_pago");

            r.Read();
            String[] pagos = new String[4];
            int      i     = 0;

            do
            {
                if (i == 0 || i == 1)
                {
                    pagos[i] = "Prekinder. Inscripción: $" + r["Inscripcion"] + " Colegiatura: $" + r["Colegiatura"];
                }

                else
                {
                    pagos[i] = "Kinder. Inscripción: $" + r["Inscripcion"] + " Colegiatura: $" + r["Colegiatura"];
                }
                i++;
            } while (r.Read());

            this.cmbPago.Items.AddRange(new object[] {
                pagos[0], pagos[1], pagos[2], pagos[3]
            });
            r.Close();

            String[]  rowCurp = Procesos_Alumno.obtenerDocumentacion(alumno.getId());
            Boolean[] rowDocu = Procesos_Alumno.obtenerDocuBool(alumno.getId());
            this.chkActa.Checked           = rowDocu[0];
            this.chkCopiaActa.Checked      = rowDocu[1];
            this.chkCopiasCartilla.Checked = rowDocu[2];
            this.txtCURP.Text = rowCurp[3];

            if (alumno.getGrupo().Equals("No") == true)
            {
                this.cmbGrupo.SelectedIndex = 0;
            }
            if (alumno.getGrupo().Equals("A ") == true)
            {
                this.cmbGrupo.SelectedIndex = 1;
            }
            if (alumno.getGrupo().Equals("B ") == true)
            {
                this.cmbGrupo.SelectedIndex = 2;
            }
            if (alumno.getGrupo().Equals("C ") == true)
            {
                this.cmbGrupo.SelectedIndex = 3;
            }
            this.cmbPago.SelectedIndex = alumno.getModalidad();
            this.txtNombre.Text        = alumno.getNombre().ToString();
            this.txtApellido.Text      = alumno.getApellido().ToString();
            this.cmbSangre.Text        = alumno.getSangre();
            DateTime nuevo = alumno.getNacimiento();

            this.cmbDay.SelectedIndex   = nuevo.Day - 1;
            this.cmbMes.SelectedIndex   = nuevo.Month - 1;
            this.cmbYear.SelectedIndex  = nuevo.Year - 2005;
            this.txtCalle.Text          = alumno.getCalle();
            this.txtColonia.Text        = alumno.getColonia();
            this.txtTel.Text            = alumno.getTelefono();
            this.cmbGrado.SelectedIndex = alumno.getGrado();
            this.Show();
        }