using GMW_data;
using Microsoft.Reporting.WinForms;
using SteamWare;
using System;
using System.Collections.Generic;
using System.Data;
using System.Drawing.Imaging;
using System.Drawing.Printing;
using System.IO;
using System.Text;

/// <summary>
/// Classe che si occupa di stampare report da reportViewer via printer remota
/// </summary>
public class reportPrinter
{
  #region area codice da non modificare

  private int m_currentPageIndex;
  protected int logLevel = 0;
  protected bool doPdfCopy = false;
  /// <summary>
  /// stream del report...
  /// </summary>
  private IList<Stream> m_streams;
  /// <summary>
  /// ciclo da fornire al renderizzatore dei report, per salvare 1 immagine da ogni pagina del report
  /// </summary>
  /// <param name="name"></param>
  /// <param name="fileNameExtension"></param>
  /// <param name="encoding"></param>
  /// <param name="mimeType"></param>
  /// <param name="willSeek"></param>
  /// <returns></returns>
  private Stream CreateStream(string name, string fileNameExtension, Encoding encoding, string mimeType, bool willSeek)
  {
    // creo files con nomi univoci...
    string filePathName = string.Format(@"~\temp\{0}_{1:HHmmss}_{1:ffff}.{2}", name, DateTime.Now, fileNameExtension);
        //Stream stream = new FileStream(SteamWare.SteamwareStrings.getFilePath(@"~\temp\" + name + "." + fileNameExtension), FileMode.Create);
        Stream stream = new FileStream(SteamWare.fileMover.getFilePath(filePathName), FileMode.Create);
        //Stream stream = new FileStream(SteamWare.SteamwareStrings.getFilePath(filePathName), FileMode.Create);
        m_streams.Add(stream);
    return stream;
  }
  /// <summary>
  /// ciclo da fornire al renderizzatore dei report, per salvare 1 pdf da ogni pagina del report
  /// </summary>
  /// <param name="name"></param>
  /// <param name="fileNameExtension"></param>
  /// <param name="encoding"></param>
  /// <param name="mimeType"></param>
  /// <param name="willSeek"></param>
  /// <returns></returns>
  private Stream CreateStreamPdf(string name, string fileNameExtension, Encoding encoding, string mimeType, bool willSeek)
  {
    // creo Directory se non c'è
    SteamWare.fileMover fm = new fileMover(string.Format(@"{0}\{1:yyyy}\{1:MM}\{1:dd}\", memLayer.ML.confReadString("PdfFolder"), DateTime.Now), "");
    fm.checkDir();
    string pdfPathName = string.Format(@"{0}\{1:yyyy}\{1:MM}\{1:dd}\{2}_{1:HHmmss}_{1:ffff}.{3}", memLayer.ML.confReadString("PdfFolder"), DateTime.Now, name, fileNameExtension);
        //Stream stream = new FileStream(SteamWare.SteamwareStrings.getFilePath(@"~\temp\" + name + "." + fileNameExtension), FileMode.Create);
        Stream stream = new FileStream(SteamWare.fileMover.getFilePath(pdfPathName), FileMode.Create);
        //Stream stream = new FileStream(SteamWare.SteamwareStrings.getFilePath(pdfPathName), FileMode.Create);
        m_streams.Add(stream);
    return stream;
  }
  /// <summary>
  /// Handler per PrintPageEvents
  /// </summary>
  /// <param name="sender"></param>
  /// <param name="ev"></param>
  private void PrintPage(object sender, PrintPageEventArgs ev)
  {
    Metafile pageImage = new Metafile(m_streams[m_currentPageIndex]);
    ev.Graphics.DrawImage(pageImage, ev.PageBounds);
    m_currentPageIndex++;
    ev.HasMorePages = (m_currentPageIndex < m_streams.Count);
  }
  /// <summary>
  /// funzione di stampa...
  /// </summary>
  private void Print(string printerName)
  {
    //const string printerName = "Microsoft Office Document Image Writer";
    //const string printerName = "Brother HL-2170W series";
    if (m_streams == null || m_streams.Count == 0)
      return;
    PrintDocument printDoc = new PrintDocument();
    printDoc.PrinterSettings.PrinterName = printerName;
    if (!printDoc.PrinterSettings.IsValid)
    {
      logger.lg.scriviLog(String.Format("Impostazioni non valide per la stampante \"{0}\".", printerName), tipoLog.ERROR);
      return;
    }
    printDoc.PrintPage += new PrintPageEventHandler(PrintPage);
    printDoc.Print();
  }
  /// <summary>
  /// Export del report come EMF (Enhanced Metafile) file.
  /// </summary>
  /// <param name="report"></param>
  private void Export(LocalReport report, string deviceInfo)
  {
    Warning[] warnings;
    m_streams = new List<Stream>();
    report.Render("Image", deviceInfo, CreateStream, out warnings);
    foreach (Stream stream in m_streams) stream.Position = 0;
  }
  /// <summary>
  /// Export del report come PDF file.
  /// </summary>
  /// <param name="report"></param>
  private void ExportPDF(LocalReport report, string deviceInfo)
  {
    Warning[] warnings;
    m_streams = new List<Stream>();
    report.Render("PDF", deviceInfo, CreateStreamPdf, out warnings);
    foreach (Stream stream in m_streams) stream.Position = 0;
  }
  /// <summary>
  /// dispone l'applicazione e rilascia le risorse
  /// </summary>
  public void Dispose()
  {
    if (m_streams != null)
    {
      foreach (Stream stream in m_streams)
        stream.Close();
      m_streams = null;
    }
  }

  #endregion

  #region area codice da modificare

  /// <summary>
  /// carica i dati richiesti dal report dalla StoredProcedure (filtrando quindi...)
  /// </summary>
  /// <param name="tipoReport"></param>
  /// <param name="UDC">cod UDC</param>
  /// <returns>tabella dati</returns>
  private DataTable caricaDati(reportRichiesto tipoReport, string UDC)
  {
    DataTable tab = new DataTable();
    switch (tipoReport)
    {
      case reportRichiesto.CartellinoAL:
        tab = (DataTable)DataProxy.obj.taPrtCartAL.GetData(UDC);
        break;
      case reportRichiesto.CartellinoALRX:
        tab = (DataTable)DataProxy.obj.taPrtCartAL.GetData(UDC);
        break;
      case reportRichiesto.CartellinoALTT:
        tab = (DataTable)DataProxy.obj.taPrtCartAL.GetData(UDC);
        break;
      case reportRichiesto.CartellinoAnime:
        tab = (DataTable)DataProxy.obj.taPrtCartAnime.GetData(UDC);
        break;
      case reportRichiesto.CartellinoFiniti:
        tab = (DataTable)DataProxy.obj.taPrtCartFiniti.GetData(UDC);
        break;
      case reportRichiesto.CartellinoFinitiRxSP:
        tab = (DataTable)DataProxy.obj.taPrtCartFinitiRxSP.GetData(UDC);
        break;
      case reportRichiesto.CartellinoFinitiSP:
        tab = (DataTable)DataProxy.obj.taPrtCartFinitiSP.GetData(UDC);
        break;
      case reportRichiesto.CartellinoFusi:
        tab = (DataTable)DataProxy.obj.taPrtCartFusi.GetData(UDC);
        break;
      case reportRichiesto.CartellinoALANkit:
        tab = (DataTable)DataProxy.obj.taPrtCartKitAnime.GetData(UDC);
        break;
      case reportRichiesto.CartellinoLiquidiF10:
        tab = (DataTable)DataProxy.obj.taPrtCartLiqF10.GetData(UDC);
        break;
      case reportRichiesto.CartellinoLiquidiF18:
        tab = (DataTable)DataProxy.obj.taPrtCartLiqF18.GetData(UDC);
        break;
      case reportRichiesto.CartellinoMP:
        tab = (DataTable)DataProxy.obj.taPrtCartMP.GetData(UDC);
        break;
      case reportRichiesto.CartellinoOdette:
        tab = (DataTable)Odette.mgr.taOdette.getByUdc(UDC);
        break;
      case reportRichiesto.CartellinoSterrati:
        tab = (DataTable)DataProxy.obj.taPrtCartSterrati.GetData(UDC);
        break;
      case reportRichiesto.CartellinoTara:
        tab = (DataTable)DataProxy.obj.taPrtCart.GetData(UDC);
        break;
      case reportRichiesto.CartellinoTrattati:
        tab = (DataTable)DataProxy.obj.taPrtCartTratt.GetData(UDC);
        break;
      case reportRichiesto.CartellinoWIP:
        tab = (DataTable)DataProxy.obj.taPrtCart.GetData(UDC);
        break;
      default:
        break;
    }
    return tab;
  }
  /// <summary>
  /// Crea un report locale da file rdlc, carica i dati, esporta report come EMF file e quindi lo invia alla stampante
  /// </summary>
  /// <param name="tipoReport">report ammessi: ElencoMacchine / RichiestaIntervento</param>
  /// <param name="printerName">nome completo stampante (rispetto al server)</param>
  /// <param name="UDC">cod UDC</param>
  /// <param name="deviceInfoParam">parametri "device input"</param>
  public void printReport(reportRichiesto tipoReport, string printerName, string UDC, devInfoParam deviceInfoParam)
  {
    LocalReport report = new LocalReport();
    string deviceInfo = "";
    switch (tipoReport)
    {
      case reportRichiesto.CartellinoAL:
        report.ReportPath = string.Format(@"{0}\CartellinoAL.rdlc", memLayer.ML.cdv("ReportBasePath"));
        report.DataSources.Add(new ReportDataSource(memLayer.ML.cdv("ReportDatasourceAL"), caricaDati(tipoReport, UDC)));
        break;
      case reportRichiesto.CartellinoALRX:
        report.ReportPath = string.Format(@"{0}\CartellinoALRX.rdlc", memLayer.ML.cdv("ReportBasePath"));
        report.DataSources.Add(new ReportDataSource(memLayer.ML.cdv("ReportDatasourceALRX"), caricaDati(tipoReport, UDC)));
        break;
      case reportRichiesto.CartellinoALTT:
        report.ReportPath = string.Format(@"{0}\CartellinoALTT.rdlc", memLayer.ML.cdv("ReportBasePath"));
        report.DataSources.Add(new ReportDataSource(memLayer.ML.cdv("ReportDatasourceALTT"), caricaDati(tipoReport, UDC)));
        break;
      case reportRichiesto.CartellinoAnime:
        report.ReportPath = string.Format(@"{0}\CartellinoAnime.rdlc", memLayer.ML.cdv("ReportBasePath"));
        report.DataSources.Add(new ReportDataSource(memLayer.ML.cdv("ReportDatasourceAnime"), caricaDati(tipoReport, UDC)));
        break;
      case reportRichiesto.CartellinoALANkit:
        report.ReportPath = string.Format(@"{0}\CartellinoALANkit.rdlc", memLayer.ML.cdv("ReportBasePath"));
        report.DataSources.Add(new ReportDataSource(memLayer.ML.cdv("ReportDatasourceALANkit"), caricaDati(tipoReport, UDC)));
        break;
      case reportRichiesto.CartellinoFiniti:
        report.ReportPath = string.Format(@"{0}\CartellinoFiniti.rdlc", memLayer.ML.cdv("ReportBasePath"));
        report.DataSources.Add(new ReportDataSource(memLayer.ML.cdv("ReportDatasourceFiniti"), caricaDati(tipoReport, UDC)));
        break;
      case reportRichiesto.CartellinoFinitiRxSP:
        report.ReportPath = string.Format(@"{0}\CartellinoFinitiRxSP.rdlc", memLayer.ML.cdv("ReportBasePath"));
        report.DataSources.Add(new ReportDataSource(memLayer.ML.cdv("ReportDatasourceFinitiRxSP"), caricaDati(tipoReport, UDC)));
        break;
      case reportRichiesto.CartellinoFinitiSP:
        report.ReportPath = string.Format(@"{0}\CartellinoFinitiSP.rdlc", memLayer.ML.cdv("ReportBasePath"));
        report.DataSources.Add(new ReportDataSource(memLayer.ML.cdv("ReportDatasourceFinitiSP"), caricaDati(tipoReport, UDC)));
        break;
      case reportRichiesto.CartellinoFusi:
        report.ReportPath = string.Format(@"{0}\CartellinoFusi.rdlc", memLayer.ML.cdv("ReportBasePath"));
        report.DataSources.Add(new ReportDataSource(memLayer.ML.cdv("ReportDatasourceFusi"), caricaDati(tipoReport, UDC)));
        break;
      case reportRichiesto.CartellinoMP:
        report.ReportPath = string.Format(@"{0}\CartellinoMP.rdlc", memLayer.ML.cdv("ReportBasePath"));
        report.DataSources.Add(new ReportDataSource(memLayer.ML.cdv("ReportDatasource"), caricaDati(tipoReport, UDC)));
        break;
      case reportRichiesto.CartellinoLiquidiF10:
        report.ReportPath = string.Format(@"{0}\CartellinoLiquidiF10.rdlc", memLayer.ML.cdv("ReportBasePath"));
        report.DataSources.Add(new ReportDataSource(memLayer.ML.cdv("ReportDatasourceLiquidiF10"), caricaDati(tipoReport, UDC)));
        break;
      case reportRichiesto.CartellinoLiquidiF18:
        report.ReportPath = string.Format(@"{0}\CartellinoLiquidiF18.rdlc", memLayer.ML.cdv("ReportBasePath"));
        report.DataSources.Add(new ReportDataSource(memLayer.ML.cdv("ReportDatasourceLiquidiF18"), caricaDati(tipoReport, UDC)));
        break;
      case reportRichiesto.CartellinoOdette:
        report.ReportPath = string.Format(@"{0}\CartellinoOdette.rdlc", memLayer.ML.cdv("ReportBasePath"));
        report.DataSources.Add(new ReportDataSource(memLayer.ML.cdv("ReportDatasourceOdette"), caricaDati(tipoReport, UDC)));
        break;
      case reportRichiesto.CartellinoSterrati:
        report.ReportPath = string.Format(@"{0}\CartellinoSterrati.rdlc", memLayer.ML.cdv("ReportBasePath"));
        report.DataSources.Add(new ReportDataSource(memLayer.ML.cdv("ReportDatasourceSterrati"), caricaDati(tipoReport, UDC)));
        break;
      case reportRichiesto.CartellinoTara:
        report.ReportPath = string.Format(@"{0}\CartellinoTara.rdlc", memLayer.ML.cdv("ReportBasePath"));
        report.DataSources.Add(new ReportDataSource(memLayer.ML.cdv("ReportDatasource"), caricaDati(tipoReport, UDC)));
        break;
      case reportRichiesto.CartellinoTrattati:
        report.ReportPath = string.Format(@"{0}\CartellinoTrattati.rdlc", memLayer.ML.cdv("ReportBasePath"));
        report.DataSources.Add(new ReportDataSource(memLayer.ML.cdv("ReportDatasourceTrattati"), caricaDati(tipoReport, UDC)));
        break;
      case reportRichiesto.CartellinoWIP:
        report.ReportPath = string.Format(@"{0}\CartellinoWip.rdlc", memLayer.ML.cdv("ReportBasePath"));
        report.DataSources.Add(new ReportDataSource(memLayer.ML.cdv("ReportDatasource"), caricaDati(tipoReport, UDC)));
        break;
    }
    deviceInfo = deviceInfoParam.xmlParam;
    doEmfPrint(printerName, report, deviceInfo);
    // controllo se devo fare copia PDF... stampiamo ANCHE su pdf su una folder locale
    if (doPdfCopy)
    {
      deviceInfoParam.OutputFormat = "PDF";
      deviceInfo = deviceInfoParam.xmlParam;
      doLocalPdfPrint(report, deviceInfo);
    }
  }
  /// <summary>
  /// esegue print vero e proprio
  /// </summary>
  /// <param name="printerName"></param>
  /// <param name="report"></param>
  /// <param name="deviceInfo"></param>
  private void doEmfPrint(string printerName, LocalReport report, string deviceInfo)
  {
    // export in EMF
    Export(report, deviceInfo);
    m_currentPageIndex = 0;
    // stampo
    Print(printerName);
    // do dispose?
    Dispose();
  }
  /// <summary>
  /// effettua stampa in PDF dei vari report in una cartella Anno/Mese/Giorno
  /// </summary>
  /// <param name="report"></param>
  /// <param name="deviceInfo"></param>
  private void doLocalPdfPrint(LocalReport report, string deviceInfo)
  {
    // export in PDF
    ExportPDF(report, deviceInfo);
    m_currentPageIndex = 0;
    // do dispose?
    Dispose();
  }
  /// <summary>
  /// effettua la stampa del cartellino indicato
  /// </summary>
  /// <param name="cartellino"></param>
  /// <param name="UDC"></param>
  /// <param name="printerName">indirizzo di rete completo stampante del tipo \\nomePc\nomeStampante, oppure "" x default</param>
  /// <returns></returns>
  public bool stampaCartellino(tipoCartellino cartellino, string UDC, string printerName)
  {
    bool answ = false;
    int idxPrintJob = 0;
    DataProxy dtProx = new DataProxy();
    // gestione coda: SE abilitata...
    if (memLayer.ML.confReadBool("enableQueue"))
    {
      // incomincio con gestione della coda di stampa... inserisco in tab la richiesta di stampa...
      if (memLayer.ML.CRB("disable_singleton"))
      {
        dtProx.taPJQ.insertQuery(cartellino.ToString(), UDC, printerName);
      }
      else
      {
        DataProxy.obj.taPJQ.insertQuery(cartellino.ToString(), UDC, printerName);
      }
      // faccio un ciclo while... finchè non sono "in testa" alla coda delle esecuzioni aspetto...
      string nextUdc = "ND";
      try
      {
        if (memLayer.ML.CRB("disable_singleton"))
        {
          nextUdc = dtProx.taPJQ.getNext()[0].UDC;
        }
        else
        {
          nextUdc = DataProxy.obj.taPJQ.getNext()[0].UDC;
        }
      }
      catch
      {
        nextUdc = "ND";
      }
      // verifico eventuali processi zombie: quelli in stato 0 con LastTry superiore a data attuale meno zombieMsTime
      if (memLayer.ML.CRB("disable_singleton"))
      {
        dtProx.taPJQ.chiudiZoombie(DateTime.Now.AddMilliseconds(-memLayer.ML.confReadInt("zombieMsTime")));
      }
      else
      {
        DataProxy.obj.taPJQ.chiudiZoombie(DateTime.Now.AddMilliseconds(-memLayer.ML.confReadInt("zombieMsTime")));
      }
      // ora inizio a fare le mie stampe...
      Random rand = new Random();
      int msWait = 200;
      while (nextUdc != UDC)
      {
        // indico che ho fatto un tentativo di stampa aggiornando dtLastTry
        if (memLayer.ML.CRB("disable_singleton"))
        {
          dtProx.taPJQ.updateLastTry(UDC);
        }
        else
        {
          DataProxy.obj.taPJQ.updateLastTry(UDC);
        }
        // aspetto...
        msWait = rand.Next(memLayer.ML.confReadInt("minWait"), memLayer.ML.confReadInt("maxWait"));
        System.Threading.Thread.Sleep(msWait);
        // leggo prox record da coda
        if (memLayer.ML.CRB("disable_singleton"))
        {
          nextUdc = dtProx.taPJQ.getNext()[0].UDC;
        }
        else
        {
          nextUdc = DataProxy.obj.taPJQ.getNext()[0].UDC;
        }
      }
      // salvo idx job...
      if (memLayer.ML.CRB("disable_singleton"))
      {
        idxPrintJob = dtProx.taPJQ.getNext()[0].IdxPrintJob;
      }
      else
      {
        idxPrintJob = DataProxy.obj.taPJQ.getNext()[0].IdxPrintJob;
      }
    }
    string outForm = "";
    string pagWidth = "";
    string pagHeigth = "";
    string margin = "";
    reportRichiesto report = reportRichiesto.CartellinoFusi;
    string tipo = "";
    switch (cartellino)
    {
      case tipoCartellino.cartAL:
        tipo = "CartAL";
        report = reportRichiesto.CartellinoAL;
        break;
      case tipoCartellino.cartALRX:
        tipo = "CartAL";
        report = reportRichiesto.CartellinoALRX;
        break;
      case tipoCartellino.cartALTT:
        tipo = "CartAL";
        report = reportRichiesto.CartellinoALTT;
        break;
      case tipoCartellino.cartAnime:
        tipo = "CartAnime";
        report = reportRichiesto.CartellinoAnime;
        break;
      case tipoCartellino.cartALANkit:
        tipo = "CartALANkit";
        report = reportRichiesto.CartellinoALANkit;
        break;
      case tipoCartellino.cartFiniti:
        tipo = "CartFiniti";
        report = reportRichiesto.CartellinoFiniti;
        break;
      case tipoCartellino.cartFinitiRxSP:
        tipo = "CartFiniti";
        report = reportRichiesto.CartellinoFinitiRxSP;
        break;
      case tipoCartellino.cartFinitiSP:
        tipo = "CartFiniti";
        report = reportRichiesto.CartellinoFinitiSP;
        break;
      case tipoCartellino.cartFusi:
        tipo = "CartFusi";
        report = reportRichiesto.CartellinoFusi;
        break;
      case tipoCartellino.cartLiquidiF10:
        tipo = "CartLiquidiF10";
        report = reportRichiesto.CartellinoLiquidiF10;
        break;
      case tipoCartellino.cartLiquidiF18:
        tipo = "CartLiquidiF18";
        report = reportRichiesto.CartellinoLiquidiF18;
        break;
      case tipoCartellino.cartMP:
        tipo = "CartMP";
        report = reportRichiesto.CartellinoMP;
        break;
      case tipoCartellino.cartOdette:
        tipo = "CartOdette";
        report = reportRichiesto.CartellinoOdette;
        break;
      case tipoCartellino.cartSterr:
        tipo = "CartSterr";
        report = reportRichiesto.CartellinoSterrati;
        break;
      case tipoCartellino.cartTara:
        tipo = "CartTara";
        report = reportRichiesto.CartellinoTara;
        break;
      case tipoCartellino.cartTratt:
        tipo = "CartTratt";
        report = reportRichiesto.CartellinoTrattati;
        break;
      case tipoCartellino.cartWip:
        tipo = "CartWip";
        report = reportRichiesto.CartellinoWIP;
        break;
      default:
        break;
    }
    // carico di dati con lettura da web.config parametrica
    if (string.IsNullOrEmpty(printerName))
    {
      printerName = memLayer.ML.cdv(string.Format("printer{0}", tipo));
    }
    outForm = "EMF";
    pagWidth = memLayer.ML.cdv(string.Format("PageWidth{0}", tipo));
    pagHeigth = memLayer.ML.cdv(string.Format("PageHeight{0}", tipo));
    margin = memLayer.ML.cdv(string.Format("Margin{0}", tipo));
    // compongo parametri stampa
    devInfoParam deviceInfo = new devInfoParam(outForm, pagHeigth, pagWidth, margin, margin, margin, margin);
    answ = printAndLog(UDC, printerName, answ, report, deviceInfo);
    // gestione coda: SE abilitata...
    if (memLayer.ML.confReadBool("enableQueue"))
    {
      if (answ)
      {
        // registro stampato in tabella queue...
        if (memLayer.ML.CRB("disable_singleton"))
        {
          dtProx.taPJQ.updateStato(idxPrintJob, 1);
        }
        else
        {
          DataProxy.obj.taPJQ.updateStato(idxPrintJob, 1);
        }
      }
      else
      {
        // registro annullato in tab queue...
        if (memLayer.ML.CRB("disable_singleton"))
        {
          dtProx.taPJQ.updateStato(idxPrintJob, -1);
        }
        else
        {
          DataProxy.obj.taPJQ.updateStato(idxPrintJob, -1);
        }
      }
    }
    return answ;
  }
  /// <summary>
  /// effettua la vera e propria fase di stampa
  /// </summary>
  /// <param name="UDC"></param>
  /// <param name="printerName"></param>
  /// <param name="answ"></param>
  /// <param name="report"></param>
  /// <param name="deviceInfo"></param>
  /// <returns></returns>
  private bool printAndLog(string UDC, string printerName, bool answ, reportRichiesto report, devInfoParam deviceInfo)
  {
    try
    {
      if (logLevel > 5) logger.lg.scriviLog(String.Format("Sto per inviare un report alla stampante {0}", printerName), tipoLog.INFO);
      reportPrinter.obj.printReport(report, printerName, UDC, deviceInfo);
      if (logLevel > 5) logger.lg.scriviLog(String.Format("inviato comando print alla stampante {0}", printerName), tipoLog.INFO);
      answ = true;
    }
    catch (Exception e)
    {
      logger.lg.scriviLog(String.Format("Errore in fase di creazione e stampa report: stampante {0}, errore riscontrato {1}", printerName, e), tipoLog.EXCEPTION);
    }
    return answ;
  }
  /// <summary>
  /// oggetto protected
  /// </summary>
  /// <param name="args"></param>
  protected reportPrinter()
  {
    logLevel = memLayer.ML.confReadInt("_logLevel");
    doPdfCopy = memLayer.ML.confReadBool("doPdfCopy");
  }
  /// <summary>
  /// singleton pubblico
  /// </summary>
  public static reportPrinter obj = new reportPrinter();
  /// <summary>
  /// effettua pulizia della cartella temp x i files più vecchi di X ore (web.config)
  /// </summary>
  public void pulisciDir()
  {
    // num max ore di età x files "vecchi" da tenere in temp area...
    int maxOre = memLayer.ML.confReadInt("maxAgeTempAreaHours");
    int eliminati = 0;
    // ottengo elenco files *.emf
    fileMover.obj.setDirectory(@"~\temp\");
    FileInfo[] _fis = fileMover.obj.elencoFiles_FI("*.emf");
    bool fatto = false;
    foreach (FileInfo _file in _fis)
    {
      if (_file.CreationTime < DateTime.Now.AddHours(-maxOre)) // elimino files vecchi...
      {
        fatto = fileMover.obj.eliminaFile(_file);
        if (fatto)
        {
          logger.lg.scriviLog(String.Format("Eliminato file {0}", _file.Name), tipoLog.INFO);
          eliminati++;
        }
      }
    }
    // salvo il log degli update
    if (eliminati > 0)
    {
      logger.lg.scriviLog(String.Format("Eliminati {0} files temporanei da area temp", eliminati), tipoLog.INFO);
    }
  }

  #endregion
}
/// <summary>
/// tipologia di report ammessi alla stampa...
/// </summary>
public enum reportRichiesto
{
  CartellinoAL,
  CartellinoALANkit,
  CartellinoALRX,
  CartellinoALTT,
  CartellinoAnime,
  CartellinoFiniti,
  CartellinoFinitiRxSP,
  CartellinoFinitiSP,
  CartellinoFusi,
  CartellinoLiquidiF10,
  CartellinoLiquidiF18,
  CartellinoMP,
  CartellinoOdette,
  CartellinoSterrati,
  CartellinoTara,
  CartellinoTrattati,
  CartellinoWIP
}
