/// <summary> /// Busca retorno de lotes selecionados. /// </summary> /// <param name="ilLotes">IList(int) com lotes que deverão ser consultados.</param> /// <returns>true/false indicando se o busca foi realizado com sucesso.</returns> public bool Buscar_Retorno_Lote(IList <int> ilLotes) { bool bRetorno = false; foreach (int iLote in ilLotes) { string sQuery = string.Format("select protocolo, empresa from notas_fiscais_lotes where nota_fiscal_lote = {0}", iLote); DataRow row = SQL.Select(sQuery, "x", false).Rows[0]; string sProtocolo = row["Protocolo"].ToString(); int iEmpresa = Convert.ToInt32(row["Empresa"]); row.Table.Dispose(); DataRow row_Empresa = this.Buscar_Dados_Empresa(iEmpresa); //-- busca dados da empresa //-- Cria a instancia dos valores para consulta. CompSoft.NFpaulista_Mod1.Autenticacao autentic = new CompSoft.NFpaulista_Mod1.Autenticacao(); CompSoft.NFpaulista_Mod1.ArquivoNF_Mod1 nfp = new CompSoft.NFpaulista_Mod1.ArquivoNF_Mod1(); //-- Seta parametros para autenticação do usuário. autentic.CategoriaUsuario = (byte)row_Empresa["NFP_Categoria_Usuario"]; autentic.CNPJ = row_Empresa["CNPJ"].ToString(); autentic.Usuario = row_Empresa["NFP_Usuario"].ToString(); autentic.Senha = row_Empresa["NFP_Senha"].ToString(); nfp.AutenticacaoValue = autentic; //-- consulta o protocolo try { string sRetornoConsulta = nfp.Consultar(sProtocolo); this.Grava_Informacoes_Consulta(iLote, sRetornoConsulta); } catch { CompSoft.compFrameWork.MsgBox.Show("Não foi possível acessar o WebService da Nota Fiscal Paulista, aguarde alguns instantes e tente novamente" , "Atençao" , System.Windows.Forms.MessageBoxButtons.OK , System.Windows.Forms.MessageBoxIcon.Warning); bRetorno = false; break; } } return(bRetorno); }
/// <summary> /// Enviar arquivos e dados para o WebService da Nota fiscal paulista /// </summary> /// <param name="iEmpresa">int com o código da empresa</param> /// <param name="ilLotes">IList(Int) com os lotes qua serão enviados.</param> /// <returns>true/false se o envio foi feito com sucesso.</returns> public bool Enviar_Arquivos(int iEmpresa, IList <int> ilLotes) { string sRetornoEnviar = string.Empty; bool bRetorno = true; //-- busca dados da empresa DataRow row_Empresa = this.Buscar_Dados_Empresa(iEmpresa); //-- Varre todos os lotes gerados foreach (int iLote in ilLotes) { string sQuery = "SELECT Arquivo_Envio FROM NOTAS_FISCAIS_LOTES where nota_fiscal_lote = {0}"; sQuery = string.Format(sQuery, iLote); FileInfo fi = new FileInfo(SQL.ExecuteScalar(sQuery).ToString()); //-- Verifica se o arquivo existe. if (fi.Exists) { //-- Cria a instancia dos valores para envio. CompSoft.NFpaulista_Mod1.Autenticacao autentic = new CompSoft.NFpaulista_Mod1.Autenticacao(); CompSoft.NFpaulista_Mod1.ArquivoNF_Mod1 nfp = new CompSoft.NFpaulista_Mod1.ArquivoNF_Mod1(); nfp.Timeout = 600000; //-- 10 minutos... //-- Seta parametros para autenticação do usuário. autentic.CategoriaUsuario = (byte)row_Empresa["NFP_Categoria_Usuario"]; autentic.CNPJ = row_Empresa["CNPJ"].ToString(); autentic.Usuario = row_Empresa["NFP_Usuario"].ToString(); autentic.Senha = row_Empresa["NFP_Senha"].ToString(); nfp.AutenticacaoValue = autentic; //-- Abre o arquivo e captura dados para a variavel. StreamReader sr = new StreamReader(fi.FullName, Encoding.UTF8); string sConteudo = sr.ReadToEnd(); sr.Close(); sr.Dispose(); sr = null; //-- faz o envio dos dados. try { sRetornoEnviar = nfp.Enviar(fi.Name, sConteudo, string.Empty); } catch { sRetornoEnviar = DateTime.Now.ToString("dd/MM/yyyy hh:mm:ss") + "||999|Erro ao conectar ao WebService"; bRetorno = false; //-- Insere log this.TrataRetorno_Enviar(iLote, sRetornoEnviar); break; } } else { sRetornoEnviar = DateTime.Now.ToString("dd/MM/yyyy hh:mm:ss") + "||999|Arquivo inexistente"; bRetorno = false; //-- Insere log this.TrataRetorno_Enviar(iLote, sRetornoEnviar); } //-- Trava o retorno do processo de envio. bool bTrataRetorno = this.TrataRetorno_Enviar(iLote, sRetornoEnviar); if (bRetorno) { bRetorno = bTrataRetorno; } //-- Salva o arquivo de retorno em disco para eventuais excessões. try { string sPath = System.Windows.Forms.Application.StartupPath; if (!sPath.EndsWith(@"\")) { sPath += @"\"; } StreamWriter sw = new StreamWriter(sPath + "RetornoNFP.txt"); sw.Write(sRetornoEnviar); } catch { } } //-- Verifica se o envio foi realizado com sucesso e tenta capturar o retorno if (bRetorno) { //-- Aguarda 10 segundos para tentativa de processamento do lote pela Secretária da Fazenda. System.Threading.Thread.Sleep(10000); //-- busca atualizações do lote. this.Buscar_Retorno_Lote(ilLotes); } return(bRetorno); }