public void PopulaDataSetXML(dsDanfe dsdanfe, string caminho, string codigo) { XmlDocument xml = new XmlDocument(); xml.Load(@caminho); int ihoraImpDanfe = (Acesso.VISUALIZA_HORA_DANFE == "True" ? 1 : 0); int idataImpDanfe = (Acesso.VISUALIZA_DATA_DANFE == "True" ? 1 : 0); PopulaDs populads = new PopulaDs(); populads.populaTagInfNFe(dsdanfe, xml, codigo, ihoraImpDanfe, idataImpDanfe); populads.populaTagIDE(dsdanfe, xml, codigo); populads.populaTagEmit(dsdanfe, xml, codigo); populads.populaTagDest(dsdanfe, xml, codigo); populads.populaTagdet(dsdanfe, xml, codigo); populads.populaTagTotal(dsdanfe, xml, codigo); populads.PopulaTagTransp(dsdanfe, xml, codigo); populads.PopulaTagCobr(dsdanfe, xml, codigo); populads.PopulaTagInfAdic(dsdanfe, xml, codigo); populads.PopulaTagExporta(dsdanfe, xml, codigo); populads.PopulaTagCompra(dsdanfe, xml, codigo); populads.PopulaTagEntrega(dsdanfe, xml, codigo); populads.PopulaTagRetirada(dsdanfe, xml, codigo); populads.PopulaTagInfProt(dsdanfe, xml, codigo); if ((Acesso.LOGOTIPO != "\r\n")) { Byte[] bimagem = Util.CarregaImagem(Acesso.LOGOTIPO); if (bimagem != null) { if (bimagem.Length <= 100000) { populads.PopulaImagem(dsdanfe, bimagem); } else { KryptonMessageBox.Show(null, "Logotipo muito Grande, Favor reduzir os para menos de 100KB" + Environment.NewLine + Environment.NewLine + "A Danfe não sairá com logotipo néssa visualização!", "A V I S O", MessageBoxButtons.OK, MessageBoxIcon.Information); } } } }
public void populaTagdet(dsDanfe dsdanfe, XmlDocument xml, string CodinfNfeId) { XmlNodeList xNdDet = xml.GetElementsByTagName("det"); XmlNodeList xNdProd = xml.GetElementsByTagName("prod"); XmlNodeList xNdImposto = xml.GetElementsByTagName("imposto"); XmlNodeList xNdICMS = xml.GetElementsByTagName("ICMS"); XmlNodeList xNdICMS00 = xml.GetElementsByTagName("ICMS00"); XmlNodeList xNdICMS10 = xml.GetElementsByTagName("ICMS10"); XmlNodeList xNdICMS20 = xml.GetElementsByTagName("ICMS20"); XmlNodeList xNdICMS30 = xml.GetElementsByTagName("ICMS30"); XmlNodeList xNdICMS40 = xml.GetElementsByTagName("ICMS40"); XmlNodeList xNdICMS51 = xml.GetElementsByTagName("ICMS51"); XmlNodeList xNdICMS60 = xml.GetElementsByTagName("ICMS60"); XmlNodeList xNdICMS70 = xml.GetElementsByTagName("ICMS70"); XmlNodeList xNdICMS90 = xml.GetElementsByTagName("ICMS90"); XmlNodeList xNdICMSPart = xml.GetElementsByTagName("ICMSPart"); XmlNodeList xNdICMSST = xml.GetElementsByTagName("ICMSST"); XmlNodeList xNdICMSSN101 = xml.GetElementsByTagName("ICMSSN101"); XmlNodeList xNdICMSSN102 = xml.GetElementsByTagName("ICMSSN102"); XmlNodeList xNdICMSSN201 = xml.GetElementsByTagName("ICMSSN201"); XmlNodeList xNdICMSSN500 = xml.GetElementsByTagName("ICMSSN500"); XmlNodeList xNdICMSSN900 = xml.GetElementsByTagName("ICMSSN900"); XmlNodeList xNdIPI = xml.GetElementsByTagName("IPI"); XmlNodeList xNdIPItrib = xml.GetElementsByTagName("IPITrib"); XmlNodeList xNdIPInt = xml.GetElementsByTagName("IPINT"); XmlNodeList xndII = xml.GetElementsByTagName("II"); XmlNodeList xndPIS = xml.GetElementsByTagName("PIS"); XmlNodeList xndPISAliq = xml.GetElementsByTagName("PISAliq"); XmlNodeList xndPISQtde = xml.GetElementsByTagName("PISQtde"); XmlNodeList xndPISNT = xml.GetElementsByTagName("PISNT"); XmlNodeList xndPISOutr = xml.GetElementsByTagName("PISOutr"); XmlNodeList xndPISST = xml.GetElementsByTagName("PISST"); XmlNodeList xndCOFINS = xml.GetElementsByTagName("COFINS"); XmlNodeList xndCOFINSaliq = xml.GetElementsByTagName("COFINSAliq"); XmlNodeList xndCOFINSqtde = xml.GetElementsByTagName("COFINSQtde"); XmlNodeList xndCOFINSnt = xml.GetElementsByTagName("COFINSNT"); XmlNodeList xndCOFINSoutr = xml.GetElementsByTagName("COFINSOutr"); XmlNodeList xndCOFINSst = xml.GetElementsByTagName("COFINSST"); XmlNodeList xndISSQN = xml.GetElementsByTagName("ISSQN"); XmlNodeList xndInfAdProd = xml.GetElementsByTagName("infAdProd"); drDet = dsdanfe.det.NewdetRow(); drProd = dsdanfe.prod.NewprodRow(); drImposto = dsdanfe.imposto.NewimpostoRow(); drICMS = dsdanfe.ICMS.NewICMSRow(); drICMS00 = dsdanfe.ICMS00.NewICMS00Row(); drICMS10 = dsdanfe.ICMS10.NewICMS10Row(); drICMS20 = dsdanfe.ICMS20.NewICMS20Row(); drICMS30 = dsdanfe.ICMS30.NewICMS30Row(); drICMS40 = dsdanfe.ICMS40.NewICMS40Row(); drICMS60 = dsdanfe.ICMS60.NewICMS60Row(); drICMS70 = dsdanfe.ICMS70.NewICMS70Row(); drICMS90 = dsdanfe.ICMS90.NewICMS90Row(); drICMSPart = dsdanfe.ICMSPart.NewICMSPartRow(); drICMSST = dsdanfe.ICMSST.NewICMSSTRow(); drICMSSN101 = dsdanfe.ICMSSN101.NewICMSSN101Row(); drICMSSN102 = dsdanfe.ICMSSN102.NewICMSSN102Row(); drICMSSN201 = dsdanfe.ICMSSN201.NewICMSSN201Row(); drICMSSN500 = dsdanfe.ICMSSN500.NewICMSSN500Row(); drICMSSN900 = dsdanfe.ICMSSN900.NewICMSSN900Row(); //Claudinei - o.s. sem - 18/12/2009 drICMS51 = dsdanfe.ICMS51.NewICMS51Row(); //Fim - Claudinei - o.s. sem - 18/12/2009 drIPI = dsdanfe.IPI.NewIPIRow(); drIPItrib = dsdanfe.IPITrib.NewIPITribRow(); drIPInt = dsdanfe.IPINT.NewIPINTRow(); drII = dsdanfe.II.NewIIRow(); drPIS = dsdanfe.PIS.NewPISRow(); drPisAliq = dsdanfe.PISAliq.NewPISAliqRow(); drPisQtde = dsdanfe.PISQtde.NewPISQtdeRow(); drPisNT = dsdanfe.PISNT.NewPISNTRow(); drPisOutr = dsdanfe.PISOutr.NewPISOutrRow(); drPisST = dsdanfe.PISST.NewPISSTRow(); drCofins = dsdanfe.COFINS.NewCOFINSRow(); drCofinsAliq = dsdanfe.COFINSAliq.NewCOFINSAliqRow(); drCofinsNT = dsdanfe.COFINSNT.NewCOFINSNTRow(); drCofinsOutr = dsdanfe.COFINSOutr.NewCOFINSOutrRow(); drCofinsST = dsdanfe.COFINSST.NewCOFINSSTRow(); drISSQN = dsdanfe.ISSQN.NewISSQNRow(); drInfAdProd = dsdanfe.infAdProd.NewinfAdProdRow(); // Diego - OS. 24144 - 19/02/2010 drRetira = dsdanfe.retirada.NewretiradaRow(); // Diego - OS. 24144 - 19/02/2010 - FIM // Diego - OS_24302 - 01/04/2010 int iPK_itens_notaAnterior = dsdanfe.det.Count; // Diego - OS_24302 - 01/04/2010 Fim if (xNdProd.Count > 0) { int i = 0; int detID = 0; while (i < xNdProd.Count) { if (dsdanfe.det.Count > 0) { detID = dsdanfe.det.Count + 1; } else { detID = i + 1; } drDet = dsdanfe.det.NewdetRow(); populaDadosDet(detID, CodinfNfeId); dsdanfe.det.AdddetRow(drDet); i++; } } if (xNdProd.Count > 0) { for (int i = 0; i < xNdProd.Count; i++) { int prodId = 0; if (dsdanfe.prod.Count > 0) { prodId = dsdanfe.prod.Count + 1; } else { prodId = i + 1; } // qtde de nodes iqtdeComercial = Convert.ToInt16(LeRegWin.LeRegConfig("QtdeCasasProdutos")); for (int j = 0; j < xNdProd[i].ChildNodes.Count; j++) { populaDadosProd(xNdProd[i].ChildNodes[j].LocalName, xNdProd[i].ChildNodes[j].InnerText, prodId.ToString()); } dsdanfe.prod.AddprodRow(drProd); drProd = dsdanfe.prod.NewprodRow(); } } if (xNdImposto.Count > 0) // POPULA TABLE IMPOSTO - ICMS - PIS - COFINS { int i = 0; int impostoID = 0; while (i < xNdImposto.Count) { impostoID = dsdanfe.imposto.Count + 1; drImposto = dsdanfe.imposto.NewimpostoRow(); drICMS = dsdanfe.ICMS.NewICMSRow(); drPIS = dsdanfe.PIS.NewPISRow(); drCofins = dsdanfe.COFINS.NewCOFINSRow(); populaDadosImposto_ICMS_PIS_COFINS(impostoID); dsdanfe.ICMS.AddICMSRow(drICMS); dsdanfe.imposto.AddimpostoRow(drImposto); dsdanfe.PIS.AddPISRow(drPIS); dsdanfe.COFINS.AddCOFINSRow(drCofins); i++; } } int i00 = 0; int i10 = 0; int i20 = 0; int i30 = 0; int i40 = 0; int i51 = 0; int i60 = 0; int i70 = 0; int i90 = 0; int iPart = 0; int iST = 0; int i101 = 0; int i102 = 0; int i201 = 0; int i500 = 0; int i900 = 0; for (int i = 0; i < xNdICMS.Count; i++) { // Diego - OS_24302 - 01/04/2010 iPK_itens_notaAnterior++; switch (xNdICMS[i].FirstChild.Name) { case "ICMS00": for (int j = 0; j < xNdICMS00[i00].ChildNodes.Count; j++) { populaDadosICMS00(xNdICMS00[i00].ChildNodes[j].LocalName, xNdICMS00[i00].ChildNodes[j].InnerText, (iPK_itens_notaAnterior).ToString()); } dsdanfe.ICMS00.AddICMS00Row(drICMS00); drICMS00 = dsdanfe.ICMS00.NewICMS00Row(); i00++; break; case "ICMS10": for (int j = 0; j < xNdICMS10[i10].ChildNodes.Count; j++) { populaDadosICMS10(xNdICMS10[i10].ChildNodes[j].LocalName, xNdICMS10[i10].ChildNodes[j].InnerText, (iPK_itens_notaAnterior).ToString()); } dsdanfe.ICMS10.AddICMS10Row(drICMS10); drICMS10 = dsdanfe.ICMS10.NewICMS10Row(); i10++; break; case "ICMS20": for (int j = 0; j < xNdICMS20[i20].ChildNodes.Count; j++) { populaDadosICMS20(xNdICMS20[i20].ChildNodes[j].LocalName, xNdICMS20[i20].ChildNodes[j].InnerText, (iPK_itens_notaAnterior).ToString()); } dsdanfe.ICMS20.AddICMS20Row(drICMS20); drICMS20 = dsdanfe.ICMS20.NewICMS20Row(); i20++; break; case "ICMS30": for (int j = 0; j < xNdICMS30[i30].ChildNodes.Count; j++) { populaDadosICMS30(xNdICMS30[i30].ChildNodes[j].LocalName, xNdICMS30[i30].ChildNodes[j].InnerText, (iPK_itens_notaAnterior).ToString()); } dsdanfe.ICMS30.AddICMS30Row(drICMS30); drICMS30 = dsdanfe.ICMS30.NewICMS30Row(); i30++; break; case "ICMS40": for (int j = 0; j < xNdICMS40[i40].ChildNodes.Count; j++) { populaDadosICMS40(xNdICMS40[i40].ChildNodes[j].LocalName, xNdICMS40[i40].ChildNodes[j].InnerText, (iPK_itens_notaAnterior).ToString()); } dsdanfe.ICMS40.AddICMS40Row(drICMS40); drICMS40 = dsdanfe.ICMS40.NewICMS40Row(); i40++; break; case "ICMS51": for (int j = 0; j < xNdICMS51[i51].ChildNodes.Count; j++) { populaDadosICMS51(xNdICMS51[i51].ChildNodes[j].LocalName, xNdICMS51[i51].ChildNodes[j].InnerText, (iPK_itens_notaAnterior).ToString()); } dsdanfe.ICMS51.AddICMS51Row(drICMS51); drICMS51 = dsdanfe.ICMS51.NewICMS51Row(); i51++; break; case "ICMS60": for (int j = 0; j < xNdICMS60[i60].ChildNodes.Count; j++) { populaDadosICMS60(xNdICMS60[i60].ChildNodes[j].LocalName, xNdICMS60[i60].ChildNodes[j].InnerText, (iPK_itens_notaAnterior).ToString()); } dsdanfe.ICMS60.AddICMS60Row(drICMS60); drICMS60 = dsdanfe.ICMS60.NewICMS60Row(); i60++; break; case "ICMS70": for (int j = 0; j < xNdICMS70[i70].ChildNodes.Count; j++) { populaDadosICMS70(xNdICMS70[i70].ChildNodes[j].LocalName, xNdICMS70[i70].ChildNodes[j].InnerText, (iPK_itens_notaAnterior).ToString()); } dsdanfe.ICMS70.AddICMS70Row(drICMS70); drICMS70 = dsdanfe.ICMS70.NewICMS70Row(); i70++; break; case "ICMS90": for (int j = 0; j < xNdICMS90[i90].ChildNodes.Count; j++) { populaDadosICMS90(xNdICMS90[i90].ChildNodes[j].LocalName, xNdICMS90[i90].ChildNodes[j].InnerText, (iPK_itens_notaAnterior).ToString()); } dsdanfe.ICMS90.AddICMS90Row(drICMS90); drICMS90 = dsdanfe.ICMS90.NewICMS90Row(); i90++; break; case "ICMSPart": for (int j = 0; j < xNdICMSPart[iPart].ChildNodes.Count; j++) { populaDadosICMSPart(xNdICMSPart[iPart].ChildNodes[j].LocalName, xNdICMSPart[iPart].ChildNodes[j].InnerText, (iPK_itens_notaAnterior).ToString()); } dsdanfe.ICMSPart.AddICMSPartRow(drICMSPart); drICMSPart = dsdanfe.ICMSPart.NewICMSPartRow(); iPart++; break; case "ICMSST": for (int j = 0; j < xNdICMSST[iST].ChildNodes.Count; j++) { populaDadosICMSST(xNdICMSST[iST].ChildNodes[j].LocalName, xNdICMSST[iST].ChildNodes[j].InnerText, (iPK_itens_notaAnterior).ToString()); } dsdanfe.ICMSST.AddICMSSTRow(drICMSST); drICMSST = dsdanfe.ICMSST.NewICMSSTRow(); iST++; break; case "ICMSSN101": for (int j = 0; j < xNdICMSSN101[i101].ChildNodes.Count; j++) { populaDadosICMSSN101(xNdICMSSN101[i101].ChildNodes[j].LocalName, xNdICMSSN101[i101].ChildNodes[j].InnerText, (iPK_itens_notaAnterior).ToString()); } dsdanfe.ICMSSN101.AddICMSSN101Row(drICMSSN101); drICMSSN101 = dsdanfe.ICMSSN101.NewICMSSN101Row(); i101++; break; case "ICMSSN102": for (int j = 0; j < xNdICMSSN102[i102].ChildNodes.Count; j++) { populaDadosICMSSN102(xNdICMSSN102[i102].ChildNodes[j].LocalName, xNdICMSSN102[i102].ChildNodes[j].InnerText, (iPK_itens_notaAnterior).ToString()); } dsdanfe.ICMSSN102.AddICMSSN102Row(drICMSSN102); drICMSSN102 = dsdanfe.ICMSSN102.NewICMSSN102Row(); i102++; break; case "ICMSSN201": for (int j = 0; j < xNdICMSSN201[i201].ChildNodes.Count; j++) { populaDadosICMSSN201(xNdICMSSN201[i201].ChildNodes[j].LocalName, xNdICMSSN201[i201].ChildNodes[j].InnerText, (iPK_itens_notaAnterior).ToString()); } dsdanfe.ICMSSN201.AddICMSSN201Row(drICMSSN201); drICMSSN201 = dsdanfe.ICMSSN201.NewICMSSN201Row(); i201++; break; case "ICMSSN500": for (int j = 0; j < xNdICMSSN500[i500].ChildNodes.Count; j++) { populaDadosICMSSN500(xNdICMSSN500[i500].ChildNodes[j].LocalName, xNdICMSSN500[i500].ChildNodes[j].InnerText, (iPK_itens_notaAnterior).ToString()); } dsdanfe.ICMSSN500.AddICMSSN500Row(drICMSSN500); drICMSSN500 = dsdanfe.ICMSSN500.NewICMSSN500Row(); i500++; break; case "ICMSSN900": for (int j = 0; j < xNdICMSSN900[i900].ChildNodes.Count; j++) { populaDadosICMSSN900(xNdICMSSN900[i900].ChildNodes[j].LocalName, xNdICMSSN900[i900].ChildNodes[j].InnerText, (iPK_itens_notaAnterior).ToString()); } dsdanfe.ICMSSN900.AddICMSSN900Row(drICMSSN900); drICMSSN900 = dsdanfe.ICMSSN900.NewICMSSN900Row(); i900++; break; } // Diego - OS_24302 - 01/04/2010 - Fim if (xNdIPI.Count > 0) { for (int j = 0; j < xNdIPI[i].ChildNodes.Count; j++) { populaDadosIPI(xNdIPI[i].ChildNodes[j].LocalName, xNdIPI[i].ChildNodes[j].InnerText, (iPK_itens_notaAnterior), (iPK_itens_notaAnterior).ToString()); } dsdanfe.IPI.AddIPIRow(drIPI); drIPI = dsdanfe.IPI.NewIPIRow(); } //Claudinei - o.s. sem - 18/02/2010 // Diego - Sem O.S - 18/02/2010 for (int x = 0; x < xNdIPI[i].ChildNodes.Count; x++) { if (xNdIPI[i].ChildNodes[x].Name.Equals("IPITrib")) { if (xNdIPItrib[icountxNdIPI] != null) { for (int j = 0; j < xNdIPItrib[icountxNdIPI].ChildNodes.Count; j++) { populaDadosIPItrib(xNdIPItrib[icountxNdIPI].ChildNodes[j].LocalName, xNdIPItrib[icountxNdIPI].ChildNodes[j].InnerText, (iPK_itens_notaAnterior).ToString()); } icountxNdIPI++; dsdanfe.IPITrib.AddIPITribRow(drIPItrib); drIPItrib = dsdanfe.IPITrib.NewIPITribRow(); } } } for (int x = 0; x < xNdIPI[i].ChildNodes.Count; x++) { if (xNdIPI[i].ChildNodes[x].Name.Equals("IPINT")) { if (xNdIPInt[icontxNdIPInt] != null) { for (int j = 0; j < xNdIPInt[icontxNdIPInt].ChildNodes.Count; j++) { populaDadosIPInt(xNdIPInt[icontxNdIPInt].ChildNodes[j].LocalName, xNdIPInt[icontxNdIPInt].ChildNodes[j].InnerText, (iPK_itens_notaAnterior).ToString()); } icontxNdIPInt++; dsdanfe.IPINT.AddIPINTRow(drIPInt); drIPInt = dsdanfe.IPINT.NewIPINTRow(); } } } // Diego - Sem O.S - 18/02/2010 - fIM if (xndII.Count > 0) { for (int j = 0; j < xndII[i].ChildNodes.Count; j++) { populaDadosII(xndII[i].ChildNodes[j].LocalName, xndII[i].ChildNodes[j].InnerText, (iPK_itens_notaAnterior).ToString()); } dsdanfe.II.AddIIRow(drII); drII = dsdanfe.II.NewIIRow(); } if (xndPISAliq.Count > 0) { if (xndPISAliq[i] != null) { for (int j = 0; j < xndPISAliq[i].ChildNodes.Count; j++) //Claudinei - sem - 20/01/2010 { populaDadosPisAliq(xndPISAliq[i].ChildNodes[j].LocalName, xndPISAliq[i].ChildNodes[j].InnerText, (iPK_itens_notaAnterior).ToString()); } dsdanfe.PISAliq.AddPISAliqRow(drPisAliq); drPisAliq = dsdanfe.PISAliq.NewPISAliqRow(); } } if (xndPISQtde.Count > 0) { for (int j = 0; j < xndPISQtde[i].ChildNodes.Count; j++) //Claudinei - sem - 20/01/2010 { populaDadosPisQtde(xndPISQtde[i].ChildNodes[j].LocalName, xndPISQtde[i].ChildNodes[j].InnerText, (iPK_itens_notaAnterior).ToString()); } dsdanfe.PISQtde.AddPISQtdeRow(drPisQtde); drPisQtde = dsdanfe.PISQtde.NewPISQtdeRow(); } if (xndPISNT.Count > 0) { if (xndPISNT[i] != null) { for (int j = 0; j < xndPISNT[i].ChildNodes.Count; j++) { populaDadosPisNT(xndPISNT[i].ChildNodes[j].LocalName, xndPISNT[i].ChildNodes[j].InnerText, (iPK_itens_notaAnterior).ToString()); } dsdanfe.PISNT.AddPISNTRow(drPisNT); drPisNT = dsdanfe.PISNT.NewPISNTRow(); } } if (xndPISOutr[i] != null) { if (xndPISOutr[i].ChildNodes.Count > 0) { for (int j = 0; j < xndPISOutr[i].ChildNodes.Count; j++) { populaDadosPisOut(xndPISOutr[i].ChildNodes[j].LocalName, xndPISOutr[i].ChildNodes[j].InnerText, (iPK_itens_notaAnterior).ToString()); } dsdanfe.PISOutr.AddPISOutrRow(drPisOutr); drPisOutr = dsdanfe.PISOutr.NewPISOutrRow(); } } if (xndPISST.Count > 0) { for (int j = 0; j < xndPISST[i].ChildNodes.Count; j++) { populaDadosPisST(xndPISST[i].ChildNodes[j].LocalName, xndPISST[i].ChildNodes[j].InnerText, (iPK_itens_notaAnterior).ToString()); } dsdanfe.PISST.AddPISSTRow(drPisST); drPisST = dsdanfe.PISST.NewPISSTRow(); } if (xndCOFINSaliq.Count > 0) { if (xndCOFINSaliq[i] != null) { for (int j = 0; j < xndCOFINSaliq[i].ChildNodes.Count; j++) { populaDadosCofinsAliq(xndCOFINSaliq[i].ChildNodes[j].LocalName, xndCOFINSaliq[i].ChildNodes[j].InnerText, (iPK_itens_notaAnterior).ToString()); } dsdanfe.COFINSAliq.AddCOFINSAliqRow(drCofinsAliq); drCofinsAliq = dsdanfe.COFINSAliq.NewCOFINSAliqRow(); } } if (xndCOFINSqtde.Count > 0) { for (int j = 0; j < xndCOFINSqtde[i].ChildNodes.Count; j++) { populaDadosCofinsQtde(xndCOFINSqtde[i].ChildNodes[j].LocalName, xndCOFINSqtde[i].ChildNodes[j].InnerText, (iPK_itens_notaAnterior).ToString()); } dsdanfe.COFINSQtde.AddCOFINSQtdeRow(drCofinsQtde); drCofinsQtde = dsdanfe.COFINSQtde.NewCOFINSQtdeRow(); } if (xndCOFINSnt.Count > 0) { if (xndCOFINSnt[i] != null) { for (int j = 0; j < xndCOFINSnt[i].ChildNodes.Count; j++) { populaDadosCofinsNT(xndCOFINSnt[i].ChildNodes[j].LocalName, xndCOFINSnt[i].ChildNodes[j].InnerText, (iPK_itens_notaAnterior).ToString()); } dsdanfe.COFINSNT.AddCOFINSNTRow(drCofinsNT); drCofinsNT = dsdanfe.COFINSNT.NewCOFINSNTRow(); } } if (xndCOFINSoutr[i] != null) { for (int j = 0; j < xndCOFINSoutr[i].ChildNodes.Count; j++) { populaDadosCofinsOutr(xndCOFINSoutr[i].ChildNodes[j].LocalName, xndCOFINSoutr[i].ChildNodes[j].InnerText, (iPK_itens_notaAnterior).ToString()); } dsdanfe.COFINSOutr.AddCOFINSOutrRow(drCofinsOutr); drCofinsOutr = dsdanfe.COFINSOutr.NewCOFINSOutrRow(); } if (xndCOFINSst.Count > 0) { for (int j = 0; j < xndCOFINSst[i].ChildNodes.Count; j++) { populaDadosCofinsST(xndCOFINSst[i].ChildNodes[j].LocalName, xndCOFINSst[i].ChildNodes[j].InnerText, (iPK_itens_notaAnterior).ToString()); } dsdanfe.COFINSST.AddCOFINSSTRow(drCofinsST); drCofinsST = dsdanfe.COFINSST.NewCOFINSSTRow(); } if (xndISSQN.Count > 0) { for (int j = 0; j < xndISSQN[i].ChildNodes.Count; j++) { populaDadosISSQN(xndISSQN[i].ChildNodes[j].LocalName, xndISSQN[i].ChildNodes[j].InnerText, (iPK_itens_notaAnterior).ToString()); } dsdanfe.ISSQN.AddISSQNRow(drISSQN); drISSQN = dsdanfe.ISSQN.NewISSQNRow(); } //comentar //Diego - o.s. sem - 09/02/2010 for (int x = 0; x < xNdDet[i].ChildNodes.Count; x++) { if (xNdDet[i].ChildNodes[x].Name.Equals("infAdProd")) { populaDadosInfAdProd(xNdDet[i].ChildNodes[x].InnerText, (iPK_itens_notaAnterior).ToString()); } } dsdanfe.infAdProd.AddinfAdProdRow(drInfAdProd); drInfAdProd = dsdanfe.infAdProd.NewinfAdProdRow(); } }
public void populaTagDest(dsDanfe dsdanfe, XmlDocument xml, string CodinfNfeId) { XmlNodeList xNenderDest = xml.GetElementsByTagName("enderDest"); XmlNodeList xNdest = xml.GetElementsByTagName("dest"); drEnderDest = dsdanfe.enderDest.NewenderDestRow(); drDest = dsdanfe.dest.NewdestRow(); if (xNenderDest.Count > 0) { for (int i = 0; i < xNenderDest.Count; i++) { int destId = dsdanfe.emit.Count; // qtde de nodes for (int j = 0; j < xNenderDest[i].ChildNodes.Count; j++) { populaDadosEnderDest(xNenderDest[i].ChildNodes[j].LocalName, xNenderDest[i].ChildNodes[j].InnerText, destId.ToString()); } dsdanfe.enderDest.AddenderDestRow(drEnderDest); drEnderDest = dsdanfe.enderDest.NewenderDestRow(); } } if (xNdest.Count > 0) { for (int i = 0; i < xNdest.Count; i++) { int destID = 0; if (dsdanfe.dest.Count > 0) { destID = dsdanfe.dest.Count + 1; } else { destID = i + 1; } // qtde de nodes for (int j = 0; j < xNdest[i].ChildNodes.Count; j++) { populaDadosDest(xNdest[i].ChildNodes[j].LocalName, xNdest[i].ChildNodes[j].InnerText, destID.ToString(), CodinfNfeId); } dsdanfe.dest.AdddestRow(drDest); drDest = dsdanfe.dest.NewdestRow(); } } }
public void populaTagEmit(dsDanfe dsdanfe, XmlDocument xml, string CodinfNfeId) { XmlNodeList xNdenderEmit = xml.GetElementsByTagName("enderEmit"); XmlNodeList xNdEmit = xml.GetElementsByTagName("emit"); drenderEmit = dsdanfe.enderEmit.NewenderEmitRow(); dremit = dsdanfe.emit.NewemitRow(); if (xNdenderEmit.Count > 0) { for (int i = 0; i < xNdenderEmit.Count; i++) { int emitID = dsdanfe.emit.Count + 1; // qtde de nodes for (int j = 0; j < xNdenderEmit[i].ChildNodes.Count; j++) { populaDadosEndeEmit(xNdenderEmit[i].ChildNodes[j].LocalName, xNdenderEmit[i].ChildNodes[j].InnerText, emitID.ToString()); } dsdanfe.enderEmit.AddenderEmitRow(drenderEmit); drenderEmit = dsdanfe.enderEmit.NewenderEmitRow(); } } if (xNdEmit.Count > 0) { // verifico qtas tags existem do mesmo tipo dentro do XML for (int i = 0; i < xNdEmit.Count; i++) { int emitID = 0; if (dsdanfe.emit.Count > 0) { emitID = dsdanfe.emit.Count + 1; } else { emitID = i + 1; } // qtde de nodes for (int j = 0; j < xNdEmit[i].ChildNodes.Count; j++) { populaDadosEmit(xNdEmit[i].ChildNodes[j].LocalName, xNdEmit[i].ChildNodes[j].InnerText, emitID.ToString(), CodinfNfeId); } dsdanfe.emit.AddemitRow(dremit); dremit = dsdanfe.emit.NewemitRow(); } } }
public void populaTagIDE(dsDanfe dsdanfe, XmlDocument xml, string CodinfNfeId) { XmlNodeList xNdrefNF = xml.GetElementsByTagName("refNF"); XmlNodeList xNdNFref = xml.GetElementsByTagName("NFref"); XmlNodeList xNdIde = xml.GetElementsByTagName("ide"); drrefNF = dsdanfe.refNF.NewrefNFRow(); drNFref = dsdanfe.NFref.NewNFrefRow(); drIde = dsdanfe.ide.NewideRow(); // Verficação se as tags estão criadas. if (xNdrefNF.Count > 0) { //Danner - o.s. 24184 - 01/03/2010 //for (int i = 0; i < xNdrefNF.Count; i++) //{ // int NFrefId = i + 1; // for (int j = 0; j < xNdrefNF[i].ChildNodes.Count; j++) // { // populaDadosRefNF(xNdrefNF[i].ChildNodes[j].LocalName, xNdrefNF[i].ChildNodes[j].InnerText, NFrefId.ToString()); // } // dsdanfe.refNF.AddrefNFRow(drrefNF); // drrefNF = dsdanfe.refNF.NewrefNFRow(); //} //Fim - Danner - o.s. 24184 - 01/03/2010 } if (xNdNFref.Count > 0) { //Danner - o.s. 24184 - 01/03/2010 //for (int i = 0; i < xNdNFref.Count; i++) //{ // int ideID = 0; // int NFrefId = dsdanfe.NFref.Count; // if (dsdanfe.NFref.Count > 0) // { // ideID = dsdanfe.ide.Count + 1; // } // else // { // ideID = i + 1; // } // int Id = i + 1; // Chave primária e estrangeira // for (int j = 0; j < xNdNFref[i].ChildNodes.Count; j++) // { // populaDadosRefNF(xNdNFref[i].ChildNodes[j].LocalName, xNdNFref[i].ChildNodes[j].InnerText, Id.ToString()); // } // dsdanfe.NFref.AddNFrefRow(drNFref); // drNFref = dsdanfe.NFref.NewNFrefRow(); //} //Fim - Danner - o.s. 24184 - 01/03/2010 } if (xNdIde.Count > 0) { // verifico qtas tags existem do mesmo tipo dentro do XML for (int i = 0; i < xNdIde.Count; i++) { int ideID = 0; if (dsdanfe.ide.Count > 0) { ideID = dsdanfe.ide.Count + 1; } else { ideID = i + 1; } // qtde de nodes for (int j = 0; j < xNdIde[i].ChildNodes.Count; j++) { populaDadosIDE(xNdIde[i].ChildNodes[j].LocalName, xNdIde[i].ChildNodes[j].InnerText, ideID.ToString(), CodinfNfeId); } dsdanfe.ide.AddideRow(drIde); drIde = dsdanfe.ide.NewideRow(); } } }
// Diego - OS_23723 - 11/06/2009 public void PopulaImagem(dsDanfe dsdanfe, Byte[] imagem) { drLogo = dsdanfe.Logo.NewLogoRow(); drLogo.Imagem = imagem; dsdanfe.Logo.AddLogoRow(drLogo); }
public void PopulaTagInfProt(dsDanfe dsdanfe, XmlDocument xml, string CodinfNfeId) { XmlNodeList xNdInfProt = xml.GetElementsByTagName("infProt"); drInfProt = dsdanfe.infProt.NewinfProtRow(); if (xNdInfProt.Count > 0) { for (int i = 0; i < xNdInfProt.Count; i++) { int InfNFeId = i + 1; // qtde de nodes for (int j = 0; j < xNdInfProt[i].ChildNodes.Count; j++) { populaDadosInfProt(xNdInfProt[i].ChildNodes[j].LocalName, xNdInfProt[i].ChildNodes[j].InnerText, InfNFeId.ToString(), CodinfNfeId); } dsdanfe.infProt.AddinfProtRow(drInfProt); drInfProt = dsdanfe.infProt.NewinfProtRow(); } } }
public void PopulaTagEntrega(dsDanfe dsdanfe, XmlDocument xml, string CodinfNfeId) { XmlNodeList xNdEntrega = xml.GetElementsByTagName("entrega"); if (xNdEntrega.Count > 0) { for (int i = 0; i < xNdEntrega.Count; i++) { int InfNFeId = i + 1; // qtde de nodes for (int j = 0; j < xNdEntrega[i].ChildNodes.Count; j++) { populaDadosEntrega(xNdEntrega[i].ChildNodes[j].LocalName, xNdEntrega[i].ChildNodes[j].InnerText, InfNFeId.ToString(), CodinfNfeId); } dsdanfe.entrega.AddentregaRow(drEntrega); drEntrega = dsdanfe.entrega.NewentregaRow(); } } }
public void PopulaTagInfAdic(dsDanfe dsdanfe, XmlDocument xml, string CodinfNfeId) { XmlNodeList xndInfAdic = xml.GetElementsByTagName("infAdic"); XmlNodeList xndObsCont = xml.GetElementsByTagName("obsCont"); XmlNodeList xndObsFisco = xml.GetElementsByTagName("obsFisco"); XmlNodeList xndprocRef = xml.GetElementsByTagName("procRef"); drInfAdic = dsdanfe.infAdic.NewinfAdicRow(); drObsCont = dsdanfe.obsCont.NewobsContRow(); drFat = dsdanfe.fat.NewfatRow(); drDup = dsdanfe.dup.NewdupRow(); if (xndInfAdic.Count > 0) { for (int i = 0; i < xndInfAdic.Count; i++) { int infNFe = dsdanfe.infAdic.Count; int infAdicID = 0; if (dsdanfe.infAdic.Count > 0) { infAdicID = dsdanfe.infAdic.Count + 1; } else { infAdicID = i + 1; } // qtde de nodes for (int j = 0; j < xndInfAdic[i].ChildNodes.Count; j++) { populaDadosInfAdic(xndInfAdic[i].ChildNodes[j].LocalName, xndInfAdic[i].ChildNodes[j].InnerText, infAdicID.ToString(), CodinfNfeId); } if (xndInfAdic[i].ChildNodes.Count > 0) { dsdanfe.infAdic.AddinfAdicRow(drInfAdic); drInfAdic = dsdanfe.infAdic.NewinfAdicRow(); } } } if (xndObsCont.Count > 0) { for (int i = 0; i < xndObsCont.Count; i++) { int infAdicID = i + 1; // qtde de nodes for (int j = 0; j < xndObsCont[i].ChildNodes.Count; j++) { populaDadosObsCont(xndObsCont[i].ChildNodes[j].LocalName, xndObsCont[i].ChildNodes[j].InnerText, infAdicID.ToString()); } dsdanfe.obsCont.AddobsContRow(drObsCont); drObsCont = dsdanfe.obsCont.NewobsContRow(); } } if (xndObsFisco.Count > 0) { for (int i = 0; i < xndObsFisco.Count; i++) { int infAdicID = i + 1; // qtde de nodes for (int j = 0; j < xndObsFisco[i].ChildNodes.Count; j++) { populaDadosObsFisco(xndObsFisco[i].ChildNodes[j].LocalName, xndObsFisco[i].ChildNodes[j].InnerText, infAdicID.ToString()); } dsdanfe.obsFisco.AddobsFiscoRow(drObsFisco); drObsFisco = dsdanfe.obsFisco.NewobsFiscoRow(); } } if (xndprocRef.Count > 0) { for (int i = 0; i < xndprocRef.Count; i++) { int infAdicID = i + 1; // qtde de nodes for (int j = 0; j < xndprocRef[i].ChildNodes.Count; j++) { populaDadosProcRef(xndprocRef[i].ChildNodes[j].LocalName, xndprocRef[i].ChildNodes[j].InnerText, infAdicID.ToString()); } dsdanfe.procRef.AddprocRefRow(drProcRef); drProcRef = dsdanfe.procRef.NewprocRefRow(); } } }
public void PopulaTagCobr(dsDanfe dsdanfe, XmlDocument xml, string CodinfNfeId) { XmlNodeList xndCobr = xml.GetElementsByTagName("cobr"); XmlNodeList xndFat = xml.GetElementsByTagName("fat"); XmlNodeList xndDup = xml.GetElementsByTagName("dup"); drCobr = dsdanfe.cobr.NewcobrRow(); drFat = dsdanfe.fat.NewfatRow(); drDup = dsdanfe.dup.NewdupRow(); if (xndCobr.Count > 0) // POPULA TABLE COBR { int i = 0; int cobr = 0; while (i < xndCobr.Count) { if (dsdanfe.cobr.Count > 0) { cobr = dsdanfe.cobr.Count + 1; } else { cobr = i + 1; } drCobr = dsdanfe.cobr.NewcobrRow(); populaDadosCobr(cobr.ToString(), CodinfNfeId); dsdanfe.cobr.AddcobrRow(drCobr); i++; } } if (xndFat.Count > 0) { for (int i = 0; i < xndFat.Count; i++) { int cobrID = dsdanfe.cobr.Count; // qtde de nodes for (int j = 0; j < xndFat[i].ChildNodes.Count; j++) { populaDadosFat(xndFat[i].ChildNodes[j].LocalName, xndFat[i].ChildNodes[j].InnerText, cobrID.ToString()); } dsdanfe.fat.AddfatRow(drFat); drFat = dsdanfe.fat.NewfatRow(); } } if (xndDup.Count > 0) { for (int i = 0; i < xndDup.Count; i++) { int cobrID = dsdanfe.cobr.Count; // qtde de nodes for (int j = 0; j < xndDup[i].ChildNodes.Count; j++) { populaDadosDup(xndDup[i].ChildNodes[j].LocalName, xndDup[i].ChildNodes[j].InnerText, cobrID.ToString()); } dsdanfe.dup.AdddupRow(drDup); drDup = dsdanfe.dup.NewdupRow(); } } }
public void PopulaTagTransp(dsDanfe dsdanfe, XmlDocument xml, string CodinfNfeId) { XmlNodeList xndTransp = xml.GetElementsByTagName("transp"); XmlNodeList xndTransportadora = xml.GetElementsByTagName("transporta"); XmlNodeList xndRetTransp = xml.GetElementsByTagName("retTransp"); XmlNodeList xndVeicTransp = xml.GetElementsByTagName("veicTransp"); XmlNodeList xndReboque = xml.GetElementsByTagName("reboque "); XmlNodeList xndVol = xml.GetElementsByTagName("vol"); XmlNodeList xndLacres = xml.GetElementsByTagName("lacres"); drTransp = dsdanfe.transp.NewtranspRow(); drTransportadora = dsdanfe.transporta.NewtransportaRow(); drRetTransp = dsdanfe.retTransp.NewretTranspRow(); drVeicTransp = dsdanfe.veicTransp.NewveicTranspRow(); drReboque = dsdanfe.reboque.NewreboqueRow(); drVol = dsdanfe.vol.NewvolRow(); drLacres = dsdanfe.lacres.NewlacresRow(); if (xndTransp.Count > 0) { for (int i = 0; i < xndTransp.Count; i++) { int transpID = 0; if (dsdanfe.transp.Count > 0) { transpID = dsdanfe.transp.Count + 1; } else { transpID = i + 1; } // qtde de nodes for (int j = 0; j < xndTransp[i].ChildNodes.Count; j++) { populaDadostransp(xndTransp[i].ChildNodes[j].LocalName, xndTransp[i].ChildNodes[j].InnerText, transpID.ToString(), CodinfNfeId); } dsdanfe.transp.AddtranspRow(drTransp); drTransp = dsdanfe.transp.NewtranspRow(); } } if (xndTransportadora.Count > 0) { for (int i = 0; i < xndTransportadora.Count; i++) { int transpID = dsdanfe.transp.Count; // qtde de nodes for (int j = 0; j < xndTransportadora[i].ChildNodes.Count; j++) { populaDadosTransportadora(xndTransportadora[i].ChildNodes[j].LocalName, xndTransportadora[i].ChildNodes[j].InnerText, transpID.ToString()); } dsdanfe.transporta.AddtransportaRow(drTransportadora); drTransportadora = dsdanfe.transporta.NewtransportaRow(); } } if (xndRetTransp.Count > 0) { for (int i = 0; i < xndRetTransp.Count; i++) { int transpID = i + 1; // qtde de nodes for (int j = 0; j < xndRetTransp[i].ChildNodes.Count; j++) { populaDadosretTransp(xndRetTransp[i].ChildNodes[j].LocalName, xndRetTransp[i].ChildNodes[j].InnerText, transpID.ToString()); } dsdanfe.retTransp.AddretTranspRow(drRetTransp); drRetTransp = dsdanfe.retTransp.NewretTranspRow(); } } if (xndVeicTransp.Count > 0) { for (int i = 0; i < xndVeicTransp.Count; i++) { int transpID = i + 1; // qtde de nodes for (int j = 0; j < xndVeicTransp[i].ChildNodes.Count; j++) { populaDadosVeicTransp(xndVeicTransp[i].ChildNodes[j].LocalName, xndVeicTransp[i].ChildNodes[j].InnerText, transpID.ToString()); } dsdanfe.veicTransp.AddveicTranspRow(drVeicTransp); drVeicTransp = dsdanfe.veicTransp.NewveicTranspRow(); } } if (xndReboque.Count > 0) { for (int i = 0; i < xndReboque.Count; i++) { int transpID = i + 1; // qtde de nodes for (int j = 0; j < xndReboque[i].ChildNodes.Count; j++) { populaDadosReboque(xndReboque[i].ChildNodes[j].LocalName, xndReboque[i].ChildNodes[j].InnerText, transpID.ToString()); } dsdanfe.reboque.AddreboqueRow(drReboque); drReboque = dsdanfe.reboque.NewreboqueRow(); } } if (xndVol.Count > 0) { for (int i = 0; i < xndVol.Count; i++) { int transpID = dsdanfe.transp.Count; int volID = 0; if (dsdanfe.vol.Count > 0) { volID = dsdanfe.vol.Count + 1; } else { volID = i + 1; } // qtde de nodes for (int j = 0; j < xndVol[i].ChildNodes.Count; j++) { populaDadosVol(xndVol[i].ChildNodes[j].LocalName, xndVol[i].ChildNodes[j].InnerText, transpID.ToString(), volID.ToString()); } dsdanfe.vol.AddvolRow(drVol); drVol = dsdanfe.vol.NewvolRow(); } } if (xndLacres.Count > 0) { for (int i = 0; i < xndLacres.Count; i++) { int volID = i + 1; // qtde de nodes for (int j = 0; j < xndLacres[i].ChildNodes.Count; j++) { populaDadosLacres(xndLacres[i].ChildNodes[j].LocalName, xndLacres[i].ChildNodes[j].InnerText, volID.ToString()); } dsdanfe.lacres.AddlacresRow(drLacres); drLacres = dsdanfe.lacres.NewlacresRow(); } } }
public void populaTagTotal(dsDanfe dsdanfe, XmlDocument xml, string CodinfNfeId) { XmlNodeList xndtotal = xml.GetElementsByTagName("total"); XmlNodeList xndICMStot = xml.GetElementsByTagName("ICMSTot"); XmlNodeList xndISSQNtot = xml.GetElementsByTagName("ISSQNtot"); XmlNodeList xndretTrib = xml.GetElementsByTagName("retTrib"); drTotal = dsdanfe.total.NewtotalRow(); drICMStot = dsdanfe.ICMSTot.NewICMSTotRow(); drISSQNtot = dsdanfe.ISSQNtot.NewISSQNtotRow(); drRetTrib = dsdanfe.retTrib.NewretTribRow(); if (xndtotal.Count > 0) { int i = 0; while (i < xndtotal.Count) { drTotal = dsdanfe.total.NewtotalRow(); populaDadosTotal(CodinfNfeId); dsdanfe.total.AddtotalRow(drTotal); i++; } } if (xndICMStot.Count > 0) { for (int i = 0; i < xndICMStot.Count; i++) { int totalID = dsdanfe.total.Count; // qtde de nodes for (int j = 0; j < xndICMStot[i].ChildNodes.Count; j++) { populaDadosICMStot(xndICMStot[i].ChildNodes[j].LocalName, xndICMStot[i].ChildNodes[j].InnerText, totalID.ToString()); } dsdanfe.ICMSTot.AddICMSTotRow(drICMStot); drICMStot = dsdanfe.ICMSTot.NewICMSTotRow(); } } if (xndISSQNtot.Count > 0) { for (int i = 0; i < xndISSQNtot.Count; i++) { int totalID = dsdanfe.total.Count; // qtde de nodes for (int j = 0; j < xndISSQNtot[i].ChildNodes.Count; j++) { populaDadosISSQNtot(xndISSQNtot[i].ChildNodes[j].LocalName, xndISSQNtot[i].ChildNodes[j].InnerText, totalID.ToString()); } dsdanfe.ISSQNtot.AddISSQNtotRow(drISSQNtot); drISSQNtot = dsdanfe.ISSQNtot.NewISSQNtotRow(); } } if (xndretTrib.Count > 0) { for (int i = 0; i < xndretTrib.Count; i++) { int totalID = dsdanfe.total.Count; // qtde de nodes for (int j = 0; j < xndretTrib[i].ChildNodes.Count; j++) { populaDadosretTrib(xndretTrib[i].ChildNodes[j].LocalName, xndretTrib[i].ChildNodes[j].InnerText, totalID.ToString()); } dsdanfe.retTrib.AddretTribRow(drRetTrib); drRetTrib = dsdanfe.retTrib.NewretTribRow(); } } }
public void populaTagInfNFe(dsDanfe dsdanfe, XmlDocument xml, string CodinfNfeId, int ihoraImpDanfe, int iDataImpDanfe) { XmlNodeList xNinfNFe = xml.GetElementsByTagName("infNFe"); drInfNFe = dsdanfe.infNFe.NewinfNFeRow(); HLP.bel.GeraXMLExp objbelGeraExp = new GeraXMLExp(); if (xNinfNFe.Count > 0) { for (int i = 0; i < xNinfNFe.Count; i++) { string InfNFeId = CodinfNfeId; //Codigo // qtde de nodes for (int j = 0; j < xNinfNFe[i].Attributes.Count; j++) { populaDadosInfNFe(xNinfNFe[i].Attributes[j].LocalName, xNinfNFe[i].Attributes[j].Value, InfNFeId.ToString()); } string sCodDadosNfe = objbelGeraExp.GeraChaveDadosNfe(i, xml); dsdanfe.infNFe.AddinfNFeRow(drInfNFe); drInfNFe = dsdanfe.infNFe.NewinfNFeRow(); // Diego - O.S 24205 - 02/03/2010 if (dsdanfe.infNFe[Convert.ToInt16(CodinfNfeId) - 1].Id != "") // Diego - OS_24302 - 01/04/2010 { XmlNodeList xDet = xml.GetElementsByTagName("det"); //Para Verificar a Qtde de Pag. drCodigoBarras = dsdanfe.codigo_barras.Newcodigo_barrasRow(); drCodigoBarras.codId = Convert.ToInt32(InfNFeId); drCodigoBarras.InfNFeId = InfNFeId.ToString(); // DIEGO - 05/05/2010 drCodigoBarras.horaImpDanfe = ihoraImpDanfe; drCodigoBarras.dataImpDanfe = iDataImpDanfe; // DIEGO - 05/05/2010 - FIM Byte[] bimagem = SalvaCodBarras(dsdanfe.infNFe[Convert.ToInt16(CodinfNfeId) - 1].Id); Byte[] bImagemDadosNfe = SalvaCodBarras(sCodDadosNfe); drCodigoBarras.cod_Barras = bimagem; drCodigoBarras.cod_BarrasContingenciaDadosNfe = bImagemDadosNfe; drCodigoBarras.cod_DadosNfe = sCodDadosNfe; // Diego - OS_24302 - 01/04/2010 if (xDet.Count < 19) { drCodigoBarras.qtdePagRetrato = "1"; } else { double dx = (xDet.Count - 19) / 44.0; int ix = (xDet.Count - 19) / 44; if (dx == Convert.ToDouble(ix)) { drCodigoBarras.qtdePagRetrato = ix.ToString(); } else { drCodigoBarras.qtdePagRetrato = (ix + 2).ToString(); } } // Diego - OS_24302 - 01/04/2010 - fim dsdanfe.codigo_barras.Addcodigo_barrasRow(drCodigoBarras); drCodigoBarras = dsdanfe.codigo_barras.Newcodigo_barrasRow(); } // Diego - O.S 24205 - 02/03/2010 - FIM } } }
private void GeraPDF_Danfe(dsDanfe ds, TipoPDF tpPdf, bool bVisualiza) { try { string sRelImpressao = ""; if (tpPdf == TipoPDF.CANCELADO) { sRelImpressao = "RelDanfeCancelados.rpt"; } if (tpPdf == TipoPDF.ENVIADO) { if (cbxFormDanfe.SelectedIndex == 0) { string simplificado = LeRegWin.LeRegConfig("UsaDanfeSimplificada"); if (simplificado.ToUpper() == "TRUE") { sRelImpressao = "RelDanfeSimplificada.rpt"; } else { sRelImpressao = "RelDanfe.rpt"; } } else { sRelImpressao = "RelDanfePaisagem.rpt"; } } ReportDocument rpt = new ReportDocument(); if (LeRegWin.LeRegConfig("UsaRelatorioEspecifico") == "True") { string sCaminho = LeRegWin.LeRegConfig("CaminhoRelatorioEspecifico") + "\\" + sRelImpressao; rpt.Load(sCaminho); } else { rpt.Load(Application.StartupPath + "\\Relatorios" + "\\" + sRelImpressao); } rpt.SetDataSource(ds); rpt.Refresh(); DirectoryInfo dinfo = new DirectoryInfo(belStaticPastas.ENVIADOS + "\\PDF"); if (!dinfo.Exists) { dinfo.Create(); } string sNmPdfVisualizacao = Environment.MachineName + "_Grupo_Danfes"; string sCaminhoSave = belStaticPastas.ENVIADOS + "\\PDF\\" + (bVisualiza == false ? (ds.infNFe[0].ideRow.nNF.ToString().PadLeft(6, '0') + (tpPdf.ToString().Equals("ENVIADO") ? "_enviado" : "_cancelado")) : sNmPdfVisualizacao) + ".pdf"; ExportPDF(rpt, sCaminhoSave); if (bVisualiza) { // System.Diagnostics.Process.Start(sCaminhoSave); frmPreviwDanfe objfrmDanfe = new frmPreviwDanfe(rpt); objfrmDanfe.Show(); } } catch (Exception ex) { throw ex; } }
private void btnImprimir_Click(object sender, EventArgs e) { try { List<String> sChaves = new List<string>(); List<string> lCaminhosXml = new List<string>(); List<string> lCaminhosXmlContingencia = new List<string>(); List<string> lCaminhosXmlCancelados = new List<string>(); StringBuilder sbSeq = new StringBuilder(); string nao_autorizada = ""; string cancelada = ""; string arquivoInexist = ""; int cont_1 = 0; int cont = 0; DirectoryInfo dinfo = null; FileInfo[] finfo = null; XmlDocument xml = new XmlDocument(); List<belIde> objlbelIde = new List<belIde>(); // Lista de Notas Para envio de email string select = ""; for (int i = 0; i < dgvNF.RowCount; i++) { bool bImprime = false; if (dgvNF["Imprime", i].Value == null) { bImprime = false; } else if (dgvNF["Imprime", i].Value.ToString() == "False") { bImprime = false; } else { bImprime = true; } if (((dgvNF["ST_NFE", i].Value.ToString().Equals("1")) || (dgvNF["st_contingencia", i].Value.ToString().Equals("S"))) && (bImprime == true))//&& (dgvNF["CANCELADA", i].Value.ToString().Equals("0"))) { select = "Select cd_chavenfe from nf where cd_empresa = '" + belStatic.codEmpresaNFe.Trim() + "' and CD_NFSEQ ='" + dgvNF["CD_NFSEQ", i].Value.ToString() + "'"; try { using (FbCommand cmd = new FbCommand(select, cx.get_Conexao())) { cx.Open_Conexao(); sChaves.Add(cmd.ExecuteScalar().ToString()); try { if ((dgvNF["st_contingencia", i].Value.ToString().Equals("S")) && (dgvNF["ST_NFE", i].Value.ToString().Equals("0")) && (dgvNF["CD_NOTAFIS", i].Value.ToString() != "")) { #region Imprime Contingência dinfo = new DirectoryInfo(belStaticPastas.CONTINGENCIA); ; finfo = dinfo.GetFiles(); foreach (FileInfo item in finfo) { if (Path.GetExtension(item.FullName).ToUpper().Equals(".XML")) { if (item.Name.ToString().Length == 26) { xml.Load(@item.FullName); if (xml.GetElementsByTagName("infNFe")[0].Attributes["Id"].Value.ToString().Replace("NFe", "").Equals(cmd.ExecuteScalar().ToString())) { lCaminhosXmlContingencia.Add(belStaticPastas.CONTINGENCIA + "\\" + (item.ToString())); } } } } #endregion } else if (dgvNF["cd_recibocanc", i].Value.ToString() != "") { dinfo = new DirectoryInfo(belStaticPastas.CANCELADOS); ; finfo = dinfo.GetFiles(); bool bAchouArquivo = false; foreach (FileInfo item in finfo) { if (Path.GetExtension(item.FullName).ToUpper().Equals(".XML")) { if (item.Name.ToString().Length == 56) { if (item.Name.Replace("-can.xml.xml", "").Equals(cmd.ExecuteScalar().ToString())) { lCaminhosXmlCancelados.Add(dinfo.FullName + "\\" + (item.ToString())); belIde objbelide = new belIde(); objbelide.Cnf = dgvNF["CD_NOTAFIS", i].Value.ToString(); objbelide.Nnf = dgvNF["CD_NFSEQ", i].Value.ToString(); objlbelIde.Add(objbelide); bAchouArquivo = true; } } } } if (bAchouArquivo == false) { foreach (DirectoryInfo diretorio in dinfo.GetDirectories()) { foreach (FileInfo item in diretorio.GetFiles("*.xml")) { if (item.Name.ToString().Length == 56) { if (item.Name.Replace("-can.xml.xml", "").Equals(cmd.ExecuteScalar().ToString())) { lCaminhosXmlCancelados.Add(diretorio.FullName + "\\" + (item.ToString())); belIde objbelide = new belIde(); objbelide.Cnf = dgvNF["CD_NOTAFIS", i].Value.ToString(); objbelide.Nnf = dgvNF["CD_NFSEQ", i].Value.ToString(); objlbelIde.Add(objbelide); break; } } } } } } else { string sArquivo = belStaticPastas.ENVIADOS + cmd.ExecuteScalar().ToString().Substring(2, 4) + "\\" + cmd.ExecuteScalar().ToString() + "-nfe.xml"; if (File.Exists(sArquivo)) { lCaminhosXml.Add(sArquivo); belIde objbelide = new belIde(); objbelide.Cnf = dgvNF["CD_NOTAFIS", i].Value.ToString(); objbelide.Nnf = dgvNF["CD_NFSEQ", i].Value.ToString(); objlbelIde.Add(objbelide); } else { dinfo = new DirectoryInfo(belStaticPastas.ENVIADOS + "/" + cmd.ExecuteScalar().ToString().Substring(2, 4)); ; finfo = dinfo.GetFiles(); foreach (FileInfo item in finfo) { if (Path.GetExtension(item.FullName).ToUpper().Equals(".XML")) { if (item.Name.ToString().Length == 52) { // xml.Load(@item.FullName); if (item.Name.Replace("-nfe.xml", "").Equals(cmd.ExecuteScalar().ToString())) { lCaminhosXml.Add(dinfo.FullName + "\\" + (item.ToString())); belIde objbelide = new belIde(); objbelide.Cnf = dgvNF["CD_NOTAFIS", i].Value.ToString(); objbelide.Nnf = dgvNF["CD_NFSEQ", i].Value.ToString(); objlbelIde.Add(objbelide); // EnviaEmail(i, item); } } } } } } } catch (Exception ex) { new HLPexception("Verifique se não existe nenhum arquivo Corrompido ou que não seja de Enviados na Pasta Correspondente", ex); break; } } } catch (Exception) { throw; } finally { cx.Close_Conexao(); } } else if ((bImprime == true) && (dgvNF["CANCELADA", i].Value.ToString().Equals("0"))) { if (cont > 0) { nao_autorizada = nao_autorizada + ", " + dgvNF["CD_NFSEQ", i].Value.ToString(); } else { nao_autorizada = dgvNF["CD_NFSEQ", i].Value.ToString(); } cont++; } } // Diego - OS_23834 18/12/2009 if ((lCaminhosXml.Count > 0) || (lCaminhosXmlContingencia.Count > 0) || (lCaminhosXmlCancelados.Count > 0)) { if (lCaminhosXmlCancelados.Count > 0) { //Impressão de Danfe Normal dsdanfe = new dsDanfe(); for (int i = 0; i < lCaminhosXmlCancelados.Count; i++) { InformaStatusEnvio("Gerando PDF da DANFE ", i, lCaminhosXml.Count); PopulaDataSetXML(dsdanfe, lCaminhosXmlCancelados[i].ToString(), (i + 1).ToString()); dsDanfe dsPDF = new dsDanfe(); PopulaDataSetXML(dsPDF, lCaminhosXmlCancelados[i].ToString(), 1.ToString()); GeraPDF_Danfe(dsPDF, TipoPDF.CANCELADO, false); } if (LeRegWin.LeRegConfig("EmailAutomatico").ToString() == "True") { EnviaEmail(lCaminhosXml, objlbelIde); } GeraPDF_Danfe(dsdanfe, TipoPDF.CANCELADO, true); } if (lCaminhosXml.Count > 0) { //Impressão de Danfe Normal dsdanfe = new dsDanfe(); for (int i = 0; i < lCaminhosXml.Count; i++) { InformaStatusEnvio("Gerando PDF da DANFE ", i, lCaminhosXml.Count); statusStrip1.Refresh(); PopulaDataSetXML(dsdanfe, lCaminhosXml[i].ToString(), (i + 1).ToString()); dsDanfe dsPDF = new dsDanfe(); PopulaDataSetXML(dsPDF, lCaminhosXml[i].ToString(), 1.ToString()); GeraPDF_Danfe(dsPDF, TipoPDF.ENVIADO, false); } if (LeRegWin.LeRegConfig("EmailAutomatico").ToString() == "True") { EnviaEmail(lCaminhosXml, objlbelIde); } GeraPDF_Danfe(dsdanfe, TipoPDF.ENVIADO, true); } sslStatusEnvio.Text = ""; #region Contingencia if ((lCaminhosXmlContingencia.Count > 0)) { string sQueryEmpresa = "select empresa.nm_empresa from empresa " + "where empresa.cd_empresa = '" + belStatic.codEmpresaNFe + "'"; FbCommand fbComEmp = new FbCommand(sQueryEmpresa, cx.get_Conexao()); fbComEmp.ExecuteNonQuery(); FbDataReader drEmp = fbComEmp.ExecuteReader(); cx.Close_Conexao(); drEmp.Read(); frmContratoContingenciaNfe objfrmAviso = new frmContratoContingenciaNfe(drEmp["nm_empresa"].ToString()); objfrmAviso.ShowDialog(); if (objfrmAviso.bImprime) { //Impressão de Danfe em Contingencia dsdanfe = new dsDanfe(); for (int i = 0; i < lCaminhosXmlContingencia.Count; i++) { PopulaDataSetXML(dsdanfe, lCaminhosXmlContingencia[i].ToString(), (i + 1).ToString()); }// OS.23999 - DIEGO - 02/02/2010 PrintReport(TipoPDF.CONTINGENCIA); } else { KryptonMessageBox.Show(null, "Impressão Cancelada!!", "IMPRESSÃO DE DANFE", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } } #endregion } else { KryptonMessageBox.Show(null, "Nenhuma nota selecionada para Impressão!", "IMPRESSÃO DE DANFE", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } if (nao_autorizada != "") { KryptonMessageBox.Show(null, "Sequencia de Notas não autorizadas para a impressão do Danfe: " + nao_autorizada, "Alerta", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } if (arquivoInexist != "") { KryptonMessageBox.Show(null, "XML da sequencia a seguir não foi encontrada na Pasta: " + arquivoInexist, "Alerta", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } if (cancelada != "") { KryptonMessageBox.Show(null, "XML da Sequencia a seguir está Cancelado e não pode ser impresso: " + cancelada, "Alerta", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } for (int i = 0; i < dgvNF.RowCount; i++) { dgvNF["Imprime", i].Value = false; } PopulaDataGridView(); } catch (DirectoryNotFoundException) { KryptonMessageBox.Show(null, "Pasta de Arquivos não encontrados", "Erro", MessageBoxButtons.OK, MessageBoxIcon.Error); } catch (Exception ex) { new HLPexception(ex.Message, ex); } finally { cx.Close_Conexao(); } }