示例#1
0
        //=========================================
        //             Eventos Diversos
        //=========================================
        private void frmFormatRel_Load(object sender, EventArgs e)
        {
            try
            {
                for (int i = 0; i < ColunasTabelas.Length / 3; i++)
                {
                    string Nome_da_coluna = ColunasTabelas[i, 1];
                    if (Nome_da_coluna != null)
                    {
                        string Dado_da_coluna = DT_Dados.Columns[Nome_da_coluna].DataType.ToString();

                        cboGrupo.Items.Add(ColunasTabelas[i, 0]);
                        cboSubGrupo.Items.Add(ColunasTabelas[i, 0]);
                        cboClasse.Items.Add(ColunasTabelas[i, 0]);
                    }
                }
                Dados  dd      = new Dados();
                string unidade = dd.RetornaUnidade(0, Int32.Parse(ParRelatorio[4]));
                //cboValores.Items.Add("Área - " + unidade);

                cboGrupo.SelectedIndex    = 0;
                cboSubGrupo.SelectedIndex = 0;
                cboClasse.SelectedIndex   = 0;
                //cboValores.SelectedIndex = 0;
            }

            catch
            {
            }
        }
示例#2
0
        public bool Pesquisa(string sintaxe, bool ehpesquisa)
        {
            bool PesquisaCorreta = false;
            string[] strResultado = { "", "", "", "", "" };
            int parte = 0;
            try
            {
                DataRow[] dr1 = dtTabelaPA.Select(sintaxe);
                int intTmp001 = dr1.Length;

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

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

                        string ColunaDataTipo = dtTabelaPA.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;
                                prpStrAvancada = strResulFim;
                            }
                            if (chkRelatorio.Checked)
                            {
                                frmFormatRel FormataRelatorio = new frmFormatRel(sintaxe, dtTabelaPA,
                                    strParametrosPesquisa, strPrmAdicional);
                                FormataRelatorio.prpFalso = this.prpRel;
                                FormataRelatorio.ShowDialog(this);
                            }
                            break;
                    }//switch
                }//if
                else
                {
                    if (chkRelatorio.Checked)
                    {
                        frmFormatRel FormataRelatorio = new frmFormatRel(sintaxe, dtTabelaPA,
                            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");
            }
            //this.UseWaitCursor = false;

            return PesquisaCorreta;
        }
示例#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;
        }