196 lines
7.4 KiB
C#
196 lines
7.4 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using ceTe.DynamicPDF.IO;
|
|
using ceTe.DynamicPDF;
|
|
using DataAccessLayer;
|
|
using NLog;
|
|
using System.Data.SqlClient;
|
|
using System.Data;
|
|
using System.IO;
|
|
using System.Web.UI;
|
|
using System.Diagnostics.Eventing.Reader;
|
|
|
|
public class TemplateProvider
|
|
{
|
|
private static NLog.Logger logger = NLog.LogManager.GetCurrentClassLogger();
|
|
|
|
private string _templateReportPath;
|
|
private string _templateCopertinaPath;
|
|
private string _templateGlossarioPath;
|
|
private string _templateWelcomeLetterPath;
|
|
private float _reportTypeFontColor_R;
|
|
private float _reportTypeFontColor_G;
|
|
private float _reportTypeFontColor_B;
|
|
private float _chapterBackground_R;
|
|
private float _chapterBackground_G;
|
|
private float _chapterBackground_B;
|
|
private float _chapterFontColor_R;
|
|
private float _chapterFontColor_G;
|
|
private float _chapterFontColor_B;
|
|
private float _tableHeaderFontColor_R;
|
|
private float _tableHeaderFontColor_G;
|
|
private float _tableHeaderFontColor_B;
|
|
private Stream _templateReportStream;
|
|
private Stream _templateCopertinaStream;
|
|
private Stream _templateGlossarioStream;
|
|
private Stream _templateWelcomeLetterStream;
|
|
|
|
// 2
|
|
//public static int idReportDiagnosi;
|
|
public static string CF = string.Empty;
|
|
private string ambiente = CACHE.AMBIENTE;
|
|
private DataTable Rosaspina = null;
|
|
private int Contratto = 0;
|
|
private string Rete = "";
|
|
private bool Periodico = false;
|
|
|
|
public TemplateProvider(int contratto, string rete, bool periodico)
|
|
{
|
|
Contratto = contratto;
|
|
Rete = rete;
|
|
Periodico = periodico;
|
|
string msg = $"Error Template not found for contratto={contratto},rete={rete},periodico={periodico.ToString()},CF={CF}";
|
|
DataTemplate template = null;
|
|
|
|
if (periodico == CACHE.Periodico)
|
|
{
|
|
template = CACHE.DirectTemplates.FirstOrDefault(x => x.rete == rete && x.contracttype == contratto);
|
|
|
|
if (template == null)
|
|
{
|
|
logger.Errors(msg);
|
|
throw new Exception(msg);
|
|
}
|
|
else
|
|
ReadFromTemplate(template);
|
|
}
|
|
|
|
if (!periodico && CACHE.Periodico)
|
|
{
|
|
template = CACHE.LetterTemplates.FirstOrDefault(x => x.rete == rete && x.contracttype == contratto);
|
|
|
|
if (template == null)
|
|
{
|
|
logger.Errors(msg);
|
|
throw new Exception(msg);
|
|
}
|
|
else
|
|
ReadFromTemplate(template);
|
|
}
|
|
|
|
if (ambiente == "SVILUPPO")
|
|
{
|
|
|
|
if (contratto != 3)
|
|
{
|
|
_templateReportPath = @"C:\TEMPLATES\PDFGeneration_FILE\S\Templ_BFreport.pdf";
|
|
_templateCopertinaPath = @"C:\TEMPLATES\PDFGeneration_FILE\S\Templ_copertinaSP.pdf";
|
|
_templateGlossarioPath = @"C:\TEMPLATES\PDFGeneration_FILE\S\Glossario.pdf";
|
|
_templateWelcomeLetterPath = @"C:\TEMPLATES\PDFGeneration_FILE\S\TemplateBF.pdf";
|
|
}
|
|
else
|
|
{
|
|
_templateReportPath = @"C:\TEMPLATES\PDFGeneration_FILE\FD\Report.pdf";
|
|
_templateCopertinaPath = @"C:\TEMPLATES\PDFGeneration_FILE\FD\copertinaBF.pdf";
|
|
_templateGlossarioPath = @"C:\TEMPLATES\PDFGeneration_FILE\FD\Glossario.pdf";
|
|
_templateWelcomeLetterPath = @"C:\TEMPLATES\PDFGeneration_FILE\FD\Lettera.pdf";
|
|
}
|
|
}
|
|
|
|
try
|
|
{
|
|
logger.Infos(" Utils -> _templateReportPath = " + _templateReportPath);
|
|
(new FileStream(_templateWelcomeLetterPath, FileMode.Open, FileAccess.Read)).CopyTo(_templateWelcomeLetterStream = new MemoryStream());
|
|
(new FileStream(_templateReportPath, FileMode.Open, FileAccess.Read)).CopyTo(_templateReportStream = new MemoryStream());
|
|
(new FileStream(_templateCopertinaPath, FileMode.Open, FileAccess.Read)).CopyTo(_templateCopertinaStream = new MemoryStream());
|
|
(new FileStream(_templateGlossarioPath, FileMode.Open, FileAccess.Read)).CopyTo(_templateGlossarioStream = new MemoryStream());
|
|
|
|
}
|
|
catch (Exception exx3)
|
|
{
|
|
logger.Errors(exx3);
|
|
logger.Debugs($"Error exx3 at TemplateProvider.ctor(contratto={contratto},rete={rete},periodico={periodico.ToString()}),CF={CF}");
|
|
}
|
|
|
|
}
|
|
|
|
private void ReadFromTemplate(DataTemplate template)
|
|
{
|
|
if (template != null)
|
|
{
|
|
_reportTypeFontColor_R = template.reporttypefontcolor_r;
|
|
_reportTypeFontColor_G = template.reporttypefontcolor_g;
|
|
_reportTypeFontColor_B = template.reporttypefontcolor_b;
|
|
|
|
_chapterBackground_R = template.chapterbackground_r;
|
|
_chapterBackground_G = template.chapterbackground_g;
|
|
_chapterBackground_B = template.chapterbackground_b;
|
|
|
|
_chapterFontColor_R = template.chapterfontcolor_r;
|
|
_chapterFontColor_G = template.chapterfontcolor_g;
|
|
_chapterFontColor_B = template.chapterfontcolor_b;
|
|
|
|
_tableHeaderFontColor_R = template.tableheaderfontcolor_r;
|
|
_tableHeaderFontColor_G = template.tableheaderfontcolor_g;
|
|
_tableHeaderFontColor_B = template.tableheaderfontcolor_b;
|
|
|
|
_templateReportPath = template.templatereportpath;
|
|
_templateCopertinaPath = template.templatecopertinapath;
|
|
_templateGlossarioPath = template.templateglossariopath;
|
|
_templateWelcomeLetterPath = template.templatewelcomeletterpath;
|
|
}
|
|
else
|
|
{
|
|
// CASO IMPOSSIBILE
|
|
}
|
|
|
|
}
|
|
public int SignYPosition { get { return 716; } }
|
|
public int LetteraAccompagnamentoPeriodicoSalutiYBonus { get { return -5; } }
|
|
public int LetteraAccompagnamentoPeriodicoFirmaYBonus { get { return -5; } }
|
|
public int SalutiYBonus { get { return 15; } }
|
|
public int MarginRight { get { return 259; } }
|
|
public int GlossarioMarginRight { get { return 40; } }
|
|
public int MarginDown { get { return 105; } }
|
|
public System.IO.Stream TemplateWelcomeLetter { get { return _templateWelcomeLetterStream; } }
|
|
public System.IO.Stream TemplateReport { get { return _templateReportStream; } }
|
|
public System.IO.Stream TemplateCopertina { get { return _templateCopertinaStream; } }
|
|
public ceTe.DynamicPDF.RgbColor ReportTypeFontColor
|
|
{
|
|
get
|
|
{
|
|
return new ceTe.DynamicPDF.RgbColor(_reportTypeFontColor_R, _reportTypeFontColor_G, _reportTypeFontColor_B);
|
|
}
|
|
}
|
|
public ceTe.DynamicPDF.RgbColor ChapterBackgroundColor
|
|
{
|
|
get
|
|
{
|
|
if (Contratto != 3)
|
|
return new ceTe.DynamicPDF.RgbColor(_chapterBackground_R, _chapterBackground_G, _chapterBackground_B);//SEI
|
|
else
|
|
return new ceTe.DynamicPDF.RgbColor(34, 128, 0);//DA
|
|
}
|
|
}
|
|
public ceTe.DynamicPDF.RgbColor ChapterFontColor
|
|
{
|
|
get
|
|
{
|
|
if (Contratto != 3)
|
|
return new ceTe.DynamicPDF.RgbColor(_chapterFontColor_R, _chapterFontColor_G, _chapterFontColor_B);//SEI
|
|
else
|
|
return new ceTe.DynamicPDF.RgbColor(34, 128, 0);//DA
|
|
}
|
|
}
|
|
public ceTe.DynamicPDF.RgbColor TableHeaderFontColor
|
|
{
|
|
get
|
|
{
|
|
return new ceTe.DynamicPDF.RgbColor(_tableHeaderFontColor_R, _tableHeaderFontColor_G, _tableHeaderFontColor_B);
|
|
}
|
|
}
|
|
}// end of TemplateProvider
|
|
|