Example #1
0
        private void CreatePDF(string ruta)
        {
            try
            {
                using (FileStream msReport = new FileStream(ruta, FileMode.Create))
                {
                    //step 1

                    using (Document pdfDoc = new Document(PageSize.LETTER, 22f, 10f, 180f, 40f))
                    {
                        try
                        {
                            // step 2
                            PdfWriter pdfWriter = PdfWriter.GetInstance(pdfDoc, msReport);
                            ITextOEN  ITE       = new ITextOEN();
                            ITE.NombreDoc       = "ORDEN DE ENTRADA OEN";
                            ITE.NoDoc           = oenSeleccionada.Id.ToString();
                            ITE.CodigoDoc       = oenSeleccionada.CODIGODEBARRAS;
                            ITE.FechaDoc        = oenSeleccionada.FECHA;
                            ITE.NombreProveedor = textBoxProveedor.Text;
                            //ITE.total = 50;
                            pdfWriter.PageEvent = ITE;
                            pdfDoc.Open();
                            #region tablas
                            PdfPTable NombreColumnas2 = new PdfPTable(5);
                            NombreColumnas2.TotalWidth      = pdfDoc.PageSize.Width - 90f;
                            NombreColumnas2.LockedWidth     = true;
                            NombreColumnas2.WidthPercentage = 70;
                            float[] widths2 = new float[] { 1f, 4f, 8f, 1f, 2 };
                            NombreColumnas2.SetWidths(widths2);
                            #region foreach
                            double totales = 0;
                            foreach (DataGridViewRow partida in dataGridView1.Rows)
                            {
                                // productos pctos = new productos(partida.ID_PRODUCTO);
                                if (partida.Cells["ITEM"].Value != null)
                                {
                                    PdfPCell item = new PdfPCell(new Phrase(partida.Cells["ITEM"].Value.ToString(), ITextEvents.arial2));
                                    item.HorizontalAlignment = 1;
                                    item.VerticalAlignment   = Element.ALIGN_MIDDLE;
                                    NombreColumnas2.AddCell(item);

                                    PdfPCell Catalogo;
                                    Catalogo                     = new PdfPCell(new Phrase(partida.Cells["CATALOGO"].Value.ToString(), ITextEvents.arial2));
                                    Catalogo.FixedHeight         = 22f;
                                    Catalogo.HorizontalAlignment = 0;
                                    Catalogo.VerticalAlignment   = Element.ALIGN_MIDDLE;
                                    NombreColumnas2.AddCell(Catalogo);

                                    PdfPCell Descrip = new PdfPCell(new Phrase(partida.Cells["DESCRIPCION"].Value.ToString(), ITextEvents.arial2));
                                    Descrip.HorizontalAlignment = 0;
                                    Descrip.VerticalAlignment   = Element.ALIGN_MIDDLE;
                                    NombreColumnas2.AddCell(Descrip);

                                    PdfPCell Cantidad = new PdfPCell(new Phrase(partida.Cells["CANTIDAD"].Value.ToString(), ITextEvents.arial2));
                                    Cantidad.HorizontalAlignment = 1;
                                    Cantidad.VerticalAlignment   = Element.ALIGN_MIDDLE;
                                    NombreColumnas2.AddCell(Cantidad);

                                    PdfPCell Factura = new PdfPCell(new Phrase(partida.Cells["FACTURA_PROVEEDOR"].Value.ToString(), ITextEvents.arial2));
                                    Factura.HorizontalAlignment = 1;
                                    Factura.VerticalAlignment   = Element.ALIGN_MIDDLE;
                                    NombreColumnas2.AddCell(Factura);
                                    double valor = 0;
                                    if (partida.Cells["MONEDA"].Value.ToString() == "PMX")
                                    {
                                        valor = Convert.ToDouble(partida.Cells["PU"].Value) / Convert.ToDouble(partida.Cells["TC"].Value);
                                    }
                                    else
                                    {
                                        valor = Convert.ToDouble(partida.Cells["PU"].Value);
                                    }
                                    valor    = valor * Convert.ToInt32(partida.Cells["CANTIDAD"].Value);
                                    totales += valor;
                                }
                            }
                            ITE.total = totales;
                            #endregion
                            PdfPCell espacio1 = new PdfPCell();
                            espacio1.FixedHeight = 8F;
                            espacio1.Colspan     = 6;
                            espacio1.Border      = 0;
                            NombreColumnas2.AddCell(espacio1);
                            NombreColumnas2.DefaultCell.PaddingBottom = 60;
                            NombreColumnas2.DefaultCell.PaddingTop    = 60;
                            pdfDoc.Add(NombreColumnas2);
                            #endregion tablas
                            pdfDoc.Close();
                        }
                        catch (Exception)
                        {
                            MessageBox.Show("Cierre el pdf");
                        }
                        finally
                        {
                        }
                    }
                }
            }
            catch { MessageBox.Show("Cierre el pdf"); }
        }
