253 lines
10 KiB
C#
Raw Blame History

using System;
using System.Collections.Generic;
using System.Text;
using ceTe.DynamicPDF;
using ceTe.DynamicPDF.Merger;
using ceTe.DynamicPDF.Text;
using System.Configuration;
using System.Reflection;
using System.IO;
using ceTe.DynamicPDF.Imaging;
using Dundas.Charting.WebControl;
using System.Threading;
using System.Globalization;
using ceTe.DynamicPDF.PageElements;
namespace Consulenza.PDFLettera
{
public enum TipoContratto {
Old=0,
Affluent=1,
Private=2
}
public enum TipoLettera {
LetteraAccettazioneConAttivazioneSei,
LetteraAccettazioneAttivazioneSeiPosticipata,
RistampaLettera,
ReportPeriodico
}
namespace LetteraAccompagnamento
{
public enum TipoReport
{
Diagnosi,
Monitoraggio
}
}
public abstract class LetteraBenvenuto {
private byte[] data;
public byte[] Data {
get { return data; }
}
protected Image firma;
protected Document lettera;
protected int fontSize,
idLettera;
protected string path,
nome,
cognome,
appellativo,
nomeLettera,
indirizzo,
rete,
testoSaluti,
testoOggetto,
testo;
protected FormattedTextArea cliente,
indirizzoBanca,
oggetto,
luogo,
saluti,
corpo;
protected DateTime dataGenerazione;
protected LetteraBenvenuto(string rete, int idLettera, string testo,string nome, string cognome,string indirizzo,bool ristampa,string appellativo,string obj,string firma) {
Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US");
this.rete = rete;
this.data = null;
this.appellativo = appellativo;
this.testoOggetto = obj;
this.testoSaluti = firma;
this.indirizzo = indirizzo;
this.idLettera = idLettera;
this.testo = testo;
this.nome = nome;
this.cognome = cognome;
//this.codiceContratto = codiceContratto;
this.dataGenerazione = DateTime.Now;
PageDimensions dimensions = new PageDimensions(PageSize.A4, PageOrientation.Portrait);
dimensions.BottomMargin = Convert.ToInt32(ConfigurationManager.AppSettings["MargineInfPX"]);
dimensions.TopMargin = Convert.ToInt32(ConfigurationManager.AppSettings["MargineSupPX"]);
dimensions.LeftMargin = Convert.ToInt32(ConfigurationManager.AppSettings["MargineSxPX"]);
dimensions.RightMargin = Convert.ToInt32(ConfigurationManager.AppSettings["MargineDxPX"]);
//Page page = new Page(dimensions);
lettera = new Document();
// Lettura Template
System.Reflection.Assembly thisExe;
thisExe = System.Reflection.Assembly.GetExecutingAssembly();
System.IO.Stream file = null;
if(rete.ToUpper() == "F")
file = thisExe.GetManifestResourceStream("Consulenza.PDFLettera.TemplateBF.pdf");
else
file = thisExe.GetManifestResourceStream("Consulenza.PDFLettera.templateSPI.pdf");
PdfDocument pp = new PdfDocument(file);
Page page = new ImportedPage(pp.GetPage(1));
page.Dimensions = dimensions;
// pg = new ImportedPage(pp.GetPage(1));
lettera.Pages.Add(page);
fontSize = Convert.ToInt32(ConfigurationManager.AppSettings["fontSize"]);
string[] valoriTextArea;
valoriTextArea = ConfigurationManager.AppSettings["AreaClientePX"].Split(',');
cliente = new FormattedTextArea(string.Empty,
Convert.ToInt32(valoriTextArea[0]),
Convert.ToInt32(valoriTextArea[1]),
Convert.ToInt32(valoriTextArea[2]),
Convert.ToInt32(valoriTextArea[3]),
FontFamily.Times,
fontSize,
true);
valoriTextArea = ConfigurationManager.AppSettings["AreaLuogoPX"].Split(',');
luogo = new FormattedTextArea(string.Empty,
Convert.ToInt32(valoriTextArea[0]),
Convert.ToInt32(valoriTextArea[1]),
Convert.ToInt32(valoriTextArea[2]),
Convert.ToInt32(valoriTextArea[3]),
FontFamily.Times,
fontSize,
true);
valoriTextArea = ConfigurationManager.AppSettings["AreaOggettoPX"].Split(',');
oggetto = new FormattedTextArea(string.Empty,
Convert.ToInt32(valoriTextArea[0]),
Convert.ToInt32(valoriTextArea[1]),
Convert.ToInt32(valoriTextArea[2]),
Convert.ToInt32(valoriTextArea[3]),
FontFamily.Times,
fontSize,
true);
valoriTextArea = ConfigurationManager.AppSettings["AreaCorpoPX"].Split(',');
this.corpo = new FormattedTextArea(string.Empty,
Convert.ToInt32(valoriTextArea[0]),
Convert.ToInt32(valoriTextArea[1]),
Convert.ToInt32(valoriTextArea[2]),
Convert.ToInt32(valoriTextArea[3]),
FontFamily.Times,
fontSize,
true);
valoriTextArea = ConfigurationManager.AppSettings["AreaSalutiPX"].Split(',');
this.saluti = new FormattedTextArea(string.Empty,
Convert.ToInt32(valoriTextArea[0]),
Convert.ToInt32(valoriTextArea[1]),
Convert.ToInt32(valoriTextArea[2]),
Convert.ToInt32(valoriTextArea[3]),
FontFamily.Times,
fontSize,
true);
// Fc 03/07/2015
// modifica "a mano" del valore impostato xFirma a 290
//int xFirma = (int)(saluti.X + (this.saluti.Width - 94) / 2);
int xFirma = 290;
int yFirmaF = (int)(saluti.Y - saluti.Height + 20);
int yFirmaS = (int)(saluti.Y - saluti.Height + 10);
if (rete.ToUpper() == "F")
this.firma = GetImageByResourceName("Consulenza.PDFLettera.firma_Fideuram.jpg", xFirma, yFirmaF, (float)0.2);
else
this.firma = GetImageByResourceName("Consulenza.PDFLettera.firma_SanPaoloInvest.jpg", xFirma, yFirmaS, (float)0.2);
oggetto.Style.Paragraph.Align = ceTe.DynamicPDF.TextAlign.Justify;
corpo.Style.Paragraph.Align = ceTe.DynamicPDF.TextAlign.Justify;
luogo.Style.Paragraph.Align = ceTe.DynamicPDF.TextAlign.Right;
//this.appellativo = appellativo;
//this.testoOggetto = obj;
//this.testoSaluti = firma;
//this.indirizzo = indirizzo;
//this.idLettera = idLettera;
//this.testo = testo;
//this.nome = nome;
//this.cognome = cognome;
//cliente.Text = this.nome.ToString() + " " + this.cognome.ToString();
//corpo.Text = this.corpo.ToString();
//oggetto.Text = this.oggetto.ToString();
this.corpo.Text = "";
page.Elements.Add(this.corpo);
page.Elements.Add(cliente);
page.Elements.Add(oggetto);
page.Elements.Add(luogo);
////page.Elements.Add(indirizzoBanca);
page.Elements.Add(this.firma);
page.Elements.Add(saluti);
//** NOTA
//FC 26/06/2015
// MOdificato per nuovo template
//float xNota = 0;
//float yNota = 712;//709
float xNota = 27;
float yNota = 720;
float wNota = 150;
page.Elements.Add(new ceTe.DynamicPDF.PageElements.Line(xNota, yNota, xNota + wNota, yNota, 0.5F, RgbColor.Black));
page.Elements.Add(new ceTe.DynamicPDF.PageElements.Label(
"<22>Il private banker <20> un professionista della consulenza finanziaria, previdenziale e assicurativa, iscritto all<6C>Albo Unico dei Consulenti Finanziari."
, xNota
, yNota+3
,480
,30
, new OpenTypeFont("times.ttf")
, 9
));
//** NOTA
path = ConfigurationManager.AppSettings["pathScritturaLettera"];
}
public void writePDF() {
data = lettera.Draw();
//DECOMMENTARE PER EFFETTUARE LE PROVE, SALVA LA LETTERA SUL PERCORSO
//SPECIFICATO SU pathScritturaLettera
//lettera.Draw(path + nomeLettera + ".pdf");
}
protected static Image GetImageByResourceName(string resourceName,int X,int Y,float ratio)
{
Assembly a = Assembly.GetExecutingAssembly();
try {
Stream stream = a.GetManifestResourceStream(resourceName);
Image gif = new Image(stream,X,Y,ratio);
return gif;
}
catch{
return null;
}
}
protected abstract void settaCampi();
}
}