示例#1
0
        private List <strucArquivo> MontaStrucArquivos(string[] Arquivos)
        {
            List <strucArquivo>      objArquivos          = new List <strucArquivo>();
            List <strucXmlValidacao> objLisXmlNaoValidado = new List <strucXmlValidacao>();

            string sNomearq = string.Empty;

            try
            {
                foreach (string sArquivo in Arquivos)
                {
                    strucArquivo objArquivo = new strucArquivo();
                    objArquivo.Arquivo = sArquivo.ToString();
                    sNomearq           = sArquivo;
                    belImportaXmlNFe xmlEscritor = new belImportaXmlNFe(sNomearq);

                    try
                    {
                        belInfNFe objInfNFe = xmlEscritor.MontaInfNFe();
                        if (objInfNFe != null)
                        {
                            objArquivo.Nota         = objInfNFe.ide.Nnf;
                            objArquivo.Emitente     = objInfNFe.emit.Xnome;
                            objArquivo.Destinatario = objInfNFe.dest.Xnome;
                            objArquivo.Emissao      = objInfNFe.ide.Demi;
                            objArquivo.NFE          = objInfNFe.id;

                            objArquivos.Add(objArquivo);
                        }
                        else
                        {
                            strucXmlValidacao obj = new strucXmlValidacao();
                            obj.Xml    = sNomearq;
                            obj.Motivo = "Não foi encontrado a Tag 'protNFe'.  Xml não é válid0";
                            objLisXmlNaoValidado.Add(obj);
                        }
                    }
                    catch (Exception ex)
                    {
                        strucXmlValidacao obj = new strucXmlValidacao();
                        obj.Xml    = sNomearq;
                        obj.Motivo = ex.Message;
                        objLisXmlNaoValidado.Add(obj);
                    }
                }
            }
            catch (Exception ex)
            {
                //throw new Exception(string.Format("Não foi possivel ler o arquivo {0}, devido ao Erro.: {1}",
                //                                  sNomearq,
                //                                  ex.Message));
                strucXmlValidacao obj = new strucXmlValidacao();
                obj.Xml    = sNomearq;
                obj.Motivo = ex.Message;
                objLisXmlNaoValidado.Add(obj);
            }
            dgvXmlNaoValidado.DataSource = objLisXmlNaoValidado;
            if (objLisXmlNaoValidado.Count > 0)
            {
                lblXmlNaoValidado.Text = objLisXmlNaoValidado.Count.ToString() + " arquivo(s) não válido(s)";
            }
            else
            {
                lblXmlNaoValidado.Text = "";
            }

            return(objArquivos);
        }
示例#2
0
        private void btnImporta_Click(object sender, EventArgs e)
        {
            string sArquivoXML = string.Empty;

            try
            {
                if (txtXml.Text == "")
                {
                    throw new Exception("Pasta dos Arquivos Xml não foi selecionada");
                }

                if (cbxEmpresas.SelectedValue.ToString() == "")
                {
                    throw new Exception("Empresa para Importação não foi selecionada");
                }

                List <string> lsXmls = new List <string>();

                for (int i = 0; i < dgvXmls.RowCount; i++)
                {
                    if (((dgvXmls["Selecionar", i].Value != null) && (dgvXmls["Selecionar", i].Value.ToString().Equals("True"))))
                    {
                        lsXmls.Add((string)dgvXmls["Arquivo", i].Value);
                    }
                }

                if (lsXmls.Count > 0)
                {
                    pgbNF.Step    = 1;
                    pgbNF.Minimum = 0;
                    pgbNF.Maximum = lsXmls.Count;
                    pgbNF.MarqueeAnimationSpeed = lsXmls.Count;
                    pgbNF.Value = 0;

                    for (int i = 0; i < lsXmls.Count; i++)
                    {
                        try
                        {
                            lblStatusScrituracao.Text = "Escriturando " + (i + 1).ToString() + " de " + lsXmls.Count.ToString();
                            pgbNF.PerformStep();
                            statusStrip1.Refresh();
                            this.Refresh();
                            sArquivoXML = lsXmls[i];
                            belImportaXmlNFe xmlEscritor = new belImportaXmlNFe(lsXmls[i]);
                            belInfNFe        objInfNFe   = xmlEscritor.MontaInfNFe();
                            objInfNFe.Empresa = cbxEmpresas.SelectedValue.ToString();
                            belEscrituracao objEscrituracao = new belEscrituracao(objInfNFe);
                        }
                        catch (Exception ex)
                        {
                            new HLPexception(ex);
                        }
                    }
                    KryptonMessageBox.Show(null,
                                           string.Format("Importação efetuada com Sucesso!"),
                                           "Importação de XML",
                                           MessageBoxButtons.OK,
                                           MessageBoxIcon.Information);
                    pgbNF.Value = 0;
                    //toolStripButton2_Click(sender, e);
                    lblarquivosEscriturados.Text = "Escriturado " + lsXmls.Count.ToString() + " registro(s) de " + lsXmls.Count.ToString();
                }
                else
                {
                    KryptonMessageBox.Show(null,
                                           string.Format("Nenhum Xml Foi selecionado!"),
                                           "Importação de XML",
                                           MessageBoxButtons.OK,
                                           MessageBoxIcon.Information);
                }
            }
            catch (Exception ex)
            {
                if (!String.IsNullOrEmpty(sArquivoXML))
                {
                    KryptonMessageBox.Show(null,
                                           string.Format("Não foi possível importar o Xml. Erro {0}, Lendo o Arquivo {1}",
                                                         ex.Message,
                                                         sArquivoXML),
                                           Mensagens.MSG_Aviso,
                                           MessageBoxButtons.OK,
                                           MessageBoxIcon.Information);
                }
                else
                {
                    new HLPexception(ex);
                }
            }
        }