SetWidths() public method

Sets the widths of the different columns (percentages).
You can give up relative values of borderwidths. The sum of these values will be considered 100%. The values will be recalculated as percentages of this sum.
public SetWidths ( int widths ) : void
widths int an array with values
return void
Exemplo n.º 1
0
        protected static DocumentPDF printTable(StampaVO.Table tableTmp, DataTable dt, DocumentPDF docPDF)
        {
            if (dt == null)
            {
                return(docPDF);
            }

            //** Operazioni Preliminari
            //reupero del numero di colonne dal DataTable
            int col         = tableTmp.columns.Length;
            int col_visible = 0;

            for (int j = 0; j < tableTmp.columns.Length; j++)
            {
                if (tableTmp.columns[j].visible)
                {
                    col_visible++;
                }
            }

            try
            {
                //creazione della tabella
                iTextSharp.text.Table aTable = new iTextSharp.text.Table(col_visible);

                //Adattamento delle colonne al contenuto
                aTable.Padding   = tableTmp.padding;
                aTable.Spacing   = tableTmp.spacing;
                aTable.Width     = 100;
                aTable.Alignment = Utils.getAlign(tableTmp.align);
                int[] widths = getColWidths(tableTmp, col_visible);

                aTable.SetWidths(widths);
                aTable.TableFitsPage = true;

                //** Aggiunta automatica dell'header della tabella
                for (int k = 0; k < col; k++)
                {
                    if (((StampaVO.Column)tableTmp.columns[k]).visible)
                    {
                        StampaVO.Font font  = tableTmp.headerTable.font;
                        Font          font1 = FontFactory.GetFont(font.name, font.size, Utils.getFontStyle(font.style), Utils.getColor(font.color));
                        string        testo = ((StampaVO.Column)tableTmp.columns[k]).alias;
                        Cell          c     = new Cell(new Phrase(testo, font1));
                        c.HorizontalAlignment = Utils.getAlign(tableTmp.headerTable.align);
                        c.VerticalAlignment   = Utils.getAlign(tableTmp.headerTable.vAlign);
                        //c.NoWrap=true;
                        c.BackgroundColor = Utils.getColor(tableTmp.headerTable.bgColor);
                        aTable.AddCell(c);
                    }
                }

                aTable.EndHeaders();

                //** Popolamento automatico della tabella
                //Scansione dei dati
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    //Creazione delle celle
                    for (int h = 0; h < col; h++)
                    {
                        if (((StampaVO.Column)tableTmp.columns[h]).visible)
                        {
                            StampaVO.Font font        = tableTmp.dataTable.font;
                            Font          font1       = FontFactory.GetFont(font.name, font.size, Utils.getFontStyle(font.style), Utils.getColor(font.color));
                            string        column_name = tableTmp.columns[h].name;
                            Cell          c1          = new Cell(new Phrase(dt.Rows[i][column_name].ToString(), font1));
                            c1.HorizontalAlignment = Utils.getAlign(tableTmp.columns[h].align);
                            c1.VerticalAlignment   = Utils.getAlign(tableTmp.columns[h].vAlign);
                            if (!string.IsNullOrEmpty(tableTmp.columns[h].bgColor))
                            {
                                c1.BackgroundColor = Utils.getColor(tableTmp.columns[h].bgColor);
                            }
                            aTable.AddCell(c1, new System.Drawing.Point(i + 1, h));
                        }
                    }
                }

                docPDF.Add(aTable);
            }
            catch (Exception ex)
            {
                docPDF.Close();
                writer.Close();
                throw new ReportException(ErrorCode.IncompletePDFFile, "Errore nella scrittura dei dati: " + ex.Message);
            }
            return(docPDF);
        }
