public List <Stock> listar(bool SoloEscasos)
        {
            SqlConnection   conexion = new SqlConnection();
            SqlCommand      comando  = new SqlCommand();
            SqlDataReader   lector;
            List <Stock>    listado         = new List <Stock>();
            ProductoNegocio negocioProducto = new ProductoNegocio();
            Stock           stock;

            try
            {
                DetalleCompraNegocio negocioDetCompra = new DetalleCompraNegocio();
                conexion.ConnectionString = AccesoDatosManager.cadenaConexion;
                comando.CommandType       = System.Data.CommandType.Text;
                comando.CommandText       = "SELECT * FROM[TPC_ESPINOLA].[dbo].[Productos]";
                comando.Connection        = conexion;
                conexion.Open();
                lector = comando.ExecuteReader();

                while (lector.Read())
                {
                    stock             = new Stock();
                    stock.Producto    = negocioProducto.traerProducto(lector["Id"].ToString());
                    stock.StockActual = long.Parse(lector["Stock"].ToString());
                    if (!Convert.IsDBNull(lector["StockMinimo"]))
                    {
                        stock.StockMinimo = int.Parse(lector["StockMinimo"].ToString());
                    }
                    else
                    {
                        stock.StockMinimo = 0;
                    }
                    if (SoloEscasos == false)
                    {
                        listado.Add(stock);
                    }
                    else if (stock.StockActual <= stock.StockMinimo)
                    {
                        listado.Add(stock);
                    }
                }

                return(listado);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                conexion.Close();
            }
        }
        //public void modificar(Producto nuevoProducto, int productoID)
        //{
        //    SqlConnection conexion = new SqlConnection();
        //    SqlCommand comando = new SqlCommand();
        //    List<Producto> listado = new List<Producto>();
        //    try
        //    {
        //        conexion.ConnectionString = AccesoDatosManager.cadenaConexion;
        //        comando.CommandType = System.Data.CommandType.Text;
        //        //MSF-20190420: agregué todos los datos del heroe. Incluso su universo, que lo traigo con join.
        //        comando.CommandText = "UPDATE [TPC_ESPINOLA].[dbo].[Productos] SET Titulo = @Titulo, Descripcion = @Descripcion, URLImagen = @URLImagen WHERE[TPC_ESPINOLA].[dbo].[Productos].ID = @ID";
        //        comando.Parameters.Clear();
        //        comando.Parameters.AddWithValue("@Titulo", nuevoProducto.Titulo);
        //        comando.Parameters.AddWithValue("@Descripcion", nuevoProducto.Descripcion);
        //        comando.Parameters.AddWithValue("@URLImagen", nuevoProducto.URLImagen);
        //        comando.Parameters.AddWithValue("@ID", productoID);
        //        comando.Connection = conexion;
        //        conexion.Open();
        //        comando.ExecuteNonQuery();
        //    }
        //    catch (Exception ex)
        //    {
        //        throw ex;
        //    }

        //    finally
        //    {
        //        conexion.Close();
        //    }
        //}
        private bool ValidarStock(Venta nuevaVenta)
        {
            ProductoNegocio negocioProducto = new ProductoNegocio();
            Producto        producto;
            bool            response = true;

            foreach (Detalle det in nuevaVenta.Detalle)
            {
                producto = negocioProducto.traerProducto(det.Producto.ID.ToString());
                if (producto != null)
                {
                    if (producto.Stock < det.Cantidad)
                    {
                        response = false;
                    }
                }
            }
            return(response);
        }
        public List <Detalle> listar(string CompraID)
        {
            SqlConnection  conexion = new SqlConnection();
            SqlCommand     comando  = new SqlCommand();
            SqlDataReader  lector;
            List <Detalle> listado = new List <Detalle>();
            Detalle        detalle;

            try
            {
                conexion.ConnectionString = AccesoDatosManager.cadenaConexion;
                comando.CommandType       = System.Data.CommandType.Text;
                //MSF-20190420: agregué todos los datos del heroe. Incluso su universo, que lo traigo con join.
                comando.CommandText = "SELECT * FROM [TPC_ESPINOLA].[dbo].[DetalleCompras] WHERE [TPC_ESPINOLA].[dbo].[DetalleCompras].CompraID = @IDCompra";
                comando.Connection  = conexion;
                comando.Parameters.AddWithValue("@IDCompra", CompraID);
                conexion.Open();
                lector = comando.ExecuteReader();
                ProductoNegocio negocioProducto = new ProductoNegocio();
                while (lector.Read())
                {
                    detalle          = new Detalle();
                    detalle.ID       = Convert.ToInt32(lector["ID"].ToString());
                    detalle.Producto = negocioProducto.traerProducto(lector["ProductoID"].ToString());
                    detalle.Cantidad = int.Parse(lector["Cantidad"].ToString());
                    detalle.Precio   = float.Parse(lector["Precio"].ToString());
                    detalle.SubTotal = int.Parse(lector["Cantidad"].ToString()) * float.Parse(lector["Precio"].ToString());

                    listado.Add(detalle);
                }

                return(listado);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                conexion.Close();
            }
        }