Example #2
0
        private void CreatePDF(string ruta)
        {
            try
            {
                using (FileStream msReport = new FileStream(ruta, FileMode.Create))
                {
                    //step 1
                    using (Document pdfDoc = new Document(PageSize.LETTER, 22f, 10f, 180f, 40f))
                    {
                        try
                        {
                            // step 2
                            PdfWriter pdfWriter = PdfWriter.GetInstance(pdfDoc, msReport);
                            ITextOEN  ITE       = new ITextOEN();
                            ITE.NombreDoc       = "ORDEN DE ENTRADA OEN";
                            ITE.NoDoc           = OENGralSeleccionada.Id.ToString();
                            ITE.CodigoDoc       = OENGralSeleccionada.CODIGODEBARRAS;
                            ITE.FechaDoc        = OENGralSeleccionada.FECHA;
                            ITE.NombreProveedor = ProveedorSeleccionado.NOMBRE;
                            ITE.total           = totales;
                            pdfWriter.PageEvent = ITE;
                            //open the stream
                            pdfDoc.Open();
                            #region tablas
                            //     Conv conv = new Conv();
                            PdfPTable NombreColumnas2 = new PdfPTable(5);
                            NombreColumnas2.TotalWidth      = pdfDoc.PageSize.Width - 90f;
                            NombreColumnas2.LockedWidth     = true;
                            NombreColumnas2.WidthPercentage = 70;
                            float[] widths2 = new float[] { 1f, 4f, 8f, 1f, 2 };
                            NombreColumnas2.SetWidths(widths2);

                            #region foreach
                            foreach (oen_indiv partida in OENGralSeleccionada.PARTIDAS)
                            {
                                productos pctos = new productos(partida.ID_PRODUCTO);


                                PdfPCell item = new PdfPCell(new Phrase(partida.ITEM.ToString(), ITextEvents.arial2));
                                item.HorizontalAlignment = 1;
                                item.VerticalAlignment   = Element.ALIGN_MIDDLE;
                                //  item.BackgroundColor = BaseColor.LIGHT_GRAY;
                                NombreColumnas2.AddCell(item);

                                PdfPCell Catalogo;

                                Catalogo = new PdfPCell(new Phrase(pctos.CATALOGO, ITextEvents.arial2));
                                //  PdfPCell Catalogo = new PdfPCell(new Phrase(partida.ALIAS, ITextEvents.arial2));
                                Catalogo.FixedHeight         = 22f;
                                Catalogo.HorizontalAlignment = 0;
                                Catalogo.VerticalAlignment   = Element.ALIGN_MIDDLE;
                                //  Catalogo.BackgroundColor = BaseColor.LIGHT_GRAY;
                                NombreColumnas2.AddCell(Catalogo);

                                PdfPCell Descrip = new PdfPCell(new Phrase(pctos.DESCRIPCION, ITextEvents.arial2));
                                Descrip.HorizontalAlignment = 0;
                                Descrip.VerticalAlignment   = Element.ALIGN_MIDDLE;
                                //  Descrip.BackgroundColor = BaseColor.LIGHT_GRAY;
                                NombreColumnas2.AddCell(Descrip);

                                PdfPCell Cantidad = new PdfPCell(new Phrase(partida.QTY.ToString(), ITextEvents.arial2));
                                Cantidad.HorizontalAlignment = 1;
                                Cantidad.VerticalAlignment   = Element.ALIGN_MIDDLE;
                                //  Cantidad.BackgroundColor = BaseColor.LIGHT_GRAY;
                                NombreColumnas2.AddCell(Cantidad);

                                PdfPCell Factura = new PdfPCell(new Phrase(partida.FACTURA_PROVEEDOR, ITextEvents.arial2));
                                Factura.HorizontalAlignment = 1;
                                Factura.VerticalAlignment   = Element.ALIGN_MIDDLE;
                                //  Cantidad.BackgroundColor = BaseColor.LIGHT_GRAY;
                                NombreColumnas2.AddCell(Factura);
                            }
                            #endregion

                            PdfPCell espacio1 = new PdfPCell();
                            espacio1.FixedHeight = 8F;
                            espacio1.Colspan     = 6;
                            espacio1.Border      = 0;
                            NombreColumnas2.AddCell(espacio1);
                            NombreColumnas2.DefaultCell.PaddingBottom = 60;
                            NombreColumnas2.DefaultCell.PaddingTop    = 60;
                            pdfDoc.Add(NombreColumnas2);
                            #endregion tablas
                            pdfDoc.Close();
                        }
                        catch (Exception)
                        {
                            MessageBox.Show("Cierre el pdf");
                        }
                        finally
                        {
                        }
                    }
                }
            }
            catch
            { MessageBox.Show("Cierre el pdf"); }
        }