コード例 #1
0
 private static DocumentPDF printParagraph(StampaVO.Paragraph paragraph, DocumentPDF docPDF)
 {
     try
     {
         string[] testo;
         testo = paragraph.text.Split('&');
         StampaVO.Font font  = paragraph.font;
         Font          font1 = FontFactory.GetFont(font.name, font.size, Utils.getFontStyle(font.style), Utils.getColor(font.color));
         for (int i = 0; i < testo.Length; i++)
         {
             Paragraph p = new Paragraph(new Phrase(testo[i], font1));
             p.IndentationLeft  = paragraph.indentationLeft;
             p.IndentationRight = paragraph.indentationRight;
             p.Alignment        = Utils.getAlign(paragraph.align);
             docPDF.Add(p);
         }
     }
     catch (Exception ex)
     {
         docPDF.Close();
         writer.Close();
         throw new ReportException(ErrorCode.IncompletePDFFile, "Errore nella scrittura dei dati: " + ex.Message);
     }
     return(docPDF);
 }
コード例 #2
0
        public static DocumentPDF appendData(Hashtable parameters, DocumentPDF docPDF, StampaVO.Document templateDoc, string target, bool newPage)
        {
            try
            {
                if (templateDoc != null)
                {
                    if (templateDoc.dataToPrint != null && templateDoc.dataToPrint.Count > 0)
                    {
                        bool trovato = false;
                        StampaVO.Paragraph paragrafo;
                        for (int i = 0; (i < templateDoc.dataToPrint.Count && !trovato); i++)
                        {
                            if (target == null || ((StampaVO.DataElement)templateDoc.dataToPrint[i]).target.Equals(target))
                            {
                                if (target == null)
                                {
                                    trovato = true;
                                }

                                paragrafo = (StampaVO.Paragraph)templateDoc.dataToPrint[i];
                                //sostituzione parametri
                                if (!paragrafo.text.Equals(""))
                                {                                //Sostituisce i parametri
                                    foreach (string key in parameters.Keys)
                                    {
                                        string pval = parameters[key].ToString();
                                        if (pval == null)
                                        {
                                            pval = "";
                                        }
                                        paragrafo.text = paragrafo.text.Replace(key, pval);
                                    }
                                }
                                if (newPage)
                                {
                                    docPDF.NewPage();
                                }
                                docPDF  = printParagraph(paragrafo, docPDF);
                                trovato = true;
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                docPDF.Close();
                writer.Close();
                throw new ReportException(ErrorCode.IncompletePDFFile, "Errore nella scrittura dei dati: " + ex.Message);
            }
            return(docPDF);
        }
コード例 #3
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="dt"></param>
 /// <param name="docPDF"></param>
 /// <param name="templateDoc"></param>
 /// <param name="target"></param>
 /// <param name="newPage"></param>
 /// <param name="Utente"></param>
 /// <returns></returns>
 public static DocumentPDF appendData(DataTable dt, DocumentPDF docPDF, StampaVO.Document templateDoc, string target, bool newPage, DocsPaVO.utente.InfoUtente infoUt)
 {
     try
     {
         if (templateDoc != null)
         {
             if (templateDoc.dataToPrint != null && templateDoc.dataToPrint.Count > 0)
             {
                 bool           trovato = false;
                 StampaVO.Table table;
                 for (int i = 0; (i < templateDoc.dataToPrint.Count && !trovato); i++)
                 {
                     if (((StampaVO.DataElement)templateDoc.dataToPrint[i]).target.Equals(target))
                     {
                         table = (StampaVO.Table)templateDoc.dataToPrint[i];
                         if (newPage)
                         {
                             docPDF.NewPage();
                         }
                         if (dt.TableName != "REP_TRASMISSIONI")
                         {
                             docPDF = printTable(table, dt, docPDF);
                         }
                         else
                         {
                             docPDF = printCustomTable(table, dt, docPDF, infoUt);
                         }
                         trovato = true;
                     }
                 }
             }
         }
     }
     catch (Exception ex)
     {
         docPDF.Close();
         writer.Close();
         throw new ReportException(ErrorCode.IncompletePDFFile, "Errore nella scrittura dei dati: " + ex.Message);
     }
     return(docPDF);
 }
コード例 #4
0
 public MemoryStream close()
 {
     if (docPDF == null)
     {
         throw new ReportException(ErrorCode.BadPDFFile, "Impossibile chiudere il file. Il file non è aperto");
     }
     try
     {
         if (docPDF.IsOpen())
         {
             docPDF.Close();
         }
     }
     catch (Exception e)
     {
         //Si è verificato un errore nella creazione del file PDF
         //Il dettaglio è contenuto nel messaggio che viene propagato.
         throw new ReportException(ErrorCode.BadPDFFile, e.Message);
     }
     return(docPDF.memoryStream);
 }
コード例 #5
0
 public static DocumentPDF appendData(string testo, DocumentPDF docPDF, StampaVO.Document templateDoc, string target, bool newPage)
 {
     try
     {
         if (templateDoc != null)
         {
             if (templateDoc.dataToPrint != null && templateDoc.dataToPrint.Count > 0)
             {
                 bool trovato = false;
                 StampaVO.Paragraph paragrafo;
                 for (int i = 0; (i < templateDoc.dataToPrint.Count && !trovato); i++)
                 {
                     if (((StampaVO.DataElement)templateDoc.dataToPrint[i]).target.Equals(target))
                     {
                         paragrafo = (StampaVO.Paragraph)templateDoc.dataToPrint[i];
                         if (testo != null && !testo.Equals(""))
                         {
                             paragrafo.text = testo;
                         }
                         if (newPage)
                         {
                             docPDF.NewPage();
                         }
                         docPDF  = printParagraph(paragrafo, docPDF);
                         trovato = true;
                     }
                 }
             }
         }
     }
     catch (Exception ex)
     {
         docPDF.Close();
         writer.Close();
         throw new ReportException(ErrorCode.IncompletePDFFile, "Errore nella scrittura dei dati: " + ex.Message);
     }
     return(docPDF);
 }
コード例 #6
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);
        }
コード例 #7
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);
        }
