Ejemplo n.º 1
0
        private void btnAdicionarFiltro_Click(object sender, EventArgs e)
        {
            if (ValidaAdicionarFiltro())
            {
                // recupera as informações da tag do txtFiltro para inserir na grid
                ParametrosFiltro p = ((ParametrosFiltro)txtFiltro.Tag);

                DataTable dt    = ((DataTable)dgvFiltros.DataSource);
                DataRow   linha = dt.NewRow();

                linha["FILTRO"]      = txtFiltro.Text;
                linha["FILTRO_DESC"] = txtFiltroDesc.Text;

                linha["NOME_CAMPO"]        = p.NOME_CAMPO;
                linha["TIPO_FILTRO"]       = p.TIPO_FILTRO;
                linha["OBRIGATORIO"]       = p.OBRIGATORIO;
                linha["TIPO_VALOR"]        = p.TIPO_VALOR;
                linha["POSICAO_FILTRO"]    = p.POSICAO_FILTRO;
                linha["NOME_CAMPO_FILTRO"] = p.NOME_CAMPO_FILTRO;

                // Verifica o Tipo de Valor para exibir de forma específica e melhor visível para o usuário
                // 1-Inteiro, 2-Data Única 3- Data Período, 4-String, 5-Competência, 6-Período de Competência
                switch (linha["TIPO_VALOR"].ToString())
                {
                case "1":                              // inteiro
                    if (p.CONTEM_PESQUISA.Equals("1")) // Filtro informado contém pesquisa
                    {
                        linha["VALOR"]      = txtValorFiltro.Text;
                        linha["VALOR_DESC"] = txtValorFiltro.Text + " - " + txtValorFiltroDesc.Text;
                    }
                    else
                    {
                        linha["VALOR"]      = txtValorFiltroSemPesquisa.Text;
                        linha["VALOR_DESC"] = txtValorFiltroSemPesquisa.Text;
                    }
                    break;

                case "2":     // data única
                    linha["VALOR"]      = mtxtPeriodoInicio.Text;
                    linha["VALOR_DESC"] = mtxtPeriodoInicio.Text;
                    break;

                case "3":     // data período
                    linha["VALOR"]      = mtxtPeriodoInicio.Text + ";" + mtxtPeriodoFim.Text;
                    linha["VALOR_DESC"] = "Entre " + mtxtPeriodoInicio.Text + " e " + mtxtPeriodoFim.Text;
                    break;

                case "4":                              // string
                    if (p.CONTEM_PESQUISA.Equals("1")) // Filtro informado contém pesquisa
                    {
                        linha["VALOR"]      = txtValorFiltro.Text;
                        linha["VALOR_DESC"] = txtValorFiltro.Text + " - " + txtValorFiltroDesc.Text;
                    }
                    else
                    {
                        linha["VALOR"]      = txtValorFiltroSemPesquisa.Text;
                        linha["VALOR_DESC"] = txtValorFiltroSemPesquisa.Text;
                    }
                    break;

                case "5":     // competência
                    linha["VALOR"]      = mtxtCompetenciaInicial.Text;
                    linha["VALOR_DESC"] = mtxtCompetenciaInicial.Text;
                    break;

                case "6":     // período de competência
                    linha["VALOR"]      = DateTime.Parse(mtxtCompetenciaInicial.Text).ToString("yyyyMM") + ";" + DateTime.Parse(mtxtCompetenciaFinal.Text).ToString("yyyyMM");
                    linha["VALOR_DESC"] = mtxtCompetenciaInicial.Text + " a " + mtxtCompetenciaFinal.Text;
                    break;

                case "7":     // DateTime período
                    linha["VALOR"]      = DateTime.Parse(mtxtCompetenciaInicial.Text).ToString("dd/MM/yyyy HH:mm:ss") + ";" + DateTime.Parse(mtxtCompetenciaFinal.Text).ToString("dd/MM/yyyy HH:mm:ss");
                    linha["VALOR_DESC"] = mtxtCompetenciaInicial.Text + " a " + mtxtCompetenciaFinal.Text;
                    break;

                case "8":     // DateTime competência
                    linha["VALOR"]      = DateTime.Parse(mtxtCompetenciaInicial.Text).ToString("dd/MM/yyyy HH:mm:ss");
                    linha["VALOR_DESC"] = mtxtCompetenciaInicial.Text;
                    break;

                case "9":     // Time período
                    linha["VALOR"]      = DateTime.Parse(mtxtCompetenciaInicial.Text).ToString("HH:mm:ss") + ";" + DateTime.Parse(mtxtCompetenciaFinal.Text).ToString("HH:mm:ss");
                    linha["VALOR_DESC"] = mtxtCompetenciaInicial.Text + " a " + mtxtCompetenciaFinal.Text;
                    break;

                case "10":     // Time competência
                    linha["VALOR"]      = DateTime.Parse(mtxtCompetenciaInicial.Text).ToString("HH:mm:ss");
                    linha["VALOR_DESC"] = mtxtCompetenciaInicial.Text;
                    break;

                case "11":     // Faixas de string/inteiro
                    linha["VALOR"]      = txtFaixaInicial.Text + ";" + txtFaixaFinal.Text;
                    linha["VALOR_DESC"] = txtFaixaInicial.Text + " a " + txtFaixaFinal.Text;
                    break;

                default:
                    throw new Exception(@"Tipo de Valor do Filtro " + txtFiltro.Text + " não encontrado.");
                }

                dt.Rows.Add(linha);

                dt.DefaultView.Sort = "FILTRO, VALOR";
                dt = dt.DefaultView.ToTable();

                dgvFiltros.DataSource = dt;

                txtValorFiltro.Text            = "";
                txtValorFiltroSemPesquisa.Text = "";
                mtxtPeriodoInicio.Text         = "";
                mtxtPeriodoFim.Text            = "";
                mtxtCompetenciaInicial.Text    = "";
                mtxtCompetenciaFinal.Text      = "";

                txtFiltro.Focus();
            }
        }
