private void ExecutarEnviaArquivo() { Custom = false; gpbArquivos.Visible = false; btnSel.Visible = false; btnDes.Visible = false; gpbEnviados.Visible = true; btnVoltar.Visible = true; btnEnviar.Visible = false; try { pnlArquivo.Controls?.Cast <CheckBox>().Where(_check => _check.Checked)?.ToList().ForEach(_check => { Model.Report.DCTF.RetornoREINF.RetornoEvento _retornoEvento = new Model.Report.DCTF.RetornoREINF.RetornoEvento { Descricao = _check.Text }; TreeNode _nodeCheck = new TreeNode(_check.Text); int _contador = 0; string _url; if (((SCI.Reinf.Irko.TipoEvento)_check.Tag).Codigo == "R-5011") { _url = "https://www.irko.com.br/csp/prgdcn/reinf/retornoXML.csp?"; _url += "CODEMP=" + GetDesktop().GetEmpresa().Codigo.ToString(); _url += "&GUID=" + Guid; } else { _url = "https://www.irko.com.br/csp/prgdcn/reinf/arquivoXML.csp?"; _url += "CODEMP=" + GetDesktop().GetEmpresa().Codigo.ToString(); _url += "&NOMREG=" + ((SCI.Reinf.Irko.TipoEvento)_check.Tag).Codigo; _url += "&GUID=" + Guid; } XmlDocument _xml = new XmlDocument { PreserveWhitespace = false }; _xml.Load(_url); if (_xml.DocumentElement.Name == "Fim" || _xml.DocumentElement.Name == "Falha") { } else { XmlNode _xmlReinf = _xml.DocumentElement; string _cnpjTransmissao = "07074083000102"; string _cnpjContr = string.Empty; var resultadoCNPJ = wrReinf.RecuperaCNPJCPFCertificado(Guid); if (resultadoCNPJ.Sucesso) { _cnpjContr = resultadoCNPJ.RetornoResultadoRecuperaCNPJCPFCertificado; } if (String.IsNullOrEmpty(_cnpjContr)) { _cnpjContr = _xml.DocumentElement.GetElementsByTagName("ideContri")?.Cast <XmlElement>() .FirstOrDefault()?.GetElementsByTagName("nrInsc")?.Cast <XmlElement>().FirstOrDefault()?.InnerText; } String _tpAmb = _xml.DocumentElement.GetElementsByTagName("tpAmb")?.Cast <XmlElement>()? .FirstOrDefault()?.InnerText; _cnpjTransmissao = _cnpjContr; var _xmlElements = _xml.GetElementsByTagName("loteEventos").Cast <XmlElement>().FirstOrDefault(); List <string> _listaId = _xmlElements?.Cast <XmlNode>().Where(_node => _node.Name == "evento")? .Select(_id => _id.Attributes["id"].Value)?.ToList(); Resultado _resultadoAssinar = new Resultado(); _resultadoAssinar.Sucesso = true; if (((SCI.Reinf.Irko.TipoEvento)_check.Tag).Codigo != "R-5011") { _resultadoAssinar = AssinarXML(ref _xml, _cnpjContr); } if (_resultadoAssinar.Sucesso) { XmlNode _retorno = null; SCI.Base.Resultado <System.Web.Services.Protocols.SoapHttpClientProtocol> _resultado = GetWrAssinado(_cnpjTransmissao, ((SCI.Reinf.Irko.TipoEvento)_check.Tag).Codigo, _tpAmb); if (_resultado.Sucesso) { System.Web.Services.Protocols.SoapHttpClientProtocol _wrAssinado = _resultado.Retorno; try { System.Net.ServicePointManager.ServerCertificateValidationCallback += delegate( object sender, X509Certificate cert, X509Chain chain, SslPolicyErrors sslPolicyErrors) { if (sslPolicyErrors == SslPolicyErrors.None) { return(true); } return(false); }; ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls; if (((SCI.Reinf.Irko.TipoEvento)_check.Tag).Codigo == "R-5011") { XmlNodeList xnList = _xmlReinf.SelectNodes("/ConsultaInformacoesConsolidadas"); byte _tipoInscricaoContribuinte = Convert.ToByte(xnList.Item(0).ChildNodes.Item(0).InnerText); string _numeroInscricaoContribuinte = xnList.Item(0).ChildNodes.Item(1).InnerText; string _numeroProtocoloFechamento = xnList.Item(0).ChildNodes.Item(2).InnerText; if (_tpAmb == "1") { _retorno = ((Reinf.Producao.Retorno.ConsultasReinf)_wrAssinado).ConsultaInformacoesConsolidadas(_tipoInscricaoContribuinte, _numeroInscricaoContribuinte, _numeroProtocoloFechamento); } else { _retorno = ((Reinf.ProducaoRestrita.Retorno.ConsultasReinf)_wrAssinado).ConsultaInformacoesConsolidadas(_tipoInscricaoContribuinte, _numeroInscricaoContribuinte, _numeroProtocoloFechamento); } } else { if (_tpAmb == "1") { _retorno = ((Reinf.Producao.Envio.RecepcaoLoteReinf)_wrAssinado).ReceberLoteEventos(_xmlReinf); } else { _retorno = ((Reinf.ProducaoRestrita.Envio.RecepcaoLoteReinf)_wrAssinado).ReceberLoteEventos(_xmlReinf); } } XmlDocument _docRetorno = new XmlDocument(); _docRetorno.LoadXml(_retorno.OuterXml); XmlElement _retornoElement = _docRetorno.DocumentElement; Reinf.Irko.ResultadoGravarRetornoEvento _retornoWR = GravarEnvio(_retorno, _listaId, _cnpjTransmissao, ((SCI.Reinf.Irko.TipoEvento)_check.Tag).Codigo); if (_retornoWR.Sucesso) { if (((SCI.Reinf.Irko.TipoEvento)_check.Tag).Codigo == "R-5011") { if (_retornoWR.RetornoRetornoTotEvt10300 != null) { Reinf.Irko.evtTotalContrib _retornoLoteEventos = _retornoWR.RetornoRetornoTotEvt10300.evtTotalContrib; _contador++; TreeNode _nodeArquivo = new TreeNode("Arquivo " + _contador.ToString()); TreeNode _nodeStatus = new TreeNode(_retornoLoteEventos.ideRecRetorno.ideStatus.descRetorno); TreeNode _nodeId = new TreeNode(_retornoLoteEventos.id); _retornoLoteEventos.ideRecRetorno.ideStatus.regOcorrs?.ToList().ForEach(_ocorr => { TreeNode _nodeTpOcorr = new TreeNode(_ocorr.tpOcorr.ToString()); _nodeId.Nodes.Add(_nodeTpOcorr); TreeNode _nodeCodResp = new TreeNode(_ocorr.codResp); _nodeId.Nodes.Add(_nodeCodResp); TreeNode _nodeDscResp = new TreeNode(_ocorr.dscResp); _nodeId.Nodes.Add(_nodeDscResp); }); _nodeStatus.Nodes.Add(_nodeId); _nodeArquivo.Nodes.Add(_nodeStatus); _nodeCheck.Nodes.Add(_nodeArquivo); } else { Reinf.Irko.evtTotalContrib1 _retornoLoteEventos = _retornoWR.RetornoRetornoTotEvt10400.evtTotalContrib; _contador++; TreeNode _nodeArquivo = new TreeNode("Arquivo " + _contador.ToString()); TreeNode _nodeStatus = new TreeNode(_retornoLoteEventos.ideRecRetorno.ideStatus.descRetorno); TreeNode _nodeId = new TreeNode(_retornoLoteEventos.id); _retornoLoteEventos.ideRecRetorno.ideStatus.regOcorrs?.ToList().ForEach(_ocorr => { TreeNode _nodeTpOcorr = new TreeNode(_ocorr.tpOcorr.ToString()); _nodeId.Nodes.Add(_nodeTpOcorr); TreeNode _nodeCodResp = new TreeNode(_ocorr.codResp); _nodeId.Nodes.Add(_nodeCodResp); TreeNode _nodeDscResp = new TreeNode(_ocorr.dscResp); _nodeId.Nodes.Add(_nodeDscResp); }); _nodeStatus.Nodes.Add(_nodeId); _nodeArquivo.Nodes.Add(_nodeStatus); _nodeCheck.Nodes.Add(_nodeArquivo); } } else { if (_retornoWR.RetornoRetornoLote10300 != null) { Reinf.Irko.retornoLoteEventos _retornoLoteEventos = _retornoWR.RetornoRetornoLote10300.retornoLoteEventos; _contador++; TreeNode _nodeArquivo = new TreeNode("Arquivo " + _contador.ToString()); TreeNode _nodeStatus = new TreeNode(_retornoLoteEventos.status.descRetorno); _retornoLoteEventos.retornoEventos?.ToList().ForEach(_evento => { TreeNode _nodeId = new TreeNode(_evento.id); TreeNode _nodeStatusId = new TreeNode(_evento.Reinf.evtTotal.ideRecRetorno.ideStatus.descRetorno); _evento.Reinf.evtTotal.ideRecRetorno.ideStatus.regOcorrs?.ToList().ForEach(_ocorr => { TreeNode _nodeTpOcorr = new TreeNode(_ocorr.tpOcorr.ToString()); _nodeStatusId.Nodes.Add(_nodeTpOcorr); TreeNode _nodeCodResp = new TreeNode(_ocorr.codResp); _nodeStatusId.Nodes.Add(_nodeCodResp); TreeNode _nodeDscResp = new TreeNode(_ocorr.dscResp); _nodeStatusId.Nodes.Add(_nodeDscResp); }); _nodeId.Nodes.Add(_nodeStatusId); _nodeStatus.Nodes.Add(_nodeId); }); _retornoLoteEventos.status.dadosRegistroOcorrenciaLote?.ToList().ForEach(_evento => { TreeNode _nodeCodigo = new TreeNode(_evento.codigo); TreeNode _nodeDescricao = new TreeNode(_evento.descricao); _nodeCodigo.Nodes.Add(_nodeDescricao); _nodeStatus.Nodes.Add(_nodeCodigo); }); _nodeArquivo.Nodes.Add(_nodeStatus); _nodeCheck.Nodes.Add(_nodeArquivo); } else { Reinf.Irko.retornoLoteEventos1 _retornoLoteEventos = _retornoWR.RetornoRetornoLote10400.retornoLoteEventos; _contador++; TreeNode _nodeArquivo = new TreeNode("Arquivo " + _contador.ToString()); TreeNode _nodeStatus = new TreeNode(_retornoLoteEventos.status.descRetorno); _retornoLoteEventos.retornoEventos?.ToList().ForEach(_evento => { TreeNode _nodeId = new TreeNode(_evento.id); TreeNode _nodeStatusId = new TreeNode(_evento.Reinf.evtTotal.ideRecRetorno.ideStatus.descRetorno); _evento.Reinf.evtTotal.ideRecRetorno.ideStatus.regOcorrs?.ToList().ForEach(_ocorr => { TreeNode _nodeTpOcorr = new TreeNode(_ocorr.tpOcorr.ToString()); _nodeStatusId.Nodes.Add(_nodeTpOcorr); TreeNode _nodeCodResp = new TreeNode(_ocorr.codResp); _nodeStatusId.Nodes.Add(_nodeCodResp); TreeNode _nodeDscResp = new TreeNode(_ocorr.dscResp); _nodeStatusId.Nodes.Add(_nodeDscResp); }); _nodeId.Nodes.Add(_nodeStatusId); _nodeStatus.Nodes.Add(_nodeId); }); _retornoLoteEventos.status.dadosRegistroOcorrenciaLote?.ToList().ForEach(_evento => { TreeNode _nodeCodigo = new TreeNode(_evento.codigo); TreeNode _nodeDescricao = new TreeNode(_evento.descricao); _nodeCodigo.Nodes.Add(_nodeDescricao); _nodeStatus.Nodes.Add(_nodeCodigo); }); _nodeArquivo.Nodes.Add(_nodeStatus); _nodeCheck.Nodes.Add(_nodeArquivo); } /*Reinf.Irko.retornoLoteEventos1 _retornoLoteEventos = _retornoWR.RetornoRetornoLote10400.retornoLoteEventos; * _contador++; * * TreeNode _nodeArquivo = new TreeNode("Arquivo " + _contador.ToString()); * * TreeNode _nodeStatus = new TreeNode(_retornoLoteEventos.status.descRetorno); * * _retornoLoteEventos.retornoEventos.ToList().ForEach(_evento => * { * TreeNode _nodeId = new TreeNode(_evento.id); * * TreeNode _nodeStatusId = new TreeNode(_evento.Reinf.evtTotal.ideRecRetorno.ideStatus.descRetorno); * _evento.Reinf.evtTotal.ideRecRetorno.ideStatus.regOcorrs?.ToList().ForEach(_ocorr => * { * TreeNode _nodeTpOcorr = new TreeNode(_ocorr.tpOcorr.ToString()); * _nodeStatusId.Nodes.Add(_nodeTpOcorr); * TreeNode _nodeCodResp = new TreeNode(_ocorr.codResp); * _nodeStatusId.Nodes.Add(_nodeCodResp); * TreeNode _nodeDscResp = new TreeNode(_ocorr.dscResp); * _nodeStatusId.Nodes.Add(_nodeDscResp); * }); * * _nodeId.Nodes.Add(_nodeStatusId); * _nodeStatus.Nodes.Add(_nodeId); * }); * * _nodeArquivo.Nodes.Add(_nodeStatus); * _nodeCheck.Nodes.Add(_nodeArquivo);*/ } } else { MessageBox.Show(_retornoWR.Mensagem); } } #pragma warning disable CS0168 // A variável foi declarada, mas nunca foi usada catch (Exception ex) #pragma warning restore CS0168 // A variável foi declarada, mas nunca foi usada { MessageBox.Show(ex.Message); return; } } //_retornReinf.Eventos.Add(_retornoEvento); trvEnviado.Nodes.Add(_nodeCheck); } else { MessageBox.Show(_resultadoAssinar.Mensagem); } } }); } catch (Exception _ex) { MessageBox.Show(_ex.Message); } }
private void ExecutarEnviaArquivo() { Custom = false; gpbArquivos.Visible = false; btnSel.Visible = false; btnDes.Visible = false; imgVoltar.Visible = true; imgEnviar.Visible = false; try { List <SCI.Model.Report.DCTF.Reinf.RetornoREINF> _listRetorno = new List <Model.Report.DCTF.Reinf.RetornoREINF>(); pnlArquivo.Controls?.Cast <CheckBox>().Where(_check => _check.Checked)?.ToList().ForEach(_check => { Model.Report.DCTF.RetornoREINF.RetornoEvento _retornoEvento = new Model.Report.DCTF.RetornoREINF.RetornoEvento { Descricao = _check.Text }; int _contador = 0; string _url; if (((SCI.Reinf.Irko.TipoEvento)_check.Tag).Codigo == "R-5011") { _url = "https://www.irko.com.br/csp/prgdcn/reinf/retornoXML.csp?"; _url += "CODEMP=" + GetDesktop().GetEmpresa().Codigo.ToString(); _url += "&GUID=" + Guid; } else { _url = "https://www.irko.com.br/csp/prgdcn/reinf/arquivoXML.csp?"; _url += "CODEMP=" + GetDesktop().GetEmpresa().Codigo.ToString(); _url += "&NOMREG=" + ((SCI.Reinf.Irko.TipoEvento)_check.Tag).Codigo; _url += "&GUID=" + Guid; } XmlDocument _xml = new XmlDocument { PreserveWhitespace = false }; _xml.Load(_url); if (_xml.DocumentElement.Name == "Fim" || _xml.DocumentElement.Name == "Falha") { } else { XmlNode _xmlReinf = _xml.DocumentElement; string _cnpjTransmissao = "07074083000102"; string _cnpjContr = string.Empty; var resultadoCNPJ = wrReinf.RecuperaCNPJCPFCertificado(Guid); if (resultadoCNPJ.Sucesso) { _cnpjContr = resultadoCNPJ.RetornoResultadoRecuperaCNPJCPFCertificado; } if (String.IsNullOrEmpty(_cnpjContr)) { _cnpjContr = _xml.DocumentElement.GetElementsByTagName("ideContri")?.Cast <XmlElement>() .FirstOrDefault()?.GetElementsByTagName("nrInsc")?.Cast <XmlElement>().FirstOrDefault()?.InnerText; } String _tpAmb = _xml.DocumentElement.GetElementsByTagName("tpAmb")?.Cast <XmlElement>()? .FirstOrDefault()?.InnerText; _cnpjTransmissao = _cnpjContr; var _xmlElements = _xml.GetElementsByTagName("loteEventos").Cast <XmlElement>().FirstOrDefault(); List <string> _listaId = _xmlElements?.Cast <XmlNode>().Where(_node => _node.Name == "evento")? .Select(_id => _id.Attributes["id"].Value)?.ToList(); Resultado _resultadoAssinar = new Resultado(); _resultadoAssinar.Sucesso = true; if (((SCI.Reinf.Irko.TipoEvento)_check.Tag).Codigo != "R-5011") { _resultadoAssinar = AssinarXML(ref _xml, _cnpjContr); } if (_resultadoAssinar.Sucesso) { XmlNode _retorno = null; SCI.Base.Resultado <System.Web.Services.Protocols.SoapHttpClientProtocol> _resultado = GetWrAssinado(_cnpjTransmissao, ((SCI.Reinf.Irko.TipoEvento)_check.Tag).Codigo, _tpAmb); if (_resultado.Sucesso) { System.Web.Services.Protocols.SoapHttpClientProtocol _wrAssinado = _resultado.Retorno; try { System.Net.ServicePointManager.ServerCertificateValidationCallback += delegate( object sender, X509Certificate cert, X509Chain chain, SslPolicyErrors sslPolicyErrors) { if (sslPolicyErrors == SslPolicyErrors.None) { return(true); } return(false); }; ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls; if (((SCI.Reinf.Irko.TipoEvento)_check.Tag).Codigo == "R-5011") { XmlNodeList xnList = _xmlReinf.SelectNodes("/ConsultaInformacoesConsolidadas"); byte _tipoInscricaoContribuinte = Convert.ToByte(xnList.Item(0).ChildNodes.Item(0).InnerText); string _numeroInscricaoContribuinte = xnList.Item(0).ChildNodes.Item(1).InnerText; string _numeroProtocoloFechamento = xnList.Item(0).ChildNodes.Item(2).InnerText; if (_tpAmb == "1") { _retorno = ((Reinf.Producao.Retorno.ConsultasReinf)_wrAssinado).ConsultaInformacoesConsolidadas(_tipoInscricaoContribuinte, _numeroInscricaoContribuinte, _numeroProtocoloFechamento); } else { _retorno = ((Reinf.ProducaoRestrita.Retorno.ConsultasReinf)_wrAssinado).ConsultaInformacoesConsolidadas(_tipoInscricaoContribuinte, _numeroInscricaoContribuinte, _numeroProtocoloFechamento); } } else { if (_tpAmb == "1") { _retorno = ((Reinf.Producao.Envio.RecepcaoLoteReinf)_wrAssinado).ReceberLoteEventos(_xmlReinf); } else { _retorno = ((Reinf.ProducaoRestrita.Envio.RecepcaoLoteReinf)_wrAssinado).ReceberLoteEventos(_xmlReinf); } } XmlDocument _docRetorno = new XmlDocument(); _docRetorno.LoadXml(_retorno.OuterXml); XmlElement _retornoElement = _docRetorno.DocumentElement; Reinf.Irko.ResultadoGravarRetornoEvento _retornoWR = GravarEnvio(_retorno, _listaId, _cnpjTransmissao, ((SCI.Reinf.Irko.TipoEvento)_check.Tag).Codigo); if (_retornoWR.Sucesso) { if (((SCI.Reinf.Irko.TipoEvento)_check.Tag).Codigo == "R-5011") { Reinf.Irko.evtTotalContrib _retornoLoteEventos = _retornoWR.RetornoRetornoTotEvt10300.evtTotalContrib; _contador++; _retornoLoteEventos.ideRecRetorno.ideStatus.regOcorrs?.ToList().ForEach(_ocorr => { SCI.Model.Report.DCTF.Reinf.RetornoREINF _retReinf = new Model.Report.DCTF.Reinf.RetornoREINF(); _retReinf.codEvt = ((SCI.Reinf.Irko.TipoEvento)_check.Tag).Codigo; _retReinf.dscEvt = ((SCI.Reinf.Irko.TipoEvento)_check.Tag).Descricao; _retReinf.nomArq = _contador.ToString(); _retReinf.idEVT = _retornoLoteEventos.id; _retReinf.stsEvt = _retornoLoteEventos.ideRecRetorno.ideStatus.descRetorno; _retReinf.tipOco = _ocorr.tpOcorr.ToString(); _retReinf.dscOco = _ocorr.codResp + " - " + _ocorr.dscResp; _listRetorno.Add(_retReinf); }); } else { Reinf.Irko.retornoLoteEventos _retornoLoteEventos = _retornoWR.RetornoRetornoLote10300.retornoLoteEventos; _contador++; _retornoLoteEventos.retornoEventos.ToList().ForEach(_evento => { _evento.Reinf.evtTotal.ideRecRetorno.ideStatus.regOcorrs?.ToList().ForEach(_ocorr => { SCI.Model.Report.DCTF.Reinf.RetornoREINF _retReinf = new Model.Report.DCTF.Reinf.RetornoREINF(); _retReinf.codEvt = ((SCI.Reinf.Irko.TipoEvento)_check.Tag).Codigo; _retReinf.dscEvt = ((SCI.Reinf.Irko.TipoEvento)_check.Tag).Descricao; _retReinf.nomArq = "Arquivo " + _contador.ToString(); _retReinf.idEVT = _retornoLoteEventos.id; _retReinf.stsEvt = _evento.Reinf.evtTotal.ideRecRetorno.ideStatus.descRetorno; _retReinf.tipOco = _ocorr.tpOcorr.ToString(); _retReinf.dscOco = _ocorr.codResp + " - " + _ocorr.dscResp; _listRetorno.Add(_retReinf); }); }); } } else { MessageBox.Show(_retornoWR.Mensagem); } } catch (Exception ex) { MessageBox.Show(ex.Message); return; } } //_retornReinf.Eventos.Add(_retornoEvento); //trvEnviado.Nodes.Add(_nodeCheck); } else { MessageBox.Show(_resultadoAssinar.Mensagem); } } }); rptREINF.LocalReport.DataSources.Clear(); ReportDataSource _source = new ReportDataSource("RetornoArquivoREINF", _listRetorno); rptREINF.LocalReport.DataSources.Add(_source); rptREINF.LocalReport.SetParameters(new ReportParameter[] { new ReportParameter("Agora", DateTime.Now.ToString()) }); rptREINF.RefreshReport(); gpbEnviados.Visible = true; pctLoad.Visible = false; lblLoad.Visible = false; } catch (Exception _ex) { MessageBox.Show(_ex.Message); } }