コード例 #1
0
        public static Presentacion ObtenerPresentaciones(int id)
        {
            Presentacion presentacion = null;

            if (listaPresentacion.Count == 0)
            {
                Presentacion.obtenerPresentacion();
            }

            foreach (Presentacion p in listaPresentacion)
            {
                if (p.idPresentacion == id)
                {
                    presentacion = p;
                    break;
                }
            }
            return(presentacion);

            /*
             * O se puede utilizar la forma más corta con Linq:
             * return Proveedor.ObtenerProveedores().Find(p => p.Id == id);
             *
             */
        }
コード例 #2
0
        public static List <Presentacion> obtenerPresentacion()
        {
            Presentacion presentacion;

            listaPresentacion.Clear();
            using (SqlConnection con = new SqlConnection(Conexion.CADENA_CONEXION))
            {
                con.Open();
                string textoCMD = "Select * from Presentacion";

                SqlCommand cmd = new SqlCommand(textoCMD, con);

                SqlDataReader elLectorDeDatos = cmd.ExecuteReader();

                while (elLectorDeDatos.Read())
                {
                    presentacion = new Presentacion();
                    presentacion.idPresentacion          = elLectorDeDatos.GetInt32(0);
                    presentacion.nombrePresentacion      = elLectorDeDatos.GetString(1);
                    presentacion.descripcionPresentacion = elLectorDeDatos.GetString(2);

                    listaPresentacion.Add(presentacion);
                }

                return(listaPresentacion);
            }
        }
コード例 #3
0
        public static void eliminarPresentacion(Presentacion pre)
        {
            //listaPresentacion.Remove(pre);
            using (SqlConnection con = new SqlConnection(Conexion.CADENA_CONEXION))
            {
                con.Open();
                string SENTENCIA_SQL = "delete from Presentacion where idPresentacion = @idPresentacion";

                SqlCommand   cmd = new SqlCommand(SENTENCIA_SQL, con);
                SqlParameter p3  = new SqlParameter("@idPresentacion", pre.idPresentacion);
                p3.SqlDbType = SqlDbType.Int;
                cmd.Parameters.Add(p3);

                cmd.ExecuteNonQuery();
            }
        }
コード例 #4
0
        public static Presentacion obtenerPresentacion(int idPresentacion)
        {
            Presentacion presentacion = null;

            if (listaPresentacion.Count == 0)
            {
                Presentacion.obtenerPresentacion();
            }

            foreach (Presentacion pre in listaPresentacion)
            {
                if (pre.idPresentacion == idPresentacion)
                {
                    presentacion = pre;
                    break;
                }
            }

            return(presentacion);
        }
コード例 #5
0
        public static void editarPresentacion(Presentacion pre, int indice)
        {
            //Presentacion.listaPresentacion[indice] = pre;
            using (SqlConnection con = new SqlConnection(Conexion.CADENA_CONEXION))
            {
                con.Open();
                string     textoCMD = "UPDATE Presentacion SET nombrePresentacion = @nombrePresentacion, descripcionPresentacion = @descripcionPresentacion where Idpresentacion = @Idpresentacion";
                SqlCommand cmd      = new SqlCommand(textoCMD, con);

                SqlParameter p1 = new SqlParameter("@nombrePresentacion", pre.nombrePresentacion);
                SqlParameter p2 = new SqlParameter("@descripcionPresentacion", pre.descripcionPresentacion);

                p1.SqlDbType = SqlDbType.VarChar;
                p2.SqlDbType = SqlDbType.VarChar;

                cmd.Parameters.Add(p1);
                cmd.Parameters.Add(p2);

                cmd.ExecuteNonQuery();
            }
        }
コード例 #6
0
        public static void agregarPresentacion(Presentacion pre)
        {
            //listaPresentacion.Add(pre);
            using (SqlConnection con = new SqlConnection(Conexion.CADENA_CONEXION))
            {
                con.Open();
                string     textoCmd = "insert into Presentacion (nombrePresentacion, descripcionPresentacion) VALUES (@nombrePresentacion, @descripcionPresentacion)";
                SqlCommand cmd      = new SqlCommand(textoCmd, con);

                SqlParameter p1 = new SqlParameter("@nombrePresentacion", pre.nombrePresentacion);
                SqlParameter p2 = new SqlParameter("@descripcionPresentacion", pre.descripcionPresentacion);

                p1.SqlDbType = SqlDbType.VarChar;
                p2.SqlDbType = SqlDbType.VarChar;

                cmd.Parameters.Add(p1);
                cmd.Parameters.Add(p2);

                cmd.ExecuteNonQuery();
            }
        }
コード例 #7
0
        public static List <Articulo> ObtenerArticulos()
        {
            Articulo art;

            listaArticulos.Clear();

            using (SqlConnection con = new SqlConnection(Conexion.CADENA_CONEXION))
            {
                try
                {
                    con.Open();
                    string     tectoCMD = "select * from Articulo";
                    SqlCommand cmd      = new SqlCommand(tectoCMD, con);

                    SqlDataReader elLectorDeDatos = cmd.ExecuteReader();

                    while (elLectorDeDatos.Read())
                    {
                        art              = new Articulo();
                        art.idArticulo   = elLectorDeDatos.GetInt32(0);
                        art.codigo       = elLectorDeDatos.GetString(1);
                        art.nombre       = elLectorDeDatos.GetString(2);
                        art.descripcion  = elLectorDeDatos.GetString(3);
                        art.categoria    = Categoria.ObtenerCategorias(elLectorDeDatos.GetInt32(4));
                        art.presentacion = Presentacion.ObtenerPresentaciones(elLectorDeDatos.GetInt32(5));

                        listaArticulos.Add(art);
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Ha ocurrido un error: " + ex.Message);
                }
            }

            return(listaArticulos);
        }