示例#1
0
        private void Consultar_Load(object sender, EventArgs e)
        {
            ComboBoxTipoConsulta.SelectedIndex = 0;

            if (Global.Contribuinte != null)
            {
                TextBoxCNPJ.Text     = Global.Contribuinte.COD_CNPJ_CPF.AplicarMascara(Mascaras.CNPJ);
                TextBoxCNPJ.Enabled  = false;
                LabelSubCNPJ.Visible = false;

                // Preenche períodos
                var datas      = ServiceEfdReinf.BuscarDatasProcessadasEnviadasR2010(Global.Contribuinte.OID_CONTRIBUINTE);
                var listaDatas = new List <AnoMes>();

                foreach (var data in datas)
                {
                    listaDatas.AddRange(data.Meses);
                }

                ComboBoxPeriodo.DataSource    = listaDatas;
                ComboBoxPeriodo.DisplayMember = "Data";
                //ComboBoxPeriodo.DropDownStyle = ComboBoxStyle.DropDownList;

                // Preenche prestadores
                var prestadores = ServiceEfdReinf.BuscarPrestadores(Global.Contribuinte.OID_CONTRIBUINTE);

                ComboBoxCNPJPrestador.DataSource    = prestadores;
                ComboBoxCNPJPrestador.DropDownStyle = ComboBoxStyle.DropDownList;
                LabelSubPrestador.Visible           = false;
            }

            ComboBoxTipoConsulta_SelectedIndexChanged(this, null);
        }
