Ejemplo n.º 1
0
        public List <HistorialPrecio> historialCambioPrecios(int mes, int annio)
        {
            List <HistorialPrecio> historial = new List <HistorialPrecio>();

            Conexion bd    = new Conexion();
            String   query = "SELECT t1.IdProducto, t1.fechaCambioPrecio, t1.precioProducto, t2.nombre, t2.precioVenta " +
                             "FROM historialprecio t1 INNER JOIN producto t2 ON t1.IdProducto = t2.IdProducto " +
                             "WHERE MONTH(t1.fechaCambioPrecio) = ?mes AND YEAR(t1.fechaCambioPrecio) = ?annio;";

            try
            {
                MySqlCommand cmd = new MySqlCommand(query, bd.abrirConexion());
                cmd.Parameters.AddWithValue("mes", mes);
                cmd.Parameters.AddWithValue("annio", annio);

                MySqlDataReader reader = cmd.ExecuteReader();
                while (reader.Read())
                {
                    HistorialPrecio registro = new HistorialPrecio();

                    registro.IdProducto     = reader.GetInt32("IdProducto");
                    registro.Fecha          = reader.GetDateTime("fechaCambioPrecio");
                    registro.PrecioAnterior = reader.GetDouble("precioProducto");
                    registro.Producto       = reader.GetString("nombre");
                    registro.PrecioActual   = reader.GetDouble("precioVenta");

                    historial.Add(registro);
                }
            }catch (Exception e) {
                System.Windows.Forms.MessageBox.Show("Error de conexion a la base de datos");
            }
            return(historial);
        }
        public void setup()
        {
            Gaseosa = new Categoria()
            {
                Nombre = "Gaseosa"
            };
            HistorialPrecio h1 = new HistorialPrecio()
            {
                PrecioUnitario = 100,
                FechaHora      = new DateTime(2019, 06, 26)
            };
            HistorialPrecio h2 = new HistorialPrecio()
            {
                PrecioUnitario = 150,
                FechaHora      = new DateTime(2019, 06, 27)
            };

            CocaCola                  = new Producto();
            CocaCola.Nombre           = "Coca Cola 2.25L";
            CocaCola.Categoria        = Gaseosa;
            CocaCola.Cantidad         = 200;
            CocaCola.PrecioUnitario   = h2.PrecioUnitario;
            CocaCola.HistorialPrecios = new List <HistorialPrecio>()
            {
                h1, h2
            };
        }