Beispiel #1
0
        private ClsEntidadEstudiantes GenerarDatos()
        {
            //VARIABLES
            ClsEntidadEstudiantes vlo_EntidadEstudiantes;

            // EN CASO DE QUE LA VARIABLE GLOVAL REGISTRO NUEVO ESTÉ EN TRUE SE INSTANCIA LA CLASE.
            if (RegistroNuevo == true)
            {
                vlo_EntidadEstudiantes = new ClsEntidadEstudiantes();
            }
            else
            {
                //EN CASO CONTRARIO SE IGUALA A LA DE ENTIDAD REGISTRADA.
                vlo_EntidadEstudiantes = EntidadRegistrada;
            }
            //SE ESTABLESE LOS VALORES DE LA ENTIDAD.
            vlo_EntidadEstudiantes.Canton = txtAACanton.Text;
            //vlo_EntidadEstudiantes.Carnet = txtAACarnet.Text;
            vlo_EntidadEstudiantes.Correo           = txtAACorreo.Text;
            vlo_EntidadEstudiantes.Distrito         = txtAADistrito.Text;
            vlo_EntidadEstudiantes.EstadoEstudiante = CmbEstado.Text;
            vlo_EntidadEstudiantes.FechaIngreso     = DateTime.Today;
            vlo_EntidadEstudiantes.FechaNacimiento  = txtAAFechaNacimiento.Value;
            vlo_EntidadEstudiantes.Identificacion   = txtAAIdentificacion.Text;
            vlo_EntidadEstudiantes.Nacionalidad     = txtAANacionalidad.Text;
            vlo_EntidadEstudiantes.Nombre           = txtAANombre.Text;
            vlo_EntidadEstudiantes.OtrasSenias      = txtAAOtrasSenias.Text;
            vlo_EntidadEstudiantes.PrimerApellido   = txtAAPrimerApellido.Text;
            vlo_EntidadEstudiantes.Provincia        = CmbAAProvincia.Text;
            vlo_EntidadEstudiantes.SegundoApellido  = txtAASegundoApellido.Text;
            vlo_EntidadEstudiantes.Telefono         = txtAATel.Text;

            return(vlo_EntidadEstudiantes);
        }
        //Insertar Estudiantes
        public string Insertar(ClsEntidadEstudiantes pvo_EntidadEstudiante)
        {
            //Se establece las variables de conexion y de acceso a comandos sql.
            SqlConnection vlo_Conexion = new SqlConnection(vgc_CadenaConexion);
            SqlCommand    vlo_Command  = new SqlCommand();
            //Variables
            string vlc_Carnet    = string.Empty;
            string vlc_Sentencia = string.Empty;

            //Inicio
            vlo_Command.Connection = vlo_Conexion;
            try
            {
                // SE INVOCA EL METODO DE GENERAR GARNET EL CUAL CREA UN NUEVO CARNET.
                pvo_EntidadEstudiante.Carnet = NuevoCarnet();
                //SE PASAN LOS VALORES OBTENIDOS DE LA CAPA SUPERIOR A LA BASE DE DATOS.
                vlc_Sentencia = "INSERT INTO ESTUDIANTES(CARNET,ID_ESTUDIANTE,NOMBRE_ESTUDIANTE,PRIMER_APELLIDO_E,SEGUNDO_APELLIDO_E,TELEFONO_ESTUDIANTE,CORREO_ESTUDIANTE,PROVINCIA_ESTUDIANTE,CANTON_ESTUDIANTE,DISTRITO_ESTUDIANTE,OTRAS_SENIAS,NACIONALIDAD,FECHA_NACIMIENTO,FECHA_INGRESO,ESTADO,BORRADO) VALUES(@Carnet, @Id_Estudiante, @Nombre_Estudiante, @Primer_Apellido_E, @Segundo_Apellido_E, @Telefono_Estudiante, @Correo_Estudiante, @Provincia_Estudiante, @Canton_Estudiante, @Distrito_Estudiante, @Otras_Senias_E, @Nacionalidad, @Fecha_Nacimiento, @Fecha_Ingreso, @Estado, @Borrado)";
                vlo_Command.Parameters.AddWithValue("@Carnet", pvo_EntidadEstudiante.Carnet);
                vlo_Command.Parameters.AddWithValue("@Id_Estudiante", pvo_EntidadEstudiante.Identificacion);
                vlo_Command.Parameters.AddWithValue("@Nombre_Estudiante", pvo_EntidadEstudiante.Nombre);
                vlo_Command.Parameters.AddWithValue("Primer_Apellido_E", pvo_EntidadEstudiante.PrimerApellido);
                vlo_Command.Parameters.AddWithValue("@Segundo_Apellido_E", pvo_EntidadEstudiante.SegundoApellido);
                vlo_Command.Parameters.AddWithValue("@Telefono_Estudiante", pvo_EntidadEstudiante.Telefono);
                vlo_Command.Parameters.AddWithValue("@Correo_Estudiante", pvo_EntidadEstudiante.Correo);
                vlo_Command.Parameters.AddWithValue("@Provincia_Estudiante", pvo_EntidadEstudiante.Provincia);
                vlo_Command.Parameters.AddWithValue("@Canton_Estudiante", pvo_EntidadEstudiante.Canton);
                vlo_Command.Parameters.AddWithValue("@Distrito_Estudiante", pvo_EntidadEstudiante.Distrito);
                vlo_Command.Parameters.AddWithValue("@Otras_Senias_E", pvo_EntidadEstudiante.OtrasSenias);
                vlo_Command.Parameters.AddWithValue("@Nacionalidad", pvo_EntidadEstudiante.Nacionalidad);
                vlo_Command.Parameters.AddWithValue("@Fecha_Nacimiento", pvo_EntidadEstudiante.FechaNacimiento);
                vlo_Command.Parameters.AddWithValue("@Fecha_Ingreso", pvo_EntidadEstudiante.FechaIngreso);
                vlo_Command.Parameters.AddWithValue("@Estado", pvo_EntidadEstudiante.EstadoEstudiante);
                vlo_Command.Parameters.AddWithValue("@Borrado", pvo_EntidadEstudiante.Borrado);
                vlo_Command.CommandText = vlc_Sentencia;
                //SE ABRE LA CONEXION
                vlo_Conexion.Open();
                // SE EJECUTA LA SENTENCIA CON LOS VALORES.
                vlo_Command.ExecuteScalar();
                vlo_Conexion.Close();
                // YA QUE EL VALOR DE CARNET ES GENERADO POR CODIGO ENTONCES SE GUARDA ESTE VALOR DE LA VARIABLE DONDE SE GUARDÓ EL CARNET
                vlc_Carnet = pvo_EntidadEstudiante.Carnet;
            }
            catch (Exception)
            {
                vlc_Carnet = string.Empty;
                throw;
            }
            finally
            {
                vlo_Conexion.Dispose();
                vlo_Command.Dispose();
            }
            return(vlc_Carnet);
        }
        public int Modificar(ClsEntidadEstudiantes pvo_EntidadEstudiante)
        {
            //VARIABLES
            SqlConnection vlo_Conexion  = new SqlConnection(vgc_CadenaConexion);
            SqlCommand    vlo_Command   = new SqlCommand();
            int           vln_Resultado = -1;

            //SE ESTABLECE LA CONEXION CON LA BASE DE DATOS.
            vlo_Command.Connection = vlo_Conexion;
            string vlc_Sentencia;

            //SE ESTABLECEN LOS VALORES QUE SE VAN A GUARDAR EN LA BASE DE DATOS QUE PROVIENEN DE LA CAPA SUPERIOR.
            vlo_Command.Parameters.AddWithValue("@Carnet", pvo_EntidadEstudiante.Carnet);
            vlo_Command.Parameters.AddWithValue("@Id_Estudiante", pvo_EntidadEstudiante.Identificacion);
            vlo_Command.Parameters.AddWithValue("@Nombre_Estudiante", pvo_EntidadEstudiante.Nombre);
            vlo_Command.Parameters.AddWithValue("Primer_Apellido_E", pvo_EntidadEstudiante.PrimerApellido);
            vlo_Command.Parameters.AddWithValue("@Segundo_Apellido_E", pvo_EntidadEstudiante.SegundoApellido);
            vlo_Command.Parameters.AddWithValue("@Telefono_Estudiante", pvo_EntidadEstudiante.Telefono);
            vlo_Command.Parameters.AddWithValue("@Correo_Estudiante", pvo_EntidadEstudiante.Correo);
            vlo_Command.Parameters.AddWithValue("@Provincia_Estudiante", pvo_EntidadEstudiante.Provincia);
            vlo_Command.Parameters.AddWithValue("@Canton_Estudiante", pvo_EntidadEstudiante.Canton);
            vlo_Command.Parameters.AddWithValue("@Distrito_Estudiante", pvo_EntidadEstudiante.Distrito);
            vlo_Command.Parameters.AddWithValue("@Otras_Senias_E", pvo_EntidadEstudiante.OtrasSenias);
            vlo_Command.Parameters.AddWithValue("@Nacionalidad", pvo_EntidadEstudiante.Nacionalidad);
            vlo_Command.Parameters.AddWithValue("@Fecha_Nacimiento", pvo_EntidadEstudiante.FechaNacimiento);
            vlo_Command.Parameters.AddWithValue("@Fecha_Ingreso", pvo_EntidadEstudiante.FechaIngreso);
            vlo_Command.Parameters.AddWithValue("@Estado", pvo_EntidadEstudiante.EstadoEstudiante);
            vlo_Command.Parameters.AddWithValue("@Borrado", pvo_EntidadEstudiante.Borrado);
            //SE ESTABLECE LA SENTENCIA SQL.
            vlc_Sentencia = "UPDATE ESTUDIANTES SET ID_ESTUDIANTE=@Id_Estudiante,NOMBRE_ESTUDIANTE=@Nombre_Estudiante,PRIMER_APELLIDO_E=@Primer_Apellido_E,SEGUNDO_APELLIDO_E=@Segundo_Apellido_E,TELEFONO_ESTUDIANTE=@Telefono_Estudiante,CORREO_ESTUDIANTE=@Correo_Estudiante,PROVINCIA_ESTUDIANTE=@Provincia_Estudiante,CANTON_ESTUDIANTE=@Canton_Estudiante,DISTRITO_ESTUDIANTE=@Distrito_Estudiante,OTRAS_SENIAS=@Otras_Senias_E,NACIONALIDAD=@Nacionalidad,FECHA_NACIMIENTO=@Fecha_Nacimiento,FECHA_INGRESO=@Fecha_Ingreso,ESTADO=@Estado,BORRADO=@Borrado WHERE CARNET=@Carnet";
            try
            {
                // SE EJECUTA LA SENTENCIA SQL CON LOS VALORES NECESARIO.
                vlo_Command.CommandText = vlc_Sentencia;
                vlo_Conexion.Open();
                vln_Resultado = vlo_Command.ExecuteNonQuery();
                vlo_Conexion.Close();
            }
            catch (Exception)
            {
                vln_Resultado = -1;
                throw;
            }
            finally
            {
                vlo_Conexion.Dispose();
                vlo_Command.Dispose();
            }
            //SE RETORNA UN ENTERO CON LA CANTIDAD DE VALORES MODIFICADOS.
            return(vln_Resultado);
        }
        public int EliminarEstudiante(ClsEntidadEstudiantes pvo_EntidadEstudiante)
        {
            int              vln_Resultado = 0;
            ClsADEstudiante  vlo_ADEstudiantes;
            ClsConfiguracion vlo_confi = new ClsConfiguracion();

            try
            {
                vlo_ADEstudiantes = new ClsADEstudiante(vlo_confi.getConnectionString);
                vln_Resultado     = vlo_ADEstudiantes.Eliminar(pvo_EntidadEstudiante);
            }
            catch (Exception)
            {
                throw;
            }
            return(vln_Resultado);
        }
        //EN SINTESIS EL RESTO DE METODOS DE ESTA CAPA HACEN LO MISMO.
        public int ModificarEstudiante(ClsEntidadEstudiantes pvo_EntidadEstudiantes)
        {
            int              vln_Resultado = 0;
            ClsADEstudiante  vlo_ADEstudiante;
            ClsConfiguracion vlo_Confi = new ClsConfiguracion();

            try
            {
                vlo_ADEstudiante = new ClsADEstudiante(vlo_Confi.getConnectionString);
                vln_Resultado    = vlo_ADEstudiante.Modificar(pvo_EntidadEstudiantes);
            }
            catch (Exception)
            {
                throw;
            }
            return(vln_Resultado);
        }
        public int Eliminar(ClsEntidadEstudiantes pvo_EntidadEstudiante)
        {
            //VARIABLES
            int           vln_Resultado = -1;
            SqlConnection vlo_Conexion  = new SqlConnection(vgc_CadenaConexion);
            SqlCommand    vlo_Command   = new SqlCommand();
            string        vlc_setencia  = string.Empty;

            //SE ESTABLECE LA CADENA DE CONEXION.
            vlo_Command.Connection = vlo_Conexion;
            vlo_Command.Parameters.AddWithValue("@carnet", pvo_EntidadEstudiante.Carnet);
            vlc_setencia = "select count(carnet) from matricula where carnet=@carnet";
            try
            {
                //SE ABRE LA CONEXION A LA BASE DE DATOS.
                vlo_Conexion.Open();
                vlo_Command.CommandText = vlc_setencia;
                //SE EJECUTA LA SENTENCIA SQL EL CUAL VERIFICA QUE CLASE DE BORRADO SE DEBE HACER.
                vln_Resultado = vlo_Command.ExecuteNonQuery();
                //SEGUN EL RESULTADO SE HACE UN BORRADO LOGICO O BORRADO DE LA BASE DE DATOS.
                if (vln_Resultado > 0)
                {
                    vlc_setencia = "update estudiantes set borrado=1 where carnet=@carnet";
                }
                else
                {
                    vlc_setencia = "DELETE FROM ESTUDIANTES WHERE CARNET=@CARNET";
                }
                //SE EJECUTA LA SENTENCIA CON EL VALOR QUE SE DESEA BORRAR.
                vlo_Command.CommandText = vlc_setencia;
                vln_Resultado           = vlo_Command.ExecuteNonQuery();
                vlo_Conexion.Close();
            }
            catch (Exception)
            {
                vln_Resultado = -1;
                throw;
            }
            finally
            {
                vlo_Command.Dispose();
                vlo_Conexion.Dispose();
            }
            return(vln_Resultado);
        }
        public string InsertarEstudiante(ClsEntidadEstudiantes pvo_EntidadEstudiantes)
        {
            //VARIABLES
            string           vlc_Resultado = string.Empty;
            ClsADEstudiante  vlo_ADEstudiante;
            ClsConfiguracion vlo_Confi = new ClsConfiguracion();

            try
            {
                //SE INSTANCIA LA VARIABLE DE ACCESO A DATOS CON LA CADENA DE CONEXION.
                vlo_ADEstudiante = new ClsADEstudiante(vlo_Confi.getConnectionString);
                //SE OBTIENE EL RESULTADO DE AGREGAR UN ESTUDIANTE INVOCANDO AL METODO.
                vlc_Resultado = vlo_ADEstudiante.Insertar(pvo_EntidadEstudiantes);
            }
            catch (Exception)
            {
                throw;
            }
            //SE RETORNA LA CANTIDAD DE FILAS AFECTADAS
            return(vlc_Resultado);
        }