Exemplo n.º 2
0
    protected void btnPDF_Click1(object sender, EventArgs e)
    {
        Document MyDocumnet = new Document(PageSize.A4, 30, 30, 30, 30);

        System.IO.MemoryStream MyReport = new System.IO.MemoryStream();

        PdfWriter writer = PdfWriter.GetInstance(MyDocumnet, MyReport);

        MyDocumnet.AddAuthor("Report");
        MyDocumnet.AddSubject("My Firsr Pdf");
        MyDocumnet.Open();

        #region Header
        iTextSharp.text.Table tblHeader = new iTextSharp.text.Table(4);
        tblHeader.Width   = 100;
        tblHeader.Padding = 2;
        tblHeader.Spacing = 1;
        tblHeader.Border  = iTextSharp.text.Rectangle.NO_BORDER;

        int[] tblWidths = { 25, 15, 20, 20 };
        tblHeader.SetWidths(tblWidths);


        Cell cellHeader = new Cell(new Phrase("Roche Professional Services", FontFactory.GetFont("Arial Narrow", 10, Font.BOLD, Color.BLACK)));
        cellHeader.HorizontalAlignment = Element.ALIGN_LEFT;
        cellHeader.VerticalAlignment   = Element.ALIGN_TOP;
        cellHeader.Leading             = 8;
        cellHeader.Colspan             = 1;
        cellHeader.Border = Rectangle.NO_BORDER;
        tblHeader.AddCell(cellHeader);

        cellHeader = new Cell(new Phrase(" Clarify case id:", FontFactory.GetFont("Arial Narrow", 10, Font.BOLD, Color.BLACK)));
        cellHeader.HorizontalAlignment = Element.ALIGN_RIGHT;
        cellHeader.VerticalAlignment   = Element.ALIGN_BOTTOM;
        cellHeader.Leading             = 8;
        cellHeader.Colspan             = 1;
        cellHeader.Border = Rectangle.NO_BORDER;
        tblHeader.AddCell(cellHeader);

        cellHeader = new Cell(new Phrase(" ", FontFactory.GetFont("Arial Narrow", 10, Font.BOLD, Color.BLACK)));
        cellHeader.HorizontalAlignment = Element.ALIGN_RIGHT;
        cellHeader.VerticalAlignment   = Element.ALIGN_BOTTOM;
        cellHeader.Leading             = 8;
        cellHeader.Colspan             = 1;
        cellHeader.Border = Rectangle.BOTTOM_BORDER;
        tblHeader.AddCell(cellHeader);

        iTextSharp.text.Image img = iTextSharp.text.Image.GetInstance(Server.MapPath("Intel_logo.png"));
        img.ScaleAbsolute(30, 15);

        cellHeader = new Cell(img);
        cellHeader.HorizontalAlignment = Element.ALIGN_RIGHT;
        cellHeader.VerticalAlignment   = Element.ALIGN_TOP;
        cellHeader.Leading             = 8;
        cellHeader.Colspan             = 1;
        cellHeader.Border = Rectangle.NO_BORDER;
        tblHeader.AddCell(cellHeader);

        cellHeader = new Cell(new Phrase(" ", FontFactory.GetFont("Arial Narrow", 10, Font.BOLD, Color.BLACK)));
        cellHeader.HorizontalAlignment = Element.ALIGN_RIGHT;
        cellHeader.VerticalAlignment   = Element.ALIGN_BOTTOM;
        cellHeader.Leading             = 8;
        cellHeader.Colspan             = 2;
        cellHeader.Border = Rectangle.NO_BORDER;
        tblHeader.AddCell(cellHeader);

        MyDocumnet.Add(tblHeader);

        #endregion

        #region table1
        iTextSharp.text.Table tbl1 = new iTextSharp.text.Table(3);
        tbl1.Width   = 100;
        tbl1.Padding = 3;
        tbl1.Spacing = 1;
        tbl1.Border  = iTextSharp.text.Rectangle.NO_BORDER;

        int[] tbl1Widths = { 10, 30, 30 };
        tbl1.SetWidths(tbl1Widths);

        Cell cellTbl1 = new Cell(new Phrase("Report No.", FontFactory.GetFont("Arial Narrow", 10, Font.BOLD, Color.BLACK)));
        cellTbl1.HorizontalAlignment = Element.ALIGN_LEFT;
        cellTbl1.VerticalAlignment   = Element.ALIGN_MIDDLE;
        cellTbl1.Leading             = 8;
        cellTbl1.Colspan             = 1;
        cellTbl1.BackgroundColor     = iTextSharp.text.Color.LIGHT_GRAY;
        cellTbl1.Border = Rectangle.BOX;
        tbl1.AddCell(cellTbl1);

        cellTbl1 = new Cell(new Phrase("Instrument Serial No.", FontFactory.GetFont("Arial Narrow", 10, Font.BOLD, Color.BLACK)));
        cellTbl1.HorizontalAlignment = Element.ALIGN_LEFT;
        cellTbl1.VerticalAlignment   = Element.ALIGN_MIDDLE;
        cellTbl1.Leading             = 8;
        cellTbl1.Colspan             = 1;
        cellTbl1.BackgroundColor     = iTextSharp.text.Color.LIGHT_GRAY;
        cellTbl1.Border = Rectangle.BOX;
        tbl1.AddCell(cellTbl1);

        cellTbl1 = new Cell(new Phrase("Visit Date", FontFactory.GetFont("Arial Narrow", 10, Font.BOLD, Color.BLACK)));
        cellTbl1.HorizontalAlignment = Element.ALIGN_CENTER;
        cellTbl1.VerticalAlignment   = Element.ALIGN_MIDDLE;
        cellTbl1.Leading             = 8;
        cellTbl1.Colspan             = 1;
        cellTbl1.BackgroundColor     = iTextSharp.text.Color.LIGHT_GRAY;
        cellTbl1.Border = Rectangle.BOX;
        tbl1.AddCell(cellTbl1);

        cellTbl1 = new Cell(new Phrase("02154", FontFactory.GetFont("Arial Narrow", 10, Font.BOLD, Color.BLACK)));
        cellTbl1.HorizontalAlignment = Element.ALIGN_LEFT;
        cellTbl1.VerticalAlignment   = Element.ALIGN_MIDDLE;
        cellTbl1.Leading             = 8;
        cellTbl1.Colspan             = 1;
        cellTbl1.Border = Rectangle.BOX;
        tbl1.AddCell(cellTbl1);

        cellTbl1 = new Cell(new Phrase(" ", FontFactory.GetFont("Arial Narrow", 10, Font.BOLD, Color.BLACK)));
        cellTbl1.HorizontalAlignment = Element.ALIGN_LEFT;
        cellTbl1.VerticalAlignment   = Element.ALIGN_MIDDLE;
        cellTbl1.Leading             = 8;
        cellTbl1.Colspan             = 1;
        cellTbl1.Border = Rectangle.BOX;
        tbl1.AddCell(cellTbl1);

        cellTbl1 = new Cell(new Phrase(" ", FontFactory.GetFont("Arial Narrow", 10, Font.BOLD, Color.BLACK)));
        cellTbl1.HorizontalAlignment = Element.ALIGN_LEFT;
        cellTbl1.VerticalAlignment   = Element.ALIGN_MIDDLE;
        cellTbl1.Leading             = 8;
        cellTbl1.Colspan             = 1;
        cellTbl1.Border = Rectangle.BOX;
        tbl1.AddCell(cellTbl1);

        cellTbl1 = new Cell(new Phrase(" ", FontFactory.GetFont("Arial Narrow", 10, Font.BOLD, Color.BLACK)));
        cellTbl1.HorizontalAlignment = Element.ALIGN_LEFT;
        cellTbl1.VerticalAlignment   = Element.ALIGN_MIDDLE;
        cellTbl1.Leading             = 8;
        cellTbl1.Colspan             = 3;
        cellTbl1.Border = Rectangle.NO_BORDER;
        tbl1.AddCell(cellTbl1);

        MyDocumnet.Add(tbl1);
        #endregion

        #region table2
        iTextSharp.text.Table tbl2 = new iTextSharp.text.Table(4);
        tbl2.Width   = 100;
        tbl2.Padding = 3;
        tbl2.Spacing = 1;
        tbl2.Border  = iTextSharp.text.Rectangle.NO_BORDER;

        int[] tbl2Widths = { 10, 10, 10, 20 };
        tbl2.SetWidths(tbl2Widths);

        Cell cellTbl2 = new Cell(new Phrase("Charge Type:", FontFactory.GetFont("Arial Narrow", 10, Font.BOLD, Color.BLACK)));
        cellTbl2.HorizontalAlignment = Element.ALIGN_LEFT;
        cellTbl2.VerticalAlignment   = Element.ALIGN_MIDDLE;
        cellTbl2.Leading             = 8;
        cellTbl2.Colspan             = 4;
        cellTbl2.BackgroundColor     = iTextSharp.text.Color.LIGHT_GRAY;
        cellTbl2.Border = Rectangle.BOX;
        tbl2.AddCell(cellTbl2);

        cellTbl2 = new Cell(new Phrase("[ ] Service Contract", FontFactory.GetFont("Arial Narrow", 10, Font.NORMAL, Color.BLACK)));
        cellTbl2.HorizontalAlignment = Element.ALIGN_LEFT;
        cellTbl2.VerticalAlignment   = Element.ALIGN_MIDDLE;
        cellTbl2.Leading             = 8;
        cellTbl2.Colspan             = 1;
        cellTbl2.Border = Rectangle.BOX;
        tbl2.AddCell(cellTbl2);

        cellTbl2 = new Cell(new Phrase("[ ] Ad-hoc", FontFactory.GetFont("Arial Narrow", 10, Font.NORMAL, Color.BLACK)));
        cellTbl2.HorizontalAlignment = Element.ALIGN_LEFT;
        cellTbl2.VerticalAlignment   = Element.ALIGN_MIDDLE;
        cellTbl2.Leading             = 8;
        cellTbl2.Colspan             = 1;
        cellTbl2.Border = Rectangle.BOX;
        tbl2.AddCell(cellTbl2);

        cellTbl2 = new Cell(new Phrase("[ ] Placement/Rental", FontFactory.GetFont("Arial Narrow", 10, Font.NORMAL, Color.BLACK)));
        cellTbl2.HorizontalAlignment = Element.ALIGN_LEFT;
        cellTbl2.VerticalAlignment   = Element.ALIGN_MIDDLE;
        cellTbl2.Leading             = 8;
        cellTbl2.Colspan             = 1;
        cellTbl2.Border = Rectangle.BOX;
        tbl2.AddCell(cellTbl2);

        cellTbl2 = new Cell(new Phrase("[ ] Other(Pls specify):", FontFactory.GetFont("Arial Narrow", 10, Font.NORMAL, Color.BLACK)));
        cellTbl2.HorizontalAlignment = Element.ALIGN_LEFT;
        cellTbl2.VerticalAlignment   = Element.ALIGN_MIDDLE;
        cellTbl2.Leading             = 8;
        cellTbl2.Colspan             = 1;
        cellTbl2.Border = Rectangle.BOX;
        tbl2.AddCell(cellTbl2);


        cellTbl2 = new Cell(new Phrase(" ", FontFactory.GetFont("Arial Narrow", 10, Font.BOLD, Color.BLACK)));
        cellTbl2.HorizontalAlignment = Element.ALIGN_LEFT;
        cellTbl2.VerticalAlignment   = Element.ALIGN_MIDDLE;
        cellTbl2.Leading             = 8;
        cellTbl2.Colspan             = 4;
        cellTbl2.Border = Rectangle.NO_BORDER;
        tbl2.AddCell(cellTbl2);

        MyDocumnet.Add(tbl2);
        #endregion


        #region table3
        iTextSharp.text.Table tbl3 = new iTextSharp.text.Table(5);
        tbl3.Width   = 100;
        tbl3.Padding = 3;
        tbl3.Spacing = 1;
        tbl3.Border  = iTextSharp.text.Rectangle.NO_BORDER;

        int[] tbl3Widths = { 10, 10, 10, 10, 10 };
        tbl3.SetWidths(tbl3Widths);

        Cell cellTbl3 = new Cell(new Phrase("Call Details:", FontFactory.GetFont("Arial Narrow", 10, Font.BOLD, Color.BLACK)));
        cellTbl3.HorizontalAlignment = Element.ALIGN_LEFT;
        cellTbl3.VerticalAlignment   = Element.ALIGN_MIDDLE;
        cellTbl3.Leading             = 8;
        cellTbl3.Colspan             = 5;
        cellTbl3.BackgroundColor     = iTextSharp.text.Color.LIGHT_GRAY;
        cellTbl3.Border = Rectangle.BOX;
        tbl3.AddCell(cellTbl3);

        cellTbl3 = new Cell(new Phrase("Call Received Date :", FontFactory.GetFont("Arial Narrow", 10, Font.NORMAL, Color.BLACK)));
        cellTbl3.HorizontalAlignment = Element.ALIGN_LEFT;
        cellTbl3.VerticalAlignment   = Element.ALIGN_MIDDLE;
        cellTbl3.Leading             = 8;
        cellTbl3.Colspan             = 1;
        cellTbl3.Border = Rectangle.BOX;
        tbl3.AddCell(cellTbl3);

        cellTbl3 = new Cell(new Phrase(" ", FontFactory.GetFont("Arial Narrow", 10, Font.NORMAL, Color.BLACK)));
        cellTbl3.HorizontalAlignment = Element.ALIGN_LEFT;
        cellTbl3.VerticalAlignment   = Element.ALIGN_MIDDLE;
        cellTbl3.Leading             = 8;
        cellTbl3.Colspan             = 1;
        cellTbl3.Border = Rectangle.BOX;
        tbl3.AddCell(cellTbl3);

        cellTbl3 = new Cell(new Phrase("Call Attended Dates :", FontFactory.GetFont("Arial Narrow", 10, Font.NORMAL, Color.BLACK)));
        cellTbl3.HorizontalAlignment = Element.ALIGN_LEFT;
        cellTbl3.VerticalAlignment   = Element.ALIGN_MIDDLE;
        cellTbl3.Leading             = 8;
        cellTbl3.Colspan             = 1;
        cellTbl3.Border = Rectangle.BOX;
        tbl3.AddCell(cellTbl3);

        cellTbl3 = new Cell(new Phrase(" ", FontFactory.GetFont("Arial Narrow", 10, Font.NORMAL, Color.BLACK)));
        cellTbl3.HorizontalAlignment = Element.ALIGN_LEFT;
        cellTbl3.VerticalAlignment   = Element.ALIGN_MIDDLE;
        cellTbl3.Leading             = 8;
        cellTbl3.Colspan             = 1;
        cellTbl3.Border = Rectangle.BOX;
        tbl3.AddCell(cellTbl3);

        cellTbl3 = new Cell(new Phrase("Travel Hours ", FontFactory.GetFont("Arial Narrow", 10, Font.NORMAL, Color.BLACK)));
        cellTbl3.HorizontalAlignment = Element.ALIGN_LEFT;
        cellTbl3.VerticalAlignment   = Element.ALIGN_MIDDLE;
        cellTbl3.Leading             = 8;
        cellTbl3.Colspan             = 1;
        cellTbl3.Rowspan             = 2;
        cellTbl3.Border = Rectangle.BOX;
        tbl3.AddCell(cellTbl3);


        //2nd Row


        cellTbl3 = new Cell(new Phrase("Time :", FontFactory.GetFont("Arial Narrow", 10, Font.NORMAL, Color.BLACK)));
        cellTbl3.HorizontalAlignment = Element.ALIGN_LEFT;
        cellTbl3.VerticalAlignment   = Element.ALIGN_MIDDLE;
        cellTbl3.Leading             = 8;
        cellTbl3.Colspan             = 1;
        cellTbl3.Border = Rectangle.BOX;
        tbl3.AddCell(cellTbl3);

        cellTbl3 = new Cell(new Phrase(" ", FontFactory.GetFont("Arial Narrow", 10, Font.NORMAL, Color.BLACK)));
        cellTbl3.HorizontalAlignment = Element.ALIGN_LEFT;
        cellTbl3.VerticalAlignment   = Element.ALIGN_MIDDLE;
        cellTbl3.Leading             = 8;
        cellTbl3.Colspan             = 1;
        cellTbl3.Border = Rectangle.BOX;
        tbl3.AddCell(cellTbl3);

        cellTbl3 = new Cell(new Phrase("Time :", FontFactory.GetFont("Arial Narrow", 10, Font.NORMAL, Color.BLACK)));
        cellTbl3.HorizontalAlignment = Element.ALIGN_LEFT;
        cellTbl3.VerticalAlignment   = Element.ALIGN_MIDDLE;
        cellTbl3.Leading             = 8;
        cellTbl3.Colspan             = 1;
        cellTbl3.Border = Rectangle.BOX;
        tbl3.AddCell(cellTbl3);

        cellTbl3 = new Cell(new Phrase(" ", FontFactory.GetFont("Arial Narrow", 10, Font.NORMAL, Color.BLACK)));
        cellTbl3.HorizontalAlignment = Element.ALIGN_LEFT;
        cellTbl3.VerticalAlignment   = Element.ALIGN_MIDDLE;
        cellTbl3.Leading             = 8;
        cellTbl3.Colspan             = 1;
        cellTbl3.Border = Rectangle.BOX;
        tbl3.AddCell(cellTbl3);



        //2nd row end------------


        cellTbl3 = new Cell(new Phrase(" ", FontFactory.GetFont("Arial Narrow", 10, Font.BOLD, Color.BLACK)));
        cellTbl3.HorizontalAlignment = Element.ALIGN_LEFT;
        cellTbl3.VerticalAlignment   = Element.ALIGN_MIDDLE;
        cellTbl3.Leading             = 8;
        cellTbl3.Colspan             = 4;
        cellTbl3.Border = Rectangle.NO_BORDER;
        tbl3.AddCell(cellTbl3);

        MyDocumnet.Add(tbl3);
        #endregion
        //-----------------------------------------------------------------------------------------------------------------------------------------------------------------
        #region table4

        iTextSharp.text.Table tbl4 = new iTextSharp.text.Table(1);
        tbl4.Width   = 100;
        tbl4.Padding = 3;
        tbl4.Spacing = 1;
        tbl4.Border  = iTextSharp.text.Rectangle.NO_BORDER;

        int[] tbl4Widths = { 50 };
        tbl4.SetWidths(tbl4Widths);



        Cell cellTbl4 = new Cell(new Phrase("Problem Description : \n \n\n\n\n\n", FontFactory.GetFont("Arial Narrow", 10, Font.BOLD, Color.BLACK)));
        cellTbl4.HorizontalAlignment = Element.ALIGN_LEFT;
        cellTbl4.VerticalAlignment   = Element.ALIGN_MIDDLE;
        cellTbl4.Leading             = 8;
        cellTbl4.Colspan             = 1;
        //cellTbl4.BackgroundColor = iTextSharp.text.Color.LIGHT_GRAY;
        cellTbl4.Border = Rectangle.BOX;
        tbl4.AddCell(cellTbl4);

        cellTbl4 = new Cell(new Phrase(" ", FontFactory.GetFont("Arial Narrow", 10, Font.BOLD, Color.BLACK)));
        cellTbl4.HorizontalAlignment = Element.ALIGN_LEFT;
        cellTbl4.VerticalAlignment   = Element.ALIGN_MIDDLE;
        cellTbl4.Leading             = 8;
        cellTbl4.Colspan             = 1;
        cellTbl4.Border = Rectangle.NO_BORDER;
        tbl4.AddCell(cellTbl4);

        MyDocumnet.Add(tbl4);
        #endregion
        //-------------------------------------------------------------------------------------------------------------------------------------------------------------------------

        iTextSharp.text.Table tbl5 = new iTextSharp.text.Table(1);
        tbl5.Width   = 100;
        tbl5.Padding = 3;
        tbl5.Spacing = 1;
        tbl5.Border  = iTextSharp.text.Rectangle.NO_BORDER;

        int[] tbl5Widths = { 50 };
        tbl5.SetWidths(tbl5Widths);


        Cell cellTbl5 = new Cell(new Phrase("Action Summary : \n \n\n\n\n\n", FontFactory.GetFont("Arial Narrow", 10, Font.BOLD, Color.BLACK)));
        cellTbl5.HorizontalAlignment = Element.ALIGN_LEFT;
        cellTbl5.VerticalAlignment   = Element.ALIGN_MIDDLE;
        cellTbl5.Leading             = 8;
        cellTbl5.Colspan             = 1;
        //cellTbl4.BackgroundColor = iTextSharp.text.Color.LIGHT_GRAY;
        cellTbl5.Border = Rectangle.BOX;
        tbl5.AddCell(cellTbl5);

        cellTbl5 = new Cell(new Phrase(" ", FontFactory.GetFont("Arial Narrow", 10, Font.BOLD, Color.BLACK)));
        cellTbl5.HorizontalAlignment = Element.ALIGN_LEFT;
        cellTbl5.VerticalAlignment   = Element.ALIGN_MIDDLE;
        cellTbl5.Leading             = 8;
        cellTbl5.Colspan             = 1;
        cellTbl5.Border = Rectangle.NO_BORDER;
        tbl5.AddCell(cellTbl5);

        MyDocumnet.Add(tbl5);

        //-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

        iTextSharp.text.Table tbl6 = new iTextSharp.text.Table(1);
        tbl6.Width   = 100;
        tbl6.Padding = 3;
        tbl6.Spacing = 1;
        tbl6.Border  = iTextSharp.text.Rectangle.NO_BORDER;

        int[] tbl6Widths = { 50 };
        tbl6.SetWidths(tbl6Widths);


        Cell cellTbl6 = new Cell(new Phrase("Service Eng remark : \n \n\n\n\n\n", FontFactory.GetFont("Arial Narrow", 10, Font.BOLD, Color.BLACK)));
        cellTbl6.HorizontalAlignment = Element.ALIGN_LEFT;
        cellTbl6.VerticalAlignment   = Element.ALIGN_MIDDLE;
        cellTbl6.Leading             = 8;
        cellTbl6.Colspan             = 1;
        //cellTbl4.BackgroundColor = iTextSharp.text.Color.LIGHT_GRAY;
        cellTbl6.Border = Rectangle.BOX;
        tbl6.AddCell(cellTbl6);

        cellTbl6 = new Cell(new Phrase(" ", FontFactory.GetFont("Arial Narrow", 10, Font.BOLD, Color.BLACK)));
        cellTbl6.HorizontalAlignment = Element.ALIGN_LEFT;
        cellTbl6.VerticalAlignment   = Element.ALIGN_MIDDLE;
        cellTbl6.Leading             = 8;
        cellTbl6.Colspan             = 1;
        cellTbl6.Border = Rectangle.NO_BORDER;
        tbl6.AddCell(cellTbl6);
        MyDocumnet.Add(tbl6);

        //----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
        //Other tables

        #region table11

        iTextSharp.text.Table tbl11 = new iTextSharp.text.Table(5);
        tbl11.Width   = 100;
        tbl11.Padding = 3;
        tbl11.Spacing = 1;
        tbl11.Border  = iTextSharp.text.Rectangle.NO_BORDER;

        int[] tbl11Widths = { 40, 1, 30, 1, 40 };
        tbl11.SetWidths(tbl11Widths);

        Cell cellTbl11 = new Cell(new Phrase("Service Engineer/Application Specialist Name:", FontFactory.GetFont("Arial Narrow", 8, Font.NORMAL, Color.BLACK)));
        cellTbl11.HorizontalAlignment = Element.ALIGN_CENTER;
        cellTbl11.VerticalAlignment   = Element.ALIGN_MIDDLE;
        cellTbl11.Leading             = 8;
        cellTbl11.Colspan             = 1;
        cellTbl11.Border = Rectangle.BOX;
        tbl11.AddCell(cellTbl11);

        cellTbl11 = new Cell(new Phrase(" ", FontFactory.GetFont("Arial Narrow", 8, Font.NORMAL, Color.BLACK)));
        cellTbl11.HorizontalAlignment = Element.ALIGN_LEFT;
        cellTbl11.VerticalAlignment   = Element.ALIGN_MIDDLE;
        cellTbl11.Leading             = 8;
        cellTbl11.Colspan             = 1;
        cellTbl11.Border = Rectangle.NO_BORDER;
        tbl11.AddCell(cellTbl11);

        cellTbl11 = new Cell(new Phrase("3 SP Address Seal", FontFactory.GetFont("Arial Narrow", 8, Font.NORMAL, Color.BLACK)));
        cellTbl11.HorizontalAlignment = Element.ALIGN_CENTER;
        cellTbl11.VerticalAlignment   = Element.ALIGN_MIDDLE;
        cellTbl11.Leading             = 8;
        cellTbl11.Colspan             = 1;
        cellTbl11.Border = Rectangle.BOX;
        tbl11.AddCell(cellTbl11);

        cellTbl11 = new Cell(new Phrase(" ", FontFactory.GetFont("Arial Narrow", 8, Font.NORMAL, Color.BLACK)));
        cellTbl11.HorizontalAlignment = Element.ALIGN_LEFT;
        cellTbl11.VerticalAlignment   = Element.ALIGN_MIDDLE;
        cellTbl11.Leading             = 8;
        cellTbl11.Colspan             = 1;
        cellTbl11.Border = Rectangle.NO_BORDER;
        tbl11.AddCell(cellTbl11);

        cellTbl11 = new Cell(new Phrase("Customer's/Users Name:", FontFactory.GetFont("Arial Narrow", 8, Font.NORMAL, Color.BLACK)));
        cellTbl11.HorizontalAlignment = Element.ALIGN_CENTER;
        cellTbl11.VerticalAlignment   = Element.ALIGN_MIDDLE;
        cellTbl11.Leading             = 8;
        cellTbl11.Colspan             = 1;
        cellTbl11.Border = Rectangle.BOX;
        tbl11.AddCell(cellTbl11);

        ///Row 2
        cellTbl11 = new Cell(new Phrase(" \n", FontFactory.GetFont("Arial Narrow", 8, Font.NORMAL, Color.BLACK)));
        cellTbl11.HorizontalAlignment = Element.ALIGN_CENTER;
        cellTbl11.VerticalAlignment   = Element.ALIGN_MIDDLE;
        cellTbl11.Leading             = 8;
        cellTbl11.Colspan             = 1;
        cellTbl11.Border = Rectangle.BOX;
        tbl11.AddCell(cellTbl11);

        cellTbl11 = new Cell(new Phrase(" ", FontFactory.GetFont("Arial Narrow", 8, Font.NORMAL, Color.BLACK)));
        cellTbl11.HorizontalAlignment = Element.ALIGN_LEFT;
        cellTbl11.VerticalAlignment   = Element.ALIGN_MIDDLE;
        cellTbl11.Leading             = 8;
        cellTbl11.Colspan             = 1;
        cellTbl11.Border = Rectangle.NO_BORDER;
        tbl11.AddCell(cellTbl11);

        cellTbl11 = new Cell(new Phrase(" \n", FontFactory.GetFont("Arial Narrow", 8, Font.NORMAL, Color.BLACK)));
        cellTbl11.HorizontalAlignment = Element.ALIGN_CENTER;
        cellTbl11.VerticalAlignment   = Element.ALIGN_MIDDLE;
        cellTbl11.Leading             = 8;
        cellTbl11.Colspan             = 1;
        cellTbl11.Rowspan             = 4;
        cellTbl11.Border = Rectangle.BOX;
        tbl11.AddCell(cellTbl11);

        cellTbl11 = new Cell(new Phrase(" ", FontFactory.GetFont("Arial Narrow", 8, Font.NORMAL, Color.BLACK)));
        cellTbl11.HorizontalAlignment = Element.ALIGN_LEFT;
        cellTbl11.VerticalAlignment   = Element.ALIGN_MIDDLE;
        cellTbl11.Leading             = 8;
        cellTbl11.Colspan             = 1;
        cellTbl11.Border = Rectangle.NO_BORDER;
        tbl11.AddCell(cellTbl11);

        cellTbl11 = new Cell(new Phrase(" \n", FontFactory.GetFont("Arial Narrow", 8, Font.NORMAL, Color.BLACK)));
        cellTbl11.HorizontalAlignment = Element.ALIGN_CENTER;
        cellTbl11.VerticalAlignment   = Element.ALIGN_MIDDLE;
        cellTbl11.Leading             = 8;
        cellTbl11.Colspan             = 1;
        cellTbl11.Border = Rectangle.BOX;
        tbl11.AddCell(cellTbl11);

        //Row
        cellTbl11 = new Cell(new Phrase(" ", FontFactory.GetFont("Arial Narrow", 10, Font.BOLD, Color.BLACK)));
        cellTbl11.HorizontalAlignment = Element.ALIGN_LEFT;
        cellTbl11.VerticalAlignment   = Element.ALIGN_MIDDLE;
        cellTbl11.Leading             = 8;
        cellTbl11.Colspan             = 2;
        cellTbl11.Border = Rectangle.NO_BORDER;
        tbl11.AddCell(cellTbl11);

        cellTbl11 = new Cell(new Phrase(" ", FontFactory.GetFont("Arial Narrow", 10, Font.BOLD, Color.BLACK)));
        cellTbl11.HorizontalAlignment = Element.ALIGN_LEFT;
        cellTbl11.VerticalAlignment   = Element.ALIGN_MIDDLE;
        cellTbl11.Leading             = 8;
        cellTbl11.Colspan             = 2;
        cellTbl11.Border = Rectangle.NO_BORDER;
        tbl11.AddCell(cellTbl11);

        //Row
        cellTbl11 = new Cell(new Phrase("Service Engineer/Application Specialist Name:", FontFactory.GetFont("Arial Narrow", 8, Font.NORMAL, Color.BLACK)));
        cellTbl11.HorizontalAlignment = Element.ALIGN_CENTER;
        cellTbl11.VerticalAlignment   = Element.ALIGN_MIDDLE;
        cellTbl11.Leading             = 8;
        cellTbl11.Colspan             = 1;
        cellTbl11.Border = Rectangle.BOX;
        tbl11.AddCell(cellTbl11);

        cellTbl11 = new Cell(new Phrase(" ", FontFactory.GetFont("Arial Narrow", 8, Font.NORMAL, Color.BLACK)));
        cellTbl11.HorizontalAlignment = Element.ALIGN_LEFT;
        cellTbl11.VerticalAlignment   = Element.ALIGN_MIDDLE;
        cellTbl11.Leading             = 8;
        cellTbl11.Colspan             = 1;
        cellTbl11.Border = Rectangle.NO_BORDER;
        tbl11.AddCell(cellTbl11);

        cellTbl11 = new Cell(new Phrase(" ", FontFactory.GetFont("Arial Narrow", 8, Font.NORMAL, Color.BLACK)));
        cellTbl11.HorizontalAlignment = Element.ALIGN_LEFT;
        cellTbl11.VerticalAlignment   = Element.ALIGN_MIDDLE;
        cellTbl11.Leading             = 8;
        cellTbl11.Colspan             = 1;
        cellTbl11.Border = Rectangle.NO_BORDER;
        tbl11.AddCell(cellTbl11);

        cellTbl11 = new Cell(new Phrase("Customer's/Users Name:", FontFactory.GetFont("Arial Narrow", 8, Font.NORMAL, Color.BLACK)));
        cellTbl11.HorizontalAlignment = Element.ALIGN_CENTER;
        cellTbl11.VerticalAlignment   = Element.ALIGN_MIDDLE;
        cellTbl11.Leading             = 8;
        cellTbl11.Colspan             = 1;
        cellTbl11.Border = Rectangle.BOX;
        tbl11.AddCell(cellTbl11);

        cellTbl11 = new Cell(new Phrase(" \n", FontFactory.GetFont("Arial Narrow", 8, Font.NORMAL, Color.BLACK)));
        cellTbl11.HorizontalAlignment = Element.ALIGN_CENTER;
        cellTbl11.VerticalAlignment   = Element.ALIGN_MIDDLE;
        cellTbl11.Leading             = 8;
        cellTbl11.Colspan             = 1;
        cellTbl11.Border = Rectangle.BOX;
        tbl11.AddCell(cellTbl11);

        cellTbl11 = new Cell(new Phrase(" ", FontFactory.GetFont("Arial Narrow", 8, Font.NORMAL, Color.BLACK)));
        cellTbl11.HorizontalAlignment = Element.ALIGN_LEFT;
        cellTbl11.VerticalAlignment   = Element.ALIGN_MIDDLE;
        cellTbl11.Leading             = 8;
        cellTbl11.Colspan             = 1;
        cellTbl11.Border = Rectangle.NO_BORDER;
        tbl11.AddCell(cellTbl11);

        cellTbl11 = new Cell(new Phrase(" ", FontFactory.GetFont("Arial Narrow", 8, Font.NORMAL, Color.BLACK)));
        cellTbl11.HorizontalAlignment = Element.ALIGN_LEFT;
        cellTbl11.VerticalAlignment   = Element.ALIGN_MIDDLE;
        cellTbl11.Leading             = 8;
        cellTbl11.Colspan             = 1;
        cellTbl11.Border = Rectangle.NO_BORDER;
        tbl11.AddCell(cellTbl11);

        cellTbl11 = new Cell(new Phrase(" \n", FontFactory.GetFont("Arial Narrow", 8, Font.NORMAL, Color.BLACK)));
        cellTbl11.HorizontalAlignment = Element.ALIGN_CENTER;
        cellTbl11.VerticalAlignment   = Element.ALIGN_MIDDLE;
        cellTbl11.Leading             = 8;
        cellTbl11.Colspan             = 1;
        cellTbl11.Border = Rectangle.BOX;
        tbl11.AddCell(cellTbl11);

        MyDocumnet.Add(tbl11);
        #endregion

        MyDocumnet.Close();
        Response.Clear();

        Response.AddHeader("content-disposition", "attachment;filename=Q5533.pdf");
        Response.ContentType = "application/pdf";
        Response.BinaryWrite(MyReport.ToArray());
        Response.End();
    }
    public iTextSharp.text.Table GenerateCoreReport(String RptDate)
    {
        iTextSharp.text.Table datatable = new iTextSharp.text.Table(10);
        datatable.Padding = 4.0F;
        datatable.Spacing = 0.0F;
        //datatable.setBorder(Rectangle.NO_BORDER);
        int[] headerwidths = { 10, 24, 12, 12, 7, 7, 7, 7, 1, 1 };

        datatable.SetWidths(headerwidths);
        datatable.Width = 100;

        // the first cell spans 10 columns
        Cell cell = new Cell(new Phrase("Daily Production Report For " + RptDate, FontFactory.GetFont(FontFactory.HELVETICA, 18, iTextSharp.text.Font.BOLD)));
        cell.HorizontalAlignment = 1;
        cell.Leading = 30;
        cell.Colspan = 10;
        cell.Border =   iTextSharp.text.Rectangle.NO_BORDER;
        cell.BackgroundColor = iTextSharp.text.Color.LIGHT_GRAY;
        datatable.AddCell(cell);

        // These cells span 2 rows
        datatable.DefaultCellBorderWidth = 2;
        datatable.DefaultHorizontalAlignment = 1;
        datatable.DefaultRowspan = 2;
        datatable.AddCell("User Id");
        datatable.AddCell(new Phrase("Name", FontFactory.GetFont(FontFactory.HELVETICA, 14, iTextSharp.text.Font.BOLD)));
        datatable.AddCell("Work order");
        datatable.AddCell("Comments");

        // This cell spans the remaining 6 columns in 1 row
        datatable.DefaultRowspan = 1;
        datatable.DefaultColspan = 6;
        datatable.AddCell("Hours");

        // These cells span 1 row and 1 column
        datatable.DefaultColspan = 1;
        datatable.AddCell("Fab.");
        datatable.AddCell("Finish");
        datatable.AddCell("Eng.");
        datatable.AddCell("Misc.");
        datatable.AddCell("");
        datatable.AddCell("");

        //Here goes the Outer Loop to get the Project Information for the Day.Get the Project Name and display Here.
        whitfield_prod_reports _wproj = new whitfield_prod_reports();
        DataSet _mOuter = _wproj.GetProjectReportOuter(RptDate);
        DataTable dtProject = _mOuter.Tables[0];
        foreach (DataRow dProjRow in dtProject.Rows)
        {
            String _projNumber = dProjRow["TWC_Proj_Number"] == DBNull.Value ? "" : dProjRow["TWC_Proj_Number"].ToString();
            String _projName = dProjRow["ProjName"] == DBNull.Value ? "" : dProjRow["ProjName"].ToString();
            String _rptNumber = dProjRow["twc_report_number"] == DBNull.Value ? "" : dProjRow["twc_report_number"].ToString();

            Cell cell1 = new Cell(new Phrase(_projName + '(' + _projNumber + ')' , FontFactory.GetFont(FontFactory.HELVETICA, 12, iTextSharp.text.Font.BOLD)));
            cell1.HorizontalAlignment = 1;
            cell1.Leading = 30;
            cell1.Colspan = 10;
            cell1.Border = iTextSharp.text.Rectangle.TOP_BORDER;
            cell1.BackgroundColor = iTextSharp.text.Color.LIGHT_GRAY;
            datatable.AddCell(cell1);

            datatable.DefaultCellBorderWidth = 1;
            datatable.DefaultRowspan = 1;

            //Here Goes the Inner Loop for the Employees worked on the Project.
            DataSet _mInner = _wproj.GetProjectReportInner(Convert.ToInt32(_rptNumber), Convert.ToInt32(_projNumber));
            DataTable dtActivity = _mInner.Tables[0];
            foreach (DataRow drActivity in dtActivity.Rows)
            {
                datatable.DefaultHorizontalAlignment = 1;
                datatable.AddCell(drActivity["loginid"] == DBNull.Value ? "" : drActivity["loginid"].ToString());
                datatable.AddCell(drActivity["UName"] == DBNull.Value ? "" : drActivity["UName"].ToString());
                datatable.AddCell(drActivity["Description"] == DBNull.Value ? "" : drActivity["Description"].ToString());
                datatable.AddCell(drActivity["empl_comments"] == DBNull.Value ? "" : drActivity["empl_comments"].ToString());
                datatable.DefaultHorizontalAlignment = 0;
                datatable.AddCell(drActivity["fab_hours"] == DBNull.Value ? "0" : drActivity["fab_hours"].ToString());
                datatable.AddCell(drActivity["fin_hours"] == DBNull.Value ? "0" : drActivity["fin_hours"].ToString());
                datatable.AddCell(drActivity["eng_hours"] == DBNull.Value ? "0" : drActivity["eng_hours"].ToString());
                datatable.AddCell(drActivity["misc_hours"] == DBNull.Value ? "0" : drActivity["misc_hours"].ToString());
                _totFabHours += Convert.ToInt32(drActivity["fab_hours"] == DBNull.Value ? "0" : drActivity["fab_hours"].ToString());
                _totFinHours += Convert.ToInt32(drActivity["fin_hours"] == DBNull.Value ? "0" : drActivity["fin_hours"].ToString());
                _totEngHours += Convert.ToInt32(drActivity["eng_hours"] == DBNull.Value ? "0" : drActivity["eng_hours"].ToString());
                _totMiscHours += Convert.ToInt32(drActivity["misc_hours"] == DBNull.Value ? "0" : drActivity["misc_hours"].ToString());
                datatable.AddCell("");
                datatable.AddCell("");
            }
                    //Here goes the SubTotal Per project.. Dont Forget.
                    datatable.DefaultCellBorderWidth = 1;
                    datatable.DefaultRowspan = 1;
                    datatable.DefaultHorizontalAlignment = 1;
                    datatable.AddCell("");
                    datatable.AddCell("Subtotal:");
                    datatable.AddCell("");
                    datatable.AddCell("");
                    datatable.DefaultHorizontalAlignment = 0;
                    datatable.AddCell(_totFabHours.ToString());
                    datatable.AddCell(_totFinHours.ToString());
                    datatable.AddCell(_totEngHours.ToString());
                    datatable.AddCell(_totMiscHours.ToString());
                    datatable.AddCell("");
                    datatable.AddCell("");
                    //Subtotal calculation ends here.
            _totFabHours = 0;
            _totFinHours = 0;
            _totEngHours = 0;
            _totMiscHours = 0;
        }
        return datatable;
    }
