232 lines
8.7 KiB
C#
232 lines
8.7 KiB
C#
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;
|
|
|
|
/// <summary>
|
|
/// Testo introduttivo della sezione.
|
|
/// </summary>
|
|
public string TestoIntroduttivo
|
|
{
|
|
get
|
|
{
|
|
return _testointroduttivo;
|
|
}
|
|
set
|
|
{
|
|
_testointroduttivo = value;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Testo del titolo della sezione.
|
|
/// </summary>
|
|
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, "<br>"), 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<br>Operazione", 60, TipoAllineamento.SINISTRA, false, 7, false));
|
|
tabellaDettaglio_OUT.Colonne.Add(new Colonna("Contratto", "Contratto/<br>Dossier", 100, TipoAllineamento.SINISTRA, false, 7, false));
|
|
tabellaDettaglio_OUT.Colonne.Add(new Colonna("CodiceContratto", "Nr.Contratto/<br>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<br>operazione (€)", 100, TipoAllineamento.DESTRA, false, 7, false));
|
|
tabellaDettaglio_OUT.Colonne.Add(new Colonna("FirmaDigitale", "Modalità di<br>firma", 80, TipoAllineamento.SINISTRA, false, 7, false));
|
|
|
|
// Scrive la tabella Totali
|
|
tabellaDettaglio_OUT.Draw(datitab, document);
|
|
#endregion
|
|
|
|
#region Totali
|
|
List<TotaliOUT> _listaTotali = new List<TotaliOUT>();
|
|
|
|
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<decimal>("Importo"));
|
|
|
|
_clsTotali.ImportoTotale = _importo.ToString("#,##0.00"); //Convert.ToString(_importo).ToString("#,##0.00");
|
|
_clsTotali.Firma = string.Empty;
|
|
|
|
_listaTotali.Add(_clsTotali);
|
|
|
|
|
|
DataTable dtTotali = ToDataTable<TotaliOUT>(_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<T> ConvertTo<T>(DataTable datatable) where T : new()
|
|
{
|
|
List<T> Temp = new List<T>();
|
|
try
|
|
{
|
|
List<string> columnsNames = new List<string>();
|
|
foreach (DataColumn DataColumn in datatable.Columns)
|
|
columnsNames.Add(DataColumn.ColumnName);
|
|
Temp = datatable.AsEnumerable().ToList().ConvertAll<T>(row => getObject<T>(row, columnsNames));
|
|
return Temp;
|
|
}
|
|
catch
|
|
{
|
|
return Temp;
|
|
}
|
|
}
|
|
|
|
public T getObject<T>(DataRow row, List<string> 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<T>(IList<T> 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; }
|
|
}
|
|
}
|