using System; using System.Collections.Generic; using System.Linq; using System.Text; using PDFGenerator.BusinessLayer; using PDFGenerator.Presentation.Section; using PDFGenerator; using PDFGenerator.Presentation.Section.Tables; using PDFGenerator.BusinessLayer; using PDFGenerator.BusinessLayer.DataSection; using ceTe.DynamicPDF.PageElements; using System.Data; using System.Reflection; using System.ComponentModel; namespace PDFGenerator.Presentation.Section { public class S44 : ISezione { private string Titolo = string.Empty; private string _testotitolo; private string _testointroduttivo; /// /// Testo introduttivo della sezione. /// public string TestoIntroduttivo { get { return _testointroduttivo; } set { _testointroduttivo = value; } } /// /// Testo del titolo della sezione. /// public string TestoTitolo { get { return _testotitolo; } set { _testotitolo = value; } } public void setTitolo(string label) { Titolo = label; } public void writeSezione(DataThread dataThread) { DocumentPDF document = dataThread.DocumentPDF; DatiTabella datitab; DataSetS44 set = (DataSetS44)dataThread.Data.DatiSezione; // Titolo della sezione //document.setLastPos(200); //document.addPage(); document.setChapterHeader(string.Concat(_testointroduttivo, "
"), 0, 520, 8); datitab = new DatiTabella(); datitab.table = set.Tables["OperazioniUltimoTrimestre"]; /*********************** Modifica per Trimestrale capitolo 1.7 su nuova pagina - Pino **************************/ // document.setSezHeader(_testointroduttivo); /***************************************************************************************************************/ #region Disegno la tabella // Disegno la tabella Tabella tabellaDettaglio_OUT = new Tabella(document.getMargineLeft(), document.getLastPos()); tabellaDettaglio_OUT.X = document.getMargineLeft(); tabellaDettaglio_OUT.HeaderFont = 8; tabellaDettaglio_OUT.Header = true; tabellaDettaglio_OUT.Datasource = datitab.table; tabellaDettaglio_OUT.AltezzaCella = 23; tabellaDettaglio_OUT.LineaFineTabella = true; tabellaDettaglio_OUT.Colonne.Add(new Colonna("DataOperazione", "Data
Operazione", 60, TipoAllineamento.SINISTRA, false, 7, false)); tabellaDettaglio_OUT.Colonne.Add(new Colonna("Contratto", "Contratto/
Dossier", 100, TipoAllineamento.SINISTRA, false, 7, false)); tabellaDettaglio_OUT.Colonne.Add(new Colonna("CodiceContratto", "Nr.Contratto/
Dossier", 80, TipoAllineamento.SINISTRA, false, 7, false)); tabellaDettaglio_OUT.Colonne.Add(new Colonna("Descrizione", "Operazione", 100, TipoAllineamento.SINISTRA, false, 7, false)); tabellaDettaglio_OUT.Colonne.Add(new Colonna("Importo", "Importo
operazione (€)", 100, TipoAllineamento.DESTRA, false, 7, false)); tabellaDettaglio_OUT.Colonne.Add(new Colonna("FirmaDigitale", "Modalità di
firma", 80, TipoAllineamento.SINISTRA, false, 7, false)); // Scrive la tabella Totali tabellaDettaglio_OUT.Draw(datitab, document); #endregion #region Totali List _listaTotali = new List(); TotaliOUT _clsTotali = new TotaliOUT(); if (set.Tables["OperazioniUltimoTrimestre"].Rows.Count > 0) { _clsTotali.Testo = "Totale"; DataTable _dt = set.Tables["OperazioniUltimoTrimestre"]; decimal _importo = _dt.AsEnumerable().Sum(s => s.Field("Importo")); _clsTotali.ImportoTotale = _importo.ToString("#,##0.00"); //Convert.ToString(_importo).ToString("#,##0.00"); _clsTotali.Firma = string.Empty; _listaTotali.Add(_clsTotali); DataTable dtTotali = ToDataTable(_listaTotali); datitab = new DatiTabella(); datitab.table = dtTotali; Tabella tabellaTotali_OUT = new Tabella(document.getMargineLeft(), document.getLastPos() + tabellaDettaglio_OUT.AltezzaTabella + 30); tabellaTotali_OUT.HeaderFont = 8; tabellaTotali_OUT.Header = false; tabellaTotali_OUT.SaltoPagina = false; tabellaTotali_OUT.Colonne.Add(new Colonna("Testo", "", 60, TipoAllineamento.SINISTRA, true, 8, true)); tabellaTotali_OUT.Colonne.Add(new Colonna("ImportoTotale", "", 380, TipoAllineamento.DESTRA, true, 8, true)); tabellaTotali_OUT.Colonne.Add(new Colonna("Firma", " ", 80, TipoAllineamento.DESTRA, true, 8, true)); // Scrive la tabella Totali tabellaTotali_OUT.Draw(datitab, document); float ultimaPosizione = document.getLastPos(); //document.setLastPos(ultimaPosizione + tabellaTotali_OUT.AltezzaTabella + 100); //document.setLastPos(ultimaPosizione + 100); document.setLastPos(tabellaDettaglio_OUT.AltezzaTabella + tabellaTotali_OUT.AltezzaTabella); } #endregion } public List ConvertTo(DataTable datatable) where T : new() { List Temp = new List(); try { List columnsNames = new List(); foreach (DataColumn DataColumn in datatable.Columns) columnsNames.Add(DataColumn.ColumnName); Temp = datatable.AsEnumerable().ToList().ConvertAll(row => getObject(row, columnsNames)); return Temp; } catch { return Temp; } } public T getObject(DataRow row, List columnsName) where T : new() { T obj = new T(); try { string columnname = ""; string value = ""; PropertyInfo[] Properties; Properties = typeof(T).GetProperties(); foreach (PropertyInfo objProperty in Properties) { columnname = columnsName.Find(name => name.ToLower() == objProperty.Name.ToLower()); if (!string.IsNullOrEmpty(columnname)) { value = row[columnname].ToString(); if (!string.IsNullOrEmpty(value)) { if (Nullable.GetUnderlyingType(objProperty.PropertyType) != null) { value = row[columnname].ToString().Replace("$", "").Replace(",", ""); objProperty.SetValue(obj, Convert.ChangeType(value, Type.GetType(Nullable.GetUnderlyingType(objProperty.PropertyType).ToString())), null); } else { value = row[columnname].ToString().Replace("%", ""); objProperty.SetValue(obj, Convert.ChangeType(value, Type.GetType(objProperty.PropertyType.ToString())), null); } } } } return obj; } catch { return obj; } } private DataTable ToDataTable(IList data) { PropertyDescriptorCollection props = TypeDescriptor.GetProperties(typeof(T)); DataTable table = new DataTable(); for (int i = 0; i < props.Count; i++) { PropertyDescriptor prop = props[i]; table.Columns.Add(prop.Name, Nullable.GetUnderlyingType(prop.PropertyType) ?? prop.PropertyType); } object[] values = new object[props.Count]; foreach (T item in data) { for (int i = 0; i < values.Length; i++) values[i] = props[i].GetValue(item) ?? DBNull.Value; table.Rows.Add(values); } return table; } } public class TotaliOUT { public string Testo { get; set; } public string ImportoTotale { get; set; } public string Firma { get; set; } } }