diff --git a/Ashx/SIGWeb.ashx b/Ashx/SIGWeb.ashx index 281f03674..a92ab17f2 100644 --- a/Ashx/SIGWeb.ashx +++ b/Ashx/SIGWeb.ashx @@ -6,6 +6,7 @@ Imports System.Data Imports Newtonsoft.Json Imports Extensiones Imports System.IO +Imports Microsoft.Reporting.WebForms Public Class SIGWeb : Implements IHttpHandler, IRequiresSessionState 'TEMPORAL, DEBE SER REEMPLAZADO POR EL MODELO DE LA LIBRERIA @@ -119,11 +120,160 @@ Public Class SIGWeb : Implements IHttpHandler, IRequiresSessionState getSATColonias(context) Case "GetFilesDirectory" GetFilesDirectory(context) + Case "Getetiquetas" + Getetiquetas(context) End Select Catch ex As Exception ex.GuardaLog(ex.Message) End Try End Sub + + + Public Sub ImprimirPDF(RutaReporte As String, DataSource As List(Of ReportDataSource), Parametros As List(Of ReportParameter), Optional NombreArchivo As String = "Reporte", Optional Formato As String = "PDF", Optional MR As ReportViewer = Nothing, Optional Content_Disposition As String = "attachment") + 'limpio ReportViwer + ImprimirbytesPDF(StreamPDF(RutaReporte, DataSource, Parametros, NombreArchivo, Formato, MR), NombreArchivo, Formato, Content_Disposition:=Content_Disposition) + End Sub + + Public Function StreamPDF(RutaReporte As String, DataSource As List(Of ReportDataSource), Parametros As List(Of ReportParameter), Optional NombreArchivo As String = "Reporte", Optional Formato As String = "PDF", Optional MR As ReportViewer = Nothing) As Byte() + 'limpio ReportViwer + Dim sw As New System.Diagnostics.Stopwatch() + sw.Start() + Dim Bytes As Byte() = Nothing + + Dim CveUsuario As Integer = 0 + Dim CveEmpresa As Integer = 0 + Dim RutaEmpresa As String = "" + + + Dim bdir As String = If(RutaReporte.Contains("Empresas"), ModExtensiones.DirectorioBaseEmpresas, AppDomain.CurrentDomain.BaseDirectory) + + 'TOMAR LA RUTA BASE PARA EL DIRECTORIO DE LA EMPRESA + If Not String.IsNullOrEmpty(RutaEmpresa) AndAlso Not RutaReporte.Contains("Grales") Then + bdir = RutaEmpresa.Replace($"{CveEmpresa}/", "") + End If + + RutaReporte.Replace("/", "\") + + If Not RutaReporte.ToUpper().StartsWith(bdir.ToUpper()) Then + RutaReporte = String.Format("{0}{1}", bdir, RutaReporte) + End If + + If False Then + + Dim wsreport As New WSRDLC.WebServiceSoapClient + Dim params As New List(Of WSRDLC.ReportParameter) + Dim ds As New DataSet + For Each rpds As ReportDataSource In DataSource + Dim dt As DataTable = DirectCast(rpds.Value, Data.DataTable) + If dt Is Nothing Then + dt = New DataTable() + Else + dt = dt.Copy() + End If + dt.TableName = rpds.Name + ds.Tables.Add(dt) + Next + For Each rpds As ReportParameter In Parametros + Dim param As New WSRDLC.ReportParameter + param.Name = rpds.Name + param.Values = {rpds.Values(0)} + params.Add(param) + Next + Bytes = wsreport.StreamPDFBytes(RutaReporte, ds, params.ToArray(), NombreArchivo, Formato, CveEmpresa, CveUsuario) + wsreport = Nothing + params = Nothing + ds.Dispose() : ds = Nothing + Else + If IsNothing(MR) Then MR = New ReportViewer + Try + ' MasterReporteador.LocalReport.DataSources.Clear() + For Each RDS As ReportDataSource In DataSource + MR.LocalReport.DataSources.Add(RDS) + Next + + MR.LocalReport.ReportPath = RutaReporte + MR.ProcessingMode = ProcessingMode.Local + MR.LocalReport.EnableExternalImages = True + MR.LocalReport.SetParameters(Parametros) + MR.LocalReport.Refresh() + Dim Warnings As Warning() = Nothing + Dim StreamIds As String() = Nothing + Dim MimeType As String = Nothing + Dim Encoding As String = Nothing + Dim Extension As String = Nothing + Bytes = MR.LocalReport.Render(Formato, Nothing, MimeType, Encoding, Extension, StreamIds, Warnings) + Catch ex As Microsoft.Reporting.WebForms.ScriptManagerNotFoundException + GuardaLog($"Error: { If(ex.InnerException.Message IsNot Nothing, ex.InnerException.Message, ex.Message) } | Descripcion: {If(ex.InnerException IsNot Nothing AndAlso ex.InnerException.InnerException IsNot Nothing AndAlso ex.InnerException.InnerException.Message IsNot Nothing, ex.InnerException.InnerException.Message, If(ex.InnerException IsNot Nothing AndAlso ex.InnerException.Message IsNot Nothing, ex.InnerException.Message, "Sin descripcion"))} - Ruta {RutaReporte}") + 'HAY QUE VALIDAR QUE LOS OBJETOS QUE SE USAN PARA GUARDAR LOG EXISTEN!!! IPP 14 AGOSTO 2017 + 'GuardaLog($"Error: {ex.InnerException.Message} | Descripcion: {If(ex.InnerException.InnerException IsNot Nothing, ex.InnerException.InnerException.Message, "Sin descripcion")} - Ruta {RutaReporte}") + Catch ex As Exception + GuardaLog($"Error: { If(ex.InnerException.Message IsNot Nothing, ex.InnerException.Message, ex.Message) } | Descripcion: {If(ex.InnerException IsNot Nothing AndAlso ex.InnerException.InnerException IsNot Nothing AndAlso ex.InnerException.InnerException.Message IsNot Nothing, ex.InnerException.InnerException.Message, If(ex.InnerException IsNot Nothing AndAlso ex.InnerException.Message IsNot Nothing, ex.InnerException.Message, "Sin descripcion"))} - Ruta {RutaReporte}") + 'HAY QUE VALIDAR QUE LOS OBJETOS QUE SE USAN PARA GUARDAR LOG EXISTEN!!! IPP 14 AGOSTO 2017 + 'GuardaLog($"Error {ex.InnerException.Message} | Descripcion: {If(ex.InnerException.InnerException IsNot Nothing, ex.InnerException.InnerException.Message, "Sin descripcion")} - Ruta {RutaReporte}") + End Try + MR.Dispose() + MR = Nothing + + End If + sw.Stop() + + If sw.Elapsed.TotalSeconds > 5 Then + GuardaLog($"Reporte:{RutaReporte} | Tiempo Renderizado Milisegundos: {sw.ElapsedMilliseconds},Total Segundos: {sw.Elapsed.TotalSeconds} ") + End If + + Return Bytes + End Function + + Public Sub ImprimirbytesPDF(bytes As Byte(), Optional NombreArchivo As String = "Reporte", Optional Formato As String = "PDF", Optional Descarga As Boolean = False, Optional Content_Disposition As String = "attachment") + 'limpio ReportViwer + Dim mimeType As String = Nothing + Dim extension As String = Nothing + + 'If Descarga Then + ' Try + ' bytes = bytes + ' File.WriteAllBytes(String.Format("{0}PDF/whatever.gif", UsuarioActual.Empresa.Ruta), img) + ' Catch ex As Exception + ' If UsuarioActual.CveRol = 1 Then + ' Alert(ex.Message, TipoMensaje.MsgAdvertencia) + ' Else + ' Alert("Ocurrió un error al generar la descarga. Favor de contactar a soporte tecnico cod'IMPDFclspag'", TipoMensaje.MsgAdvertencia) + ' End If + ' End Try + 'End If + + Try + bytes = bytes + Response.Buffer = True + Response.Clear() + Response.ContentType = mimeType + Response.AddHeader("content-disposition", String.Format("{0}; filename={1}.{2}", Content_Disposition, NombreArchivo, If(Formato = "PDF", "pdf", "xls"))) + Response.BinaryWrite(bytes) ' create the file + Response.Flush() ' send it to the client to download + HttpContext.Current.Response.SuppressContent = True + HttpContext.Current.ApplicationInstance.CompleteRequest() + HttpContext.Current.Response.End() + bytes = Nothing + Catch ex As Exception + + Alert("Ocurrió un error al generar la descarga. Favor de contactar a soporte tecnico cod:'IMPDFclspag'", TipoMensaje.MsgAdvertencia) + + End Try + End Sub + Dim Response As HttpResponse + Private Function Getetiquetas(context As HttpContext) As String + Dim retorno As String = "" + Dim params As New List(Of ReportParameter) + params.Add(New ReportParameter("Envase", "1 1/9")) + params.Add(New ReportParameter("Tamano", "Small")) + params.Add(New ReportParameter("Cultivo", "Tomate")) + params.Add(New ReportParameter("noPallet", "000001")) + Response = context.Response + Dim tablaReporte As New DataTable + '"Empresas/Grales/Formatos/EquiposGPS.rdlc" + ImprimirPDF("D:\\ADSistemas\\Proyectos\\SIG\\SIGIT\\GPS\\PalletEtiqueta.rdlc", (New List(Of ReportDataSource)), params, "Equipo GPS") + Return retorno + End Function Private Function GetTokenAngular(context As HttpContext) As String Dim usuario As Usuario = UsuarioActual(context) Dim tokenDescriptor = New Microsoft.IdentityModel.Tokens.SecurityTokenDescriptor With {