Example #1
0
        public static MemoryStream MS_InformeViajes(string nroTransporte, string transportista, string nombreOrigen, string destinos, string tracto, string trailer, string nroContenedor, string conductor, string rutConductor, string score, string nombreCliente, List <Track_GetDetalleTrayecto_Result> _detalleTrayecto, List <Track_GetAlertasInformeViaje_Result> _alertasInformeViaje)
        {
            //Disable SSL certificate security. It´s not working other way
            ServicePointManager.ServerCertificateValidationCallback = delegate(object s, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)
            { return(true); };

            Document document = new Document();

            MemoryStream memoryStream = new MemoryStream();
            PdfWriter    pdfWriter    = PdfWriter.GetInstance(document, memoryStream);

            PdfPTable pdfTableResumen = new PdfPTable(2);

            pdfTableResumen.WidthPercentage     = 100;
            pdfTableResumen.DefaultCell.Border  = Rectangle.NO_BORDER;
            pdfTableResumen.HorizontalAlignment = Element.ALIGN_LEFT;

            float[] widths = new float[] { 1f, 3f };
            pdfTableResumen.SetWidths(widths);

            pdfTableResumen.SpacingBefore = 30f;
            pdfTableResumen.SpacingAfter  = 40f;

            pdfTableResumen.AddCell("Guía:");
            pdfTableResumen.AddCell(" " + nroTransporte);
            pdfTableResumen.AddCell("Cliente:");
            pdfTableResumen.AddCell(nombreCliente);
            pdfTableResumen.AddCell("Transportista:");
            pdfTableResumen.AddCell(" " + transportista);
            pdfTableResumen.AddCell("Origen");
            pdfTableResumen.AddCell(" " + nombreOrigen);
            pdfTableResumen.AddCell("Destino/s:");
            pdfTableResumen.AddCell(destinos);
            pdfTableResumen.AddCell("Tracto:");
            pdfTableResumen.AddCell(" " + tracto);
            pdfTableResumen.AddCell("Rampla:");
            pdfTableResumen.AddCell(" " + trailer);
            pdfTableResumen.AddCell("Nro. Contenendor:");
            pdfTableResumen.AddCell(" " + nroContenedor);
            pdfTableResumen.AddCell("Conductor:");
            pdfTableResumen.AddCell(" " + conductor);
            pdfTableResumen.AddCell("Rut Conductor:");
            pdfTableResumen.AddCell(" " + rutConductor);
            pdfTableResumen.AddCell("Score:");
            pdfTableResumen.AddCell(" " + score);

            document.Open();

            var   server    = HttpContext.Current.Server;
            var   imagePath = server.MapPath("Images");
            Image logo      = Image.GetInstance(imagePath + "/logo_white_1500x789.png");

            logo.ScalePercent(7f);

            document.Add(logo);

            var boldTitle = FontFactory.GetFont(FontFactory.HELVETICA_BOLD, 20);

            Paragraph title = new Paragraph("Informe de Viaje", boldTitle);

            title.Alignment = Element.ALIGN_CENTER;

            document.Add(title);

            document.Add(pdfTableResumen);

            var boldFont = FontFactory.GetFont(FontFactory.HELVETICA_BOLD, 12);

            var tituloDetalle = new Phrase();

            tituloDetalle.Add(new Chunk("Detalle de trayecto:", boldFont));
            document.Add(new Paragraph(tituloDetalle));

            PdfPTable pdfTableDetalleTrayecto = new PdfPTable(2);

            pdfTableDetalleTrayecto.WidthPercentage     = 100;
            pdfTableDetalleTrayecto.HorizontalAlignment = Element.ALIGN_LEFT;
            pdfTableDetalleTrayecto.DefaultCell.Border  = Rectangle.NO_BORDER;
            float[] widthsTableDetalleTrayecto = new float[] { 3f, 6f };
            pdfTableDetalleTrayecto.SetWidths(widthsTableDetalleTrayecto);
            pdfTableDetalleTrayecto.SpacingBefore = 10;
            pdfTableDetalleTrayecto.SpacingAfter  = 20;
            //pdfTableDetalleTrayecto.AddCell("Fecha");
            //pdfTableDetalleTrayecto.AddCell("Detalle");

            for (int j = 0; j < _detalleTrayecto.Count; j++)
            {
                pdfTableDetalleTrayecto.AddCell(_detalleTrayecto[j].Fecha);
                pdfTableDetalleTrayecto.AddCell(_detalleTrayecto[j].Detalle);
            }
            document.Add(pdfTableDetalleTrayecto);

            var tituloAlertas = new Phrase();

            tituloAlertas.Add(new Chunk("Alertas:", boldFont));

            var tituloObservaciones = new Phrase();

            tituloObservaciones.Add(new Chunk("Observaciones:", boldFont));

            if (_alertasInformeViaje.Count > 0)
            {
                document.NewPage();
                document.Add(new Paragraph(tituloAlertas));
            }

            int countMapPag = 0;

            for (int i = 0; i < _alertasInformeViaje.Count; i++)
            {
                PdfPTable pdfTableAlertas = new PdfPTable(5);
                pdfTableAlertas.WidthPercentage     = 100;
                pdfTableAlertas.HorizontalAlignment = Element.ALIGN_LEFT;
                //float[] widthsTableAlertas = new float[] { 1f, 3f, 2f, 5f };
                //pdfTableResumen.SetWidths(widths);

                pdfTableAlertas.SpacingBefore = 40;
                pdfTableAlertas.SpacingAfter  = 10f;

                Anchor anchor = new Anchor("Link");

                anchor.Reference = "https://maps.google.com/maps?q=" + _alertasInformeViaje[i].Latitud.ToString() + ',' + _alertasInformeViaje[i].Longitud.ToString();

                pdfTableAlertas.AddCell("Fecha Inicio:");
                pdfTableAlertas.AddCell("Fecha Envío:");
                pdfTableAlertas.AddCell("Destino:");
                pdfTableAlertas.AddCell("Descripción");
                pdfTableAlertas.AddCell("Ver en mapa");
                pdfTableAlertas.AddCell(_alertasInformeViaje[i].FechaInicioAlerta.ToString());
                pdfTableAlertas.AddCell(_alertasInformeViaje[i].FechaHoraCreacion.ToString());
                pdfTableAlertas.AddCell(_alertasInformeViaje[i].LocalDestino.ToString());
                pdfTableAlertas.AddCell(_alertasInformeViaje[i].DescripcionAlerta.ToString());
                pdfTableAlertas.AddCell(anchor);

                document.Add(pdfTableAlertas);

                string center = _alertasInformeViaje[i].Latitud + "," + _alertasInformeViaje[i].Longitud;
                string polygon;

                if (_alertasInformeViaje[i].ZoneLocation != -1)
                {
                    int _idZona;
                    _idZona = Convert.ToInt32(_alertasInformeViaje[i].ZoneLocation);

                    polygon = "&path=color:0x000000%7Cweight:2%7Cfillcolor:0x9966FF%7C";

                    Methods_Zonas         _obj      = new Methods_Zonas();
                    List <Track_Vertices> _vertices = _obj.GetAllVerticesZona(_idZona);
                    for (int k = 0; k < _vertices.Count; k++)
                    {
                        polygon = polygon + _vertices[k].Latitud.ToString().Replace(",", ".") + ',' + _vertices[k].Longitud.ToString().Replace(",", ".");

                        if (k < _vertices.Count - 1)
                        {
                            polygon = polygon + "%7C";
                        }
                    }
                }
                else
                {
                    polygon = "";
                }

                var stringUrlMap = "https://maps.googleapis.com/maps/api/staticmap?zoom=13&maptype=roadmap&size=400x200" + "&markers=color:red%7C" + center + "&key=AIzaSyDKLevfrbLESV7ebpmVxb9P7XRRKE1ypq8" + polygon;

                iTextSharp.text.Image mapImage = iTextSharp.text.Image.GetInstance(stringUrlMap);
                document.Add(mapImage);

                document.Add(new Paragraph(tituloObservaciones));
                if (_alertasInformeViaje[i].Observaciones != "")
                {
                    document.Add(new Paragraph(_alertasInformeViaje[i].Observaciones));
                }
                else
                {
                    document.Add(new Paragraph("Sin observaciones."));
                }

                countMapPag = countMapPag + 1;

                if (countMapPag >= 2)
                {
                    document.NewPage();
                    countMapPag = 0;
                }
            }

            document.Close();

            return(memoryStream);
        }