Exemplo n.º 4
0
        /// <summary>
        /// overloading per passare nome e cognome dell'utente loggato,in modo da evidenziare le trasmissioni di cui l'utente è destinatario
        /// Dimitri
        /// </summary>
        /// <param name="tableTmp"></param>
        /// <param name="dt"></param>
        /// <param name="docPDF"></param>
        /// <param name="infoUt"></param>
        /// <returns></returns>
        protected static DocumentPDF printCustomTable(StampaVO.Table tableTmp, DataTable dt, DocumentPDF docPDF, DocsPaVO.utente.InfoUtente infoUt)
        {
            if (dt == null)
            {
                return(docPDF);
            }

            //** Operazioni Preliminari
            //reupero del numero di colonne dal DataTable
            int col         = tableTmp.columns.Length;
            int col_visible = 0;

            for (int j = 0; j < tableTmp.columns.Length; j++)
            {
                if (tableTmp.columns[j].visible)
                {
                    col_visible++;
                }
            }
            try
            {
                //creazione della tabella
                iTextSharp.text.Table aTable = new iTextSharp.text.Table(col_visible);

                //Adattamento delle colonne al contenuto
                aTable.Padding = tableTmp.padding;
                aTable.Spacing = tableTmp.spacing;
                //aTable.WidthPercentage = 100;
                aTable.Width     = 100;
                aTable.Alignment = Utils.getAlign(tableTmp.align);
                int[] widths = getColWidths(tableTmp, col_visible);

                aTable.SetWidths(widths);
                //aTable.hasToFitPageCells();
                aTable.TableFitsPage = true;

                //** Aggiunta automatica dell'header della tabella
                for (int k = 0; k < col; k++)
                {
                    if (((StampaVO.Column)tableTmp.columns[k]).visible)
                    {
                        StampaVO.Font font       = tableTmp.headerTable.font;
                        Font          font1      = FontFactory.GetFont(font.name, font.size, Utils.getFontStyle(font.style), Utils.getColor(font.color));
                        string        testo      = ((StampaVO.Column)tableTmp.columns[k]).alias;
                        string[]      testoSplit = testo.Split(';');
                        string        testo_1    = string.Empty;
                        if (testoSplit.Length > 1)
                        {
                            testo_1 = @testoSplit[0] + "\n" + testoSplit[1];
                        }
                        else
                        {
                            testo_1 = testoSplit[0];
                        }
                        Cell c = new Cell(new Phrase(testo_1, font1));
                        if (((StampaVO.Column)tableTmp.columns[k]).name == "DESCR" || ((StampaVO.Column)tableTmp.columns[k]).name == "MITT_UT" || ((StampaVO.Column)tableTmp.columns[k]).name == "DEST" || ((StampaVO.Column)tableTmp.columns[k]).name == "NOTE_GENER")
                        {
                            c.HorizontalAlignment = Utils.getAlign("LEFT");
                        }
                        else
                        {
                            c.HorizontalAlignment = Utils.getAlign(tableTmp.headerTable.align);
                        }
                        c.VerticalAlignment = Utils.getAlign(tableTmp.headerTable.vAlign);
                        c.NoWrap            = true;
                        c.BackgroundColor   = Utils.getColor(tableTmp.headerTable.bgColor);
                        aTable.AddCell(c);
                    }
                }
                aTable.EndHeaders();

                //** Popolamento automatico della tabella
                //Scansione dei dati
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    //Creazione delle celle
                    for (int h = 0; h < col; h++)
                    {
                        if (((StampaVO.Column)tableTmp.columns[h]).visible)
                        {
                            StampaVO.Font font          = tableTmp.dataTable.font;
                            string        style         = font.style;
                            string        column_name   = tableTmp.columns[h].name;
                            string        evidenziaDest = "";
                            if (dt.Rows[i]["SYSTEM_ID_DEST_UT"].ToString() == infoUt.idPeople && column_name == "DEST_UT")
                            {
                                evidenziaDest = "  *";
                                style         = "BOLD";
                            }

                            Font font1 = FontFactory.GetFont(font.name, font.size, Utils.getFontStyle(style), Utils.getColor(font.color));
                            // Font font1 = FontFactory.GetFont(font.name, font.size, Utils.getFontStyle(font.style), Utils.getColor(font.color));

                            Cell c1;

                            if (column_name == "ID_REG_PROTO_ANNO")
                            {
                                string s = string.Empty;
                                if (dt.Rows[i]["COD_REG"].ToString() != "")
                                {
                                    s = @dt.Rows[i]["ID"].ToString() + "\n" + dt.Rows[i]["COD_REG"].ToString() + " - " + dt.Rows[i]["NUM_PROTO"].ToString() + " - " + dt.Rows[i]["ANNO"].ToString();
                                }
                                else
                                {
                                    s = dt.Rows[i]["ID"].ToString() + "\n Non Protocollato";
                                }
                                c1 = new Cell(new Phrase(s, font1));
                                c1.HorizontalAlignment = Utils.getAlign(tableTmp.columns[h].align);
                                c1.VerticalAlignment   = Utils.getAlign(tableTmp.columns[h].vAlign);
                                aTable.AddCell(c1, new System.Drawing.Point(i + 1, h));
                            }
                            if (column_name == "MITT_UT")
                            {
                                string s = @dt.Rows[i][column_name].ToString();
                                c1 = new Cell(new Phrase(s, font1));
                                c1.HorizontalAlignment = Utils.getAlign(tableTmp.columns[h].align);
                                c1.VerticalAlignment   = Utils.getAlign(tableTmp.columns[h].vAlign);
                                aTable.AddCell(c1, new System.Drawing.Point(i + 1, h));
                            }
                            if (column_name == "MITT_RU")
                            {
                                string s = dt.Rows[i]["MITT_RU"].ToString();
                                c1 = new Cell(new Phrase(s, font1));
                                c1.HorizontalAlignment = Utils.getAlign(tableTmp.columns[h].align);
                                c1.VerticalAlignment   = Utils.getAlign(tableTmp.columns[h].vAlign);
                                aTable.AddCell(c1, new System.Drawing.Point(i + 1, h));
                            }

                            //Aggiunta note individuali alle generali
                            if (column_name == "NOTE_GENER")
                            {
                                if (dt.Rows[i]["NOTE_INDIVID"] != null)
                                {
                                    string s = @dt.Rows[i]["NOTE_GENER"].ToString() + Environment.NewLine + "--------------" + Environment.NewLine;
                                    if (dt.Rows[i]["SYSTEM_ID_MITT_UT"].ToString() == infoUt.idPeople)
                                    {
                                        s += dt.Rows[i]["NOTE_INDIVID"].ToString();
                                    }
                                    c1 = new Cell(new Phrase(s, font1));
                                    c1.HorizontalAlignment = Utils.getAlign(tableTmp.columns[h].align);
                                    c1.VerticalAlignment   = Utils.getAlign(tableTmp.columns[h].vAlign);
                                    aTable.AddCell(c1, new System.Drawing.Point(i + 1, h));
                                }
                            }

                            if (column_name == "DEST_UT")
                            {
                                if (dt.Rows[i]["DEST_UT"] != null)
                                {
                                    string s = @dt.Rows[i]["DEST_UT"].ToString() + evidenziaDest;
                                    c1 = new Cell(new Phrase(s, font1));
                                    c1.HorizontalAlignment = Utils.getAlign(tableTmp.columns[h].align);
                                    c1.VerticalAlignment   = Utils.getAlign(tableTmp.columns[h].vAlign);
                                    aTable.AddCell(c1, new System.Drawing.Point(i + 1, h));
                                }
                            }

                            if (column_name != "ID_REG_PROTO_ANNO" && column_name != "MITT_UT" && column_name != "MITT_RU" && column_name != "NUM_PROTO" && column_name != "ANNO" && column_name != "NOTE_GENER" && column_name != "DEST_UT")
                            {
                                c1 = new Cell(new Phrase(dt.Rows[i][column_name].ToString(), font1));
                                c1.HorizontalAlignment = Utils.getAlign(tableTmp.columns[h].align);
                                c1.VerticalAlignment   = Utils.getAlign(tableTmp.columns[h].vAlign);
                                aTable.AddCell(c1, new System.Drawing.Point(i + 1, h));
                            }
                        }
                    }
                }

                //     aTable.Complete();
                //     aTable.FlushContent();

                docPDF.Add(aTable);
            }

            catch (Exception ex)
            {
                docPDF.Close();
                writer.Close();
                throw new ReportException(ErrorCode.IncompletePDFFile, "Errore nella scrittura dei dati: " + ex.Message);
            }
            return(docPDF);
        }
        //Se genera el PDF
        public void VariasPaginas(string OT, string NombreOT, string FI, string FT, string Check)
        {            //inicio variables
            int    CantGuias   = 0;
            string tirajeTotal = "";
            int    totalDesp   = 0;

            //fin variables
            List <DespachoPDF> lista = ListDespacho(OT, NombreOT, FI, FT, Check);


            MemoryStream MStream  = new MemoryStream();
            Document     document = new Document(PageSize.A4.Rotate(), 30, 30, 60, 30);
            PdfWriter    writer   = PdfWriter.GetInstance(document, MStream);

            writer.CloseStream = false;

            itsEvents ev = new itsEvents();

            writer.PageEvent = ev;
            BaseFont bftime = BaseFont.CreateFont(BaseFont.TIMES_ROMAN, BaseFont.CP1252, false);
            Font     time   = new Font(bftime, 16, Font.BOLD, Color.BLACK);

            if (FI == "01/01/1900" || FT == ":01/01/1900")
            {
                info = "INFORME DIARIO \nFecha : " + DateTime.Now.ToString("dd/MM/yyyy") + " ";// Nombre : " + NombreOT + "
            }
            else
            {
                if (FI == FT)
                {
                    info = "INFORME DIARIO \nFecha : " + FI + " ";
                }
                else
                {
                    info = "INFORME DIARIO \nFecha Inicio:" + FI + "  Fecha Termino: " + FT;
                }
            }



            Paragraph    para   = new Paragraph("  ", time);//"      Informe Despachos por OT \n", time
            HeaderFooter header = new HeaderFooter(para, false);

            header.Alignment = Element.ALIGN_CENTER;
            header.Border    = 0;

            document.Header = header;
            document.Open();


            int columnCount = 7;
            int rowCount    = lista.Count;
            int tableRows   = rowCount + 3;

            iTextSharp.text.Table grdTable = new iTextSharp.text.Table(columnCount, tableRows);
            //
            grdTable.Width = 100;
            //int[] w = new int[] { 12, 13, 35, 60, 25, 15, 20, 2 };
            //int[] w = new int[] { 8, 18, 36, 68, 15, 10, 8 }; ORIGNAL
            int[] w = new int[] { 12, 13, 35, 60, 25, 15, 20 };
            grdTable.SetWidths(w);
            grdTable.BorderColor = new iTextSharp.text.Color(0);
            grdTable.BorderWidth = 1;//1
            grdTable.Cellpadding = 15;
            grdTable.Cellspacing = -15;

            int[] widths   = new int[lista.Count];
            int   contador = 0;

            foreach (DespachoPDF des in lista)
            {
                if ((contador % 2) == 0)
                {
                    grdTable.DefaultCell.BackgroundColor = new iTextSharp.text.Color(255, 255, 255);
                    grdTable.Cellpadding = 1;
                    grdTable.Cellspacing = 0;
                    //grdTable.DefaultCell.BorderColor = new iTextSharp.text.Color(255, 255, 255);
                }
                else
                {
                    grdTable.DefaultCell.BackgroundColor = new iTextSharp.text.Color(210, 210, 210);
                    grdTable.Cellpadding = 1;
                    grdTable.Cellspacing = 0;
                    //grdTable.DefaultCell.BorderColor = new iTextSharp.text.Color(255, 255, 255);
                }
                bftime = BaseFont.CreateFont(BaseFont.TIMES_ROMAN, BaseFont.CP1252, false);
                time   = new Font(bftime, 9, Font.NORMAL, Color.BLACK);

                grdTable.DefaultCell.HorizontalAlignment = Element.ALIGN_LEFT;

                grdTable.AddCell(new Paragraph(des.OT, time));
                grdTable.DefaultCell.HorizontalAlignment = Element.ALIGN_RIGHT;

                grdTable.AddCell(new Paragraph(des.guia.ToString(), time));
                grdTable.DefaultCell.HorizontalAlignment = Element.ALIGN_LEFT;

                grdTable.AddCell(new Paragraph(des.NombreOT, time));
                grdTable.AddCell(new Paragraph(des.Cliente, time));
                grdTable.DefaultCell.HorizontalAlignment = Element.ALIGN_CENTER;
                grdTable.AddCell(new Paragraph(des.FechaImpresion.ToString(), time));

                grdTable.DefaultCell.HorizontalAlignment = Element.ALIGN_RIGHT;

                grdTable.AddCell(new Paragraph(des.TirajeTotal, time));
                grdTable.AddCell(new Paragraph(des.Despachado, time));
                contador++;

                totalDesp   = totalDesp + des.Rut;
                CantGuias   = CantGuias + 1;
                tirajeTotal = des.TirajeTotal;
            }

            ////
            //iTextSharp.text.Table grdTable2 = new iTextSharp.text.Table(3, 3);
            ////
            //grdTable2.Width = 100;

            //int[] w2 = new int[] { 100, 15, 10 };
            //grdTable2.SetWidths(w2);
            //grdTable2.BorderColor = new iTextSharp.text.Color(0);
            //grdTable2.BorderWidth = 0;
            //grdTable2.Cellpadding = 1;//15
            ////grdTable2.Cellspacing = -15;
            //grdTable2.DefaultCell.Border = 0;
            //grdTable2.AddCell(new Paragraph("", time));//1
            //grdTable2.DefaultCell.BackgroundColor = new iTextSharp.text.Color(210, 210, 210);
            //grdTable2.DefaultCell.HorizontalAlignment = Element.ALIGN_LEFT;
            //grdTable2.DefaultCell.Border = 1;
            //grdTable2.DefaultCell.BorderWidthLeft = 1;
            //grdTable2.DefaultCell.BorderWidthRight = 1;
            //grdTable2.AddCell(new Paragraph("Cantidad Guías: ", time));

            //grdTable2.DefaultCell.BackgroundColor = new iTextSharp.text.Color(255, 255, 255);
            //grdTable2.DefaultCell.HorizontalAlignment = Element.ALIGN_RIGHT;
            //grdTable2.AddCell(new Paragraph(" " + CantGuias.ToString("N0"), time));

            //grdTable2.DefaultCell.Border = 0;
            //grdTable2.AddCell(new Paragraph("", time));//2
            //grdTable2.DefaultCell.BackgroundColor = new iTextSharp.text.Color(210, 210, 210);
            //grdTable2.DefaultCell.HorizontalAlignment = Element.ALIGN_LEFT;
            //grdTable2.DefaultCell.Border = 1;
            //grdTable2.DefaultCell.BorderWidthLeft = 1;
            //grdTable2.DefaultCell.BorderWidthRight = 1;
            //grdTable2.AddCell(new Paragraph("Tiraje Total: ", time));

            //grdTable2.DefaultCell.BackgroundColor = new iTextSharp.text.Color(255, 255, 255);
            //grdTable2.DefaultCell.HorizontalAlignment = Element.ALIGN_RIGHT;
            //grdTable2.AddCell(new Paragraph(" " + tirajeTotal, time));

            //grdTable2.DefaultCell.Border = 0;
            //grdTable2.AddCell(new Paragraph("", time));//3
            //grdTable2.DefaultCell.BackgroundColor = new iTextSharp.text.Color(210, 210, 210);
            //grdTable2.DefaultCell.HorizontalAlignment = Element.ALIGN_LEFT;
            //grdTable2.DefaultCell.Border = 1;
            //grdTable2.DefaultCell.BorderWidthLeft = 1;
            //grdTable2.DefaultCell.BorderWidthRight = 1;
            //grdTable2.DefaultCell.BorderWidthBottom = 1;
            //grdTable2.AddCell(new Paragraph("Total Despachado: ", time));

            //grdTable2.DefaultCell.BackgroundColor = new iTextSharp.text.Color(255, 255, 255);
            //grdTable2.DefaultCell.HorizontalAlignment = Element.ALIGN_RIGHT;
            //grdTable2.AddCell(new Paragraph(" " + totalDesp.ToString("N0"), time));



            document.Add(grdTable);

            //document.Add(new Paragraph("\n"));
            //document.Add(grdTable2);

            document.Close();

            //var context = HttpContext.Current;
            Response.ContentType = "application/pdf";
            Response.Buffer      = true;
            Response.ClearContent();
            Response.ClearHeaders();

            string fecha = "";

            if (FI == "01/01/1900" || FI == "")
            {
                fecha = DateTime.Now.ToString("dd/MM/yyyy");
            }
            else
            {
                fecha = FI;
            }
            Response.AddHeader("Content-Disposition", "attachment;filename=InformeDiario_" + fecha.ToString() + ".pdf");
            Response.BinaryWrite(MStream.GetBuffer());
            Response.End();
        }
