Exemple #1
0
        public void Preenche_cboValor(int indexSelecao)
        {
            //método destinado a encher o segundo listbox, com valores únicos e ordenados da coluna selecionada
            //LOG dispensado (valor insignificante)

            cboValor.Items.Clear();
            try
            {
                string strTmp001 = strParametrosPesquisa[indexSelecao, 1]; //pega o nome da coluna
                int intTmp001 = dtTabelaPB.Columns[strTmp001].Ordinal; // indica a posição da coluna na tabela
                //intTmp001 = ;
                string strTmp002 = dtTabelaPB.Columns[strTmp001].DataType.ToString(); //pega o tipo de dado da coluna
                //DataRow[] drLinhas = dtTabelaPB.Select(); //faz a seleção de todas as linhas (não sei pra que)
                Dados dd = new Dados();

                //segundo o tipo de dados da coluna, o programa inicia a montagem correta, 
                //incluindo aspas nas strings;

                switch (strTmp002)
                {
                    case "System.String":
                        string[] strLista = new string[dtTabelaPB.Rows.Count - 1];

                        //transporta os valores da coluna selecionada para um Array, para que possa ser ordenado
                        for (int i = 0; i < dtTabelaPB.Rows.Count - 1; i++) //resgata os valores da tabela em um array
                        {
                            //strLista[i] = drLinhas[i].ItemArray[intTmp001].ToString();
                            strLista[i] = dtTabelaPB.Rows[i].ItemArray[intTmp001].ToString();
                        }

                        //faz o retorno de apenas valores unicos e ordena os valores
                        int intTmp002 = dd.GetDistinctValues<string>(strLista).Length;
                        string[] strTmp003 = new string[intTmp002];
                        strTmp003 = dd.GetDistinctValues<string>(strLista);
                        Array.Sort(strTmp003);

                        //preenche o cboValor
                        for (int i = 0; i < intTmp002; i++)
                        {
                            cboValor.Items.Add("'" + strTmp003[i] + "'");
                        }
                        break;


                    case "System.Int":
                        int[] intLista = new int[dtTabelaPB.Rows.Count - 1]; // drLinhas.Length 

                        //transporta os valores da coluna selecionada para um Array, para que possa ser ordenado
                        for (int i = 0; i < dtTabelaPB.Rows.Count - 1; i++) //resgata os valores da tabela em um array (drLinhas.Length)
                        {
                            string strIntString = dtTabelaPB.Rows[i].ItemArray[intTmp001].ToString();
                                                       //drLinhas[i].ItemArray[intTmp001].ToString();
                            if (strIntString != "")
                            {
                                intLista[i] = System.Int32.Parse(strIntString);
                            }
                            else
                            {
                                intLista[i] = -1;
                            }
                        }

                        //faz o retorno de apenas valores unicos e ordena os valores
                        int intTmp003 = dd.GetDistinctValues<int>(intLista).Length;
                        int[] intTmp004 = new int[intTmp003];
                        intTmp004 = dd.GetDistinctValues<int>(intLista);
                        Array.Sort(intTmp004);

                        //preenche o cboValor
                        for (int i = 0; i < intTmp001; i++)
                        {
                            cboValor.Items.Add(intTmp004[i].ToString());
                        }
                        break;

                    case "System.Double":
                        double[] dblLista = new double[dtTabelaPB.Rows.Count - 1];

                        for (int i = 0; i < dtTabelaPB.Rows.Count - 1; i++) //resgata os valores da tabela em um array
                        {
                            string strDoubleString = dtTabelaPB.Rows[i].ItemArray[intTmp001].ToString();
                                                          //drLinhas[i].ItemArray[intTmp001].ToString();
                            if (strDoubleString != "")
                            {
                                dblLista[i] = System.Double.Parse(strDoubleString);
                            }
                            else
                            {
                                dblLista[i] = -1;
                            }
                        }
                        //faz o retorno de apenas valores unicos e ordena os valores

                        int intTmp003_d = dd.GetDistinctValues<double>(dblLista).Length;
                        double[] dblTmp004_d = new double[intTmp003_d];
                        dblTmp004_d = dd.GetDistinctValues<double>(dblLista);
                        Array.Sort(dblTmp004_d);

                        //preenche o cboValor
                        for (int i = 0;
                            i < intTmp003_d;
                            i++)
                        {
                            string strValor = dblTmp004_d[i].ToString();
                            strValor = strValor.Replace(',', '.');
                            cboValor.Items.Add(strValor);
                        }
                        break;


                        //=================
                        // pra cima nao
                        //=================
                    case "System.Decimal":
                        decimal[] dcmLista = new decimal[dtTabelaPB.Rows.Count - 1];

                        for (int i = 0; i < dtTabelaPB.Rows.Count - 1; i++) //resgata os valores da tabela em um array
                        {
                            string strDecimalString = dtTabelaPB.Rows[i].ItemArray[intTmp001].ToString();
                            //drLinhas[i].ItemArray[intTmp001].ToString();
                            if (strDecimalString != "")
                            {
                                dcmLista[i] = System.Decimal.Parse(strDecimalString);
                            }
                            else
                            {
                                dcmLista[i] = -1;
                            }
                        }
                        //faz o retorno de apenas valores unicos e ordena os valores

                        int intTmp003_dc = dd.GetDistinctValues<decimal>(dcmLista).Length;
                        decimal[] dblTmp004_dc = new decimal[intTmp003_dc];
                        dblTmp004_dc = dd.GetDistinctValues<decimal>(dcmLista);
                        Array.Sort(dblTmp004_dc);

                        //preenche o cboValor
                        for (int i = 0;
                            i < intTmp003_dc;
                            i++)
                        {
                            string strValor = dblTmp004_dc[i].ToString();
                            strValor = strValor.Replace(',', '.');
                            cboValor.Items.Add(strValor);
                            //cboValor.Items.Add(dblTmp004_dc[i].ToString());
                        }
                        break;


                    //=================
                    // pra baixo nao
                    //=================

                    case "System.Boolean":
                        bool[] boolLista = new bool[dtTabelaPB.Rows.Count - 1];

                        for (int i = 0; i < dtTabelaPB.Rows.Count - 1; i++) //resgata os valores da tabela em um array
                        {
                            string strBoolString = dtTabelaPB.Rows[i].ItemArray[intTmp001].ToString();
                            //drLinhas[i].ItemArray[intTmp001].ToString();
                            if (strBoolString != "")
                            {
                                boolLista[i] = System.Boolean.Parse(strBoolString);
                            }
                            else
                            {
                                boolLista[i] = false;
                            }
                        }
                        //faz o retorno de apenas valores unicos e ordena os valores

                        int intTmp003_b = dd.GetDistinctValues<bool>(boolLista).Length;
                        bool[] dblTmp004_b = new bool[intTmp003_b];
                        dblTmp004_b = dd.GetDistinctValues<bool>(boolLista);
                        Array.Sort(dblTmp004_b);

                        //preenche o cboValor
                        for (int i = 0;
                            i < intTmp003_b;
                            i++)
                        {
                            cboValor.Items.Add(dblTmp004_b[i].ToString());
                        }
                        break;
                }
           }
            catch (Exception Ex)
            {
                MessageBox.Show("Um erro ocorreu com este projeto. Entre em contato com seu desenvolvedor informando o erro: \r\n" +
                    Ex.Message);
            }
        }
