public Document BindingData(Document doc, Int64 nroTarja) { string jsonPlan = string.Empty, jsonDocsConsig = string.Empty, jsonCliente = string.Empty, jsonNave = string.Empty, jsonPuertoD = string.Empty, jsonTarjador = string.Empty; PlanificacionConsBO planCons; List <DocumentoConsigBO> listaDocs; ForwardersBO cliente; NavesBO nave; PuertosBO puerto_dest; PersonasBO tarjador; try { jsonPlan = new PlanificacionConsBLL().sp_sel_PlanificacionConsoIDDAL(nroTarja); planCons = JsonConvert.DeserializeObject <PlanificacionConsBO>(jsonPlan.Trim(new char[] { '[', ']' })); jsonDocsConsig = new DocumentoConsigBLL().sp_sel_documentosIDBLL(nroTarja); listaDocs = JsonConvert.DeserializeObject <List <DocumentoConsigBO> >(jsonDocsConsig); jsonCliente = JsonConvert.SerializeObject(new ForwardersBLL().sp_selPlanDesc_forwarderBLL(planCons.Rut_cliente)); cliente = JsonConvert.DeserializeObject <ForwardersBO>(jsonCliente.Trim(new char[] { '[', ']' })); jsonNave = JsonConvert.SerializeObject(new NavesBLL().sp_sel_naveIDBLL(planCons.Cod_nave)); nave = JsonConvert.DeserializeObject <NavesBO>(jsonNave.Trim(new char[] { '[', ']' })); jsonPuertoD = JsonConvert.SerializeObject(new PuertoBLL().sp_sel_puertoIDBLL(planCons.Cod_puerto_dest)); puerto_dest = JsonConvert.DeserializeObject <PuertosBO>(jsonPuertoD.Trim(new char[] { '[', ']' })); jsonTarjador = JsonConvert.SerializeObject(new PersonasBLL().sp_sel_personasIDBLL(planCons.Rut_tarjador)); tarjador = JsonConvert.DeserializeObject <PersonasBO>(jsonTarjador.Trim(new char[] { '[', ']' })); } catch (Exception ex) { throw ex; } Font arialHeading = FontFactory.GetFont("Arial", 15, 1); Font arialText = FontFactory.GetFont("Arial", 10, 1); string logoPath = HostingEnvironment.MapPath("~/assets/custom/images"); var settings = new BarCodeSettings { Type = BarCodeType.Code128, Data = nroTarja.ToString() }; var generator = new BarCodeGenerator(settings); iTextSharp.text.Image imgbarcode; using (var barcodeImage = generator.GenerateImage()) { ImageFormat format = ImageFormat.Bmp; imgbarcode = Image.GetInstance(barcodeImage, format); imgbarcode.ScalePercent(100f); } //Añadir encabezado PdfPTable tableHeader = new PdfPTable(3); PdfPCell subheader = new PdfPCell(imgbarcode); subheader.HorizontalAlignment = 1; subheader.VerticalAlignment = 5; subheader.Border = 0; tableHeader.WidthPercentage = 100; tableHeader.DefaultCell.Padding = 4.5f; tableHeader.DefaultCell.Border = 0; tableHeader.DefaultCell.HorizontalAlignment = 1; tableHeader.DefaultCell.VerticalAlignment = 5; Image logo = Image.GetInstance(logoPath + "/logo.png"); tableHeader.AddCell(logo); Paragraph titulo = new Paragraph("Documento de Consolidado", arialHeading); tableHeader.AddCell(titulo); tableHeader.AddCell(subheader); //Añadir Tabla de detalles PdfPTable detailTable = new PdfPTable(6); detailTable.WidthPercentage = 100; detailTable.DefaultCell.Padding = 4.5f; detailTable.DefaultCell.Border = 15; detailTable.DefaultCell.HorizontalAlignment = 1; detailTable.DefaultCell.VerticalAlignment = 5; //row1 inicializacion PdfPCell TitleCliente = new PdfPCell(new Paragraph("CLIENTE", arialText)); TitleCliente.BackgroundColor = BaseColor.LIGHT_GRAY; TitleCliente.HorizontalAlignment = 1; TitleCliente.VerticalAlignment = 5; PdfPCell cellrutCliente = new PdfPCell(new Paragraph(cliente.Rut_cliente + "-" + cliente.Dv_cliente, arialText)); cellrutCliente.HorizontalAlignment = 1; cellrutCliente.VerticalAlignment = 5; PdfPCell cellcliente = new PdfPCell(new Paragraph(cliente.Nombre_cliente, arialText)); cellcliente.HorizontalAlignment = 1; cellcliente.VerticalAlignment = 5; PdfPCell vacio1 = new PdfPCell(new Paragraph("")); PdfPCell celltitlefecha = new PdfPCell(new Paragraph("FECHA", arialText)); celltitlefecha.HorizontalAlignment = 1; celltitlefecha.VerticalAlignment = 5; celltitlefecha.BackgroundColor = BaseColor.LIGHT_GRAY; PdfPCell cellfecha = new PdfPCell(new Paragraph(planCons.Fecha.ToString("dd-MM-yyyy").Substring(0, 10), arialText)); cellfecha.HorizontalAlignment = 1; cellfecha.VerticalAlignment = 5; //row2 inicializacion PdfPCell celltitlenave = new PdfPCell(new Paragraph("NAVE", arialText)); celltitlenave.BackgroundColor = BaseColor.LIGHT_GRAY; celltitlenave.HorizontalAlignment = 1; celltitlenave.VerticalAlignment = 5; PdfPCell cellnave = new PdfPCell(new Paragraph(nave.Nav_nom, arialText)); cellnave.HorizontalAlignment = 1; cellnave.VerticalAlignment = 5; PdfPCell celltitlehorrai = new PdfPCell(new Paragraph("HORA INICIO", arialText)); celltitlehorrai.BackgroundColor = BaseColor.LIGHT_GRAY; celltitlehorrai.HorizontalAlignment = 1; celltitlehorrai.VerticalAlignment = 5; PdfPCell cellhorainicio = new PdfPCell(new Paragraph(planCons.Hora_inicio.ToString(), arialText)); cellhorainicio.HorizontalAlignment = 1; cellhorainicio.VerticalAlignment = 5; PdfPCell celltitlehorrat = new PdfPCell(new Paragraph("HORA TERMINO", arialText)); celltitlehorrat.BackgroundColor = BaseColor.LIGHT_GRAY; celltitlehorrat.HorizontalAlignment = 1; celltitlehorrat.VerticalAlignment = 5; PdfPCell cellhoratermino = new PdfPCell(new Paragraph(planCons.Hora_termino.ToString(), arialText)); cellhoratermino.HorizontalAlignment = 1; cellhoratermino.VerticalAlignment = 5; //row3 inicializacion PdfPCell titledestino = new PdfPCell(new Paragraph("DESTINO", arialText)); titledestino.BackgroundColor = BaseColor.LIGHT_GRAY; titledestino.HorizontalAlignment = 1; titledestino.VerticalAlignment = 5; PdfPCell celldestino = new PdfPCell(new Paragraph(puerto_dest.Gls_nombre_puerto, arialText)); celldestino.HorizontalAlignment = 1; celldestino.VerticalAlignment = 5; PdfPCell titlecontenedor = new PdfPCell(new Paragraph("CONTENEDOR", arialText)); titlecontenedor.BackgroundColor = BaseColor.LIGHT_GRAY; titlecontenedor.HorizontalAlignment = 1; titlecontenedor.VerticalAlignment = 5; PdfPCell cellcontenedor = new PdfPCell(new Paragraph(planCons.Gls_contenedor.Substring(0, 10) + "-" + planCons.Gls_contenedor.Substring(10), arialText)); cellcontenedor.HorizontalAlignment = 1; cellcontenedor.VerticalAlignment = 5; PdfPCell celltitlesello = new PdfPCell(new Paragraph("SELLO", arialText)); celltitlesello.HorizontalAlignment = 1; celltitlesello.VerticalAlignment = 5; celltitlesello.BackgroundColor = BaseColor.LIGHT_GRAY; PdfPCell cellsello = new PdfPCell(new Paragraph(planCons.Gls_sello, arialText)); cellsello.HorizontalAlignment = 1; cellsello.VerticalAlignment = 5; //row4 inicializacion PdfPCell titlecodiso = new PdfPCell(new Paragraph("CODIGO ISO", arialText)); titlecodiso.BackgroundColor = BaseColor.LIGHT_GRAY; titlecodiso.HorizontalAlignment = 1; titlecodiso.VerticalAlignment = 5; PdfPCell cellcodiso = new PdfPCell(new Paragraph(planCons.Cod_iso, arialText)); cellcodiso.HorizontalAlignment = 1; cellcodiso.VerticalAlignment = 5; PdfPCell titletara = new PdfPCell(new Paragraph("TARA", arialText)); titletara.BackgroundColor = BaseColor.LIGHT_GRAY; titletara.HorizontalAlignment = 1; titletara.VerticalAlignment = 5; PdfPCell celltara = new PdfPCell(new Paragraph(planCons.F_capacidad.ToString(), arialText)); celltara.HorizontalAlignment = 1; celltara.VerticalAlignment = 5; //row1 detailTable.AddCell(TitleCliente); detailTable.AddCell(cellrutCliente); detailTable.AddCell(cellcliente); detailTable.AddCell(vacio1); detailTable.AddCell(celltitlefecha); detailTable.AddCell(cellfecha); //row2 detailTable.AddCell(celltitlenave); detailTable.AddCell(cellnave); detailTable.AddCell(celltitlehorrai); detailTable.AddCell(cellhorainicio); detailTable.AddCell(celltitlehorrat); detailTable.AddCell(cellhoratermino); //row3 detailTable.AddCell(titledestino); detailTable.AddCell(celldestino); detailTable.AddCell(titlecontenedor); detailTable.AddCell(cellcontenedor); detailTable.AddCell(celltitlesello); detailTable.AddCell(cellsello); //row4 detailTable.AddCell(titlecodiso); detailTable.AddCell(cellcodiso); detailTable.AddCell(vacio1); detailTable.AddCell(vacio1); detailTable.AddCell(vacio1); detailTable.AddCell(vacio1); ////tabla contenedor PdfPTable detailConte = new PdfPTable(3); detailConte.WidthPercentage = 100; detailConte.DefaultCell.HorizontalAlignment = 1; detailConte.DefaultCell.VerticalAlignment = 5; ////row 1 Image vector = Image.GetInstance(logoPath + "/vector.png"); vector.ScalePercent(52f); PdfPCell cellFotoCont = new PdfPCell(vector); cellFotoCont.HorizontalAlignment = 1; cellFotoCont.VerticalAlignment = 5; PdfPTable tableSecVec = new PdfPTable(2); List <SectorVectorBO> listSector = JsonConvert.DeserializeObject <List <SectorVectorBO> >(new SectorVectorBLL().sp_sel_sectorVectorIDDAL(nroTarja)); string codEstado, nroSector, estado; #pragma warning disable CS0219 // La variable 'j' está asignada pero su valor nunca se usa int j = 1; #pragma warning restore CS0219 // La variable 'j' está asignada pero su valor nunca se usa foreach (SectorVectorBO sector in listSector) { codEstado = sector.Cod_estado.ToString(); nroSector = sector.Nro_sector.ToString(); PdfPCell estadoSec = new PdfPCell(); estado = sector.Gls_nombre_estado.ToString(); estadoSec.AddElement(new Paragraph(nroSector + " " + estado, arialText)); estadoSec.BackgroundColor = BaseColor.YELLOW; estadoSec.HorizontalAlignment = 1; estadoSec.VerticalAlignment = 5; if (codEstado.Equals("S")) { estadoSec.BackgroundColor = BaseColor.WHITE; } tableSecVec.AddCell(estadoSec); } tableSecVec.AddCell(""); PdfPCell cellEstadosSec = new PdfPCell(tableSecVec); PdfPTable tableObs = new PdfPTable(1); PdfPCell titleObs = new PdfPCell(new Paragraph("OBSERVACIONES GENERALES", arialText)); titleObs.HorizontalAlignment = 1; titleObs.VerticalAlignment = 5; titleObs.BackgroundColor = BaseColor.LIGHT_GRAY; PdfPCell cellObs = new PdfPCell(new Paragraph(planCons.Observacion, arialText)); tableObs.AddCell(titleObs); tableObs.AddCell(cellObs); PdfPCell obs = new PdfPCell(tableObs); detailConte.AddCell(cellFotoCont); detailConte.AddCell(cellEstadosSec); detailConte.AddCell(obs); //tabla detalles personas DataTable personasT = new PersonasBLL().sp_sel_personasExpoBLL(nroTarja); string movilizadores = string.Empty; string horquillero = string.Empty; string grua = string.Empty; foreach (DataRow row in personasT.Rows) { if (row["FUNCION"].ToString() == "Movilizador") { movilizadores += row["nom_persona"].ToString() + "\n"; } else { horquillero = row["nom_persona"].ToString(); } } grua = new GruasDescBLL().sp_sel_gruaExpoBLL(nroTarja); PdfPTable tablapersonas = new PdfPTable(4); tablapersonas.WidthPercentage = 100; //row1 PdfPCell titlegrua = new PdfPCell(new Paragraph("GRUA", arialText)); titlegrua.BackgroundColor = BaseColor.LIGHT_GRAY; titlegrua.HorizontalAlignment = 1; titlegrua.VerticalAlignment = 5; PdfPCell cellgrua = new PdfPCell(new Paragraph(grua, arialText)); cellgrua.HorizontalAlignment = 1; cellgrua.VerticalAlignment = 5; PdfPCell titlemovilizadores = new PdfPCell(new Paragraph("MOVILIZADORES", arialText)); titlemovilizadores.BackgroundColor = BaseColor.LIGHT_GRAY; titlemovilizadores.HorizontalAlignment = 1; titlemovilizadores.VerticalAlignment = 5; PdfPCell titletarjador = new PdfPCell(new Paragraph("TARJADOR", arialText)); titletarjador.HorizontalAlignment = 1; titletarjador.VerticalAlignment = 5; titletarjador.BackgroundColor = BaseColor.LIGHT_GRAY; //row2 PdfPCell titlehorquillero = new PdfPCell(new Paragraph("HORQUILLERO", arialText)); titlehorquillero.BackgroundColor = BaseColor.LIGHT_GRAY; titlehorquillero.HorizontalAlignment = 1; titlehorquillero.VerticalAlignment = 5; PdfPCell cellhorquillero = new PdfPCell(new Paragraph(horquillero, arialText)); cellhorquillero.HorizontalAlignment = 1; cellhorquillero.VerticalAlignment = 5; PdfPCell cellmovilizadeores = new PdfPCell(new Paragraph(movilizadores, arialText)); titlemovilizadores.HorizontalAlignment = 1; titlemovilizadores.VerticalAlignment = 5; PdfPCell celltarjador = new PdfPCell(new Paragraph(tarjador.Nom_persona, arialText)); titletarjador.HorizontalAlignment = 1; titletarjador.VerticalAlignment = 5; PdfPCell vacio2 = new PdfPCell(new Paragraph("", arialText)); vacio2.Border = 0; tablapersonas.AddCell(titlegrua); tablapersonas.AddCell(cellgrua); tablapersonas.AddCell(titlemovilizadores); tablapersonas.AddCell(titletarjador); tablapersonas.AddCell(titlehorquillero); tablapersonas.AddCell(cellhorquillero); tablapersonas.AddCell(cellmovilizadeores); tablapersonas.AddCell(celltarjador); //Tabla Merc PdfPTable detalleMerc = new PdfPTable(4); detalleMerc.WidthPercentage = 100; PdfPCell titlemarca = new PdfPCell(new Paragraph("MARCAS/NUMEROS", arialText)); titlemarca.HorizontalAlignment = 1; titlemarca.VerticalAlignment = 5; titlemarca.BackgroundColor = BaseColor.LIGHT_GRAY; titlemarca.Border = 15; detalleMerc.AddCell(titlemarca); PdfPCell titlebulto = new PdfPCell(new Paragraph("TIPO BULTO", arialText)); titlebulto.HorizontalAlignment = 1; titlebulto.VerticalAlignment = 5; titlebulto.Border = 15; titlebulto.BackgroundColor = BaseColor.LIGHT_GRAY; detalleMerc.AddCell(titlebulto); PdfPCell titlecantidad = new PdfPCell(new Paragraph("CANTIDAD", arialText)); titlecantidad.HorizontalAlignment = 1; titlecantidad.VerticalAlignment = 5; titlecantidad.BackgroundColor = BaseColor.LIGHT_GRAY; titlecantidad.Border = 15; detalleMerc.AddCell(titlecantidad); PdfPCell titleobs = new PdfPCell(new Paragraph("OBSERVACIONES", arialText)); titleobs.HorizontalAlignment = 1; titleobs.VerticalAlignment = 5; titleobs.BackgroundColor = BaseColor.LIGHT_GRAY; titleobs.Border = 15; detalleMerc.AddCell(titleobs); PdfPCell cellmarca, cellbultos, cellcantidad, cellobs, celltotal; string nomBulto = "", marca = ""; int suma = 0; int cantidad = 0; Int64[] codigosMerc; List <MercanciaExpoBO> listMercs = null; foreach (DocumentoConsigBO docConsig in listaDocs) { string jsonMercs = new MercanciaExpoBLL().sp_sel_mercExpoBLL(docConsig.Nro_documento, docConsig.Nro_tarja); listMercs = JsonConvert.DeserializeObject <List <MercanciaExpoBO> >(jsonMercs); foreach (MercanciaExpoBO merc in listMercs) { marca = merc.Gls_marca; cantidad = merc.N_cantidad; suma += cantidad; nomBulto = new BultosBLL().sp_sel_bultosIDBLL(merc.N_bulto).Rows[0].ItemArray[1].ToString(); cellmarca = new PdfPCell(new Paragraph(marca, arialText)); cellmarca.HorizontalAlignment = 1; cellmarca.VerticalAlignment = 5; cellmarca.Border = 15; detalleMerc.AddCell(cellmarca); cellbultos = new PdfPCell(new Paragraph(nomBulto, arialText)); cellmarca.HorizontalAlignment = 1; cellmarca.VerticalAlignment = 5; cellmarca.Border = 15; detalleMerc.AddCell(cellbultos); cellcantidad = new PdfPCell(new Paragraph(cantidad.ToString(), arialText)); cellmarca.HorizontalAlignment = 1; cellmarca.VerticalAlignment = 5; cellmarca.Border = 15; detalleMerc.AddCell(cellcantidad); cellobs = new PdfPCell(new Paragraph("")); cellmarca.HorizontalAlignment = 1; cellmarca.VerticalAlignment = 5; cellmarca.Border = 15; detalleMerc.AddCell(cellobs); } } celltotal = new PdfPCell(new Paragraph(suma.ToString(), arialText)); celltotal.HorizontalAlignment = 1; celltotal.VerticalAlignment = 5; celltotal.Border = 15; PdfPCell cellnada = new PdfPCell(new Paragraph("")); cellnada.Border = 0; detalleMerc.AddCell(cellnada); PdfPCell titletotal = new PdfPCell(new Paragraph("TOTAL", arialText)); titletotal.Border = 15; titletotal.HorizontalAlignment = 1; titletotal.VerticalAlignment = 5; titletotal.BackgroundColor = BaseColor.LIGHT_GRAY; detalleMerc.AddCell(titletotal); detalleMerc.AddCell(celltotal); detalleMerc.AddCell(cellnada); Paragraph salto = new Paragraph(); salto.Add("\n"); Paragraph p1 = new Paragraph(); p1.Add(tableHeader); Paragraph p2 = new Paragraph(); p2.Add(detailTable); Paragraph p3 = new Paragraph(); p3.Add(detailConte); Paragraph p4 = new Paragraph(); p4.Add(tablapersonas); Paragraph p5 = new Paragraph(); p5.Add(detalleMerc); doc.Add(p1); doc.Add(salto); doc.Add(salto); doc.Add(p2); doc.Add(p3); doc.Add(p4); doc.Add(salto); doc.Add(p5); PdfPTable tablefotos = new PdfPTable(3); tablefotos.WidthPercentage = 100; PdfPCell titletable = new PdfPCell(new Paragraph("FOTOGRAFIAS CONSOLIDADO", arialText)); titletable.Border = 15; titletable.HorizontalAlignment = 1; titletable.VerticalAlignment = 5; titletable.BackgroundColor = BaseColor.LIGHT_GRAY; PdfPCell cellnombrefoto; PdfPTable subtabla = new PdfPTable(1); PdfPCell cellfotografias; #pragma warning disable CS0168 // La variable 'cellfoto' se ha declarado pero nunca se usa PdfPCell cellfoto; #pragma warning restore CS0168 // La variable 'cellfoto' se ha declarado pero nunca se usa string base64Img = ""; string nombreImg = string.Empty; var doctypeConsCnt = ConfigurationManager.AppSettings["FDM:DocTypeConsCnt"].ToString(); var doctypeMercCons = ConfigurationManager.AppSettings["FDM:DocTypeMercCons"].ToString(); var fechaLimiteStr = ConfigurationManager.AppSettings["FechaLimite"].ToString().Split('-'); DateTime fechaLimite = new DateTime(Convert.ToInt32(fechaLimiteStr[0]), Convert.ToInt32(fechaLimiteStr[1]), Convert.ToInt32(fechaLimiteStr[2])); if (planCons.Fecha < fechaLimite) { try { byte[] imageBytes; List <FotoContenedorBO> listFotos = new FotoContenedorBLL().sp_sel_fotoConsoBLL(nroTarja); foreach (FotoContenedorBO fotoCont in listFotos) { if (!nombreImg.Equals(fotoCont.Gls_nombreImg)) { if (string.IsNullOrEmpty(nombreImg)) { nombreImg = fotoCont.Gls_nombreImg; base64Img = fotoCont.Gls_imagen; } else { if (base64Img.Length % 4 != 0) { string len = (base64Img.Length % 4).ToString(); } else { imageBytes = Convert.FromBase64String(base64Img); Image foto = Image.GetInstance(imageBytes); foto.ScaleAbsolute(159f, 159f); cellnombrefoto = new PdfPCell(new Paragraph("FOTO CONSOLIDADO", arialText)); cellnombrefoto.HorizontalAlignment = 1; cellnombrefoto.VerticalAlignment = 5; subtabla = new PdfPTable(1); subtabla.AddCell(new PdfPCell(foto) { HorizontalAlignment = 1, VerticalAlignment = 5 }); subtabla.AddCell(cellnombrefoto); cellfotografias = new PdfPCell(subtabla); cellfotografias.HorizontalAlignment = 1; cellfotografias.VerticalAlignment = 5; tablefotos.AddCell(cellfotografias); } base64Img = fotoCont.Gls_imagen; nombreImg = fotoCont.Gls_nombreImg; } } else { if (!string.IsNullOrEmpty(nombreImg)) { var parte = fotoCont.Gls_imagen; var largo = parte.Length; base64Img += "" + parte; } } } if (!string.IsNullOrEmpty(nombreImg)) { imageBytes = Convert.FromBase64String(base64Img); Image foto2 = Image.GetInstance(imageBytes); foto2.ScaleAbsolute(159f, 159f); cellnombrefoto = new PdfPCell(new Paragraph("FOTO CONSOLIDADO", arialText)); cellnombrefoto.HorizontalAlignment = 1; cellnombrefoto.VerticalAlignment = 5; subtabla = new PdfPTable(1); subtabla.AddCell(new PdfPCell(foto2) { HorizontalAlignment = 1, VerticalAlignment = 5 }); subtabla.AddCell(cellnombrefoto); cellfotografias = new PdfPCell(subtabla); cellfotografias.HorizontalAlignment = 1; cellfotografias.VerticalAlignment = 5; tablefotos.AddCell(cellfotografias); } nombreImg = ""; } catch (Exception ex) { Console.WriteLine("Ha ocurrido un error: " + ex.ToString()); } } else { try { List <FotografiasFDM> listFotos = new FotografiasFDM().obtenerFotografias(doctypeConsCnt, nroTarja.ToString()); foreach (FotografiasFDM fotoCont in listFotos) { Image foto2 = Image.GetInstance(new Uri(fotoCont.url_foto)); foto2.ScaleAbsolute(159f, 159f); cellnombrefoto = new PdfPCell(new Paragraph("FOTO CONSOLIDADO", arialText)); cellnombrefoto.HorizontalAlignment = 1; cellnombrefoto.VerticalAlignment = 5; subtabla = new PdfPTable(1); subtabla.AddCell(new PdfPCell(foto2) { HorizontalAlignment = 1, VerticalAlignment = 5 }); subtabla.AddCell(cellnombrefoto); cellfotografias = new PdfPCell(subtabla); cellfotografias.HorizontalAlignment = 1; cellfotografias.VerticalAlignment = 5; tablefotos.AddCell(cellfotografias); } } catch (Exception ex) { Console.WriteLine("Ha ocurrido un error: " + ex.ToString()); } } foreach (DocumentoConsigBO docConsig in listaDocs) { //documento PdfPTable documento = new PdfPTable(6); //row1 documento.AddCell(TitleCliente); documento.AddCell(cellcliente); documento.AddCell(cellnada); documento.AddCell(cellnada); documento.AddCell(celltitlefecha); documento.AddCell(cellfecha); //row2 documento.AddCell(celltitlenave); documento.AddCell(cellnave); documento.AddCell(cellnada); documento.AddCell(cellnada); documento.AddCell(titledestino); documento.AddCell(celldestino); //row3 documento.AddCell(titlecontenedor); documento.AddCell(cellcontenedor); PdfPCell titleviaje = new PdfPCell(new Paragraph(("VIAJE"), arialText)); titleviaje.HorizontalAlignment = 1; titleviaje.VerticalAlignment = 5; titleviaje.BackgroundColor = BaseColor.LIGHT_GRAY; titleviaje.Border = 15; documento.AddCell(titleviaje); PdfPCell cellviaje = new PdfPCell(new Paragraph(planCons.N_viaje.ToString(), arialText)); cellviaje.HorizontalAlignment = 1; cellviaje.VerticalAlignment = 5; cellviaje.Border = 15; documento.AddCell(cellviaje); PdfPCell titleReserva = new PdfPCell(new Paragraph("RESERVA", arialText)); titleReserva.HorizontalAlignment = 1; titleReserva.VerticalAlignment = 5; titleReserva.BackgroundColor = BaseColor.LIGHT_GRAY; titleReserva.Border = 15; PdfPCell cellReserva = new PdfPCell(new Paragraph(planCons.Gls_reserva, arialText)); cellReserva.HorizontalAlignment = 1; cellReserva.VerticalAlignment = 5; cellReserva.Border = 15; documento.AddCell(titleReserva); documento.AddCell(cellReserva); PdfPTable datosDoc = new PdfPTable(2); PdfPTable participantesDoc = new PdfPTable(2); participantesDoc.DefaultCell.Border = 0; PdfPCell titledres = new PdfPCell(new Paragraph("DRES", arialText)); titledres.HorizontalAlignment = 1; titledres.VerticalAlignment = 5; titledres.Border = 15; titledres.BackgroundColor = BaseColor.LIGHT_GRAY; PdfPCell celldres = new PdfPCell(new Paragraph(docConsig.Gls_dres, arialText)); celldres.HorizontalAlignment = 1; celldres.VerticalAlignment = 5; celldres.Border = 15; PdfPCell titleconsignante = new PdfPCell(new Paragraph("CONSIGNANTE", arialText)); titleconsignante.HorizontalAlignment = 1; titleconsignante.VerticalAlignment = 5; titleconsignante.Border = 15; titleconsignante.BackgroundColor = BaseColor.LIGHT_GRAY; PdfPCell cellconsignante = new PdfPCell(new Paragraph(docConsig.Gls_consignante, arialText)); cellconsignante.HorizontalAlignment = 1; cellconsignante.VerticalAlignment = 5; cellconsignante.Border = 15; PdfPCell titleconsignatario = new PdfPCell(new Paragraph("CONSIGNATARIO", arialText)); titleconsignatario.HorizontalAlignment = 1; titleconsignatario.VerticalAlignment = 5; titleconsignatario.Border = 15; titleconsignatario.BackgroundColor = BaseColor.LIGHT_GRAY; PdfPCell cellconsignatario = new PdfPCell(new Paragraph(docConsig.Gls_consignatario, arialText)); cellconsignatario.HorizontalAlignment = 1; cellconsignatario.VerticalAlignment = 5; cellconsignatario.Border = 15; PdfPCell titledespachante = new PdfPCell(new Paragraph("DESPACHANTE", arialText)); titledespachante.HorizontalAlignment = 1; titledespachante.VerticalAlignment = 5; titledespachante.Border = 15; titledespachante.BackgroundColor = BaseColor.LIGHT_GRAY; PdfPCell celldespachante = new PdfPCell(new Paragraph(docConsig.Gls_despachante, arialText)); celldespachante.HorizontalAlignment = 1; celldespachante.VerticalAlignment = 5; celldespachante.Border = 15; participantesDoc.AddCell(titledres); participantesDoc.AddCell(celldres); participantesDoc.AddCell(titleconsignante); participantesDoc.AddCell(cellconsignante); participantesDoc.AddCell(titleconsignatario); participantesDoc.AddCell(cellconsignatario); participantesDoc.AddCell(titledespachante); participantesDoc.AddCell(celldespachante); datosDoc.AddCell(new PdfPCell(participantesDoc)); datosDoc.DefaultCell.Border = 0; PdfPTable nombreDoc = new PdfPTable(2); nombreDoc.DefaultCell.Border = 0; nombreDoc.AddCell(cellnada); PdfPCell nombreDocum = new PdfPCell(new Paragraph(new TIpoDocumentoBLL().sp_sel_tipoDocIDBLL(docConsig.Tipo_documento) + "\n" + docConsig.Nro_documento, arialHeading)); nombreDocum.HorizontalAlignment = 1; nombreDocum.VerticalAlignment = 5; nombreDocum.Border = 15; nombreDocum.Colspan = 2; nombreDoc.AddCell(nombreDocum); PdfPCell nombreDocumento = new PdfPCell(nombreDoc); nombreDocumento.Border = 0; datosDoc.AddCell((nombreDocumento)); PdfPTable detalleMercDoc = new PdfPTable(5); detalleMercDoc.WidthPercentage = 100; PdfPCell titlemarcas = new PdfPCell(new Paragraph("MARCAS/NUMEROS", arialText)); titlemarcas.HorizontalAlignment = 1; titlemarcas.VerticalAlignment = 5; titlemarcas.BackgroundColor = BaseColor.LIGHT_GRAY; titlemarcas.Border = 15; detalleMercDoc.AddCell(titlemarcas); PdfPCell titlecontenido = new PdfPCell(new Paragraph("CONTENIDO", arialText)); titlecontenido.HorizontalAlignment = 1; titlecontenido.VerticalAlignment = 5; titlecontenido.BackgroundColor = BaseColor.LIGHT_GRAY; titlecontenido.Border = 15; detalleMercDoc.AddCell(titlecontenido); PdfPCell titlebultos = new PdfPCell(new Paragraph("TIPO BULTO", arialText)); titlebultos.HorizontalAlignment = 1; titlebultos.VerticalAlignment = 5; titlebultos.Border = 15; titlebultos.BackgroundColor = BaseColor.LIGHT_GRAY; detalleMercDoc.AddCell(titlebultos); PdfPCell titlecantidades = new PdfPCell(new Paragraph("CANTIDAD", arialText)); titlecantidades.HorizontalAlignment = 1; titlecantidades.VerticalAlignment = 5; titlecantidades.BackgroundColor = BaseColor.LIGHT_GRAY; titlecantidades.Border = 15; detalleMercDoc.AddCell(titlecantidades); PdfPCell titlekilos = new PdfPCell(new Paragraph("KILOS", arialText)); titlekilos.HorizontalAlignment = 1; titlekilos.VerticalAlignment = 5; titlekilos.BackgroundColor = BaseColor.LIGHT_GRAY; titlekilos.Border = 15; detalleMercDoc.AddCell(titlekilos); string jsonMercs = new MercanciaExpoBLL().sp_sel_mercExpoBLL(docConsig.Nro_documento, docConsig.Nro_tarja); listMercs = JsonConvert.DeserializeObject <List <MercanciaExpoBO> >(jsonMercs); codigosMerc = new Int64[listMercs.Count]; int i = 0; foreach (MercanciaExpoBO merc in listMercs) { marca = merc.Gls_marca; cantidad = Convert.ToInt32(merc.N_cantidad); suma += cantidad; codigosMerc[i] = Convert.ToInt64(merc.Cod_mercancia); i++; nomBulto = new BultosBLL().sp_sel_bultosIDBLL(merc.N_bulto).Rows[0].ItemArray[1].ToString(); cellmarca = new PdfPCell(new Paragraph(marca, arialText)); cellmarca.HorizontalAlignment = 1; cellmarca.VerticalAlignment = 5; cellmarca.Border = 15; detalleMercDoc.AddCell(cellmarca); PdfPCell cellContenido = new PdfPCell(new Paragraph(merc.Gls_contenido, arialText)); cellContenido.HorizontalAlignment = 1; cellContenido.VerticalAlignment = 5; cellContenido.Border = 15; detalleMercDoc.AddCell(cellContenido); cellbultos = new PdfPCell(new Paragraph(nomBulto, arialText)); cellmarca.HorizontalAlignment = 1; cellmarca.VerticalAlignment = 5; cellmarca.Border = 15; detalleMercDoc.AddCell(cellbultos); cellcantidad = new PdfPCell(new Paragraph(cantidad.ToString(), arialText)); cellmarca.HorizontalAlignment = 1; cellmarca.VerticalAlignment = 5; cellmarca.Border = 15; detalleMercDoc.AddCell(cellcantidad); PdfPCell cellkilos = new PdfPCell(new Paragraph(merc.F_peso.ToString(), arialText)); cellkilos.HorizontalAlignment = 1; cellkilos.VerticalAlignment = 5; cellkilos.Border = 15; detalleMercDoc.AddCell(cellkilos); } if (planCons.Fecha < fechaLimite) { foreach (Int64 codigo in codigosMerc) { try { byte[] imageBytes; string marcaMerc = ""; string nombreImagen = string.Empty; List <FotoMercanciaBO> listFotoMerc = new FotoMercanciaBLL().sp_sel_fotoMercExpoBLL(codigo); marcaMerc = new MercanciaExpoBLL().sp_sel_marcaMercBLL(codigo); foreach (FotoMercanciaBO fotoMerc in listFotoMerc) { if (!nombreImagen.Equals(fotoMerc.Gls_nombreImg)) { if (string.IsNullOrEmpty(nombreImagen)) { nombreImagen = fotoMerc.Gls_nombreImg; base64Img = fotoMerc.Gls_imagen; } else { if (base64Img.Length % 4 != 0) { string len = (base64Img.Length % 4).ToString(); } else { imageBytes = Convert.FromBase64String(base64Img); Image foto = Image.GetInstance(imageBytes); foto.ScaleAbsolute(159f, 159f); cellnombrefoto = new PdfPCell(new Paragraph(marcaMerc, arialText)); cellnombrefoto.HorizontalAlignment = 1; cellnombrefoto.VerticalAlignment = 5; subtabla = new PdfPTable(1); subtabla.AddCell(new PdfPCell(foto) { HorizontalAlignment = 1, VerticalAlignment = 5 }); subtabla.AddCell(cellnombrefoto); cellfotografias = new PdfPCell(subtabla); cellfotografias.HorizontalAlignment = 1; cellfotografias.VerticalAlignment = 5; tablefotos.AddCell(cellfotografias); } nombreImagen = fotoMerc.Gls_nombreImg; base64Img = fotoMerc.Gls_imagen; } } else { if (!string.IsNullOrEmpty(nombreImagen)) { var parte = fotoMerc.Gls_imagen; var largo = parte.Length; base64Img += "" + parte; } } } imageBytes = Convert.FromBase64String(base64Img); Image foto2 = Image.GetInstance(imageBytes); foto2.ScaleAbsolute(159f, 159f); cellnombrefoto = new PdfPCell(new Paragraph(marcaMerc, arialText)); cellnombrefoto.HorizontalAlignment = 1; cellnombrefoto.VerticalAlignment = 5; subtabla = new PdfPTable(1); subtabla.AddCell(new PdfPCell(foto2) { HorizontalAlignment = 1, VerticalAlignment = 5 }); subtabla.AddCell(cellnombrefoto); cellfotografias = new PdfPCell(subtabla); cellfotografias.HorizontalAlignment = 1; cellfotografias.VerticalAlignment = 5; tablefotos.AddCell(cellfotografias); } catch (Exception ex) { Console.WriteLine("Ha ocurrido un error: " + ex.ToString()); } } } else { foreach (Int64 codigo in codigosMerc) { try { string marcaMerc = ""; List <FotografiasFDM> listFotoMerc = new FotografiasFDM().obtenerFotografias(doctypeMercCons, codigo.ToString()); marcaMerc = new MercanciaExpoBLL().sp_sel_marcaMercBLL(codigo); foreach (FotografiasFDM fotoMerc in listFotoMerc) { Image foto2 = Image.GetInstance(new Uri(fotoMerc.url_foto)); foto2.ScaleAbsolute(159f, 159f); cellnombrefoto = new PdfPCell(new Paragraph(marcaMerc, arialText)); cellnombrefoto.HorizontalAlignment = 1; cellnombrefoto.VerticalAlignment = 5; subtabla = new PdfPTable(1); subtabla.AddCell(new PdfPCell(foto2) { HorizontalAlignment = 1, VerticalAlignment = 5 }); subtabla.AddCell(cellnombrefoto); cellfotografias = new PdfPCell(subtabla); cellfotografias.HorizontalAlignment = 1; cellfotografias.VerticalAlignment = 5; tablefotos.AddCell(cellfotografias); } } catch (Exception ex) { Console.WriteLine("Ha ocurrido un error: " + ex.ToString()); } } } tablefotos.AddCell(vacio1); tablefotos.AddCell(vacio1); doc.NewPage(); doc.Add(logo); doc.Add(salto); doc.Add(salto); doc.Add(documento); doc.Add(salto); doc.Add(salto); doc.Add(datosDoc); doc.Add(salto); doc.Add(detalleMercDoc); } doc.NewPage(); doc.Add(tablefotos); return(doc); }
public MemoryStream crearZip(Int64 nroTarja, DateTime fecha) { MemoryStream memo = new MemoryStream(); Int64[] codigosMerc; List <MercanciasDescBO> listMerc = null; var doctypeDesCnt = ConfigurationManager.AppSettings["FDM:DocTypeDescCnt"].ToString(); var docTypeMercDes = ConfigurationManager.AppSettings["FDM:DocTypeMercDesc"].ToString(); String base64Img = ""; var fechaLimiteStr = ConfigurationManager.AppSettings["FechaLimite"].ToString().Split('-'); DateTime fechaLimite = new DateTime(Convert.ToInt32(fechaLimiteStr[0]), Convert.ToInt32(fechaLimiteStr[1]), Convert.ToInt32(fechaLimiteStr[2])); if (fecha < fechaLimite) { try { listMerc = new MercanciasDescBll().sp_sel_mercDescBLL(nroTarja); int i = 0; codigosMerc = new Int64[listMerc.Count]; foreach (MercanciasDescBO mercs in listMerc) { codigosMerc[i] = mercs.Cod_mercancia; i++; } } catch (Exception ex) { throw new Exception("Ha ocurrido un error: " + ex.ToString()); } using (ZipFile zip = new ZipFile()) { try { byte[] imageBytes; List <FotoContenedorBO> listFotos = new FotoContenedorBLL().sp_sel_fotoContDescBLL(nroTarja); string nombreImagen = string.Empty; foreach (FotoContenedorBO fotoCl in listFotos) { if (!nombreImagen.Equals(fotoCl.Gls_nombreImg)) { if (string.IsNullOrEmpty(nombreImagen)) { nombreImagen = fotoCl.Gls_nombreImg; base64Img = fotoCl.Gls_imagen; } else { if (base64Img.Length % 4 != 0) { string len = (base64Img.Length % 4).ToString(); } else { imageBytes = Convert.FromBase64String(base64Img); zip.AddEntry(nombreImagen, imageBytes); } nombreImagen = fotoCl.Gls_nombreImg; base64Img = fotoCl.Gls_imagen; } } else { if (!string.IsNullOrEmpty(nombreImagen)) { var parte = fotoCl.Gls_imagen; var largo = parte.Length; base64Img += "" + parte; } } } if (!string.IsNullOrEmpty(base64Img)) { imageBytes = Convert.FromBase64String(base64Img); zip.AddEntry(nombreImagen, imageBytes); } base64Img = ""; nombreImagen = ""; } catch (Exception ex) { throw new Exception("Ha ocurrido un error: " + ex.ToString()); } foreach (Int64 codigo in codigosMerc) { try { byte[] imageBytes; string marcaMerc = ""; string nombreImagen = string.Empty; List <FotoMercanciaBO> listFotoMerc = new FotoMercanciaBLL().sp_sel_fotoMercDescBLL(codigo); marcaMerc = new MercanciasDescBll().sp_sel_marcaMercBLL(codigo); foreach (FotoMercanciaBO fotoMerc in listFotoMerc) { if (!nombreImagen.Equals(fotoMerc.Gls_nombreImg)) { if (string.IsNullOrEmpty(nombreImagen)) { nombreImagen = fotoMerc.Gls_nombreImg; base64Img = fotoMerc.Gls_imagen; } else { if (base64Img.Length % 4 != 0) { string len = (base64Img.Length % 4).ToString(); } else { imageBytes = Convert.FromBase64String(base64Img); zip.AddEntry(nombreImagen, imageBytes); } nombreImagen = fotoMerc.Gls_nombreImg; base64Img = fotoMerc.Gls_imagen; } } else { if (!string.IsNullOrEmpty(nombreImagen)) { var parte = fotoMerc.Gls_imagen; var largo = parte.Length; base64Img += "" + parte; } } } if (!string.IsNullOrEmpty(nombreImagen)) { imageBytes = Convert.FromBase64String(base64Img); zip.AddEntry(nombreImagen, imageBytes); nombreImagen = ""; base64Img = ""; } } catch (Exception ex) { throw new Exception("Ha ocurrido un error: " + ex.ToString()); } } try { byte[] imageBytes; string nombreImagen = string.Empty; List <FotoContenedorBO> listFotosFin = new FotoContenedorBLL().sp_sel_fotoContFinBLL(nroTarja); foreach (FotoContenedorBO fotoFin in listFotosFin) { if (!nombreImagen.Equals(fotoFin.Gls_nombreImg)) { if (string.IsNullOrEmpty(nombreImagen)) { nombreImagen = fotoFin.Gls_nombreImg; base64Img = fotoFin.Gls_imagen; } else { if (base64Img.Length % 4 != 0) { string len = (base64Img.Length % 4).ToString(); } else { imageBytes = Convert.FromBase64String(base64Img); zip.AddEntry(nombreImagen, imageBytes); } nombreImagen = fotoFin.Gls_nombreImg; base64Img = fotoFin.Gls_imagen; } } else { if (!string.IsNullOrEmpty(nombreImagen)) { var parte = fotoFin.Gls_imagen; var largo = parte.Length; base64Img += "" + parte; } } } if (!string.IsNullOrEmpty(nombreImagen)) { imageBytes = Convert.FromBase64String(base64Img); base64Img = Convert.ToBase64String(imageBytes); zip.AddEntry(nombreImagen, imageBytes); } nombreImagen = ""; base64Img = ""; } catch (Exception ex) { throw new Exception("Ha ocurrido un error: " + ex.ToString()); } zip.Save(memo); } } else { try { listMerc = new MercanciasDescBll().sp_sel_mercDescBLL(nroTarja); int i = 0; codigosMerc = new Int64[listMerc.Count]; foreach (MercanciasDescBO mercs in listMerc) { codigosMerc[i] = mercs.Cod_mercancia; i++; } } catch (Exception ex) { throw new Exception("Ha ocurrido un error: " + ex.ToString()); } using (ZipFile zip = new ZipFile()) { try { List <FotografiasFDM> listFotos = new FotografiasFDM().obtenerFotografias(doctypeDesCnt, nroTarja.ToString()); string nombreImagen = string.Empty; foreach (FotografiasFDM fotoCl in listFotos) { nombreImagen = fotoCl.nombre_foto; using (var webClient = new WebClient()) { byte[] imageBytes = webClient.DownloadData(fotoCl.url_foto); zip.AddEntry(nombreImagen, imageBytes); } } } catch (Exception ex) { throw new Exception("Ha ocurrido un error: " + ex.ToString()); } foreach (Int64 codigo in codigosMerc) { try { byte[] imageBytes; string marcaMerc = ""; string nombreImagen = string.Empty; List <FotografiasFDM> listFotoMerc = new FotografiasFDM().obtenerFotografias(docTypeMercDes, codigo.ToString()); marcaMerc = new MercanciasDescBll().sp_sel_marcaMercBLL(codigo); foreach (FotografiasFDM fotoMerc in listFotoMerc) { nombreImagen = marcaMerc + "-" + fotoMerc.nombre_foto; using (var webClient = new WebClient()) { imageBytes = webClient.DownloadData(fotoMerc.url_foto); zip.AddEntry(nombreImagen, imageBytes); } } } catch (Exception ex) { throw new Exception("Ha ocurrido un error: " + ex.ToString()); } } zip.Save(memo); } } return(memo); }
public MemoryStream crearZip(Int64 nroTarja, DateTime fecha) { var fechaLimiteStr = ConfigurationManager.AppSettings["FechaLimite"].ToString().Split('-'); DateTime fechaLimite = new DateTime(Convert.ToInt32(fechaLimiteStr[0]), Convert.ToInt32(fechaLimiteStr[1]), Convert.ToInt32(fechaLimiteStr[2])); MemoryStream memo = new MemoryStream(); List <DocumentoConsigBO> listaDocs; string jsonDocsConsig = string.Empty; string base64Img = ""; List <MercanciaExpoBO> listMercs = null; string nombreImg = string.Empty; jsonDocsConsig = new DocumentoConsigBLL().sp_sel_documentosIDBLL(nroTarja); listaDocs = JsonConvert.DeserializeObject <List <DocumentoConsigBO> >(jsonDocsConsig); var doctypeConsCnt = ConfigurationManager.AppSettings["FDM:DocTypeConsCnt"].ToString(); var doctypeMercCons = ConfigurationManager.AppSettings["FDM:DocTypeMercCons"].ToString(); if (fecha < fechaLimite) { using (ZipFile zip = new ZipFile()) { try { byte[] imageBytes; List <FotoContenedorBO> listFotos = new FotoContenedorBLL().sp_sel_fotoConsoBLL(nroTarja); foreach (FotoContenedorBO fotoCont in listFotos) { if (!nombreImg.Equals(fotoCont.Gls_nombreImg)) { if (string.IsNullOrEmpty(nombreImg)) { nombreImg = fotoCont.Gls_nombreImg; base64Img = fotoCont.Gls_imagen; } else { if (base64Img.Length % 4 != 0) { string len = (base64Img.Length % 4).ToString(); } else { imageBytes = Convert.FromBase64String(base64Img); zip.AddEntry(nombreImg, imageBytes); } base64Img = fotoCont.Gls_imagen; nombreImg = fotoCont.Gls_nombreImg; } } else { if (!string.IsNullOrEmpty(nombreImg)) { var parte = fotoCont.Gls_imagen; var largo = parte.Length; base64Img += "" + parte; } } } if (!string.IsNullOrEmpty(nombreImg)) { imageBytes = Convert.FromBase64String(base64Img); zip.AddEntry(nombreImg, imageBytes); } nombreImg = ""; } catch (Exception ex) { throw new Exception("Ha ocurrido un error: " + ex.ToString()); } foreach (DocumentoConsigBO docConsig in listaDocs) { string jsonMercs = new MercanciaExpoBLL().sp_sel_mercExpoBLL(docConsig.Nro_documento, docConsig.Nro_tarja); listMercs = JsonConvert.DeserializeObject <List <MercanciaExpoBO> >(jsonMercs); foreach (MercanciaExpoBO codigo in listMercs) { try { byte[] imageBytes; string nombreImagen = string.Empty; List <FotoMercanciaBO> listFotoMerc = new FotoMercanciaBLL().sp_sel_fotoMercExpoBLL(codigo.Cod_mercancia); foreach (FotoMercanciaBO fotoMerc in listFotoMerc) { if (!nombreImagen.Equals(fotoMerc.Gls_nombreImg)) { if (string.IsNullOrEmpty(nombreImagen)) { nombreImagen = fotoMerc.Gls_nombreImg; base64Img = fotoMerc.Gls_imagen; } else { if (base64Img.Length % 4 != 0) { string len = (base64Img.Length % 4).ToString(); } else { imageBytes = Convert.FromBase64String(base64Img); zip.AddEntry(nombreImagen, imageBytes); } nombreImagen = fotoMerc.Gls_nombreImg; base64Img = fotoMerc.Gls_imagen; } } else { if (!string.IsNullOrEmpty(nombreImagen)) { var parte = fotoMerc.Gls_imagen; var largo = parte.Length; base64Img += "" + parte; } } } } catch (Exception ex) { throw new Exception("Ha ocurrido un error: " + ex.ToString()); } } } zip.Save(memo); } } else { using (ZipFile zip = new ZipFile()) { try { byte[] imageBytes; List <FotografiasFDM> listFotos = new FotografiasFDM().obtenerFotografias(doctypeConsCnt, nroTarja.ToString()); foreach (FotografiasFDM fotoCont in listFotos) { nombreImg = fotoCont.nombre_foto; using (var webClient = new WebClient()) { imageBytes = webClient.DownloadData(fotoCont.url_foto); zip.AddEntry(nombreImg, imageBytes); } } } catch (Exception ex) { throw new Exception("Ha ocurrido un error: " + ex.ToString()); } foreach (DocumentoConsigBO docConsig in listaDocs) { string jsonMercs = new MercanciaExpoBLL().sp_sel_mercExpoBLL(docConsig.Nro_documento, docConsig.Nro_tarja); listMercs = JsonConvert.DeserializeObject <List <MercanciaExpoBO> >(jsonMercs); foreach (MercanciaExpoBO codigo in listMercs) { try { byte[] imageBytes; string nombreImagen = string.Empty; List <FotografiasFDM> listFotoMerc = new FotografiasFDM().obtenerFotografias(doctypeMercCons, codigo.Cod_mercancia.ToString()); foreach (FotografiasFDM fotoMerc in listFotoMerc) { nombreImagen = fotoMerc.nombre_foto; using (var webClient = new WebClient()) { imageBytes = webClient.DownloadData(fotoMerc.url_foto); zip.AddEntry(nombreImg, imageBytes); } } } catch (Exception ex) { throw new Exception("Ha ocurrido un error: " + ex.ToString()); } } } zip.Save(memo); } } return(memo); }
public Document BindingData(Document doc, PlanificacionDescBO planDesc, TarjaDescDetBO tarja) { string jsonCliente = JsonConvert.SerializeObject(new ForwardersBLL().sp_selPlanDesc_forwarderBLL(planDesc.Rut_cliente)); ForwardersBO cliente = JsonConvert.DeserializeObject <ForwardersBO>(jsonCliente.Trim(new char[] { '[', ']' })); string jsonNave = JsonConvert.SerializeObject(new NavesBLL().sp_sel_naveIDBLL(planDesc.Cod_nave)); NavesBO nave = JsonConvert.DeserializeObject <NavesBO>(jsonNave.Trim(new char[] { '[', ']' })); string jsonPuertoO = JsonConvert.SerializeObject(new PuertoBLL().sp_sel_puertoIDBLL(planDesc.Pue_codO)); PuertosBO puerto_or = JsonConvert.DeserializeObject <PuertosBO>(jsonPuertoO.Trim(new char[] { '[', ']' })); string jsonPuertoD = JsonConvert.SerializeObject(new PuertoBLL().sp_sel_puertoIDBLL(planDesc.Pue_codD)); PuertosBO puerto_dest = JsonConvert.DeserializeObject <PuertosBO>(jsonPuertoD.Trim(new char[] { '[', ']' })); string jsonTarjador = JsonConvert.SerializeObject(new PersonasBLL().sp_sel_personasIDBLL(planDesc.Rut_tarjador)); PersonasBO tarjador = JsonConvert.DeserializeObject <PersonasBO>(jsonTarjador.Trim(new char[] { '[', ']' })); DataTable personasT = new PersonasBLL().sp_sel_personasTarjaBLL(tarja.Nro_tarja); string movilizadores = string.Empty; string horquillero = string.Empty; foreach (DataRow row in personasT.Rows) { if (row["FUNCION"].ToString() == "Movilizador") { movilizadores += row["nom_persona"].ToString() + "\n"; } else { horquillero = row["nom_persona"].ToString(); } } var settings = new BarCodeSettings { Type = BarCodeType.Code128, Data = tarja.Nro_tarja.ToString() }; var generator = new BarCodeGenerator(settings); Image imgbarcode; using (var barcodeImage = generator.GenerateImage()) { ImageFormat format = ImageFormat.Bmp; imgbarcode = Image.GetInstance(barcodeImage, format); imgbarcode.ScalePercent(100f); } Font arialHeading = FontFactory.GetFont("Arial", 15, 1); Font arialText = FontFactory.GetFont("Arial", 10, 1); string logoPath = HostingEnvironment.MapPath("~/assets/custom/images"); //Añadir encabezado PdfPTable tableHeader = new PdfPTable(3); PdfPCell subheader = new PdfPCell(imgbarcode); subheader.HorizontalAlignment = 1; subheader.VerticalAlignment = 5; subheader.Border = 0; tableHeader.WidthPercentage = 100; tableHeader.DefaultCell.Border = 0; tableHeader.DefaultCell.HorizontalAlignment = 1; tableHeader.DefaultCell.VerticalAlignment = 5; Image logo = Image.GetInstance(logoPath + "/logo.png"); tableHeader.AddCell(logo); Paragraph titulo = new Paragraph("Documento de Desconsolidado", arialHeading); tableHeader.AddCell(titulo); tableHeader.AddCell(subheader); //Añadir Tabla de detalles PdfPTable detailTable = new PdfPTable(6); detailTable.WidthPercentage = 100; detailTable.DefaultCell.Padding = 4.5f; detailTable.DefaultCell.Border = 15; detailTable.DefaultCell.HorizontalAlignment = 1; detailTable.DefaultCell.VerticalAlignment = 5; //row1 inicializacion PdfPCell TitleCliente = new PdfPCell(new Paragraph("Cliente", arialText)); TitleCliente.BackgroundColor = BaseColor.LIGHT_GRAY; TitleCliente.HorizontalAlignment = 1; TitleCliente.VerticalAlignment = 5; PdfPCell cellrutCliente = new PdfPCell(new Paragraph(cliente.Rut_cliente + "-" + cliente.Dv_cliente, arialText)); cellrutCliente.HorizontalAlignment = 1; cellrutCliente.VerticalAlignment = 5; PdfPCell cellcliente = new PdfPCell(new Paragraph(cliente.Nombre_cliente, arialText)); cellcliente.HorizontalAlignment = 1; cellcliente.VerticalAlignment = 5; PdfPCell vacio1 = new PdfPCell(new Paragraph("")); PdfPCell celltitlecontainer = new PdfPCell(new Paragraph("Contenedor", arialText)); celltitlecontainer.HorizontalAlignment = 1; celltitlecontainer.VerticalAlignment = 5; celltitlecontainer.BackgroundColor = BaseColor.LIGHT_GRAY; PdfPCell cellcontainer = new PdfPCell(new Paragraph(planDesc.Cod_contenedor.Substring(0, 4) + "-" + planDesc.Cod_contenedor.Substring(4, 6) + "-" + planDesc.Cod_contenedor.Substring(10, 1), arialText)); cellcontainer.HorizontalAlignment = 1; cellcontainer.VerticalAlignment = 5; //row2 inicializacion PdfPCell celltitlenave = new PdfPCell(new Paragraph("Nave", arialText)); celltitlenave.BackgroundColor = BaseColor.LIGHT_GRAY; celltitlenave.HorizontalAlignment = 1; celltitlenave.VerticalAlignment = 5; PdfPCell cellnave = new PdfPCell(new Paragraph(nave.Nav_nom, arialText)); cellnave.HorizontalAlignment = 1; cellnave.VerticalAlignment = 5; PdfPCell celltitleFechaI = new PdfPCell(new Paragraph("Fecha Inicio", arialText)); celltitleFechaI.BackgroundColor = BaseColor.LIGHT_GRAY; celltitleFechaI.HorizontalAlignment = 1; celltitleFechaI.VerticalAlignment = 5; PdfPCell cellFechaI = new PdfPCell(new Paragraph(planDesc.Fecha.ToString("dd-MM-yyyy").Substring(0, 10), arialText)); cellFechaI.HorizontalAlignment = 1; cellFechaI.VerticalAlignment = 5; PdfPCell celltitleiso = new PdfPCell(new Paragraph("Codigo Iso", arialText)); celltitleiso.BackgroundColor = BaseColor.LIGHT_GRAY; celltitleiso.HorizontalAlignment = 1; celltitleiso.VerticalAlignment = 5; PdfPCell celliso = new PdfPCell(new Paragraph(planDesc.Cod_iso, arialText)); celliso.HorizontalAlignment = 1; celliso.VerticalAlignment = 5; //row3 inicializacion PdfPCell titleviaje = new PdfPCell(new Paragraph("Viaje/Etapa", arialText)); titleviaje.BackgroundColor = BaseColor.LIGHT_GRAY; titleviaje.HorizontalAlignment = 1; titleviaje.VerticalAlignment = 5; PdfPCell cellviaje = new PdfPCell(new Paragraph(planDesc.Cod_viaje.ToString(), arialText)); cellviaje.HorizontalAlignment = 1; cellviaje.VerticalAlignment = 5; PdfPCell celltitlefecha = new PdfPCell(new Paragraph("Fecha Termino", arialText)); celltitlefecha.BackgroundColor = BaseColor.LIGHT_GRAY; celltitlefecha.HorizontalAlignment = 1; celltitlefecha.VerticalAlignment = 5; PdfPCell cellfecha = new PdfPCell(new Paragraph(planDesc.FechaT.ToString("dd-MM-yyyy").Substring(0, 10), arialText)); cellfecha.HorizontalAlignment = 1; cellfecha.VerticalAlignment = 5; PdfPCell celltitletara = new PdfPCell(new Paragraph("Tara (Kg.)", arialText)); celltitletara.HorizontalAlignment = 1; celltitletara.VerticalAlignment = 5; celltitletara.BackgroundColor = BaseColor.LIGHT_GRAY; PdfPCell celltara = new PdfPCell(new Paragraph(planDesc.Tara.ToString(), arialText)); celltara.HorizontalAlignment = 1; celltara.VerticalAlignment = 5; //row4 inicializacion PdfPCell titlemanifiesto = new PdfPCell(new Paragraph("Duración Faena", arialText)); titlemanifiesto.BackgroundColor = BaseColor.LIGHT_GRAY; titlemanifiesto.HorizontalAlignment = 1; titlemanifiesto.VerticalAlignment = 5; PdfPCell cellmanifiesto = new PdfPCell(new Paragraph(Convert.ToInt32(planDesc.Duracion * 60) + " Min.", arialText)); cellmanifiesto.HorizontalAlignment = 1; cellmanifiesto.VerticalAlignment = 5; PdfPCell titleturno = new PdfPCell(new Paragraph("Mano de Trabajo", arialText)); titleturno.BackgroundColor = BaseColor.LIGHT_GRAY; titleturno.HorizontalAlignment = 1; celltitlefecha.VerticalAlignment = 5; PdfPCell cellturno = new PdfPCell(new Paragraph(planDesc.Mddt, arialText)); cellturno.HorizontalAlignment = 1; cellturno.VerticalAlignment = 5; PdfPCell titlesello1 = new PdfPCell(new Paragraph("Sello 1 (Manifestado/Fisico)", arialText)); titlesello1.HorizontalAlignment = 1; titlesello1.VerticalAlignment = 5; titlesello1.BackgroundColor = BaseColor.LIGHT_GRAY; PdfPCell cellsello1 = new PdfPCell(new Paragraph(planDesc.Sello1 + " / " + planDesc.SelloFis1, arialText)); cellsello1.HorizontalAlignment = 1; cellsello1.VerticalAlignment = 5; //row5 inicializacion PdfPCell titleorigen = new PdfPCell(new Paragraph("Origen", arialText)); titleorigen.BackgroundColor = BaseColor.LIGHT_GRAY; titleorigen.HorizontalAlignment = 1; titleorigen.VerticalAlignment = 5; PdfPCell cellorigen = new PdfPCell(new Paragraph(puerto_or.Gls_nombre_puerto, arialText)); cellorigen.HorizontalAlignment = 1; cellorigen.VerticalAlignment = 5; PdfPCell titlehorai = new PdfPCell(new Paragraph("Hora Inicio", arialText)); titlehorai.BackgroundColor = BaseColor.LIGHT_GRAY; titlehorai.HorizontalAlignment = 1; titlehorai.VerticalAlignment = 5; PdfPCell cellhorai = new PdfPCell(new Paragraph(planDesc.HoraIR.ToString(), arialText)); cellhorai.HorizontalAlignment = 1; cellhorai.VerticalAlignment = 5; PdfPCell titlesello2 = new PdfPCell(new Paragraph("Sello 2 (Manifestado/Fisico)", arialText)); titlesello2.HorizontalAlignment = 1; titlesello2.VerticalAlignment = 5; titlesello2.BackgroundColor = BaseColor.LIGHT_GRAY; PdfPCell cellsello2 = new PdfPCell(new Paragraph(planDesc.Sello2 + " / " + planDesc.SelloFis2, arialText)); cellsello2.HorizontalAlignment = 1; cellsello2.VerticalAlignment = 5; //row6 inicializacion PdfPCell titledestino = new PdfPCell(new Paragraph("Destino", arialText)); titledestino.BackgroundColor = BaseColor.LIGHT_GRAY; titledestino.HorizontalAlignment = 1; titledestino.VerticalAlignment = 5; PdfPCell celldestino = new PdfPCell(new Paragraph(puerto_dest.Gls_nombre_puerto, arialText)); celldestino.HorizontalAlignment = 1; celldestino.VerticalAlignment = 5; PdfPCell titlehorat = new PdfPCell(new Paragraph("Hora Termino", arialText)); titlehorat.BackgroundColor = BaseColor.LIGHT_GRAY; titlehorat.HorizontalAlignment = 1; titlehorat.VerticalAlignment = 5; PdfPCell cellhorat = new PdfPCell(new Paragraph(planDesc.HoraTR.ToString(), arialText)); cellhorat.HorizontalAlignment = 1; cellhorat.VerticalAlignment = 5; PdfPCell titlesello3 = new PdfPCell(new Paragraph("Sello 3 (Manifestado/Fisico)", arialText)); titlesello3.HorizontalAlignment = 1; titlesello3.VerticalAlignment = 5; titlesello3.BackgroundColor = BaseColor.LIGHT_GRAY; PdfPCell cellsello3 = new PdfPCell(new Paragraph(planDesc.Sello3 + " / " + planDesc.SelloFis3, arialText)); cellsello3.HorizontalAlignment = 1; cellsello3.VerticalAlignment = 5; //row1 detailTable.AddCell(TitleCliente); detailTable.AddCell(cellrutCliente); detailTable.AddCell(cellcliente); detailTable.AddCell(vacio1); detailTable.AddCell(celltitlecontainer); detailTable.AddCell(cellcontainer); //row2 detailTable.AddCell(celltitlenave); detailTable.AddCell(cellnave); detailTable.AddCell(celltitleFechaI); detailTable.AddCell(cellFechaI); detailTable.AddCell(celltitleiso); detailTable.AddCell(celliso); //row3 detailTable.AddCell(titleviaje); detailTable.AddCell(cellviaje); detailTable.AddCell(celltitlefecha); detailTable.AddCell(cellfecha); detailTable.AddCell(celltitletara); detailTable.AddCell(celltara); //row4 detailTable.AddCell(titlemanifiesto); detailTable.AddCell(cellmanifiesto); detailTable.AddCell(titleturno); detailTable.AddCell(cellturno); detailTable.AddCell(titlesello1); detailTable.AddCell(cellsello1); //row5 detailTable.AddCell(titleorigen); detailTable.AddCell(cellorigen); detailTable.AddCell(titlehorai); detailTable.AddCell(cellhorai); detailTable.AddCell(titlesello2); detailTable.AddCell(cellsello2); //row6 detailTable.AddCell(titledestino); detailTable.AddCell(celldestino); detailTable.AddCell(titlehorat); detailTable.AddCell(cellhorat); detailTable.AddCell(titlesello3); detailTable.AddCell(cellsello3); ////tabla contenedor PdfPTable detailConte = new PdfPTable(3); detailConte.WidthPercentage = 100; detailConte.DefaultCell.HorizontalAlignment = 1; detailConte.DefaultCell.VerticalAlignment = 5; ////row 1 Image vector = Image.GetInstance(logoPath + "/vector.png"); vector.ScalePercent(52f); PdfPCell cellFotoCont = new PdfPCell(vector); cellFotoCont.HorizontalAlignment = 1; cellFotoCont.VerticalAlignment = 5; PdfPTable tableSecVec = new PdfPTable(2); List <SectorVectorBO> listSector = JsonConvert.DeserializeObject <List <SectorVectorBO> >(new SectorVectorBLL().sp_sel_sectorVectorIDDAL(tarja.Nro_tarja)); string codEstado, nroSector, estado; #pragma warning disable CS0219 // La variable 'j' está asignada pero su valor nunca se usa int j = 1; #pragma warning restore CS0219 // La variable 'j' está asignada pero su valor nunca se usa foreach (SectorVectorBO sector in listSector) { codEstado = sector.Cod_estado.ToString(); nroSector = sector.Nro_sector.ToString(); PdfPCell estadoSec = new PdfPCell(); estado = sector.Gls_nombre_estado.ToString(); estadoSec.AddElement(new Paragraph(nroSector + " " + estado, arialText)); estadoSec.BackgroundColor = BaseColor.YELLOW; estadoSec.HorizontalAlignment = 1; estadoSec.VerticalAlignment = 5; if (codEstado.Equals("S")) { estadoSec.BackgroundColor = BaseColor.WHITE; } tableSecVec.AddCell(estadoSec); } tableSecVec.AddCell(""); PdfPCell cellEstadosSec = new PdfPCell(tableSecVec); PdfPTable tableObs = new PdfPTable(1); PdfPCell titleObs = new PdfPCell(new Paragraph("OBSERVACIONES GENERALES", arialText)); titleObs.HorizontalAlignment = 1; titleObs.VerticalAlignment = 5; titleObs.BackgroundColor = BaseColor.LIGHT_GRAY; PdfPCell cellObs = new PdfPCell(new Paragraph(tarja.Observacion, arialText)); tableObs.AddCell(titleObs); tableObs.AddCell(cellObs); PdfPCell obs = new PdfPCell(tableObs); detailConte.AddCell(cellFotoCont); detailConte.AddCell(cellEstadosSec); detailConte.AddCell(obs); //tabla detalles personas PdfPTable tablapersonas = new PdfPTable(4); tablapersonas.WidthPercentage = 100; //row1 PdfPCell titlegrua = new PdfPCell(new Paragraph("GRUA", arialText)); titlegrua.BackgroundColor = BaseColor.LIGHT_GRAY; titlegrua.HorizontalAlignment = 1; titlegrua.VerticalAlignment = 5; PdfPCell cellgrua = new PdfPCell(new Paragraph(tarja.Grua_cod, arialText)); cellgrua.HorizontalAlignment = 1; cellgrua.VerticalAlignment = 5; PdfPCell titlemovilizadores = new PdfPCell(new Paragraph("MOVILIZADORES", arialText)); titlemovilizadores.BackgroundColor = BaseColor.LIGHT_GRAY; titlemovilizadores.HorizontalAlignment = 1; titlemovilizadores.VerticalAlignment = 5; PdfPCell titletarjador = new PdfPCell(new Paragraph("TARJADOR", arialText)); titletarjador.HorizontalAlignment = 1; titletarjador.VerticalAlignment = 5; titletarjador.BackgroundColor = BaseColor.LIGHT_GRAY; //row2 PdfPCell titlehorquillero = new PdfPCell(new Paragraph("HORQUILLERO", arialText)); titlehorquillero.BackgroundColor = BaseColor.LIGHT_GRAY; titlehorquillero.HorizontalAlignment = 1; titlehorquillero.VerticalAlignment = 5; PdfPCell cellhorquillero = new PdfPCell(new Paragraph(horquillero, arialText)); cellhorquillero.HorizontalAlignment = 1; cellhorquillero.VerticalAlignment = 5; PdfPCell cellmovilizadeores = new PdfPCell(new Paragraph(movilizadores, arialText)); titlemovilizadores.HorizontalAlignment = 1; titlemovilizadores.VerticalAlignment = 5; PdfPCell celltarjador = new PdfPCell(new Paragraph(tarjador.Nom_persona, arialText)); titletarjador.HorizontalAlignment = 1; titletarjador.VerticalAlignment = 5; tablapersonas.AddCell(titlegrua); tablapersonas.AddCell(cellgrua); tablapersonas.AddCell(titlemovilizadores); tablapersonas.AddCell(titletarjador); tablapersonas.AddCell(titlehorquillero); tablapersonas.AddCell(cellhorquillero); tablapersonas.AddCell(cellmovilizadeores); tablapersonas.AddCell(celltarjador); ////Tabla Merc Int64[] codigosMerc = null; string[] marcas = null; List <MercanciasDescBO> listMerc = null; PdfPTable detalleMerc = new PdfPTable(6); detalleMerc.WidthPercentage = 100; PdfPCell titlemarca = new PdfPCell(new Paragraph("MARCAS/NUMEROS", arialText)); titlemarca.HorizontalAlignment = 1; titlemarca.VerticalAlignment = 5; titlemarca.BackgroundColor = BaseColor.LIGHT_GRAY; titlemarca.Border = 15; detalleMerc.AddCell(titlemarca); PdfPCell titlebulto = new PdfPCell(new Paragraph("TIPO BULTO", arialText)); titlebulto.HorizontalAlignment = 1; titlebulto.VerticalAlignment = 5; titlebulto.Border = 15; titlebulto.BackgroundColor = BaseColor.LIGHT_GRAY; detalleMerc.AddCell(titlebulto); PdfPCell titleretiro = new PdfPCell(new Paragraph("TIPO DE RETIRO", arialText)); titleretiro.HorizontalAlignment = 1; titleretiro.VerticalAlignment = 5; titleretiro.BackgroundColor = BaseColor.LIGHT_GRAY; titlebulto.Border = 15; detalleMerc.AddCell(titleretiro); PdfPCell titlecantidad = new PdfPCell(new Paragraph("CANTIDAD", arialText)); titlecantidad.HorizontalAlignment = 1; titlecantidad.VerticalAlignment = 5; titlecantidad.BackgroundColor = BaseColor.LIGHT_GRAY; titlecantidad.Border = 15; detalleMerc.AddCell(titlecantidad); PdfPCell titleTotalmarca = new PdfPCell(new Paragraph("TOTAL", arialText)); titleTotalmarca.HorizontalAlignment = 1; titleTotalmarca.VerticalAlignment = 5; titleTotalmarca.BackgroundColor = BaseColor.LIGHT_GRAY; titleTotalmarca.Border = 15; detalleMerc.AddCell(titleTotalmarca); PdfPCell titleobs = new PdfPCell(new Paragraph("OBSERVACIONES", arialText)); titleobs.HorizontalAlignment = 1; titleobs.VerticalAlignment = 5; titleobs.BackgroundColor = BaseColor.LIGHT_GRAY; titleobs.Border = 15; detalleMerc.AddCell(titleobs); PdfPCell cellmarca, cellbultos, cellretiro, cellcantidad, celltotalM, cellobs, celltotal; string nomBulto = ""; int suma = 0; try { listMerc = new MercanciasDescBll().sp_sel_mercDescBLL(tarja.Nro_tarja); int i = 0; codigosMerc = new Int64[listMerc.Count]; marcas = new string[listMerc.Count]; foreach (MercanciasDescBO mercs in listMerc) { int cantidadB = 0; string cantidad = string.Empty; string observacioMerc = string.Empty; codigosMerc[i] = mercs.Cod_mercancia; if (!verificarMarca(marcas, mercs.Gls_marca)) { marcas[i] = mercs.Gls_marca; foreach (MercanciasDescBO mercAux in listMerc) { if (mercAux.Gls_marca.Equals(mercs.Gls_marca)) { cantidad += mercAux.N_cantidad.ToString() + " + "; observacioMerc += " " + mercAux.Observacion; cantidadB += mercAux.N_cantidad; nomBulto = mercAux.Desc_bulto; } } cantidad = cantidad.Substring(0, cantidad.Length - 2); suma += cantidadB; cellmarca = new PdfPCell(new Paragraph(mercs.Gls_marca, arialText)); cellmarca.HorizontalAlignment = 1; cellmarca.VerticalAlignment = 5; cellmarca.Border = 15; detalleMerc.AddCell(cellmarca); cellbultos = new PdfPCell(new Paragraph(nomBulto, arialText)); cellbultos.HorizontalAlignment = 1; cellbultos.VerticalAlignment = 5; cellbultos.Border = 15; detalleMerc.AddCell(cellbultos); cellretiro = new PdfPCell(new Paragraph(mercs.Gls_retiro, arialText)); cellretiro.HorizontalAlignment = 1; cellretiro.VerticalAlignment = 5; cellretiro.Border = 15; detalleMerc.AddCell(cellretiro); cellcantidad = new PdfPCell(new Paragraph(cantidad.ToString(), arialText)); cellcantidad.HorizontalAlignment = 1; cellcantidad.VerticalAlignment = 5; cellcantidad.Border = 15; detalleMerc.AddCell(cellcantidad); celltotalM = new PdfPCell(new Paragraph(cantidadB.ToString(), arialText)); celltotalM.HorizontalAlignment = 1; celltotalM.VerticalAlignment = 5; celltotalM.Border = 15; detalleMerc.AddCell(celltotalM); cellobs = new PdfPCell(new Paragraph(observacioMerc, arialText)); cellobs.HorizontalAlignment = 1; cellobs.VerticalAlignment = 5; cellobs.Border = 15; detalleMerc.AddCell(cellobs); } i++; } } catch (Exception ex) { Console.WriteLine("Ha ocurrido un error: " + ex.ToString()); } PdfPCell titletotal = new PdfPCell(new Paragraph("TOTAL", arialText)); titletotal.Border = 15; titletotal.HorizontalAlignment = 1; titletotal.VerticalAlignment = 5; titletotal.BackgroundColor = BaseColor.LIGHT_GRAY; detalleMerc.AddCell(titletotal); celltotal = new PdfPCell(new Paragraph(suma.ToString(), arialText)); celltotal.HorizontalAlignment = 1; celltotal.VerticalAlignment = 5; celltotal.Border = 15; detalleMerc.AddCell(celltotal); PdfPCell cellnada = new PdfPCell(new Paragraph("")); cellnada.Border = 0; detalleMerc.AddCell(cellnada); detalleMerc.AddCell(cellnada); detalleMerc.AddCell(cellnada); detalleMerc.AddCell(cellnada); PdfPTable tablefotos = new PdfPTable(3); tablefotos.WidthPercentage = 100; PdfPCell titletable = new PdfPCell(new Paragraph("FOTOGRAFIAS DESCONSOLIDADO", arialText)); titletable.Border = 15; titletable.HorizontalAlignment = 1; titletable.VerticalAlignment = 5; titletable.BackgroundColor = BaseColor.LIGHT_GRAY; PdfPCell cellnombrefoto; PdfPTable subtabla = new PdfPTable(1); PdfPCell cellfotografias; #pragma warning disable CS0168 // La variable 'cellfoto' se ha declarado pero nunca se usa PdfPCell cellfoto; #pragma warning restore CS0168 // La variable 'cellfoto' se ha declarado pero nunca se usa String base64Img = ""; var doctypeDesCnt = ConfigurationManager.AppSettings["FDM:DocTypeDescCnt"].ToString(); var fechaLimiteStr = ConfigurationManager.AppSettings["FechaLimite"].ToString().Split('-'); DateTime fechaLimite = new DateTime(Convert.ToInt32(fechaLimiteStr[0]), Convert.ToInt32(fechaLimiteStr[1]), Convert.ToInt32(fechaLimiteStr[2])); if (planDesc.Fecha < fechaLimite) { try { byte[] imageBytes; List <FotoContenedorBO> listFotos = new FotoContenedorBLL().sp_sel_fotoContDescBLL(tarja.Nro_tarja); string nombreImagen = string.Empty; foreach (FotoContenedorBO fotoCl in listFotos) { if (!nombreImagen.Equals(fotoCl.Gls_nombreImg)) { if (string.IsNullOrEmpty(nombreImagen)) { nombreImagen = fotoCl.Gls_nombreImg; base64Img = fotoCl.Gls_imagen; } else { if (base64Img.Length % 4 != 0) { string len = (base64Img.Length % 4).ToString(); } else { imageBytes = Convert.FromBase64String(base64Img); Image foto = Image.GetInstance(imageBytes); foto.ScaleAbsolute(159f, 235f); cellnombrefoto = new PdfPCell(new Paragraph(nombreImagen, arialText)); cellnombrefoto.HorizontalAlignment = 1; cellnombrefoto.VerticalAlignment = 5; subtabla = new PdfPTable(1); subtabla.AddCell(new PdfPCell(foto) { HorizontalAlignment = 1, VerticalAlignment = 5 }); subtabla.AddCell(cellnombrefoto); cellfotografias = new PdfPCell(subtabla); cellfotografias.HorizontalAlignment = 1; cellfotografias.VerticalAlignment = 5; tablefotos.AddCell(cellfotografias); } nombreImagen = fotoCl.Gls_nombreImg; base64Img = fotoCl.Gls_imagen; } } else { if (!string.IsNullOrEmpty(nombreImagen)) { var parte = fotoCl.Gls_imagen; var largo = parte.Length; base64Img += "" + parte; } } } if (!string.IsNullOrEmpty(base64Img)) { imageBytes = Convert.FromBase64String(base64Img); Image foto2 = Image.GetInstance(imageBytes); foto2.ScaleAbsolute(159f, 235f); cellnombrefoto = new PdfPCell(new Paragraph(nombreImagen, arialText)); cellnombrefoto.HorizontalAlignment = 1; cellnombrefoto.VerticalAlignment = 5; subtabla = new PdfPTable(1); subtabla.AddCell(new PdfPCell(foto2) { HorizontalAlignment = 1, VerticalAlignment = 5 }); subtabla.AddCell(cellnombrefoto); cellfotografias = new PdfPCell(subtabla); cellfotografias.HorizontalAlignment = 1; cellfotografias.VerticalAlignment = 5; tablefotos.AddCell(cellfotografias); } base64Img = ""; nombreImagen = ""; } catch (Exception ex) { Console.WriteLine("Ha ocurrido un error: " + ex.ToString()); } foreach (Int64 codigo in codigosMerc) { try { byte[] imageBytes; string marcaMerc = ""; string nombreImagen = string.Empty; List <FotoMercanciaBO> listFotoMerc = new FotoMercanciaBLL().sp_sel_fotoMercDescBLL(codigo); marcaMerc = new MercanciasDescBll().sp_sel_marcaMercBLL(codigo); foreach (FotoMercanciaBO fotoMerc in listFotoMerc) { if (!nombreImagen.Equals(fotoMerc.Gls_nombreImg)) { if (string.IsNullOrEmpty(nombreImagen)) { nombreImagen = fotoMerc.Gls_nombreImg; base64Img = fotoMerc.Gls_imagen; } else { if (base64Img.Length % 4 != 0) { string len = (base64Img.Length % 4).ToString(); } else { imageBytes = Convert.FromBase64String(base64Img); Image foto = Image.GetInstance(imageBytes); foto.ScaleAbsolute(159f, 235f); cellnombrefoto = new PdfPCell(new Paragraph(marcaMerc, arialText)); cellnombrefoto.HorizontalAlignment = 1; cellnombrefoto.VerticalAlignment = 5; subtabla = new PdfPTable(1); subtabla.AddCell(new PdfPCell(foto) { HorizontalAlignment = 1, VerticalAlignment = 5 }); subtabla.AddCell(cellnombrefoto); cellfotografias = new PdfPCell(subtabla); cellfotografias.HorizontalAlignment = 1; cellfotografias.VerticalAlignment = 5; tablefotos.AddCell(cellfotografias); } nombreImagen = fotoMerc.Gls_nombreImg; base64Img = fotoMerc.Gls_imagen; } } else { if (!string.IsNullOrEmpty(nombreImagen)) { var parte = fotoMerc.Gls_imagen; var largo = parte.Length; base64Img += "" + parte; } } } if (!string.IsNullOrEmpty(nombreImagen)) { imageBytes = Convert.FromBase64String(base64Img); Image foto2 = Image.GetInstance(imageBytes); foto2.ScaleAbsolute(159f, 235f); cellnombrefoto = new PdfPCell(new Paragraph(marcaMerc, arialText)); cellnombrefoto.HorizontalAlignment = 1; cellnombrefoto.VerticalAlignment = 5; subtabla = new PdfPTable(1); subtabla.AddCell(new PdfPCell(foto2) { HorizontalAlignment = 1, VerticalAlignment = 5 }); subtabla.AddCell(cellnombrefoto); cellfotografias = new PdfPCell(subtabla); cellfotografias.HorizontalAlignment = 1; cellfotografias.VerticalAlignment = 5; tablefotos.AddCell(cellfotografias); nombreImagen = ""; base64Img = ""; } } catch (Exception ex) { Console.WriteLine("Ha ocurrido un error: " + ex.ToString()); } } try { byte[] imageBytes; string nombreImagen = string.Empty; List <FotoContenedorBO> listFotosFin = new FotoContenedorBLL().sp_sel_fotoContFinBLL(tarja.Nro_tarja); foreach (FotoContenedorBO fotoFin in listFotosFin) { if (!nombreImagen.Equals(fotoFin.Gls_nombreImg)) { if (string.IsNullOrEmpty(nombreImagen)) { nombreImagen = fotoFin.Gls_nombreImg; base64Img = fotoFin.Gls_imagen; } else { if (base64Img.Length % 4 != 0) { string len = (base64Img.Length % 4).ToString(); } else { imageBytes = Convert.FromBase64String(base64Img); Image foto = Image.GetInstance(imageBytes); foto.ScaleAbsolute(159f, 235f); cellnombrefoto = new PdfPCell(new Paragraph(nombreImagen, arialText)); cellnombrefoto.HorizontalAlignment = 1; cellnombrefoto.VerticalAlignment = 5; subtabla = new PdfPTable(1); subtabla.AddCell(new PdfPCell(foto) { HorizontalAlignment = 1, VerticalAlignment = 5 }); subtabla.AddCell(cellnombrefoto); cellfotografias = new PdfPCell(subtabla); cellfotografias.HorizontalAlignment = 1; cellfotografias.VerticalAlignment = 5; tablefotos.AddCell(cellfotografias); } nombreImagen = fotoFin.Gls_nombreImg; base64Img = fotoFin.Gls_imagen; } } else { if (!string.IsNullOrEmpty(nombreImagen)) { var parte = fotoFin.Gls_imagen; var largo = parte.Length; base64Img += "" + parte; } } } if (!string.IsNullOrEmpty(nombreImagen)) { imageBytes = Convert.FromBase64String(base64Img); base64Img = Convert.ToBase64String(imageBytes); Image foto2 = Image.GetInstance(imageBytes); foto2.ScaleAbsolute(159f, 235f); cellnombrefoto = new PdfPCell(new Paragraph(nombreImagen, arialText)); cellnombrefoto.HorizontalAlignment = 1; cellnombrefoto.VerticalAlignment = 5; subtabla = new PdfPTable(1); subtabla.AddCell(new PdfPCell(foto2) { HorizontalAlignment = 1, VerticalAlignment = 5 }); subtabla.AddCell(cellnombrefoto); cellfotografias = new PdfPCell(subtabla); cellfotografias.HorizontalAlignment = 1; cellfotografias.VerticalAlignment = 5; tablefotos.AddCell(cellfotografias); } nombreImagen = ""; base64Img = ""; } catch (Exception ex) { Console.WriteLine("Ha ocurrido un error: " + ex.ToString()); } } else { try { List <FotografiasFDM> listFotos = new FotografiasFDM().obtenerFotografias(doctypeDesCnt, tarja.Nro_tarja.ToString()); string nombreImagen = string.Empty; foreach (FotografiasFDM fotoCl in listFotos) { Image foto = Image.GetInstance(new Uri(fotoCl.url_foto)); foto.ScaleAbsolute(159f, 235f); cellnombrefoto = new PdfPCell(new Paragraph(fotoCl.nombre_foto, arialText)); cellnombrefoto.HorizontalAlignment = 1; cellnombrefoto.VerticalAlignment = 5; subtabla = new PdfPTable(1); subtabla.AddCell(new PdfPCell(foto) { HorizontalAlignment = 1, VerticalAlignment = 5 }); subtabla.AddCell(cellnombrefoto); cellfotografias = new PdfPCell(subtabla); cellfotografias.HorizontalAlignment = 1; cellfotografias.VerticalAlignment = 5; tablefotos.AddCell(cellfotografias); } } catch (Exception ex) { Console.WriteLine("Ha ocurrido un error: " + ex.ToString()); } var docTypeMercDes = ConfigurationManager.AppSettings["FDM:DocTypeMercDesc"].ToString(); foreach (Int64 codigo in codigosMerc) { try { string marcaMerc = ""; string nombreImagen = string.Empty; List <FotografiasFDM> listFotoMerc = new FotografiasFDM().obtenerFotografias(docTypeMercDes, codigo.ToString()); marcaMerc = new MercanciasDescBll().sp_sel_marcaMercBLL(codigo); foreach (FotografiasFDM fotoMerc in listFotoMerc) { Image foto2 = Image.GetInstance(new Uri(fotoMerc.url_foto)); foto2.ScaleAbsolute(159f, 235f); cellnombrefoto = new PdfPCell(new Paragraph(marcaMerc, arialText)); cellnombrefoto.HorizontalAlignment = 1; cellnombrefoto.VerticalAlignment = 5; subtabla = new PdfPTable(1); subtabla.AddCell(new PdfPCell(foto2) { HorizontalAlignment = 1, VerticalAlignment = 5 }); subtabla.AddCell(cellnombrefoto); cellfotografias = new PdfPCell(subtabla); cellfotografias.HorizontalAlignment = 1; cellfotografias.VerticalAlignment = 5; tablefotos.AddCell(cellfotografias); } } catch (Exception ex) { Console.WriteLine("Ha ocurrido un error: " + ex.ToString()); } } } tablefotos.AddCell(vacio1); tablefotos.AddCell(vacio1); Paragraph vacio = new Paragraph(); vacio.Add("\n"); Paragraph p1 = new Paragraph(); p1.Add(tableHeader); Paragraph p2 = new Paragraph(); p2.Add(detailTable); Paragraph p3 = new Paragraph(); p3.Add(detailConte); Paragraph p4 = new Paragraph(); p4.Add(tablapersonas); Paragraph p5 = new Paragraph(); p5.Add(detalleMerc); Paragraph p6 = new Paragraph(); p6.Add(tablefotos); doc.Add(p1); doc.Add(vacio); doc.Add(p2); doc.Add(p3); doc.Add(p4); doc.NewPage(); doc.Add(p5); doc.NewPage(); doc.Add(p6); return(doc); }