Exemplo n.º 1
0
        private void cbEmpresa_SelectedIndexChanged(object sender, EventArgs e)
        {
            try
            {
                this.comboUf.Enabled      =
                    this.cbVersao.Enabled = this.cbEmpresa.SelectedValue != null;

                this.buttonPesquisa.Enabled = false;

                if (this.cbEmpresa.SelectedValue != null)
                {
                    var list = (this.cbEmpresa.DataSource as System.Collections.ArrayList)[this.cbEmpresa.SelectedIndex] as NFe.Components.ComboElem;
                    this.Emp = Empresas.FindConfEmpresaIndex(list.Valor, NFe.Components.EnumHelper.StringToEnum <TipoAplicativo>(list.Servico));
                    if (this.Emp >= 0)
                    {
                        if (Empresas.Configuracoes[this.Emp].Servico == TipoAplicativo.Nfse)
                        {
                            throw new Exception("NFS-e não dispõe do serviço de consulta a cadastro de contribuinte.");
                        }

                        uninfeDummy.xmlParams.WriteValue(this.GetType().Name, "last_empresa", this.cbEmpresa.SelectedIndex);
                        uninfeDummy.xmlParams.Save();

                        this.comboUf.SelectedValue = Functions.CodigoParaUF(Empresas.Configuracoes[this.Emp].UnidadeFederativaCodigo).Trim();

                        this.buttonPesquisa.Enabled = true;
                    }
                }
            }
            catch (Exception ex)
            {
                MetroFramework.MetroMessageBox.Show(uninfeDummy.mainForm, ex.Message, "", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Exemplo n.º 2
0
        private void cbEmpresa_SelectedIndexChanged(object sender, EventArgs e)
        {
            this.Emp = -1;
            this.cbServico.SelectedIndexChanged -= cbServico_SelectedIndexChanged;
            this.cbServico.Enabled = false;

            try
            {
                if (this.cbEmpresa.SelectedValue != null)
                {
                    var list = (this.cbEmpresa.DataSource as System.Collections.ArrayList)[this.cbEmpresa.SelectedIndex] as NFe.Components.ComboElem;
                    this.Emp = Empresas.FindConfEmpresaIndex(list.Valor, NFe.Components.EnumHelper.StringToEnum <TipoAplicativo>(list.Servico));
                    if (this.Emp >= 0)
                    {
                        uninfeDummy.xmlParams.WriteValue(this.GetType().Name, "last_empresa", this.cbEmpresa.SelectedIndex);
                        uninfeDummy.xmlParams.Save();

                        this.comboUf.SelectedValue = Functions.CodigoParaUF(Empresas.Configuracoes[this.Emp].UnidadeFederativaCodigo).Trim();

                        //Posicionar o elemento da combo Ambiente
                        this.cbAmbiente.SelectedValue = Empresas.Configuracoes[this.Emp].AmbienteCodigo;

                        //Exibir CNPJ da empresa
                        txtCNPJ.Text = uninfeDummy.FmtCnpjCpf(Empresas.Configuracoes[Emp].CNPJ, true);

                        //Posicionar o elemento da combo tipo de emissão
                        this.cbEmissao.SelectedValue = Empresas.Configuracoes[this.Emp].tpEmis;

                        this.ChangeVersao(Empresas.Configuracoes[this.Emp].Servico);

                        //Posicionar o elemento da combo tipo de servico
                        if (Empresas.Configuracoes[this.Emp].Servico != TipoAplicativo.Todos)
                        {
                            this.cbServico.SelectedValue = (int)Empresas.Configuracoes[this.Emp].Servico;
                        }
                        else
                        {
                            this.cbServico.SelectedValue = (int)TipoAplicativo.Nfe;
                            this.cbServico.Enabled       = true;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                this.cbServico.Enabled = false;
                MetroFramework.MetroMessageBox.Show(uninfeDummy.mainForm, ex.Message, "");
            }
            finally
            {
                this.cbServico.SelectedIndexChanged  += cbServico_SelectedIndexChanged;
                this.buttonPesquisa.Enabled           =
                    this.cbAmbiente.Enabled           =
                        this.cbEmissao.Enabled        =
                            this.comboUf.Enabled      =
                                this.cbVersao.Enabled = this.Emp >= 0;
            }
        }
Exemplo n.º 3
0
        private void ValidarCertificadoA3(bool salvando)
        {
            if (String.IsNullOrEmpty(empresa.CertificadoPIN))
            {
                throw new Exception("Informe o PIN do certificado");
            }

            Wait.Show("Validando PIN...");
            try
            {
                if (Empresas.FindConfEmpresaIndex(empresa.CNPJ, empresa.Servico) == -1)
                {
                    Empresas.Configuracoes.Add(empresa);
                }

                CertificadoProviders certificadoProviders = new CertificadoProviders(empresa.X509Certificado,
                                                                                     empresa.PastaXmlEnvio,
                                                                                     Empresas.FindConfEmpresaIndex(empresa.CNPJ, empresa.Servico),
                                                                                     empresa.CertificadoPIN);
                CertProviders xCertProviders = new CertProviders();

                if (certificadoProviders.TestarProvider(xCertProviders))
                {
                    Wait.Close();
                    if (!salvando)
                    {
                        MetroFramework.MetroMessageBox.Show(uninfeDummy.mainForm,
                                                            "Configuração do PIN validada, XML assinado com sucesso.",
                                                            provError,
                                                            MessageBoxButtons.OK);
                    }
                }

                else
                {
                    Wait.Close();
                    MetroFramework.MetroMessageBox.Show(uninfeDummy.mainForm,
                                                        "PIN inválido, não foi possível assinar um XML com esta chave.",
                                                        provError,
                                                        MessageBoxButtons.OK);

                    if (salvando)
                    {
                        throw new Exception("Não foi possível salvar a configuração.");
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                Wait.Close();
            }
        }
Exemplo n.º 4
0
        private void cbEmpresas_SelectedIndexChanged(object sender, EventArgs e)
        {
            this.Emp = -1;
            try
            {
                if (this.cbEmpresas.SelectedValue != null)
                {
                    var list = (this.cbEmpresas.DataSource as System.Collections.ArrayList)[this.cbEmpresas.SelectedIndex] as NFe.Components.ComboElem;
                    this.Emp = Empresas.FindConfEmpresaIndex(list.Valor, NFe.Components.EnumHelper.StringToEnum <TipoAplicativo>(list.Servico));

                    uninfeDummy.xmlParams.WriteValue(this.GetType().Name, "last_empresa", this.cbEmpresas.SelectedIndex);
                    uninfeDummy.xmlParams.Save();
                }
            }
            catch (Exception ex)
            {
                MetroFramework.MetroMessageBox.Show(uninfeDummy.mainForm, ex.Message, "");
            }
            finally
            {
                this.edtFilename.Enabled     =
                    this.btn_Validar.Enabled = this.Emp >= 0;
            }
        }
Exemplo n.º 5
0
        private void buttonPesquisa_Click(object sender, EventArgs e)
        {
            this.Refresh();
            txtMensagem.Clear();
            metroGridSituacao.Rows.Clear();

            bool todasEmpresas = cbEmpresa.SelectedValue.Equals("Todos");

            try
            {
                TipoEmissao    tpEmis  = (TipoEmissao)this.cbEmissao.SelectedValue;
                int            amb     = (int)cbAmbiente.SelectedValue;
                string         versao  = this.cbVersao.SelectedItem.ToString();
                TipoAplicativo servico = TipoAplicativo.Nulo;
                int            cUF     = 0;

                if (!todasEmpresas)
                {
                    servico = (TipoAplicativo)cbServico.SelectedValue;
                    cUF     = Functions.UFParaCodigo(this.comboUf.SelectedValue.ToString());

                    switch (servico)
                    {
                    case TipoAplicativo.Cte:
                        if (tpEmis == TipoEmissao.teSVCAN)    // this.cbEmissao.SelectedIndex == 4)
                        {
                            throw new Exception("CT-e não dispõe do tipo de contingência SVCAN.");
                        }
                        break;

                    case TipoAplicativo.Nfe:
                        if (tpEmis == TipoEmissao.teSVCSP)    // this.cbEmissao.SelectedIndex == 3)
                        {
                            throw new Exception("NF-e não dispõe do tipo de contingência SVCSP.");
                        }
                        break;

                    case TipoAplicativo.MDFe:
                        if (tpEmis != TipoEmissao.teNormal)
                        {
                            throw new Exception("MDF-e só dispõe do tipo de emissão Normal.");
                        }
                        break;

                    case TipoAplicativo.NFCe:
                        if (tpEmis != TipoEmissao.teNormal)
                        {
                            throw new Exception("NFC-e só dispõe do tipo de emissão Normal.");
                        }
                        break;
                    }
                }

                Formularios.Wait.Show("Consulta a situação do serviço...");

                List <ConsultaRealizada> consultasRealizadas = new List <ConsultaRealizada>();

                if (todasEmpresas)
                {
                    tpEmis = TipoEmissao.teNormal;

                    for (int i = 0; i < Empresas.Configuracoes.Count; i++)
                    {
                        int emp = Empresas.FindConfEmpresaIndex(Empresas.Configuracoes[i].CNPJ, Empresas.Configuracoes[i].Servico);
                        cUF = Empresas.Configuracoes[emp].UnidadeFederativaCodigo;

                        switch (Empresas.Configuracoes[emp].Servico)
                        {
                        case TipoAplicativo.Todos:
                            GerarConsulta(emp, TipoAplicativo.Nfe, (int)tpEmis, cUF, amb, "4.00", consultasRealizadas);
                            GerarConsulta(emp, TipoAplicativo.NFCe, (int)tpEmis, cUF, amb, "4.00", consultasRealizadas);
                            GerarConsulta(emp, TipoAplicativo.MDFe, (int)tpEmis, cUF, amb, "3.00", consultasRealizadas);
                            GerarConsulta(emp, TipoAplicativo.Cte, (int)tpEmis, cUF, amb, "3.00", consultasRealizadas);
                            break;

                        case TipoAplicativo.Nfe:
                            GerarConsulta(emp, TipoAplicativo.Nfe, (int)tpEmis, cUF, amb, "4.00", consultasRealizadas);
                            break;

                        case TipoAplicativo.Cte:
                            GerarConsulta(emp, TipoAplicativo.Cte, (int)tpEmis, cUF, amb, "3.00", consultasRealizadas);
                            break;

                        case TipoAplicativo.MDFe:
                            GerarConsulta(emp, TipoAplicativo.MDFe, (int)tpEmis, cUF, amb, "3.00", consultasRealizadas);
                            break;

                        case TipoAplicativo.NFCe:
                            GerarConsulta(emp, TipoAplicativo.NFCe, (int)tpEmis, cUF, amb, "4.00", consultasRealizadas);
                            break;
                        }
                    }
                }
                else
                {
                    GerarConsulta(Emp, servico, (int)tpEmis, cUF, amb, versao, consultasRealizadas);
                }

                //Demonstrar o status do serviço
                for (int i = 0; i < consultasRealizadas.Count; i++)
                {
                    string nomeEmpresa = consultasRealizadas[i].Empresa.Nome;
                    string tipoServico = consultasRealizadas[i].Servico.ToString();
                    string uf          = Functions.CodigoParaUF(consultasRealizadas[i].Empresa.UnidadeFederativaCodigo);
                    string result      = VerStatusServico(consultasRealizadas[i].ArquivoRetorno, consultasRealizadas[i].Emp);

                    metroGridSituacao.Rows.Add(new object[] { nomeEmpresa, uf, tipoServico, result });
                }
            }
            catch (Exception ex)
            {
                Formularios.Wait.Close();
                txtMensagem.Text = ex.Message;
            }
        }
Exemplo n.º 6
0
        private void cbEmpresa_SelectedIndexChanged(object sender, EventArgs e)
        {
            try
            {
                this.cbAmbiente.Enabled               =
                    this.cbEmissao.Enabled            =
                        this.comboUf.Enabled          =
                            this.cbServico.Enabled    =
                                this.cbVersao.Enabled = this.cbEmpresa.SelectedValue != null;

                this.buttonPesquisa.Enabled = false;

                if (this.cbEmpresa.SelectedValue != null)
                {
                    var list = (this.cbEmpresa.DataSource as System.Collections.ArrayList)[this.cbEmpresa.SelectedIndex] as NFe.Components.ComboElem;

                    this.Emp = Empresas.FindConfEmpresaIndex(list.Valor, NFe.Components.EnumHelper.StringToEnum <TipoAplicativo>(list.Servico));
                    if (this.Emp >= 0)
                    {
                        uninfeDummy.xmlParams.WriteValue(this.GetType().Name, "last_empresa", this.cbEmpresa.SelectedIndex);
                        uninfeDummy.xmlParams.Save();

                        /*
                         * if (Empresas.Configuracoes[this.Emp].Servico == TipoAplicativo.Nfse)
                         * {
                         *  throw new Exception("NFS-e não dispõe do serviço de consulta a status.");
                         * }
                         */
                        this.comboUf.SelectedValue = Functions.CodigoParaUF(Empresas.Configuracoes[this.Emp].UnidadeFederativaCodigo).Trim();

                        //Posicionar o elemento da combo Ambiente
                        this.cbAmbiente.SelectedValue = Empresas.Configuracoes[this.Emp].AmbienteCodigo;

                        //Posicionar o elemento da combo tipo de emissão
                        this.cbEmissao.SelectedValue = Empresas.Configuracoes[this.Emp].tpEmis;

                        //Posicionar o elemento da combo tipo de servico
                        this.cbServico.SelectedValue = (int)Empresas.Configuracoes[this.Emp].Servico;

                        if (Empresas.Configuracoes[this.Emp].Servico == TipoAplicativo.Todos)
                        {
                            this.cbVersao.SelectedValue  = "3.10";
                            this.cbServico.SelectedIndex = 0;
                            this.cbServico.Enabled       = true;
                        }
                        else
                        {
                            this.cbServico.Enabled = false;
                            if (Empresas.Configuracoes[this.Emp].Servico != TipoAplicativo.Nfe)
                            {
                                this.cbVersao.SelectedValue = "2.00";
                            }
                        }
                        this.buttonPesquisa.Enabled = true;
                    }
                }
            }
            catch (Exception ex)
            {
                MetroFramework.MetroMessageBox.Show(uninfeDummy.mainForm, ex.Message, "");
            }
        }