Exemple #2
0
        /// <summary>
        /// Realiza a pesquisa na tabela de acordo com a sintaxe definida pelo usuário
        /// </summary>
        /// <param name="sintaxe">sintaxe de pesquisa criada pelo usuário</param>
        /// <param name="ehpesquisa">valor para determinar se é uma pesquisa ou uma verificação</param>
        /// <returns>retorna se a pesquisa teve resultados corretos, evitando a execução erronea do software</returns>
        public bool Pesquisa(string sintaxe,bool ehpesquisa)
        {
            bool PesquisaCorreta = false;
            string[] strResultado = {"","","","",""};
            int parte = 0;

            try
            {
                DataRow[] dr1 = dtTabelaPB.Select(sintaxe);
                
                int intTmp001 = dr1.Length;

                if (sintaxe != "")
                {
                    double dblTmp001 = 0;
                    for (int i = 0; i < intTmp001; i++)
                    {
                        int intColArea = dtTabelaPB.Columns[strPrmAdicional[5]].Ordinal;//int.Parse(tmp001);
                        int intColShape = dtTabelaPB.Columns[strPrmAdicional[6]].Ordinal;

                        string strTmp001 = dr1[i][intColArea].ToString();
                        dblTmp001 = dblTmp001 + System.Double.Parse(strTmp001);

                        string ColunaDataTipo = dtTabelaPB.Columns[strPrmAdicional[6]].DataType.ToString();

                        if (strResultado[parte].Length > 0)
                        {
                            if (ColunaDataTipo == "System.String")
                            {
                                strResultado[parte] = strResultado[parte] + " OR " + strPrmAdicional[0] +
                                    "='" + dr1[i][intColShape].ToString() + "'";
                            }
                            else
                            {
                                strResultado[parte] = strResultado[parte] + " OR " + strPrmAdicional[0] + 
                                    "=" + dr1[i][intColShape].ToString() + "";
                            }
                             
                        }
                        else
                        {
                            if (ColunaDataTipo == "System.String")
                            {
                                strResultado[parte] = strPrmAdicional[0] + "=" + dr1[i][intColShape].ToString();
                            }
                            else
                            {
                                strResultado[parte] = strPrmAdicional[0] + "=" + dr1[i][intColShape].ToString() + "";
                            }
                        }

                        if (strResultado[parte].Length > 30000)
                        {
                            parte = parte + 1;
                        }

                    }
                    string strResulFim = strResultado[0] + "*" + strResultado[1] + "*" + strResultado[2] +
                        "*" + strResultado[3] + "*" + strResultado[4];

                    //dblTmp001 = dblTmp001 / 10000;
                    dblTmp001 = Math.Round(dblTmp001, 1);

                    switch (intTmp001)
                    {
                        case 0:
                            MessageBox.Show("A sintaxe está correta, entretanto, não foram encontrados polígonos"
                                + " que satisfaçam as condições da sintaxe elaborada.");
                            break;

                        default:
                            Dados dd = new Dados();
                            int temp001 = int.Parse(strPrmAdicional[4]);
                            MessageBox.Show("A área encontrada é de " + dblTmp001.ToString() + " " + dd.RetornaUnidade(0, temp001));
                            
                            if (ehpesquisa)
                            {
                                PesquisaCorreta = true;
                                prpStrBasica = strResulFim;
                            }
                            if (chkRelatorio.Checked)
                            {
                                frmFormatRel FormataRelatorio = new frmFormatRel(sintaxe, dtTabelaPB,
                                    strParametrosPesquisa, strPrmAdicional);
                                FormataRelatorio.prpFalso = this.prpRel;
                                FormataRelatorio.ShowDialog(this);                                
                            }
                            break;
                    }//switch
                }//if
                else
                {
                    if (chkRelatorio.Checked)
                    {
                        frmFormatRel FormataRelatorio = new frmFormatRel(sintaxe, dtTabelaPB,
                            strParametrosPesquisa, strPrmAdicional);
                        FormataRelatorio.prpFalso = this.prpRel;
                        FormataRelatorio.ShowDialog(this);
                    }
                    else
                    {
                        MessageBox.Show("A caixa de pesquisa está vazia.");
                    }
                    
                }
            }//try
            catch (Exception Ex)
            {
                MessageBox.Show(Ex.Message + "\r\nOcorreu um erro com a sintaxe. Verifique");
            }


            return PesquisaCorreta;
        }
