private void tsbBuscar_Click(object sender, EventArgs e) { var ordenesVenta = (from OV in _dbCosolemEntities.tbOrdenVentaCabecera where OV.idEmpresaFactura == idEmpresa && OV.idTiendaFactura == idTienda && OV.tipoOrdenVenta == "O" && OV.idEstadoOrdenVenta == 5 select OV); if (devoluciones) { DateTime fechaDesde = Program.fechaHora.AddDays(-8).Date; DateTime fechaHasta = Program.fechaHora.AddDays(-1).Date; ordenesVenta = (from OV in ordenesVenta where EntityFunctions.TruncateTime(OV.fechaHoraFactura) >= EntityFunctions.TruncateTime(fechaDesde) && EntityFunctions.TruncateTime(OV.fechaHoraFactura) <= EntityFunctions.TruncateTime(fechaHasta) select OV); } else { ordenesVenta = (from OV in ordenesVenta where EntityFunctions.TruncateTime(OV.fechaHoraFactura) == EntityFunctions.TruncateTime(Program.fechaHora.Date) select OV); } if (!String.IsNullOrEmpty(txtNumeroIdentificacion.Text.Trim())) { ordenesVenta = (from OV in ordenesVenta where OV.tbCliente.tbPersona.numeroIdentificacion == txtNumeroIdentificacion.Text.Trim() select OV); } if (!String.IsNullOrEmpty(txtNumeroFactura.Text.Trim())) { long numeroFactura = Convert.ToInt64(txtNumeroFactura.Text.Trim()); ordenesVenta = (from OV in ordenesVenta where OV.numeroFactura == numeroFactura select OV); } SortableBindingList <tbOrdenVentaCabecera> _BindingListtbOrdenVentaCabecera = new SortableBindingList <tbOrdenVentaCabecera>(ordenesVenta.ToList()); _BindingListtbOrdenVentaCabecera.ToList().ForEach(x => { x.seleccionado = false; x.descripcionFormaPago = x.tbFormaPago.descripcion; x.descripcionCliente = x.numeroIdentificacion + " - " + x.cliente; x.descripcionEstadoOrdenVenta = x.tbEstadoOrdenVenta.descripcion; }); dgvOrdenVentaCabecera.DataSource = _BindingListtbOrdenVentaCabecera; dgvOrdenVentaDetalle.DataSource = null; dgvOrdenVentaFormaPago.DataSource = null; }