public int Agregar(Matricula pMatricula)
        {
            int resultado = 0;

            using (SqlConnection con = ConexionBD.Conectar())
            {
                con.Open();
                string     ssql      = "insert into Matriculas(Año, Ciclo, CarreraId,EstudianteId,GrupoId)values('{0}','{1}',{2},{3},{4})";
                string     sentencia = string.Format(ssql, pMatricula.Año, pMatricula.Ciclo, pMatricula.CarreraId.Id, pMatricula.EstudianteId.Id, pMatricula.GrupoId.Id);
                SqlCommand comando   = new SqlCommand(sentencia, con);
                comando.CommandType = CommandType.Text;
                resultado           = comando.ExecuteNonQuery();
                con.Close();
            }
            return(resultado);
        }
        public int Modificar(Matricula pMatricula)
        {
            int resultado = 0;

            using (SqlConnection con = ConexionBD.Conectar())
            {
                con.Open();
                string     ssql      = @"update Matriculas set Año='{0}',
                                                      Ciclo='{1}',
                                                      CarreraId={2},
                                                      EstudianteId={3},
                                                      GrupoId={4} where Id={5}";
                string     sentencia = string.Format(ssql, pMatricula.Año, pMatricula.Ciclo, pMatricula.CarreraId.Id, pMatricula.EstudianteId.Id, pMatricula.GrupoId.Id, pMatricula.Id);
                SqlCommand comando   = new SqlCommand(sentencia, con);
                comando.CommandType = CommandType.Text;
                resultado           = comando.ExecuteNonQuery();
                con.Close();
            }
            return(resultado);
        }
Exemple #3
0
        public Matricula ObtenerMatriculaPorCodigo(string codigoMatricula)
        {
            string spName = "[Matricula_GetById]";

            List <Matricula> Matriculas = new List <Matricula>();
            Matricula        item       = null;


            using (SqlConnection con = new SqlConnection(ConnectionString))
            {
                con.Open();

                SqlCommand cmd = new SqlCommand();
                cmd.CommandText = spName;
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.AddWithValue("@Id_Matricula", codigoMatricula);
                cmd.Connection = con;


                using (var reader = cmd.ExecuteReader())
                {
                    while (reader.Read())
                    {
                        var Matricula = new Matricula
                        {
                            Id_Matricula    = Convert.ToInt32(reader["Id_Matricula"]),
                            CodigoMatricula = Convert.ToInt32(reader["CodigoMatricula"]),
                            Anho            = Convert.ToInt32(reader["Anho"]),
                            Numero          = Convert.ToInt32(reader["Numero"]),
                            Descripcion     = reader["Descripcion"].ToString(),
                        };

                        Matriculas.Add(Matricula);
                        item = Matricula;
                    }
                }
            }

            return(item);
        }
        public int matriculaNoExist(Matricula pMatricula)
        {
            int result = 0;

            using (SqlConnection con = ConexionBD.Conectar())
            {
                con.Open();
                string     ssql      = "select * from Matriculas where Ciclo='{0}' and EstudianteId={1}";
                string     sentencia = string.Format(ssql, pMatricula.Ciclo, pMatricula.EstudianteId.Id);
                SqlCommand comando   = new SqlCommand(sentencia, con);
                comando.CommandType = CommandType.Text;
                IDataReader lector = comando.ExecuteReader();
                if (lector.Read())
                {
                    result = 1;
                }
                else
                {
                    result = 0;
                }
                con.Close();
            }
            return(result);
        }