Guest User

Untitled

a guest
Feb 20th, 2018
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.65 KB | None | 0 0
  1. public class ide
  2. {
  3. public ide() { }
  4. public string cUF { get; set; }
  5. public string tpAmb { get; set; }
  6. public string tpEmit { get; set; }
  7. public string tpTransp { get; set; }
  8. public string mod { get; set; }
  9. public string serie { get; set; }
  10. public string nMDF { get; set; }
  11. public string cMDF { get; set; }
  12. public int cDV { get; set; }
  13. public string modal { get; set; }
  14. public string dhEmi { get; set; }
  15. public string tpEmis { get; set; }
  16. public string procEmi { get; set; }
  17. public string verProc { get; set; }
  18. public string UFIni { get; set; }
  19. public string UFFim { get; set; }
  20.  
  21. public List<infMunCarrega> InfMunCarrega { get; set; }
  22. public class infMunCarrega
  23. {
  24. public infMunCarrega()
  25. {
  26.  
  27. }
  28. public int cMunCarrega { get; set; }
  29. public string xMunCarrega { get; set; }
  30. }
  31.  
  32. }
  33.  
  34. public class MdfeFuncoes
  35. {
  36. private void objetoParaXML(XmlWriter xmlWriter, object objeto, bool ignorarDeclaracaoElemento)
  37. {
  38. if (objeto == null)
  39. return;
  40.  
  41. Type tipoObjeto;
  42. tipoObjeto = objeto.GetType();
  43. PropertyInfo[] propriedades;
  44. propriedades = tipoObjeto.GetProperties();
  45.  
  46. if (!ignorarDeclaracaoElemento)
  47. xmlWriter.WriteStartElement(tipoObjeto.Name);
  48.  
  49. foreach (PropertyInfo propriedade in propriedades)
  50. {
  51. if (Funcoes.novaTag(propriedade) && !(propriedade.GetValue(objeto, null) == null))
  52. {
  53. objetoParaXML(xmlWriter, propriedade.GetValue(objeto, null), false);
  54. continue;
  55. }
  56. object[] obj = propriedade.GetCustomAttributes(false);
  57. Funcoes.gravarElemento(xmlWriter, propriedade.Name, propriedade.GetValue(objeto, null), obj);
  58. }
  59. if (!ignorarDeclaracaoElemento)
  60. xmlWriter.WriteEndElement();
  61. }
  62.  
  63. public XmlDocument GerarXml()
  64. {
  65. XmlWriterSettings configXML = new XmlWriterSettings();
  66. configXML.Indent = true;
  67. configXML.IndentChars = "";
  68. configXML.NewLineOnAttributes = false;
  69. configXML.OmitXmlDeclaration = false;
  70.  
  71. Stream xmlSaida = new MemoryStream();
  72.  
  73. XmlWriter oXmlGravar = XmlWriter.Create(xmlSaida, configXML);
  74. oXmlGravar.WriteStartDocument();
  75. oXmlGravar.WriteStartElement("MDFe", "http://www.portalfiscal.inf.br/mdfe");
  76. oXmlGravar.WriteStartElement("infMDFe");
  77. oXmlGravar.WriteAttributeString("xmlns", "xsi", null, "http://www.w3.org/2001/XMLSchema-instance");
  78. oXmlGravar.WriteAttributeString("Id", "MDFe" + Id.ToString());
  79. oXmlGravar.WriteAttributeString("versao", "3.00");
  80.  
  81. Type tipoObjeto;
  82. tipoObjeto = infMDFe.Ide.GetType();
  83. PropertyInfo[] propriedades;
  84. propriedades = tipoObjeto.GetProperties();
  85.  
  86.  
  87. objetoParaXML(oXmlGravar, infMDFe.Ide, false);
  88.  
  89.  
  90. objetoParaXML(oXmlGravar, infMDFe.Emit, false);
  91.  
  92. //oXmlGravar.WriteStartElement("infModal"); //abre o infModal
  93. //oXmlGravar.WriteAttributeString("versaoModal", null, "3.00");
  94. //objetoParaXML(oXmlGravar, infMDFe.Rodo, false);
  95. //oXmlGravar.WriteEndElement(); //fecha o infModal
  96.  
  97. //oXmlGravar.WriteStartElement("infDoc"); //abre o infDoc
  98. //if (infMDFe.InfDoc.InfMunDescarga != null)
  99. //{
  100. // foreach (infMDFe.infDoc.infMunDescarga docDescarga in infMDFe.InfDoc.InfMunDescarga)
  101. // {
  102. // objetoParaXML(oXmlGravar, docDescarga, false);
  103. // }
  104. //}
  105. //oXmlGravar.WriteEndElement(); //fecha o infDoc
  106.  
  107. //objetoParaXML(oXmlGravar, infMDFe.Seg, false);
  108. //objetoParaXML(oXmlGravar, infMDFe.Tot, false);
  109.  
  110. //if (infMDFe.Lacres != null)
  111. //{
  112. // foreach (infMDFe.lacres Lacres in infMDFe.Lacres)
  113. // {
  114. // objetoParaXML(oXmlGravar, Lacres, false);
  115. // }
  116. //}
  117.  
  118. //if (infMDFe.AutXML != null)
  119. //{
  120. // objetoParaXML(oXmlGravar, infMDFe.AutXML, false);
  121. //}
  122.  
  123. //if (infMDFe.InfAdic != null)
  124. //{
  125. // objetoParaXML(oXmlGravar, infMDFe.InfAdic, false);
  126. //}
  127.  
  128. oXmlGravar.WriteEndElement(); //fecha infMDFe
  129. oXmlGravar.WriteEndElement(); //fecha MDFe
  130.  
  131. oXmlGravar.Flush();
  132. xmlSaida.Flush();
  133. xmlSaida.Position = 0;
  134.  
  135. XmlDocument documento = new XmlDocument();
  136. documento.Load(xmlSaida);
  137.  
  138. oXmlGravar.Close();
  139. return documento;
  140. }
  141. } //o código continua, mas eu resolvendo essa falha no List<T>, dou conta do resto...
Add Comment
Please, Sign In to add comment