public void EliminaTest()
        {
            int id = 10;

            Factura = BLL.FacturaDetallesBLL.Buscar(c => c.IdDetalle == id);

            Assert.IsTrue(BLL.FacturaDetallesBLL.Eliminar(Factura));
        }
        protected void Button2_Click(object sender, EventArgs e)
        {
            Entidades.FacturaDetalles detallef = new Entidades.FacturaDetalles();
            LlenarDatos(detallef);
            var guardar = new Entidades.Deudasclientes();

            int idcliente     = int.Parse(DropDownCliente.Text);
            var ClienteNombre = BLL.ClientesBLL.Buscar(p => p.ClienteId == idcliente);



            if (detallef.Detalle.Count == 0)
            {
                Utilidades.ShowToastr(this, "Primero agregue Articulos", "Consejo", "info");
            }
            else

            {
                if (TextBoxTotal.Text == "" && DropDownTipoVenta.Text == "Contado")
                {
                    Utilidades.ShowToastr(this, "Calcule total", "ATENCION", "info");
                }

                else
                {
                    if (BLL.FacturaBLL.Guardar(facturaG, detallef.Detalle))
                    {
                        EliminarExitencia();

                        if (DropDownTipoVenta.Text == "Credito")
                        {
                            if (TextBoxTotal.Text == "")
                            {
                                Utilidades.ShowToastr(this, "Calcule total, presionando el boton ", "ATENCION", "info");
                            }
                            else
                            {
                                guardar.Cliente = ClienteNombre.Nombres;
                                guardar.Deuda   = Convert.ToDecimal(TextBoxTotal.Text);
                                if (BLL.DeudasclientesBLL.Guardar(guardar))
                                {
                                    Utilidades.ShowToastr(this, "Nueva deuda agregada", "ATENCION", "info");
                                }
                            }
                        }

                        Utilidades.ShowToastr(this, "Guardo", "Correcto", "success");

                        limpiar();
                    }
                    else
                    {
                        Utilidades.ShowToastr(this, "Error", "Error", "error");
                    }
                }
            }
        }
        public void ModificarTest()
        {
            int id = 10;

            Factura = BLL.FacturaDetallesBLL.Buscar(c => c.IdDetalle == id);

            Factura.Cantidad = 100;
            Factura.Nombre   = "Juan";



            Assert.IsTrue(BLL.FacturaDetallesBLL.Mofidicar(Factura));
        }
        private void SumarExistencia()
        {
            decimal suma = 0;

            foreach (GridViewRow producto in FacturaGrid.Rows)
            {
                Entidades.FacturaDetalles detallef = new Entidades.FacturaDetalles();
                int productoId = Convert.ToInt32(producto.Cells[0].Text); ///Celda 0 es el idArticulo antes esta detalleid y facturaid
                suma = Convert.ToDecimal(producto.Cells[2].Text);         //Celda 2 es la cantiddad

                detallef.Articulo             = BLL.ArticuloBLL.BuscarB(productoId);
                detallef.Articulo.Existencia += Convert.ToInt32(suma);
                BLL.ArticuloBLL.Mofidicar(detallef.Articulo);
            }
        }
        public void BuscarTest()
        {
            int  id      = 3; //ID Varia dependiendo lo registrado en la base de datos
            bool bandera = false;

            Factura = BLL.FacturaDetallesBLL.Buscar(p => p.IdDetalle == id);
            if (Factura != null)
            {
                bandera = true;
            }
            else
            {
                bandera = false;
            }
            Assert.IsTrue(bandera);
        }
        public void LlenarDatos(Entidades.FacturaDetalles detalle)
        {
            int id        = 0;
            int idCliente = 0;
            int cantidad  = 0;

            idCliente = Utilidades.TOINT(DropDownCliente.Text);
            var clientec = BLL.ClientesBLL.Buscar(p => p.ClienteId == idCliente);

            if (facturaG != null)
            {
                id = facturaG.IdFactura;
            }

            foreach (GridViewRow dr in FacturaGrid.Rows)
            {
                detalle.AgregarDetalle(Convert.ToInt32(dr.Cells[0].Text), 0, 0,
                                       Convert.ToDecimal(dr.Cells[1].Text), Convert.ToInt32(dr.Cells[2].Text), Convert.ToString(dr.Cells[3].Text), Convert.ToDecimal(dr.Cells[4].Text)
                                       );
                cantidad++;
                BotonCalcularDevuelta.Focus();
                CalcularMonto();
            }

            if (TextBoxTotal.Text == "" && TextBoxSubTotal.Text == "")
            {
                CalcularMonto();
            }
            else
            {
                if (clientec != null)
                {
                    facturaG = new Entidades.Facturas(0, Base.Usuario, DateTime.Now, clientec.Nombres, DropDownTipoVenta.Text, cantidad, Convert.ToDecimal(TextBoxTotal.Text));
                }
                else
                {
                    Utilidades.ShowToastr(this, "Error cliente vacio", "error");
                }
            }
        }