示例#4
0
        public List <Detalle> listar(string VentaID)
        {
            SqlConnection  conexion = new SqlConnection();
            SqlCommand     comando  = new SqlCommand();
            SqlDataReader  lector;
            List <Detalle> listado = new List <Detalle>();
            Detalle        detalleVenta;

            try
            {
                conexion.ConnectionString = AccesoDatosManager.cadenaConexion;
                comando.CommandType       = System.Data.CommandType.Text;
                comando.CommandText       = "SELECT * FROM [TPC_ESPINOLA].[dbo].[DetalleVentas] WHERE [TPC_ESPINOLA].[dbo].[DetalleVentas].VentaID = @ID";
                comando.Connection        = conexion;
                comando.Parameters.AddWithValue("@ID", VentaID);
                conexion.Open();
                lector = comando.ExecuteReader();
                ProductoNegocio negocioProducto = new ProductoNegocio();
                while (lector.Read())
                {
                    detalleVenta          = new Detalle();
                    detalleVenta.ID       = Convert.ToInt32(lector["ID"].ToString());
                    detalleVenta.Precio   = float.Parse(lector["Precio"].ToString());
                    detalleVenta.Producto = negocioProducto.traerProducto(lector["ProductoID"].ToString());
                    detalleVenta.Cantidad = int.Parse(lector["Cantidad"].ToString());
                    detalleVenta.SubTotal = int.Parse(lector["Cantidad"].ToString()) * float.Parse(lector["Precio"].ToString());

                    listado.Add(detalleVenta);
                }

                return(listado);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                conexion.Close();
            }
        }
示例#5
0
        public List <Producto> listarProductos(string ProveedorID)
        {
            List <Producto> listaProductos = new List <Producto>();
            SqlConnection   conexion       = new SqlConnection();
            SqlCommand      comando        = new SqlCommand();
            SqlDataReader   lector;
            string          productoID;
            Producto        producto;
            ProductoNegocio negocio = new ProductoNegocio();

            try
            {
                conexion.ConnectionString = AccesoDatosManager.cadenaConexion;
                comando.CommandType       = System.Data.CommandType.Text;
                comando.CommandText       = "SELECT [ProductoID] FROM [TPC_ESPINOLA].[dbo].[ProductosXProveedores] WHERE [TPC_ESPINOLA].[dbo].[ProductosXProveedores].ProveedorID = @ProveedorID";
                comando.Connection        = conexion;
                comando.Parameters.AddWithValue("@ProveedorID", ProveedorID);
                conexion.Open();
                lector = comando.ExecuteReader();

                while (lector.Read())
                {
                    productoID = lector["ProductoID"].ToString();
                    producto   = negocio.traerProducto(productoID);
                    listaProductos.Add(producto);
                }

                return(listaProductos);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                conexion.Close();
            }
        }
        //public void modificar(Producto nuevoProducto, int productoID)
        //{
        //    SqlConnection conexion = new SqlConnection();
        //    SqlCommand comando = new SqlCommand();
        //    List<Producto> listado = new List<Producto>();
        //    try
        //    {
        //        conexion.ConnectionString = AccesoDatosManager.cadenaConexion;
        //        comando.CommandType = System.Data.CommandType.Text;
        //        //MSF-20190420: agregué todos los datos del heroe. Incluso su universo, que lo traigo con join.
        //        comando.CommandText = "UPDATE [TPC_ESPINOLA].[dbo].[Productos] SET Titulo = @Titulo, Descripcion = @Descripcion, URLImagen = @URLImagen WHERE[TPC_ESPINOLA].[dbo].[Productos].ID = @ID";
        //        comando.Parameters.Clear();
        //        comando.Parameters.AddWithValue("@Titulo", nuevoProducto.Titulo);
        //        comando.Parameters.AddWithValue("@Descripcion", nuevoProducto.Descripcion);
        //        comando.Parameters.AddWithValue("@URLImagen", nuevoProducto.URLImagen);
        //        comando.Parameters.AddWithValue("@ID", productoID);
        //        comando.Connection = conexion;
        //        conexion.Open();
        //        comando.ExecuteNonQuery();
        //    }
        //    catch (Exception ex)
        //    {
        //        throw ex;
        //    }

        //    finally
        //    {
        //        conexion.Close();
        //    }
        //}
        public string agregarCompraYDetalle(Compra nuevaCompra)
        {
            DetalleCompraNegocio negocioDetalleCompra = new DetalleCompraNegocio();
            ProductoNegocio      negocioProducto      = new ProductoNegocio();
            Producto             producto;
            string response = "";
            string IDCompra = this.agregar(nuevaCompra);

            if (IDCompra != "")
            {
                foreach (Detalle det in nuevaCompra.Detalle)
                {
                    negocioDetalleCompra.agregar(det, nuevaCompra.Proveedor.ID.ToString(), IDCompra);
                    producto = negocioProducto.traerProducto(det.Producto.ID.ToString());
                    negocioProducto.modificarStock(producto, det.Cantidad, true); // alta = true / baja = false
                }
            }
            else
            {
                response = "Error al generar compra! intente nuevamente mas tarde";
                //Falla al generar la compra
            }
            return(response);
        }