170 lines
6.7 KiB
C#
170 lines
6.7 KiB
C#
|
|
using System;
|
|
using System.Globalization;
|
|
using System.Threading.Tasks;
|
|
using System.Windows.Forms;
|
|
using System.IO;
|
|
using PdfSharp.Pdf;
|
|
|
|
namespace GenesisZeroFlow
|
|
{
|
|
public static class Files
|
|
{
|
|
|
|
|
|
#region Open files/ save to file
|
|
public static Boolean SavePdf(PdfDocument document, String fullpath, CultureInfo culture)
|
|
{
|
|
Boolean SavingOK = false;
|
|
try
|
|
{
|
|
Task.Run(() =>
|
|
{
|
|
document.Save(@fullpath);
|
|
System.Diagnostics.Process.Start(@fullpath);
|
|
});
|
|
SavingOK = true;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
ErrorLog.Log(LogErrReason.Exeption, "Files.SavePdf() failed", $"0x{ex.HResult.ToString("X", culture)}", String.Empty, culture);
|
|
}
|
|
|
|
return SavingOK;
|
|
}
|
|
#endregion
|
|
#region File dialogs
|
|
public static Boolean SaveFiledialogPdf(out String fullpath, String initialDirectory, out String timeForHeader, CultureInfo culture)
|
|
{
|
|
#region Definitions and initializations
|
|
String FullFilename = String.Empty;
|
|
Boolean DialogOk = false;
|
|
var time = DateTime.Now;
|
|
String TimeForFilename = time.ToString(Formats.LogFileDateTimeString, culture);
|
|
timeForHeader = time.ToString(Formats.HeaderFileDateTimeString, culture);
|
|
fullpath = String.Empty;
|
|
#endregion
|
|
#region Everything else
|
|
try
|
|
{
|
|
#region Set Filename
|
|
FullFilename = $"GenesisZeroFlow_EventLogging_{TimeForFilename}.pdf";
|
|
#endregion
|
|
#region SaveFileDialog
|
|
using (SaveFileDialog saveFileDialog1 = new SaveFileDialog())
|
|
{
|
|
saveFileDialog1.Filter = "document (*.pdf)|*.pdf";
|
|
saveFileDialog1.FilterIndex = 2;
|
|
saveFileDialog1.RestoreDirectory = true;
|
|
saveFileDialog1.FileName = FullFilename;
|
|
if (Directory.Exists(initialDirectory))
|
|
saveFileDialog1.InitialDirectory = initialDirectory;
|
|
#region Save to file
|
|
if (DialogResult.Equals(saveFileDialog1.ShowDialog(), DialogResult.OK))
|
|
{
|
|
DialogOk = true;
|
|
fullpath = Path.GetFullPath(saveFileDialog1.FileName);
|
|
}
|
|
#endregion
|
|
}
|
|
#endregion
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
ErrorLog.Log(LogErrReason.Exeption, "Files.SaveFiledialogPdf() failed", $"0x{ex.HResult.ToString("X", culture)}", String.Empty, culture);
|
|
}
|
|
#endregion
|
|
|
|
return DialogOk;
|
|
}
|
|
|
|
public static Boolean SaveFiledialogTxt(out String fullPath, String initialDirectory, out String timeForHeader, CultureInfo culture)
|
|
{
|
|
#region Definitions and initializations
|
|
fullPath = String.Empty;
|
|
Boolean DialogOk = false;
|
|
DateTime time = new DateTime();
|
|
time = DateTime.Now;
|
|
String TimeForFilename = time.ToString(Formats.LogFileDateTimeString, culture);
|
|
timeForHeader = time.ToString(Formats.RawDataDateTimeLogString, culture);
|
|
#endregion
|
|
#region Everything else
|
|
try
|
|
{
|
|
#region Set Filename
|
|
String FullFilename = $"GenesisZeroFlow_EventLog_{TimeForFilename}.txt";
|
|
#endregion
|
|
#region SaveFileDialog
|
|
using (SaveFileDialog saveFileDialog1 = new SaveFileDialog())
|
|
{
|
|
saveFileDialog1.Filter = "text files (*.txt)|*.txt";
|
|
saveFileDialog1.FilterIndex = 2;
|
|
saveFileDialog1.RestoreDirectory = true;
|
|
saveFileDialog1.FileName = FullFilename;
|
|
if (Directory.Exists(initialDirectory))
|
|
saveFileDialog1.InitialDirectory = initialDirectory;
|
|
#region Save to file
|
|
if (saveFileDialog1.ShowDialog() == DialogResult.OK)
|
|
{
|
|
DialogOk = true;
|
|
fullPath = Path.GetFullPath(saveFileDialog1.FileName);
|
|
}
|
|
#endregion
|
|
}
|
|
#endregion
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
ErrorLog.Log(LogErrReason.Exeption, "Files.SaveFiledialogTxt() failed", $"0x{ex.HResult.ToString("X", culture)}", String.Empty, culture);
|
|
}
|
|
#endregion
|
|
|
|
return DialogOk;
|
|
}
|
|
|
|
public static Boolean SaveFiledialogTempCalTxt(out String fullPath, String initialDirectory, String pcbID, out String timeForHeader, CultureInfo culture)
|
|
{
|
|
#region Definitions and initializations
|
|
fullPath = String.Empty;
|
|
Boolean DialogOk = false;
|
|
DateTime time = new DateTime();
|
|
time = DateTime.Now;
|
|
String TimeForFilename = time.ToString(Formats.LogFileDateTimeString, culture);
|
|
timeForHeader = time.ToString(Formats.RawDataDateTimeLogString, culture);
|
|
#endregion
|
|
#region Everything else
|
|
try
|
|
{
|
|
#region Set Filename
|
|
String FullFilename = $"GenesisTempCalib {pcbID}{TimeForFilename}.txt";
|
|
#endregion
|
|
#region SaveFileDialog
|
|
using (SaveFileDialog saveFileDialog1 = new SaveFileDialog())
|
|
{
|
|
saveFileDialog1.Filter = "text files (*.txt)|*.txt";
|
|
saveFileDialog1.FilterIndex = 2;
|
|
saveFileDialog1.RestoreDirectory = true;
|
|
saveFileDialog1.FileName = FullFilename;
|
|
if (Directory.Exists(initialDirectory))
|
|
saveFileDialog1.InitialDirectory = initialDirectory;
|
|
#region Save to file
|
|
if (saveFileDialog1.ShowDialog() == DialogResult.OK)
|
|
{
|
|
DialogOk = true;
|
|
fullPath = Path.GetFullPath(saveFileDialog1.FileName);
|
|
}
|
|
#endregion
|
|
}
|
|
#endregion
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
ErrorLog.Log(LogErrReason.Exeption, "Files.SaveFiledialogTempCalTxt() failed", $"0x{ex.HResult.ToString("X", culture)}", String.Empty, culture);
|
|
}
|
|
#endregion
|
|
|
|
return DialogOk;
|
|
}
|
|
#endregion
|
|
}
|
|
} |