示例#2
0
 private void ButtonEntrar_Click(object sender, EventArgs e)
 {
     try
     {
         Global.Token = ServiceEfdReinf.Login(TextBoxEmail.Text, TextBoxSenha.Text).AccessToken;
         HomeForm.Logar();
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
 }
示例#3
0
        private void Contribuinte_Load(object sender, EventArgs e)
        {
            Global.Usuario    = ServiceEfdReinf.BuscarUsuario();
            LabelUsuario.Text = Global.Usuario.NOM_USUARIO;

            var contribuintes = ServiceEfdReinf.BuscarContribuintesAtivos();

            ComboBoxContribuinte.DataSource    = contribuintes;
            ComboBoxContribuinte.DisplayMember = "NOM_RAZAO_SOCIAL";
            ComboBoxContribuinte.SelectedIndex = 0;
            ComboBoxContribuinte.Enabled       = false;
            Global.Contribuinte = (ContribuinteEntidade)ComboBoxContribuinte.SelectedItem;
        }
示例#4
0
        private void ProcessarR2098(XmlNode xml)
        {
            try
            {
                var nav   = xml.CreateNavigator();
                var nsmgr = new XmlNamespaceManager(nav.NameTable);
                nsmgr.AddNamespace("a", "http://www.reinf.esocial.gov.br/schemas/retornoRecibosChaveEvento/v1_05_01");

                var status = xml.SelectSingleNode("//a:Reinf/a:ideStatus/a:cdRetorno", nsmgr);
                if (status.InnerText == "0")
                {
                    var descRetorno = xml.SelectSingleNode("//a:Reinf/a:ideStatus/a:descRetorno", nsmgr);
                    MessageBox.Show(descRetorno.InnerText);
                    return;
                }

                var eventos = xml.SelectNodes("//a:Reinf/a:retornoEventos/a:evento", nsmgr);

                var ultimoY = 0;

                for (var i = 0; i < eventos.Count; i++)
                {
                    var id            = eventos[i].Attributes["id"].Value;
                    var oidR2010      = Convert.ToDecimal(id.Substring(31));
                    var dtRecebimento = eventos[i]["dtHoraRecebimento"].InnerText;
                    var numRecibo     = eventos[i]["nrRecibo"].InnerText;

                    var registro = new R2010(dtRecebimento, numRecibo)
                    {
                        Location = new System.Drawing.Point(0, ultimoY)
                    };

                    panel1.Controls.Add(registro);
                    ultimoY = registro.Height + ultimoY;

                    if (CheckBoxAlinharRecibos.Checked)
                    {
                        ServiceEfdReinf.UpdateRecibo(DMN_TIPO_REGISTRO.R2098, oidR2010, numRecibo);
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
示例#5
0
        private void ButtonTransmitir_Click(object sender, EventArgs e)
        {
            try
            {
                ButtonProcurar.Enabled   = false;
                ButtonTransmitir.Enabled = false;
                TextBoxLog.Clear();

                ProgressBarSecundaria.Value = 0;
                ProgressBarPrimaria.Value   = 0;

                dispatcher.DoEvents();

                // Instancia a classe que irá assinar o arquivo
                var assinador = new AssinadorXML(dispatcher, ProgressBarSecundaria);

                var dirZipDescompactado = Guid.NewGuid().ToString();

                // Descompacta o arquivo .intech
                if (!Directory.Exists(dirZipDescompactado))
                {
                    Directory.CreateDirectory(dirZipDescompactado);
                }

                Zip.Descompacta(TextBoxArquivo.Text, dirZipDescompactado);

                var arquivos     = Directory.GetFiles(dirZipDescompactado);
                var contadorLote = 0;
                var totalLotes   = arquivos.Length;

                ProgressBarPrimaria.Maximum = arquivos.Length;

                // Processa cada xml contido no arquivo .intech
                foreach (var arquivo in arquivos)
                {
                    contadorLote++;

                    LabelProgressBarPrimaria.Text = $"Processando lote {contadorLote} de {totalLotes}...";

                    // Assina o xml do lote utilizando o certificado digital selecionado
                    LabelProgressBarSecundaria.Text = "Assinando lote...";
                    ProgressBarSecundaria.Value     = 0;
                    dispatcher.DoEvents();
                    var xml = assinador.AssinarEventosDoArquivo(Global.Certificado, arquivo);

                    if (xml == null)
                    {
                        return;
                    }

                    var tipoEvento = assinador.BuscarElementoAssinar(xml);

                    var ambiente = BuscarAmbiente(xml, tipoEvento);

                    if (ambiente == "1")
                    {
                        webServices = new WebServicesRF(true);
                    }
                    else
                    {
                        webServices = new WebServicesRF(false);
                    }

                    LabelProgressBarSecundaria.Text = "Enviando lote...";
                    ProgressBarSecundaria.Value     = 0;
                    ProgressBarSecundaria.Maximum   = 1;
                    dispatcher.DoEvents();

                    var retorno = webServices.ReceberLoteEvento(XElement.Parse(xml.InnerXml)).ToXmlNode();

                    ProgressBarSecundaria.Value = 1;
                    dispatcher.DoEvents();

                    //if (tipoEvento.Tag == "evtServTom")
                    //{
                    var sucesso = true;
                    var eventos = BuscaEventosRetorno(retorno);

                    LabelProgressBarSecundaria.Text = "Atualizando status dos registros...";
                    ProgressBarSecundaria.Value     = 0;
                    ProgressBarSecundaria.Maximum   = eventos.Count;
                    dispatcher.DoEvents();

                    if (eventos.Count == 0)
                    {
                        var resultado = BuscaResultadoEventoUnico(retorno);

                        if (resultado == "ERRO")
                        {
                            var mensagem = BuscaMensagemEventoUnico(retorno);

                            // Atualiza a ocorrência no banco utilizando a API
                            //ServiceEfdReinf.UpdateRecibo(oidArquivoUpload, numRecibo);
                            AdicionarLog("Erro: " + mensagem);
                            sucesso = false;
                            dispatcher.DoEvents();
                        }
                    }

                    for (int i = 0; i < eventos.Count; i++)
                    {
                        var resultado = BuscaResultadoEvento(eventos[i]);

                        if (resultado == "ERRO")
                        {
                            // Mostra um dialogo para salvar o retorno
                            //SalvarArquivoRetorno(eventos[i]);

                            var mensagem = BuscaMensagemEvento(eventos[i]);

                            try
                            {
                                // Atualiza a ocorrência no banco utilizando a API
                                //ServiceEfdReinf.UpdateRecibo(oidArquivoUpload, numRecibo);
                                AdicionarLog("Erro ao atualizar ocorrência: " + mensagem);
                                sucesso = false;
                                dispatcher.DoEvents();
                            }
                            catch (Exception ex)
                            {
                                AdicionarLog("Erro ao atualizar ocorrência: " + mensagem);
                            }
                        }
                        else
                        {
                            if (tipoEvento.Tipo != DMN_TIPO_REGISTRO.R1000)
                            {
                                try
                                {
                                    var idEvento = BuscaIDEvento(eventos[i]);
                                    var oid      = Convert.ToDecimal(idEvento.Substring(31));

                                    // Atualiza o status e o nº do recibo no banco utilizando a API
                                    var numRecibo = BuscaRecibo(eventos[i]);
                                    ServiceEfdReinf.UpdateRecibo(tipoEvento.Tipo, oid, numRecibo);
                                }
                                catch (Exception ex)
                                {
                                    // Mostra um dialogo para salvar o retorno
                                    //SalvarArquivoRetorno(eventos[i]);

                                    AdicionarLog("Erro ao atualizar movimento: " + ex.Message);
                                }
                            }
                        }

                        ProgressBarSecundaria.Increment(1);
                        dispatcher.DoEvents();
                    }

                    LabelProgressBarPrimaria.Text = string.Empty;

                    if (sucesso)
                    {
                        LabelProgressBarSecundaria.Text = "Arquivo enviado com sucesso!";
                    }
                    else
                    {
                        LabelProgressBarSecundaria.Text = "Arquivo enviado com erros.";
                    }
                    //}
                    //else
                    //{
                    //    var resultado = BuscaResultado(retorno);

                    //    if (resultado == "ERRO")
                    //    {
                    //        // Mostra um dialogo para salvar o retorno
                    //        //SalvarArquivoRetorno(retorno);

                    //        AdicionarLog("Erro: " + BuscaMensagem(retorno));
                    //    }
                    //    else
                    //    {
                    //        LabelProgressBarPrimaria.Text = string.Empty;
                    //        LabelProgressBarSecundaria.Text = "Arquivo enviado com sucesso!";
                    //        var numRecibo = BuscaRecibo(retorno);
                    //        MessageBox.Show("Arquivo enviado com sucesso!\nNúmero do recibo: " + numRecibo);

                    //        // Atualiza o status e o nº do recibo no banco
                    //        //ServiceEfdReinf.UpdateRecibo(oidArquivoUpload, numRecibo);
                    //    }
                    //}

                    ProgressBarPrimaria.Increment(1);
                    dispatcher.DoEvents();
                }

                Directory.Delete(dirZipDescompactado, true);
            }
            catch (Exception ex)
            {
                AdicionarLog("Erro: " + ex.Message);
                VerificarInnerException(ex);
            }
            finally
            {
                ButtonProcurar.Enabled   = true;
                ButtonTransmitir.Enabled = true;

                if (salvar)
                {
                    TextWriter writer = new StreamWriter(nomeArquivoLog);
                    writer.Write(logEventos);
                    writer.Flush();
                    writer.Close();
                }
            }
        }