Beispiel #1
0
        private void crearFiltro()
        {
            string filtro_fecha        = string.Empty;
            string filtro_razon        = string.Empty;
            string filtro_npresupuesto = string.Empty;

            bool and = false;


            if (txt_filtro_razon.Text.Trim() != "" || !string.IsNullOrEmpty(txt_filtro_razon.Text))
            {
                if (and)
                {
                    filtro_razon = string.Format(" AND convert([Razon Social], 'System.String') like '%{0}%'", txt_filtro_razon.Text.Trim().Replace("'", "''"));
                }
                else
                {
                    filtro_razon = string.Format(" convert([Razon Social], 'System.String') like '%{0}%'", txt_filtro_razon.Text.Trim().Replace("'", "''"));
                }
                and = true;
            }
            if (txt_filtro_npresupuesto.Text.Trim() != "" || !string.IsNullOrEmpty(txt_filtro_npresupuesto.Text))
            {
                if (and)
                {
                    filtro_npresupuesto = string.Format(" AND convert([Id], 'System.String') like '%{0}%'", txt_filtro_npresupuesto.Text.Trim().Replace("'", "''"));
                }
                else
                {
                    filtro_npresupuesto = string.Format(" convert([Id], 'System.String') like '%{0}%'", txt_filtro_npresupuesto.Text.Trim().Replace("'", "''"));
                }
                and = true;
            }
            if (txt_desde.Value != DateTime.Now.Date || txt_hasta.Value != DateTime.Now.Date)
            {
                if (and)
                {
                    filtro_fecha = string.Format(" AND " + ControladorFuncVariadas.filtro_desde_hasta(txt_desde, txt_hasta));
                }
                else
                {
                    filtro_fecha = string.Format(" " + ControladorFuncVariadas.filtro_desde_hasta(txt_desde, txt_hasta));
                }
                and = true;
            }


            var bd = (BindingSource)dgv_tabla.DataSource;
            var dt = (DataTable)bd.DataSource;

            string query = filtro_razon + filtro_npresupuesto + filtro_fecha;

            dt.DefaultView.RowFilter = query;
            dgv_tabla.Refresh();
        }
Beispiel #2
0
        private void crearFiltro()
        {
            string filtro_estado   = string.Empty;
            string filtro_razon    = string.Empty;
            string filtro_nfactura = string.Empty;
            string filtro_fecha    = string.Empty;
            bool   and             = false;

            if (filtro_estado_venta.SelectedIndex != -1)
            {
                and = true;
                if (filtro_estado_venta.SelectedIndex == 2)
                {
                    filtro_estado = string.Format("[Cobrada] = 0");
                }
                else if (filtro_estado_venta.SelectedIndex == 0)
                {
                    and           = false;
                    filtro_estado = string.Empty;
                }
                else if (filtro_estado_venta.SelectedIndex == 1)
                {
                    filtro_estado = string.Format("[Cobrada] = 1");
                }
            }

            if (txt_filtro_razon.Text.Trim() != "" || !string.IsNullOrEmpty(txt_filtro_razon.Text))
            {
                if (and)
                {
                    filtro_razon = string.Format(" AND convert([Razon Social], 'System.String') like '%{0}%'", txt_filtro_razon.Text.Trim().Replace("'", "''"));
                }
                else
                {
                    filtro_razon = string.Format(" convert([Razon Social], 'System.String') like '%{0}%'", txt_filtro_razon.Text.Trim().Replace("'", "''"));
                }
                and = true;
            }
            if (txt_filtro_factura.Text.Trim() != "" || !string.IsNullOrEmpty(txt_filtro_factura.Text))
            {
                if (and)
                {
                    filtro_nfactura = string.Format(" AND convert([Nro Factura], 'System.String') like '%{0}%'", txt_filtro_factura.Text.Trim().Replace("'", "''"));
                }
                else
                {
                    filtro_nfactura = string.Format(" convert([Nro Factura], 'System.String') like '%{0}%'", txt_filtro_factura.Text.Trim().Replace("'", "''"));
                }
                and = true;
            }
            if (txt_desde.Value != DateTime.Now.Date || txt_hasta.Value != DateTime.Now.Date)
            {
                if (and)
                {
                    filtro_fecha = string.Format(" AND " + ControladorFuncVariadas.filtro_desde_hasta(txt_desde, txt_hasta));
                }
                else
                {
                    filtro_fecha = string.Format(" " + ControladorFuncVariadas.filtro_desde_hasta(txt_desde, txt_hasta));
                }
                and = true;
            }


            var bd = (BindingSource)dgv_tabla.DataSource;
            var dt = (System.Data.DataTable)bd.DataSource;


            string query = filtro_estado + filtro_razon + filtro_nfactura + filtro_fecha;

            dt.DefaultView.RowFilter = query;
            dgv_tabla.Refresh();
        }