コード例 #1
0
        internal static bool Insert(LicitacaoHistorico historico)
        {
            LicitacaoHistoricoRepository repoH = new LicitacaoHistoricoRepository();

            if (!repoH.IfExist(historico))
            {
                try
                {
                    repoH.Insert(historico);
                    return(true);
                }
                catch (Exception ex)
                {
                    RService.Log("Exception (Insert) CNETHT: " + ex.Message + " / " + ex.StackTrace + " / " + ex.InnerException + " at {0}", Path.GetTempPath() + "CNETHT.txt");
                    return(false);
                }
            }
            return(false);
        }
コード例 #2
0
        private static void GetHistoricos(Licitacao l, string Historic)
        {
            try
            {
                string num        = Regex.Replace(l.Num, @"[^\d+]", "");
                string parametros = string.Format(@"coduasg={0}&modprp=5&numprp={1}", l.Uasg, num);

                HtmlDocument htmlDocument = WebHandle.HtmlParaObjeto(Constants.CN_HISTORICO_LINK + parametros, Encoding.GetEncoding("ISO-8859-1"));

                if (htmlDocument.DocumentNode.LastChild == null)
                {
                    return;
                }

                if (!Regex.IsMatch(htmlDocument.DocumentNode.InnerHtml, @"rico de eventos "))
                {
                    string          expRegular = "<tr bgcolor=\"#ffffff\" class=\"tex3a\">(.+?)</tr>";
                    MatchCollection matches    = Regex.Matches(Regex.Replace(htmlDocument.DocumentNode.InnerHtml, "\n", "").Replace("\r", ""), expRegular);

                    if (matches.Count > 0)
                    {
                        RService.Log("(GetHistoricos) " + Historic + ": Buscando histórico da licitação: " + l.IdLicitacaoFonte + " at {0}", Path.GetTempPath() + Historic + ".txt");

                        for (int i = 0; i < matches.Count; i++)
                        {
                            LicitacaoHistorico historico = new LicitacaoHistorico();
                            historico.IdLicitacao = l.Id;

                            var      helper    = Regex.Match(matches[i].Value, @"\d{2}/\d{2}/\d{4}( +)\d{2}\:\d{2}\:\d{2}").Value;
                            DateTime valorData = new DateTime();
                            historico.DataCadastro = DateTime.TryParse(helper, out valorData) ? valorData : new DateTime();

                            helper = Regex.Match(matches[i].Value, "<td align=\"left\">(.+?)</td>").Value;
                            helper = Regex.Replace(helper, @"&nbsp", " ");
                            helper = Regex.Replace(helper, "<td align=\"left\">", "");
                            helper = Regex.Replace(helper, "</td>", "");
                            historico.Historico = helper.Trim();

                            if (LicitacaoHistoricoController.Insert(historico))
                            {
                                RService.Log("(ConsultaAtaPregao) " + Historic + ": Histórico registrado com sucesso" + " at {0}", Path.GetTempPath() + Historic + ".txt");
                                NumHistoricos++;
                            }
                        }

                        if (matches.Count == 1)
                        {
                            RService.Log("(GetHistoricos) " + Historic + ": Encontrado 1 item de histórico at {0}", Path.GetTempPath() + Historic + ".txt");
                        }
                        else if (matches.Count > 1)
                        {
                            RService.Log("(GetHistoricos) " + Historic + ": Encontrados " + matches.Count + " itens de histórico at {0}", Path.GetTempPath() + Historic + ".txt");
                        }
                        else
                        {
                            RService.Log("(GetHistoricos) " + Historic + ": Não foram encontrados novos itens de histórico at {0}", Path.GetTempPath() + Historic + ".txt");
                        }
                    }
                    else
                    {
                        RService.Log("(GetHistoricos) " + Historic + ": Não foram encontrados itens de histórico at {0}", Path.GetTempPath() + Historic + ".txt");
                    }
                }
            }
            catch (Exception e)
            {
                RService.Log("Exception (GetHistoricos) " + Historic + " para licitação " + l.IdLicitacaoFonte + ": " + e.Message + " / " + e.StackTrace + " / " + e.InnerException + " at {0}", Path.GetTempPath() + Historic + ".txt");
            }
        }
