--mejora en lectura de xml,
This commit is contained in:
@@ -724,19 +724,33 @@ Partial Class Compras_Proveedores
|
|||||||
Dim ObjeFacturas As New ClsCompras
|
Dim ObjeFacturas As New ClsCompras
|
||||||
If ObjeFacturas.GetFacturas(CveFactura, "-1", NowADS().AddYears(-2), NowADS(), "-1", "-1", -1, -1, -1, -1, "-1", UsuarioActual.CveEmpresa) Then
|
If ObjeFacturas.GetFacturas(CveFactura, "-1", NowADS().AddYears(-2), NowADS(), "-1", "-1", -1, -1, -1, -1, "-1", UsuarioActual.CveEmpresa) Then
|
||||||
Dim XMLDoc As New XmlDocument
|
Dim XMLDoc As New XmlDocument
|
||||||
|
Dim SXML As String
|
||||||
|
Dim dr As DataRow = ObjeFacturas.DtResultados.Rows(0)
|
||||||
|
Dim Archivo As String = String.Format("{0}Compras\{1}\{2}", UsuarioActual.Empresa.Ruta, dr("RFCDe"), dr("XML"))
|
||||||
Try
|
Try
|
||||||
Dim dr As DataRow = ObjeFacturas.DtResultados.Rows(0)
|
SXML = File.ReadAllText(Archivo).Replace("<br>", "").Replace("<", "").Replace("o;?", "").Replace(ChrW(&HFEFF), "")
|
||||||
|
|
||||||
|
|
||||||
Dim SXML As String = File.ReadAllText(UsuarioActual.Empresa.Ruta & "Compras\" & dr("RFCDe").ToString & "\" & dr("XML").ToString)
|
|
||||||
'SXML = SXML.TrimStart(vbCr, vbLf, vbNullChar)
|
'SXML = SXML.TrimStart(vbCr, vbLf, vbNullChar)
|
||||||
'SXML = SXML.TrimEnd(vbCr, vbLf, vbNullChar)
|
'SXML = SXML.TrimEnd(vbCr, vbLf, vbNullChar)
|
||||||
SXML = SXML.Trim(New Char() {""c})
|
SXML = SXML.Trim(New Char() {""c})
|
||||||
SXML = SXML.Replace("o;?", "")
|
SXML = SXML.Replace("o;?", "")
|
||||||
|
|
||||||
XMLDoc.LoadXml(SXML)
|
XMLDoc.LoadXml(SXML)
|
||||||
Dim Prefijo As String = If(XMLDoc.DocumentElement.Prefix = "", "cfd", XMLDoc.DocumentElement.Prefix)
|
Catch ex As Exception
|
||||||
|
Try
|
||||||
|
Dim oReader As New StreamReader(Archivo, Encoding.GetEncoding("ISO-8859-1"))
|
||||||
|
XMLDoc.Load(oReader)
|
||||||
|
oReader.Dispose()
|
||||||
|
Catch ex2 As Exception
|
||||||
|
GuardaLog("Error al intentar leer el XML del SAT. Error:" & ex2.ToString())
|
||||||
|
End Try
|
||||||
|
End Try
|
||||||
|
|
||||||
|
If XMLDoc.InnerXml = "" Then
|
||||||
|
Alert("No se pudo procesar el archivo xml.", TipoMensaje.MsgError)
|
||||||
|
Return 0
|
||||||
|
End If
|
||||||
|
|
||||||
|
Dim Prefijo As String = If(XMLDoc.DocumentElement.Prefix = "", "cfd", XMLDoc.DocumentElement.Prefix)
|
||||||
Dim cfdVer As String = "http://www.sat.gob.mx/cfd/3"
|
Dim cfdVer As String = "http://www.sat.gob.mx/cfd/3"
|
||||||
Dim namespaces As New XmlNamespaceManager(XMLDoc.NameTable)
|
Dim namespaces As New XmlNamespaceManager(XMLDoc.NameTable)
|
||||||
|
|
||||||
@@ -756,55 +770,51 @@ Partial Class Compras_Proveedores
|
|||||||
|
|
||||||
'If Prefijo.ToLower <> "cfdi" Then cfdVer = "http://www.sat.gob.mx/cfd/2"
|
'If Prefijo.ToLower <> "cfdi" Then cfdVer = "http://www.sat.gob.mx/cfd/2"
|
||||||
namespaces.AddNamespace(Prefijo, cfdVer)
|
namespaces.AddNamespace(Prefijo, cfdVer)
|
||||||
|
' XMLDoc.LoadXml(File.ReadAllText(Archivo).Replace("<br>", "").Replace("<", "").Replace("o;?", "").Replace(ChrW(&HFEFF), ""))
|
||||||
|
|
||||||
|
|
||||||
Dim node As XmlNode
|
Dim node As XmlNode
|
||||||
node = XMLDoc.SelectSingleNode(String.Format("//{0}:Emisor", Prefijo), namespaces)
|
node = XMLDoc.SelectSingleNode(String.Format("//{0}:Emisor", Prefijo), namespaces)
|
||||||
If node IsNot Nothing Then
|
If node IsNot Nothing Then
|
||||||
TxtRFC.Text = ValorXml(node, "rfc")
|
TxtRFC.Text = ValorXml(node, "rfc")
|
||||||
|
|
||||||
If Version = "3.3" Or Version = "4.0" Then
|
If Version = "3.3" Or Version = "4.0" Then
|
||||||
TxtRazonSocial.Text = HttpUtility.HtmlDecode(ValorXml(node, "Nombre"))
|
TxtRazonSocial.Text = HttpUtility.HtmlDecode(ValorXml(node, "Nombre"))
|
||||||
TxtNombreComercial.Text = HttpUtility.HtmlDecode(ValorXml(node, "Nombre"))
|
TxtNombreComercial.Text = HttpUtility.HtmlDecode(ValorXml(node, "Nombre"))
|
||||||
ChkEstado.Checked = True
|
ChkEstado.Checked = True
|
||||||
|
|
||||||
Dim CodigoRegimenFiscal As String = ValorXml(node, "RegimenFiscal")
|
Dim CodigoRegimenFiscal As String = ValorXml(node, "RegimenFiscal")
|
||||||
|
|
||||||
If Version = "4.0" Or CodigoRegimenFiscal.Trim.Length > 0 Then
|
If Version = "4.0" Or CodigoRegimenFiscal.Trim.Length > 0 Then
|
||||||
|
|
||||||
|
|
||||||
Dim CveRegimenFiscal As Integer = GlobalDTRegimenesFiscales(-1).FiltroPrimeroValor("CveRegimenFiscal", $" CodigoRegimenFiscal = '{ CodigoRegimenFiscal }'").ToEntero
|
Dim CveRegimenFiscal As Integer = GlobalDTRegimenesFiscales(-1).FiltroPrimeroValor("CveRegimenFiscal", $" CodigoRegimenFiscal = '{ CodigoRegimenFiscal }'").ToEntero
|
||||||
DdlRegimenFiscal.SelectedValueExist(CveRegimenFiscal)
|
DdlRegimenFiscal.SelectedValueExist(CveRegimenFiscal)
|
||||||
|
|
||||||
End If
|
End If
|
||||||
|
|
||||||
Else
|
Else
|
||||||
TxtRazonSocial.Text = HttpUtility.HtmlDecode(ValorXml(node, "nombre"))
|
TxtRazonSocial.Text = HttpUtility.HtmlDecode(ValorXml(node, "nombre"))
|
||||||
TxtNombreComercial.Text = HttpUtility.HtmlDecode(ValorXml(node, "nombre"))
|
TxtNombreComercial.Text = HttpUtility.HtmlDecode(ValorXml(node, "nombre"))
|
||||||
Dim nodeDomicilio As XmlNode = XMLDoc.SelectSingleNode(String.Format("//{0}:DomicilioFiscal", Prefijo), namespaces)
|
Dim nodeDomicilio As XmlNode = XMLDoc.SelectSingleNode(String.Format("//{0}:DomicilioFiscal", Prefijo), namespaces)
|
||||||
TxtDireccion.Text = ValorXml(nodeDomicilio, "calle") & " " & ValorXml(nodeDomicilio, "noExterior")
|
TxtDireccion.Text = ValorXml(nodeDomicilio, "calle") & " " & ValorXml(nodeDomicilio, "noExterior")
|
||||||
ChkEstado.Checked = True
|
ChkEstado.Checked = True
|
||||||
|
|
||||||
node = XMLDoc.SelectSingleNode(String.Format("//{0}:Impuestos", Prefijo), namespaces)
|
node = XMLDoc.SelectSingleNode(String.Format("//{0}:Impuestos", Prefijo), namespaces)
|
||||||
If node IsNot Nothing AndAlso node.ChildNodes.Count > 0 Then
|
If node IsNot Nothing AndAlso node.ChildNodes.Count > 0 Then
|
||||||
'Dim nodeRetenciones As XmlNodeList = XMLDoc.SelectNodes(String.Format("//{0}:Retencion", Prefijo), namespaces)
|
'Dim nodeRetenciones As XmlNodeList = XMLDoc.SelectNodes(String.Format("//{0}:Retencion", Prefijo), namespaces)
|
||||||
'Dim nodeRet As XmlNode = XMLDoc.SelectSingleNode(String.Format("//{0}:Retenciones", Prefijo), namespaces)
|
'Dim nodeRet As XmlNode = XMLDoc.SelectSingleNode(String.Format("//{0}:Retenciones", Prefijo), namespaces)
|
||||||
|
|
||||||
Dim nodeTraslados As XmlNodeList = XMLDoc.SelectNodes(String.Format("//{0}:Traslado", Prefijo), namespaces)
|
Dim nodeTraslados As XmlNodeList = XMLDoc.SelectNodes(String.Format("//{0}:Traslado", Prefijo), namespaces)
|
||||||
For Each traslado As XmlNode In nodeTraslados
|
For Each traslado As XmlNode In nodeTraslados
|
||||||
If traslado.Attributes("impuesto").Value = "IVA" Then
|
If traslado.Attributes("impuesto").Value = "IVA" Then
|
||||||
TxtIVA.Text = traslado.Attributes("tasa").Value.ToDouble.ToString("N2")
|
TxtIVA.Text = traslado.Attributes("tasa").Value.ToDouble.ToString("N2")
|
||||||
'Retenciones
|
'Retenciones
|
||||||
End If
|
End If
|
||||||
Next
|
Next
|
||||||
End If
|
|
||||||
End If
|
End If
|
||||||
End If
|
End If
|
||||||
|
End If
|
||||||
Catch ex As Exception
|
|
||||||
Alert(String.Format("No se pudo cargar la información ({0})", ex.Message), TipoMensaje.MsgAdvertencia)
|
|
||||||
Return 0
|
|
||||||
End Try
|
|
||||||
|
|
||||||
End If
|
End If
|
||||||
Return 1
|
Return 1
|
||||||
@@ -5847,11 +5857,8 @@ Partial Class Compras_Proveedores
|
|||||||
Protected Sub LnkDownLoadDoc_Click(sender As Object, e As EventArgs)
|
Protected Sub LnkDownLoadDoc_Click(sender As Object, e As EventArgs)
|
||||||
Dim GvRow As GridViewRow = DirectCast(DirectCast(sender, LinkButton).NamingContainer, GridViewRow)
|
Dim GvRow As GridViewRow = DirectCast(DirectCast(sender, LinkButton).NamingContainer, GridViewRow)
|
||||||
Dim Adjunto As String = GvRow.DataKey("Adjunto")
|
Dim Adjunto As String = GvRow.DataKey("Adjunto")
|
||||||
|
|
||||||
|
|
||||||
Dim stringDescargaDocumento As String = UsuarioActual.Empresa.Ruta & String.Format("Edoc\\Proveedor\{0}\{1}", CveProveedor, Adjunto)
|
Dim stringDescargaDocumento As String = UsuarioActual.Empresa.Ruta & String.Format("Edoc\\Proveedor\{0}\{1}", CveProveedor, Adjunto)
|
||||||
|
|
||||||
|
|
||||||
Dim File As New FileInfo(stringDescargaDocumento)
|
Dim File As New FileInfo(stringDescargaDocumento)
|
||||||
|
|
||||||
If File.Exists Then
|
If File.Exists Then
|
||||||
|
|||||||
Reference in New Issue
Block a user