update reports!
This commit is contained in:
@@ -0,0 +1,146 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Data;
|
||||
using System.Text;
|
||||
using System.Drawing.Imaging;
|
||||
using System.Drawing.Printing;
|
||||
using System.Collections.Generic;
|
||||
using System.Windows.Forms;
|
||||
using Microsoft.Reporting.WinForms;
|
||||
using System.Configuration;
|
||||
|
||||
public class stampaSchedaIdent : IDisposable
|
||||
{
|
||||
|
||||
#region area codice da non modificare
|
||||
|
||||
private int m_currentPageIndex;
|
||||
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)
|
||||
{
|
||||
Stream stream = new FileStream(@"..\..\" + name + "." + fileNameExtension, 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)
|
||||
{
|
||||
string msg = String.Format("Can't find printer \"{0}\".", printerName);
|
||||
MessageBox.Show(msg, "Print Error");
|
||||
return;
|
||||
}
|
||||
printDoc.PrintPage += new PrintPageEventHandler(PrintPage);
|
||||
printDoc.Print();
|
||||
}
|
||||
/// <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="idxObj"></param>
|
||||
/// <returns></returns>
|
||||
private DataTable caricaDati(string idxObj)
|
||||
{
|
||||
PrintLocalReport.DS_applicazioneTableAdapters.sp_schedaIdentTableAdapter taSp = new PrintLocalReport.DS_applicazioneTableAdapters.sp_schedaIdentTableAdapter();
|
||||
taSp.Connection.ConnectionString = ConfigurationSettings.AppSettings.Get("reportConnectionString");
|
||||
return (DataTable)taSp.GetData(idxObj);
|
||||
}
|
||||
/// <summary>
|
||||
/// Export del report come EMF (Enhanced Metafile) file.
|
||||
/// </summary>
|
||||
/// <param name="report"></param>
|
||||
private void Export(LocalReport report)
|
||||
{
|
||||
// !!!verificare formato!!!
|
||||
string deviceInfo =
|
||||
"<DeviceInfo>" +
|
||||
" <OutputFormat>EMF</OutputFormat>" +
|
||||
" <PageWidth>25cm</PageWidth>" +
|
||||
" <PageHeight>17.6cm</PageHeight>" +
|
||||
" <MarginTop>0.2cm</MarginTop>" +
|
||||
" <MarginLeft>0.2cm</MarginLeft>" +
|
||||
" <MarginRight>0.2cm</MarginRight>" +
|
||||
" <MarginBottom>0.2cm</MarginBottom>" +
|
||||
"</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>
|
||||
/// Crea un report locale da file rdlc, carica i dati, esporta report come EMF file e quindi lo invia alla stampante
|
||||
/// </summary>
|
||||
/// <param name="idxObjRich"></param>
|
||||
/// <param name="printerName"></param>
|
||||
private void Run(string printerName, string idxObjRich)
|
||||
{
|
||||
LocalReport report = new LocalReport();
|
||||
report.ReportPath = @"..\..\ReportSchedaIdentificazione.rdlc";
|
||||
report.DataSources.Add(new ReportDataSource("Equa", caricaDati(idxObjRich))); // OCCHIO!!! va messa sorgente dati CORRETTA
|
||||
ReportParameter[] idxObj = { new ReportParameter("IdxObj", idxObjRich) }; // OCCHIO!!! van messi parametri corretti richeisti dal report
|
||||
report.SetParameters(idxObj);
|
||||
Export(report);
|
||||
m_currentPageIndex = 0;
|
||||
Print(printerName);
|
||||
}
|
||||
/// <summary>
|
||||
/// avvio della console application per stampa del report scheda di identificazione
|
||||
/// </summary>
|
||||
/// <param name="args"></param>
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
using (stampaSchedaIdent stampaScheda = new stampaSchedaIdent())
|
||||
{
|
||||
stampaScheda.Run(args[0], args[1]);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user