232 lines
8.2 KiB
C#
232 lines
8.2 KiB
C#
using CMS_SC_Data;
|
|
using SteamWare;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Web.UI;
|
|
|
|
namespace CMS_SC
|
|
{
|
|
public partial class ReportCompleto : System.Web.UI.Page
|
|
{
|
|
protected void Page_Load(object sender, EventArgs e)
|
|
{
|
|
if (!Page.IsPostBack)
|
|
{
|
|
ddlFase.DataBind();
|
|
ddlLingue.DataBind();
|
|
string _idxDossier = memLayer.ML.QSS("IdxDossier");
|
|
int idxReq = 0;
|
|
int.TryParse(_idxDossier, out idxReq);
|
|
idxDossier = idxReq;
|
|
// se c'è seleziono fase...
|
|
idxFase = memLayer.ML.QSS("Fase");
|
|
// fix x revisione...
|
|
ddlRev.DataBind();
|
|
// fix x button download
|
|
lbtExportWithAttach.DataBind();
|
|
//mod_reportCompleto.Fase = ddlFase.SelectedValue;
|
|
//mod_reportCompleto.Lingua = ddlLingue.SelectedValue;
|
|
fixSelReport();
|
|
fixReportAndSpecBtn();
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// Controllo visibilità button full report: SOLO SE utente ha permesso...
|
|
/// </summary>
|
|
private void fixReportAndSpecBtn()
|
|
{
|
|
lbtExportWithAttach.Visible = devicesAuthProxy.stObj.userHasRight("ReportFullPdf") || devicesAuthProxy.stObj.userHasRight("CapoOfficina");
|
|
hlDownloadPdf.Visible = false;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Valore dossier salvato nell'hidden input
|
|
/// </summary>
|
|
protected int idxDossier
|
|
{
|
|
get
|
|
{
|
|
int answ = 0;
|
|
int.TryParse(hfIdxDossier.Value, out answ);
|
|
return answ;
|
|
}
|
|
set
|
|
{
|
|
hfIdxDossier.Value = value.ToString();
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// Fase selezionata
|
|
/// </summary>
|
|
protected string idxFase
|
|
{
|
|
get
|
|
{
|
|
return ddlFase.SelectedValue;
|
|
}
|
|
set
|
|
{
|
|
ddlFase.SelectedValue = value;
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// wrapper traduzione
|
|
/// </summary>
|
|
/// <param name="lemma"></param>
|
|
/// <returns></returns>
|
|
public string traduci(string lemma)
|
|
{
|
|
return user_std.UtSn.Traduci(lemma);
|
|
}
|
|
/// <summary>
|
|
/// cambio fase
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
protected void ddlFase_SelectedIndexChanged(object sender, EventArgs e)
|
|
{
|
|
// update ddl rev...
|
|
odsRev.DataBind();
|
|
ddlRev.DataBind();
|
|
// fix!
|
|
fixSelReport();
|
|
fixReportAndSpecBtn();
|
|
}
|
|
/// <summary>
|
|
/// cambio lingua
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
protected void ddlLingue_SelectedIndexChanged(object sender, EventArgs e)
|
|
{
|
|
fixSelReport();
|
|
fixReportAndSpecBtn();
|
|
}
|
|
/// <summary>
|
|
/// Cambio revisione
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
protected void ddlRev_SelectedIndexChanged(object sender, EventArgs e)
|
|
{
|
|
fixSelReport();
|
|
fixReportAndSpecBtn();
|
|
}
|
|
/// <summary>
|
|
/// Sistemazione report con parametri
|
|
/// </summary>
|
|
private void fixSelReport()
|
|
{
|
|
// recupero num revisione
|
|
int rev = 0;
|
|
int.TryParse(ddlRev.SelectedValue, out rev);
|
|
// imposto!
|
|
mod_reportCompleto.Fase = idxFase;
|
|
mod_reportCompleto.Rev = rev;
|
|
mod_reportCompleto.Lingua = ddlLingue.SelectedValue;
|
|
mod_reportCompleto.fixReport();
|
|
}
|
|
/// <summary>
|
|
/// Sistemazione report con parametri + stampa pdf con nome indicato
|
|
/// </summary>
|
|
/// <param name="outFilePath"></param>
|
|
private void printReport(string outFilePath)
|
|
{
|
|
fixSelReport();
|
|
mod_reportCompleto.printReport(outFilePath);
|
|
}
|
|
/// <summary>
|
|
/// Premuto button x generare un unico PDF dei report...
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
protected void lbtExportWithAttach_Click(object sender, EventArgs e)
|
|
{
|
|
logger.lg.scriviLog("-------------------------- FULL REPORT + ALLEGATI START -------------------------- ");
|
|
logger.lg.scriviLog($"Inizio FullReport richiesto dall'utente {OpAuth.currAuth.CognomeNome} ({OpAuth.currAuth.email})");
|
|
bool allDone = false;
|
|
int numFilesDone = 0;
|
|
int allFiles = 0;
|
|
// effettua merge Report Completo + allegati: registro in primis la richiesta!
|
|
var tabDoss = DtProxy.man.taED.getByDossier(idxDossier);
|
|
if (tabDoss.Count > 0)
|
|
{
|
|
logger.lg.scriviLog($"Trovati {tabDoss.Count} Dossiers");
|
|
var currDoss = tabDoss[0];
|
|
DtProxy.man.taFRGL.insertQuery(OpAuth.currAuth.email, idxDossier, DateTime.Now, currDoss.Matricola, currDoss.FaseAct, currDoss.RevAct);
|
|
logger.lg.scriviLog($"Registrato record FRGL: {OpAuth.currAuth.email} | Dossiers {idxDossier} - {currDoss.Matricola}");
|
|
// step 1: genera directory lavoro
|
|
string currOutPath = $"{memLayer.ML.CRS("urlTemp")}{idxDossier}";
|
|
logger.lg.scriviLog($"Puntamento alla folder {currOutPath}");
|
|
fileMover.obj.setDirectoryMapPath(currOutPath);
|
|
fileMover.obj.checkDir();
|
|
// eventualmente elimino dalla directory i pdf contenuti...
|
|
fileMover.obj.svuotaDir("*.pdf");
|
|
logger.lg.scriviLog($"Eliminazione vecchi pdf effettuata");
|
|
// path scehde!
|
|
string urlSchede = memLayer.ML.CRS("urlSchede");
|
|
string pdfInFullPath = "";
|
|
List<string> elencoPdf = new List<string>();
|
|
// step 2: esporta pdf collaudo in dir temporanea come PRIMO file
|
|
string fullReportFilename = $"{currOutPath}\\ReportOnly.pdf";
|
|
printReport(fullReportFilename);
|
|
//se richiesto da conf di aggiungere in testa il report...
|
|
if (memLayer.ML.CRB("mergeReport2Pdf"))
|
|
{
|
|
pdfInFullPath = Server.MapPath(fullReportFilename);
|
|
// aggiungo primo PDF all'elenco...
|
|
elencoPdf.Add(pdfInFullPath);
|
|
allFiles++;
|
|
logger.lg.scriviLog($"Allegato pdf report principale: {pdfInFullPath}");
|
|
}
|
|
// step 3: colleziona allegati schede e li copia in locale
|
|
var tabDati = DtProxy.man.taASC.getByDossier(idxDossier, idxFase);
|
|
foreach (var item in tabDati)
|
|
{
|
|
pdfInFullPath = "";
|
|
// controllo SE HO un pdf...
|
|
if (!string.IsNullOrEmpty(item.Path))
|
|
{
|
|
try
|
|
{
|
|
if (!elencoPdf.Contains(item.Path))
|
|
{
|
|
allFiles++;
|
|
pdfInFullPath = Server.MapPath(string.Format(urlSchede, item.Path));
|
|
elencoPdf.Add(pdfInFullPath);
|
|
logger.lg.scriviLog($"Allegato pdf: {pdfInFullPath}");
|
|
}
|
|
}
|
|
catch
|
|
{ }
|
|
}
|
|
}
|
|
// step 4: MERGE di tutti i pdf nel file di output
|
|
string outFilePath = $"ReportAndSpec_{idxDossier}.pdf";
|
|
string outFilePathMapped = $"{Server.MapPath(currOutPath)}\\{outFilePath}";
|
|
logger.lg.scriviLog($"Richiesto merge nel file {outFilePathMapped} dei pdf collezionati");
|
|
numFilesDone = pdfUtils.mergePdfFiles(outFilePathMapped, elencoPdf);
|
|
logger.lg.scriviLog($"Effettuato merge per {numFilesDone} pdf");
|
|
allDone = (numFilesDone == allFiles && allFiles > 0);
|
|
// step 5: chiamo pagina x download nuovo file composto... aggiornando hyperLink button x scaricare in target "_blank" il report creato...
|
|
lbtExportWithAttach.Visible = !allDone;
|
|
hlDownloadPdf.Visible = allDone;
|
|
lblOutMessage.Visible = !allDone;
|
|
if (allDone)
|
|
{
|
|
hlDownloadPdf.NavigateUrl = $"downloadReport?baseDir={currOutPath}&fileName={outFilePath}&cType=pdf";
|
|
logger.lg.scriviLog($"Modificato link per download documento pdf: {hlDownloadPdf.NavigateUrl}");
|
|
}
|
|
else
|
|
{
|
|
lblOutMessage.Text = $"Attenzione: non è stato possibile trovare tutti i files richiesti({numFilesDone}/{allFiles}), verificare i pdf";
|
|
logger.lg.scriviLog($"Errore: {lblOutMessage.Text}");
|
|
}
|
|
// refresh finale report mostrato (ho usaro reportviewer x export pdf...)
|
|
fixSelReport();
|
|
logger.lg.scriviLog($"Completato FullReport richiesto dall'utente {OpAuth.currAuth.CognomeNome} ({OpAuth.currAuth.email})");
|
|
logger.lg.scriviLog("-------------------------- FULL REPORT + ALLEGATI END -------------------------- ");
|
|
}
|
|
}
|
|
}
|
|
} |