public List <Importacion> TraerTodo()
        {
            List <Importacion> importaciones = new List <Importacion>();

            //CAMBIAR XXXX POR LO QUE CORRESPONDA!!!!!!!
            string        strCon = "Data Source=(local)\\SQLEXPRESS; Initial Catalog=PortLog5; Integrated Security=SSPI;";
            SqlConnection con    = new SqlConnection(strCon);

            string     sql = "select * from Importaciones;";
            SqlCommand com = new SqlCommand(sql, con);

            try
            {
                con.Open();
                SqlDataReader reader = com.ExecuteReader();

                while (reader.Read())
                {
                    Importacion importacion = new Importacion
                    {
                        CodigoImp       = reader.GetInt32(0),
                        Cantidad        = reader.GetInt32(1),
                        PrecioPorUnidad = reader.GetDecimal(2),
                        FechaIngreso    = reader.GetDateTime(3),
                        FechaSalida     = reader.GetDateTime(4),
                        Producto        = FachadaDistribuidora.BuscarProductoPorId((Convert.ToString(reader.GetInt32(5))))
                    };

                    importaciones.Add(importacion);
                }
                con.Close();
            }
            catch
            {
                throw;
            }
            finally
            {
                if (con.State == ConnectionState.Open)
                {
                    con.Close();
                }
            }

            return(importaciones);
        }
Beispiel #2
0
        public List <Producto> TraerTodo()
        {
            List <Producto> productos = new List <Producto>();

            //CAMBIAR XXXX POR LO QUE CORRESPONDA!!!!!!!
            string        strCon = "Data Source=(local)\\SQLEXPRESS; Initial Catalog=PortLog5; Integrated Security=SSPI;";
            SqlConnection con    = new SqlConnection(strCon);

            string     sql = "select * from Productos;";
            SqlCommand com = new SqlCommand(sql, con);

            try
            {
                con.Open();
                SqlDataReader reader = com.ExecuteReader();

                while (reader.Read())
                {
                    Producto producto = new Producto
                    {
                        Codigo     = reader.GetInt32(0),
                        Nombre     = reader.GetString(1),
                        PesoUnidad = (float)reader.GetDouble(2),
                        Cliente    = FachadaDistribuidora.TraerClientePorRut(reader.GetString(3))
                    };

                    productos.Add(producto);
                }
                con.Close();
            }
            catch
            {
                throw;
            }
            finally
            {
                if (con.State == ConnectionState.Open)
                {
                    con.Close();
                }
            }

            return(productos);
        }
Beispiel #3
0
        public Producto BuscarPorId(int id)
        {
            Producto productoExistente = null;

            //CAMBIAR XXXX POR LO QUE CORRESPONDA!!!!!!!
            string        strCon = "Data Source=(local)\\SQLEXPRESS; Initial Catalog=PortLog5; Integrated Security=SSPI;";
            SqlConnection con    = new SqlConnection(strCon);

            string     sql = "select * from Productos where IdProd=@id;";
            SqlCommand com = new SqlCommand(sql, con);

            com.Parameters.AddWithValue("@id", id);

            try
            {
                con.Open();
                SqlDataReader reader = com.ExecuteReader();

                if (reader.Read())
                {
                    productoExistente = new Producto
                    {
                        Codigo     = reader.GetInt32(0),
                        Nombre     = reader.GetString(1),
                        PesoUnidad = (float)reader.GetDouble(2),
                        Cliente    = FachadaDistribuidora.TraerClientePorRut(reader.GetString(3))
                    };
                }
                con.Close();
            }
            catch
            {
                throw;
            }
            finally
            {
                if (con.State == ConnectionState.Open)
                {
                    con.Close();
                }
            }
            return(productoExistente);
        }