private void toolStripButton3_Click(object sender, EventArgs e) { string sArquivoXML = string.Empty; try { if (txtXml.Text == "") { throw new Exception("Arquivo XML não foi selecionado !"); } if (cbxEmpresas.SelectedValue.ToString() == "") { throw new Exception("Empresa para Importçã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 = (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, fbConexao); } catch (Exception ex) { KryptonMessageBox.Show(null, "Ocorreu uma excessão não esperada, Verifique a Messagem abaixo e Informe o Suporte." + Environment.NewLine + Environment.NewLine + ex.Message, "E R R 0", MessageBoxButtons.OK, MessageBoxIcon.Error); } } 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.Error); } } catch (Exception ex) { KryptonMessageBox.Show(null, string.Format("Não foi possivel importar o XML. Erro {0}, Lendo o Arquivo {1}", ex.Message, sArquivoXML), "Erro", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private List<strucArquivo> MontaStrucArquivos(string[] Arquivos) { List<strucArquivo> objArquivos = new List<strucArquivo>(); List<strucXmlValidacao> objLisXmlNaoValidado = new List<strucXmlValidacao>(); string sNomearq = string.Empty; try { string sDoc = ""; foreach (string sArquivo in Arquivos) { strucArquivo objArquivo = new strucArquivo(); objArquivo.Arquivo = sArquivo.ToString(); sNomearq = sArquivo; belImportaXmlNFe xmlEscritor = new belImportaXmlNFe(sNomearq); belEscrituracao objbelEscrituracao = new belEscrituracao(fbConexao); string sCD_EMPRESA = cbxEmpresas.SelectedValue.ToString(); string sCD_CLIFOR = ""; string sTipo = ""; bool bValida = true; try { belInfNFe objInfNFe = xmlEscritor.MontaInfNFe(); if (objInfNFe != null) { string sTipoLanc = TipoLancamento(objInfNFe); bool bSaida = true; // NotaSaida(); if (sTipoLanc == "E") { bSaida = false; } sDoc = ""; if (!bSaida) { if (objInfNFe.BelEmit.Cnpj != null) { sDoc = objInfNFe.BelEmit.Cnpj.ToString(); } else { sDoc = objInfNFe.BelEmit.Cpf.ToString(); } } else { if (objInfNFe.BelDest.Cnpj != null) { sDoc = objInfNFe.BelDest.Cnpj.ToString(); } else { sDoc = objInfNFe.BelDest.Cpf.ToString(); } } sTipo = (objInfNFe.BelDest.Cnpj != null ? "CNPJ" : "CPF"); sCD_CLIFOR = objbelEscrituracao.BuscaCodigoClifor(objbelEscrituracao.FormataString(sDoc, sTipo), objInfNFe, bSaida); if (sCD_CLIFOR != "") { // if (bSaida) { bValida = objbelEscrituracao.ValidaNotaJaEscriturada(sCD_EMPRESA, objInfNFe.BelIde.Nnf, objInfNFe.BelIde.Serie, sCD_CLIFOR, objInfNFe.BelIde.Mod, bSaida ); } } if (bValida) { objArquivo.Nota = objInfNFe.BelIde.Nnf; objArquivo.Emitente = objInfNFe.BelEmit.Xnome; objArquivo.Destinatario = objInfNFe.BelDest.Xnome; objArquivo.Emissao = objInfNFe.BelIde.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ÁLIDO!! "; 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;// "Não foi encontrado a Tag 'protNFe'. XML NÃO É VÁLIDO!! "; objLisXmlNaoValidado.Add(obj); } dgvXmlNaoValidado.DataSource = objLisXmlNaoValidado; dgvXmlNaoValidado.Columns[0].Width = 500; dgvXmlNaoValidado.Columns[1].Width = 200; if (objLisXmlNaoValidado.Count > 0) { lblXmlNaoValidado.Text = "| " + objLisXmlNaoValidado.Count.ToString() + " registros não válidos para Escrituração"; } else { lblXmlNaoValidado.Text = ""; } return objArquivos; }