private void boton_Buscar_Click(object sender, EventArgs e) { string comando_sql = ""; string comando_sql_having = ""; //CADENA DE NUMERO FACTURA if (rb_numFactura.Checked) { if (txt_NumFactura.Text == "") { MessageBox.Show("Se ecuentra seleccionada la opcion de filtado por numero de factura, por ende debe escribir un numero."); txt_NumFactura.Focus(); return; } else { comando_sql = comando_sql + " WHERE " + txt_NumFactura._campo + " = " + txt_NumFactura.Text.Trim(); } } //CADENA DE PRECIO if (rb_MontoFactura.Checked) { if (txt_PrecioDesde.Text == "") { MessageBox.Show("Se ecuentra seleccionada la opcion de filtado por precio, por ende debe escribir un precio desde y un precio hasta."); txt_PrecioDesde.Focus(); return; } if (txt_PrecioHasta.Text == "") { MessageBox.Show("Se ecuentra seleccionada la opcion de filtado por precio, por ende debe escribir un precio desde y un precio hasta."); txt_PrecioHasta.Focus(); return; } if (int.Parse(txt_PrecioDesde.Text) > int.Parse(txt_PrecioHasta.Text)) { MessageBox.Show("El precio desde debe ser menor al precio hasta."); txt_PrecioDesde.Text = ""; txt_PrecioHasta.Text = ""; txt_PrecioDesde.Focus(); return; } if (comando_sql_having == "") { comando_sql_having = comando_sql_having + @"GROUP BY C.nro_factura, CL.nombres, CL.apellido HAVING SUM(P.precio * D.cantidad) BETWEEN " + txt_PrecioDesde.Text.Trim() + " AND " + txt_PrecioHasta.Text.Trim(); } } //CADENA DE CLIENTE if (rb_Cliente.Checked) { if (txt_Cliente.Text == "") { MessageBox.Show("Se ecuentra seleccionada la opcion de filtado por nombre de cliente, por ende debe escribir uno."); txt_Cliente.Focus(); return; } if (comando_sql == "") { comando_sql = comando_sql + " WHERE " + txt_Cliente._campo + " LIKE '%" + txt_Cliente.Text.Trim() + "%'"; } else { comando_sql = comando_sql + " AND " + txt_Cliente._campo + " LIKE '%" + txt_Cliente.Text.ToString() + "%'"; } } //CADENA DE FECHA if (rb_Fecha.Checked) { if (txt_FechaDesde.Text == "") { MessageBox.Show("Se ecuentra seleccionada la opcion de filtado por fecha, por ende debe escribir una fecha desde y una fecha hasta."); txt_FechaDesde.Focus(); return; } if (txt_FechaHasta.Text == "") { MessageBox.Show("Se ecuentra seleccionada la opcion de filtado por fecha, por ende debe escribir una fecha desde y una fecha hasta."); txt_FechaHasta.Focus(); return; } if (comando_sql == "") { comando_sql = comando_sql + " WHERE " + txt_FechaDesde._campo + " BETWEEN CONVERT(char(10),'" + txt_FechaDesde.Text.Trim() + "',103) AND CONVERT(char(10),'" + txt_FechaHasta.Text.Trim() + "',103)"; } else { comando_sql = comando_sql + " AND " + txt_FechaDesde._campo + " BETWEEN CONVERT(char(10),'" + txt_FechaDesde.Text.Trim() + "', 103) AND CONVERT(char(10),'" + txt_FechaHasta.Text.Trim() + "', 103)"; } } DataTable tabla = new DataTable(); tabla = factura.buscar_facturaFiltrado(comando_sql, comando_sql_having); if (tabla.Rows.Count == 0) { MessageBox.Show("No se encuentra ningun producto segun la busqueda realizada."); } else { dataGridView1.DataSource = tabla; } }