2025-06-03 15:11:16 +02:00

174 lines
6.2 KiB
C#
Raw Blame History

using System;
using System.Text;
using System.IO;
using System.Configuration;
using System.Data;
using System.Diagnostics;
using System.Collections.Specialized;
using System.Collections.Generic;
using System.Data.SqlClient;
using Amib.Threading;
using System.Threading;
using PDFGenerator.BusinessLayer;
using PDFGenerator;
using DataAccessLayer;
namespace GestorePDF.Logic
{
using NLog;
public class GestoreThread
{
private static NLog.Logger logger = NLog.LogManager.GetCurrentClassLogger();
// Richiamato da GestorePDF.Logic\ThreadManager.cs : ProcessPdfDocuments
[STAThread]
public void DoWork(DataThread _dataThread)
{
logger.Debugs(_dataThread.CodiceFiscale + "_Start");
string rete = _dataThread.Rete;
string cf = _dataThread.CodiceFiscale;
int esito = -1;
List<SessionStruct> _tabelleSessione = new List<SessionStruct>();
ReportTipo reportTypeDiagnosi = _dataThread.ReportsType.Find(delegate (ReportTipo r)
{
return r.Descrizione.ToUpper() == "DIAGNOSI";
});
if (reportTypeDiagnosi != null) //Lettere di benvenuto
{
_dataThread.TipoReport = "DIAGNOSI";
logger.Debugs("Creo lettera di benvenuto con CF=" + cf + " rete=" + rete + "_INIZIO");
try
{
esito = MakePDF(_tabelleSessione, _dataThread);
}
catch (Exception e)
{
logger.Errors(e);
}
logger.Debugs("Creo lettera di benvenuto con CF=" + cf + " rete=" + rete + "_FINE");
}
ReportTipo reportTypeMonitoraggio = _dataThread.ReportsType.Find(delegate (ReportTipo r)
{
return r.Descrizione.ToUpper() == "MONITORAGGIO";
});
if (reportTypeMonitoraggio != null)//Trimestrale
{
_dataThread.TipoReport = "MONITORAGGIO";
logger.Debugs("Creo lettera trimestrale con CF=" + cf + " rete=" + rete + "_INIZIO");
try
{
esito = MakePDF(_tabelleSessione, _dataThread);
}
catch (Exception e)
{
logger.Errors(e);
}
logger.Debugs("Creo lettera trimestrale con CF=" + cf + " rete=" + rete + "_FINE");
}
try
{
// Se il PDF <20> stato creato correttamente la prossima volta non sar<61> da creare!
if (esito != -1 && CACHE.SavePDFtoDISK == 1 && CACHE.Flag_stampa != string.Empty)
{
using (SQLServer db = new SQLServer(_dataThread.CodiceFiscale, _dataThread.Rete))
{
var ret = db.executeNonQueryWT(
CACHE.Flag_stampa
, new List<SqlParameter>()
{
new SqlParameter("codfis",_dataThread.CodiceFiscale),
new SqlParameter("rt",_dataThread.Rete)
}, CommandType.Text);
if (ret != -1)
logger.Debugs("La riga nella tabella TB_Campione di riferimento non e' stata aggiornata pur creando il pdf per '" + _dataThread.CodiceFiscale + "'");
}
}
else
{
if (esito == -1)
{
logger.Debugs("Il Pdf collegato al codice fiscale e rete (" + _dataThread.CodiceFiscale + "," + _dataThread.Rete + ") non e' stato generato");
}
}
if (esito!=-1 && CACHE.SavePDFtoDISK == 2)
{
//=5=
using (SQLServer db = new SQLServer(_dataThread.CodiceFiscale, _dataThread.Rete))
{
var ret = db.executeNonQueryWT("c6martPeriodico.UpdateStatoReport",
new List<SqlParameter>()
{
new SqlParameter("FiscalCode",_dataThread.CodiceFiscale),
new SqlParameter("Rete",_dataThread.Rete)
});
}
}
}
catch (Exception ex)
{
logger.Errors(ex);
string reportType;
if (_dataThread.TipoReport == TipologiaReport.DIAGNOSI.ToString())
{
reportType = "D";
}
else
{
reportType = "M";
}
InsertFaultCustomer(_dataThread.Rete, _dataThread.CodiceFiscale, reportType, ex.Message);
}
logger.Debugs(_dataThread.CodiceFiscale + "_End");
_dataThread.IsCompleted = true;
}
private int MakePDF(List<SessionStruct> tabelleSessione, DataThread dataThread)
{
PDFGenerator.PDFGenerator generator = new PDFGenerator.PDFGenerator(tabelleSessione, dataThread);
return generator.Create();
}
private static void InsertFaultCustomer(string rete, string codfis, string reportType, string errorDescription)
{
if (CACHE.scriviErroreNelDB)
{
var parameters = new List<SqlParameter>()
{
new SqlParameter("cod_fiscale",codfis),
new SqlParameter("rete",rete),
new SqlParameter("tipoReport",reportType),
new SqlParameter("errorText",errorDescription)
};
try
{
using (SQLServer db = new SQLServer(codfis, rete))
{
db.executeNonQueryWT("[C6MartPeriodico].[GESTIONE_INSERT_CUSTOMER_ERROR]", parameters);
}
}
catch (Exception ex)
{
logger.Errors(ex);
}
}
}
}
}