Exemplo n.º 6
0
        /// <summary>
        /// 输出到PDF
        /// </summary>
        /// <param name="list"></param>
        /// <param name="sysFont"></param>
        /// <param name="multiRow"></param>
        /// <param name="export">算高度的情况最后输出时使用</param>
        /// <returns></returns>
        public Table WriteFields(List<List<PdfDesc>> list, System.Drawing.Font sysFont, int multiRow, bool export)
        {
            #region Variable Definition
            Cell cell = null;
            int maxColumnCount = -1;
            int maxRowCount = -1;
            LineSeparator lineSeparator = null;
            int tempCount = 0;
            int previousFieldCells = 0;
            Table tb = null;
            #endregion

            //try
            //{
                Font pdfFont = this.GetPdfFont(sysFont);

                //Hashtable allStartIndex = new Hashtable();

                Dictionary<int, int> allStartIndex = new Dictionary<int, int>();

                if (export)
                {
                    foreach (List<PdfDesc> row in list)
                    {
                        if (!allStartIndex.ContainsKey(row[0].FieldNum))
                        {
                            allStartIndex.Add(row[0].FieldNum, list.IndexOf(row));
                        }
                    }
                }
                else
                {
                    allStartIndex.Add(0, 0);
                }

                List<int> startIndex = new List<int>();

                foreach (int index in allStartIndex.Values)
                {
                    startIndex.Add(index);
                }

                for (int l = 0; l < startIndex.Count; l++)
                {
                    //計算最大Column和最大Row

                    maxColumnCount = 0;

                    if (startIndex.Count == 1)
                    {
                        maxRowCount = list.Count;
                    }
                    else if (l != startIndex.Count - 1)
                    {
                        maxRowCount = startIndex[l + 1] - startIndex[l];
                    }
                    else
                    {
                        maxRowCount = list.Count - startIndex[l];
                    }

                    for (int s = startIndex[l]; s < list.Count; s++)
                    //foreach (List<PdfDesc> row in list)
                    {
                        if (startIndex.Count != 1)
                        {
                            if (l != startIndex.Count - 1 && s == startIndex[l + 1])
                            {
                                break;
                            }
                        }

                        List<PdfDesc> row = list[s];

                        foreach (PdfDesc pdfDesc in row)
                        {
                            tempCount += pdfDesc.Cells;
                        }

                        if (tempCount > maxColumnCount)
                        {
                            maxColumnCount = tempCount;
                        }

                        tempCount = 0;
                    }

                    tb = new Table(maxColumnCount, maxRowCount);

                    #region 計算欄位寬度
                    if (multiRow == 1)
                    {
                        int[] widths = new int[maxColumnCount];

                        previousFieldCells = 0;

                        List<PdfDesc> firstRow = list[startIndex[l]];

                        for (int i = 0; i < firstRow.Count; i++)
                        {
                            int widthPercent = Convert.ToInt32(Math.Truncate((UnitConversion.GetPdfLetterWidth(firstRow[i].Width, sysFont)
                                / Convert.ToDouble((this.pdfDoc.PageSize.Width - this.pdfDoc.LeftMargin - this.pdfDoc.RightMargin))) * 100)); //算出百分比

                            if (i == 0)
                            {
                                widths[i] = widthPercent;

                                if (firstRow[i].Cells > 1)
                                {
                                    for (int j = 0; j < firstRow[i].Cells - 1; j++)
                                    {
                                        widths[i + j + 1] = widthPercent;
                                    }
                                }
                            }
                            else
                            {
                                widths[previousFieldCells] = widthPercent;

                                if (firstRow[i].Cells > 1)
                                {
                                    for (int j = 0; j < firstRow[i].Cells - 1; j++)
                                    {
                                        widths[previousFieldCells + j + 1] = widthPercent;
                                    }
                                }
                            }

                            previousFieldCells += firstRow[i].Cells;
                        }

                        tb.SetWidths(widths);

                        previousFieldCells = 0;
                    }
                    #endregion

                    if (!this.report.Format.ColumnGridLine)
                    {
                        tb.Border = Rectangle.NO_BORDER;
                    }

                    tb.Cellpadding = PdfSizeConfig.Cellpadding;
                    //tb.Width = ((this.pdfDoc.PageSize.Width - this.pdfDoc.LeftMargin - this.pdfDoc.RightMargin) / this.pdfDoc.PageSize.Width) * 100; //此處為百分比
                    tb.Width = 100;
                    tb.Alignment = Element.ALIGN_LEFT;

                    for (int j = startIndex[l]; j < list.Count; j++)
                    {
                        if (startIndex.Count != 1)
                        {
                            if (l != startIndex.Count - 1 && j == startIndex[l + 1])
                            {
                                break;
                            }
                        }

                        List<PdfDesc> row = list[j];

                        previousFieldCells = 0;
                        for (int i = 0; i < row.Count; i++)
                        {
                            PdfDesc pdfDesc = row[i];

                            switch (pdfDesc.GroupGap)
                            {
                                case DataSourceItem.GroupGapType.None:
                                    cell = new Cell(new Chunk(pdfDesc.Value, pdfFont));
                                    cell.Colspan = pdfDesc.Cells;
                                    cell.HorizontalAlignment = this.GetPdfHAlignByStr(pdfDesc.HAlign);
                                    break;
                                case DataSourceItem.GroupGapType.EmptyRow:
                                    if (i == 0)
                                    {
                                        cell = new Cell(new Chunk(String.Empty, pdfFont));
                                        cell.Colspan = maxColumnCount;
                                    }
                                    break;
                                case DataSourceItem.GroupGapType.SingleLine:
                                    if (i == 0)
                                    {
                                        cell = new Cell();
                                        lineSeparator = new LineSeparator();
                                        lineSeparator.LineWidth = cell.Width;
                                        lineSeparator.Offset = PdfSizeConfig.LineSeparatorOffsetU;
                                        cell.AddElement(lineSeparator);
                                        cell.Colspan = tb.Columns;
                                    }
                                    break;
                                case DataSourceItem.GroupGapType.DoubleLine:
                                    if (i == 0)
                                    {
                                        cell = new Cell();
                                        lineSeparator = new LineSeparator();
                                        lineSeparator.LineWidth = cell.Width;
                                        lineSeparator.Offset = PdfSizeConfig.LineSeparatorOffsetU;
                                        cell.AddElement(lineSeparator);
                                        lineSeparator = new LineSeparator();
                                        lineSeparator.LineWidth = cell.Width;
                                        lineSeparator.Offset = PdfSizeConfig.LineSeparatorOffsetD;
                                        cell.AddElement(lineSeparator);
                                        cell.Colspan = tb.Columns;
                                    }
                                    break;
                            }

                            cell.BorderWidthLeft = pdfDesc.LeftLine == true ? PdfSizeConfig.BorderWidth : PdfSizeConfig.BorderWidthZero;
                            cell.BorderWidthRight = pdfDesc.RightLine == true ? PdfSizeConfig.BorderWidth : PdfSizeConfig.BorderWidthZero;
                            cell.BorderWidthTop = pdfDesc.TopLine == true ? PdfSizeConfig.BorderWidth : PdfSizeConfig.BorderWidthZero;
                            cell.BorderWidthBottom = pdfDesc.BottomLine == true ? PdfSizeConfig.BorderWidth : PdfSizeConfig.BorderWidthZero;

                            if (j == list.Count - 1)
                            {
                                cell.BorderWidthBottom = report.Format.RowGridLine == true ? PdfSizeConfig.BorderWidth : PdfSizeConfig.BorderWidthZero;
                            }

                            cell.UseAscender = true; //此屬性設置為True的時候VerticalAlignment才會起作用
                            cell.VerticalAlignment = Cell.ALIGN_MIDDLE;

                            switch (pdfDesc.GroupGap)
                            {
                                case DataSourceItem.GroupGapType.None:
                                    if (i == 0)
                                    {
                                        tb.AddCell(cell, j, i);
                                    }
                                    else
                                    {
                                        tb.AddCell(cell, j, previousFieldCells);
                                    }
                                    break;
                                case DataSourceItem.GroupGapType.EmptyRow:
                                case DataSourceItem.GroupGapType.SingleLine:
                                case DataSourceItem.GroupGapType.DoubleLine:
                                    if (i == 0)
                                    {
                                        tb.AddCell(cell, j, i);
                                    }
                                    break;
                            }

                            previousFieldCells += pdfDesc.Cells;
                        }
                    }

                    if (!ExportByHeight || export)
                    {
                        this.pdfDoc.Add(tb);
                    }
                }
            //}
            //catch (Exception ex)
            //{
            //    log.WriteExceptionInfo(ex);
            //    throw ex;
            //}

            return tb;
        }
        //Se genera el PDF
        public void VariasPaginas(string OT, string NombreOT, string Cliente, string FeInicio, string FeTermino)
        {
            info = "";
            List <DespachoFuturosExcel> lista = ListDespachoFuturos(OT, NombreOT, Cliente, FeInicio, FeTermino);
            MemoryStream MStream  = new MemoryStream();
            Document     document = new Document(PageSize.A4.Rotate(), 30, 30, 60, 30);
            PdfWriter    writer   = PdfWriter.GetInstance(document, MStream);

            writer.CloseStream = false;

            itsEvents ev = new itsEvents();

            writer.PageEvent = ev;
            BaseFont bftime = BaseFont.CreateFont(BaseFont.TIMES_ROMAN, BaseFont.CP1252, false);
            Font     time   = new Font(bftime, 16, Font.BOLD, Color.BLACK);

            if (OT != "" || NombreOT != "" || Cliente != "" || (FeInicio != "" && FeTermino != ""))
            {
                if (OT != "")
                {
                    info = info + "OT : " + OT;
                }
                if (NombreOT != "")
                {
                    info = info + " Nombre OT : " + NombreOT;
                }
                if (Cliente != "")
                {
                    info = info + " Cliente :" + Cliente;
                }
                if (FeInicio != "")
                {
                    info = info + " Fecha Inicio : " + FeInicio;
                }
                if (FeTermino != "")
                {
                    info = info + " Fecha Termino " + FeTermino;
                }
            }
            else
            {
                string   f           = DateTime.Now.ToShortDateString();
                string[] str3        = f.Split('/');
                string   nowFecha    = str3[1] + "/" + str3[0] + "/" + str3[2].Substring(0, 4) + " 0:00:00 AM";
                string   f2          = DateTime.Now.ToString();
                string[] str4        = f2.Split('/');
                string   mañanaFecha = str4[1] + "/" + str4[0] + "/" + str4[2].Substring(0, 4);
                info = "Fecha Inicio : " + nowFecha + " Fecha Termino : " + mañanaFecha + " 23:59:59 PM";
            }
            Paragraph    para   = new Paragraph("      Informe Despachos Futuros \n", time);
            HeaderFooter header = new HeaderFooter(para, false);

            header.Alignment = Element.ALIGN_CENTER;
            header.Border    = 0;

            document.Header = header;
            document.Open();


            int columnCount = 6;
            int rowCount    = lista.Count;
            int tableRows   = rowCount + 3;

            iTextSharp.text.Table grdTable = new iTextSharp.text.Table(columnCount, tableRows);
            //
            grdTable.Width = 100;
            int[] w = new int[] { 8, 36, 36, 15, 15, 10 };
            grdTable.SetWidths(w);
            grdTable.BorderColor = new iTextSharp.text.Color(0);
            grdTable.BorderWidth = 1;
            grdTable.Cellpadding = 15;
            grdTable.Cellspacing = -15;

            int[] widths   = new int[lista.Count];
            int   contador = 0;

            foreach (DespachoFuturosExcel des in lista)
            {
                if ((contador % 2) == 0)
                {
                    grdTable.DefaultCell.BackgroundColor = new iTextSharp.text.Color(255, 255, 255);
                    grdTable.Cellpadding = 1;
                    grdTable.Cellspacing = 0;
                    //grdTable.DefaultCell.BorderColor = new iTextSharp.text.Color(255, 255, 255);
                }
                else
                {
                    grdTable.DefaultCell.BackgroundColor = new iTextSharp.text.Color(210, 210, 210);
                    grdTable.Cellpadding = 1;
                    grdTable.Cellspacing = 0;
                    //grdTable.DefaultCell.BorderColor = new iTextSharp.text.Color(255, 255, 255);
                }
                bftime = BaseFont.CreateFont(BaseFont.TIMES_ROMAN, BaseFont.CP1252, false);
                time   = new Font(bftime, 9, Font.NORMAL, Color.BLACK);
                grdTable.DefaultCell.HorizontalAlignment = Element.ALIGN_LEFT;
                grdTable.AddCell(new Paragraph(des.OT, time));
                grdTable.AddCell(new Paragraph(des.NombreOT, time));
                grdTable.AddCell(new Paragraph(des.Cliente, time));
                grdTable.DefaultCell.HorizontalAlignment = Element.ALIGN_RIGHT;
                grdTable.AddCell(new Paragraph(des.Cant, time));
                DateTime de    = Convert.ToDateTime(des.FechaDes);
                string   fecha = de.ToString("dd/MM/yyyy HH:mm:ss");//des.fechades.tostring(...)
                grdTable.AddCell(new Paragraph(fecha, time));
                try
                {
                    string[] str        = des.Despachado.Split('>');
                    string   porcentaje = str[1];
                    grdTable.AddCell(new Paragraph(porcentaje, time));
                }
                catch
                {
                    grdTable.AddCell(new Paragraph(des.Despachado, time));
                }
                contador++;
            }


            document.Add(grdTable);
            document.Close();

            //var context = HttpContext.Current;
            Response.ContentType = "application/pdf";
            Response.Buffer      = true;
            Response.ClearContent();
            Response.ClearHeaders();

            Response.AddHeader("Content-Disposition", "attachment;filename=Reporte_Despacho.pdf");
            Response.BinaryWrite(MStream.GetBuffer());
            Response.End();
        }
