private static int[] getColWidths(StampaVO.Table table, int col_visible) { int[] widths = new int[col_visible]; for (int i = 0; i < table.columns.Length; i++) { if (table.columns[i].visible) { string width = table.columns[i].width; if (width == null || width.Equals("")) { width = StampaVO.Column.COLUMN_WIDTH; } widths[i] = Int32.Parse(width); } } return(widths); }
private static StampaVO.Table getTabella(XmlNode nodoTable) { StampaVO.Table table = null; //XmlNode nodoTable = nodo.SelectSingleNode("table"); if (nodoTable != null) { table = new StampaVO.Table(); //TODO: /*table.font = getFont(nodoTable); * * table.width = Utils.getAttributeI("width",nodoTable); * table.height = Utils.getAttributeI("height",nodoTable);*/ table.target = Utils.getAttribute("target", nodoTable); table.padding = Utils.getAttributeI("padding", nodoTable); table.spacing = Utils.getAttributeI("spacing", nodoTable); table.headerTable = getHeaderTable(nodoTable); table.dataTable = getDataTable(nodoTable); table.columns = getColumns(nodoTable); } return(table); }
private static ArrayList setDati() { ArrayList dati = new ArrayList(); //XmlNode nodoDati = nodoReport.SelectSingleNode("dati"); XmlNodeList nodoDati1 = nodoReport.SelectNodes("dati"); foreach (XmlNode nodoDati in nodoDati1) //if (nodoDati!=null) { if (nodoDati.ChildNodes.Count > 0) { foreach (XmlNode nodo in nodoDati.ChildNodes) { if (nodo.Name.Equals("paragrafo")) { StampaVO.Paragraph par = getParagrafo(nodo); if (par != null) { dati.Add(par); } } else if (nodo.Name.Equals("tabella")) { StampaVO.Table tab = getTabella(nodo); if (tab != null) { dati.Add(tab); } } // else if (nodo.Name.Equals("spazio")) // getSpazio(nodo); } } } return(dati); }
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); }
/// <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); }