public void PopulaConhecimentos(belPopulaObjetos objbelObjetos) { this.objbelObjetos = objbelObjetos; try { if (File.Exists(objbelObjetos.sPath)) { File.Delete(objbelObjetos.sPath); } foreach (string sCte in objbelObjetos.objListaNumeroConhecimentos) { string sCTe = "CTe" + GeraChave(sCte); belinfCte objbelinfCte = new belinfCte(); belDadosIde objIde = new belDadosIde(); belDadosEmit objEmit = new belDadosEmit(); belDadosRem objRem = new belDadosRem(); belDadosDest objDest = new belDadosDest(); belDadosNf objNf = new belDadosNf(); belDadosExped objExped = new belDadosExped(); belDadosReceb objReceb = new belDadosReceb(); belDadosVPrest objVPrest = new belDadosVPrest(); belDadosImp objImp = new belDadosImp(); belDadosinfCarga objInfCarga = new belDadosinfCarga(); belDadosinfQ objInfQ = new belDadosinfQ(); belDadosrodo objRodo = new belDadosrodo(); objbelinfCte.compl = new belcompl(sCte); objIde.PopulaIde(sCte, sCTe[sCTe.Length - 1].ToString(), objbelinfCte, sCTe); objEmit.PopulaEmit(objbelinfCte); objRem.PopulaRem(objbelinfCte, sCte); objDest.PopulaDest(objbelinfCte, sCte); objNf.PopulaNf(objbelinfCte, sCte); objExped.PopulaExped(objbelinfCte, sCte); objReceb.PopulaReceb(objbelinfCte, sCte); objVPrest.PopulaVPrest(objbelinfCte, sCte); objImp.PopulaImp(objbelinfCte, sCte); objInfCarga.PopulainfCarga(objbelinfCte, sCte); objInfQ.PopulainfQ(objbelinfCte, sCte); objRodo.PopulaRodo(objbelinfCte, sCte); objRodo.PopulaVeiculo(objbelinfCte, sCte); objRodo.PopulaMotorista(objbelinfCte, sCte); objbelObjetos.objListaConhecimentos.Add(objbelinfCte); } } catch (Exception ex) { throw ex; } }
public frmVisualizaCte(belPopulaObjetos objObjetos) { InitializeComponent(); listErros.ListBox.MouseDoubleClick += new MouseEventHandler(listErros_MouseDoubleClick); this.objObjetos = objObjetos; CriaObjAlter(); bsNotas.DataSource = this.objObjetosAlter.objListaConhecimentos; ValidaConhecimentos(); PopulaForm(); VerificaCampos(); }
public void GravarRecibo(belPopulaObjetos objObjetos, string sRecibo) { try { for (int i = 0; i < objObjetos.objListaConhecimentos.Count; i++) { SalvarRecibo(sRecibo, objObjetos.objListaConhecimentos[i].ide.nCT); } } catch (Exception ex) { throw new Exception("Erro ao Gravar o Recibo no Banco de Dados."); } }
public void GravarChave(belPopulaObjetos objObjetos) { try { for (int i = 0; i < objObjetos.objListaConhecimentos.Count; i++) { string sChave = objObjetos.objListaConhecimentos[i].id.Replace("CTe", ""); SalvaChave(sChave, objObjetos.objListaConhecimentos[i].ide.nCT); } } catch (Exception ex) { throw new Exception("Erro ao Gravar a Chave no Banco de Dados."); } }
private void btnContingencia_Click(object sender, EventArgs e) { try { #region Verifica se Item Selecionado já foi enviado for (int i = 0; i < dgvArquivos.RowCount; i++) { if (dgvArquivos["cl_assina", i].Value != null) { if (dgvArquivos["cl_assina", i].Value.ToString().Equals("True")) { if (objGerais.VerificaCampoReciboPreenchido(dgvArquivos["nr_lanc", i].Value.ToString()) != "") { throw new Exception("O Conhecimento de Sequência " + dgvArquivos["nr_lanc", i].Value.ToString() + " Já tem um recibo Salvo no Banco de Dados, tente Buscar Retorno."); } else if (Convert.ToBoolean(dgvArquivos["st_cte", i].Value) == false && Convert.ToBoolean(dgvArquivos["st_contingencia", i].Value) == true) { throw new Exception("O Conhecimento de Sequência " + dgvArquivos["nr_lanc", i].Value.ToString() + " Já foi Gerado em Modo de Contingência."); } } } } #endregion #region Pega Notas Selecionadas na Grid string sCanceladas = ""; slistaConhec = new List<string>(); for (int i = 0; i < dgvArquivos.RowCount; i++) { if (((dgvArquivos["cl_assina", i].Value != null) && (dgvArquivos["cl_assina", i].Value.ToString().Equals("True"))) && ((dgvArquivos["ds_cancelamento", i].Value == null) || (dgvArquivos["ds_cancelamento", i].Value.ToString() == "0")) && (dgvArquivos["st_cte", i].Value.ToString().Equals("0"))) { slistaConhec.Add((string)dgvArquivos["nr_lanc", i].Value); } if ((dgvArquivos["ds_cancelamento", i].Value != null) && (dgvArquivos["ds_cancelamento", i].Value.ToString() == "1")) { if (dgvArquivos["cl_assina", i].Value == "1") { sCanceladas += "Conhecimento de Transp. " + dgvArquivos["cd_conheci", i].Value.ToString() + " - Esta Cancelado e não é Permitido o Reenvio do mesmo!" + Environment.NewLine + Environment.NewLine; } } } #endregion if (slistaConhec.Count == 0) { KryptonMessageBox.Show("Nenhum CT-e válido foi Selecionado para Gerar Xml.", Mensagens.CHeader, MessageBoxButtons.OK, MessageBoxIcon.Information); if (sCanceladas != "") { throw new Exception(sCanceladas); } } else if (slistaConhec.Count > 1) { throw new Exception("Só é Possível Gerar uma Xml de Cada vez em Modo de Contingência."); } else { //verifica no banco se as sequencias são existentes. List<string> objLGerarSeq = objGerais.ValidaSeqNoBanco(slistaConhec); if (objLGerarSeq.Count > 0) { frmGerarNumeroCte objfrmGerarNum = new frmGerarNumeroCte(objLGerarSeq); objfrmGerarNum.ShowDialog(); } #region Popula as Classes e abre form Visualização belPopulaObjetos objObjetos = new belPopulaObjetos(slistaConhec); belPopulaCte objdaoInfCte = new belPopulaCte(); objdaoInfCte.PopulaConhecimentos(objObjetos); frmVisualizaCte objFrm = new frmVisualizaCte(objObjetos); objFrm.ShowDialog(); #endregion if (objFrm.Cancelado) { throw new Exception("Geração do XML Cancelada"); } else { #region Gera XML Contingencia daoGenerator objGerator = new daoGenerator(); int iNumLote = Convert.ToInt32(objGerator.RetornaProximoValorGenerator("GEN_LOTE_CTE")); objGravaDadosRetorno.GravarChave(objFrm.objObjetosAlter); string sRecibo = objCriaXml.GerarXml(objFrm.objObjetosAlter, iNumLote); objGravaDadosRetorno.AlterarStatusCteContingencia(objFrm.objObjetosAlter.objListaConhecimentos[0].ide.nCT); KryptonMessageBox.Show("Arquivo gravado na pasta Contingência com Sucesso!", Mensagens.CHeader, MessageBoxButtons.OK, MessageBoxIcon.Information); PesquisaConhecimentos(); #endregion } } } catch (Exception ex) { new HLPexception(ex); } }
private void btnEnvio_Click(object sender, EventArgs e) { try { bool bContingencia = false; #region Verifica se Item Selecionado já foi enviado for (int i = 0; i < dgvArquivos.RowCount; i++) { if (dgvArquivos["cl_assina", i].Value != null) { if (dgvArquivos["cl_assina", i].Value.ToString().Equals("True")) { if (objGerais.VerificaCampoReciboPreenchido(dgvArquivos["nr_lanc", i].Value.ToString()) != "") { throw new Exception("O Conhecimento de Sequência " + dgvArquivos["nr_lanc", i].Value.ToString() + " Já tem um recibo Salvo no Banco de Dados, tente Buscar Retorno."); } } } } #endregion #region Pega Notas Selecionadas na Grid string sCanceladas = ""; slistaConhec = new List<string>(); for (int i = 0; i < dgvArquivos.RowCount; i++) { if (((dgvArquivos["cl_assina", i].Value != null) && (dgvArquivos["cl_assina", i].Value.ToString().Equals("True"))) && ((dgvArquivos["ds_cancelamento", i].Value == null) || (dgvArquivos["ds_cancelamento", i].Value.ToString() == "0")) && (dgvArquivos["st_cte", i].Value.ToString().Equals("0"))) { if (Convert.ToBoolean(dgvArquivos["st_cte", i].Value) == false && Convert.ToBoolean(dgvArquivos["st_contingencia", i].Value) == true) { bContingencia = true; if (slistaConhec.Count() > 0) { throw new Exception("Os Conhecimentos Pendentes devem ser Enviados um por vez."); } } slistaConhec.Add((string)dgvArquivos["nr_lanc", i].Value); } if ((dgvArquivos["ds_cancelamento", i].Value != null) && (dgvArquivos["ds_cancelamento", i].Value.ToString() == "1")) { if (dgvArquivos["cl_assina", i].Value == "1") { sCanceladas += "Conhecimento de Transp. " + dgvArquivos["cd_conheci", i].Value.ToString() + " - Esta Cancelado e não é Permitido o Reenvio do mesmo!" + Environment.NewLine + Environment.NewLine; } } } #endregion if (slistaConhec.Count == 0) { KryptonMessageBox.Show("Nenhum CT-e válido foi Selecionado para Envio.", Mensagens.CHeader, MessageBoxButtons.OK, MessageBoxIcon.Information); if (sCanceladas != "") { throw new Exception(sCanceladas); } } else { if (!bContingencia) { #region Envio Normal //verifica no banco se as sequencias são existentes. List<string> objListaSeq = objGerais.ValidaSeqNoBanco(slistaConhec); if (objListaSeq.Count > 0) { frmGerarNumeroCte objfrmGerarNum = new frmGerarNumeroCte(objListaSeq); objfrmGerarNum.ShowDialog(); } #region Popula as Classes e abre form Visualização belPopulaObjetos objObjetos = new belPopulaObjetos(slistaConhec); belPopulaCte objdaoInfCte = new belPopulaCte(); objdaoInfCte.PopulaConhecimentos(objObjetos); frmVisualizaCte objFrm = new frmVisualizaCte(objObjetos); objFrm.ShowDialog(); #endregion if (objFrm.Cancelado) { throw new Exception("Envio do(s) Conhecimento(s) Cancelado"); } else { #region Envia Lote WebService daoGenerator objGerator = new daoGenerator(); int iNumLote = Convert.ToInt32(objGerator.RetornaProximoValorGenerator("GEN_LOTE_CTE")); objGravaDadosRetorno.GravarChave(objFrm.objObjetosAlter); string sRecibo = objCriaXml.GerarXml(objFrm.objObjetosAlter, iNumLote); List<belStatusCte> ListaStatus = objCriaXml.ConsultaLoteEnviado(sRecibo); // if (sRecibo != "") { objGravaDadosRetorno.GravarRecibo(objFrm.objObjetosAlter, sRecibo); } List<string> lstatusValid = new List<string>(); lstatusValid.Add("218"); lstatusValid.Add("101"); lstatusValid.Add("103"); lstatusValid.Add("104"); lstatusValid.Add("105"); lstatusValid.Add("100"); lstatusValid.Add("204"); foreach (belStatusCte cte in ListaStatus) { if (!lstatusValid.Contains(cte.CodRetorno)) { objGravaDadosRetorno.ApagarRecibo(sRecibo); } else { //objGravaDadosRetorno.GravarProtocoloEnvio(cte.Protocolo, cte.NumeroSeq); if (cte.CodRetorno == "204" || cte.CodRetorno == "100") { cte.Enviado = true; } objGravaDadosRetorno.GravarProtocoloEnvio(cte.Protocolo, cte.NumeroSeq); } } KryptonMessageBox.Show(belTrataMensagem.RetornaMensagem(ListaStatus, belTrataMensagem.Tipo.Envio), Mensagens.CHeader, MessageBoxButtons.OK, MessageBoxIcon.Information); foreach (belStatusCte cte in ListaStatus.Where(C => C.Enviado == true)) { objGravaDadosRetorno.AlterarStatusCte(cte.NumeroSeq); objCriaXml.SalvaArquivoPastaEnviado(objGerais.BuscaNumeroConhecimento(cte.NumeroSeq), cte.Chave); } Pendencias = objGerais.VerificaPendenciasdeEnvio(); if (Pendencias.Count > 0) { btnPendencias.Visible = true; } else { btnPendencias.Visible = false; } PesquisaConhecimentos(); #endregion } #endregion } else { #region Envio Contingencia XmlDocument doc = new XmlDocument(); string sChave = objGerais.BuscaChaveRetornoCteSeq(slistaConhec[0]); DirectoryInfo dPastaContingencia = new DirectoryInfo(Pastas.CONTINGENCIA); FileInfo[] finfo = dPastaContingencia.GetFiles("*.xml", SearchOption.AllDirectories); bool ArquivoPastaEnvio = false; bool ArquivoPastaEnvioMesAtual = false; string sCaminho = ""; foreach (FileInfo arq in finfo) { if (arq.Name.Contains("Lote") && ArquivoPastaEnvio == false) { doc.Load(@arq.FullName); if (doc.GetElementsByTagName("infCte")[0].Attributes["Id"].Value.ToString().Replace("CTe", "").Equals(sChave)) { sCaminho = @arq.FullName; string sPathDest = Pastas.ENVIO + "\\" + arq.Name; string sPathOrigem = Pastas.CONTINGENCIA + "\\" + arq.Name; if (File.Exists(sPathDest)) { File.Delete(sPathDest); } File.Copy(sPathOrigem, sPathDest); ArquivoPastaEnvio = true; } } else if (!arq.Name.Contains("Lote") && ArquivoPastaEnvioMesAtual == false) { string sData = daoUtil.GetDateServidor().Date.ToString("dd-MM-yyyy"); doc.Load(@arq.FullName); if (doc.GetElementsByTagName("infCte")[0].Attributes["Id"].Value.ToString().Replace("CTe", "").Equals(sChave)) { string sPathDest = Pastas.ENVIO + sData.Substring(3, 2) + "-" + sData.Substring(8, 2) + @"\\" + arq.Name; string sPathOrigem = Pastas.CONTINGENCIA + sData.Substring(3, 2) + "-" + sData.Substring(8, 2) + @"\\" + arq.Name; if (File.Exists(sPathDest)) { File.Delete(sPathDest); } File.Copy(sPathOrigem, sPathDest); ArquivoPastaEnvioMesAtual = true; } } if (ArquivoPastaEnvioMesAtual && ArquivoPastaEnvio) { doc.Load(sCaminho); string sRetorno = objCriaXml.TransmitirLote(doc); string sRecibo = objCriaXml.BuscaReciboRetornoEnvio(sRetorno); List<belStatusCte> ListaStatus = objCriaXml.ConsultaLoteEnviado(sRecibo); if (sRecibo != "") { objGravaDadosRetorno.SalvarRecibo(sRecibo, slistaConhec[0].ToString()); } foreach (belStatusCte cte in ListaStatus) { if (cte.CodRetorno != "103" && cte.CodRetorno != "104" && cte.CodRetorno != "105" && cte.CodRetorno != "100") { objGravaDadosRetorno.ApagarRecibo(sRecibo); } else { objGravaDadosRetorno.GravarProtocoloEnvio(cte.Protocolo, cte.NumeroSeq); } } KryptonMessageBox.Show(belTrataMensagem.RetornaMensagem(ListaStatus, belTrataMensagem.Tipo.Envio), Mensagens.CHeader, MessageBoxButtons.OK, MessageBoxIcon.Information); foreach (belStatusCte cte in ListaStatus.Where(C => C.Enviado == true)) { objGravaDadosRetorno.AlterarStatusCte(cte.NumeroSeq); objCriaXml.SalvaArquivoPastaEnviado(objGerais.BuscaNumeroConhecimento(cte.NumeroSeq), cte.Chave); } btnPendencias_Click(sender, e); break; } } if (!ArquivoPastaEnvioMesAtual && !ArquivoPastaEnvio) { KryptonMessageBox.Show("Arquivo para Envio não Encontrado", Mensagens.CHeader, MessageBoxButtons.OK, MessageBoxIcon.Information); } #endregion } } } catch (Exception ex) { new HLPexception(ex); } }
public string GerarXml(belPopulaObjetos objObjetos, int iNumLote) { try { List<string> listXml = new List<string>(); DirectoryInfo dPastaMesAtual = null; DirectoryInfo dPastaEnvio = null; string sData = daoUtil.GetDateServidor().Date.ToString("dd-MM-yyyy"); string sRecibo = ""; XContainer CTe = null; XContainer infCte = null; XContainer ide = null; XContainer toma03 = null; XContainer toma4 = null; XContainer enderToma = null; XContainer emit = null; XContainer compl = null; XContainer enderEmit = null; XContainer rem = null; XContainer enderReme = null; XContainer infNF = null; XContainer infNFe = null; XContainer infOutros = null; XContainer exped = null; XContainer enderExped = null; XContainer receb = null; XContainer enderReceb = null; XContainer dest = null; XContainer enderDest = null; XContainer vPrest = null; XContainer Comp = null; XContainer imp = null; XContainer ICMS = null; XContainer ICMS00 = null; XContainer ICMS20 = null; XContainer ICMS45 = null; XContainer ICMS60 = null; XContainer ICMS90 = null; XContainer ICMSOutraUF = null; XContainer ICMSSN = null; XContainer infCTeNorm = null; XContainer seg = null; XContainer infModal = null; XContainer rodo = null; XContainer veic = null; XContainer prop = null; XContainer moto = null; #region Monta Cabecalho XNamespace pf = "http://www.portalfiscal.inf.br/cte"; XNamespace ns = "http://www.w3.org/2001/XMLSchema-instance"; #endregion for (int i = 0; i < objObjetos.objListaConhecimentos.Count; i++) { CTe = new XElement(pf + "CTe"); belinfCte obj = objObjetos.objListaConhecimentos[i]; infCte = (new XElement(pf + "infCte", new XAttribute("versao", "2.00"), new XAttribute("Id", obj.id))); #region ide ide = (new XElement(pf + "ide", new XElement(pf + "cUF", obj.ide.cUF), new XElement(pf + "cCT", obj.ide.cCT), new XElement(pf + "CFOP", obj.ide.CFOP), new XElement(pf + "natOp", obj.ide.natOp), new XElement(pf + "forPag", obj.ide.forPag), new XElement(pf + "mod", obj.ide.mod), new XElement(pf + "serie", obj.ide.serie), new XElement(pf + "nCT", Convert.ToInt32(obj.ide.nCT)), new XElement(pf + "dhEmi", (daoUtil.GetDateServidor()).ToString("yyyy-MM-ddTHH:MM:ss")), new XElement(pf + "tpImp", obj.ide.tpImp), new XElement(pf + "tpEmis", obj.ide.tpEmis), new XElement(pf + "cDV", obj.ide.cDV), new XElement(pf + "tpAmb", obj.ide.tpAmb), new XElement(pf + "tpCTe", obj.ide.tpCTe), new XElement(pf + "procEmi", obj.ide.procEmi), new XElement(pf + "verProc", obj.ide.verProc), new XElement(pf + "cMunEnv", obj.ide.cMunEnv), new XElement(pf + "xMunEnv", obj.ide.xMunEnv), new XElement(pf + "UFEnv", obj.ide.UFEnv), new XElement(pf + "modal", obj.ide.modal), new XElement(pf + "tpServ", obj.ide.tpServ), new XElement(pf + "cMunIni", obj.ide.cMunIni), new XElement(pf + "xMunIni", obj.ide.xMunIni), new XElement(pf + "UFIni", obj.ide.UFIni), new XElement(pf + "cMunFim", obj.ide.cMunFim), new XElement(pf + "xMunFim", obj.ide.xMunFim), new XElement(pf + "UFFim", obj.ide.UFFim), new XElement(pf + "retira", obj.ide.retira))); if (obj.ide.toma03 != null) { toma03 = (new XElement(pf + "toma03", new XElement(pf + "toma", obj.ide.toma03.toma))); ide.Add(toma03); } else if (obj.ide.toma04 != null) { toma4 = (new XElement(pf + "toma4", new XElement(pf + "toma", obj.ide.toma04.toma), obj.ide.toma04.CNPJ != "" ? new XElement(pf + "CNPJ", obj.ide.toma04.CNPJ) : null, obj.ide.toma04.CPF != "" ? new XElement(pf + "CPF", obj.ide.toma04.CPF) : null, obj.ide.toma04.IE != "" ? new XElement(pf + "IE", obj.ide.toma04.IE) : null, new XElement(pf + "xNome", obj.ide.toma04.xNome), obj.ide.toma04.xFant != "" ? new XElement(pf + "xFant", obj.ide.toma04.xFant) : null, obj.ide.toma04.fone != "" ? new XElement(pf + "fone", obj.ide.toma04.fone) : null)); enderToma = (new XElement(pf + "enderToma", new XElement(pf + "xLgr", obj.ide.toma04.enderToma.xLgr), new XElement(pf + "nro", obj.ide.toma04.enderToma.nro), obj.ide.toma04.enderToma.xCpl != "" ? new XElement(pf + "xCpl", obj.ide.toma04.enderToma.xCpl) : null, new XElement(pf + "xBairro", obj.ide.toma04.enderToma.xBairro), new XElement(pf + "cMun", obj.ide.toma04.enderToma.cMun), new XElement(pf + "xMun", obj.ide.toma04.enderToma.xMun), obj.ide.toma04.enderToma.CEP != "" ? new XElement(pf + "CEP", obj.ide.toma04.enderToma.CEP) : null, new XElement(pf + "UF", obj.ide.toma04.enderToma.UF), obj.ide.toma04.enderToma.cPais != "" ? new XElement(pf + "cPais", obj.ide.toma04.enderToma.cPais) : null, obj.ide.toma04.enderToma.xPais != null ? new XElement(pf + "xPais", obj.ide.toma04.enderToma.xPais) : null)); toma4.Add(enderToma); ide.Add(toma4); } #endregion #region Comp // OS_ 30302 if (obj.compl.ObsCont.xTexto.Trim() != "") { compl = (obj.compl != null ? new XElement(pf + "compl", new XElement(pf + "ObsCont", new XAttribute("xCampo", obj.compl.ObsCont.xCampo), new XElement(pf + "xTexto", obj.compl.ObsCont.xTexto.Trim()))) : null); } #endregion #region emit emit = (new XElement(pf + "emit", new XElement(pf + "CNPJ", obj.emit.CNPJ), new XElement(pf + "IE", obj.emit.IE), new XElement(pf + "xNome", obj.emit.xNome), obj.emit.xFant != "" ? new XElement(pf + "xFant", obj.emit.xFant) : null)); enderEmit = (new XElement(pf + "enderEmit", new XElement(pf + "xLgr", obj.emit.enderEmit.xLgr), new XElement(pf + "nro", obj.emit.enderEmit.nro), obj.emit.enderEmit.xCpl != "" ? new XElement(pf + "xCpl", obj.emit.enderEmit.xCpl) : null, new XElement(pf + "xBairro", obj.emit.enderEmit.xBairro), new XElement(pf + "cMun", obj.emit.enderEmit.cMun), new XElement(pf + "xMun", obj.emit.enderEmit.xMun), obj.emit.enderEmit.CEP != "" ? new XElement(pf + "CEP", obj.emit.enderEmit.CEP) : null, new XElement(pf + "UF", obj.emit.enderEmit.UF), obj.emit.enderEmit.fone != "" ? new XElement(pf + "fone", obj.emit.enderEmit.fone) : null)); emit.Add(enderEmit); #endregion #region rem rem = (new XElement(pf + "rem", obj.rem.CNPJ != "" ? new XElement(pf + "CNPJ", obj.rem.CNPJ) : null, obj.rem.CPF != "" ? new XElement(pf + "CPF", obj.rem.CPF) : null, new XElement(pf + "IE", obj.rem.IE), new XElement(pf + "xNome", obj.rem.xNome), obj.rem.xFant != "" ? new XElement(pf + "xFant", obj.rem.xFant) : null, obj.rem.fone != "" ? new XElement(pf + "fone", obj.rem.fone) : null)); enderReme = (new XElement(pf + "enderReme", new XElement(pf + "xLgr", obj.rem.enderReme.xLgr), new XElement(pf + "nro", obj.rem.enderReme.nro), obj.rem.enderReme.xCpl != "" ? new XElement(pf + "xCpl", obj.rem.enderReme.xCpl) : null, new XElement(pf + "xBairro", obj.rem.enderReme.xBairro), new XElement(pf + "cMun", obj.rem.enderReme.cMun), new XElement(pf + "xMun", obj.rem.enderReme.xMun), obj.rem.enderReme.CEP != "" ? new XElement(pf + "CEP", obj.rem.enderReme.CEP) : null, new XElement(pf + "UF", obj.rem.enderReme.UF), obj.rem.enderReme.cPais != "" ? new XElement(pf + "cPais", obj.rem.enderReme.cPais) : null, obj.rem.enderReme.xPais != "" ? new XElement(pf + "xPais", obj.rem.enderReme.xPais) : null)); rem.Add(enderReme); // 1 //for (int j = 0; j < obj.rem.infNF.Count; j++) //{ // infNF = new XElement(pf + "infNF", // new XElement(pf + "mod", obj.rem.infNF[j].mod), // new XElement(pf + "serie", obj.rem.infNF[j].serie), // new XElement(pf + "nDoc", obj.rem.infNF[j].nDoc.Replace(",", ".")), // new XElement(pf + "dEmi", (Convert.ToDateTime(obj.rem.infNF[j].dEmi)).ToString("yyyy-MM-dd")), // new XElement(pf + "vBC", obj.rem.infNF[j].vBC.Replace(",", ".")), // new XElement(pf + "vICMS", obj.rem.infNF[j].vICMS.Replace(",", ".")), // new XElement(pf + "vBCST", obj.rem.infNF[j].vBCST.Replace(",", ".")), // new XElement(pf + "vST", obj.rem.infNF[j].vST.Replace(",", ".")), // new XElement(pf + "vProd", obj.rem.infNF[j].vProd.Replace(",", ".")), // new XElement(pf + "vNF", obj.rem.infNF[j].vNF.Replace(",", ".")), // new XElement(pf + "nCFOP", obj.rem.infNF[j].nCFOP.Replace(",", "."))); // rem.Add(infNF); //} // 2 //for (int nfe = 0; nfe < obj.rem.infNFe.Count; nfe++) //{ // infNFe = new XElement(pf + "infNFe", new XElement(pf + "chave", obj.rem.infNFe[nfe].chave)); // rem.Add(infNFe); //} //3 //for (int j = 0; j < obj.rem.infOutros.Count; j++) //{ // infOutros = new XElement(pf + "infOutros", // new XElement(pf + "tpDoc", obj.rem.infOutros[j].tpDoc), // obj.rem.infOutros[j].descOutros != "" ? new XElement(pf + "descOutros", obj.rem.infOutros[j].descOutros) : null, // new XElement(pf + "nDoc", obj.rem.infOutros[j].nDoc), // new XElement(pf + "dEmi", Convert.ToDateTime(obj.rem.infOutros[j].dEmi).ToString("yyyy-MM-dd")), // new XElement(pf + "vDocFisc", obj.rem.infOutros[j].vDocFisc.Replace(",", "."))); // rem.Add(infOutros); //} #endregion #region exped exped = null; if (obj.exped != null) { exped = (new XElement(pf + "exped", obj.exped.CNPJ != "" ? new XElement(pf + "CNPJ", obj.exped.CNPJ) : null, obj.exped.CPF != "" ? new XElement(pf + "CPF", obj.exped.CPF) : null, new XElement(pf + "IE", obj.exped.IE), new XElement(pf + "xNome", obj.exped.xNome), obj.exped.fone != "" ? new XElement(pf + "fone", obj.exped.fone) : null)); enderExped = (new XElement(pf + "enderExped", new XElement(pf + "xLgr", obj.exped.enderExped.xLgr), new XElement(pf + "nro", obj.exped.enderExped.nro), obj.exped.enderExped.xCpl != "" ? new XElement(pf + "xCpl", obj.exped.enderExped.xCpl) : null, new XElement(pf + "xBairro", obj.exped.enderExped.xBairro), new XElement(pf + "cMun", obj.exped.enderExped.cMun), new XElement(pf + "xMun", obj.exped.enderExped.xMun), obj.exped.enderExped.CEP != "" ? new XElement(pf + "CEP", obj.exped.enderExped.CEP) : null, new XElement(pf + "UF", obj.exped.enderExped.UF), obj.exped.enderExped.cPais != "" ? new XElement(pf + "cPais", obj.exped.enderExped.cPais) : null, obj.exped.enderExped.xPais != "" ? new XElement(pf + "xPais", obj.exped.enderExped.xPais) : null)); exped.Add(enderExped); } #endregion #region receb receb = null; if (obj.receb != null) { receb = (new XElement(pf + "receb", obj.receb.CNPJ != "" ? new XElement(pf + "CNPJ", obj.receb.CNPJ) : null, obj.receb.CPF != "" ? new XElement(pf + "CPF", obj.receb.CPF) : null, new XElement(pf + "IE", obj.receb.IE), new XElement(pf + "xNome", obj.receb.xNome), obj.receb.fone != "" ? new XElement(pf + "fone", obj.receb.fone) : null)); enderReceb = (new XElement(pf + "enderReceb", new XElement(pf + "xLgr", obj.receb.enderReceb.xLgr), new XElement(pf + "nro", obj.receb.enderReceb.nro), obj.receb.enderReceb.xCpl != "" ? new XElement(pf + "xCpl", obj.receb.enderReceb.xCpl) : null, new XElement(pf + "xBairro", obj.receb.enderReceb.xBairro), new XElement(pf + "cMun", obj.receb.enderReceb.cMun), new XElement(pf + "xMun", obj.receb.enderReceb.xMun), obj.receb.enderReceb.CEP != "" ? new XElement(pf + "CEP", obj.receb.enderReceb.CEP) : null, new XElement(pf + "UF", obj.receb.enderReceb.UF), obj.receb.enderReceb.cPais != "" ? new XElement(pf + "cPais", obj.receb.enderReceb.cPais) : null, obj.receb.enderReceb.xPais != "" ? new XElement(pf + "xPais", obj.receb.enderReceb.xPais) : null)); receb.Add(enderReceb); } #endregion #region dest dest = (new XElement(pf + "dest", obj.dest.CNPJ != "" ? new XElement(pf + "CNPJ", obj.dest.CNPJ) : null, obj.dest.CPF != "" ? new XElement(pf + "CPF", obj.dest.CPF) : null, obj.dest.IE != "" ? new XElement(pf + "IE", obj.dest.IE) : null, new XElement(pf + "xNome", obj.dest.xNome), obj.dest.fone != "" ? new XElement(pf + "fone", obj.dest.fone) : null, obj.dest.ISUF != "" ? new XElement(pf + "ISUF", obj.dest.ISUF) : null)); enderDest = (new XElement(pf + "enderDest", new XElement(pf + "xLgr", obj.dest.enderDest.xLgr), new XElement(pf + "nro", obj.dest.enderDest.nro), obj.dest.enderDest.xCpl != "" ? new XElement(pf + "xCpl", obj.dest.enderDest.xCpl) : null, new XElement(pf + "xBairro", obj.dest.enderDest.xBairro), new XElement(pf + "cMun", obj.dest.enderDest.cMun), new XElement(pf + "xMun", obj.dest.enderDest.xMun), obj.dest.enderDest.CEP != "" ? new XElement(pf + "CEP", obj.dest.enderDest.CEP) : null, new XElement(pf + "UF", obj.dest.enderDest.UF), obj.dest.enderDest.cPais != "" ? new XElement(pf + "cPais", obj.dest.enderDest.cPais) : null, obj.dest.enderDest.xPais != "" ? new XElement(pf + "xPais", obj.dest.enderDest.xPais) : null)); dest.Add(enderDest); #endregion #region vPrest vPrest = (new XElement(pf + "vPrest", new XElement(pf + "vTPrest", obj.vPrest.vTPrest.Replace(",", ".")), new XElement(pf + "vRec", obj.vPrest.vRec.Replace(",", ".")))); for (int j = 0; j < obj.vPrest.Comp.Count; j++) { if (Convert.ToDecimal(obj.vPrest.Comp[j].vComp.Replace(".", ",")) > 0) { Comp = new XElement(pf + "Comp", new XElement(pf + "xNome", obj.vPrest.Comp[j].xNome), new XElement(pf + "vComp", Convert.ToDecimal(obj.vPrest.Comp[j].vComp.Replace(".", ",")).ToString("#0.00").Replace(",", "."))); vPrest.Add(Comp); } } #endregion #region imp imp = new XElement(pf + "imp"); //ICMS = new XElement(pf + "ICMS", new XElement(pf + "vTotTrib", "200.06")); ICMS = new XElement(pf + "ICMS"); if (obj.imp.ICMS.ICMS00 != null) { belICMS00 objICMS00 = obj.imp.ICMS.ICMS00; ICMS00 = (new XElement(pf + "ICMS00", new XElement(pf + "CST", objICMS00.CST), new XElement(pf + "vBC", objICMS00.vBC), new XElement(pf + "pICMS", objICMS00.pICMS), new XElement(pf + "vICMS", objICMS00.vICMS))); ICMS.Add(ICMS00); } else if (obj.imp.ICMS.ICMS20 != null) { belICMS20 objICMS20 = obj.imp.ICMS.ICMS20; ICMS20 = (new XElement(pf + "ICMS20", new XElement(pf + "CST", objICMS20.CST), new XElement(pf + "pRedBC", objICMS20.pRedBC), new XElement(pf + "vBC", objICMS20.vBC), new XElement(pf + "pICMS", objICMS20.pICMS), new XElement(pf + "vICMS", objICMS20.vICMS))); ICMS.Add(ICMS20); } else if (obj.imp.ICMS.ICMS45 != null) { ICMS45 = (new XElement(pf + "ICMS45", new XElement(pf + "CST", obj.imp.ICMS.ICMS45.CST))); ICMS.Add(ICMS45); } else if (obj.imp.ICMS.ICMS60 != null) { belICMS60 objICMS60 = obj.imp.ICMS.ICMS60; ICMS60 = (new XElement(pf + "ICMS60", new XElement(pf + "CST", objICMS60.CST), new XElement(pf + "vBCSTRet", objICMS60.vBCSTRet), new XElement(pf + "vICMSSTRet", objICMS60.vICMSSTRet), new XElement(pf + "pICMSSTRet", objICMS60.pICMSSTRet))); ICMS.Add(ICMS60); } else if (obj.imp.ICMS.ICMS90 != null) { belICMS90 objICMS90 = obj.imp.ICMS.ICMS90; ICMS60 = (new XElement(pf + "ICMS90", new XElement(pf + "CST", objICMS90.CST), new XElement(pf + "vBC", objICMS90.vBC), new XElement(pf + "pICMS", objICMS90.pICMS), new XElement(pf + "vICMS", objICMS90.vICMS))); ICMS.Add(ICMS90); } else if (obj.imp.ICMS.ICMSOutraUF != null) { belICMSOutraUF objICMSOutraUF = obj.imp.ICMS.ICMSOutraUF; ICMSOutraUF = (new XElement(pf + "ICMSOutraUF", new XElement(pf + "CST", objICMSOutraUF.CST), objICMSOutraUF.pRedBCOutraUF != "" ? new XElement(pf + "pRedBCOutraUF", objICMSOutraUF.pRedBCOutraUF) : null, new XElement(pf + "vBCOutraUF", objICMSOutraUF.vBCOutraUF), new XElement(pf + "pICMSOutraUF", objICMSOutraUF.pICMSOutraUF), new XElement(pf + "vICMSOutraUF", objICMSOutraUF.vICMSOutraUF))); ICMS.Add(ICMSOutraUF); } else if (obj.imp.ICMS.ICMSSN != null) { ICMSSN = (new XElement(pf + "ICMSSN", new XElement(pf + "indSN", "1"))); ICMS.Add(ICMSSN); } imp.Add(ICMS); #endregion #region infCTeNorm infCTeNorm = new XElement(pf + "infCTeNorm", new XElement(pf + "infCarga", new XElement(pf + "vCarga", obj.infCTeNorm.infCarga.vCarga), new XElement(pf + "proPred", obj.infCTeNorm.infCarga.proPred), obj.infCTeNorm.infCarga.xOutCat.Trim() != "" ? new XElement(pf + "xOutCat", obj.infCTeNorm.infCarga.xOutCat.Trim()) : null, obj.infCTeNorm.infCarga.infQ != null ? (from c in obj.infCTeNorm.infCarga.infQ select new XElement(pf + "infQ", new XElement(pf + "cUnid", c.cUnid), new XElement(pf + "tpMed", c.tpMed), new XElement(pf + "qCarga", retornaqCarga(c.qCarga)))) : null), (obj.infCTeNorm.infDoc != null ? new XElement(pf + "infDoc", (obj.infCTeNorm.infDoc.infNF.Count > 0 ? (from c in obj.infCTeNorm.infDoc.infNF //2.0 select new XElement(pf + "infNF", new XElement(pf + "mod", c.mod), new XElement(pf + "serie", c.serie), new XElement(pf + "nDoc", c.nDoc.Replace(",", ".")), new XElement(pf + "dEmi", (Convert.ToDateTime(c.dEmi)).ToString("yyyy-MM-dd")), new XElement(pf + "vBC", c.vBC.Replace(",", ".")), new XElement(pf + "vICMS", c.vICMS.Replace(",", ".")), new XElement(pf + "vBCST", c.vBCST.Replace(",", ".")), new XElement(pf + "vST", c.vST.Replace(",", ".")), new XElement(pf + "vProd", c.vProd.Replace(",", ".")), new XElement(pf + "vNF", c.vNF.Replace(",", ".")), new XElement(pf + "nCFOP", c.nCFOP.Replace(",", ".")))) : null), (obj.infCTeNorm.infDoc.infNFe.Count > 0 ? (from c in obj.infCTeNorm.infDoc.infNFe //2.0 select select new XElement(pf + "infNFe", new XElement(pf + "chave", c.chave))) : null), (obj.infCTeNorm.infDoc.infOutros.Count > 0 ? //2.0 (from c in obj.infCTeNorm.infDoc.infOutros select new XElement(pf + "infOutros", new XElement(pf + "tpDoc", c.tpDoc), c.descOutros != "" ? new XElement(pf + "descOutros", c.descOutros) : null, new XElement(pf + "nDoc", c.nDoc), new XElement(pf + "dEmi", Convert.ToDateTime(c.dEmi).ToString("yyyy-MM-dd")), new XElement(pf + "vDocFisc", c.vDocFisc.Replace(",", ".")))) : null)) : null), ((obj.ide.tpCTe == 0 || obj.ide.tpCTe == 3) && (obj.ide.tpServ > 0)) ? new XElement(pf + "docAnt", new XElement(pf + "emiDocAnt", obj.rem.CNPJ != "" ? new XElement(pf + "CNPJ", obj.rem.CNPJ) : null, obj.rem.CPF != "" ? new XElement(pf + "CPF", obj.rem.CPF) : null, new XElement(pf + "IE", obj.rem.IE), new XElement(pf + "UF", obj.rem.enderReme.UF), new XElement(pf + "xNome", obj.rem.xNome.Trim()), new XElement(pf + "idDocAnt", (from c in obj.infCTeNorm.infDoc.infNFe select new XElement(pf + "idDocAntEle", new XElement(pf + "chave", c.chave) ))))) : null); seg = new XElement(pf + "seg", new XElement(pf + "respSeg", obj.infCTeNorm.seg.respSeg), new XElement(pf + "nApol", obj.infCTeNorm.seg.nApol)); infCTeNorm.Add(seg); #region Modal Rodoviario infModal = new XElement(pf + "infModal", new XAttribute("versaoModal", "2.00")); rodo = new XElement(pf + "rodo", new XElement(pf + "RNTRC", obj.infCTeNorm.rodo.RNTRC), new XElement(pf + "dPrev", Convert.ToDateTime(obj.infCTeNorm.rodo.dPrev).ToString("yyyy-MM-dd")), new XElement(pf + "lota", obj.infCTeNorm.rodo.lota)); for (int v = 0; v < obj.infCTeNorm.rodo.veic.Count; v++) { veic = new XElement(pf + "veic", new XElement(pf + "RENAVAM", obj.infCTeNorm.rodo.veic[v].RENAVAM), new XElement(pf + "placa", obj.infCTeNorm.rodo.veic[v].placa), new XElement(pf + "tara", obj.infCTeNorm.rodo.veic[v].tara), new XElement(pf + "capKG", obj.infCTeNorm.rodo.veic[v].capKG), new XElement(pf + "capM3", obj.infCTeNorm.rodo.veic[v].capM3), new XElement(pf + "tpProp", obj.infCTeNorm.rodo.veic[v].tpProp), new XElement(pf + "tpVeic", obj.infCTeNorm.rodo.veic[v].tpVeic), new XElement(pf + "tpRod", obj.infCTeNorm.rodo.veic[v].tpRod), new XElement(pf + "tpCar", obj.infCTeNorm.rodo.veic[v].tpCar), new XElement(pf + "UF", obj.infCTeNorm.rodo.veic[v].UF)); if (obj.infCTeNorm.rodo.veic[v].prop != null) { prop = new XElement(pf + "prop", new XElement(pf + (obj.infCTeNorm.rodo.veic[v].prop.CPFCNPJ.Length == 11 ? "CPF" : "CNPJ"), obj.infCTeNorm.rodo.veic[v].prop.CPFCNPJ), new XElement(pf + "RNTRC", obj.infCTeNorm.rodo.veic[v].prop.RNTRC), new XElement(pf + "xNome", obj.infCTeNorm.rodo.veic[v].prop.xNome), new XElement(pf + "IE", obj.infCTeNorm.rodo.veic[v].prop.IE), new XElement(pf + "UF", obj.infCTeNorm.rodo.veic[v].prop.UF), new XElement(pf + "tpProp", obj.infCTeNorm.rodo.veic[v].prop.tpProp)); veic.Add(prop); } rodo.Add(veic); } if (obj.infCTeNorm.rodo.moto != null) { moto = new XElement(pf + "moto", new XElement(pf + "xNome", obj.infCTeNorm.rodo.moto.xNome), new XElement(pf + "CPF", obj.infCTeNorm.rodo.moto.CPF)); rodo.Add(moto); } #endregion infModal.Add(rodo); infCTeNorm.Add(infModal); #endregion #region Monta CTe infCte.Add(ide); infCte.Add(compl); infCte.Add(emit); infCte.Add(rem); infCte.Add(exped); infCte.Add(receb); infCte.Add(dest); infCte.Add(vPrest); infCte.Add(imp); infCte.Add(infCTeNorm); CTe.Add(infCte); #endregion #region Assinatura belAssinaXml Assinatura = new belAssinaXml(); string sCte = Assinatura.ConfigurarArquivo(CTe.ToString(), "infCte", Acesso.cert_CTe); listXml.Add(sCte); #endregion #region SalvaCteIndividual sCte = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + sCte; string sNumCte = obj.ide.nCT.PadLeft(6, '0'); if (Acesso.TP_EMIS == 2) { dPastaEnvio = new DirectoryInfo(Pastas.CONTINGENCIA); } else { dPastaEnvio = new DirectoryInfo(Pastas.ENVIO); } if (!dPastaEnvio.Exists) { dPastaEnvio.Create(); } dPastaMesAtual = new DirectoryInfo(dPastaEnvio + @"\\" + sData.Substring(3, 2) + "-" + sData.Substring(8, 2)); if (!dPastaMesAtual.Exists) { dPastaMesAtual.Create(); } File.WriteAllText(dPastaMesAtual.ToString() + "\\" + "Cte_" + sNumCte + ".xml", sCte); #endregion } #region Salva Lote string sXml = ""; foreach (var xml in listXml) { sXml = sXml + xml; } string sXmlCte = ("<?xml version=\"1.0\" encoding=\"UTF-8\"?><enviCTe versao=\"2.00\" " + "xsi:schemaLocation=\"http://www.portalfiscal.inf.br/cte enviCte_v1.04.xsd\" " + "xmlns=\"http://www.portalfiscal.inf.br/cte\" xmlns:ds=\"http://www.w3.org/2000/09/xmldsig#\" " + "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"><idLote>" + iNumLote + "</idLote>" + sXml + "</enviCTe>"); string sPathLote = dPastaEnvio.ToString() + "\\" + "Cte_Lote_" + iNumLote + "_" + sData + ".xml"; StreamWriter sw = new StreamWriter(sPathLote); sw.Write(sXmlCte); sw.Close(); #endregion #region Valida_Xml belValidaXml.ValidarXml("http://www.portalfiscal.inf.br/cte", Pastas.SCHEMA_CTE + "\\enviCTe_v2.00.xsd", sPathLote); //belGlobais getschema = new belGlobais(); //XmlSchemaCollection myschema = new XmlSchemaCollection(); //XmlValidatingReader reader; //try //{ // XmlParserContext context = new XmlParserContext(null, null, "", XmlSpace.None); // reader = new XmlValidatingReader(sXmlCte.ToString(), XmlNodeType.Element, context); // myschema.Add("http://www.portalfiscal.inf.br/cte", belStaticPastas.SCHEMA_CTE + "\\enviCte_v1.04.xsd"); // reader.ValidationType = ValidationType.Schema; // reader.Schemas.Add(myschema); // while (reader.Read()) // { // } //} //catch (XmlException x) //{ // throw new Exception(x.Message); //} //catch (XmlSchemaException x) //{ // throw new Exception(x.Message); //} #endregion #region Envia e Busca Recibo Lote WebService if (Acesso.TP_EMIS == 1 || Acesso.TP_EMIS == 6) // modo normal // os_svc { XmlDocument doc = new XmlDocument(); doc.Load(dPastaEnvio.ToString() + "\\" + "Cte_Lote_" + iNumLote + "_" + sData + ".xml"); //busca retorno string sRetorno = TransmitirLote(doc); sRecibo = BuscaReciboRetornoEnvio(sRetorno); } #endregion return sRecibo; } catch (Exception ex) { throw ex; } }
private void CriaObjAlter() { try { List<belinfCte> objList = new List<belinfCte>(); for (int i = 0; i < this.objObjetos.objListaConhecimentos.Count; i++) { belinfCte objbelinfCte = new belinfCte(); belinfCte obj = this.objObjetos.objListaConhecimentos[i]; #region Identificacao objbelinfCte.id = obj.id; objbelinfCte.ide = new belide(); objbelinfCte.ide.cUF = obj.ide.cUF; objbelinfCte.ide.cCT = obj.ide.cCT; objbelinfCte.ide.CFOP = obj.ide.CFOP; objbelinfCte.ide.natOp = obj.ide.natOp; objbelinfCte.ide.forPag = obj.ide.forPag; objbelinfCte.ide.mod = obj.ide.mod; objbelinfCte.ide.serie = obj.ide.serie; objbelinfCte.ide.nCT = obj.ide.nCT; objbelinfCte.ide.tpImp = obj.ide.tpImp; objbelinfCte.ide.tpEmis = obj.ide.tpEmis; objbelinfCte.ide.cDV = obj.ide.cDV; objbelinfCte.ide.tpAmb = obj.ide.tpAmb; objbelinfCte.ide.tpCTe = obj.ide.tpCTe; objbelinfCte.ide.procEmi = obj.ide.procEmi; objbelinfCte.ide.verProc = obj.ide.verProc; objbelinfCte.ide.cMunEnv = obj.ide.cMunEnv; objbelinfCte.ide.xMunEnv = obj.ide.xMunEnv; objbelinfCte.ide.UFEnv = obj.ide.UFEnv; objbelinfCte.ide.modal = obj.ide.modal; objbelinfCte.ide.tpServ = obj.ide.tpServ; objbelinfCte.ide.cMunIni = obj.ide.cMunIni; objbelinfCte.ide.xMunIni = obj.ide.xMunIni; objbelinfCte.ide.UFIni = obj.ide.UFIni; objbelinfCte.ide.cMunFim = obj.ide.cMunFim; objbelinfCte.ide.xMunFim = obj.ide.xMunFim; objbelinfCte.ide.UFFim = obj.ide.UFFim; objbelinfCte.ide.retira = obj.ide.retira; objbelinfCte.ide.xDetRetira = obj.ide.xDetRetira; #endregion #region Tomador if (obj.ide.toma03 != null) { objbelinfCte.ide.toma03 = new beltoma03(); objbelinfCte.ide.toma03.toma = obj.ide.toma03.toma; } else if (obj.ide.toma04 != null) { objbelinfCte.ide.toma04 = new beltoma04(); objbelinfCte.ide.toma04.toma = obj.ide.toma04.toma; objbelinfCte.ide.toma04.CNPJ = obj.ide.toma04.CNPJ; objbelinfCte.ide.toma04.CPF = obj.ide.toma04.CPF; objbelinfCte.ide.toma04.IE = obj.ide.toma04.IE; objbelinfCte.ide.toma04.xNome = obj.ide.toma04.xNome; objbelinfCte.ide.toma04.xFant = obj.ide.toma04.xFant; objbelinfCte.ide.toma04.fone = obj.ide.toma04.fone; objbelinfCte.ide.toma04.enderToma = new belenderToma(); objbelinfCte.ide.toma04.enderToma.xLgr = obj.ide.toma04.enderToma.xLgr; objbelinfCte.ide.toma04.enderToma.nro = obj.ide.toma04.enderToma.nro; objbelinfCte.ide.toma04.enderToma.xCpl = obj.ide.toma04.enderToma.xCpl; objbelinfCte.ide.toma04.enderToma.xBairro = obj.ide.toma04.enderToma.xBairro; objbelinfCte.ide.toma04.enderToma.cMun = obj.ide.toma04.enderToma.cMun; objbelinfCte.ide.toma04.enderToma.xMun = obj.ide.toma04.enderToma.xMun; objbelinfCte.ide.toma04.enderToma.CEP = obj.ide.toma04.enderToma.CEP; objbelinfCte.ide.toma04.enderToma.UF = obj.ide.toma04.enderToma.UF; objbelinfCte.ide.toma04.enderToma.cPais = obj.ide.toma04.enderToma.cPais; objbelinfCte.ide.toma04.enderToma.xPais = obj.ide.toma04.enderToma.xPais; } #endregion #region Emitente objbelinfCte.emit = new belemit(); objbelinfCte.emit.CNPJ = obj.emit.CNPJ; objbelinfCte.emit.IE = obj.emit.IE; objbelinfCte.emit.xNome = obj.emit.xNome; objbelinfCte.emit.xFant = obj.emit.xFant; objbelinfCte.emit.enderEmit = new belenderEmit(); objbelinfCte.emit.enderEmit.xLgr = obj.emit.enderEmit.xLgr; objbelinfCte.emit.enderEmit.nro = obj.emit.enderEmit.nro; objbelinfCte.emit.enderEmit.xCpl = obj.emit.enderEmit.xCpl; objbelinfCte.emit.enderEmit.xBairro = obj.emit.enderEmit.xBairro; objbelinfCte.emit.enderEmit.cMun = obj.emit.enderEmit.cMun; objbelinfCte.emit.enderEmit.xMun = obj.emit.enderEmit.xMun; objbelinfCte.emit.enderEmit.CEP = obj.emit.enderEmit.CEP; objbelinfCte.emit.enderEmit.UF = obj.emit.enderEmit.UF; objbelinfCte.emit.enderEmit.fone = obj.emit.enderEmit.fone; #endregion #region Remetente objbelinfCte.rem = new belrem(); objbelinfCte.rem.CNPJ = obj.rem.CNPJ; objbelinfCte.rem.CPF = obj.rem.CPF; objbelinfCte.rem.IE = obj.rem.IE; objbelinfCte.rem.xNome = obj.rem.xNome; objbelinfCte.rem.xFant = obj.rem.xFant; objbelinfCte.rem.fone = obj.rem.fone; objbelinfCte.rem.enderReme = new belenderReme(); objbelinfCte.rem.enderReme.xLgr = obj.rem.enderReme.xLgr; objbelinfCte.rem.enderReme.nro = obj.rem.enderReme.nro; objbelinfCte.rem.enderReme.xCpl = obj.rem.enderReme.xCpl; objbelinfCte.rem.enderReme.xBairro = obj.rem.enderReme.xBairro; objbelinfCte.rem.enderReme.cMun = obj.rem.enderReme.cMun; objbelinfCte.rem.enderReme.xMun = obj.rem.enderReme.xMun; try { objbelinfCte.rem.enderReme.CEP = obj.rem.enderReme.CEP; } catch (Exception) { } objbelinfCte.rem.enderReme.UF = obj.rem.enderReme.UF; objbelinfCte.rem.enderReme.xPais = obj.rem.enderReme.xPais; objbelinfCte.rem.enderReme.cPais = obj.rem.enderReme.cPais; #endregion #region Destinatario objbelinfCte.dest = new beldest(); objbelinfCte.dest.CNPJ = obj.dest.CNPJ; objbelinfCte.dest.CPF = obj.dest.CPF; objbelinfCte.dest.IE = obj.dest.IE; objbelinfCte.dest.xNome = obj.dest.xNome; objbelinfCte.dest.fone = obj.dest.fone; objbelinfCte.dest.ISUF = obj.dest.ISUF; objbelinfCte.dest.enderDest = new belenderDest(); objbelinfCte.dest.enderDest.xLgr = obj.dest.enderDest.xLgr; objbelinfCte.dest.enderDest.nro = obj.dest.enderDest.nro; objbelinfCte.dest.enderDest.xCpl = obj.dest.enderDest.xCpl; objbelinfCte.dest.enderDest.xBairro = obj.dest.enderDest.xBairro; objbelinfCte.dest.enderDest.cMun = obj.dest.enderDest.cMun; objbelinfCte.dest.enderDest.xMun = obj.dest.enderDest.xMun; objbelinfCte.dest.enderDest.CEP = obj.dest.enderDest.CEP; objbelinfCte.dest.enderDest.UF = obj.dest.enderDest.UF; objbelinfCte.dest.enderDest.xPais = obj.dest.enderDest.xPais; objbelinfCte.dest.enderDest.cPais = obj.dest.enderDest.cPais; #endregion #region Expedidor if (obj.exped != null) { objbelinfCte.exped = new belexped(); objbelinfCte.exped.CNPJ = obj.exped.CNPJ; objbelinfCte.exped.CPF = obj.exped.CPF; objbelinfCte.exped.IE = obj.exped.IE; objbelinfCte.exped.xNome = obj.exped.xNome; objbelinfCte.exped.fone = obj.exped.fone; objbelinfCte.exped.enderExped = new belenderExped(); objbelinfCte.exped.enderExped.xLgr = obj.exped.enderExped.xLgr; objbelinfCte.exped.enderExped.nro = obj.exped.enderExped.nro; objbelinfCte.exped.enderExped.xCpl = obj.exped.enderExped.xCpl; objbelinfCte.exped.enderExped.xBairro = obj.exped.enderExped.xBairro; objbelinfCte.exped.enderExped.cMun = obj.exped.enderExped.cMun; objbelinfCte.exped.enderExped.xMun = obj.exped.enderExped.xMun; objbelinfCte.exped.enderExped.CEP = obj.exped.enderExped.CEP; objbelinfCte.exped.enderExped.UF = obj.exped.enderExped.UF; objbelinfCte.exped.enderExped.xPais = obj.exped.enderExped.xPais; objbelinfCte.exped.enderExped.cPais = obj.exped.enderExped.cPais; } #endregion #region Recebedor if (obj.receb != null) { objbelinfCte.receb = new belreceb(); objbelinfCte.receb.CNPJ = obj.receb.CNPJ; objbelinfCte.receb.CPF = obj.receb.CPF; objbelinfCte.receb.IE = obj.receb.IE; objbelinfCte.receb.xNome = obj.receb.xNome; objbelinfCte.receb.fone = obj.receb.fone; objbelinfCte.receb.enderReceb = new belenderReceb(); objbelinfCte.receb.enderReceb.xLgr = obj.receb.enderReceb.xLgr; objbelinfCte.receb.enderReceb.nro = obj.receb.enderReceb.nro; objbelinfCte.receb.enderReceb.xCpl = obj.receb.enderReceb.xCpl; objbelinfCte.receb.enderReceb.xBairro = obj.receb.enderReceb.xBairro; objbelinfCte.receb.enderReceb.cMun = obj.receb.enderReceb.cMun; objbelinfCte.receb.enderReceb.xMun = obj.receb.enderReceb.xMun; objbelinfCte.receb.enderReceb.CEP = obj.receb.enderReceb.CEP; objbelinfCte.receb.enderReceb.UF = obj.receb.enderReceb.UF; objbelinfCte.receb.enderReceb.xPais = obj.receb.enderReceb.xPais; objbelinfCte.receb.enderReceb.cPais = obj.receb.enderReceb.cPais; } #endregion #region Informacoes da NF objbelinfCte.infCTeNorm.infDoc.infNF = obj.infCTeNorm.infDoc.infNF; //objbelinfCte.infCTeNorm.infDoc.infNF = new List<belinfNF>(); //for (int j = 0; j < obj.infCTeNorm.infDoc.infNF.Count; j++) //{ // belinfNF nf = new belinfNF(); // nf.mod = obj.infCTeNorm.infDoc.infNF[j].mod; // nf.nDoc = obj.infCTeNorm.infDoc.infNF[j].nDoc; // nf.serie = obj.infCTeNorm.infDoc.infNF[j].serie; // nf.dEmi = obj.infCTeNorm.infDoc.infNF[j].dEmi; // nf.vBC = obj.infCTeNorm.infDoc.infNF[j].vBC; // nf.vICMS = obj.infCTeNorm.infDoc.infNF[j].vICMS; // nf.vBCST = obj.infCTeNorm.infDoc.infNF[j].vBCST; // nf.vST = obj.infCTeNorm.infDoc.infNF[j].vST; // nf.vProd = obj.infCTeNorm.infDoc.infNF[j].vProd; // nf.vNF = obj.infCTeNorm.infDoc.infNF[j].vNF; // nf.nCFOP = Convert.ToInt32(obj.infCTeNorm.infDoc.infNF[j].nCFOP).ToString(); // objbelinfCte.infCTeNorm.infDoc.infNF.Add(nf); //} objbelinfCte.infCTeNorm.infDoc.infNFe = obj.infCTeNorm.infDoc.infNFe; //objbelinfCte.infCTeNorm.infDoc.infNFe = new List<belinfNFe>(); //for (int n = 0; n < obj.infCTeNorm.infDoc.infNFe.Count; n++) //{ // belinfNFe nfe = new belinfNFe(); // nfe.chave = obj.infCTeNorm.infDoc.infNFe[n].chave; // nfe.nDoc = obj.infCTeNorm.infDoc.infNFe[n].nDoc; // objbelinfCte.infCTeNorm.infDoc.infNFe.Add(nfe); //} #endregion #region Outros Documentos objbelinfCte.infCTeNorm.infDoc.infOutros = obj.infCTeNorm.infDoc.infOutros; //objbelinfCte.infCTeNorm.infDoc.infOutros = new List<belinfOutros>(); //for (int j = 0; j < obj.infCTeNorm.infDoc.infOutros.Count; j++) //{ // belinfOutros infOutros = new belinfOutros(); // infOutros.tpDoc = obj.infCTeNorm.infDoc.infOutros[j].tpDoc; // infOutros.descOutros = obj.infCTeNorm.infDoc.infOutros[j].descOutros; // infOutros.nDoc = obj.infCTeNorm.infDoc.infOutros[j].nDoc; // infOutros.dEmi = obj.infCTeNorm.infDoc.infOutros[j].dEmi; // infOutros.vDocFisc = obj.infCTeNorm.infDoc.infOutros[j].vDocFisc; // objbelinfCte.infCTeNorm.infDoc.infOutros.Add(infOutros); //} #endregion #region Valores objbelinfCte.vPrest = new belvPrest(); objbelinfCte.vPrest.vTPrest = obj.vPrest.vTPrest; objbelinfCte.vPrest.vRec = obj.vPrest.vRec; objbelinfCte.vPrest.Comp = obj.vPrest.Comp; objbelinfCte.imp = new belimp(); objbelinfCte.imp.ICMS = new belICMS(); if (obj.imp.ICMS.ICMS00 != null) { objbelinfCte.imp.ICMS.ICMS00 = new belICMS00(); objbelinfCte.imp.ICMS.ICMS00.CST = obj.imp.ICMS.ICMS00.CST; objbelinfCte.imp.ICMS.ICMS00.vBC = obj.imp.ICMS.ICMS00.vBC; objbelinfCte.imp.ICMS.ICMS00.pICMS = obj.imp.ICMS.ICMS00.pICMS; objbelinfCte.imp.ICMS.ICMS00.vICMS = obj.imp.ICMS.ICMS00.vICMS; } else if (obj.imp.ICMS.ICMS20 != null) { objbelinfCte.imp.ICMS.ICMS20 = new belICMS20(); objbelinfCte.imp.ICMS.ICMS20.CST = obj.imp.ICMS.ICMS20.CST; objbelinfCte.imp.ICMS.ICMS20.pRedBC = obj.imp.ICMS.ICMS20.pRedBC; objbelinfCte.imp.ICMS.ICMS20.vBC = obj.imp.ICMS.ICMS20.vBC; objbelinfCte.imp.ICMS.ICMS20.pICMS = obj.imp.ICMS.ICMS20.pICMS; objbelinfCte.imp.ICMS.ICMS20.vICMS = obj.imp.ICMS.ICMS20.vICMS; } else if (obj.imp.ICMS.ICMS45 != null) { objbelinfCte.imp.ICMS.ICMS45 = new belICMS45(); objbelinfCte.imp.ICMS.ICMS45.CST = obj.imp.ICMS.ICMS45.CST; } else if (obj.imp.ICMS.ICMS60 != null) { objbelinfCte.imp.ICMS.ICMS60 = new belICMS60(); objbelinfCte.imp.ICMS.ICMS60.CST = obj.imp.ICMS.ICMS60.CST; objbelinfCte.imp.ICMS.ICMS60.vBCSTRet = obj.imp.ICMS.ICMS60.vBCSTRet; objbelinfCte.imp.ICMS.ICMS60.vICMSSTRet = obj.imp.ICMS.ICMS60.vICMSSTRet; objbelinfCte.imp.ICMS.ICMS60.pICMSSTRet = obj.imp.ICMS.ICMS60.pICMSSTRet; objbelinfCte.imp.ICMS.ICMS60.vCred = obj.imp.ICMS.ICMS60.vCred; } else if (obj.imp.ICMS.ICMS90 != null) { objbelinfCte.imp.ICMS.ICMS90 = new belICMS90(); objbelinfCte.imp.ICMS.ICMS90.CST = obj.imp.ICMS.ICMS90.CST; objbelinfCte.imp.ICMS.ICMS90.pRedBC = obj.imp.ICMS.ICMS90.pRedBC; objbelinfCte.imp.ICMS.ICMS90.vBC = obj.imp.ICMS.ICMS90.vBC; objbelinfCte.imp.ICMS.ICMS90.pICMS = obj.imp.ICMS.ICMS90.pICMS; objbelinfCte.imp.ICMS.ICMS90.vICMS = obj.imp.ICMS.ICMS90.vICMS; objbelinfCte.imp.ICMS.ICMS90.vCred = obj.imp.ICMS.ICMS90.vCred; } else if (obj.imp.ICMS.ICMSOutraUF != null) { objbelinfCte.imp.ICMS.ICMSOutraUF = new belICMSOutraUF(); objbelinfCte.imp.ICMS.ICMSOutraUF.CST = obj.imp.ICMS.ICMSOutraUF.CST; objbelinfCte.imp.ICMS.ICMSOutraUF.pRedBCOutraUF = obj.imp.ICMS.ICMSOutraUF.pRedBCOutraUF; objbelinfCte.imp.ICMS.ICMSOutraUF.vBCOutraUF = obj.imp.ICMS.ICMSOutraUF.vBCOutraUF; objbelinfCte.imp.ICMS.ICMSOutraUF.pICMSOutraUF = obj.imp.ICMS.ICMSOutraUF.pICMSOutraUF; objbelinfCte.imp.ICMS.ICMSOutraUF.vICMSOutraUF = obj.imp.ICMS.ICMSOutraUF.vICMSOutraUF; } #endregion #region InformacoesCarga //objbelinfCte.infCTeNorm = new belinfCTeNorm(); objbelinfCte.infCTeNorm.infCarga = new belinfCarga(); objbelinfCte.infCTeNorm.infCarga.vCarga = obj.infCTeNorm.infCarga.vCarga; objbelinfCte.infCTeNorm.infCarga.proPred = obj.infCTeNorm.infCarga.proPred; objbelinfCte.infCTeNorm.infCarga.xOutCat = obj.infCTeNorm.infCarga.xOutCat; objbelinfCte.infCTeNorm.infCarga.infQ = new List<belinfQ>(); for (int j = 0; j < obj.infCTeNorm.infCarga.infQ.Count; j++) { belinfQ objInfQ = new belinfQ(); objInfQ.cUnid = obj.infCTeNorm.infCarga.infQ[j].cUnid; objInfQ.tpMed = obj.infCTeNorm.infCarga.infQ[j].tpMed; objInfQ.qCarga = obj.infCTeNorm.infCarga.infQ[j].qCarga; objbelinfCte.infCTeNorm.infCarga.infQ.Add(objInfQ); } #endregion #region Rodoviario objbelinfCte.infCTeNorm.seg = new belseg(); objbelinfCte.infCTeNorm.rodo = new belrodo(); objbelinfCte.infCTeNorm.seg.respSeg = obj.infCTeNorm.seg.respSeg; objbelinfCte.infCTeNorm.seg.nApol = obj.infCTeNorm.seg.nApol; objbelinfCte.infCTeNorm.rodo.RNTRC = obj.infCTeNorm.rodo.RNTRC; objbelinfCte.infCTeNorm.rodo.dPrev = obj.infCTeNorm.rodo.dPrev; objbelinfCte.infCTeNorm.rodo.lota = obj.infCTeNorm.rodo.lota; #endregion #region Obs objbelinfCte.compl = new belcompl(); objbelinfCte.compl.ObsCont.xTexto = obj.compl.ObsCont.xTexto; #endregion #region Veiculo objbelinfCte.infCTeNorm.rodo.veic = new List<belveic>(); for (int v = 0; v < obj.infCTeNorm.rodo.veic.Count; v++) { belveic veic = new belveic(); veic.RENAVAM = obj.infCTeNorm.rodo.veic[v].RENAVAM; veic.placa = obj.infCTeNorm.rodo.veic[v].placa; veic.tara = obj.infCTeNorm.rodo.veic[v].tara; veic.capKG = obj.infCTeNorm.rodo.veic[v].capKG; veic.capM3 = obj.infCTeNorm.rodo.veic[v].capM3; veic.tpProp = obj.infCTeNorm.rodo.veic[v].tpProp; veic.tpVeic = obj.infCTeNorm.rodo.veic[v].tpVeic; veic.tpRod = obj.infCTeNorm.rodo.veic[v].tpRod; veic.tpCar = obj.infCTeNorm.rodo.veic[v].tpCar; veic.UF = obj.infCTeNorm.rodo.veic[v].UF; if (obj.infCTeNorm.rodo.veic[v].prop != null) { veic.prop = new belprop(); veic.prop.CPFCNPJ = obj.infCTeNorm.rodo.veic[v].prop.CPFCNPJ; veic.prop.RNTRC = obj.infCTeNorm.rodo.veic[v].prop.RNTRC; veic.prop.xNome = obj.infCTeNorm.rodo.veic[v].prop.xNome; veic.prop.IE = obj.infCTeNorm.rodo.veic[v].prop.IE; veic.prop.UF = obj.infCTeNorm.rodo.veic[v].prop.UF; veic.prop.tpProp = obj.infCTeNorm.rodo.veic[v].prop.tpProp; } objbelinfCte.infCTeNorm.rodo.veic.Add(veic); } if (obj.infCTeNorm.rodo.moto != null) { objbelinfCte.infCTeNorm.rodo.moto = new belmoto(); objbelinfCte.infCTeNorm.rodo.moto.xNome = obj.infCTeNorm.rodo.moto.xNome; objbelinfCte.infCTeNorm.rodo.moto.CPF = obj.infCTeNorm.rodo.moto.CPF; } #endregion objList.Add(objbelinfCte); } this.objObjetosAlter = new belPopulaObjetos(objObjetos.objListaNumeroConhecimentos); this.objObjetosAlter.objListaConhecimentos = objList; this.objObjetosAlter.sFormEmiss = objObjetos.sFormEmiss; this.objObjetosAlter.sNomeArq = objObjetos.sNomeArq; this.objObjetosAlter.sPath = objObjetos.sPath; bsNotas.DataSource = this.objObjetosAlter.objListaConhecimentos; bsNotas.MoveFirst(); lblContagemNotas.Text = "1 de " + bsNotas.Count; } catch (Exception ex) { new HLPexception(ex); } }