Exemplo n.º 8
0
    //Begin gridview for pdf
    protected void btnExportPDF_Click(object sender, EventArgs e)
    {
        gvEventCaf.AllowPaging = Convert.ToBoolean(rbPaging.SelectedItem.Value);
        EventsDataContext edc = new EventsDataContext();
        var events            = (from f in edc.tblEvents_Cafes
                                 where f.EventDateTime >= DateTime.Now && f.VenueCity.Trim() == city.Trim() && (f.VenueName.Contains("Café") || f.VenueName.Contains("Cafe"))
                                 orderby f.EventDateTime
                                 select new
        {
            EventName = f.EventName,
            EventDate = f.EventDate,
            EventTime = f.EventTime,
            VenueName = f.VenueName,
            Description = edc.tblEvents_Cafe_Descriptions.OrderBy(d => d.Priority).Where(d => d.Keywords.ToLower() == f.EventName.ToLower()).Select(d => d.Description).First(),               // edc.tblEvents_Cafe_Descriptions.OrderBy(d => d.Priority).Where(d => d.Keywords.ToLower() == e.EventName.ToLower() || d.Keywords.ToLower().CompareTo(e.EventName.ToLower()) >= 0).Select(d => d.Description).First()
        }).Take(showcount);

        gvEventCaf.DataSource = events;
        gvEventCaf.DataBind();
        //Create a table
        iTextSharp.text.Table table = new iTextSharp.text.Table(gvEventCaf.Columns.Count);
        table.Cellpadding = 5;
        //Set the column widths
        int[] widths = new int[gvEventCaf.Columns.Count];
        for (int x = 0; x < gvEventCaf.Columns.Count; x++)
        {
            widths[x] = (int)gvEventCaf.Columns[x].ItemStyle.Width.Value;
            string cellText           = Server.HtmlDecode(gvEventCaf.HeaderRow.Cells[x].Text);
            iTextSharp.text.Cell cell = new iTextSharp.text.Cell(cellText);
            cell.BackgroundColor = new Color(System.Drawing.ColorTranslator.FromHtml("#25925c"));
            table.AddCell(cell);
        }
        table.SetWidths(widths);
        //Transfer rows from GridView to table
        for (int i = 0; i < gvEventCaf.Rows.Count; i++)
        {
            if (gvEventCaf.Rows[i].RowType == DataControlRowType.DataRow)
            {
                for (int j = 0; j < gvEventCaf.Columns.Count; j++)
                {
                    string cellText           = Server.HtmlDecode(gvEventCaf.Rows[i].Cells[j].Text);
                    iTextSharp.text.Cell cell = new iTextSharp.text.Cell(cellText);
                    //Set Color of Alternating row
                    if (i % 2 != 0)
                    {
                        cell.BackgroundColor = new Color(System.Drawing.ColorTranslator.FromHtml("#C2D69B"));
                    }
                    table.AddCell(cell);
                }
            }
        }
        //Create the PDF Document
        Document pdfDoc = new Document(PageSize.A4, 10f, 10f, 10f, 0f);

        PdfWriter.GetInstance(pdfDoc, Response.OutputStream);
        pdfDoc.Open();
        Paragraph chunk = new Paragraph("Calendar of Events for " + city + "Cafe");

        pdfDoc.Add(chunk);
        pdfDoc.Add(table);
        pdfDoc.Close();
        Response.ContentType = "application/pdf";
        Response.AddHeader("content-disposition", "attachment;filename=CafeCalendar.pdf");
        Response.Cache.SetCacheability(HttpCacheability.NoCache);
        Response.Write(pdfDoc);
        Response.End();
    }
