This commit is contained in:
2020-11-06 16:23:42 -07:00
parent 012a3a61f8
commit 3a653b952d
3 changed files with 569 additions and 39 deletions

135
Ashx/E141.ashx Normal file
View File

@@ -0,0 +1,135 @@
<%@ WebHandler Language="VB" Class="E141" %>
Imports System
Imports System.Web
Imports System.Data
Imports System.Net.Http
Imports Newtonsoft.Json
Imports Newtonsoft.Json.Linq
Imports Extensiones
Imports System.IO
Public Class E141 : Implements IHttpHandler
Public ReadOnly Property IsReusable() As Boolean Implements IHttpHandler.IsReusable
Get
Return False
End Get
End Property
Private ReadOnly Property CveEmpresa As Integer = 141
Public ReadOnly Property EsProduccion As Boolean
Get
If IsNothing(System.Configuration.ConfigurationManager.AppSettings("EsProduccion")) Then
Return False
Else
Return (System.Configuration.ConfigurationManager.AppSettings("EsProduccion").ToString() = "1")
End If
End Get
End Property
Public Sub ProcessRequest(ByVal context As HttpContext) Implements IHttpHandler.ProcessRequest
Dim retorno As String = "no se encontro la variable"
Try
Dim Params = If(context.Request("P") = Nothing, "", context.Request("P").ToString())
If Not String.IsNullOrEmpty(Params) Then
Dim UrlParametros As Hashtable = Parametros(Decripta(Params))
Dim File As String = UrlParametros("FILE").ToString()
If Not String.IsNullOrEmpty(File) Then
ImprimirbytesPDF(context, DescargarFactura(File), File)
End If
End If
Catch ex As Exception
retorno = ex.ToString()
ex.GuardaLog(ex.ToString())
context.Response.Write(retorno)
End Try
End Sub
'Private Function DescargarFactura(CveVenta As Integer) As Byte()
' Dim Url = New Uri(String.Format("{0}Compras/PopUpVerFactura.aspx?P={1}", ClsPaginas.UrlSitio, Encripta(String.Format("OP=VTA&CVEVENTA={0}&PAG=1&GUARDAR=0", CveVenta))))
' Dim File As Byte() = Nothing
' Try
' Using httpClient = New HttpClient()
' httpClient.Timeout = New TimeSpan(0, 15, 0)
' Using request = New HttpRequestMessage(HttpMethod.Get, Url)
' request.Headers.Add("ADSToken", Encripta(String.Format("CVEEMPRESA={0}&TICKS={1}&CVEUSUARIO=100", CveEmpresa, DateTime.UtcNow.Ticks)))
' Dim response = httpClient.SendAsync(request).Result
' If response.StatusCode = Net.HttpStatusCode.OK Then
' File = response.Content.ReadAsByteArrayAsync().Result
' End If
' End Using
' End Using
' Catch ex As Exception
' File = Nothing
' OnError("Ocurrió un error al descargar la factura", ex)
' End Try
' Return File
'End Function
Private Function DescargarFactura(FilePDF As String) As Byte()
Dim Url = New Uri(String.Format("{0}Compras/PopUpVerFactura.aspx?TipoDocto=Ing&File={1}&TipoArchivo=PDF", "http://localhost/", FilePDF))
Dim File As Byte() = Nothing
Try
Using httpClient = New HttpClient()
httpClient.Timeout = New TimeSpan(0, 1, 0)
Using request = New HttpRequestMessage(HttpMethod.Get, Url)
request.Headers.Add("ADSToken", Encripta(String.Format("CVEEMPRESA={0}&TICKS={1}&CVEUSUARIO=100", CveEmpresa, DateTime.UtcNow.Ticks)))
Dim response = httpClient.SendAsync(request).Result
If response.StatusCode = Net.HttpStatusCode.OK Then
File = response.Content.ReadAsByteArrayAsync().Result
End If
End Using
End Using
Catch ex As Exception
File = Nothing
OnError("Ocurrió un error al descargar la factura", ex)
End Try
Return File
End Function
Public Sub ImprimirbytesPDF(ByVal context As HttpContext, bytes As Byte(), NombreArchivo As String)
'limpio ReportViwer
Dim mimeType As String = Nothing
Dim extension As String = Nothing
Try
bytes = bytes
context.Response.Buffer = True
context.Response.Clear()
context.Response.ContentType = mimeType
context.Response.AddHeader("content-disposition", String.Format("attachment; filename={0}", NombreArchivo))
context.Response.BinaryWrite(bytes) ' create the file
context.Response.Flush() ' send it to the client to download
context.Response.SuppressContent = True
context.ApplicationInstance.CompleteRequest()
context.Response.End()
Catch ex As Exception
End Try
End Sub
Private Function Parametros(Cadena As String) As Hashtable
Dim P1() As String = Cadena.Split("&"c)
Dim Tmp As String
Dim P2() As String
Dim URLParametros As New Hashtable
For Each Tmp In P1
P2 = Tmp.Replace("%26%", "&").Split("="c)
URLParametros.Add(P2(0).ToString.ToUpper, P2(1))
Next
Return URLParametros
End Function
End Class