Пример #1
0
 public Business.Entities.Curso buscarCursoPorId(int id)
 {
     try
     {
         int idcurso = id;
         Conexion.getInstance().Connect();
         SqlCommand    cmd    = new SqlCommand("select * from dbo.Curso where idCurso='" + idcurso + "'", Conexion.getInstance().Conection);
         SqlDataReader reader = cmd.ExecuteReader();
         reader.Read();
         int    idCurso = (int)reader.GetValue(0);
         string nom     = reader.GetString(1);
         int    cupo    = (int)reader.GetValue(2);
         Business.Entities.Curso cur = new Curso(nom, cupo);
         if (reader["idMateria"] != DBNull.Value)
         {
             Business.Entities.Materia mat = MateriaDB.getInstance().buscarMateriaPorId((int)reader.GetValue(3));
             cur.Materia = mat;
         }
         if (reader["idComision"] != DBNull.Value)
         {
             Business.Entities.Comision com = ComisionDB.getInstance().buscarComisionPorId((int)reader.GetValue(4));
             cur.Comision = com;
         }
         //agregar los valores del comision y de la materia
         cur.IdCurso = idCurso;
         Conexion.getInstance().Disconnect();
         return(cur);
     }
     catch (Exception e)
     {
         Conexion.getInstance().Disconnect();
         return(null);
     }
 }
Пример #2
0
 public static MateriaDB getInstance()
 {
     if (MateriaDB._instance == null)
     {
         MateriaDB._instance = new MateriaDB();
     }
     return(MateriaDB._instance);
 }
Пример #3
0
        public List <Business.Entities.Curso> listarCursosPorNombre(string nombre)
        {
            try
            {
                string nomb = "%" + nombre + "%";
                Conexion.getInstance().Connect();
                SqlCommand    cmd    = new SqlCommand("select * from dbo.Curso where CONVERT(VARCHAR,nombre) like '" + nomb + "'", Conexion.getInstance().Conection);
                SqlDataReader reader = cmd.ExecuteReader();
                List <Business.Entities.Curso> cursos = new List <Curso>();
                while (reader.Read())
                {
                    int    idCurso              = (int)reader.GetValue(0);
                    string nom                  = reader.GetString(1);
                    int    cupo                 = (int)reader.GetValue(2);
                    int    idMateria            = (int)reader.GetValue(3);
                    int    idComision           = (int)reader.GetValue(4);
                    Business.Entities.Curso cur = new Curso(nom, cupo);
                    if (reader["idMateria"] != DBNull.Value)
                    {
                        Business.Entities.Materia mat = MateriaDB.getInstance().buscarMateriaPorId((int)reader.GetValue(3));
                        cur.Materia = mat;
                    }
                    if (reader["idComision"] != DBNull.Value)
                    {
                        Business.Entities.Comision com = ComisionDB.getInstance().buscarComisionPorId((int)reader.GetValue(4));
                        cur.Comision = com;
                    }
                    //agregar los valores del comision y de la materia
                    cur.IdCurso = idCurso;

                    cursos.Add(cur);
                }
                Conexion.getInstance().Disconnect();
                return(cursos);
            }
            catch (Exception e)
            {
                Conexion.getInstance().Disconnect();
                return(null);
            }
        }
Пример #4
0
        public List <Business.Entities.Curso> listarCursos()
        {
            try
            {
                Conexion.getInstance().Connect();
                SqlCommand    cmd    = new SqlCommand("select * from dbo.Curso", Conexion.getInstance().Conection);
                SqlDataReader reader = cmd.ExecuteReader();
                List <Business.Entities.Curso> cursos = new List <Curso>();
                while (reader.Read())
                {
                    int    idCurso = (int)reader.GetValue(0);
                    string nombre  = reader.GetString(1);
                    int    cupo    = (int)reader.GetValue(2);
                    Business.Entities.Curso cur = new Curso(nombre, cupo);
                    if (reader["idMateria"] != DBNull.Value)
                    {
                        Business.Entities.Materia mat = MateriaDB.getInstance().buscarMateriaPorId((int)reader.GetValue(3));
                        cur.Materia = mat;
                    }
                    if (reader["idComision"] != DBNull.Value)
                    {
                        Business.Entities.Comision com = ComisionDB.getInstance().buscarComisionPorId((int)reader.GetValue(4));
                        cur.Comision = com;
                    }

                    cur.IdCurso = idCurso;

                    cursos.Add(cur);
                }
                Conexion.getInstance().Disconnect();
                return(cursos);
            }
            catch (Exception e)
            {
                Conexion.getInstance().Disconnect();
                return(null);
            }
        }