コード例 #3
0
        private static void ConsultaAtaPregao(Licitacao licitacao)
        {
            RService.Log("(ConsultaAtaPregao) " + Historic + ": Buscando itens da ata do pregão at {0}", Path.GetTempPath() + Historic + ".txt");
            try
            {
                if (!string.IsNullOrEmpty(licitacao.Uasg) && !string.IsNullOrEmpty(licitacao.NumPregao))
                {
                    List <LicitacaoHistorico> itens = new List <LicitacaoHistorico>();

                    string       _num    = Regex.Replace(licitacao.NumPregao, @"[^\d+]", "");
                    string       _url    = string.Format(Constants.CN_ATA_PREGAO, licitacao.Uasg, _num);
                    HtmlDocument htmlDoc = WebHandle.GetHtmlDocOfPage(_url, Encoding.GetEncoding("ISO-8859-1"));

                    string _valorRegex = Regex.Match(htmlDoc.DocumentNode.InnerHtml, @"exibeQuadro\(\d+").Value;
                    string _codPregao  = Regex.Match(_valorRegex, @"\d+").Value;

                    if (!string.IsNullOrEmpty(_codPregao))
                    {
                        Dictionary <string, string> tipos = new Dictionary <string, string>();
                        tipos.Add("A", "Aviso");
                        tipos.Add("E", "Esclarecimento");
                        tipos.Add("I", "Impugnação");

                        foreach (var tipo in tipos)
                        {
                            RService.Log("(ConsultaAtaPregao) " + Historic + ": Buscando itens do tipo: " + tipo.Value + " at {0}", Path.GetTempPath() + Historic + ".txt");

                            string _urlItem = string.Format(Constants.CN_PREGAO_AVISOS_DETALHE, _codPregao, tipo.Key);

                            htmlDoc = WebHandle.GetHtmlDocOfPage(_urlItem, Encoding.GetEncoding("ISO-8859-1"));

                            var listaQaCod = Regex.Matches(htmlDoc.DocumentNode.InnerHtml, @"qaCod=[\d]+&texto=T");

                            foreach (var linkQaCod in listaQaCod)
                            {
                                try
                                {
                                    //busca mensagem
                                    string _urlItemDesc = string.Format(Constants.CN_PREGAO_AVISOS_ITEM, linkQaCod.ToString());
                                    htmlDoc = WebHandle.GetHtmlDocOfPage(_urlItemDesc, Encoding.GetEncoding("ISO-8859-1"));

                                    LicitacaoHistorico historico = new LicitacaoHistorico();
                                    historico.IdLicitacao = licitacao.Id;

                                    var tds = htmlDoc.DocumentNode.Descendants("td").Where(p => !p.InnerText.Trim().Equals(""));

                                    //pega data e descrição
                                    foreach (var td in tds)
                                    {
                                        try
                                        {
                                            if (historico.DataCadastro == new DateTime() && Regex.IsMatch(td.InnerText, @"\d{2}/\d{2}/\d{4} \d{2}:\d{2}:\d{2}"))
                                            {
                                                string   helper    = Regex.Match(td.InnerText, @"\d{2}/\d{2}/\d{4} \d{2}:\d{2}:\d{2}").Value;
                                                DateTime valorData = new DateTime();
                                                historico.DataCadastro = DateTime.TryParse(helper, out valorData) ? valorData : new DateTime();

                                                historico.Historico = td.InnerText.Split(new string[] { helper }, StringSplitOptions.RemoveEmptyEntries)[0].Trim();
                                            }
                                            else
                                            {
                                                historico.Mensagem = td.InnerText;
                                            }
                                        }
                                        catch (Exception e)
                                        {
                                            RService.Log("Exception (ConsultaAtaPregao) getData" + Historic + " para a licitacao " + licitacao.IdLicitacaoFonte + ": " + e.Message + " / " + e.StackTrace + " / " + e.InnerException + " at {0}", Path.GetTempPath() + Historic + ".txt");
                                        }
                                    }

                                    //Caso tenha resposta
                                    string _codQa = linkQaCod.ToString().Replace("&texto=T", "");
                                    _urlItemDesc = string.Format(Constants.CN_PREGAO_AVISOS_ITEM, _codQa) + "&texto=R";
                                    htmlDoc      = WebHandle.GetHtmlDocOfPage(_urlItemDesc, Encoding.GetEncoding("ISO-8859-1"));
                                    tds          = htmlDoc.DocumentNode.Descendants("td").Where(p => !p.InnerText.Trim().Equals(""));

                                    if (tds.Count() > 2)
                                    {
                                        foreach (var td in tds)
                                        {
                                            if (!Regex.IsMatch(td.InnerText, @"\d{2}/\d{2}/\d{4} \d{2}:\d{2}:\d{2}"))
                                            {
                                                historico.Resposta = td.InnerText;
                                            }
                                        }
                                    }

                                    if (LicitacaoHistoricoController.Insert(historico))
                                    {
                                        NumHistoricos++;
                                    }
                                }
                                catch (Exception e)
                                {
                                    RService.Log("Exception (ConsultaAtaPregao) getMensagem " + Historic + " para a licitacao " + licitacao.IdLicitacaoFonte + ": " + e.Message + " / " + e.StackTrace + " / " + e.InnerException + " at {0}", Path.GetTempPath() + Historic + ".txt");
                                }
                            }
                        }
                    }
                    else
                    {
                        RService.Log("(ConsultaAtaPregao) " + Historic + ": Pregão não contém ata pois não foi encerrado at {0}", Path.GetTempPath() + Historic + ".txt");
                    }
                }
            }
            catch (Exception e)
            {
                RService.Log("Exception (ConsultaAtaPregao) " + Historic + ": " + e.Message + " / " + e.StackTrace + " / " + e.InnerException + " at {0}", Path.GetTempPath() + Historic + ".txt");
            }
        }