public string agregarVentaYDetalle(Venta nuevaVenta)
        {
            DetalleVentaNegocio negocioDetalleVenta = new DetalleVentaNegocio();
            ProductoNegocio     negocioProducto     = new ProductoNegocio();
            string response = "";

            if (ValidarStock(nuevaVenta) == true)
            {
                string IDVenta = this.agregar(nuevaVenta);
                if (IDVenta != "")
                {
                    foreach (Detalle detalleVenta in nuevaVenta.Detalle)
                    {
                        negocioDetalleVenta.agregar(detalleVenta, nuevaVenta.Cliente.ID.ToString(), IDVenta);
                        negocioProducto.modificarStock(detalleVenta.Producto, detalleVenta.Cantidad, false); // alta = true / baja = false
                    }
                }
                else
                {
                    response = "Se encontro una falla al generar la venta! Por favor, intente nuevamente.";
                }
            }
            else
            {
                response = "Whoops! Al parecer no hay stock suficiente para al menos 1 de los productos detallados";
            }
            return(response);
        }
        public object DefinirEntidadaFiltrar(Panel panelContenedor, Label lblNombreFormulario)
        {
            TextBox TextBoxSeleccionado = panelContenedor.Controls.OfType <TextBox>().FirstOrDefault(x => x.Text != "");
            string  NombreTextBox       = TextBoxSeleccionado.Name.Remove(0, 4);

            if (lblNombreFormulario.Text.Remove(0, 8) == "Productos")
            {
                ProductoNegocio unProducto = new ProductoNegocio();
                NombreTextBox += "Producto";
                List <Producto> ListadoProductosFiltrados = unProducto.FiltroProducto(TextBoxSeleccionado.Text, NombreTextBox);
                return(ListadoProductosFiltrados);
            }

            else if (lblNombreFormulario.Text.Remove(0, 8) == "Clientes")
            {
                ClienteNegocio unCliente = new ClienteNegocio();
                NombreTextBox += "Cliente";
                List <Cliente> ListadoClientesFiltrados = unCliente.FiltrarCliente(TextBoxSeleccionado.Text, NombreTextBox);
                return(ListadoClientesFiltrados);
            }

            else if (lblNombreFormulario.Text.Remove(0, 8) == "Proveedores")
            {
                ProveedorNegocio unProveedor = new ProveedorNegocio();
                NombreTextBox += "Proveedor";
                if (NombreTextBox == "NombreProveedor")
                {
                    NombreTextBox = "NombreFantasia";
                }
                List <Proveedor> ListadoProveedoresFiltrados = unProveedor.FiltrarProveedor(TextBoxSeleccionado.Text, NombreTextBox);
                return(ListadoProveedoresFiltrados);
            }

            throw new Exception("El " + NombreTextBox + " ingresado no existe");
        }
        public object DefinirEntidadAlistar(string NombreFormulario)
        {
            switch (NombreFormulario)
            {
            case "Clientes":
                ClienteNegocio unCliente = new ClienteNegocio();
                return(unCliente.ListarClientes());

            case "Productos":
                ProductoNegocio unProducto = new ProductoNegocio();
                return(unProducto.ListarProductos());

            case "Proveedores":
                ProveedorNegocio unProveedor = new ProveedorNegocio();
                return(unProveedor.ListarProveedores());

            case "Rubros":
                RubroNegocio unRubro = new RubroNegocio();
                return(unRubro.ListarRubros());

            case "Descuentos":
                DescuentoNegocio unDescuento = new DescuentoNegocio();
                return(unDescuento.ListarDescuentos());

            case "Impuestos":
                ImpuestoNegocio unImpuesto = new ImpuestoNegocio();
                return(unImpuesto.ListarImpuestos());

            default:
                return(null);
            }
        }
        public float TraerUltimoPrecioCompra(string IDProducto)
        {
            float          Precio   = 0;
            SqlConnection  conexion = new SqlConnection();
            SqlCommand     comando  = new SqlCommand();
            SqlDataReader  lector;
            List <Detalle> listado = new List <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].ProductoID = @ProductoID ORDER BY ID DESC";
                comando.Connection  = conexion;
                comando.Parameters.AddWithValue("@ProductoID", IDProducto);
                conexion.Open();
                lector = comando.ExecuteReader();
                ProductoNegocio negocioProducto = new ProductoNegocio();
                if (lector.Read())
                {
                    Precio = float.Parse(lector["Precio"].ToString());
                }

                return(Precio);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                conexion.Close();
            }
        }
        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 decimal totalFactura(int numFactura)
        {
            LineaFacturaDatos facturaDatos    = new LineaFacturaDatos();
            ProductoNegocio   productoNegocio = new ProductoNegocio();
            decimal           totalFactura    = 0;

            foreach (var item in facturaDatos.getLineaFacturas())
            {
                if (item.NumFacturaFk == numFactura)
                {
                    Producto producto = productoNegocio.buscarProducto(item.CodigoProducto);
                    totalFactura += (item.Cantidad * producto.Precio);
                }
            }
            return(totalFactura);
        }
        //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 object DefinirEntidadaEliminar(object Entidad)
        {
            if (Entidad.GetType().Equals(typeof(Cliente)))
            {
                ClienteNegocio unClienteNegocio = new ClienteNegocio();
                unClienteNegocio.EliminarCliente((Cliente)Entidad);
            }

            else if (Entidad.GetType().Equals(typeof(Producto)))
            {
                ProductoNegocio unProducto = new ProductoNegocio();
                unProducto.EliminarProducto((Producto)Entidad);
            }

            else if (Entidad.GetType().Equals(typeof(Proveedor)))
            {
                ProveedorNegocio unProveedor = new ProveedorNegocio();
                unProveedor.EliminarProveedor((Proveedor)Entidad);
            }

            else if (Entidad.GetType().Equals(typeof(Rubro)))
            {
                RubroNegocio unRubro = new RubroNegocio();
                unRubro.EliminarRubro((Rubro)Entidad);
            }


            else if (Entidad.GetType().Equals(typeof(Impuesto)))
            {
                ImpuestoNegocio unImpuesto = new ImpuestoNegocio();
                unImpuesto.EliminarImpuesto((Impuesto)Entidad);
            }


            else if (Entidad.GetType().Equals(typeof(Descuento)))
            {
                DescuentoNegocio unDescuento = new DescuentoNegocio();
                unDescuento.EliminarDescuento((Descuento)Entidad);
            }

            return(null);
        }
