laatzen/ZeroFlowTool/Report.cs
2021-10-01 11:12:07 +02:00

339 lines
20 KiB
C#

using PdfSharp.Pdf;
using System;
using System.Globalization;
using System.Windows.Forms;
namespace GenesisZeroFlow
{
public partial class GenesisZeroFlow : Form
{
public void GenerateReturnNote(String meterIndex, String pcbID, String reason, String logData, CultureInfo culture)
{
String UserName = Environment.UserName;
DateTime Date = DateTime.Now;
String Content = String.Empty;
String Header = String.Empty;
String Filename = String.Empty;
String Headline = String.Empty;
if (GenesisZeroFlow._GenesisZeroFlow.InvokeRequired)
{
GenesisZeroFlow._GenesisZeroFlow.Invoke((Action<String, String, String, String, CultureInfo>)GenerateReturnNote, meterIndex, pcbID, reason, logData, culture);
return;
}
try
{
if (culture == CultureDe)
{
Headline = "Rückläuferschein";
Header = $"ZÄHLER{meterIndex} fehlgeschlagen.\nLeiterplattennummer:\t{pcbID}\nGrund:\t{reason}\nDatum:\t{Date.ToString(Formats.HeaderFileDateTimeString)}\nBenutzername:\t{UserName}\n";
Filename = $"Rückläuferschein_ZÄHLER{meterIndex}_{Date.ToString(Formats.LogFileDateTimeString, culture)}.pdf";
}
else
{
Headline = "Return note";
Header = $"METER{meterIndex} failed.\nPCB-ID\t{pcbID}\nReason:\t{reason}\nDate:\t{Date.ToString(Formats.HeaderFileDateTimeString)}\nUser name:\t{UserName}\n";
Filename = $"Return note_METER{meterIndex}_{Date.ToString(Formats.LogFileDateTimeString, culture)}.pdf";
}
using (PdfDocument Report = new PdfDocument())
{
ReportPages.ReturnNote(Headline, $"{Header}\n\n{logData}", Report);
Files.SavePdf(Report, $@"..\{Filename}", culture);
}
}
catch (Exception ex)
{
#region Error
ErrorLog.Log(LogErrReason.Exeption, "GenerateReturnNote() failed", $"0x{ex.HResult.ToString("X", culture)}", String.Empty, culture);
MessageBox.Show("Return note generation failed", "Form closing", MessageBoxButtons.OK, MessageBoxIcon.Error);
#endregion
}
}
private void GeneratePdfReport(CultureInfo culture)
{
System.Runtime.GCSettings.LatencyMode = System.Runtime.GCLatencyMode.LowLatency;
#region Prepare data
#region Definitions and initializations
Boolean FileDialogOk = false;
Boolean SavingOk = false;
UInt16 LocalNumberOfPaths = Constants.NumberOfPaths;
#endregion
#region Parameter definitions
#region Image parameters
//XImage Logo = pB_Logo1.Image;
#endregion
#region Text parameters
UInt16 Pagecounter = 0;
#endregion
#endregion
#region Titlepage, path, filenames
String Introduction = rtB_ReportTitlepageIntro.Text;
String Fullpath = String.Empty;
// string Itemname = "_" + rTB_ReportEnterOperator.Text + "_" + rTB_ReportEnterTitle.Text;
#endregion
#region Text definitions
#region Additional information
// string TextSoftwareVersion = l_About_Version.Text + "\n" + l_About_Author.Text + "\n" + l_About_Info.Text;
#endregion
#region Text GP30 settings
#region Declaration
String[] SettingsFromGP30Columns = new String[LocalNumberOfPaths];
for (UInt16 Path = Constants.PATH0; Path < LocalNumberOfPaths; Path++)
SettingsFromGP30Columns[Path] = String.Empty;
#endregion
#region First column
SettingsFromGP30Columns[ReportParams.Column1] =
"First Hit level up PATH1:\nFirst Hit level up PATH2:\nFirst Hit level up PATH3:\n"
+ "First Hit level down PATH1:\nFirst Hit level down PATH2:\nFirst Hit level up PATH3:\n"
+ "Number of bursts:\nStarthit:\nAmplitude peak detect:\nSamplerate:";
#endregion
#region Second column
// SettingsFromGP30Columns[ReportParams.Column2] =
// l_GetFirstLevelUpPath0Meter1.Text + "\n"+ l_GetFirstLevelUpPath1Meter1.Text + "\n" + l_GetFirstLevelUpPath2Meter1.Text + "\n" +
// l_GetFirstLevelDownPath0Meter1.Text + "\n"+ l_GetFirstLevelDownPath1Meter1.Text + "\n" + l_GetFirstLevelDownPath2Meter1.Text + "\n" +
// l_Gp30GetNumberOfPulsesMeter1.Text + "\n"+ l_Gp30GetStartHitMeter1.Text + "\n" + l_Gp30GetAmplitudeMeter1.Text + "\n" + l_Gp30GetSamplerateMeter1.Text;
#endregion
#region Third column
// SettingsFromGP30Columns[ReportParams.Column3] =
// "(" + l_GetFirstVoltageUpPath0Meter1.Text + ")\n" + "(" + l_GetFirstVoltageUpPath1Meter1.Text + ")\n" + "(" + l_GetFirstVoltageUpPath2Meter1.Text + ")\n" +
// "(" + l_GetFirstVoltageDownPath0Meter1.Text + ")\n" + "(" + l_GetFirstVoltageDownPath1Meter1.Text + ")\n" + "(" + l_GetFirstVoltageDownPath2Meter1.Text + ")";
#endregion
#endregion
#region Decoded data text
#region Definitions and initializations
// string[] DecodedDataColumns = new string[4] { String.Empty, String.Empty, String.Empty, String.Empty };
#endregion
#region Set data
#region First Column
#region Set data
/*
DecodedDataColumns[ReportParams.Column1] =
l_HccValPath0.Text + "\n" +
l_HccCorrectionFactorPath0.Text + "\n" +
l_PwUpPath0.Text + "\n" +
l_PwDownPath0.Text + "\n" +
l_AmpUpPath0.Text + "\n" +
l_AmpDownPath0.Text + "\n" +
l_AmpCalHighPath0.Text + "\n" +
l_AmpCalLowPath0.Text + "\n" +
l_TofSumOfAllUpPath0.Text + "\n" +
l_TofSumOfAllDownPath0.Text + "\n" +
l_Tof0UpPath0.Text + "\n" +
l_Tof1UpPath0.Text + "\n" +
l_Tof2UpPath0.Text + "\n" +
l_Tof3UpPath0.Text + "\n" +
l_Tof4UpPath0.Text + "\n" +
l_Tof5UpPath0.Text + "\n" +
l_Tof6UpPath0.Text + "\n" +
l_Tof7UpPath0.Text + "\n" +
l_Tof0DownPath0.Text + "\n" +
l_Tof1DownPath0.Text + "\n" +
l_Tof2DownPath0.Text + "\n" +
l_Tof3DownPath0.Text + "\n" +
l_Tof4DownPath0.Text + "\n" +
l_Tof5DownPath0.Text + "\n" +
l_Tof6DownPath0.Text + "\n" +
l_Tof7DownPath0.Text + "\n" +
l_TemperaturePath0.Text + "\n" +
l_ProtocolVersion.Text + "\n\n\nComment:";*/
#endregion
#endregion
#region PATH0
#region Set data
/*
DecodedDataColumns[ReportParams.Column2] =
l_HccValDispPath0.Text + "\n" +
l_HccCorrectionFactorDispPath0.Text + "\n" +
l_PwUpDispPath0.Text + "\n" +
l_PwDownDispPath0.Text + "\n" +
l_AmpUpDispPath0.Text + "\n" +
l_AmpUpDispPath0.Text + "\n" +
l_AmpCalHighDispPath0.Text + "\n" +
l_AmpCalLowDispPath0.Text + "\n" +
l_TofSumOfAllUpDispPath0.Text + "\n" +
l_TofSumOfAllDownDispPath0.Text + "\n" +
l_Tof0UpDispPath0.Text + "\n" +
l_Tof1UpDispPath0.Text + "\n" +
l_Tof2UpDispPath0.Text + "\n" +
l_Tof3UpDispPath0.Text + "\n" +
l_Tof4UpDispPath0.Text + "\n" +
l_Tof5UpDispPath0.Text + "\n" +
l_Tof6UpDispPath0.Text + "\n" +
l_Tof7UpDispPath0.Text + "\n" +
l_Tof0UpDispPath0.Text + "\n" +
l_Tof1UpDispPath0.Text + "\n" +
l_Tof2UpDispPath0.Text + "\n" +
l_Tof3UpDispPath0.Text + "\n" +
l_Tof4UpDispPath0.Text + "\n" +
l_Tof5UpDispPath0.Text + "\n" +
l_Tof6UpDispPath0.Text + "\n" +
l_Tof7UpDispPath0.Text + "\n" +
l_TemperatureDispPath0.Text + "\n" +
l_DispProtocolVersion.Text+"\n\n\n";*/
#endregion
#region Comment field
/*
if (Decoded[Constants.PATH0].Comment == string.Empty)
DecodedDataColumns[ReportParams.Column2] = DecodedDataColumns[ReportParams.Column2] + "---";
else
DecodedDataColumns[ReportParams.Column2] = DecodedDataColumns[ReportParams.Column2] + Decoded[Constants.PATH0].Comment;
*/
#endregion
#endregion
#region PATH1
#region Set data
/*
DecodedDataColumns[ReportParams.Column3] =
l_HccValDispPath1.Text + "\n" +
l_HccCorrectionFactorDispPath1.Text +"\n" +
l_PwUpDispPath1.Text + "\n" +
l_PwDownDispPath1.Text + "\n" +
l_AmpUpDispPath1.Text + "\n" +
l_AmpUpDispPath1.Text + "\n" +
l_AmpCalHighDispPath1.Text + "\n" +
l_AmpCalLowDispPath1.Text + "\n" +
l_TofSumOfAllUpDispPath1.Text + "\n" +
l_TofSumOfAllDownDispPath1.Text + "\n" +
l_Tof0UpDispPath1.Text + "\n" +
l_Tof1UpDispPath1.Text + "\n" +
l_Tof2UpDispPath1.Text + "\n" +
l_Tof3UpDispPath1.Text + "\n" +
l_Tof4UpDispPath1.Text + "\n" +
l_Tof5UpDispPath1.Text + "\n" +
l_Tof6UpDispPath1.Text + "\n" +
l_Tof7UpDispPath1.Text + "\n" +
l_Tof0UpDispPath1.Text + "\n" +
l_Tof1DownDispPath1.Text + "\n" +
l_Tof2DownDispPath1.Text + "\n" +
l_Tof3DownDispPath1.Text + "\n" +
l_Tof4DownDispPath1.Text + "\n" +
l_Tof5DownDispPath1.Text + "\n" +
l_Tof6DownDispPath1.Text + "\n" +
l_Tof7DownDispPath1.Text + "\n" +
l_TemperatureDispPath1.Text + "\n" +
l_DispProtocolVersion.Text + "\n\n\n";*/
#endregion
#region Comment field
/*
if (Decoded[Constants.PATH1].Comment == string.Empty)
DecodedDataColumns[ReportParams.Column3] = DecodedDataColumns[ReportParams.Column3] + "---";
else
DecodedDataColumns[ReportParams.Column3] = DecodedDataColumns[ReportParams.Column3] + Decoded[Constants.PATH1].Comment;
*/
#endregion
#endregion
#region PATH2
#region Set data
/*
DecodedDataColumns[ReportParams.Column4] =
l_HccValDispPath2.Text + "\n" +
l_HccCorrectionFactorDispPath2.Text + "\n" +
l_PwUpDispPath2.Text + "\n" +
l_PwDownDispPath2.Text + "\n" +
l_AmpUpDispPath2.Text + "\n" +
l_AmpUpDispPath2.Text + "\n" +
l_AmpCalHighDispPath2.Text + "\n" +
l_AmpCalLowDispPath2.Text + "\n" +
l_TofSumOfAllUpDispPath2.Text + "\n" +
l_TofSumOfAllDownDispPath2.Text + "\n" +
l_Tof0UpDispPath2.Text + "\n" +
l_Tof1UpDispPath2.Text + "\n" +
l_Tof2UpDispPath2.Text + "\n" +
l_Tof3UpDispPath2.Text + "\n" +
l_Tof4UpDispPath2.Text + "\n" +
l_Tof5UpDispPath2.Text + "\n" +
l_Tof6UpDispPath2.Text + "\n" +
l_Tof7UpDispPath2.Text + "\n" +
l_Tof0UpDispPath2.Text + "\n" +
l_Tof1DownDispPath2.Text + "\n" +
l_Tof2DownDispPath2.Text + "\n" +
l_Tof3DownDispPath2.Text + "\n" +
l_Tof4DownDispPath2.Text + "\n" +
l_Tof5DownDispPath2.Text + "\n" +
l_Tof6DownDispPath2.Text + "\n" +
l_Tof7DownDispPath2.Text + "\n" +
l_TemperatureDispPath2.Text + "\n" +
l_DispProtocolVersion.Text + "\n\n\n";*/
#endregion
#region Comment field
/*
if (Decoded[Constants.PATH2].Comment == string.Empty)
DecodedDataColumns[ReportParams.Column4] = DecodedDataColumns[ReportParams.Column4] + "---";
else
DecodedDataColumns[ReportParams.Column4] = DecodedDataColumns[ReportParams.Column4] + Decoded[Constants.PATH2].Comment;
*/
#endregion
#endregion
#endregion
#endregion
#endregion
#region Check for serial number
if (String.IsNullOrEmpty(rTB_ReportEnterSerialNumber.Text))
{
MessageBox.Show("Enter serial number!", "Form closing", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
#endregion
#endregion
#region Create pages and generate report
try
{
//using (PdfDocument Report = new PdfDocument())
//{
// #region Create new report
// Report.Info.Title = rTB_ReportEnterTitle.Text;
// Report.Info.Author = rTB_ReportEnterOperator.Text;
// #endregion
// #region Page "Titlepage
// Pagecounter = ReportPages.TitlePage(Pagecounter, Introduction, rTB_ReportEnterTitle.Text, rTB_ReportEnterDate.Text, rTB_ReportEnterOperator.Text, rTB_ReportEnterSerialNumber.Text, Report, Logo, culture);
// #endregion
// #region Page "SETTINGS"
// //Pagecounter = ReportPages.Settings(Pagecounter, TextSoftwareVersion, SettingsFromGP30Columns, cB_ReportGP30Settings.Checked, Report, Logo);
// #endregion
// #region Page "DECODED DATA"
// //Pagecounter = ReportPages.DecodedData(Pagecounter, DecodedDataColumns, Report, Logo);
// #endregion
// #region Page "MAINGRAPH"
// // Pagecounter = ReportPages.Maingraph(Pagecounter, MainGraphTitle, zGC_MainGraph, cB_ReportMainGraph.Checked, Report, Logo);
// #endregion
// #region Page "MEAN VALUES"
// //ReportPages.MeanValues(Pagecounter, MeanColumns, cB_ReportMean.Checked, cB_ReportMeanPath0.Checked, cB_ReportMeanPath1.Checked, cB_ReportMeanPath2.Checked, Report, Logo);
// #endregion
// #region Save file
// //FileDialogOK = Files.SaveFiledialogPdf(Itemname, ref Fullpath, DefaultReportDirectory);
// if (FileDialogOk)
// {
// //DefaultReportDirectory = System.IO.Path.GetDirectoryName(Fullpath);
// SavingOk = Files.SavePdf(Report, Fullpath, culture);
// }
// #endregion
// #region Result
// if((!SavingOk)&&(FileDialogOk))
// MessageBox.Show("Report generation failed", "Form closing", MessageBoxButtons.OK, MessageBoxIcon.Error);
// #endregion
//}
}
catch (Exception ex)
{
#region Error
ErrorLog.Log(LogErrReason.Exeption, "GeneratePdfReport() failed", $"0x{ex.HResult.ToString("X", culture)}", String.Empty, culture);
MessageBox.Show("Report generation failed", "Form closing", MessageBoxButtons.OK, MessageBoxIcon.Error);
#endregion
}
#endregion
System.Runtime.GCSettings.LatencyMode = System.Runtime.GCLatencyMode.SustainedLowLatency;
}
}
}