Beispiel #8
0
        public void CargarRegistros(string pvc_Carnet)
        {
            //VARIABLES
            ClsEntidadEstudiantes vlo_EntidadEstudiante;
            ClsLogicaEstudiante   vlo_LogicaCliente = new ClsLogicaEstudiante();
            // ESTABLECE LA CONDICIÓN PARA CARGAR EL REGISTRO DEL ESTUDIANTE.
            string vlc_Condicion = string.Format("CARNET='{0}'", pvc_Carnet);

            try
            {
                //SE INVOCA AL METODO DE OBTENER UN ESTUDIANTE.
                vlo_EntidadEstudiante = vlo_LogicaCliente.ObtenerEstudiante(vlc_Condicion);
                if (vlo_EntidadEstudiante.Existe == true)
                {
                    txtAACanton.Text           = vlo_EntidadEstudiante.Canton;
                    txtAACarnet.Text           = vlo_EntidadEstudiante.Carnet;
                    txtAACorreo.Text           = vlo_EntidadEstudiante.Correo;
                    txtAADistrito.Text         = vlo_EntidadEstudiante.Distrito;
                    txtAAFechaIngreso.Text     = vlo_EntidadEstudiante.FechaIngreso.ToString();
                    txtAAFechaNacimiento.Value = vlo_EntidadEstudiante.FechaNacimiento;
                    txtAAIdentificacion.Text   = vlo_EntidadEstudiante.Identificacion;
                    txtAANacionalidad.Text     = vlo_EntidadEstudiante.Nacionalidad;
                    txtAANombre.Text           = vlo_EntidadEstudiante.Nombre;
                    txtAAOtrasSenias.Text      = vlo_EntidadEstudiante.OtrasSenias;
                    txtAAPrimerApellido.Text   = vlo_EntidadEstudiante.PrimerApellido;
                    txtAASegundoApellido.Text  = vlo_EntidadEstudiante.SegundoApellido;
                    txtAATel.Text       = vlo_EntidadEstudiante.Telefono;
                    CmbAAProvincia.Text = vlo_EntidadEstudiante.Provincia;
                    CmbEstado.Text      = vlo_EntidadEstudiante.EstadoEstudiante;
                    EntidadRegistrada   = vlo_EntidadEstudiante;
                    RegistroNuevo       = false;
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
        public ClsEntidadEstudiantes ObtenerRegistro(string pvc_Condicion)
        {
            //VARIABLES
            ClsEntidadEstudiantes vlo_EntidadEstudiantes = new ClsEntidadEstudiantes();
            SqlConnection         vlo_Conexion           = new SqlConnection(vgc_CadenaConexion);
            SqlCommand            vlo_Command            = new SqlCommand();
            SqlDataReader         vlo_DataReader;
            string vlc_sentencia = string.Empty;

            // SE ESTABLESE LA CONEXION CON LA BASE DE DATOS.
            vlo_Command.Connection = vlo_Conexion;

            //SE ESTABLESE LA SENETENCIA SQL.
            vlc_sentencia = "SELECT CARNET, ID_ESTUDIANTE, NOMBRE_ESTUDIANTE, PRIMER_APELLIDO_E, SEGUNDO_APELLIDO_E, TELEFONO_ESTUDIANTE, CORREO_ESTUDIANTE,PROVINCIA_ESTUDIANTE,CANTON_ESTUDIANTE,DISTRITO_ESTUDIANTE, OTRAS_SENIAS, NACIONALIDAD,FECHA_NACIMIENTO,FECHA_INGRESO,ESTADO,BORRADO FROM ESTUDIANTES";

            //SE VERIFICA SI EL PARAMETRO TIENEN VALORES PARA MODIFICAR LA SENTENCIA EN CASO DE SER NECESARIO.
            if (!string.IsNullOrEmpty(pvc_Condicion))
            {
                vlc_sentencia = string.Format("{0} where {1}", vlc_sentencia, pvc_Condicion);
            }
            try
            {
                //SE ABRE LA CONEXION CON LA BASE DE DATOS Y ESTA RETORNA UN REGISTRO QUE CORRSPONDE CON LA CONSULTA.
                vlo_Command.CommandText = vlc_sentencia;
                vlo_Conexion.Open();
                vlo_DataReader = vlo_Command.ExecuteReader();
                if (vlo_DataReader.HasRows)
                {
                    //SE LEEN LOS DATOS RESULTANTES Y SE GUARDAN EN LA ENTIDAD QUE LE CORRESPONDE.
                    vlo_DataReader.Read();
                    vlo_EntidadEstudiantes.Carnet           = vlo_DataReader.GetString(0);
                    vlo_EntidadEstudiantes.Identificacion   = vlo_DataReader.GetString(1);
                    vlo_EntidadEstudiantes.Nombre           = vlo_DataReader.GetString(2);
                    vlo_EntidadEstudiantes.PrimerApellido   = vlo_DataReader.GetString(3);
                    vlo_EntidadEstudiantes.SegundoApellido  = vlo_DataReader.GetString(4);
                    vlo_EntidadEstudiantes.Telefono         = vlo_DataReader.GetString(5);
                    vlo_EntidadEstudiantes.Correo           = vlo_DataReader.GetString(6);
                    vlo_EntidadEstudiantes.Provincia        = vlo_DataReader.GetString(7);
                    vlo_EntidadEstudiantes.Canton           = vlo_DataReader.GetString(8);
                    vlo_EntidadEstudiantes.Distrito         = vlo_DataReader.GetString(9);
                    vlo_EntidadEstudiantes.OtrasSenias      = vlo_DataReader.GetString(10);
                    vlo_EntidadEstudiantes.Nacionalidad     = vlo_DataReader.GetString(11);
                    vlo_EntidadEstudiantes.FechaNacimiento  = vlo_DataReader.GetDateTime(12);
                    vlo_EntidadEstudiantes.FechaIngreso     = vlo_DataReader.GetDateTime(13);
                    vlo_EntidadEstudiantes.EstadoEstudiante = vlo_DataReader.GetString(14);
                    vlo_EntidadEstudiantes.Borrado          = vlo_DataReader.GetBoolean(15);
                    vlo_EntidadEstudiantes.Existe           = true;
                }
                // SE CIERRA LA C0NEXION
                vlo_Conexion.Close();
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                vlo_Conexion.Dispose();
                vlo_Command.Dispose();
            }
            //SE RETORNA LA ENTIDAD CON LOS VALORES RESULTANTES.
            return(vlo_EntidadEstudiantes);
        }