32fb68fa68
- Cleanup codice area MapoDb
214 lines
6.9 KiB
C#
214 lines
6.9 KiB
C#
using MapoDb;
|
|
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>
|
|
/// tipologia di report ammessi alla stampa...
|
|
/// </summary>
|
|
public enum reportRichiesto
|
|
{
|
|
SchedaODL
|
|
}
|
|
|
|
/// <summary>
|
|
/// Classe che si occupa di stampare report da reportViewer via printer remota
|
|
/// </summary>
|
|
public class reportPrinter
|
|
{
|
|
#region Public Fields
|
|
|
|
/// <summary>
|
|
/// singleton pubblico
|
|
/// </summary>
|
|
public static reportPrinter obj = new reportPrinter();
|
|
|
|
#endregion Public Fields
|
|
|
|
#region Public Methods
|
|
|
|
/// <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;
|
|
}
|
|
}
|
|
|
|
/// <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="parametro">numIntMtz (codice numero richiesta)</param>
|
|
public void printReport(reportRichiesto tipoReport, string printerName, string parametro)
|
|
{
|
|
LocalReport report = new LocalReport();
|
|
devInfoParam deviceInfo = new devInfoParam("EMF", "21cm", "29.7cm", "0.2cm", "0.2cm", "0.2cm", "0.2cm");
|
|
switch (tipoReport)
|
|
{
|
|
case reportRichiesto.SchedaODL:
|
|
report.ReportPath = @".\Reports\Donati_ODL.rdlc";
|
|
report.DataSources.Add(new ReportDataSource("MoonPro", caricaDati(tipoReport, parametro)));
|
|
deviceInfo = new devInfoParam("EMF", "21cm", "29.7cm", "0.2cm", "0.2cm", "0.2cm", "0.2cm");
|
|
break;
|
|
//case reportRichiesto.RichiestaIntervento:
|
|
// report.ReportPath = @".\Reports\RichiestaIntervento.rdlc";
|
|
// report.DataSources.Add(new ReportDataSource("WebGim", caricaDati(tipoReport, parametro)));
|
|
// deviceInfo = new devInfoParam("EMF", "29.7cm", "21cm", "0.2cm", "0.2cm", "0.2cm", "0.2cm");
|
|
// break;
|
|
//default:
|
|
// break;
|
|
}
|
|
doEmfPrint(printerName, report, deviceInfo.xmlParam);
|
|
}
|
|
|
|
#endregion Public Methods
|
|
|
|
#region Protected Constructors
|
|
|
|
/// <summary>
|
|
/// oggetto protected
|
|
/// </summary>
|
|
/// <param name="args"></param>
|
|
protected reportPrinter()
|
|
{
|
|
}
|
|
|
|
#endregion Protected Constructors
|
|
|
|
#region Private Fields
|
|
|
|
private int m_currentPageIndex;
|
|
private IList<Stream> m_streams;
|
|
|
|
#endregion Private Fields
|
|
|
|
#region Private Methods
|
|
|
|
/// <summary>
|
|
/// carica i dati richiesti dal report dalla StoredProcedure (filtrando quindi...)
|
|
/// </summary>
|
|
/// <param name="tipoReport">report ammessi: ElencoMacchine / RichiestaIntervento</param>
|
|
/// <param name="periodoAnalizzato">
|
|
/// oggetto che contiene data inizio e data fine dell'analisi richiesta per il report
|
|
/// </param>
|
|
/// <returns>tabella dati</returns>
|
|
private DataTable caricaDati(reportRichiesto tipoReport, string idxObj)
|
|
{
|
|
DataLayer DataLayerObj = new DataLayer();
|
|
// calcolo idxODL
|
|
int idxOdl = 0;
|
|
try
|
|
{
|
|
idxOdl = Convert.ToInt32(idxObj);
|
|
}
|
|
catch
|
|
{ }
|
|
DataTable tab = new DataTable();
|
|
switch (tipoReport)
|
|
{
|
|
case reportRichiesto.SchedaODL:
|
|
tab = (DataTable)DataLayerObj.taODL.getByIdx(idxOdl, false);
|
|
break;
|
|
//case reportRichiesto.RichiestaIntervento:
|
|
// tab = (DataTable)TA_app.obj.taInterventiMtz.getByIdx(Convert.ToInt32(idxObj));
|
|
// break;
|
|
//default:
|
|
// break;
|
|
}
|
|
return tab;
|
|
}
|
|
|
|
/// <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)
|
|
{
|
|
Stream stream = new FileStream(SteamWare.fileMover.getFilePath(@".\temp\" + name + "." + fileNameExtension), FileMode.Create);
|
|
m_streams.Add(stream);
|
|
return stream;
|
|
}
|
|
|
|
/// <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>
|
|
/// 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>
|
|
/// 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("Can't find printer \"{0}\".", printerName), tipoLog.ERROR);
|
|
return;
|
|
}
|
|
printDoc.PrintPage += new PrintPageEventHandler(PrintPage);
|
|
printDoc.Print();
|
|
}
|
|
|
|
/// <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);
|
|
}
|
|
|
|
#endregion Private Methods
|
|
} |