public static datos.EdadFechaNac DatosNac(string curp)
        {
            datos.EdadFechaNac calculo     = new datos.EdadFechaNac();
            string             an          = "20" + curp.Substring(4, 2);
            string             mes         = curp.Substring(6, 2);
            string             dia         = curp.Substring(8, 2);
            DateTime           f           = DateTime.Now;
            string             fechaActual = f.ToString("yyyy-MM-dd");
            string             annActual   = fechaActual.Substring(0, 4);
            int    fechaNac   = Convert.ToInt32(an);
            int    fechaAhora = Convert.ToInt32(annActual);
            int    edad       = fechaAhora - fechaNac;
            string rEdad      = Convert.ToString(edad);

            calculo.AnnoNac = an;
            calculo.DiaNac  = dia;
            calculo.MesNac  = mes;
            calculo.Edad    = rEdad;
            return(calculo);
        }
Beispiel #2
0
        private void validar_alu_Click(object sender, EventArgs e)
        {
            int    exi = 0, exi1 = 0;
            string sexo;

            try { sexo = listsexo.SelectedItem.ToString(); } catch { MessageBox.Show("SELECCIONE SEXO"); return; }
            sexo = listsexo.SelectedItem.ToString();
            if (NomAlum_txt.Text == "" || curpA_txt.Text == "" || ApellidoMAlum_txt.Text == "" || ApellidoPAlum_txt.Text == "")
            {
                MessageBox.Show("Llene los campos correspondientes", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else
            {
                exi  = ObtenerDatos.ExistenciaAlumno(curpA_txt.Text.Trim());
                exi1 = ObtenerDatos.ExistenciaTutor(curpT_txt.Text.Trim());
                int lenght = curpA_txt.Text.Length;
                if (curpA_txt.Text.Equals("") || lenght < 18)
                {
                    MessageBox.Show("ESCRIBA UNA CURP VALIDA (18 CARACTERES)", "error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    label28.Text      = "CURP ERRONEA";
                    label28.ForeColor = Color.Red;
                    validarinfoalum   = 1;
                }

                else
                {
                    if (exi == 0)
                    {
                        exi1 = ObtenerDatos.ExistenciaTutor(curpA_txt.Text.Trim());
                        if (exi1 == 1)
                        {
                            MessageBox.Show("CURP REGISTRADA EN UN TUTOR", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            validarinfoalum = 1;
                        }
                        else
                        {
                            int x;
                            sexo = listsexo.SelectedItem.ToString();
                            x    = ObtenerDatos.ComprobarCURP(curpA_txt.Text, NomAlum_txt.Text, ApellidoPAlum_txt.Text, ApellidoMAlum_txt.Text, sexo);
                            if (x == 2)
                            {
                                MessageBox.Show("La CURP no concuerda con los datos ingresados", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                                label28.Text      = "CURP ERRONEA";
                                label28.ForeColor = Color.Red;
                                validarinfoalum   = 1;
                            }
                            else
                            {
                                permitir();
                                label28.Text              = "CURP CORRECTA";
                                label28.ForeColor         = Color.Green;
                                curpA_txt.Enabled         = false;
                                NomAlum_txt.Enabled       = false;
                                ApellidoMAlum_txt.Enabled = false;
                                ApellidoPAlum_txt.Enabled = false;
                                listsexo.Enabled          = false;
                                //Si la curp pasa los filtros anteriores vamos a obtener la edad y fecha de nacimiento a partir de ella

                                datos.EdadFechaNac resultados = ObtenerDatos.DatosNac(curpA_txt.Text);
                                EdadAlum_txt.Text     = resultados.Edad;
                                FechaNacAlum_txt.Text = resultados.AnnoNac + "-" + resultados.MesNac + "-" + resultados.DiaNac;
                                validarinfoalum       = 0;
                            }
                        }
                    }
                    else
                    {
                        MessageBox.Show("El alumno ya esta inscrito", "No validado", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        curpA_txt.Text  = "";
                        validarinfoalum = 1;
                    }
                }
            }
        }