コード例 #8
0
        public static DocumentPDF createDocPDF(StampaVO.Document templateDoc, string overrideFooter)
        {
            DocumentPDF docPDF = null;

            if (templateDoc == null)
            {
                throw new ReportException(ErrorCode.InvalidValueObject, "Template di formato non valido");
            }
            try
            {
                try
                {                //Creazione del Documento vuoto
                    docPDF = new DocumentPDF();
                    docTmp = templateDoc;
                    writer = PdfWriter.GetInstance(docPDF, docPDF.memoryStream);
                    PDFPageEvents events = new PDFPageEvents();
                    writer.PageEvent = events;
                }
                catch (Exception e)
                {
                    writer.Close();
                    throw new ReportException(ErrorCode.BadPDFFile, e.Message);
                }

                try
                {
                    //Settaggio delle proprietà della pagina
                    docPDF = setPage(templateDoc, docPDF);
                }
                catch (Exception ex)
                {
                    writer.Close();
                    throw new ReportException(ErrorCode.IncompletePDFFile, "Fallita impostazione della Pagina: " + ex.Message);
                }

                try
                {
                    //Creazione dell'header
                    docPDF = setHeader(templateDoc, docPDF);
                }
                catch (Exception ex)
                {
                    writer.Close();
                    throw new ReportException(ErrorCode.IncompletePDFFile, "Fallita impostazione dell'Header: " + ex.Message);
                }

                try
                {
                    //Creazione del footer
                    docPDF = setFooter(templateDoc, docPDF, overrideFooter);
                }
                catch (Exception ex)
                {
                    writer.Close();
                    throw new ReportException(ErrorCode.IncompletePDFFile, "Fallita impostazione del Footer: " + ex.Message);
                }

                try
                {
                    if (!docPDF.AddCreationDate())
                    {
                        throw new Exception();
                    }
                }
                catch (Exception ex)
                {
                    throw new ReportException(ErrorCode.IncompletePDFFile, "Fallita impostazione della Data di Stampa: " + ex.Message);
                }

                docPDF.Open();

                try
                {
                    docPDF = setLogo(templateDoc, docPDF);
                }
                catch (Exception ex)
                {
                    docPDF.Close();
                    writer.Close();
                    throw new ReportException(ErrorCode.IncompletePDFFile, "Fallita impostazione del Logo: " + ex.Message);
                }
            }
            catch (ReportException re)
            {
                docPDF.Close();
                writer.Close();
                docPDF = null;
                throw re;
            }
            catch (Exception e)
            {
                docPDF.Close();
                writer.Close();
                docPDF = null;
                throw new ReportException(ErrorCode.GenericError, e.Message);
            }

            return(docPDF);
        }