Exemple #3
0
        /// <summary>
        /// metodo que controla a pesquisa e a montagem do documento PDF.
        /// </summary>
        ///
        private void GeraPDF()
        {
            try
            {
                //############################
                //    DECLARAÇÃO VARIAVEIS
                //############################
                DateTime AGORA       = DateTime.Now;
                string   nomeArquivo = "Relatorio_(" + AGORA.Day.ToString() + "-" + AGORA.Month.ToString() + "-" + AGORA.Year.ToString()
                                       + ")_" + AGORA.Hour.ToString() + "." + AGORA.Minute.ToString() + "." + AGORA.Second.ToString() + ".pdf";

                string PathDoc = Path.GetTempPath() + nomeArquivo;
                if (IsFileOpen(PathDoc))
                {
                    return;
                }
                else
                {
                    DataRow[] Linhas = DT_Dados.Select(Sintaxe);
                    //pega a posição da coluna
                    int ind_Grupo    = PosColuna(cboGrupo.SelectedItem.ToString());
                    int ind_Subgrupo = PosColuna(cboSubGrupo.SelectedItem.ToString());
                    int ind_Classe   = PosColuna(cboClasse.SelectedItem.ToString());
                    int ind_Valor    = PosColuna(ParRelatorio[5]);
                    //ind_Valor

                    string tmpCampo1Grupo = "";
                    string tmpCampo2Grupo = "";

                    double calculoValores = 0;
                    int    ContagemLinhas = 0;

                    int arredondamento = Int32.Parse(nudArredonda.Value.ToString());

                    //arrays definitivos
                    string[] ValGrupos;
                    string[] ValSubgrupos;
                    string[] ValClasse;

                    //variaveis que calcula os valores
                    //totais, para cálculo de porcentagem
                    double TotSugGrupo   = 0;
                    double TotGrupo      = 0;
                    double TotAreaEstudo = Calculo(ind_Valor, ckbAreaPerc.Checked);;


                    //############################
                    //          CODIGO
                    //############################

                    ValGrupos = pesquisa(ind_Grupo);

                    //Inicio do arquivo PDF
                    //Document DocPDF1 = new Document(PageSize.A4, 57f, 57f, 57f, 57f);
                    DocPDF = new Document(PageSize.A4, 30f, 30f, 30f, 30f);
                    // cria um Writer para o documento

                    PdfWriter.GetInstance(DocPDF, new
                                          FileStream(PathDoc, FileMode.Create));

                    string CalculoRelatorio = "";
                    if (radSoma.Checked)
                    {
                        CalculoRelatorio = radSoma.Text;
                    }
                    else if (radPercEstudo.Checked)
                    {
                        CalculoRelatorio = radPercEstudo.Text;
                    }
                    else if (radPercGrupo.Checked)
                    {
                        CalculoRelatorio = radPercGrupo.Text;
                    }
                    else if (radPercSubGrupo.Checked)
                    {
                        CalculoRelatorio = radPercSubGrupo.Text;
                    }
                    else if (radOmitirArea.Checked)
                    {
                        CalculoRelatorio = radOmitirArea.Text;
                    }

                    // abre o documento
                    DocPDF.Open();
                    //DocPDF.AddAuthor(Sintaxe);
                    DocPDF.AddKeywords(Sintaxe + "\r\n" + cboGrupo.SelectedItem.ToString() + "\r\n" + cboSubGrupo.SelectedItem.ToString() +
                                       "\r\n" + cboClasse.SelectedItem.ToString() + "\r\n" + CalculoRelatorio + "\r\n" + ckbAreaPerc.Checked.ToString());
                    //DocPDF.AddAuthor("Embrapa Solos\r\nteste");
                    //DocPDF.AddTitle("Sintaxe");
                    DocPDF.Add(AddCabecalho());

                    for (int a = 0; a < ValGrupos.Length; a++)
                    {
                        if (radPercGrupo.Checked)
                        {
                            //=== calculo todo o grupo ===
                            TotGrupo = Calculo(ValGrupos[a], ind_Grupo, ind_Valor, ckbAreaPerc.Checked);
                            //=== calculo todo o grupo ===
                        }

                        Phrase frase = new Phrase("");
                        if (ContagemLinhas == 0)
                        {
                            //insere o cabeçalho PDF da pagina

                            DocPDF.Add(frase);
                            if (ind_Grupo == ind_Subgrupo | ind_Subgrupo == ind_Classe | ind_Grupo == ind_Classe)
                            {
                                //=======================================================
                                //         Insere o cabeçalho da classe da tabela
                                //=======================================================
                                Dados  dd      = new Dados();
                                string unidade = dd.RetornaUnidade(0, Int32.Parse(ParRelatorio[4]));

                                string tmpCampo2TCl = cboClasse.SelectedItem.ToString();
                                string tmpCampo3TCl = "Área - " + unidade;

                                DocPDF.Add(AddTClasse(tmpCampo2TCl, tmpCampo3TCl));
                                ContagemLinhas = ControlaLinhas(ContagemLinhas);
                                //=======================================================
                            }
                        } // if (ContagemLinhas == 0)


                        if (ind_Grupo != ind_Subgrupo | ind_Grupo != ind_Classe)
                        {
                            //=======================================================
                            //         Insere a linha de grupo da tabela
                            //=======================================================
                            tmpCampo1Grupo = cboGrupo.SelectedItem.ToString();
                            tmpCampo2Grupo = ValGrupos[a];
                            DocPDF.Add(AddGrupo(tmpCampo1Grupo, tmpCampo2Grupo));
                            ContagemLinhas = ControlaLinhas(ContagemLinhas);
                            //=======================================================
                        }

                        ValSubgrupos = pesquisa(ValGrupos[a], ind_Grupo, ind_Subgrupo);
                        for (int b = 0; b < ValSubgrupos.Length; b++)
                        {
                            if (radPercSubGrupo.Checked)
                            {
                                //=== calculo todo o subgrupo ===
                                TotSugGrupo = Calculo(ValSubgrupos[b], ind_Subgrupo, ind_Valor, ckbAreaPerc.Checked);
                                //=== calculo todo o subgrupo ===
                            }
                            if (ind_Grupo != ind_Subgrupo | ind_Subgrupo != ind_Classe)
                            {
                                //=======================================================
                                //         Insere a linha de SubGrupo da tabela
                                //=======================================================
                                string tmpCampo1SG = cboSubGrupo.SelectedItem.ToString();
                                string tmpCampo2SG = ValSubgrupos[b];

                                DocPDF.Add(AddSubgrupo(tmpCampo1SG, tmpCampo2SG));
                                ContagemLinhas = ControlaLinhas(ContagemLinhas);
                                //=======================================================

                                //=======================================================
                                //         Insere o cabeçalho da classe da tabela
                                //=======================================================
                                Dados  dd      = new Dados();
                                string unidade = dd.RetornaUnidade(0, Int32.Parse(ParRelatorio[4]));

                                string tmpCampo2TCl = "";
                                string tmpCampo3TCl = "";

                                if (radSoma.Checked)
                                {
                                    tmpCampo2TCl = cboClasse.SelectedItem.ToString();
                                    tmpCampo3TCl = "Área - " + unidade;
                                }
                                else if (radPercSubGrupo.Checked)
                                {
                                    tmpCampo2TCl = cboClasse.SelectedItem.ToString();
                                    tmpCampo3TCl = "% da área para " + tmpCampo1SG + " = " + tmpCampo2SG;
                                }
                                else if (radPercGrupo.Checked)
                                {
                                    tmpCampo2TCl = cboClasse.SelectedItem.ToString();
                                    tmpCampo3TCl = "% da área para " + tmpCampo1Grupo + " = " + tmpCampo2Grupo;
                                }
                                else if (radPercEstudo.Checked)
                                {
                                    tmpCampo2TCl = cboClasse.SelectedItem.ToString();
                                    tmpCampo3TCl = "% da área em relação a região de estudo";
                                }
                                else if (radOmitirArea.Checked)
                                {
                                    tmpCampo2TCl = cboClasse.SelectedItem.ToString();
                                    tmpCampo3TCl = "";
                                }

                                DocPDF.Add(AddTClasse(tmpCampo2TCl, tmpCampo3TCl));
                                ContagemLinhas = ControlaLinhas(ContagemLinhas);
                                //=======================================================
                            }

                            ValClasse = pesquisa(ValGrupos[a], ind_Grupo, ValSubgrupos[b], ind_Subgrupo, ind_Classe);
                            for (int c = 0; c < ValClasse.Length; c++)
                            {
                                //calculoValores = Calculo(ValClasse[c], ind_Classe, ind_Valor);
                                calculoValores = Calculo(ValClasse[c], ind_Classe, ValSubgrupos[b], ind_Subgrupo,
                                                         ValGrupos[a], ind_Grupo, ind_Valor);
                                //=======================================================
                                //         Insere a linha da Classe da tabela
                                //=======================================================

                                string tmpCampo2Cl = "";
                                string tmpCampo3Cl = "";

                                if (radSoma.Checked)
                                {
                                    tmpCampo2Cl = ValClasse[c].ToString();
                                    tmpCampo3Cl = Math.Round(calculoValores, arredondamento).ToString();
                                    //tmpCampo3Cl =  calculoValores.ToString();
                                }
                                else if (radPercSubGrupo.Checked)
                                {
                                    tmpCampo2Cl = ValClasse[c].ToString();
                                    tmpCampo3Cl = CalculoPorcentagem(TotSugGrupo, calculoValores).ToString(); //marcar este
                                }
                                else if (radPercGrupo.Checked)
                                {
                                    tmpCampo2Cl = ValClasse[c].ToString();
                                    tmpCampo3Cl = CalculoPorcentagem(TotGrupo, calculoValores).ToString();
                                }
                                else if (radPercEstudo.Checked)
                                {
                                    tmpCampo2Cl = ValClasse[c].ToString();
                                    if (CalculoPorcentagem(TotAreaEstudo, calculoValores) == 0)
                                    {
                                    }

                                    tmpCampo3Cl = CalculoPorcentagem(TotAreaEstudo, calculoValores).ToString();
                                }
                                else if (radOmitirArea.Checked)
                                {
                                    tmpCampo2Cl = ValClasse[c].ToString();
                                    tmpCampo3Cl = "";
                                }
                                PdfPTable tabelaClasse = AddClasse(tmpCampo2Cl, tmpCampo3Cl);
                                DocPDF.Add(tabelaClasse);
                                ContagemLinhas = ControlaLinhas(ContagemLinhas);
                                //=======================================================
                            }
                        }

                        prgAndamento.Value = Convert.ToInt32(a * 99 / ValGrupos.Length);
                    }//fim do laço for a
                    DocPDF.Add(AddRodape());
                    DocPDF.Close();
                    System.Diagnostics.Process.Start(PathDoc);
                }
            }
            catch (Exception Ex)
            {
                MessageBox.Show("Um erro ocorreu com este projeto. Entre em contato com seu desenvolvedor informando o erro: \r\n" +
                                Ex.Message);
            }
            prgAndamento.Value = 0;
        }