Example #1
0
        protected void btnFiltar_Click(object sender, EventArgs e)
        {
            try
            {
                bandera1 = false;
                bandera2 = false;
                vacio    = false;
                //txtFiltrarCodigo
                if (db.validaNumeros(txtFiltrarCodigo.Text))
                {
                    if (!string.IsNullOrEmpty(txtFiltrarFechainicio.Text))
                    {
                        match = Regex.Match(txtFiltrarFechainicio.Text, @"^(0[1-9]|[12][0-9]|3[01])[/](0[1-9]|1[012])[/](19|20)\d\d$");
                        if (match.Success)
                        {
                            bandera1 = true;
                            vacio    = true;
                        }
                        else
                        {
                            verModal("Error", "La fecha inicio no tiene el formato dd/mm/aaaa");
                        }
                    }
                    else
                    {
                        bandera1 = true;
                    }

                    if (!string.IsNullOrEmpty(txtFiltrarFechaFin.Text))
                    {
                        match = Regex.Match(txtFiltrarFechainicio.Text, @"^(0[1-9]|[12][0-9]|3[01])[/](0[1-9]|1[012])[/](19|20)\d\d$");
                        if (match.Success)
                        {
                            if (vacio)
                            {
                                if (Convert.ToDateTime(txtFiltrarFechainicio.Text) <= Convert.ToDateTime(txtFiltrarFechaFin.Text))
                                {
                                    bandera2 = true;
                                }
                                else
                                {
                                    verModal("Error", "La fecha incio es mayor que la fecha fin");
                                }
                            }
                        }
                        else
                        {
                            verModal("Error", "La fecha fin no tiene el formato dd/mm/aaaa");
                        }
                    }
                    else
                    {
                        bandera2 = true;
                    }
                    if (bandera1 && bandera2)
                    {
                        llenarGrid();
                    }
                }
                else
                {
                    verModal("Error", "El campo código no tiene el formato correcto");
                }
            }
            catch (Exception es)
            {
                verModal("Error", es.Message.ToString());
            }
        }