86 lines
4.0 KiB
Plaintext
86 lines
4.0 KiB
Plaintext
<%@ WebHandler Language="VB" Class="SIGDesc" %>
|
|
|
|
Option Strict Off
|
|
Imports System.Data
|
|
Imports System.IO
|
|
Imports Extensiones
|
|
Imports Microsoft.Reporting.WebForms
|
|
Imports Newtonsoft.Json
|
|
Imports System.Net.Http
|
|
|
|
Public Class SIGDesc : Implements IHttpHandler, IRequiresSessionState
|
|
|
|
ReadOnly Property UsuarioActual(ByVal context As HttpContext) As Usuario
|
|
Get
|
|
UsuarioActual = DirectCast(context.Session("UsuarioSIG"), Usuario)
|
|
End Get
|
|
End Property
|
|
|
|
Public Sub ProcessRequest(ByVal context As HttpContext) Implements IHttpHandler.ProcessRequest
|
|
If context.Request("metodo") IsNot Nothing AndAlso context.Request("metodo").ToString() = "descargarPDFVenta" Then
|
|
Dim CveVenta As Integer = context.Request("CveVenta").ToEntero()
|
|
DescargarPDFVenta(context, CveVenta)
|
|
End If
|
|
|
|
End Sub
|
|
|
|
Private Sub DescargarPDFVenta(ByVal context As HttpContext, CveVenta As Integer)
|
|
Dim usuario As Usuario = UsuarioActual(context)
|
|
If Not IsNothing(usuario) Then
|
|
Dim ObjFactura As New Modelos.Factura(usuario, CveVenta, usuario.CveEmpresa, CargaDTDetalle:=False, CargaDatosCliente:=False, CargaDatosRelacionados:=False, VerificaAlmacen:=False)
|
|
|
|
Dim ArchivoPDF = String.Format("{0}Empresas\{1}\PDF\{2}\{3}.pdf", ModExtensiones.DirectorioBaseEmpresas, usuario.CveEmpresa, ObjFactura.TipoDocto, ObjFactura.SerieFolio)
|
|
Dim FileInfo As FileInfo = New FileInfo(ArchivoPDF)
|
|
If FileInfo.Exists Then
|
|
context.Response.ContentType = "application/pdf"
|
|
context.Response.Flush()
|
|
context.Response.WriteFile(FileInfo.FullName)
|
|
context.Response.End()
|
|
Else
|
|
DescargarPDFVentaPeticion(context, ObjFactura)
|
|
End If
|
|
FileInfo = Nothing
|
|
End If
|
|
End Sub
|
|
|
|
|
|
Private Sub DescargarPDFVentaPeticion(ByVal context As HttpContext, ObjFactura As Modelos.Factura)
|
|
Dim usuario As Usuario = UsuarioActual(context)
|
|
If Not IsNothing(usuario) Then
|
|
Dim strURLHOST = String.Format("{0}://{1}:{2}", HttpContext.Current.Request.Url.Scheme, HttpContext.Current.Request.Url.Host, HttpContext.Current.Request.Url.Port)
|
|
|
|
Dim Url As New Uri(String.Format("{0}/Compras/PopUpVerFactura.aspx?P={1}", strURLHOST, Encripta(String.Format("OP=VTA&CVEVENTA={0}&PAG=1&GUARDAR=1®ENERAR={1}", ObjFactura.CveVenta, "1"))))
|
|
Dim File As Byte() = Nothing
|
|
Try
|
|
Using httpClient As New HttpClient()
|
|
httpClient.Timeout = New TimeSpan(0, 1, 0)
|
|
Using request As New HttpRequestMessage(HttpMethod.Get, Url)
|
|
request.Headers.Add("ADSToken", Encripta(String.Format("CVEEMPRESA={0}&TICKS={1}&CveUsuario={2}", ObjFactura.CveEmpresa, DateTime.UtcNow.Ticks, ObjFactura.CveUsuario)))
|
|
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
|
|
|
|
context.Response.Buffer = True
|
|
context.Response.Clear()
|
|
context.Response.ContentType = "application/pdf"
|
|
context.Response.ClearHeaders()
|
|
context.Response.AddHeader("content-disposition", String.Format("{0}; filename=""{1}.{2}""", "attachment", ObjFactura.SerieFolio, "pdf"))
|
|
context.Response.BinaryWrite(File) ' create the file
|
|
context.Response.End()
|
|
End If
|
|
End Sub
|
|
|
|
Public ReadOnly Property IsReusable() As Boolean Implements IHttpHandler.IsReusable
|
|
Get
|
|
Return False
|
|
End Get
|
|
End Property
|
|
|
|
End Class |