public static List<HistoryCompra> GetAllComprasByParametersLike(Usuario user, HistoryCompraFilters filter) { var param = new List<SPParameter> { new SPParameter("idUsuario", user.ID), new SPParameter("ID_Compra", filter.Codigo ?? (object)DBNull.Value), new SPParameter("Descripcion", filter.Descripcion ?? (object)DBNull.Value) , new SPParameter("Precio", filter.Precio ?? (object)DBNull.Value), new SPParameter("Compra_Cantidad", filter.Cantidad ?? (object)DBNull.Value), new SPParameter("Compra_Fecha", filter.Fecha?? (object)DBNull.Value) }; var sp = new StoreProcedure(DataBaseConst.Compra.SPGetHistoryComprasByUsuarioByParametersLike, param); return sp.ExecuteReader<HistoryCompra>(); }
private void LblBuscar_Click(object sender, EventArgs e) { try { #region Validations var filtersSetted = false; var exceptionMessage = string.Empty; if (!TypesHelper.IsEmpty(txtCodigo.Text)) { filtersSetted = true; if (!TypesHelper.IsNumeric(txtCodigo.Text)) exceptionMessage += Environment.NewLine + "El código debe ser numérico."; } if (!TypesHelper.IsEmpty(txtDesc.Text)) { filtersSetted = true; } if (!TypesHelper.IsEmpty(txtPrecio.Text)) { filtersSetted = true; if (!TypesHelper.IsDecimal(txtPrecio.Text)) exceptionMessage += Environment.NewLine + "El precio de la publicacion ser decimal (o numérico)."; } if (!TypesHelper.IsEmpty(txtFecha.Text)) { filtersSetted = true; } if (!TypesHelper.IsEmpty(txtCantidad.Text)) { filtersSetted = true; if (!TypesHelper.IsNumeric(txtCantidad.Text)) exceptionMessage += Environment.NewLine + "La cantidad debe ser numérica."; } if (!filtersSetted) exceptionMessage = "No se puede realizar la busqueda ya que no se informó ningún filtro"; if (!TypesHelper.IsEmpty(exceptionMessage)) throw new Exception(exceptionMessage); #endregion var filters = new HistoryCompraFilters { Codigo = (!TypesHelper.IsEmpty(txtCodigo.Text)) ? Convert.ToInt32(txtCodigo.Text) : (int?)null, Descripcion = (!TypesHelper.IsEmpty(txtDesc.Text)) ? txtDesc.Text : null, Precio = (!TypesHelper.IsEmpty(txtPrecio.Text)) ? Convert.ToDouble(txtPrecio.Text) : (double?)null, Fecha = (!TypesHelper.IsEmpty(txtFecha.Text)) ? txtFecha.Text : null, Cantidad = (!TypesHelper.IsEmpty(txtCantidad.Text)) ? Convert.ToInt32(txtCantidad.Text) : (int?)null }; var historyCompras = (cBExact.Checked) ? CompraPersistance.GetAllComprasByParameters(SessionManager.CurrentUser, filters) : CompraPersistance.GetAllComprasByParametersLike(SessionManager.CurrentUser, filters); if (historyCompras == null || historyCompras.Count == 0) throw new Exception("No se encontraron compras según los filtros informados."); RefreshSources(historyCompras); } catch (Exception ex) { MessageBox.Show(ex.Message, "Atención"); ClearFiltersAndTable(); } }