Exemplo n.º 9
0
        //public void PDModel2Html(PDModel m)
        //{
        //    Export(m, ExportTyep.HTML);
        //}

        private void Export(IList<PDTable> tableList,string title, ExportTyep exportType)
        {
            Document doc = new Document(PageSize.A4.Rotate(), 20, 20, 20, 20);
            DocWriter w;

            switch (exportType)
            {
                case ExportTyep.PDF:
                    w = PdfWriter.GetInstance(doc, new FileStream(fileName, FileMode.Create, FileAccess.Write));
                    break;
                case ExportTyep.RTF:
                    w = RtfWriter2.GetInstance(doc, new FileStream(fileName, FileMode.Create, FileAccess.Write));
                    break;
                //case ExportTyep.HTML:
                //    w = HtmlWriter.GetInstance(doc, new FileStream(fileName, FileMode.Create, FileAccess.Write));
                //break;
                default:
                    break;
            }

            doc.Open();
            doc.NewPage();

            //IList<PDTable> tableList = m.AllTableList;

            //Chapter cpt = new Chapter(m.Name, 1);
            Chapter cpt = new Chapter(title, 1);
            Section sec;

            //doc.AddTitle(m.Name);
            doc.AddTitle(title);
            doc.AddAuthor("Kalman");
            doc.AddCreationDate();
            doc.AddCreator("Kalman");
            doc.AddSubject("PDM数据库文档");

            foreach (PDTable table in tableList)
            {
                sec = cpt.AddSection(new Paragraph(string.Format("{0}[{1}]", table.Name, table.Code), font));

                if (string.IsNullOrEmpty(table.Comment) == false)
                {
                    Chunk chunk = new Chunk(table.Comment, font);
                    sec.Add(chunk);
                }

                t = new Table(9, table.ColumnList.Count);

                //t.Border = 15;
                //t.BorderColor = Color.BLACK;
                //t.BorderWidth = 1.0f;
                t.AutoFillEmptyCells = true;
                t.CellsFitPage = true;
                t.TableFitsPage = true;
                t.Cellpadding = 3;
                //if (exportType == ExportTyep.PDF) t.Cellspacing = 2;
                t.DefaultVerticalAlignment = Element.ALIGN_MIDDLE;

                t.SetWidths(new int[] { 200, 200, 150, 50, 50, 50, 50, 50, 300 });

                t.AddCell(BuildHeaderCell("名称"));
                t.AddCell(BuildHeaderCell("代码"));
                t.AddCell(BuildHeaderCell("数据类型"));
                t.AddCell(BuildHeaderCell("长度"));
                t.AddCell(BuildHeaderCell("精度"));
                t.AddCell(BuildHeaderCell("主键"));
                t.AddCell(BuildHeaderCell("外键"));
                t.AddCell(BuildHeaderCell("可空"));
                t.AddCell(BuildHeaderCell("注释"));

                foreach (PDColumn column in table.ColumnList)
                {
                    t.AddCell(BuildCell(column.Name));
                    t.AddCell(BuildCell(column.Code));
                    t.AddCell(BuildCell(column.DataType));
                    t.AddCell(BuildCell(column.Length == 0 ? "" : column.Length.ToString()));
                    t.AddCell(BuildCell(column.Precision == 0 ? "" : column.Precision.ToString()));
                    t.AddCell(BuildCell(column.IsPK ? " √" : ""));
                    t.AddCell(BuildCell(column.IsFK ? " √" : ""));
                    t.AddCell(BuildCell(column.Mandatory ? "" : " √"));
                    t.AddCell(BuildCell(column.Comment));
                }

                sec.Add(t);
            }

            doc.Add(cpt);
            doc.Close();
        }