示例#9
0
        public Proveedor traerProveedor(string ID)
        {
            SqlConnection   conexion = new SqlConnection();
            SqlCommand      comando  = new SqlCommand();
            SqlDataReader   lector;
            ProductoNegocio negocioProducto;
            Proveedor       proveedor = new Proveedor();

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

                if (lector.Read())
                {
                    negocioProducto        = new ProductoNegocio();
                    proveedor.ID           = int.Parse(lector["Id"].ToString());
                    proveedor.RazonSocial  = lector["RazonSocial"].ToString();
                    proveedor.CUIT         = lector["CUIT"].ToString();
                    proveedor.Ciudad       = lector["Ciudad"].ToString();
                    proveedor.CodigoPostal = lector["CodigoPostal"].ToString();
                    proveedor.Direccion    = lector["Direccion"].ToString();
                    proveedor.Email        = lector["Email"].ToString();
                    proveedor.Productos    = negocioProducto.listar(lector["Id"].ToString());
                }
                return(proveedor);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                conexion.Close();
            }
        }
        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();
            }
        }
示例#11
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();
            }
        }
        public List <Usuario> listar()
        {
            SqlConnection  conexion = new SqlConnection();
            SqlCommand     comando  = new SqlCommand();
            SqlDataReader  lector;
            List <Usuario> listado = new List <Usuario>();
            Usuario        usuario;

            try
            {
                conexion.ConnectionString = AccesoDatosManager.cadenaConexion;
                comando.CommandType       = System.Data.CommandType.Text;
                comando.CommandText       = "SELECT * FROM [TPC_ESPINOLA].[dbo].[Usuarios] ";
                comando.Connection        = conexion;
                conexion.Open();
                lector = comando.ExecuteReader();
                ProductoNegocio negocioProducto = new ProductoNegocio();
                while (lector.Read())
                {
                    usuario               = new Usuario();
                    usuario.ID            = int.Parse(lector["ID"].ToString());
                    usuario.Identificador = lector["Identificador"].ToString();
                    usuario.Contraseña    = lector["Contraseña"].ToString();
                    usuario.Nivel         = Convert.ToInt32(lector["Nivel"].ToString());
                    usuario.Email         = lector["Email"].ToString();

                    listado.Add(usuario);
                }

                return(listado);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                conexion.Close();
            }
        }
示例#13
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();
            }
        }
示例#14
0
        //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);
        }