Ejemplo n.º 2
0
        private void txtFiltro_Leave(object sender, EventArgs e)
        {
            // verifica o txtFiltroDesc para não executar o Leave 2x na hora que da o Focus no campo Valor exibido
            if (txtFiltro.ContemValor() && string.IsNullOrEmpty(txtFiltroDesc.Text))
            {
                DataTable dt = BuscaExtratorDadosComandosFiltros(txtComando.Text, txtFiltro.Text, this.Sistema);
                mtxtCompetenciaInicial.Location = new Point(89, 53);
                mtxtCompetenciaFinal.Location   = new Point(200, 53);
                mtxtCompetenciaInicial.Size     = new Size(84, 21);
                mtxtCompetenciaFinal.Size       = new Size(84, 21);
                lblPeriodo.Location             = new Point(179, 56);

                if (dt.Rows.Count == 1)
                {
                    //validarFiltrosAnteriores(txtFiltro.Text);

                    if (ValidarCadastroFiltro(dt))
                    {
                        txtFiltroDesc.Text = dt.Rows[0]["FILTRO_DESC"].ToString();

                        // a Tag do txtFiltro irá guardar os campos relevantes para serem inseridos na grid pelo botão Inserir e posteriormente serem
                        // usados na hora de montar os Filtros no botão Gerar.
                        ParametrosFiltro pf = new ParametrosFiltro();
                        pf.NOME_CAMPO        = dt.Rows[0]["NOME_CAMPO"].ToString();
                        pf.TIPO_FILTRO       = dt.Rows[0]["TIPO_FILTRO"].ToString();
                        pf.OBRIGATORIO       = dt.Rows[0]["OBRIGATORIO"].ToString();
                        pf.TIPO_VALOR        = dt.Rows[0]["TIPO_VALOR"].ToString();
                        pf.CONTEM_PESQUISA   = dt.Rows[0]["CONTEM_PESQUISA"].ToString();
                        pf.POSICAO_FILTRO    = dt.Rows[0]["POSICAO_FILTRO"].ToString();
                        pf.NOME_CAMPO_FILTRO = dt.Rows[0]["NOME_CAMPO_FILTRO"].ToString();
                        //txtFiltro.Tag = dt.Rows[0]["NOME_CAMPO"].ToString() + "&" +
                        //                dt.Rows[0]["TIPO_FILTRO"].ToString() + "&" +
                        //                dt.Rows[0]["OBRIGATORIO"].ToString() + "&" +
                        //                dt.Rows[0]["TIPO_VALOR"].ToString() + "&" +
                        //                dt.Rows[0]["CONTEM_PESQUISA"].ToString() + "&" +
                        //                dt.Rows[0]["POSICAO_FILTRO"].ToString() + "&" +
                        //                dt.Rows[0]["NOME_CAMPO_FILTRO"].ToString();
                        txtFiltro.Tag = pf;


                        txtValorFiltroSemPesquisa.Visible = false;
                        txtFaixaInicial.Visible           = false;
                        txtFaixaFinal.Visible             = false;
                        txtValorFiltro.Visible            = false;
                        txtValorFiltroDesc.Visible        = false;
                        mtxtPeriodoInicio.Visible         = false;
                        mtxtPeriodoFim.Visible            = false;
                        lblPeriodo.Visible             = false;
                        mtxtCompetenciaInicial.Visible = false;
                        mtxtCompetenciaFinal.Visible   = false;

                        // tipos de valor:1-Inteiro, 2-Data Única 3- Data Período, 4-String, 5-Competência, 6-Período de Competência
                        //                7-Periodo DateTime, 8-Competencia DateTime, 9-Periodo Hora, 10-Competencia Hora
                        if (pf.TIPO_VALOR.Equals("1") || pf.TIPO_VALOR.Equals("4")) // inteiro ou string
                        {
                            txtValorFiltro.Visible            = pf.CONTEM_PESQUISA.Equals("1");
                            txtValorFiltroDesc.Visible        = pf.CONTEM_PESQUISA.Equals("1");
                            txtValorFiltroSemPesquisa.Visible = !pf.CONTEM_PESQUISA.Equals("1");

                            if (pf.CONTEM_PESQUISA.ToString().Equals("1"))
                            {
                                txtValorFiltro.Focus();
                            }
                            else
                            {
                                txtValorFiltroSemPesquisa.Focus();
                            }
                        }
                        else if (pf.TIPO_VALOR.Equals("2")) // data única
                        {
                            mtxtPeriodoInicio.Visible = true;

                            mtxtPeriodoInicio.Text = DateTime.Parse(DateTime.Now.AddMonths(-1).ToString("MM/yyyy")).ToShortDateString();
                            mtxtPeriodoFim.Text    = "";

                            mtxtPeriodoInicio.Focus();
                        }
                        else if (pf.TIPO_VALOR.Equals("3")) // período de data
                        {
                            mtxtPeriodoInicio.Visible = true;
                            mtxtPeriodoFim.Visible    = true;
                            lblPeriodo.Visible        = true;
                            mtxtPeriodoInicio.Text    = DateTime.Parse(DateTime.Now.AddMonths(-1).ToString("MM/yyyy")).ToShortDateString();
                            mtxtPeriodoFim.Text       = DateTime.Parse("01/" + DateTime.Now.ToString("MM/yyyy")).AddDays(-1).ToShortDateString();

                            mtxtPeriodoInicio.Focus();
                        }
                        else if (pf.TIPO_VALOR.Equals("5")) // Competência
                        {
                            mtxtCompetenciaInicial.Visible = true;
                            mtxtCompetenciaInicial.Text    = DateTime.Now.AddMonths(-1).ToString("MM/yyyy");
                        }
                        else if (pf.TIPO_VALOR.Equals("6")) //Período de Competência Obrigatório e Opcional
                        {
                            mtxtCompetenciaInicial.Visible = true;
                            mtxtCompetenciaFinal.Visible   = true;
                            lblPeriodo.Visible             = true;

                            mtxtCompetenciaInicial.Text = DateTime.Now.AddMonths(-1).ToString("MM/yyyy");
                            mtxtCompetenciaFinal.Text   = DateTime.Now.AddMonths(-1).ToString("MM/yyyy");
                        }
                        else if (pf.TIPO_VALOR.Equals("7")) //DATETIME PERIODO
                        {
                            mtxtCompetenciaInicial.Visible = true;
                            mtxtCompetenciaFinal.Visible   = true;
                            lblPeriodo.Visible             = true;

                            mtxtCompetenciaInicial.Mask = "00/00/0000 00:00:00";
                            mtxtCompetenciaFinal.Mask   = "00/00/0000 00:00:00";

                            mtxtCompetenciaInicial.Size   = new Size(mtxtCompetenciaInicial.Width + 50, mtxtCompetenciaInicial.Height);
                            mtxtCompetenciaFinal.Size     = new Size(mtxtCompetenciaFinal.Width + 50, mtxtCompetenciaFinal.Height);
                            mtxtCompetenciaFinal.Location = new Point(mtxtCompetenciaFinal.Location.X + 50, mtxtCompetenciaFinal.Location.Y);
                            lblPeriodo.Location           = new Point(lblPeriodo.Location.X + 50, lblPeriodo.Location.Y);
                        }
                        else if (pf.TIPO_VALOR.Equals("8")) //DATETIME COMPETENCIA
                        {
                            mtxtCompetenciaInicial.Visible = true;

                            mtxtCompetenciaInicial.Mask = "00/00/0000 00:00:00";
                            mtxtCompetenciaInicial.Size = new Size(mtxtCompetenciaInicial.Width + 50, mtxtCompetenciaInicial.Height);
                        }
                        else if (pf.TIPO_VALOR.Equals("9")) //TIME PERIODO
                        {
                            mtxtCompetenciaInicial.Visible = true;
                            mtxtCompetenciaFinal.Visible   = true;
                            lblPeriodo.Visible             = true;

                            mtxtCompetenciaInicial.Mask = "00:00:00";
                            mtxtCompetenciaFinal.Mask   = "00:00:00";
                        }
                        else if (pf.TIPO_VALOR.Equals("10")) //TIME COMPETENCIA
                        {
                            mtxtCompetenciaInicial.Visible = true;

                            mtxtCompetenciaInicial.Mask = "00:00:00";
                        }
                        else if (pf.TIPO_VALOR.Equals("11")) //Faixas de String/Inteiro
                        {
                            txtFaixaInicial.Visible = true;
                            txtFaixaFinal.Visible   = true;
                            lblPeriodo.Visible      = true;
                        }
                        else
                        {
                            throw new Exception(@"Tipo de Valor do Filtro inválido.");
                        }
                    }
                    else
                    {
                        txtFiltro.Text = "";
                        txtFiltro.Focus();
                    }
                }
                else
                {
                    MessageBox.Show("Filtro não encontrado ou não relacionado ao Comando informado.", "Informação", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    txtFiltro.Text = "";
                }
            }
        }