Exemplo n.º 10
0
        private List<SOTable> Export(DbSchema schema, SODatabase db, List<SOTable> tableList, ExportTyep exportType)
        {
            if (schema == null) throw new ArgumentException("参数schema不能为空", "schema");
            if (db == null) throw new ArgumentException("参数dbName不能为空", "dbName");

            Document doc = new Document(PageSize.A4.Rotate(), 20, 20, 20, 20);
            DocWriter w;

            switch (exportType)
            {
                case ExportTyep.PDF:
                    w = PdfWriter.GetInstance(doc, new FileStream(fileName, FileMode.Create, FileAccess.Write));
                    break;
                case ExportTyep.RTF:
                    w = RtfWriter2.GetInstance(doc, new FileStream(fileName, FileMode.Create, FileAccess.Write));
                    break;
                //case ExportTyep.HTML:
                //    w = HtmlWriter.GetInstance(doc, new FileStream(fileName, FileMode.Create, FileAccess.Write));
                    //break;
                default:
                    break;
            }

            doc.Open();
            doc.NewPage();

            if (tableList == null) tableList = schema.GetTableList(db);

            Chapter cpt = new Chapter(db.Name, 1);
            Section sec;

            doc.AddTitle(db.Name);
            doc.AddAuthor("Kalman");
            doc.AddCreationDate();
            doc.AddCreator("Kalman");
            doc.AddSubject("数据库文档");

            foreach (SOTable table in tableList)
            {
                sec = cpt.AddSection(new Paragraph(table.Name, font));

                if (string.IsNullOrEmpty(table.Comment) == false)
                {
                    Chunk chunk = new Chunk(table.Comment, font);
                    sec.Add(chunk);
                }

                List<SOColumn> columnList = schema.GetTableColumnList(table);

                t = new Table(7, columnList.Count);

                t.AutoFillEmptyCells = true;
                t.CellsFitPage = true;
                t.TableFitsPage = true;
                t.Cellpadding = 3;
                //if (exportType == ExportTyep.PDF) t.Cellspacing = 2;
                t.DefaultVerticalAlignment = Element.ALIGN_MIDDLE;

                t.SetWidths(new int[] { 200, 150, 50, 50, 50, 100, 300 });

                t.AddCell(BuildHeaderCell("名称"));
                t.AddCell(BuildHeaderCell("数据类型"));
                t.AddCell(BuildHeaderCell("主键"));
                t.AddCell(BuildHeaderCell("标志"));
                t.AddCell(BuildHeaderCell("可空"));
                t.AddCell(BuildHeaderCell("默认值"));
                t.AddCell(BuildHeaderCell("注释"));

                foreach (SOColumn column in columnList)
                {
                    t.AddCell(BuildCell(column.Name));
                    t.AddCell(BuildCell(GetDbColumnType(column)));
                    t.AddCell(BuildCell(column.PrimaryKey ? " √" : ""));
                    t.AddCell(BuildCell(column.Identify ? " √" : ""));
                    t.AddCell(BuildCell(column.Nullable ? " √" : ""));
                    t.AddCell(BuildCell(column.DefaultValue == null ? "" : column.DefaultValue.ToString()));
                    t.AddCell(BuildCell(column.Comment));
                }

                sec.Add(t);
            }

            doc.Add(cpt);
            doc.Close();
            return tableList;
        }
