Prima bozza stampa....
This commit is contained in:
@@ -7,6 +7,7 @@
|
||||
<!-- conf server comunicazione-->
|
||||
<add key="serverBaseAddr" value="http://iis02/NKC" />
|
||||
<add key="localReportPath" value="reports" />
|
||||
<add key="localPdfPath" value="pdf" />
|
||||
<add key="_logDir" value="/logs/" />
|
||||
</appSettings>
|
||||
<runtime>
|
||||
|
||||
+6
-4
@@ -168,6 +168,7 @@
|
||||
<Compile Include="printQueue.cs" />
|
||||
<Compile Include="Program.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="reportPrinter.cs" />
|
||||
<Compile Include="utils.cs" />
|
||||
<EmbeddedResource Include="MainForm.resx">
|
||||
<DependentUpon>MainForm.cs</DependentUpon>
|
||||
@@ -196,6 +197,9 @@
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Include="packages.config" />
|
||||
<None Include="pdf\.placeholder">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Include="Properties\Settings.settings">
|
||||
<Generator>SettingsSingleFileGenerator</Generator>
|
||||
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
|
||||
@@ -208,7 +212,7 @@
|
||||
<None Include="reports\.placeholder">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Include="temp\.placeholder">
|
||||
<None Include="pdf\temp\.placeholder">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
@@ -232,9 +236,7 @@
|
||||
<Content Include="App_Readme\SteamWare_demo\example-favicon.ico" />
|
||||
<Content Include="mongocrypt.dll" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Folder Include="pdf\" />
|
||||
</ItemGroup>
|
||||
<ItemGroup />
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
|
||||
<PropertyGroup>
|
||||
|
||||
+51
-184
@@ -1,18 +1,13 @@
|
||||
using System;
|
||||
using Newtonsoft.Json;
|
||||
using SteamWare;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Data;
|
||||
using System.Drawing;
|
||||
using System.Drawing.Imaging;
|
||||
using System.Drawing.Printing;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Net.Http;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
using Microsoft.Reporting.WinForms;
|
||||
using Newtonsoft.Json;
|
||||
using SteamWare;
|
||||
|
||||
namespace LPA
|
||||
{
|
||||
@@ -60,6 +55,10 @@ namespace LPA
|
||||
/// Code di stampa disponibili (da server)
|
||||
/// </summary>
|
||||
protected List<queueConf> listQueue = new List<queueConf>();
|
||||
/// <summary>
|
||||
/// Classe gestioen stampa report
|
||||
/// </summary>
|
||||
protected reportPrinter rPrint;
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -87,7 +86,16 @@ namespace LPA
|
||||
refreshLocaltemplate();
|
||||
refreshQueueAvail();
|
||||
setupDGV();
|
||||
setupReportPrinter();
|
||||
}
|
||||
/// <summary>
|
||||
/// Setup istanza classe stampa report
|
||||
/// </summary>
|
||||
private void setupReportPrinter()
|
||||
{
|
||||
rPrint = new reportPrinter();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Setup parametri base di configurazione
|
||||
/// </summary>
|
||||
@@ -176,6 +184,24 @@ namespace LPA
|
||||
return result;
|
||||
}
|
||||
/// <summary>
|
||||
/// Chiamata PUT async URL
|
||||
/// </summary>
|
||||
/// <param name="url2call"></param>
|
||||
/// <param name="payload"></param>
|
||||
/// <returns></returns>
|
||||
protected string postUrl(string url2call, string payload)
|
||||
{
|
||||
string result = "";
|
||||
// fix contenuto
|
||||
Uri callUri = new Uri(url2call);
|
||||
HttpContent callCont = new StringContent(payload, Encoding.UTF8, "application/json");
|
||||
// chiamo!
|
||||
var taskRes = Task.Run(() => utils.putAsync(callUri, callCont, ""));
|
||||
taskRes.Wait();
|
||||
result = taskRes.Result;
|
||||
return result;
|
||||
}
|
||||
/// <summary>
|
||||
/// Configurazione coda stampa da json file
|
||||
/// </summary>
|
||||
protected Dictionary<string, printQueue> queueSetupJson
|
||||
@@ -294,7 +320,7 @@ namespace LPA
|
||||
// aggiorno uptime...
|
||||
DateTime adesso = DateTime.Now;
|
||||
TimeSpan uptime = adesso.Subtract(appStart);
|
||||
lblUptime.Text= $"Uptime: {utils.FormatTimeSpan(uptime, true)}";
|
||||
lblUptime.Text = $"Uptime: {utils.FormatTimeSpan(uptime, true)}";
|
||||
}
|
||||
|
||||
#endregion
|
||||
@@ -534,12 +560,24 @@ namespace LPA
|
||||
bool fatto = false;
|
||||
// se ho almeno 1 stampa --> lancio!
|
||||
queueConf confCoda = listQueue.Find(conf => conf.name == coda.Key);
|
||||
if(confCoda!=null)
|
||||
if (confCoda != null)
|
||||
{
|
||||
fatto= printReport(confCoda.rdsName, coda.Value.Printer, item.rdsTable, confCoda.deviceInfoParam, true);
|
||||
fatto = rPrint.printReport(confCoda.rdsName, localReportPath, coda.Value.Printer, item.rdsTable, confCoda.deviceInfoParam, true);
|
||||
}
|
||||
|
||||
// fatta stampa aggiorno server con indicazione ceh ho stampato
|
||||
if (fatto)
|
||||
{
|
||||
// compongo payload...
|
||||
printTask printResult = new printTask()
|
||||
{
|
||||
ticketNum = item.ticketNum,
|
||||
newStatus = 1,
|
||||
message = ""
|
||||
};
|
||||
string payload = JsonConvert.SerializeObject(printResult);
|
||||
// chiamo in put print result!
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -550,177 +588,6 @@ namespace LPA
|
||||
|
||||
#endregion
|
||||
|
||||
#region metodi stampa effettiva report
|
||||
|
||||
/// <summary>
|
||||
/// Indice pagina corrente x stampa ogni report
|
||||
/// </summary>
|
||||
private int m_currentPageIndex;
|
||||
/// <summary>
|
||||
/// stream del report...
|
||||
/// </summary>
|
||||
private IList<Stream> m_streams;
|
||||
/// <summary>
|
||||
/// Crea un report locale da file rdlc, carica i dati, esporta report come EMF file e quindi lo invia alla stampante + eventuale backup pdf
|
||||
/// </summary>
|
||||
/// <param name="rdsName">Nome report</param>
|
||||
/// <param name="printerName">nome completo stampante (rispetto al server)</param>
|
||||
/// <param name="tabDati">tabella dati da caricare nel report</param>
|
||||
/// <param name="deviceInfoParam">parametri "device input"</param>
|
||||
/// <param name="doPdfCopy">effettua ANCHE copia pdf</param>
|
||||
public bool printReport(string rdsName, string printerName, DataTable tabDati, devInfoParam deviceInfoParam, bool doPdfCopy)
|
||||
{
|
||||
bool answ = false;
|
||||
LocalReport report = new LocalReport();
|
||||
report.EnableExternalImages = true;
|
||||
string deviceInfo = "";
|
||||
report.ReportPath = $"{localReportPath}\\{rdsName}";
|
||||
report.DataSources.Add(new ReportDataSource(rdsName, tabDati));
|
||||
deviceInfo = deviceInfoParam.xmlParam;
|
||||
// stampa da EMF
|
||||
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;
|
||||
// salva ANCHE pdf
|
||||
doLocalPdfPrint(report, deviceInfo);
|
||||
}
|
||||
return answ;
|
||||
}
|
||||
/// <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>
|
||||
/// 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;
|
||||
}
|
||||
}
|
||||
/// <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(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'è
|
||||
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(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();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
|
||||
+126
-405
@@ -1,99 +1,99 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.Reporting.WinForms;
|
||||
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.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace LPA
|
||||
{
|
||||
/// <summary>
|
||||
/// Classe che si occupa di stampare report da reportViewer via printer locale/remota
|
||||
/// </summary>
|
||||
public class reportPrinter
|
||||
{
|
||||
#region area codice da non modificare
|
||||
/// <summary>
|
||||
/// Path x salvataggio locale pdf
|
||||
/// </summary>
|
||||
protected string localPdfPath = "pdf";
|
||||
/// <summary>
|
||||
/// Classe reportprinter
|
||||
/// </summary>
|
||||
public reportPrinter()
|
||||
{
|
||||
localPdfPath = memLayer.ML.confReadString("localPdfPath");
|
||||
}
|
||||
|
||||
#region metodi stampa effettiva report
|
||||
|
||||
/// <summary>
|
||||
/// Indice pagina corrente x stampa ogni report
|
||||
/// </summary>
|
||||
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
|
||||
/// Crea un report locale da file rdlc, carica i dati, esporta report come EMF file e quindi lo invia alla stampante + eventuale backup pdf
|
||||
/// </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)
|
||||
/// <param name="rdsName">Nome report</param>
|
||||
/// <param name="localReportPath">Cartella locale dei report</param>
|
||||
/// <param name="printerName">nome completo stampante (rispetto al server)</param>
|
||||
/// <param name="tabDati">tabella dati da caricare nel report</param>
|
||||
/// <param name="deviceInfoParam">parametri "device input"</param>
|
||||
/// <param name="doPdfCopy">effettua ANCHE copia pdf</param>
|
||||
public bool printReport(string rdsName, string localReportPath, string printerName, DataTable tabDati, devInfoParam deviceInfoParam, bool doPdfCopy)
|
||||
{
|
||||
// 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(filePathName), FileMode.Create);
|
||||
//Stream stream = new FileStream(SteamWare.SteamwareStrings.getFilePath(@"~\temp\" + name + "." + fileNameExtension), 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.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)
|
||||
bool answ = false;
|
||||
LocalReport report = new LocalReport();
|
||||
report.EnableExternalImages = true;
|
||||
string deviceInfo = "";
|
||||
report.ReportPath = $"{localReportPath}\\{rdsName}";
|
||||
report.DataSources.Add(new ReportDataSource(rdsName, tabDati));
|
||||
deviceInfo = deviceInfoParam.xmlParam;
|
||||
// stampa da EMF
|
||||
doEmfPrint(printerName, report, deviceInfo);
|
||||
// controllo se devo fare copia PDF... stampiamo ANCHE su pdf su una folder locale
|
||||
if (doPdfCopy)
|
||||
{
|
||||
logger.lg.scriviLog(String.Format("Impostazioni non valide per la stampante \"{0}\".", printerName), tipoLog.ERROR);
|
||||
return;
|
||||
deviceInfoParam.OutputFormat = "PDF";
|
||||
deviceInfo = deviceInfoParam.xmlParam;
|
||||
// salva ANCHE pdf
|
||||
doLocalPdfPrint(report, deviceInfo);
|
||||
}
|
||||
printDoc.PrintPage += new PrintPageEventHandler(PrintPage);
|
||||
printDoc.Print();
|
||||
return answ;
|
||||
}
|
||||
/// <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>
|
||||
/// Export del report come EMF (Enhanced Metafile) file.
|
||||
@@ -129,355 +129,76 @@ namespace LPA
|
||||
m_streams = null;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region area codice da modificare
|
||||
|
||||
/// <summary>
|
||||
/// carica i dati richiesti dal report dalla StoredProcedure (filtrando quindi...)
|
||||
/// ciclo da fornire al renderizzatore dei report, per salvare 1 immagine da ogni pagina del report
|
||||
/// </summary>
|
||||
/// <param name="tipoReport"></param>
|
||||
/// <param name="keyParam">cod UDC</param>
|
||||
/// <returns>tabella dati</returns>
|
||||
private DataTable caricaDati(reportRichiesto tipoReport, string keyParam)
|
||||
{
|
||||
int intIdx = 0;
|
||||
DataTable tab = new DataTable();
|
||||
switch (tipoReport)
|
||||
{
|
||||
case reportRichiesto.cartLabel:
|
||||
// int.TryParse(keyParam, out intIdx);
|
||||
// tab = (DataTable)DataLayer.man.taRepStack.GetData(intIdx);
|
||||
break;
|
||||
case reportRichiesto.paintLabelPre:
|
||||
// int.TryParse(keyParam, out intIdx);
|
||||
// tab = (DataTable)DataLayer.man.taRepStack.GetData(intIdx);
|
||||
break;
|
||||
case reportRichiesto.paintLabelPost:
|
||||
// int.TryParse(keyParam, out intIdx);
|
||||
// tab = (DataTable)DataLayer.man.taRepStack.GetData(intIdx);
|
||||
break;
|
||||
case reportRichiesto.partLabel:
|
||||
int.TryParse(keyParam, out intIdx);
|
||||
tab = (DataTable)DataLayer.man.taIL.getByKey(intIdx);
|
||||
break;
|
||||
case reportRichiesto.stackLabel:
|
||||
int.TryParse(keyParam, out intIdx);
|
||||
tab = (DataTable)DataLayer.man.taRepStack.GetData(intIdx);
|
||||
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="keyParam">cod UDC</param>
|
||||
/// <param name="deviceInfoParam">parametri "device input"</param>
|
||||
public void printReport(reportRichiesto tipoReport, string printerName, string keyParam, devInfoParam deviceInfoParam)
|
||||
{
|
||||
LocalReport report = new LocalReport();
|
||||
report.EnableExternalImages = true;
|
||||
string deviceInfo = "";
|
||||
string repoBasePath = utils.getPath(memLayer.ML.cdv("ReportBasePath"));
|
||||
repoBasePath = repoBasePath.Replace("\\site", "");
|
||||
switch (tipoReport)
|
||||
{
|
||||
case reportRichiesto.cartLabel:
|
||||
report.ReportPath = string.Format(@"{0}\CartLabel.rdlc", repoBasePath);
|
||||
report.DataSources.Add(new ReportDataSource(memLayer.ML.cdv("ReportDS_DocCart"), caricaDati(tipoReport, keyParam)));
|
||||
break;
|
||||
case reportRichiesto.paintLabelPre:
|
||||
report.ReportPath = string.Format(@"{0}\PaintPreLabel.rdlc", repoBasePath);
|
||||
report.DataSources.Add(new ReportDataSource(memLayer.ML.cdv("ReportDS_DocPaintPre"), caricaDati(tipoReport, keyParam)));
|
||||
break;
|
||||
case reportRichiesto.paintLabelPost:
|
||||
report.ReportPath = string.Format(@"{0}\PaintPreLabel.rdlc", repoBasePath);
|
||||
report.DataSources.Add(new ReportDataSource(memLayer.ML.cdv("ReportDS_DocPaintPre"), caricaDati(tipoReport, keyParam)));
|
||||
break;
|
||||
case reportRichiesto.partLabel:
|
||||
report.ReportPath = string.Format(@"{0}\PartLabel.rdlc", repoBasePath);
|
||||
report.DataSources.Add(new ReportDataSource(memLayer.ML.cdv("ReportDS_DocPart"), caricaDati(tipoReport, keyParam)));
|
||||
break;
|
||||
case reportRichiesto.stackLabel:
|
||||
report.ReportPath = string.Format(@"{0}\StackLabel.rdlc", repoBasePath);
|
||||
report.DataSources.Add(new ReportDataSource(memLayer.ML.cdv("ReportDS_DocStack"), caricaDati(tipoReport, keyParam)));
|
||||
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="documento"></param>
|
||||
/// <param name="keyParam"></param>
|
||||
/// <param name="printerName">indirizzo di rete completo stampante del tipo \\nomePc\nomeStampante, oppure "" x default</param>
|
||||
/// <param name="name"></param>
|
||||
/// <param name="fileNameExtension"></param>
|
||||
/// <param name="encoding"></param>
|
||||
/// <param name="mimeType"></param>
|
||||
/// <param name="willSeek"></param>
|
||||
/// <returns></returns>
|
||||
public bool stampaCartellino(tipoDocumento documento, string keyParam, string printerName)
|
||||
private Stream CreateStream(string name, string fileNameExtension, Encoding encoding, string mimeType, bool willSeek)
|
||||
{
|
||||
bool answ = false;
|
||||
int idxPrintJob = 0;
|
||||
DataLayer dtProx = new DataLayer();
|
||||
// gestione coda stampa...
|
||||
|
||||
// incomincio con gestione della coda di stampa... inserisco in tab la richiesta di stampa...
|
||||
if (memLayer.ML.CRB("disable_singleton"))
|
||||
{
|
||||
dtProx.taPJQ.insertQuery(documento.ToString(), keyParam, printerName);
|
||||
}
|
||||
else
|
||||
{
|
||||
DataLayer.man.taPJQ.insertQuery(documento.ToString(), keyParam, printerName);
|
||||
}
|
||||
// faccio un ciclo while... finchè non sono "in testa" alla coda delle esecuzioni aspetto...
|
||||
string nextJob = "ND";
|
||||
try
|
||||
{
|
||||
if (memLayer.ML.CRB("disable_singleton"))
|
||||
{
|
||||
nextJob = dtProx.taPJQ.getNext()[0].KeyParam;
|
||||
}
|
||||
else
|
||||
{
|
||||
nextJob = DataLayer.man.taPJQ.getNext()[0].KeyParam;
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
nextJob = "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.CRI("zombieMsTime")));
|
||||
}
|
||||
else
|
||||
{
|
||||
DataLayer.man.taPJQ.chiudiZoombie(DateTime.Now.AddMilliseconds(-memLayer.ML.CRI("zombieMsTime")));
|
||||
}
|
||||
// ora inizio a fare le mie stampe...
|
||||
Random rand = new Random();
|
||||
int msWait = 200;
|
||||
while (nextJob != keyParam)
|
||||
{
|
||||
// indico che ho fatto un tentativo di stampa aggiornando dtLastTry
|
||||
if (memLayer.ML.CRB("disable_singleton"))
|
||||
{
|
||||
dtProx.taPJQ.updateLastTry(keyParam);
|
||||
}
|
||||
else
|
||||
{
|
||||
DataLayer.man.taPJQ.updateLastTry(keyParam);
|
||||
}
|
||||
// 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"))
|
||||
{
|
||||
nextJob = dtProx.taPJQ.getNext()[0].KeyParam;
|
||||
}
|
||||
else
|
||||
{
|
||||
nextJob = DataLayer.man.taPJQ.getNext()[0].KeyParam;
|
||||
}
|
||||
}
|
||||
// salvo idx job...
|
||||
try
|
||||
{
|
||||
if (memLayer.ML.CRB("disable_singleton"))
|
||||
{
|
||||
idxPrintJob = dtProx.taPJQ.getNext()[0].IdxPrintJob;
|
||||
}
|
||||
else
|
||||
{
|
||||
idxPrintJob = DataLayer.man.taPJQ.getNext()[0].IdxPrintJob;
|
||||
}
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
logger.lg.scriviLog($"Errore in recupero IdxPrint Job:{exc}", tipoLog.EXCEPTION);
|
||||
}
|
||||
|
||||
// dimensioni pagina
|
||||
string outForm = "";
|
||||
string pagWidth = "";
|
||||
string pagHeigth = "";
|
||||
string margin = "";
|
||||
reportRichiesto report = reportRichiesto.stackLabel;
|
||||
string tipo = "";
|
||||
|
||||
switch (documento)
|
||||
{
|
||||
case tipoDocumento.docBinPre:
|
||||
tipo = "DocPaint";
|
||||
report = reportRichiesto.paintLabelPre;
|
||||
break;
|
||||
case tipoDocumento.docBinPost:
|
||||
tipo = "DocPaintPost";
|
||||
report = reportRichiesto.paintLabelPost;
|
||||
break;
|
||||
case tipoDocumento.docCart:
|
||||
tipo = "DocCart";
|
||||
report = reportRichiesto.cartLabel;
|
||||
break;
|
||||
case tipoDocumento.docPart:
|
||||
tipo = "DocPart";
|
||||
report = reportRichiesto.partLabel;
|
||||
break;
|
||||
case tipoDocumento.docStack:
|
||||
tipo = "DocStack";
|
||||
report = reportRichiesto.stackLabel;
|
||||
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(keyParam, printerName, answ, report, deviceInfo);
|
||||
if (answ)
|
||||
{
|
||||
// registro stampato in tabella queue...
|
||||
if (memLayer.ML.CRB("disable_singleton"))
|
||||
{
|
||||
dtProx.taPJQ.updateStato(idxPrintJob, 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
DataLayer.man.taPJQ.updateStato(idxPrintJob, 1);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// registro annullato in tab queue...
|
||||
if (memLayer.ML.CRB("disable_singleton"))
|
||||
{
|
||||
dtProx.taPJQ.updateStato(idxPrintJob, -1);
|
||||
}
|
||||
else
|
||||
{
|
||||
DataLayer.man.taPJQ.updateStato(idxPrintJob, -1);
|
||||
}
|
||||
|
||||
}
|
||||
return answ;
|
||||
// compongo stringhe x file con nomi univoci
|
||||
DateTime adesso = DateTime.Now;
|
||||
string filePathName = $"{localPdfPath}\\temp\\{name}_{adesso:HHmmss}_{adesso:ffff}.{fileNameExtension}";
|
||||
Stream stream = new FileStream(SteamwareStrings.getFilePath(filePathName), FileMode.Create);
|
||||
m_streams.Add(stream);
|
||||
return stream;
|
||||
}
|
||||
/// <summary>
|
||||
/// effettua la vera e propria fase di stampa
|
||||
/// ciclo da fornire al renderizzatore dei report, per salvare 1 pdf da ogni pagina del report
|
||||
/// </summary>
|
||||
/// <param name="keyParam"></param>
|
||||
/// <param name="printerName"></param>
|
||||
/// <param name="answ"></param>
|
||||
/// <param name="report"></param>
|
||||
/// <param name="deviceInfo"></param>
|
||||
/// <param name="name"></param>
|
||||
/// <param name="fileNameExtension"></param>
|
||||
/// <param name="encoding"></param>
|
||||
/// <param name="mimeType"></param>
|
||||
/// <param name="willSeek"></param>
|
||||
/// <returns></returns>
|
||||
private bool printAndLog(string keyParam, string printerName, bool answ, reportRichiesto report, devInfoParam deviceInfo)
|
||||
private Stream CreateStreamPdf(string name, string fileNameExtension, Encoding encoding, string mimeType, bool willSeek)
|
||||
{
|
||||
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, keyParam, 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;
|
||||
// compongo stringhe
|
||||
DateTime adesso = DateTime.Now;
|
||||
string dailyDir = $"{localPdfPath}\\{adesso:yyyy}\\{adesso:MM}\\{adesso:dd}\\";
|
||||
string pdfPathName = $"{dailyDir}\\{name}_{adesso:HHmmss}_{adesso:ffff}.{fileNameExtension}";
|
||||
// creo Directory se non c'è
|
||||
fileMover fm = new fileMover(dailyDir, "");
|
||||
fm.checkDir();
|
||||
Stream stream = new FileStream(SteamwareStrings.getFilePath(pdfPathName), FileMode.Create);
|
||||
m_streams.Add(stream);
|
||||
return stream;
|
||||
}
|
||||
/// <summary>
|
||||
/// oggetto protected
|
||||
/// Handler per PrintPageEvents
|
||||
/// </summary>
|
||||
/// <param name="args"></param>
|
||||
protected reportPrinter()
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="ev"></param>
|
||||
private void PrintPage(object sender, PrintPageEventArgs ev)
|
||||
{
|
||||
logLevel = memLayer.ML.CRI("_logLevel");
|
||||
doPdfCopy = memLayer.ML.CRB("doPdfCopy");
|
||||
Metafile pageImage = new Metafile(m_streams[m_currentPageIndex]);
|
||||
ev.Graphics.DrawImage(pageImage, ev.PageBounds);
|
||||
m_currentPageIndex++;
|
||||
ev.HasMorePages = (m_currentPageIndex < m_streams.Count);
|
||||
}
|
||||
/// <summary>
|
||||
/// singleton pubblico
|
||||
/// funzione di stampa...
|
||||
/// </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()
|
||||
private void Print(string printerName)
|
||||
{
|
||||
// num max ore di età x files "vecchi" da tenere in temp area...
|
||||
int maxOre = memLayer.ML.CRI("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)
|
||||
//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)
|
||||
{
|
||||
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);
|
||||
Log.Instance.Error($"Impostazioni non valide per la stampante {printerName}");
|
||||
return;
|
||||
}
|
||||
printDoc.PrintPage += new PrintPageEventHandler(PrintPage);
|
||||
printDoc.Print();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
Reference in New Issue
Block a user