Exemplo n.º 11
0
        //Se genera el PDF
        public void VariasPaginas(string OT, string NombreOT)
        {
            List <Despacho> lista    = ListDespacho(OT);
            MemoryStream    MStream  = new MemoryStream();
            Document        document = new Document(PageSize.A4.Rotate(), 30, 30, 60, 30);
            PdfWriter       writer   = PdfWriter.GetInstance(document, MStream);

            writer.CloseStream = false;

            itsEvents ev = new itsEvents();

            writer.PageEvent = ev;
            BaseFont bftime = BaseFont.CreateFont(BaseFont.TIMES_ROMAN, BaseFont.CP1252, false);
            Font     time   = new Font(bftime, 16, Font.BOLD, Color.BLACK);

            info = "OT : " + OT + "  Nombre : " + NombreOT;
            Paragraph    para   = new Paragraph("      Informe Despachos por OT \n", time);
            HeaderFooter header = new HeaderFooter(para, false);

            header.Alignment = Element.ALIGN_CENTER;
            header.Border    = 0;

            document.Header = header;
            document.Open();


            int columnCount = 7;
            int rowCount    = lista.Count;
            int tableRows   = rowCount + 3;

            iTextSharp.text.Table grdTable = new iTextSharp.text.Table(columnCount, tableRows);
            //
            grdTable.Width = 100;
            int[] w = new int[] { 8, 18, 36, 68, 15, 10, 8 };
            grdTable.SetWidths(w);
            grdTable.BorderColor = new iTextSharp.text.Color(0);
            grdTable.BorderWidth = 1;
            grdTable.Cellpadding = 15;
            grdTable.Cellspacing = -15;

            int[] widths   = new int[lista.Count];
            int   contador = 0;

            foreach (Despacho des in lista)
            {
                if ((contador % 2) == 0)
                {
                    grdTable.DefaultCell.BackgroundColor = new iTextSharp.text.Color(255, 255, 255);
                    grdTable.Cellpadding = 1;
                    grdTable.Cellspacing = 0;
                    //grdTable.DefaultCell.BorderColor = new iTextSharp.text.Color(255, 255, 255);
                }
                else
                {
                    grdTable.DefaultCell.BackgroundColor = new iTextSharp.text.Color(210, 210, 210);
                    grdTable.Cellpadding = 1;
                    grdTable.Cellspacing = 0;
                    //grdTable.DefaultCell.BorderColor = new iTextSharp.text.Color(255, 255, 255);
                }
                bftime = BaseFont.CreateFont(BaseFont.TIMES_ROMAN, BaseFont.CP1252, false);
                time   = new Font(bftime, 9, Font.NORMAL, Color.BLACK);
                grdTable.AddCell(new Paragraph(des.NumeroFolio, time));
                grdTable.AddCell(new Paragraph(des.FechaImpresion.ToString(), time));
                grdTable.AddCell(new Paragraph(des.Destinatario, time));
                grdTable.AddCell(new Paragraph(des.Sucursal, time));
                grdTable.AddCell(new Paragraph(des.Comuna, time));
                grdTable.AddCell(new Paragraph(des.StatusDes, time));
                grdTable.AddCell(new Paragraph(des.Despachado, time));
                contador++;
            }


            document.Add(grdTable);
            document.Close();

            //var context = HttpContext.Current;
            Response.ContentType = "application/pdf";
            Response.Buffer      = true;
            Response.ClearContent();
            Response.ClearHeaders();

            Response.AddHeader("Content-Disposition", "attachment;filename=Reporte_Despacho.pdf");
            Response.BinaryWrite(MStream.GetBuffer());
            Response.End();
        }